diff --git a/HKCardManager/Form1.cs b/HKCardManager/Form1.cs index b1c0ef6..292b5e3 100644 --- a/HKCardManager/Form1.cs +++ b/HKCardManager/Form1.cs @@ -162,7 +162,7 @@ namespace HKCardManager //销户,挂失,解挂 private void button4_Click(object sender, EventArgs e) { - ShowPage(new CancellationPage()); + ShowPage(new CancellationPage(), ((Button)sender)?.Text); } //月餐段汇总表 diff --git a/HKCardManager/HKCardManager.csproj b/HKCardManager/HKCardManager.csproj index 39834f3..09b3f25 100644 --- a/HKCardManager/HKCardManager.csproj +++ b/HKCardManager/HKCardManager.csproj @@ -31,6 +31,7 @@ + diff --git a/HKCardManager/UserPages/CancellationPage.Designer.cs b/HKCardManager/UserPages/CancellationPage.Designer.cs index 3672ffb..d8361d2 100644 --- a/HKCardManager/UserPages/CancellationPage.Designer.cs +++ b/HKCardManager/UserPages/CancellationPage.Designer.cs @@ -28,30 +28,22 @@ /// private void InitializeComponent() { - this.panel1 = new System.Windows.Forms.Panel(); + this.textBox1 = new System.Windows.Forms.TextBox(); this.button2 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); - this.textBox2 = new System.Windows.Forms.TextBox(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); - this.panel1.SuspendLayout(); this.SuspendLayout(); // - // panel1 + // textBox1 // - this.panel1.Controls.Add(this.textBox2); - this.panel1.Controls.Add(this.textBox1); - this.panel1.Controls.Add(this.button2); - this.panel1.Controls.Add(this.label1); - this.panel1.Controls.Add(this.label4); - this.panel1.Location = new System.Drawing.Point(209, 184); - this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(350, 162); - this.panel1.TabIndex = 27; + this.textBox1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.textBox1.Location = new System.Drawing.Point(104, 22); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(213, 28); + this.textBox1.TabIndex = 22; // // button2 // - this.button2.Location = new System.Drawing.Point(244, 114); + this.button2.Location = new System.Drawing.Point(330, 22); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(90, 32); this.button2.TabIndex = 26; @@ -63,58 +55,29 @@ // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label1.Location = new System.Drawing.Point(36, 14); + this.label1.Location = new System.Drawing.Point(21, 25); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(90, 21); this.label1.TabIndex = 21; this.label1.Text = "杈撳叆濮撳悕锛"; // - // textBox2 - // - this.textBox2.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox2.Location = new System.Drawing.Point(121, 63); - this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(213, 28); - this.textBox2.TabIndex = 24; - // - // textBox1 - // - this.textBox1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox1.Location = new System.Drawing.Point(121, 14); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(213, 28); - this.textBox1.TabIndex = 22; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label4.Location = new System.Drawing.Point(20, 63); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(106, 21); - this.label4.TabIndex = 23; - this.label4.Text = "杈撳叆鎵嬫満鍙凤細"; - // // CancellationPage // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.panel1); + this.Controls.Add(this.button2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); this.Name = "CancellationPage"; this.Size = new System.Drawing.Size(775, 606); - this.panel1.ResumeLayout(false); - this.panel1.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion - - private Panel panel1; private Button button2; private Label label1; - private TextBox textBox2; private TextBox textBox1; - private Label label4; } } diff --git a/HKCardManager/UserPages/CancellationPage.cs b/HKCardManager/UserPages/CancellationPage.cs index b538637..e15a023 100644 --- a/HKCardManager/UserPages/CancellationPage.cs +++ b/HKCardManager/UserPages/CancellationPage.cs @@ -1,4 +1,6 @@ -锘縰sing System; +锘縰sing HKLib.Dto; +using HKLib.Interfaces; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using BPA.Helper; namespace HKCardManager.UserPages { @@ -15,18 +18,42 @@ namespace HKCardManager.UserPages public CancellationPage() { InitializeComponent(); - this.SizeChanged += CancellationPage_SizeChanged; + //this.SizeChanged += CancellationPage_SizeChanged; } - private void CancellationPage_SizeChanged(object? sender, EventArgs e) - { - panel1.Left = (this.Width - panel1.Width) / 2; - panel1.Top = (this.Height - panel1.Height) / 2; - } + //private void CancellationPage_SizeChanged(object? sender, EventArgs e) + //{ + // panel1.Left = (this.Width - panel1.Width) / 2; + // panel1.Top = (this.Height - panel1.Height) / 2; + //} private void button2_Click(object sender, EventArgs e) { + string name = textBox1.Text.Trim(); + if (string.IsNullOrEmpty(name)) + { + MessageLogNotify.GetInstance.Show("璇疯緭鍏ョ敤鎴峰悕"); + return; + } + if (string.IsNullOrEmpty(this.Name)) + { + MessageLogNotify.GetInstance.Show("鍔熻兘鍚嶇О涓虹┖锛屾搷浣滃け璐ワ紝璇烽噸璇"); + } + else + { + var resStatus = this.Name.ToEnum(); + Task.Factory.StartNew(() => + { + var res = HKLibHelper.CardStutasChange(new CardStutasDto() + { + keywrod = name, + Stutas = (int)resStatus + }); + if (res) MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 {resStatus.ToString()} 鎴愬姛"); + else MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 {resStatus.ToString()} 澶辫触锛岃閲嶈瘯"); + }); + } } } } diff --git a/HKCardManager/UserPages/CarMangerPage.Designer.cs b/HKCardManager/UserPages/CarMangerPage.Designer.cs index 41b169d..9f4dcf4 100644 --- a/HKCardManager/UserPages/CarMangerPage.Designer.cs +++ b/HKCardManager/UserPages/CarMangerPage.Designer.cs @@ -32,11 +32,7 @@ this.button1 = new System.Windows.Forms.Button(); this.textBox4 = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); - this.textBox3 = new System.Windows.Forms.TextBox(); - this.label4 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.textBox1 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label1 = new System.Windows.Forms.Label(); @@ -48,9 +44,10 @@ // // button2 // - this.button2.Location = new System.Drawing.Point(321, 330); + this.button2.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button2.Location = new System.Drawing.Point(98, 285); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(88, 34); + this.button2.Size = new System.Drawing.Size(190, 34); this.button2.TabIndex = 29; this.button2.Text = "鍐欏崱"; this.button2.UseVisualStyleBackColor = true; @@ -58,101 +55,77 @@ // // button1 // - this.button1.Location = new System.Drawing.Point(114, 330); + this.button1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.button1.Location = new System.Drawing.Point(98, 229); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(88, 34); + this.button1.Size = new System.Drawing.Size(190, 34); this.button1.TabIndex = 28; - this.button1.Text = "鍗¢獙璇"; + this.button1.Text = "璇诲崱"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox4 // - this.textBox4.Location = new System.Drawing.Point(288, 85); + this.textBox4.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.textBox4.Location = new System.Drawing.Point(98, 131); this.textBox4.Name = "textBox4"; - this.textBox4.Size = new System.Drawing.Size(121, 23); + this.textBox4.Size = new System.Drawing.Size(190, 28); this.textBox4.TabIndex = 27; // // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(224, 85); + this.label5.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label5.Location = new System.Drawing.Point(15, 131); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(68, 17); + this.label5.Size = new System.Drawing.Size(90, 21); this.label5.TabIndex = 26; - this.label5.Text = "璇佷欢鍙风爜锛"; - // - // textBox3 - // - this.textBox3.Location = new System.Drawing.Point(81, 195); - this.textBox3.Multiline = true; - this.textBox3.Name = "textBox3"; - this.textBox3.Size = new System.Drawing.Size(328, 107); - this.textBox3.TabIndex = 25; - // - // label4 - // - this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(17, 195); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(44, 17); - this.label4.TabIndex = 24; - this.label4.Text = "澶囨敞锛"; + this.label5.Text = "鎵嬫満鍙风爜锛"; // // textBox2 // - this.textBox2.Location = new System.Drawing.Point(81, 141); + this.textBox2.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.textBox2.Location = new System.Drawing.Point(98, 91); this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(121, 23); + this.textBox2.Size = new System.Drawing.Size(190, 28); this.textBox2.TabIndex = 23; // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(224, 144); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(44, 17); - this.label3.TabIndex = 22; - this.label3.Text = "鎬у埆锛"; - // - // textBox1 - // - this.textBox1.Location = new System.Drawing.Point(288, 138); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(121, 23); - this.textBox1.TabIndex = 21; - // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(17, 141); + 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(47, 94); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(44, 17); + this.label2.Size = new System.Drawing.Size(58, 21); this.label2.TabIndex = 20; this.label2.Text = "濮撳悕锛"; // // comboBox1 // + 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.Location = new System.Drawing.Point(81, 85); + this.comboBox1.Location = new System.Drawing.Point(98, 179); this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(121, 25); + this.comboBox1.Size = new System.Drawing.Size(190, 29); this.comboBox1.TabIndex = 19; // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(17, 88); + this.label1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(15, 182); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(68, 17); + this.label1.Size = new System.Drawing.Size(90, 21); this.label1.TabIndex = 18; this.label1.Text = "鏈烘瀯鍚嶇О锛"; // // radioButton2 // this.radioButton2.AutoSize = true; - this.radioButton2.Location = new System.Drawing.Point(224, 34); + this.radioButton2.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.radioButton2.Location = new System.Drawing.Point(98, 53); this.radioButton2.Name = "radioButton2"; - this.radioButton2.Size = new System.Drawing.Size(134, 21); + this.radioButton2.Size = new System.Drawing.Size(172, 25); this.radioButton2.TabIndex = 17; this.radioButton2.TabStop = true; this.radioButton2.Text = "浜哄憳宸插綍鍏ヨ繘琛屽彂鍗"; @@ -161,9 +134,10 @@ // radioButton1 // this.radioButton1.AutoSize = true; - this.radioButton1.Location = new System.Drawing.Point(17, 34); + this.radioButton1.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.radioButton1.Location = new System.Drawing.Point(98, 11); this.radioButton1.Name = "radioButton1"; - this.radioButton1.Size = new System.Drawing.Size(146, 21); + this.radioButton1.Size = new System.Drawing.Size(188, 25); this.radioButton1.TabIndex = 16; this.radioButton1.TabStop = true; this.radioButton1.Text = "鐩存帴褰曞叆浜哄憳杩涜鍙戝崱"; @@ -171,6 +145,7 @@ // // panel1 // + this.panel1.Controls.Add(this.textBox2); this.panel1.Controls.Add(this.comboBox1); this.panel1.Controls.Add(this.radioButton1); this.panel1.Controls.Add(this.button2); @@ -180,14 +155,9 @@ this.panel1.Controls.Add(this.textBox4); this.panel1.Controls.Add(this.label5); this.panel1.Controls.Add(this.label2); - this.panel1.Controls.Add(this.textBox3); - this.panel1.Controls.Add(this.textBox1); - this.panel1.Controls.Add(this.label4); - this.panel1.Controls.Add(this.label3); - this.panel1.Controls.Add(this.textBox2); this.panel1.Location = new System.Drawing.Point(331, 97); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(426, 394); + this.panel1.Size = new System.Drawing.Size(301, 335); this.panel1.TabIndex = 31; // // CarMangerPage @@ -208,11 +178,7 @@ private Button button1; private TextBox textBox4; private Label label5; - private TextBox textBox3; - private Label label4; private TextBox textBox2; - private Label label3; - private TextBox textBox1; private Label label2; private ComboBox comboBox1; private Label label1; diff --git a/HKCardManager/UserPages/CarMangerPage.cs b/HKCardManager/UserPages/CarMangerPage.cs index c55fac6..c3ea594 100644 --- a/HKCardManager/UserPages/CarMangerPage.cs +++ b/HKCardManager/UserPages/CarMangerPage.cs @@ -1,5 +1,8 @@ 锘縰sing HKLib.DB.Model.Entity; +using HKLib.Dto; +using HKLib.Interfaces; using HKLib.Logic; +using Snowflake.Core; using System; using System.Collections.Generic; using System.ComponentModel; @@ -7,8 +10,10 @@ using System.Data; using System.Drawing; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; +using UHFHelper; namespace HKCardManager.UserPages { @@ -38,7 +43,89 @@ namespace HKCardManager.UserPages //鍐欏崱 private void button2_Click(object sender, EventArgs e) { + if (UHFCardHelper.GetInstance().ComOpen) + { + if (string.IsNullOrEmpty(textBox2.Text.Trim())) + { + MessageLogNotify.GetInstance.Show("璇疯緭鍏ュ鍚"); + return; + } + if (!textBox4.Text.Trim().IsMobile()) + { + MessageLogNotify.GetInstance.Show("鎵嬫満鍙锋牸寮忎笉姝g‘"); + return; + } + string OrgName = comboBox1.Text; + string worker = new IdWorker(1, 1).NextId().ToString();// ID鐢熸垚 + UserDto userDto = new UserDto() + { + Name = textBox2.Text.Trim(), + Phone = textBox4.Text.Trim(), + OrgId = orgTables.FirstOrDefault(p => p.Name == comboBox1.Text)?.SId, + CardNo = worker + }; + Task.Factory.StartNew(() => + { + //鍐欏崱 + var res = UHFCardHelper.GetInstance().WriteCard(userDto.CardNo); + if (res != null && res.Res) + { + MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 鍐欏崱鎴愬姛"); + } + else + { + MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 鍐欏崱澶辫触锛屽師鍥狅細{res?.ResMes}"); + } + + if (HKLibHelper.AddUserAndBindCard(userDto)) + { + MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞鎴愬姛"); + } + else + MessageLogNotify.GetInstance.Show($"鐢ㄦ埛 銆恵userDto.Name}銆 娣诲姞澶辫触锛岃閲嶈瘯锛"); + }); + } + else + { + MessageLogNotify.GetInstance.Show("璁惧鏈繛鎺"); + } + } + //璇诲崱 + private void button1_Click(object sender, EventArgs e) + { + if (UHFCardHelper.GetInstance().ComOpen) + { + Task.Factory.StartNew(() => + { + var res = UHFCardHelper.GetInstance().ReadCard(); + if (Regex.IsMatch(res, "\\d{19}")) + { + var users = HKLibHelper.GetUserList("")?.FirstOrDefault(p => p.Cards?.FirstOrDefault(s => s.CardNum == res) != null); + if (users != null) + { + this.Invoke(() => + { + textBox2.Text = users.Name; + textBox4.Text = users.Phone; + if (users.OrgInfo != null && users.OrgInfo.Count > 0) + { + comboBox1.Text = users.OrgInfo.ElementAt(0).Name; + } + }); + MessageLogNotify.GetInstance.Show("璇诲崱鎴愬姛锛岃缁嗕俊鎭鍦ㄩ〉闈㈡煡鐪"); + } + } + else + { + MessageLogNotify.GetInstance.Show("璇诲崱鎴愬姛锛岃鍗℃槸鏂板崱"); + } + }); + } + else + { + MessageLogNotify.GetInstance.Show("璁惧鏈繛鎺"); + } } } } diff --git a/UHFHelper/UHFCardHelper.cs b/UHFHelper/UHFCardHelper.cs index e062949..b172042 100644 --- a/UHFHelper/UHFCardHelper.cs +++ b/UHFHelper/UHFCardHelper.cs @@ -21,15 +21,15 @@ namespace UHFHelper return Instance; } //褰撳墠鎿嶄綔鐨凜omAdr - private byte fComAdr = 0xff; + private byte fComAdr = 0xff; //杩斿洖涓插彛鐨勭储寮曞彿 private int frmcomportindex; /// /// 鎵撳紑鐨凜OM鍙e彿 /// - public int OpenComNo { get; set; } + public int OpenComNo { get; set; } //鎵鏈夋墽琛屾寚浠ょ殑杩斿洖鍊 - private int fCmdRet { get; set; } = 30; + private int fCmdRet { get; set; } = 30; /// /// 涓插彛鎵撳紑鏍囩ず /// @@ -88,17 +88,18 @@ namespace UHFHelper { StaticClassReaderB.CloseSpecComPort(frmcomportindex); ComOpen = false; - return new Resultoutput { Res=false,ResMes= "涓插彛閫氳閿欒" }; + return new Resultoutput { Res = false, ResMes = "涓插彛閫氳閿欒" }; } if ((OpenComNo == -1) && (openresult == 0x30)) { return new Resultoutput { Res = false, ResMes = "涓插彛閫氳閿欒" }; } - + } } - catch(Exception ex) { + catch (Exception ex) + { return new Resultoutput { Res = false, ResMes = ex.ToString() }; } ComOpen = true; @@ -167,6 +168,7 @@ namespace UHFHelper /// public string ReadCard() { + if (!ComOpen) return string.Empty; int CardNum = 0; int Totallen = 0; int EPClen, m; @@ -200,7 +202,7 @@ namespace UHFHelper { return ""; } - string cardcode = sEPC.Substring(1, sEPC.Length-1); + string cardcode = sEPC.Substring(1, sEPC.Length - 1); return cardcode; } } @@ -211,8 +213,9 @@ namespace UHFHelper /// 鍐欏崱 /// /// - public Resultoutput WriteCard(string CardCodeStr) + public Resultoutput WriteCard(string CardCodeStr) { + if (!ComOpen) return new Resultoutput() { ResMes = "璁惧鏈繛鎺", Res = false }; byte[] WriteEPC = new byte[100]; byte WriteEPClen; byte ENum; @@ -242,9 +245,9 @@ namespace UHFHelper catch (Exception ex) { - return new Resultoutput { Res = false, ResMes = "鍐欏崱澶辫触"+ ex.Message }; + return new Resultoutput { Res = false, ResMes = "鍐欏崱澶辫触" + ex.Message }; } - + } /// /// 瑙f瀽鏁版嵁