ASP.NET-FineUI開発実践-3

7870 ワード

1.参照アナログデータベースページングキャッシュによるメモリページングの書き換え、ページ応答速度の最適化
Gridの応答速度は硬傷で、私は共通の方法を書いてすべてのデータをキャッシュの中に置いてデータベースのページングをシミュレートして、持参したキャッシュのページングよりずっと速くて、ここに実体クラスの共通の方法を貼って、DataTableのは公式の自分で書くことを参照することができます.gridを付けることを覚えておいてください.PageIndexChangeイベントとgrid_Sort事件、ここでは書きません
  
        /// <summary>

        ///      

        /// </summary>

        /// <returns></returns>

        private void GetData()

        {

            List<MsUser> lstUser = GetData();//         

            ViewState["lstUserData"] = JsonConvert.SerializeObject(lstUser);

        }



        /// <summary>

        ///      

        /// </summary>

        private void BindGridView()

        {

            string slstUserData = ViewState["lstUserData"].ToString();

            BindGridView<MsUser>(slstUserData, ref grid);

        }







         /// <summary>

        ///      

        /// </summary>

        /// <typeparam name="T">   </typeparam>

        /// <param name="vDataNew">  Json</param>

        /// <param name="g">grid</param>

        public static void BindGridView<T>(string vDataNew, ref Grid g)

        {



            List<T> DataNew = (List<T>)JsonConvert.DeserializeObject(vDataNew, typeof(List<T>));

            g.RecordCount = DataNew.Count;

            int pageSize = g.PageSize;//      

            int pageIndex = g.PageIndex;//      

            int pi = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(DataNew.Count) / Convert.ToDouble(g.PageSize)));

            pageIndex = pageIndex + 1 > pi ? pi - 1 : pageIndex;//     (   )     

            if (pageIndex < 0)

            {

                pageIndex = 0;

            }

            try

            {

                Reverser<T> reverser = null;

                string SortField = g.SortField;//      

                if (SortField == "")

                {

                    SortField = g.Columns[1].SortField;//         

                }

                reverser = new Reverser<T>(DataNew[0].GetType(), SortField, g.SortDirection == "ASC" ? ReverserInfo.Direction.ASC : ReverserInfo.Direction.DESC);//    

                DataNew.Sort(reverser);

                if (pageSize <= DataNew.Count)

                {

                    int pz = pageSize < DataNew.Count - pageIndex * pageSize ? pageSize : DataNew.Count - pageIndex * pageSize;

                    if (pageSize == DataNew.Count)

                    {

                        pz = pageSize;

                    }

                    DataNew = DataNew.GetRange((pageIndex) * pageSize, pz);//    

                }



                g.DataSource = DataNew;//  

                g.DataBind();



            }

            catch (Exception ex)

            {

                //Response.Write(ex.Message);

                g.DataSource = null;

                g.DataBind();

            }

            g.PageIndex = g.PageIndex + 1 > g.PageCount ? g.PageCount - 1 : g.PageIndex;

            if (g.PageIndex < 0)

            {

                g.PageIndex = 0;

            }

        }







     /*           */

    /// <summary>

    ///   IComparer<T>  ,              

    /// </summary>

    /// <typeparam name="T">T     </typeparam>

    public class Reverser<T> : IComparer<T>

    {

        private Type type = null;

        private ReverserInfo info;



        /**/

        /// <summary>

        ///     

        /// </summary>

        /// <param name="type">        </param>

        /// <param name="name">           </param>

        /// <param name="direction">    (  /  )</param>

        public Reverser(Type type, string name, ReverserInfo.Direction direction)

        {

            this.type = type;

            this.info.name = name;

            if (direction != ReverserInfo.Direction.ASC)

                this.info.direction = direction;

        }





        /**/

        /// <summary>

        ///     

        /// </summary>

        /// <param name="className">        </param>

        /// <param name="name">           </param>

        /// <param name="direction">    (  /  )</param>

        public Reverser(string className, string name, ReverserInfo.Direction direction)

        {

            try

            {

                this.type = Type.GetType(className, true);

                this.info.name = name;

                this.info.direction = direction;

            }

            catch (Exception e)

            {

                throw new Exception(e.Message);

            }

        }



        /**/

        /// <summary>

        ///     

        /// </summary>

        /// <param name="t">          </param>

        /// <param name="name">           </param>

        /// <param name="direction">    (  /  )</param>

        public Reverser(T t, string name, ReverserInfo.Direction direction)

        {

            this.type = t.GetType();

            this.info.name = name;

            this.info.direction = direction;

        }



        //  !  IComparer<T>     。

        int IComparer<T>.Compare(T t1, T t2)

        {

            object x = this.type.InvokeMember(this.info.name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, t1, null);

            object y = this.type.InvokeMember(this.info.name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, t2, null);

            if (this.info.direction != ReverserInfo.Direction.ASC)

                Swap(ref x, ref y);

            return (new CaseInsensitiveComparer()).Compare(x, y);

        }



        //     

        private void Swap(ref object x, ref object y)

        {

            object temp = null;

            temp = x;

            x = y;

            y = temp;

        }

    }



    /**/

    /// <summary>

    ///            

    /// </summary>

    public struct ReverserInfo

    {

        /**/

        /// <summary>

        ///      ,  :

        /// ASC:  

        /// DESC:  

        /// </summary>

        public enum Direction

        {

            ASC = 0,

            DESC,

        };



        public enum Target

        {

            CUSTOMER = 0,

            FORM,

            FIELD,

            SERVER,

        };



        public string name;

        public Direction direction;

        public Target target;

    }


  
2.指定行指定列の値を得るバックグラウンド、rowsのvaluesは行の値、バックグラウンドは見ることができて、列番号を通じて配列の値を探し当てて、この方法はとても保険的ではありません
01.grid.Rows[rowindex].Values[grid.FindColumn(Columnid).ColumnIndex].ToString();  


  
3.ボタンは少なくとも1つの一般的な方法を選択し、OnClientClick+=累積します.
        /// <summary>

        ///       

        /// </summary>

        /// <param name="g"></param>

        /// <param name="ctrls"></param>

        private void NoSelectionNull(Grid g, params FineUI.Button[] ctrls)

        {

            foreach (FineUI.Button ctrl in ctrls)

            {

                ctrl.OnClientClick += g.GetNoSelectionAlertReference("      !");

            }

        }

        

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

              NoSelectionNull(Grid1, Button4, Button2, Button3, Button6);

            }

        }