jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;
using HH.WMS.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using HH.WMS.Entitys.Func;
using HH.WMS.Client.Common;
using HH.WMS.Entitys.Basic;
using DevComponents.DotNetBar;
 
namespace WindowsApp.MyControl
{
    /// <summary>
    /// ÉêÃ÷ίÍÐ
    /// </summary>
    /// <param name="e"></param>
    /// <returns></returns>
    public delegate int EventPagingHandler(EventPagingArg e);
    /// <summary>
    /// ·ÖÒ³¿Ø¼þ³ÊÏÖ
    /// </summary>
    public partial class Pager : UserControl
    {
        public Pager()
        {
            InitializeComponent();
        }
        public event EventPagingHandler EventPaging;
        /// <summary>
        /// Ã¿Ò³ÏÔʾ¼Ç¼Êý
        /// </summary>
        private int _pageSize = 50;
        /// <summary>
        /// Ã¿Ò³ÏÔʾ¼Ç¼Êý
        /// </summary>
        public int PageSize
        {
            get { return _pageSize; }
            set
            {
                _pageSize = value;
                GetPageCount();
            }
        }
 
        private int _nMax = 0;
        /// <summary>
        /// ×ܼǼÊý
        /// </summary>
        public int NMax
        {
            get { return _nMax; }
            set
            {
                _nMax = value;
                GetPageCount();
            }
        }
 
        private int _pageCount = 0;
        /// <summary>
        /// Ò³Êý=×ܼǼÊý/ÿҳÏÔʾ¼Ç¼Êý
        /// </summary>
        public int PageCount
        {
            get { return _pageCount; }
            set { _pageCount = value; }
        }
 
        private int _pageCurrent = 0;
        /// <summary>
        /// µ±Ç°Ò³ºÅ
        /// </summary>
        public int PageCurrent
        {
            get { return _pageCurrent; }
            set { _pageCurrent = value; }
        }
 
        public BindingNavigator ToolBar
        {
            get { return this.bindingNavigator; }
        }
 
