自做 数据分页,执行SQL操作数据分页,SQL 分页

WMS.Web.YZMManagement.YZMOrderControl.YZMOrderControl_List.aspx

        function ListGrid() {
            $("#Button1").click();
        }
 <a id="btn-query" href="javascript:;" onclick="ListGrid();" class="buttonHuge button-blue" style="color: #fff">查询</a>
        <div style="margin-top:20px;bottom: 0px; position: absolute; width:100%; text-align:center;">
            <asp:Button ID="FirstPageText" runat="server" Text="首  页" 
                onclick="FirstPageText_Click" />
            <asp:Button ID="PrevPageText" runat="server" Text="上一页" 
                onclick="PrevPageText_Click" /> 
        
            <asp:Label ID="Label1" runat="server" Text="第"></asp:Label> 
            <input id="PageIndex" type="text" runat="server" value="" style=" width:50px;" class="txt" datacol="No" checkexpession="Int" />
            <asp:Label ID="Label2" runat="server" Text="页"></asp:Label> 
            <asp:Button ID="Btn_PageIndex" runat="server" Text="GO" 
                onclick="Btn_PageIndex_Click" /> 

            <asp:Button ID="NextPageText" runat="server" Text="下一页" 
                onclick="NextPageText_Click" />
            <asp:Button ID="LastPageText" runat="server" Text="尾  页" 
                onclick="LastPageText_Click" />
                  
            <asp:Label ID="Label5" runat="server" Text="当前页"></asp:Label>
            <asp:Label ID="CurrentPage" runat="server"></asp:Label>  

            <asp:Label ID="Label4" runat="server" Text="共"></asp:Label> 
            <asp:Label ID="PageCount" runat="server"></asp:Label> 
            <asp:Label ID="Label3" runat="server" Text="页"></asp:Label> 

            <asp:Label ID="Label6" runat="server" Text="检索到"></asp:Label> 
            <asp:Label ID="CountSum" runat="server"></asp:Label> 
            <asp:Label ID="Label8" runat="server" Text="条数据"></asp:Label> 

        </div>

  

cs

        public string sel = "";
        //当前页
        public int _CurrentPage;
        //共页
        public int _PageCount;
        
        //首页
        public int _FirstPage;
        //上一页
        public int _PrevPage;
        //下一页
        public int _NextPage;
        //尾页
        public int _LastPage;

        //跳转页
        public int _GO = 1;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                sel = "sel";
                loadhtml();
            }
        }


        private void loadhtml()
        {
                            DataTable dt = new DataTable();
            //查询
            if (sel == "sel")
            {
                int count = 0;
                dt = mor_dal.GetOrderDataTablePageList(SqlWhere.ToString(), "order_id", "asc", _GO, 20, ref count);

                if (count % 20 > 0)
                {
                    _PageCount = count / 20 + 1;
                }
                else
                {
                    _PageCount = count / 20;
                }

                //给分页赋值
                CurrentPage.Text = _GO.ToString();
                PageCount.Text = _PageCount.ToString();
                CountSum.Text = count.ToString();


                if (_GO == 1)
                {
                    PrevPageText.Enabled = false;
                }
                else
                {
                    PrevPageText.Enabled = true;
                }

                if (Convert.ToInt32(PageCount.Text.Trim()) == _GO)
                {
                    NextPageText.Enabled = false;

                }
                else
                {
                    NextPageText.Enabled = true;
                }

                
            }
            else
            {
                int count = 0;
                dt = mor_dal.GetOrderDataTablePageList(SqlWhere.ToString(), "order_id", "asc", _GO, 20, ref count);

                CurrentPage.Text = _GO.ToString();
            }
        }

        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void FirstPageText_Click(object sender, EventArgs e)
        {
            _GO = 1;
            PrevPageText.Enabled = false;

            if (Convert.ToInt32(PageCount.Text.Trim()) == _GO)
            {
                NextPageText.Enabled = false;

            }
            else
            {
                NextPageText.Enabled = true;
            }

            loadhtml();
        }

        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void PrevPageText_Click(object sender, EventArgs e)
        {
            _GO = Convert.ToInt32(CurrentPage.Text.Trim()) - 1;

            if (_GO == 1)
            {
                PrevPageText.Enabled = false;
            }
            else
            {
                PrevPageText.Enabled = true;
            }

            if (Convert.ToInt32(PageCount.Text.Trim()) == _GO)
            {
                NextPageText.Enabled = false;

            }
            else
            {
                NextPageText.Enabled = true;
            }

            loadhtml();
        }

        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void NextPageText_Click(object sender, EventArgs e)
        {
            _GO = Convert.ToInt32(CurrentPage.Text.Trim()) + 1;

            if (_GO == 1)
            {
                PrevPageText.Enabled = false;
            }
            else
            {
                PrevPageText.Enabled = true;
            }

            if (Convert.ToInt32(PageCount.Text.Trim()) == _GO)
            {
                NextPageText.Enabled = false;

            }
            else
            {
                NextPageText.Enabled = true;
            }

            loadhtml();
        }

        /// <summary>
        /// 尾页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>NextPageTextLastPage
        protected void LastPageText_Click(object sender, EventArgs e)
        {
            _GO = Convert.ToInt32(PageCount.Text.Trim());

            NextPageText.Enabled = false;

            if (_GO == 1)
            {
                PrevPageText.Enabled = false;

            }
            else
            {
                PrevPageText.Enabled = true;
            }


            loadhtml();
        }

        /// <summary>
        /// G O
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Btn_PageIndex_Click(object sender, EventArgs e)
        {
            try
            {
                if (Convert.ToInt32(PageIndex.Value.Trim()) <= Convert.ToInt32(PageCount.Text.Trim()) && PageIndex.Value.Trim() != "0")
                {
                    _GO = Convert.ToInt32(PageIndex.Value.Trim());

                    if (_GO == 1)
                    {
                        PrevPageText.Enabled = false;
                    }
                    else
                    {
                        PrevPageText.Enabled = true;
                    }

                    if (Convert.ToInt32(PageCount.Text.Trim()) == _GO)
                    {
                        NextPageText.Enabled = false;

                    }
                    else
                    {
                        NextPageText.Enabled = true;
                    }


                    loadhtml();
                }
                else
                {
                    Page.Response.Write("<script type=\"text/javascript\">alert('已超出索引!');</script>");
                }
            }
            catch (Exception)
            {
                Page.Response.Write("<script type=\"text/javascript\">alert('输入有误!');</script>");
            }
        }




