|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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;
- 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
- {
- public partial class CarMangerPage : UserControl
- {
- List<string> OrgList = new List<string>();
- List<OrgTable> orgTables = new List<OrgTable>();
- public CarMangerPage()
- {
- InitializeComponent();
- this.SizeChanged += CarMangerPage_SizeChanged;
- radioButton1.Checked = true;
- orgTables = ServiceHandler.GetOrgList();
- orgTables?.ForEach(item =>
- {
- OrgList.Add(item.Name);
- });
- comboBox1.DataSource = OrgList;
- }
-
- private void CarMangerPage_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)
- {
- 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("设备未连接");
- }
- }
- }
- }
|