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

WMS.Web.YZMManagement.YZMOrderControl.YZMOrderControl_List.aspx

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

       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

?





1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

        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; ;

            }

        }

                           

  

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

时间: 2024-10-04 21:19:07

自做 数据分页,执行SQL操作数据分页,SQL 分页的相关文章

接口调用外部系统返回数据,本系统做数据分页封装

场景: 本系统用的Mybatis分页插件PageHelper,调用了外部系统返回的数据为String类型的JSON串,数据量毕竟多,界面需要分页展示. 解决思路: 返回数据转List,然后把多个List放到一个List里,然后在从这个List里进行分页,前端只需要传一个页码过来即可, 部分代码如下: Service代码 ResponseMsg<AppResp> responseMsg = new ResponseMsg<>(); int currentPage = req.getC

[读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例

这是我的文章备份,原始出处:[读书心得]资料分页的优化,以SQL 2012的 OFFSET-FETCH为例 http://www.dotblogs.com.tw/mis2000lab/archive/2015/04/10/sql_querying_paging_offset-fetch.aspx 这篇文章源自微软出版社(Microsoft Press) 2015年的新书 -- T-SQL Querying Published 3/6/2015 1st Edition 864 pages Book

【知了堂学习笔记】JSP页面数据分页实现(一)——分页概念以及主流数据库的分页查询

一.分页简介 1.分页,就是一种将数据库里的数据一部分展示给用户的技术.为什么要这样做呢?因为一般来说用户在查询时数据是非常多的,当一个页面不能显示所有数据时,我们就要对查询的数据进行分页,就像我们的书本分成一页一页一样.最简单的例子就是百度,当你百度时,成千上万的数据,并不是呈现在一个页面的. 2.分页的实现方式 1)假分页(不推荐):什么是假分页呢?假分页就是一次性将数据库里的数据全部取出来,存储在页面中,然后再将数据分别展示出来.这种假分页在数据少的还可以玩玩,当数据多起来的时候,这种方式

sql server 与 mysql 分页查询以及创建临时表的区别

一: 分页查询的时候 sql server使用的是top关键字,而mysql 使用的是limit e.g: 查询第五个到第十个入职的职员 sql server2000: select top 6 * from emp where empno not in (select top 4 empno from emp order by hiredate) order by hiredate; mysql: select * from emp order by hire date limit 4,6;

SQL Server 的通用分页显示存储过程

建立一个 Web 应用,分页浏览功能必不可少.这个问题是数据库处理中十分常见的问题.经典的数据分页方法是:ADO 纪录集分页法,也就是利用ADO自带的分页功能(利用游标)来实现分页.但这种分页方法仅适用于较小数据量的情形,因为游标本身有缺点:游标是存放在内存中,很费内存.游标一建立,就将相关的记录锁住,直到取消游标.游标提供了对特定集合中逐行扫描的手段,一般使用游标来逐行遍历数据,根据取出数据条件的不同进行不同的操作.而对于多表和大表中定义的游标(大的数据集合)循环很容易使程序进入一个漫长的等待

Oracle、MYSQL、sql server和DB2分页查询写法

一.DB2: DB2分页查询 SELECT * FROM (Select 字段1,字段2,字段3,rownumber() over(ORDER BY 排序用的列名 ASC) AS rn from 表名) AS a1 WHERE a1.rn BETWEEN 10 AND 20 以上表示提取第10到20的纪录 select * from (select rownumber() over(order by id asc ) as rowid from table where rowid <=endIn

SQL Server2012 T-SQL对分页的增强尝试

简介 SQL Server 2012中在Order By子句之后新增了OFFSET和FETCH子句来限制输出的行数从而达到了分页效果.相比较SQL Server 2005/2008的ROW_Number函数而言,使用OFFSET和FETCH不仅仅是从语法角度更加简单,并且拥有了更优的性能(看到很多人下过这个结论,但我测试有所偏差,暂且保留意见). MSDN上对于OFFSET和FETCH的详细描述可以在(http://msdn.microsoft.com/en-us/library/ms18838

SQL两种简单分页查询方式

以前我们或许都用过了linq的skip and take方式进行分页查询,但是很少自己写sql的分页查询,因为大多数时候,我们都是在调用别人的方法. 最近看到一个文档,感觉方法里面实现的分页查询进入数据库调用的时候,实际最底层调用的还是SQL的分页查询,例如,我们用linq写个分页查询,转成sql表达式后发现: 实际调用的时候,才发现SQL底层是这样进行分页的. 下面,本文主要是介绍两种SQL的分页查询. 一,TOP方式 ----第一种分页查询方式:TOP方式 declare @page int

SQL Server 执行计划利用统计信息对数据行的预估原理以及SQL Server 2014中预估策略的改变

前提  本文仅讨论SQL Server查询时, 对于非复合统计信息,也即每个字段的统计信息只包含当前列的数据分布的情况下, 在用多个字段进行组合查询的时候,如何根据统计信息去预估行数的. 利用不同字段的统计信息做数据行数预估的算法原理,以及SQL Server 2012和SQL Server 2014该算法的差异情况, 这里暂时不涉及复合统计信息,暂不涉及统计信息的更新策略及优化相关话题,以及其他SQL Server版本计算方式. 统计信息是什么 简单说就是对某些字段的数据分布的一种描述,让SQ