        private void GetPageCount()
        {
            if (this.NMax > 0)
            {
                this.PageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(this.NMax) / Convert.ToDouble(this.PageSize)));
            }
            else
            {
                this.PageCount = 0;
            }
        }
 
        /// <summary>
        /// ·­Ò³¿Ø¼þÊý¾Ý°ó¶¨µÄ·½·¨
        /// </summary>
        public void Bind()
        {
            this._pageSize = Convert.ToInt32(this.ComPageSize.Text);
            if (this.EventPaging != null)
            {
                this.NMax = this.EventPaging(new EventPagingArg(this.PageCurrent));
            }
 
            if (this.PageCurrent > this.PageCount)
            {
                this.PageCurrent = this.PageCount;
            }
            if (this.PageCount == 1)
            {
                this.PageCurrent = 1;
            }
            lblPageCount.Text = this.PageCount.ToString();
            this.lblMaxPage.Text = "¹²" + this.NMax.ToString() + "Ìõ¼Ç¼";
            this.txtCurrentPage.Text = this.PageCurrent.ToString();
 
            if (this.PageCurrent == 1)
            {
                this.btnPrev.Enabled = false;
                this.btnFirst.Enabled = false;
            }
            else
            {
                btnPrev.Enabled = true;
                btnFirst.Enabled = true;
            }
 
            if (this.PageCurrent == this.PageCount)
            {
                this.btnLast.Enabled = false;
                this.btnNext.Enabled = false;
            }
            else
            {
                btnLast.Enabled = true;
                btnNext.Enabled = true;
            }
 
            if (this.NMax == 0)
            {
                btnNext.Enabled = false;
                btnLast.Enabled = false;
                btnFirst.Enabled = false;
                btnPrev.Enabled = false;
            }
 
            //GetComboxPageSize();
        }
        //·ÖÒ³´óСÏÂÀ­¿ò
        public void GetComboxPageSize() 
        {
            this.ComPageSize.Items.Add("50");
            this.ComPageSize.Items.Add("200");
            this.ComPageSize.Items.Add("500");
            this.ComPageSize.Items.Add("1000");
            this.ComPageSize.Items.Add("2000");
            //this.ComPageSize.SelectedIndex = 0;
        }
 
        private void btnFirst_Click(object sender, EventArgs e)
        {
            PageCurrent = 1;
            this.Bind();
        }
 
        private void btnPrev_Click(object sender, EventArgs e)
        {
            PageCurrent -= 1;
            if (PageCurrent <= 0)
            {
                PageCurrent = 1;
            }
            this.Bind();
        }
 
        private void btnNext_Click(object sender, EventArgs e)
        {
            this.PageCurrent += 1;
            if (PageCurrent > PageCount)
            {
                PageCurrent = PageCount;
            }
            this.Bind();
        }
 
        private void btnLast_Click(object sender, EventArgs e)
        {
            PageCurrent = PageCount;
            this.Bind();
        }
 
        private void btnGo_Click(object sender, EventArgs e)
        {
            if (this.txtCurrentPage.Text != null && txtCurrentPage.Text != "")
            {
                if (Int32.TryParse(txtCurrentPage.Text, out _pageCurrent))
                {
                    this.Bind();
                }
                else
                {
                    MessageBox.Show("ÊäÈëÊý×Ö¸ñʽ´íÎó£¡");
                }
            }
        }
 
        private void txtCurrentPage_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.Bind();
            }
        }
 
        private void ComPageSize_TextChanged(object sender, EventArgs e)
        {
            this.Bind();
        }
    }
    /// <summary>
    /// ×Ô¶¨ÒåʼþÊý¾Ý»ùÀà
    /// </summary>
    public class EventPagingArg : EventArgs
    {
        private int _intPageIndex;
        public EventPagingArg(int PageIndex)
        {
            _intPageIndex = PageIndex;
        }
    }
    /// <summary>
    /// Êý¾ÝÔ´Ìṩ
    /// </summary>
    public class PageData
    {
        private int _PageSize = 10;
        private int _PageIndex = 1;
        private int _PageCount = 0;
        private int _TotalCount = 0;
        private string _TableName;//±íÃû
        private string _QueryFieldName = "*";//±í×Ö¶ÎFieldStr
        private string _OrderStr = string.Empty; //ÅÅÐò_SortStr
        private string _QueryCondition = string.Empty;//²éѯµÄÌõ¼þ RowFilter
        private string _PrimaryKey = string.Empty;//Ö÷¼ü
        private bool _isQueryTotalCounts = true;//ÊÇ·ñ²éѯ×ܵļǼÌõÊý
        /// <summary>
        /// ÊÇ·ñ²éѯ×ܵļǼÌõÊý
        /// </summary>
        public bool IsQueryTotalCounts
        {
            get { return _isQueryTotalCounts; }
            set { _isQueryTotalCounts = value; }
        }
        /// <summary>
        /// ÏÔʾҳÊý
        /// </summary>
        public int PageSize
        {
            get
            {
                return _PageSize;
 
            }
            set
            {
                _PageSize = value;
            }
        }
        /// <summary>
        /// µ±Ç°Ò³
        /// </summary>
        public int PageIndex
        {
            get
            {
                return _PageIndex;
            }
            set
            {
                _PageIndex = value;
            }
        }
        /// <summary>
        /// ×ÜÒ³Êý
        /// </summary>
        public int PageCount
        {
            get
            {
                return _PageCount;
            }
        }
        /// <summary>
        /// ×ܼǼÊý
        /// </summary>
        public int TotalCount
        {
            get
            {
                return _TotalCount;
            }
        }
        /// <summary>
        /// ±íÃû£¬°üÀ¨ÊÓͼ
        /// </summary>
        public string TableName
        {
            get
            {
                return _TableName;
            }
            set
            {
                _TableName = value;
            }
        }
        /// <summary>
        /// ±í×Ö¶ÎFieldStr
        /// </summary>
        public string QueryFieldName
        {
            get
            {
                return _QueryFieldName;
            }
            set
            {
                _QueryFieldName = value;
            }
        }
        /// <summary>
        /// ÅÅÐò×Ö¶Î
        /// </summary>
        public string OrderStr
        {
            get
            {
                return _OrderStr;
            }
            set
            {
                _OrderStr = value;
            }
        }
        /// <summary>
        /// ²éѯÌõ¼þ
        /// </summary>
        public string QueryCondition
        {
            get
            {
                return _QueryCondition;
            }
            set
            {
                _QueryCondition = value;
            }
        }
        /// <summary>
        /// Ö÷¼ü
        /// </summary>
        public string PrimaryKey
        {
            get
            {
                return _PrimaryKey;
            }
            set
            {
                _PrimaryKey = value;
            }
        }
        /// <summary>
        /// ÎïÁϱàÂë
        /// </summary>
        public string CN_S_ITEM_CODE { get; set; }
        public string CN_S_ITEM_NAME { get; set; }
        public string CN_S_MODEL { get; set; }
 
        #region ·ÖÒ³×¢ÊÍ
        //public DataSet QueryDataTable()
        //{
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@Tables", SqlDbType.VarChar, 255),
        //            new SqlParameter("@PrimaryKey" , SqlDbType.VarChar , 255),    
        //            new SqlParameter("@Sort", SqlDbType.VarChar , 255 ),
        //            new SqlParameter("@CurrentPage", SqlDbType.Int),
        //            new SqlParameter("@PageSize", SqlDbType.Int),                                    
        //            new SqlParameter("@Fields", SqlDbType.VarChar, 255),
        //            new SqlParameter("@Filter", SqlDbType.VarChar,1000),
        //            new SqlParameter("@Group" ,SqlDbType.VarChar , 1000 )
        //            };
        //    parameters[0].Value = _TableName;
        //    parameters[1].Value = _PrimaryKey;
        //    parameters[2].Value = _OrderStr;
        //    parameters[3].Value = PageIndex;
        //    parameters[4].Value = PageSize;
        //    parameters[5].Value = _QueryFieldName;
        //    parameters[6].Value = _QueryCondition;
        //    parameters[7].Value = string.Empty;
        //    DataSet ds = DbHelperSQL.RunProcedure("SP_Pagination", parameters, "dd");
        //    if (_isQueryTotalCounts)
        //    {
        //        _TotalCount = GetTotalCount();
        //    }
        //    if (_TotalCount == 0)
        //    {
        //        _PageIndex = 0;
        //        _PageCount = 0;
        //    }
        //    else
        //    {
        //        _PageCount = _TotalCount % _PageSize == 0 ? _TotalCount / _PageSize : _TotalCount / _PageSize + 1;
        //        if (_PageIndex > _PageCount)
        //        {
        //            _PageIndex = _PageCount;
 
        //            parameters[4].Value = _PageSize;
 
        //            ds = QueryDataTable();
        //        }
        //    }
        //    return ds;
        //}
 
 
//ALTER    PROCEDURE SP_Pagination
///**//*
//***************************************************************
//** Ç§ÍòÊýÁ¿¼¶·ÖÒ³´æ´¢¹ý³Ì **
//***************************************************************
//²ÎÊý˵Ã÷:
//1.Tables :±íÃû³Æ,ÊÓͼ
//2.PrimaryKey :Ö÷¹Ø¼ü×Ö
//3.Sort :ÅÅÐòÓï¾ä£¬²»´øOrder By ±ÈÈ磺NewsID Desc,OrderRows Asc
//4.CurrentPage :µ±Ç°Ò³Âë
//5.PageSize :·ÖÒ³³ß´ç
//6.Filter :¹ýÂËÓï¾ä£¬²»´øWhere 
//7.Group :GroupÓï¾ä,²»´øGroup By
//Ч¹ûÑÝʾ£ºhttp://www.cn5135.com/_App/Enterprise/QueryResult.aspx
//***************************************************************/
//(
//@Tables varchar(2000),
//@PrimaryKey varchar(500),
//@Sort varchar(500) = NULL,
//@CurrentPage int = 1,
//@PageSize int = 10,
//@Fields varchar(2000) = '*',
//@Filter varchar(1000) = NULL,
//@Group varchar(1000) = NULL
//)
//AS
///**//*ĬÈÏÅÅÐò*/
//IF @Sort IS NULL OR @Sort = ''
//SET @Sort = @PrimaryKey
//DECLARE @SortTable varchar(1000)
//DECLARE @SortName varchar(1000)
//DECLARE @strSortColumn varchar(1000)
//DECLARE @operator char(2)
//DECLARE @type varchar(1000)
//DECLARE @prec int
///**//*É趨ÅÅÐòÓï¾ä.*/
//IF CHARINDEX('DESC',@Sort)>0
//BEGIN
//SET @strSortColumn = REPLACE(@Sort, 'DESC', '')
//SET @operator = '<='
//END
//ELSE
//BEGIN
//IF CHARINDEX('ASC', @Sort) = 0
//SET @strSortColumn = REPLACE(@Sort, 'ASC', '')
//SET @operator = '>='
//END
//IF CHARINDEX('.', @strSortColumn) > 0
//BEGIN
//SET @SortTable = SUBSTRING(@strSortColumn, 0, CHARINDEX('.',@strSortColumn))
//SET @SortName = SUBSTRING(@strSortColumn, CHARINDEX('.',@strSortColumn) + 1, LEN(@strSortColumn))
//END
//ELSE
//BEGIN
//SET @SortTable = @Tables
//SET @SortName = @strSortColumn
//END
//SELECT @type=t.name, @prec=c.prec
//FROM sysobjects o 
//JOIN syscolumns c on o.id=c.id
//JOIN systypes t on c.xusertype=t.xusertype
//WHERE o.name = @SortTable AND c.name = @SortName
//IF CHARINDEX('char', @type) > 0
//SET @type = @type + '(' + CAST(@prec AS varchar) + ')'
//DECLARE @strPageSize varchar(500)
//DECLARE @strStartRow varchar(500)
//DECLARE @strFilter varchar(1000)
//DECLARE @strSimpleFilter varchar(1000)
//DECLARE @strGroup varchar(1000)
///**//*ĬÈϵ±Ç°Ò³*/
//IF @CurrentPage < 1
//SET @CurrentPage = 1
///**//*ÉèÖ÷ÖÒ³²ÎÊý.*/
//SET @strPageSize = CAST(@PageSize AS varchar(500))
//SET @strStartRow = CAST(((@CurrentPage - 1)*@PageSize + 1) AS varchar(500))
///**//*ɸѡÒÔ¼°·Ö×éÓï¾ä.*/
//IF @Filter IS NOT NULL AND @Filter != ''
//BEGIN
//SET @strFilter = ' WHERE ' + @Filter + ' '
//SET @strSimpleFilter = ' AND ' + @Filter + ' '
//END
//ELSE
//BEGIN
//SET @strSimpleFilter = ''
//SET @strFilter = ''
//END
//IF @Group IS NOT NULL AND @Group != ''
//SET @strGroup = ' GROUP BY ' + @Group + ' '
//ELSE
//SET @strGroup = ''
///**//*Ö´ÐвéѯÓï¾ä*/
//EXEC(
//'
//DECLARE @SortColumn ' + @type + '
//SET ROWCOUNT ' + @strStartRow + '
//SELECT @SortColumn=' + @strSortColumn + ' FROM ' + @Tables + @strFilter + ' ' + @strGroup + ' ORDER BY ' + @Sort + '
//SET ROWCOUNT ' + @strPageSize + '
//SELECT ' + @Fields + ' FROM ' + @Tables + ' WHERE ' + @strSortColumn + @operator + ' @SortColumn ' + @strSimpleFilter + ' ' + @strGroup + ' ORDER BY ' + @Sort + '
//'
//)
        #endregion ·ÖÒ³×¢ÊÍ
 
 
        public List<AutoBomItemEntity> QueryDataTable()
        {
            List<AutoBomItemEntity> dt = new List<AutoBomItemEntity>();
            try
            {
                var userInfo = new AccountEntity();
                var ss = userInfo.Token;
                string str = WebApiManager.HttpWMS_Get("/api/Common/GetListItemByCode?itemCode=" + CN_S_ITEM_CODE + "&itemName=" + CN_S_ITEM_NAME + "&model=" + CN_S_MODEL + "&pageIndex=" + _PageIndex + "&pageSize=" + _PageSize);
                
                OperateResult results = JsonConvert.DeserializeObject<OperateResult>(str);
                
                if (results.Status == ResultStatus.Success)
                {
                    JObject obj = null;
 
                    obj = (JObject)results.Data;
 
                    if (_isQueryTotalCounts)
                    {
                        _TotalCount = Convert.ToInt32(obj["total"]);
                    }
                    if (_TotalCount == 0)
                    {
                        _PageIndex = 0;
                        _PageCount = 0;
                    }
                    else
                    {
                        _PageCount = _TotalCount % _PageSize == 0 ? _TotalCount / _PageSize : _TotalCount / _PageSize + 1;
                        if (_PageIndex > _PageCount)
                        {
                            _PageIndex = _PageCount;
                            dt = QueryDataTable();
                        }
                    }
                    dt = JsonConvert.DeserializeObject<List<AutoBomItemEntity>>(obj["rows"].ToString());
                    foreach (AutoBomItemEntity entity in dt)
                    {
                       entity.CN_S_MODEL= entity.CN_S_MODEL.Replace("'", "\"");
                    }
                    return dt;
                }
                else
                {
                    MessageBoxEx.Show(results.Msg);
                    return dt;
                }
            }
            catch(Exception ex)
            {
                MessageBoxEx.Show(ex.Message);
                return dt;
            }
        }
    }
}