瀏覽代碼

数据绑定

Lishi
pry 2 年之前
父節點
當前提交
943a01319a
共有 7 個文件被更改,包括 184 次插入137 次删除
  1. +1
    -1
      HKCardManager/Form1.cs
  2. +1
    -0
      HKCardManager/HKCardManager.csproj
  3. +13
    -50
      HKCardManager/UserPages/CancellationPage.Designer.cs
  4. +34
    -7
      HKCardManager/UserPages/CancellationPage.cs
  5. +35
    -69
      HKCardManager/UserPages/CarMangerPage.Designer.cs
  6. +87
    -0
      HKCardManager/UserPages/CarMangerPage.cs
  7. +13
    -10
      UHFHelper/UHFCardHelper.cs

+ 1
- 1
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);
}

//月餐段汇总表


+ 1
- 0
HKCardManager/HKCardManager.csproj 查看文件

@@ -31,6 +31,7 @@

<ItemGroup>
<ProjectReference Include="..\HKLib\HKLib.csproj" />
<ProjectReference Include="..\UHFHelper\UHFHelper.csproj" />
</ItemGroup>

<ItemGroup>


+ 13
- 50
HKCardManager/UserPages/CancellationPage.Designer.cs 查看文件

@@ -28,30 +28,22 @@
/// </summary>
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;
}
}

+ 34
- 7
HKCardManager/UserPages/CancellationPage.cs 查看文件

@@ -1,4 +1,6 @@
using System;
using 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<CarStatus>();
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()} 失败,请重试");
});
}
}
}
}

+ 35
- 69
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;


+ 87
- 0
HKCardManager/UserPages/CarMangerPage.cs 查看文件

@@ -1,5 +1,8 @@
using 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("手机号格式不正确");
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("设备未连接");
}
}
}
}

+ 13
- 10
UHFHelper/UHFCardHelper.cs 查看文件

@@ -21,15 +21,15 @@ namespace UHFHelper
return Instance;
}
//当前操作的ComAdr
private byte fComAdr = 0xff;
private byte fComAdr = 0xff;
//返回串口的索引号
private int frmcomportindex;
/// <summary>
/// 打开的COM口号
/// </summary>
public int OpenComNo { get; set; }
public int OpenComNo { get; set; }
//所有执行指令的返回值
private int fCmdRet { get; set; } = 30;
private int fCmdRet { get; set; } = 30;
/// <summary>
/// 串口打开标示
/// </summary>
@@ -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
/// <returns></returns>
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
/// 写卡
/// </summary>
/// <returns></returns>
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 };
}
}
/// <summary>
/// 解析数据


Loading…
取消
儲存