|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using HKLib.DB.Model.Entity;
- using HKLib.Dto;
- using HKLib.Interfaces;
- 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.UserPages
- {
- public partial class PersonnelEntryPage : UserControl
- {
- List<string> OrgList = new List<string>();
- List<OrgTable> orgTables = new List<OrgTable>();
- List<UserInfoModel> userListDtos = new List<UserInfoModel>();
- public PersonnelEntryPage()
- {
- InitializeComponent();
- //this.SizeChanged += PersonnelEntryPage_SizeChanged;
- comboBox1.SelectedIndex = 0;
- orgTables = ServiceHandler.GetOrgList();
- orgTables?.ForEach(item =>
- {
- OrgList.Add(item.Name);
- });
- comboBox2.DataSource = OrgList;
- Task.Factory.StartNew(() =>
- {
- var res = HKLibHelper.GetUserList("");
- 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();
- }
- 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 = userListDtos; });
- });
- }
-
- private void TestData()
- {
- for (int i = 0; i < 10; i++)
- {
- userListDtos.Add(new UserInfoModel()
- {
- CardNum = Guid.NewGuid().ToString(),
- State = CarStatus.正常.ToString(),
- OrgName = "研发部",
- Phone = "13545893363",
- UserName = $"张{i}"
- });
- }
- }
-
- //private void PersonnelEntryPage_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 (string.IsNullOrEmpty(textBox1.Text.Trim()))
- {
- MessageLogNotify.GetInstance.Show("请输入姓名");
- return;
- }
- if (!textBox2.Text.Trim().IsMobile())
- {
- MessageLogNotify.GetInstance.Show("手机号格式不正确");
- return;
- }
- UserDto userDto = new UserDto()
- {
- Name = textBox1.Text.Trim(),
- Phone = textBox2.Text.Trim(),
- OrgId = orgTables.FirstOrDefault(p => p.Name == comboBox2.Text)?.SId
- };
- string OrgName = comboBox2.Text;
- Task.Factory.StartNew(() =>
- {
- if (HKLibHelper.AddUser(userDto))
- {
- userListDtos.Add(new UserInfoModel()
- {
- OrgName = OrgName,
- Phone = userDto.Phone,
- UserName = userDto.Name
- });
- this.Invoke(() =>
- {
- //int len = dataGridView1.Rows.Count-1;
- //dataGridView1.Rows[len].Cells[0] = userDto.Name;
- });
- MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 添加成功");
- }
- else
- MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 添加失败,请重试!");
- });
-
- }
- }
- }
|