//执行SQL
/// <summary>
        /// 销售订单明细--分页
        /// </summary>
        /// <param name="sqlwhere">条件</param>
        /// <param name="orderField">排序字段</param>
        /// <param name="orderType">排序类型</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="count">返回查询条数</param>
        /// <returns></returns>
        public System.Data.DataTable GetOrderDataTablePageList(string sqlwhere, string orderField, string orderType, int pageIndex, int pageSize, ref int count)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT 
                            E.order_id,
                            E.order_no,
                            E.cust_no, 
                            E.cust_name, 
                            E.or_currency_Name,
                            E.or_ask_money,
                            E.or_sale_uname, 
                            E.or_date,
                            E.touching_uname,
                            E.touching_date,
                            E.or_check,
                            E.or_check_date, 
                            E.or_status,
                            E.or_remark,
                            Q.op_id,
                            Q.op_matno, 
                            Q.op_matname, 
                            Q.op_matStandard,
                            Q.op_unit,
                            Q.op_unit_id,
                            Q.op_quantity, 
                            Q.op_price,
                            Q.op_money, 
                            Q.op_delivery_date,
                            Q.IsStockNum,
                            Q.NotStockNum,
                            Q.op_remark,
                            Q.pro_code,
                            D.dep_type,
							D.amount           
                            FROM YZOrder as E LEFT JOIN 
                            YZOrder_product as Q on e.order_no = Q.order_no LEFT JOIN 
                            YZ_Depot as D on q.op_matno= D.mat_no WHERE 1=1");
            strSql.Append(sqlwhere);
            return DataFactory.SqlDataBase().GetPageList(strSql.ToString(), orderField, orderType, pageIndex, pageSize, ref count);
        }



        /// <summary>
        /// 摘要:
        ///     数据分页
        /// 参数:
        ///     sql:传入要执行sql语句
        ///     param:参数化
        ///     orderField:排序字段
        ///     orderType:排序类型
        ///     pageIndex:当前页
        ///     pageSize:页大小
        ///     count:返回查询条数
        /// </summary>
        public DataTable GetPageList(string sql, SqlParam[] param, string orderField, string orderType, int pageIndex, int pageSize, ref int count)
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                int num = (pageIndex - 1) * pageSize;
                int num1 = (pageIndex) * pageSize;
                sb.Append("Select * From (Select ROW_NUMBER() Over (Order By " + orderField + " " + orderType + "");
                sb.Append(") As rowNum, * From (" + sql + ") As T ) As N Where rowNum > " + num + " And rowNum <= " + num1 + "");
                count = Convert.ToInt32(this.GetObjectValue(new StringBuilder("Select Count(1) From (" + sql + ") As t"), param));
                return this.GetDataTableBySQL(sb, param);
            }
            catch (Exception e)
            {
                DbLog.WriteException(e);
                return null; ;
            }
        }


                            

  

 

 

posted @ 2014-05-10 18:00  lengv10  阅读(302)  评论(0编辑  收藏  举报