From 557a1344dac283a90270a7f65465cf20d67fd4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Fri, 14 Oct 2022 17:59:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardManager/Form1.cs | 19 + HKCardManager/InstitutionalEntry.cs | 54 -- HKCardManager/InstitutionalEntry.resx | 120 ---- HKCardManager/Models/Global.cs | 5 + HKCardManager/UserPages/CarMangerPage.cs | 2 +- .../UserPages/InstitutionalEntryPage.cs | 1 + .../UserPages/PersonnelEntryPage.Designer.cs | 249 +++++++-- HKCardManager/UserPages/PersonnelEntryPage.cs | 528 ++++++++++++++++-- HKCardManager/UserPages/ReportFormPage.cs | 2 +- HKLib/Dto/ReportCountDto.cs | 8 +- 10 files changed, 726 insertions(+), 262 deletions(-) delete mode 100644 HKCardManager/InstitutionalEntry.cs delete mode 100644 HKCardManager/InstitutionalEntry.resx diff --git a/HKCardManager/Form1.cs b/HKCardManager/Form1.cs index 8181157..104472a 100644 --- a/HKCardManager/Form1.cs +++ b/HKCardManager/Form1.cs @@ -1,5 +1,6 @@ using HKLib.DB; using HKCardManager.UserPages; +using UHFHelper; namespace HKCardManager { @@ -12,6 +13,10 @@ namespace HKCardManager Task.Factory.StartNew(() => { DbContext.InitTable(); + var res = UHFCardHelper.GetInstance().OpenPort(); + if (res != null && res.Res) + MessageLogNotify.GetInstance.ShowError("制卡设备已连接!"); + else MessageLogNotify.GetInstance.ShowError($"制卡设备打开失败!{res?.ResMes}"); }); ShowPage(new PersonnelEntryPage()); this.SizeChanged += Form1_SizeChanged; @@ -102,6 +107,20 @@ namespace HKCardManager catch { } //清除过多的数据 + if (rtbox.Items.Count > 100) + { + int count = rtbox.Items.Count - 100; + List temp = new List(); + for (int i = 100; i < rtbox.Items.Count; i++) + { + if (rtbox.Items.Count >= i - 1) temp.Add(rtbox.Items[i]); + } + foreach (object obj in temp) + { + rtbox.Items.Remove(obj); + } + } + //rtbox.SelectedIndex = rtbox.Items.Count - 1; //if (rtbox.Items.Count > 100) //{ // int count = rtbox.Items.Count - 100; diff --git a/HKCardManager/InstitutionalEntry.cs b/HKCardManager/InstitutionalEntry.cs deleted file mode 100644 index 00e0393..0000000 --- a/HKCardManager/InstitutionalEntry.cs +++ /dev/null @@ -1,54 +0,0 @@ -锘縰sing BPA.Helper; -using HKLib.Logic; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace HKCardManager -{ - public partial class InstitutionalEntry : Form - { - public InstitutionalEntry() - { - InitializeComponent(); - } - - private void button1_Click(object sender, EventArgs e) - { - this.Close(); - } - - private void button2_Click(object sender, EventArgs e) - { - string name = textBox1.Text.Trim(); - if (string.IsNullOrEmpty(name)) - { - label2.Text = "鏈烘瀯鍚嶄笉鑳戒负绌"; - return; - } - Task.Factory.StartNew(() => - { - if (ServiceHandler.GetOrgList().FirstOrDefault(p => p.Name == name) != null) - { - this.Invoke(() => { label2.Text = "鏈烘瀯宸插瓨鍦"; }); - return; - } - if (ServiceHandler.AddOrg(textBox1.Text.Trim())) - { - this.Invoke(() => { this.Close(); }); - } - else - { - this.Invoke(() => { label2.Text = "娣诲姞澶辫触锛岃閲嶈瘯锛岃妫鏌ユ満鏋勬槸鍚﹀瓨鍦"; }); - } - }); - - } - } -} diff --git a/HKCardManager/InstitutionalEntry.resx b/HKCardManager/InstitutionalEntry.resx deleted file mode 100644 index 1af7de1..0000000 --- a/HKCardManager/InstitutionalEntry.resx +++ /dev/null @@ -1,120 +0,0 @@ -锘 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/HKCardManager/Models/Global.cs b/HKCardManager/Models/Global.cs index c828c89..d56d0e5 100644 --- a/HKCardManager/Models/Global.cs +++ b/HKCardManager/Models/Global.cs @@ -13,6 +13,11 @@ namespace HKCardManager /// public static List UserListDtos { get; set; } = new List(); + /// + /// 鍒嗛〉鏁版嵁琛 + /// + public static List PagUserListDtos { get; set; } = new List(); + /// /// 鏈烘瀯淇℃伅 /// diff --git a/HKCardManager/UserPages/CarMangerPage.cs b/HKCardManager/UserPages/CarMangerPage.cs index 8f18cb8..daa013a 100644 --- a/HKCardManager/UserPages/CarMangerPage.cs +++ b/HKCardManager/UserPages/CarMangerPage.cs @@ -196,7 +196,7 @@ namespace HKCardManager.UserPages } else { - MessageLogNotify.GetInstance.ShowError("璁惧鏈繛鎺"); + MessageLogNotify.GetInstance.ShowWarning("璁惧鏈繛鎺"); } } diff --git a/HKCardManager/UserPages/InstitutionalEntryPage.cs b/HKCardManager/UserPages/InstitutionalEntryPage.cs index 51ed60e..0b21213 100644 --- a/HKCardManager/UserPages/InstitutionalEntryPage.cs +++ b/HKCardManager/UserPages/InstitutionalEntryPage.cs @@ -31,6 +31,7 @@ namespace HKCardManager.UserPages if (string.IsNullOrEmpty(name)) { MessageLogNotify.GetInstance.ShowWarning("璇疯緭鍏ユ満鏋勫悕绉"); + return; } Task.Factory.StartNew(() => { diff --git a/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs b/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs index 185eb7a..72d6379 100644 --- a/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs +++ b/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs @@ -34,11 +34,10 @@ this.label4 = new System.Windows.Forms.Label(); this.comboBox2 = new System.Windows.Forms.ComboBox(); this.label3 = new System.Windows.Forms.Label(); - this.comboBox1 = new System.Windows.Forms.ComboBox(); - this.label2 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.鍚嶇О = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.鍗$姸鎬 = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -46,16 +45,35 @@ this.鎵嬫満鍙 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.鍗″彿 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.鍒犻櫎 = new System.Windows.Forms.DataGridViewButtonColumn(); + this.button_go = new System.Windows.Forms.Button(); + this.textBox_num = new System.Windows.Forms.TextBox(); + this.label12 = new System.Windows.Forms.Label(); + this.label13 = new System.Windows.Forms.Label(); + this.comboBox_num = new System.Windows.Forms.ComboBox(); + this.label10 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.comboBox_page = new System.Windows.Forms.ComboBox(); + this.label9 = new System.Windows.Forms.Label(); + this.label8 = new System.Windows.Forms.Label(); + this.label_end = new System.Windows.Forms.Label(); + this.label_down = new System.Windows.Forms.Label(); + this.label_up = new System.Windows.Forms.Label(); + this.label_first = new System.Windows.Forms.Label(); + this.label_count = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // button2 // - this.button2.Location = new System.Drawing.Point(844, 13); + this.button2.Location = new System.Drawing.Point(757, 13); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(90, 32); this.button2.TabIndex = 20; @@ -89,7 +107,7 @@ this.comboBox2.Items.AddRange(new object[] { "鐢", "濂"}); - this.comboBox2.Location = new System.Drawing.Point(736, 13); + this.comboBox2.Location = new System.Drawing.Point(579, 13); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(97, 29); this.comboBox2.TabIndex = 16; @@ -98,35 +116,12 @@ // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label3.Location = new System.Drawing.Point(656, 17); + this.label3.Location = new System.Drawing.Point(499, 17); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(90, 21); this.label3.TabIndex = 15; this.label3.Text = "閫夋嫨鏈烘瀯锛"; // - // comboBox1 - // - this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.comboBox1.FormattingEnabled = true; - this.comboBox1.Items.AddRange(new object[] { - "鐢", - "濂"}); - this.comboBox1.Location = new System.Drawing.Point(569, 13); - this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(61, 29); - this.comboBox1.TabIndex = 14; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label2.Location = new System.Drawing.Point(486, 17); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(90, 21); - this.label2.TabIndex = 13; - this.label2.Text = "閫夋嫨濮撳埆锛"; - // // textBox1 // this.textBox1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); @@ -154,7 +149,7 @@ // // splitContainer1.Panel1 // - this.splitContainer1.Panel1.Controls.Add(this.dataGridView1); + this.splitContainer1.Panel1.Controls.Add(this.splitContainer2); // // splitContainer1.Panel2 // @@ -163,14 +158,44 @@ this.splitContainer1.Panel2.Controls.Add(this.button2); this.splitContainer1.Panel2.Controls.Add(this.textBox1); this.splitContainer1.Panel2.Controls.Add(this.label4); - this.splitContainer1.Panel2.Controls.Add(this.comboBox1); - this.splitContainer1.Panel2.Controls.Add(this.label2); this.splitContainer1.Panel2.Controls.Add(this.label3); this.splitContainer1.Panel2.Controls.Add(this.label1); this.splitContainer1.Size = new System.Drawing.Size(947, 561); this.splitContainer1.SplitterDistance = 499; this.splitContainer1.TabIndex = 24; // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.Location = new System.Drawing.Point(0, 0); + this.splitContainer2.Name = "splitContainer2"; + this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.dataGridView1); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.button_go); + this.splitContainer2.Panel2.Controls.Add(this.textBox_num); + this.splitContainer2.Panel2.Controls.Add(this.label12); + this.splitContainer2.Panel2.Controls.Add(this.label13); + this.splitContainer2.Panel2.Controls.Add(this.comboBox_num); + this.splitContainer2.Panel2.Controls.Add(this.label10); + this.splitContainer2.Panel2.Controls.Add(this.label11); + this.splitContainer2.Panel2.Controls.Add(this.comboBox_page); + this.splitContainer2.Panel2.Controls.Add(this.label9); + this.splitContainer2.Panel2.Controls.Add(this.label8); + this.splitContainer2.Panel2.Controls.Add(this.label_end); + this.splitContainer2.Panel2.Controls.Add(this.label_down); + this.splitContainer2.Panel2.Controls.Add(this.label_up); + this.splitContainer2.Panel2.Controls.Add(this.label_first); + this.splitContainer2.Panel2.Controls.Add(this.label_count); + this.splitContainer2.Size = new System.Drawing.Size(947, 499); + this.splitContainer2.SplitterDistance = 459; + this.splitContainer2.TabIndex = 1; + // // dataGridView1 // this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.Control; @@ -187,7 +212,7 @@ this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowHeadersVisible = false; this.dataGridView1.RowTemplate.Height = 25; - this.dataGridView1.Size = new System.Drawing.Size(947, 499); + this.dataGridView1.Size = new System.Drawing.Size(947, 459); this.dataGridView1.TabIndex = 0; this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick); // @@ -244,6 +269,143 @@ this.鍒犻櫎.Text = "鍒犻櫎"; this.鍒犻櫎.UseColumnTextForButtonValue = true; // + // button_go + // + this.button_go.Location = new System.Drawing.Point(702, 7); + this.button_go.Name = "button_go"; + this.button_go.Size = new System.Drawing.Size(58, 23); + this.button_go.TabIndex = 14; + this.button_go.Text = "璺宠浆"; + this.button_go.UseVisualStyleBackColor = true; + // + // textBox_num + // + this.textBox_num.Location = new System.Drawing.Point(601, 6); + this.textBox_num.Name = "textBox_num"; + this.textBox_num.Size = new System.Drawing.Size(59, 23); + this.textBox_num.TabIndex = 13; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(663, 10); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(20, 17); + this.label12.TabIndex = 12; + this.label12.Text = "椤"; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(577, 10); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(20, 17); + this.label13.TabIndex = 11; + this.label13.Text = "绗"; + // + // comboBox_num + // + this.comboBox_num.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox_num.FormattingEnabled = true; + this.comboBox_num.Location = new System.Drawing.Point(470, 6); + this.comboBox_num.Name = "comboBox_num"; + this.comboBox_num.Size = new System.Drawing.Size(66, 25); + this.comboBox_num.TabIndex = 10; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(538, 10); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(20, 17); + this.label10.TabIndex = 9; + this.label10.Text = "鏉"; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(437, 10); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(32, 17); + this.label11.TabIndex = 8; + this.label11.Text = "姣忛〉"; + // + // comboBox_page + // + this.comboBox_page.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBox_page.FormattingEnabled = true; + this.comboBox_page.Location = new System.Drawing.Point(332, 6); + this.comboBox_page.Name = "comboBox_page"; + this.comboBox_page.Size = new System.Drawing.Size(61, 25); + this.comboBox_page.TabIndex = 7; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(397, 10); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(20, 17); + this.label9.TabIndex = 6; + this.label9.Text = "椤"; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(313, 10); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(20, 17); + this.label8.TabIndex = 5; + this.label8.Text = "绗"; + // + // label_end + // + this.label_end.AutoSize = true; + this.label_end.Location = new System.Drawing.Point(269, 10); + this.label_end.Name = "label_end"; + this.label_end.Size = new System.Drawing.Size(32, 17); + this.label_end.TabIndex = 4; + this.label_end.Text = "灏鹃〉"; + this.label_end.Click += new System.EventHandler(this.label_end_Click); + // + // label_down + // + this.label_down.AutoSize = true; + this.label_down.Location = new System.Drawing.Point(218, 10); + this.label_down.Name = "label_down"; + this.label_down.Size = new System.Drawing.Size(44, 17); + this.label_down.TabIndex = 3; + this.label_down.Text = "涓嬩竴椤"; + this.label_down.Click += new System.EventHandler(this.label_down_Click); + // + // label_up + // + this.label_up.AutoSize = true; + this.label_up.Location = new System.Drawing.Point(167, 10); + this.label_up.Name = "label_up"; + this.label_up.Size = new System.Drawing.Size(44, 17); + this.label_up.TabIndex = 2; + this.label_up.Text = "涓婁竴椤"; + this.label_up.Click += new System.EventHandler(this.label_up_Click); + // + // label_first + // + this.label_first.AutoSize = true; + this.label_first.Location = new System.Drawing.Point(128, 10); + this.label_first.Name = "label_first"; + this.label_first.Size = new System.Drawing.Size(32, 17); + this.label_first.TabIndex = 1; + this.label_first.Text = "棣栭〉"; + this.label_first.Click += new System.EventHandler(this.label_first_Click); + // + // label_count + // + this.label_count.AutoSize = true; + this.label_count.Location = new System.Drawing.Point(17, 10); + this.label_count.Name = "label_count"; + this.label_count.Size = new System.Drawing.Size(105, 17); + this.label_count.TabIndex = 0; + this.label_count.Text = "鎬0000鏉/0000椤"; + // // PersonnelEntryPage // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); @@ -256,6 +418,11 @@ this.splitContainer1.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel2.ResumeLayout(false); + this.splitContainer2.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); @@ -268,8 +435,6 @@ private Label label4; private ComboBox comboBox2; private Label label3; - private ComboBox comboBox1; - private Label label2; private TextBox textBox1; private Label label1; private SplitContainer splitContainer1; @@ -280,5 +445,21 @@ private DataGridViewTextBoxColumn 鎵嬫満鍙; private DataGridViewTextBoxColumn 鍗″彿; private DataGridViewButtonColumn 鍒犻櫎; + private SplitContainer splitContainer2; + private Label label_count; + private Button button_go; + private TextBox textBox_num; + private Label label12; + private Label label13; + private ComboBox comboBox_num; + private Label label10; + private Label label11; + private ComboBox comboBox_page; + private Label label9; + private Label label8; + private Label label_end; + private Label label_down; + private Label label_up; + private Label label_first; } } diff --git a/HKCardManager/UserPages/PersonnelEntryPage.cs b/HKCardManager/UserPages/PersonnelEntryPage.cs index 3b4746b..1235bba 100644 --- a/HKCardManager/UserPages/PersonnelEntryPage.cs +++ b/HKCardManager/UserPages/PersonnelEntryPage.cs @@ -14,6 +14,8 @@ using System.Windows.Forms; namespace HKCardManager.UserPages { + //瀹氫箟濮旀墭 + public delegate void BindHandle(object sender, EventArgs e); public partial class PersonnelEntryPage : UserControl { //List OrgList = new List(); @@ -34,10 +36,10 @@ namespace HKCardManager.UserPages dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; #endregion + this.Load += PersonnelEntryPage_Load; - this.SizeChanged += PersonnelEntryPage_SizeChanged; dataGridView1.AutoGenerateColumns = false; - comboBox1.SelectedIndex = 0; + //comboBox1.SelectedIndex = 0; orgTables = ServiceHandler.GetOrgList(); Global.OrgList.Clear(); orgTables?.ForEach(item => @@ -45,54 +47,65 @@ namespace HKCardManager.UserPages Global.OrgList.Add(item.Name); }); comboBox2.DataSource = Global.OrgList; - Task.Factory.StartNew(() => - { - var res = HKLibHelper.GetUserList(""); - Global.UserListDtos.Clear(); - res?.ToList()?.ForEach(item => - { - string status = ""; - string cardNum = ""; - if (item.Cards != null && item.Cards.Count > 0) - { - cardNum = item.Cards.ElementAt(0).CardNum; - status = ((CarStatus)item.Cards.ElementAt(0).State).ToString(); - } - Global.UserListDtos.Add(new UserInfoModel() - { - UserName = item.Name, - Phone = item.Phone, - OrgName = item.OrgInfo?.Count > 0 ? item.OrgInfo.ElementAt(0).Name : "", - CardNum = cardNum, - State = status - }); - }); - //TestData(); - this.Invoke(() => { dataGridView1.DataSource = null; dataGridView1.DataSource = Global.UserListDtos; }); - }); + Task.Factory.StartNew(() => { GetUser(); }); } - private void TestData() + private void GetUser() { - for (int i = 0; i < 10; i++) + var res = HKLibHelper.GetUserList(""); + Global.UserListDtos.Clear(); + Global.PagUserListDtos.Clear(); + res?.ToList()?.ForEach(item => { + string status = ""; + string cardNum = ""; + if (item.Cards != null && item.Cards.Count > 0) + { + cardNum = item.Cards.ElementAt(0).CardNum; + status = ((CarStatus)item.Cards.ElementAt(0).State).ToString(); + } Global.UserListDtos.Add(new UserInfoModel() { - CardNum = Guid.NewGuid().ToString(), - State = CarStatus.姝e父.ToString(), - OrgName = "鐮斿彂閮", - Phone = "13545893363", - UserName = $"寮爗i}" + UserName = item.Name, + Phone = item.Phone, + OrgName = item.OrgInfo?.Count > 0 ? item.OrgInfo.ElementAt(0).Name : "", + CardNum = cardNum, + State = status }); + }); + + for (int i = (currentPageIndex - 1) * pageSize; i < Global.UserListDtos.Count; i++) + { + if (Global.PagUserListDtos.Count < pageSize) + Global.PagUserListDtos.Add(Global.UserListDtos.ElementAt(i)); + else + break; } + + + this.Invoke(() => + { + //dataGridView1.DataSource = null; dataGridView1.DataSource = Global.UserListDtos; + dataGridView1.DataSource = null; dataGridView1.DataSource = Global.PagUserListDtos; + totalCount = Global.UserListDtos.Count; + comboBoxNum(); + showDataGirdView(); + }); + } - private void PersonnelEntryPage_SizeChanged(object? sender, EventArgs e) + private void GetPag() { - //panel1.Left = (this.Width - panel1.Width) / 2; - //panel1.Top = (this.Height - panel1.Height) / 2; - var tt1 = dataGridView1.Size; - var tt = this.Size; + Global.PagUserListDtos.Clear(); + for (int i = (currentPageIndex - 1) * pageSize; i < Global.UserListDtos.Count; i++) + { + if (Global.PagUserListDtos.Count < pageSize) + Global.PagUserListDtos.Add(Global.UserListDtos.ElementAt(i)); + else + break; + } + dataGridView1.DataSource = null; + dataGridView1.DataSource = Global.PagUserListDtos; } private void button2_Click(object sender, EventArgs e) @@ -122,16 +135,11 @@ namespace HKCardManager.UserPages this.Invoke(() => { button2.Enabled = false; }); if (HKLibHelper.AddUser(userDto)) { - Global.UserListDtos.Add(new UserInfoModel() - { - OrgName = OrgName, - Phone = userDto.Phone, - UserName = userDto.Name - }); + GetUser(); this.Invoke(() => { - dataGridView1.DataSource = null; - dataGridView1.DataSource = Global.UserListDtos; + textBox1.Text = string.Empty; + textBox2.Text = string.Empty; }); MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞鎴愬姛"); } @@ -147,8 +155,432 @@ namespace HKCardManager.UserPages int index = dataGridView1.CurrentRow.Index; if (index <= dataGridView1.Rows.Count - 1 && dataGridView1.CurrentCell.Value.ToString() == "鍒犻櫎") { - MessageLogNotify.GetInstance.Show($"鐢ㄦ埛鍚嶇О锛歿dataGridView1.Rows[index].Cells[0].Value }"); + var res = dataGridView1.Rows[index].Cells[0].Value?.ToString(); + if (string.IsNullOrEmpty(res)) + { + MessageLogNotify.GetInstance.ShowError("鐢ㄦ埛鍚嶆棤鏁"); + return; + } + Task.Factory.StartNew(() => + { + if (HKLibHelper.DisableUser(res)) + { + GetUser(); + MessageLogNotify.GetInstance.Show($"鐢ㄦ埛锛氥恵res}銆 鍒犻櫎鎴愬姛"); + } + else + MessageLogNotify.GetInstance.ShowError($"鐢ㄦ埛锛氥恵res}銆 鍒犻櫎澶辫触"); + }); + } + } + + #region datagridView 鍒嗛〉鏄剧ず + + #region 鍙橀噺瀹氫箟 + private int totalCount = 0;//鎬绘暟鎹釜鏁 + private int pageCount = 0;//鎬婚〉鏁 + private int currentPageIndex = 1;//褰撳墠椤电储寮 + private int pageSize = 10;//姣忛〉鍒嗛〉澶у皬 + private int remainder = 0;//鏈鍚庝竴椤靛墿浣欎釜鏁 + private bool isAutoUpdateLabelTip = true;//鑾峰彇鎴栬缃槸鍚﹁嚜鍔ㄦ洿鏂板垎椤垫爣绛惧唴瀹规彁绀猴紝榛樿涓簍rue + private string sqlAddress = "";//"Data Source=192.168.100.144;Initial Catalog=test;User ID=sa;Password=123456;";//DataGridViewd瑕佺粦瀹氱殑琛ㄥ悕 + private string tableName = "";//"DataSource";//DataGridViewd瑕佺粦瀹氱殑琛ㄥ悕 + private string strWhere = ""; + private DataSet dsAll = null;//鎬绘暟鎹簮 + #endregion + public event EventHandler CellClick;//datagridview cellclick 瑙﹀彂浜嬩欢 + + #region 澶栬皟鍑芥暟 + /// + /// 缁戝畾鏁版嵁 + /// + public void dataBand() + { + comboBoxNum(); + showDataGirdView(); + } + ///// + ///// 杩斿洖褰撳墠椤甸潰鏁版嵁 + ///// + ///// + //public DataGridView outputDGV() + //{ + // return dataGridView_show; + //} + #endregion + + + private void PersonnelEntryPage_Load(object? sender, EventArgs e) + { + + } + + + //鍔犺浇浜嬩欢 + //private void pager1_Load(object sender, EventArgs e) + //{ + // comboBoxNum(); + // showDataGirdView(); + //} + #region 鍒嗛〉鎿嶄綔 + //棣栭〉 + private void label_first_Click(object sender, EventArgs e) + { + currentPageIndex = 1; + showDataGirdView(); + } + //鏈〉 + private void label_end_Click(object sender, EventArgs e) + { + currentPageIndex = pageCount; + showDataGirdView(); + } + //涓婁竴椤 + private void label_up_Click(object sender, EventArgs e) + { + if (currentPageIndex <= pageCount && currentPageIndex != 1) + { + currentPageIndex--; + showDataGirdView(); + } + if (isAutoUpdateLabelTip) + { + updateSplitPageLabelTip(); + } + } + //涓嬩竴椤 + private void label_down_Click(object sender, EventArgs e) + { + if (currentPageIndex < pageCount && currentPageIndex != pageCount) + { + currentPageIndex++; + showDataGirdView(); + } + if (isAutoUpdateLabelTip) + { + updateSplitPageLabelTip(); + } + } + //绗嚑椤 + private void comboBox_page_DropDownClosed(object sender, EventArgs e) + { + currentPageIndex = int.Parse(comboBox_page.SelectedItem.ToString()); + updateSplitPageLabelTip(); + showDataGirdView(); + } + //姣忛〉鏉℃暟 + private void comboBox_num_DropDownClosed(object sender, EventArgs e) + { + pageSize = int.Parse(comboBox_num.SelectedItem.ToString()); + //鍒濆鍖栭〉鐮佷负1 + currentPageIndex = 1; + updateSplitPageLabelTip(); + showDataGirdView(); + } + //璺宠浆鎸囧畾椤 + private void button_go_Click(object sender, EventArgs e) + { + try + { + currentPageIndex = int.Parse(textBox_num.Text); + } + catch + { + currentPageIndex = 1; + } + currentPageIndex = currentPageIndex > pageCount ? pageCount : currentPageIndex; + updateSplitPageLabelTip(); + showDataGirdView(); + } + //淇敼鏄剧ず鏁版嵁 + public void updateSplitPageLabelTip() + { + pagingShow(); + comboBoxPage(); + comboBoxNum(); + } + //鍒ゆ柇鏄剧ず鐘剁姸鍐 + private void pagingShow() + { + //鍏卞灏戦〉 + pageCount = totalCount / pageSize; + remainder = totalCount % pageSize; + pageCount = remainder == 0 ? pageCount : pageCount + 1; + if (pageCount <= 1) + { + label_first.Enabled = false; + label_end.Enabled = false; + label_up.Enabled = false; + label_down.Enabled = false; + comboBox_page.Enabled = false; + textBox_num.Enabled = false; + button_go.Enabled = false; } + else + { + label_first.Enabled = true; + label_end.Enabled = true; + label_up.Enabled = true; + label_down.Enabled = true; + comboBox_page.Enabled = true; + textBox_num.Enabled = true; + button_go.Enabled = true; + } + //棣栭〉鍏抽棴棣栭〉锛屼笂涓椤 + if (currentPageIndex == 1) + { + label_first.Enabled = false; + label_up.Enabled = false; + } + else + { + label_first.Enabled = true; + label_up.Enabled = true; + } + //鏈〉鍏抽棴鏈〉锛屼笅涓椤 + if (currentPageIndex == pageCount) + { + label_end.Enabled = false; + label_down.Enabled = false; + } + else + { + label_end.Enabled = true; + label_down.Enabled = true; + } + //鍏卞灏戞潯 + label_count.Text = "鎬" + totalCount + "鏉/" + pageCount + "椤"; + textBox_num.Text = currentPageIndex.ToString(); } + //澶氬皯椤 + private void comboBoxPage() + { + comboBox_page.Items.Clear(); + for (int i = 1; i <= pageCount; i++) + { + comboBox_page.Items.Add(i.ToString()); + } + comboBox_page.SelectedIndex = -1; + //褰撲负涓椤碉紝灏辫缃缃负0 + comboBox_page.SelectedIndex = pageCount == 1 ? 0 : currentPageIndex - 1; + } + //姣忛〉澶氬皯鏉 + private void comboBoxNum() + { + comboBox_num.Items.Clear(); + comboBox_num.Items.Add("10"); + comboBox_num.Items.Add("20"); + comboBox_num.Items.Add("50"); + comboBox_num.Items.Add("100"); + comboBox_num.Items.Add("500"); + comboBox_num.Items.Add("1000"); + comboBox_num.SelectedIndex = 0; + int i = 0; + switch (pageSize) + { + case 10: + i = 0; + break; + case 20: + i = 1; + break; + case 50: + i = 2; + break; + case 100: + i = 3; + break; + case 500: + i = 4; + break; + case 1000: + i = 5; + break; + default: + break; + } + comboBox_num.SelectedIndex = i; + } + //鑾峰彇鏁版嵁 + #endregion + #region 鏁版嵁澶勭悊 + //缁戝畾鏁版嵁 + private void showDataGirdView() + { + //DataTable dt = new DataTable(); + //if (dsAll != null) + //{ + // dt = GetDsAll();//鑾峰彇浼犲叆鏁版嵁 + //} + //else + //{ + // dt = GetTable();//鑾峰彇鏁版嵁搴撴暟鎹 + //} + //try + //{ + // //缁戝畾鍓嶅彴鎺т欢 + // totalCount = int.Parse(dt.Rows[0]["total"].ToString()); + //} + //catch + //{ + // totalCount = 1; + //} + GetPag(); + updateSplitPageLabelTip(); + //缁戝畾鏁版嵁 + //dataGridView_show.DataSource = dt; + //dataGridView_show.AllowUserToAddRows = false; + } + /// + /// 鑾峰彇鏁版嵁搴撳垎椤垫煡璇 + /// + /// + /// + //private DataTable GetTable(string sql = "") + //{ + + + // DataTable dt = new DataTable(); + // try + // { + // MySqlConnection Connection = new MySqlConnection(sqlAddress); + // Connection.Open(); + // //鍒嗛〉鏌ヨ + // if (sql == "") + // { + // sql = " ,(SELECT COUNT(1) FROM " + tableName + ") as total "; + // sql = "SELECT TOP " + pageSize + " * " + sql + " FROM " + tableName + " WHERE ID NOT IN(SELECT TOP " + ((currentPageIndex - 1) * pageSize) + " ID FROM " + tableName + ")"; + // } + + // MySqlDataAdapter adpater = new MySqlDataAdapter(sql, Connection); + // DataSet ds = new DataSet(); + // adpater.Fill(ds); + // adpater.Fill(dt); + // Connection.Close(); + // } + // catch + // { + // label_count.Text = "鏃犳暟鎹"; + // } + // return dt; + //} + + /// + /// 鑾峰彇鏁版嵁婧愬垎椤垫煡璇 + /// + /// + //private DataTable GetDsAll(string sql = "") + //{ + // DataTable dt = new DataTable(); + // try + // { + // dt = DataSetHelper.SplitDataSet(dsAll, pageSize, currentPageIndex).Tables[0]; + // //娣诲姞涓鍒楄繑鍥炴绘暟鈥榯otal鈥 + // int count = dsAll.Tables[0].Rows.Count; + // dt.Columns.Add("total", typeof(int)); + // foreach (DataRow dr in dt.Rows) + // { + // dr["total"] = count; + // } + // } + // catch + // { + // label_count.Text = "鏃犳暟鎹"; + // } + // return dt; + //} + #region DataSet鍒嗛〉鏌ヨ + public class DataSetHelper + { + public static DataSet SplitDataSet(DataSet ds, int pageSize, int pageIndex) + { + DataSet vds = new DataSet(); + vds = ds.Clone(); + if (pageIndex < 1) pageIndex = 1;//濡傛灉灏忎簬1锛屽彇绗竴椤 + //if ((ds.Tables[0].Rows.Count + pageSize) <= (pageSize * pageIndex)) pageIndex = 1; + int fromIndex = pageSize * (pageIndex - 1);//寮濮嬭 + int toIndex = pageSize * pageIndex - 1; //缁撴潫琛 + for (int i = fromIndex; i <= toIndex; i++) + { + if (i >= (ds.Tables[0].Rows.Count)) //鍒拌揪杩欎竴琛岋紝閫鍑 + break; + vds.Tables[0].ImportRow(ds.Tables[0].Rows[i]); + } + ds.Dispose(); + return vds; + } + /// + /// 鏍规嵁绱㈠紩鍜宲agesize杩斿洖璁板綍 + /// + /// 璁板綍闆 DataTable + /// 褰撳墠椤 + /// 涓椤电殑璁板綍鏁 + /// + public static DataTable SplitDataTable(DataTable dt, int PageIndex, int PageSize) + { + if (dt == null) + { + return null; + } + if (PageIndex == 0) + return dt; + DataTable newdt = dt.Clone(); + //newdt.Clear(); + int rowbegin = (PageIndex - 1) * PageSize; + int rowend = PageIndex * PageSize; + + + if (rowbegin >= dt.Rows.Count) + return newdt; + + + if (rowend > dt.Rows.Count) + rowend = dt.Rows.Count; + for (int i = rowbegin; i <= rowend - 1; i++) + { + DataRow newdr = newdt.NewRow(); + DataRow dr = dt.Rows[i]; + foreach (DataColumn column in dt.Columns) + { + newdr[column.ColumnName] = dr[column.ColumnName]; + } + newdt.Rows.Add(newdr); + } + return newdt; + } + + + public static DataTable ToDataTable(DataRow[] rows) + { + if (rows == null || rows.Length == 0) + { + return null; + } + DataTable tmp = rows[0].Table.Clone(); // 澶嶅埗DataRow鐨勮〃缁撴瀯 + foreach (DataRow row in rows) + { + tmp.Rows.Add(row.ItemArray); // 灏咲ataRow娣诲姞鍒癉ataTable涓 + } + return tmp; + } + } + + private void dataGridView_show_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (this.CellClick != null) + { + //this.CellClick(this.dataGridView_show, new EventArgs()); + } + } + + #endregion + + #endregion + + + + #endregion + + } } diff --git a/HKCardManager/UserPages/ReportFormPage.cs b/HKCardManager/UserPages/ReportFormPage.cs index 48c89d5..2bf1f9c 100644 --- a/HKCardManager/UserPages/ReportFormPage.cs +++ b/HKCardManager/UserPages/ReportFormPage.cs @@ -131,7 +131,7 @@ namespace HKCardManager.UserPages { MessageLogNotify.GetInstance.ShowError("鏌ヨ澶辫触锛岃杈撳叆姝g‘鐨勬椂闂存"); } - this.Invoke(() => { button1.Enabled = false; }); + this.Invoke(() => { button1.Enabled = true; }); }); } diff --git a/HKLib/Dto/ReportCountDto.cs b/HKLib/Dto/ReportCountDto.cs index 880f234..7afc818 100644 --- a/HKLib/Dto/ReportCountDto.cs +++ b/HKLib/Dto/ReportCountDto.cs @@ -29,21 +29,21 @@ namespace HKLib.Dto /// /// 鏃 /// - public decimal AMCount { get; set; } + public int AMCount { get; set; } /// /// 涓 /// - public decimal PMCount { get; set; } + public int PMCount { get; set; } /// /// 鏅 /// - public decimal ATCount { get; set; } + public int ATCount { get; set; } /// /// 鎬昏 /// - public decimal TotalCount { get; set; } + public int TotalCount { get; set; } } } From a24fbbc689cea328b4c88c4d36d0f6e0005fffa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Sat, 15 Oct 2022 10:43:55 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardManager/Form1.Designer.cs | 59 ++- HKCardManager/Form1.cs | 98 ++--- HKCardManager/Form1.resx | 6 + HKCardManager/Servers/MessageLogNotify.cs | 18 +- .../UserPages/AdvertisingSetPage.Designer.cs | 3 +- .../UserPages/PersonnelEntryPage.Designer.cs | 4 - HKCardManager/UserPages/PersonnelEntryPage.cs | 357 ++++-------------- 7 files changed, 168 insertions(+), 377 deletions(-) diff --git a/HKCardManager/Form1.Designer.cs b/HKCardManager/Form1.Designer.cs index 02a1c9e..b2a1116 100644 --- a/HKCardManager/Form1.Designer.cs +++ b/HKCardManager/Form1.Designer.cs @@ -28,6 +28,8 @@ /// private void InitializeComponent() { + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.pictureBox11 = new System.Windows.Forms.PictureBox(); @@ -59,7 +61,9 @@ this.button1 = new System.Windows.Forms.Button(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.panel1 = new System.Windows.Forms.Panel(); - this.listBox1 = new System.Windows.Forms.ListBox(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.鍥炬爣 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.娑堟伅鏂囨湰 = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -84,6 +88,7 @@ this.splitContainer2.Panel1.SuspendLayout(); this.splitContainer2.Panel2.SuspendLayout(); this.splitContainer2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // splitContainer1 @@ -490,7 +495,7 @@ // // splitContainer2.Panel2 // - this.splitContainer2.Panel2.Controls.Add(this.listBox1); + this.splitContainer2.Panel2.Controls.Add(this.dataGridView1); this.splitContainer2.Size = new System.Drawing.Size(954, 717); this.splitContainer2.SplitterDistance = 539; this.splitContainer2.TabIndex = 0; @@ -507,17 +512,40 @@ this.panel1.Size = new System.Drawing.Size(954, 539); this.panel1.TabIndex = 1; // - // listBox1 - // - this.listBox1.BackColor = System.Drawing.SystemColors.Control; - this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.listBox1.FormattingEnabled = true; - this.listBox1.ItemHeight = 17; - this.listBox1.Location = new System.Drawing.Point(0, 0); - this.listBox1.Margin = new System.Windows.Forms.Padding(3, 10, 3, 3); - this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(954, 174); - this.listBox1.TabIndex = 0; + // dataGridView1 + // + this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.Control; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.ColumnHeadersVisible = false; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.鍥炬爣, + this.娑堟伅鏂囨湰}); + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView1.Location = new System.Drawing.Point(0, 0); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None; + this.dataGridView1.RowHeadersVisible = false; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(954, 174); + this.dataGridView1.TabIndex = 1; + // + // 鍥炬爣 + // + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.TopCenter; + this.鍥炬爣.DefaultCellStyle = dataGridViewCellStyle1; + this.鍥炬爣.HeaderText = "鍥炬爣"; + this.鍥炬爣.Name = "鍥炬爣"; + this.鍥炬爣.ReadOnly = true; + this.鍥炬爣.Width = 30; + // + // 娑堟伅鏂囨湰 + // + this.娑堟伅鏂囨湰.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.娑堟伅鏂囨湰.DefaultCellStyle = dataGridViewCellStyle2; + this.娑堟伅鏂囨湰.HeaderText = "娑堟伅鏂囨湰"; + this.娑堟伅鏂囨湰.Name = "娑堟伅鏂囨湰"; + this.娑堟伅鏂囨湰.ReadOnly = true; // // Form1 // @@ -552,6 +580,7 @@ this.splitContainer2.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); this.splitContainer2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); } @@ -573,7 +602,6 @@ private GroupBox groupBox1; private Button button3; private Button button2; - private ListBox listBox1; private Panel panel1; private SplitContainer splitContainer2; private PictureBox pictureBox1; @@ -589,5 +617,8 @@ private GroupBox groupBox5; private PictureBox pictureBox11; private Button button8; + private DataGridView dataGridView1; + private DataGridViewTextBoxColumn 鍥炬爣; + private DataGridViewTextBoxColumn 娑堟伅鏂囨湰; } } \ No newline at end of file diff --git a/HKCardManager/Form1.cs b/HKCardManager/Form1.cs index 104472a..b7130b4 100644 --- a/HKCardManager/Form1.cs +++ b/HKCardManager/Form1.cs @@ -10,6 +10,7 @@ namespace HKCardManager { InitializeComponent(); splitContainer1.SplitterDistance = 240; + DataGridViewInit(); Task.Factory.StartNew(() => { DbContext.InitTable(); @@ -21,12 +22,36 @@ namespace HKCardManager ShowPage(new PersonnelEntryPage()); this.SizeChanged += Form1_SizeChanged; this.button1.SizeChanged += Button1_SizeChanged; - MessageLogNotify.GetInstance.Info = new Action((s, br) => + MessageLogNotify.GetInstance.Info = new Action((s, br) => { - this.Invoke(() => { AddListToListBox(listBox1, s, br, true); }); + this.Invoke(() => + { + dataGridView1.Rows.Insert(0, new string[] { "", $"{DateTime.Now.ToString("HH:mm:ss")} {s}" }); + dataGridView1.Rows[0].DefaultCellStyle.ForeColor = br; + dataGridView1.Rows[0].DefaultCellStyle.Padding = new Padding(0, 0, 0, 10); + }); }); } + private void DataGridViewInit() + { + dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; + dataGridView1.AutoGenerateColumns = false;//禁止自动添加列 + dataGridView1.AllowUserToResizeColumns = false;//是否可以调整列的大小 + dataGridView1.AllowUserToResizeRows = false;//是否可以调整行的大小 + dataGridView1.BorderStyle = BorderStyle.None;//DataGridView边框样式 + dataGridView1.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; + dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; + dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None; + dataGridView1.SelectionChanged += DataGridView1_SelectionChanged; + + } + + private void DataGridView1_SelectionChanged(object? sender, EventArgs e) + { + dataGridView1.ClearSelection();//禁止选择行 + } + private void Write(string msg) { //bool条件默认为配置文件里面定义,可以自定义任何保存数据条件 @@ -41,7 +66,6 @@ namespace HKCardManager // sw.Close(); // sw.Dispose(); //} - } private void AddListToListBox(ListBox rtbox, string text, Brush foreColor, bool addTime = true) @@ -140,10 +164,6 @@ namespace HKCardManager //rtbox.SelectedIndex = rtbox.Items.Count - 1; } - - - - private void Button1_SizeChanged(object? sender, EventArgs e) { groupBox1.Width = button1.Width; @@ -182,8 +202,6 @@ namespace HKCardManager button12.Width = (groupBox4.Width - 20); } - - UserControl tempUserControl; private void Form1_SizeChanged(object? sender, EventArgs e) { @@ -212,68 +230,6 @@ namespace HKCardManager } } - //private void 人员录入ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // new PersonnelEntry().ShowDialog(); - //} - - //private void 机构录入ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // new InstitutionalEntry().ShowDialog(); - //} - - //private void 发卡ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // new Hairpin().ShowDialog(); - //} - - //private void 销户ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // Cancellation cancellation = new Cancellation(); - // cancellation.Text = "销户"; - // cancellation.ShowDialog(); - //} - - //private void 挂失ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // Cancellation cancellation = new Cancellation(); - // cancellation.Text = "挂失"; - // cancellation.ShowDialog(); - //} - - //private void 解挂ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // Cancellation cancellation = new Cancellation(); - // cancellation.Text = "解挂"; - // cancellation.ShowDialog(); - //} - - //private void 月餐段汇总表ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // DailyConsumptionTable dailyConsumptionTable = new DailyConsumptionTable(); - // dailyConsumptionTable.Text = "月餐段汇总表"; - // dailyConsumptionTable.ShowDialog(); - //} - - //private void 计次就餐天消费表ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // DailyConsumptionTable dailyConsumptionTable = new DailyConsumptionTable(); - // dailyConsumptionTable.Text = "计次就餐天消费表"; - // dailyConsumptionTable.ShowDialog(); - //} - - //private void 计次就餐消费明细表ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // DailyConsumptionTable dailyConsumptionTable = new DailyConsumptionTable(); - // dailyConsumptionTable.Text = "计次就餐消费明细表"; - // dailyConsumptionTable.ShowDialog(); - //} - - //private void 餐段设置ToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // new MealSegmentSet().ShowDialog(); - //} - //人员录入 private void button2_Click(object sender, EventArgs e) { diff --git a/HKCardManager/Form1.resx b/HKCardManager/Form1.resx index f298a7b..1338f61 100644 --- a/HKCardManager/Form1.resx +++ b/HKCardManager/Form1.resx @@ -57,4 +57,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + \ No newline at end of file diff --git a/HKCardManager/Servers/MessageLogNotify.cs b/HKCardManager/Servers/MessageLogNotify.cs index e5fc7d5..9293b12 100644 --- a/HKCardManager/Servers/MessageLogNotify.cs +++ b/HKCardManager/Servers/MessageLogNotify.cs @@ -13,16 +13,16 @@ namespace HKCardManager public static MessageLogNotify GetInstance => _Instance ?? (_Instance = new MessageLogNotify()); private MessageLogNotify() { } - public Action Info { get; set; } + public Action Info { get; set; } /// /// 甯歌鏃ュ織鏄剧ず /// /// 鏃ュ織娑堟伅 /// 鏃ュ織鏄剧ず棰滆壊 - public void Show(string info, Brush brush = null) + public void Show(string info, Color brush = default) { - Info?.Invoke($"娑堟伅锛歿info}", brush == null ? Brushes.Green : brush); + Info?.Invoke($"娑堟伅锛歿info}", brush == default ? Color.Green : brush); } /// @@ -30,9 +30,9 @@ namespace HKCardManager /// /// 鏃ュ織淇℃伅 /// 鏃ュ織鏄剧ず棰滆壊 - public void ShowEx(string info, Brush brush = null) + public void ShowEx(string info, Color brush = default) { - Info?.Invoke($"寮傚父锛歿info}", brush == null ? Brushes.Red : brush); + Info?.Invoke($"寮傚父锛歿info}", brush == default ? Color.Red : brush); } /// @@ -40,9 +40,9 @@ namespace HKCardManager /// /// 鏃ュ織淇℃伅 /// 鏃ュ織鏄剧ず棰滆壊 - public void ShowError(string info, Brush brush = null) + public void ShowError(string info, Color brush = default) { - Info?.Invoke($"閿欒锛歿info}", brush == null ? Brushes.Red : brush); + Info?.Invoke($"閿欒锛歿info}", brush == default ? Color.Red : brush); } /// @@ -50,9 +50,9 @@ namespace HKCardManager /// /// 鏃ュ織淇℃伅 /// 鏃ュ織鏄剧ず棰滆壊 - public void ShowWarning(string info, Brush brush = null) + public void ShowWarning(string info, Color brush = default) { - Info?.Invoke($"璀﹀憡锛歿info}", brush == null ? Brushes.Olive : brush); + Info?.Invoke($"璀﹀憡锛歿info}", brush == default ? Color.Olive : brush); } } diff --git a/HKCardManager/UserPages/AdvertisingSetPage.Designer.cs b/HKCardManager/UserPages/AdvertisingSetPage.Designer.cs index 9ad0506..c0950ce 100644 --- a/HKCardManager/UserPages/AdvertisingSetPage.Designer.cs +++ b/HKCardManager/UserPages/AdvertisingSetPage.Designer.cs @@ -41,8 +41,7 @@ this.webView21.Location = new System.Drawing.Point(0, 0); this.webView21.Name = "webView21"; this.webView21.Size = new System.Drawing.Size(490, 322); - this.webView21.Source = new System.Uri(" https://witt.black-pa.com/gateAdmin?storeId=0c32b2e2-0dc9-4941-b73d-3dc91f7268ab" + - "", System.UriKind.Absolute); + this.webView21.Source = new System.Uri("http://192.168.1.75:8000/gateAdmin?storeId=6d6301d8-7bec-431c-8009-9ef1a56f3fbc", System.UriKind.Absolute); this.webView21.TabIndex = 0; this.webView21.ZoomFactor = 1D; // diff --git a/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs b/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs index 72d6379..22fa120 100644 --- a/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs +++ b/HKCardManager/UserPages/PersonnelEntryPage.Designer.cs @@ -365,7 +365,6 @@ this.label_end.Size = new System.Drawing.Size(32, 17); this.label_end.TabIndex = 4; this.label_end.Text = "灏鹃〉"; - this.label_end.Click += new System.EventHandler(this.label_end_Click); // // label_down // @@ -375,7 +374,6 @@ this.label_down.Size = new System.Drawing.Size(44, 17); this.label_down.TabIndex = 3; this.label_down.Text = "涓嬩竴椤"; - this.label_down.Click += new System.EventHandler(this.label_down_Click); // // label_up // @@ -385,7 +383,6 @@ this.label_up.Size = new System.Drawing.Size(44, 17); this.label_up.TabIndex = 2; this.label_up.Text = "涓婁竴椤"; - this.label_up.Click += new System.EventHandler(this.label_up_Click); // // label_first // @@ -395,7 +392,6 @@ this.label_first.Size = new System.Drawing.Size(32, 17); this.label_first.TabIndex = 1; this.label_first.Text = "棣栭〉"; - this.label_first.Click += new System.EventHandler(this.label_first_Click); // // label_count // diff --git a/HKCardManager/UserPages/PersonnelEntryPage.cs b/HKCardManager/UserPages/PersonnelEntryPage.cs index 1235bba..730e188 100644 --- a/HKCardManager/UserPages/PersonnelEntryPage.cs +++ b/HKCardManager/UserPages/PersonnelEntryPage.cs @@ -14,42 +14,32 @@ using System.Windows.Forms; namespace HKCardManager.UserPages { - //瀹氫箟濮旀墭 - public delegate void BindHandle(object sender, EventArgs e); public partial class PersonnelEntryPage : UserControl { - //List OrgList = new List(); List orgTables = new List(); public PersonnelEntryPage() { InitializeComponent(); - - #region 绂佹鏇存敼瀹介珮 - // 绂佹鐢ㄦ埛鏀瑰彉DataGridView鐨勬墍鏈夊垪鐨勫垪瀹 - dataGridView1.AllowUserToResizeColumns = false; - //绂佹鐢ㄦ埛鏀瑰彉DataGridView鎵鏈夎鐨勮楂 - dataGridView1.AllowUserToResizeRows = false; - // 绂佹鐢ㄦ埛鏀瑰彉鍒楀ご鐨勯珮搴 - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; - // 绂佹鐢ㄦ埛鏀瑰彉鍒楀ご鐨勫搴 - dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; - #endregion - - this.Load += PersonnelEntryPage_Load; - - dataGridView1.AutoGenerateColumns = false; - //comboBox1.SelectedIndex = 0; + DataGridViewInit(); + EventInit(); orgTables = ServiceHandler.GetOrgList(); Global.OrgList.Clear(); - orgTables?.ForEach(item => - { - Global.OrgList.Add(item.Name); - }); + orgTables?.ForEach(item => { Global.OrgList.Add(item.Name); }); comboBox2.DataSource = Global.OrgList; Task.Factory.StartNew(() => { GetUser(); }); } + private void DataGridViewInit() + { + dataGridView1.AllowUserToResizeColumns = false;// 绂佹鐢ㄦ埛鏀瑰彉鎵鏈夊垪鐨勫垪瀹 + dataGridView1.AllowUserToResizeRows = false; //绂佹鐢ㄦ埛鏀瑰彉鎵鏈夎鐨勮楂 + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; // 绂佹鐢ㄦ埛鏀瑰彉鍒楀ご鐨勯珮搴 + dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; // 绂佹鐢ㄦ埛鏀瑰彉鍒楀ご鐨勫搴 + dataGridView1.AutoGenerateColumns = false;//绂佺敤鑷姩娣诲姞鍒 + } + + //鑾峰彇鎵鏈夌敤鎴蜂俊鎭 private void GetUser() { var res = HKLibHelper.GetUserList(""); @@ -82,10 +72,8 @@ namespace HKCardManager.UserPages break; } - this.Invoke(() => { - //dataGridView1.DataSource = null; dataGridView1.DataSource = Global.UserListDtos; dataGridView1.DataSource = null; dataGridView1.DataSource = Global.PagUserListDtos; totalCount = Global.UserListDtos.Count; comboBoxNum(); @@ -94,12 +82,13 @@ namespace HKCardManager.UserPages } + //鑾峰彇鍗曢〉闈㈢敤鎴蜂俊鎭 private void GetPag() { Global.PagUserListDtos.Clear(); for (int i = (currentPageIndex - 1) * pageSize; i < Global.UserListDtos.Count; i++) { - if (Global.PagUserListDtos.Count < pageSize) + if (Global.PagUserListDtos.Count < pageSize && i >= 0) Global.PagUserListDtos.Add(Global.UserListDtos.ElementAt(i)); else break; @@ -108,6 +97,7 @@ namespace HKCardManager.UserPages dataGridView1.DataSource = Global.PagUserListDtos; } + //娣诲姞鐢ㄦ埛 private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text.Trim())) @@ -150,6 +140,7 @@ namespace HKCardManager.UserPages } + //鏁版嵁琛ㄥ垪鐐瑰嚮浜嬩欢 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { int index = dataGridView1.CurrentRow.Index; @@ -174,124 +165,110 @@ namespace HKCardManager.UserPages } } - #region datagridView 鍒嗛〉鏄剧ず + #region 鍒嗛〉鏄剧ず - #region 鍙橀噺瀹氫箟 private int totalCount = 0;//鎬绘暟鎹釜鏁 private int pageCount = 0;//鎬婚〉鏁 private int currentPageIndex = 1;//褰撳墠椤电储寮 private int pageSize = 10;//姣忛〉鍒嗛〉澶у皬 private int remainder = 0;//鏈鍚庝竴椤靛墿浣欎釜鏁 private bool isAutoUpdateLabelTip = true;//鑾峰彇鎴栬缃槸鍚﹁嚜鍔ㄦ洿鏂板垎椤垫爣绛惧唴瀹规彁绀猴紝榛樿涓簍rue - private string sqlAddress = "";//"Data Source=192.168.100.144;Initial Catalog=test;User ID=sa;Password=123456;";//DataGridViewd瑕佺粦瀹氱殑琛ㄥ悕 - private string tableName = "";//"DataSource";//DataGridViewd瑕佺粦瀹氱殑琛ㄥ悕 - private string strWhere = ""; - private DataSet dsAll = null;//鎬绘暟鎹簮 - #endregion - public event EventHandler CellClick;//datagridview cellclick 瑙﹀彂浜嬩欢 - #region 澶栬皟鍑芥暟 - /// - /// 缁戝畾鏁版嵁 - /// - public void dataBand() + //浜嬩欢鍒濆鍖 + private void EventInit() { - comboBoxNum(); - showDataGirdView(); + label_first.Click += label_first_Click; //棣栭〉 + label_end.Click += label_end_Click;//鏈〉 + label_up.Click += label_up_Click;//涓婁竴椤 + label_down.Click += label_down_Click;//涓嬩竴椤 + comboBox_page.DropDownClosed += comboBox_page_DropDownClosed;//涓嬫媺鍒楄〃鍒囨崲椤甸潰 + comboBox_num.DropDownClosed += comboBox_num_DropDownClosed;//璁剧疆鍒嗛〉澶у皬 + button_go.Click += button_go_Click;//璺宠浆鎸囧畾椤 } - ///// - ///// 杩斿洖褰撳墠椤甸潰鏁版嵁 - ///// - ///// - //public DataGridView outputDGV() - //{ - // return dataGridView_show; - //} - #endregion - - private void PersonnelEntryPage_Load(object? sender, EventArgs e) - { - - } - - - //鍔犺浇浜嬩欢 - //private void pager1_Load(object sender, EventArgs e) - //{ - // comboBoxNum(); - // showDataGirdView(); - //} - #region 鍒嗛〉鎿嶄綔 //棣栭〉 - private void label_first_Click(object sender, EventArgs e) + private void label_first_Click(object? sender, EventArgs e) { currentPageIndex = 1; showDataGirdView(); } + //鏈〉 - private void label_end_Click(object sender, EventArgs e) + private void label_end_Click(object? sender, EventArgs e) { currentPageIndex = pageCount; showDataGirdView(); } + //涓婁竴椤 - private void label_up_Click(object sender, EventArgs e) + private void label_up_Click(object? sender, EventArgs e) { if (currentPageIndex <= pageCount && currentPageIndex != 1) { currentPageIndex--; showDataGirdView(); } - if (isAutoUpdateLabelTip) - { - updateSplitPageLabelTip(); - } + if (isAutoUpdateLabelTip) updateSplitPageLabelTip(); } + //涓嬩竴椤 - private void label_down_Click(object sender, EventArgs e) + private void label_down_Click(object? sender, EventArgs e) { if (currentPageIndex < pageCount && currentPageIndex != pageCount) { currentPageIndex++; showDataGirdView(); } - if (isAutoUpdateLabelTip) - { - updateSplitPageLabelTip(); - } + if (isAutoUpdateLabelTip) updateSplitPageLabelTip(); } + //绗嚑椤 - private void comboBox_page_DropDownClosed(object sender, EventArgs e) + private void comboBox_page_DropDownClosed(object? sender, EventArgs e) { - currentPageIndex = int.Parse(comboBox_page.SelectedItem.ToString()); - updateSplitPageLabelTip(); - showDataGirdView(); + if (int.TryParse(comboBox_page.Text.Trim(), out int index)) + { + if (index > 0) + { + currentPageIndex = index; + updateSplitPageLabelTip(); + showDataGirdView(); + } + } } + //姣忛〉鏉℃暟 - private void comboBox_num_DropDownClosed(object sender, EventArgs e) + private void comboBox_num_DropDownClosed(object? sender, EventArgs e) { - pageSize = int.Parse(comboBox_num.SelectedItem.ToString()); - //鍒濆鍖栭〉鐮佷负1 - currentPageIndex = 1; - updateSplitPageLabelTip(); - showDataGirdView(); + if (int.TryParse(comboBox_num.Text.Trim(), out int res)) + { + pageSize = res; + currentPageIndex = 1; //鍒濆鍖栭〉鐮佷负1 + updateSplitPageLabelTip(); + showDataGirdView(); + } } + //璺宠浆鎸囧畾椤 - private void button_go_Click(object sender, EventArgs e) + private void button_go_Click(object? sender, EventArgs e) { - try - { - currentPageIndex = int.Parse(textBox_num.Text); - } - catch + if (int.TryParse(textBox_num.Text.Trim(), out int num)) { - currentPageIndex = 1; + if (num > 0 && num <= pageCount) + { + currentPageIndex = num; + currentPageIndex = currentPageIndex > pageCount ? pageCount : currentPageIndex; + updateSplitPageLabelTip(); + showDataGirdView(); + } + else + { + currentPageIndex = 1; + MessageLogNotify.GetInstance.ShowWarning("瓒呭嚭椤甸潰鑼冨洿锛"); + } } - currentPageIndex = currentPageIndex > pageCount ? pageCount : currentPageIndex; - updateSplitPageLabelTip(); - showDataGirdView(); + else MessageLogNotify.GetInstance.ShowError("璇疯緭鍏ユ寚瀹氶〉闈紒"); } + //淇敼鏄剧ず鏁版嵁 public void updateSplitPageLabelTip() { @@ -299,6 +276,7 @@ namespace HKCardManager.UserPages comboBoxPage(); comboBoxNum(); } + //鍒ゆ柇鏄剧ず鐘剁姸鍐 private void pagingShow() { @@ -352,18 +330,16 @@ namespace HKCardManager.UserPages label_count.Text = "鎬" + totalCount + "鏉/" + pageCount + "椤"; textBox_num.Text = currentPageIndex.ToString(); } + //澶氬皯椤 private void comboBoxPage() { comboBox_page.Items.Clear(); - for (int i = 1; i <= pageCount; i++) - { - comboBox_page.Items.Add(i.ToString()); - } + for (int i = 1; i <= pageCount; i++) comboBox_page.Items.Add(i.ToString()); comboBox_page.SelectedIndex = -1; - //褰撲负涓椤碉紝灏辫缃缃负0 - comboBox_page.SelectedIndex = pageCount == 1 ? 0 : currentPageIndex - 1; + comboBox_page.SelectedIndex = pageCount == 1 ? 0 : currentPageIndex - 1; //褰撲负涓椤碉紝灏辫缃缃负0 } + //姣忛〉澶氬皯鏉 private void comboBoxNum() { @@ -401,186 +377,13 @@ namespace HKCardManager.UserPages } comboBox_num.SelectedIndex = i; } - //鑾峰彇鏁版嵁 - #endregion - #region 鏁版嵁澶勭悊 - //缁戝畾鏁版嵁 + + //鏁版嵁鏄剧ず private void showDataGirdView() { - //DataTable dt = new DataTable(); - //if (dsAll != null) - //{ - // dt = GetDsAll();//鑾峰彇浼犲叆鏁版嵁 - //} - //else - //{ - // dt = GetTable();//鑾峰彇鏁版嵁搴撴暟鎹 - //} - //try - //{ - // //缁戝畾鍓嶅彴鎺т欢 - // totalCount = int.Parse(dt.Rows[0]["total"].ToString()); - //} - //catch - //{ - // totalCount = 1; - //} GetPag(); updateSplitPageLabelTip(); - //缁戝畾鏁版嵁 - //dataGridView_show.DataSource = dt; - //dataGridView_show.AllowUserToAddRows = false; } - /// - /// 鑾峰彇鏁版嵁搴撳垎椤垫煡璇 - /// - /// - /// - //private DataTable GetTable(string sql = "") - //{ - - - // DataTable dt = new DataTable(); - // try - // { - // MySqlConnection Connection = new MySqlConnection(sqlAddress); - // Connection.Open(); - // //鍒嗛〉鏌ヨ - // if (sql == "") - // { - // sql = " ,(SELECT COUNT(1) FROM " + tableName + ") as total "; - // sql = "SELECT TOP " + pageSize + " * " + sql + " FROM " + tableName + " WHERE ID NOT IN(SELECT TOP " + ((currentPageIndex - 1) * pageSize) + " ID FROM " + tableName + ")"; - // } - - // MySqlDataAdapter adpater = new MySqlDataAdapter(sql, Connection); - // DataSet ds = new DataSet(); - // adpater.Fill(ds); - // adpater.Fill(dt); - // Connection.Close(); - // } - // catch - // { - // label_count.Text = "鏃犳暟鎹"; - // } - // return dt; - //} - - /// - /// 鑾峰彇鏁版嵁婧愬垎椤垫煡璇 - /// - /// - //private DataTable GetDsAll(string sql = "") - //{ - // DataTable dt = new DataTable(); - // try - // { - // dt = DataSetHelper.SplitDataSet(dsAll, pageSize, currentPageIndex).Tables[0]; - // //娣诲姞涓鍒楄繑鍥炴绘暟鈥榯otal鈥 - // int count = dsAll.Tables[0].Rows.Count; - // dt.Columns.Add("total", typeof(int)); - // foreach (DataRow dr in dt.Rows) - // { - // dr["total"] = count; - // } - // } - // catch - // { - // label_count.Text = "鏃犳暟鎹"; - // } - // return dt; - //} - #region DataSet鍒嗛〉鏌ヨ - public class DataSetHelper - { - public static DataSet SplitDataSet(DataSet ds, int pageSize, int pageIndex) - { - DataSet vds = new DataSet(); - vds = ds.Clone(); - if (pageIndex < 1) pageIndex = 1;//濡傛灉灏忎簬1锛屽彇绗竴椤 - //if ((ds.Tables[0].Rows.Count + pageSize) <= (pageSize * pageIndex)) pageIndex = 1; - int fromIndex = pageSize * (pageIndex - 1);//寮濮嬭 - int toIndex = pageSize * pageIndex - 1; //缁撴潫琛 - for (int i = fromIndex; i <= toIndex; i++) - { - if (i >= (ds.Tables[0].Rows.Count)) //鍒拌揪杩欎竴琛岋紝閫鍑 - break; - vds.Tables[0].ImportRow(ds.Tables[0].Rows[i]); - } - ds.Dispose(); - return vds; - } - /// - /// 鏍规嵁绱㈠紩鍜宲agesize杩斿洖璁板綍 - /// - /// 璁板綍闆 DataTable - /// 褰撳墠椤 - /// 涓椤电殑璁板綍鏁 - /// - public static DataTable SplitDataTable(DataTable dt, int PageIndex, int PageSize) - { - if (dt == null) - { - return null; - } - if (PageIndex == 0) - return dt; - DataTable newdt = dt.Clone(); - //newdt.Clear(); - int rowbegin = (PageIndex - 1) * PageSize; - int rowend = PageIndex * PageSize; - - - if (rowbegin >= dt.Rows.Count) - return newdt; - - - if (rowend > dt.Rows.Count) - rowend = dt.Rows.Count; - for (int i = rowbegin; i <= rowend - 1; i++) - { - DataRow newdr = newdt.NewRow(); - DataRow dr = dt.Rows[i]; - foreach (DataColumn column in dt.Columns) - { - newdr[column.ColumnName] = dr[column.ColumnName]; - } - newdt.Rows.Add(newdr); - } - return newdt; - } - - - public static DataTable ToDataTable(DataRow[] rows) - { - if (rows == null || rows.Length == 0) - { - return null; - } - DataTable tmp = rows[0].Table.Clone(); // 澶嶅埗DataRow鐨勮〃缁撴瀯 - foreach (DataRow row in rows) - { - tmp.Rows.Add(row.ItemArray); // 灏咲ataRow娣诲姞鍒癉ataTable涓 - } - return tmp; - } - } - - private void dataGridView_show_CellClick(object sender, DataGridViewCellEventArgs e) - { - if (this.CellClick != null) - { - //this.CellClick(this.dataGridView_show, new EventArgs()); - } - } - - #endregion - #endregion - - - - #endregion - - } }