pry 2 years ago
parent
commit
d7add0e020
2 changed files with 68 additions and 69 deletions
  1. +0
    -8
      HKCardManager/Form1.cs
  2. +68
    -61
      HKCardManager/UserPages/CarMangerPage.cs

+ 0
- 8
HKCardManager/Form1.cs View File

@@ -10,14 +10,6 @@ namespace HKCardManager
InitializeComponent();
splitContainer1.SplitterDistance = 240;
DataGridViewInit();
//DbContext.InitTable();
Task.Factory.StartNew(() =>
{
var res = UHFCardHelper.GetInstance().OpenPort();
if (res != null && res.Res)
MessageLogNotify.GetInstance.ShowError("制卡设备已连接!");
else MessageLogNotify.GetInstance.ShowError($"制卡设备未连接!");
});
ShowPage(new PersonnelEntryPage());
this.SizeChanged += Form1_SizeChanged;
this.button1.SizeChanged += Button1_SizeChanged;


+ 68
- 61
HKCardManager/UserPages/CarMangerPage.cs View File

@@ -149,8 +149,15 @@ namespace HKCardManager.UserPages
//写卡
private void button2_Click(object sender, EventArgs e)
{
if (UHFCardHelper.GetInstance().ComOpen)
var CK = UHFCardHelper.GetInstance().ComOpen;
if (!CK)
{
var res = UHFCardHelper.GetInstance().OpenPort();
if (res != null && res.Res)
MessageLogNotify.GetInstance.ShowError("制卡设备已连接!");
else MessageLogNotify.GetInstance.ShowError($"制卡设备未连接!");
}

string Name = string.Empty;

if (radioButton2.Checked)
@@ -169,99 +176,99 @@ namespace HKCardManager.UserPages
MessageLogNotify.GetInstance.ShowWarning("用户已经存在,请勿重复添加");
return;
}
Name = textBox2.Text.Trim();
Name = textBox2.Text.Trim();
}
//if (!textBox4.Text.Trim().IsMobile())
//{
// MessageLogNotify.GetInstance.ShowWarning("手机号格式不正确");
// return;
//}

string OrgName = comboBox1.Text;
string worker = new IdWorker(1, 1).NextId().ToString();// ID生成
UserDto userDto = new UserDto()
{
Name = Name,
//Phone = textBox4.Text.Trim(),
OrgId = orgTables.FirstOrDefault(p => p.Name == comboBox1.Text)?.SId,
CardNo = worker
};
Task.Factory.StartNew(() =>
try
{
//写卡
var res = UHFCardHelper.GetInstance().WriteCard(userDto.CardNo);
if (res != null && res.Res)
{
//写卡
var res = UHFCardHelper.GetInstance().WriteCard(userDto.CardNo);
if (res != null && res.Res)
MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 写卡成功");
this.Invoke(() =>
{
MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 写卡成功");
this.Invoke(() => {
textBox2.Text = String.Empty;
button2.Enabled = false;
});
}
else
{
MessageLogNotify.GetInstance.ShowError($"用户 【{userDto.Name}】 写卡失败,原因:{res?.ResMes}");
}
textBox2.Text = String.Empty;
button2.Enabled = false;
});
}
else
{
MessageLogNotify.GetInstance.ShowError($"用户 【{userDto.Name}】 写卡失败,原因:{res?.ResMes}");
}

if (HKLibHelper.AddUserAndBindCard(userDto))
{
MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 添加成功");
}
else
MessageLogNotify.GetInstance.ShowError($"用户 【{userDto.Name}】 添加失败,请重试!");
});
if (HKLibHelper.AddUserAndBindCard(userDto))
{
MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 添加成功");
}
else
MessageLogNotify.GetInstance.ShowError($"用户 【{userDto.Name}】 添加失败,请重试!");
}
else
finally
{
MessageLogNotify.GetInstance.ShowWarning("设备未连接");
UHFCardHelper.GetInstance().ClosePort();
}
}

//读卡
private void button1_Click(object sender, EventArgs e)
{
if (UHFCardHelper.GetInstance().ComOpen)
var CK = UHFCardHelper.GetInstance().ComOpen;
if (!CK)
{
var res = UHFCardHelper.GetInstance().OpenPort();
if (res != null && res.Res)
MessageLogNotify.GetInstance.ShowError("制卡设备已连接!");
else MessageLogNotify.GetInstance.ShowError($"制卡设备未连接!");
}
try
{
Task.Factory.StartNew(() =>
var res = UHFCardHelper.GetInstance().ReadCard();
if (string.IsNullOrEmpty(res))
{
var res = UHFCardHelper.GetInstance().ReadCard();
if (string.IsNullOrEmpty(res))
{
MessageLogNotify.GetInstance.Show("请放入卡片");
return;
}
if (Regex.IsMatch(res, "\\d{19}"))
MessageLogNotify.GetInstance.Show("请放入卡片");
return;
}
if (Regex.IsMatch(res, "\\d{19}"))
{
var users = HKLibHelper.GetUserList("")?.FirstOrDefault(p => p.Cards?.FirstOrDefault(s => s.CardNum == res) != null);
if (users != null)
{
var users = HKLibHelper.GetUserList("")?.FirstOrDefault(p => p.Cards?.FirstOrDefault(s => s.CardNum == res) != null);
if (users != null)
this.Invoke(() =>
{
this.Invoke(() =>
textBox2.Text = users.Name;
if (users.OrgInfo != null && users.OrgInfo.Count > 0)
{
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($"读卡成功,当前卡号【{res}】,详细信息请在页面查看");
}
else
{
MessageLogNotify.GetInstance.Show("卡号已制作未绑定用户");
}
comboBox1.Text = users.OrgInfo.ElementAt(0).Name;
}
});
MessageLogNotify.GetInstance.Show($"读卡成功,当前卡号【{res}】,用户【{users.Name}】,详细信息请在页面查看");
}
else
{
MessageLogNotify.GetInstance.Show("读卡成功,该卡是新卡");
MessageLogNotify.GetInstance.Show("卡号已制作未绑定用户");
}
}
else
{
MessageLogNotify.GetInstance.Show("读卡成功,该卡是新卡");
}

this.Invoke(() => { button2.Enabled = true; });
});
this.Invoke(() => { button2.Enabled = true; });
}
else
finally
{
MessageLogNotify.GetInstance.ShowWarning("设备未连接");
UHFCardHelper.GetInstance().ClosePort();
}

}
}
}

Loading…
Cancel
Save