You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PersonnelEntryPage.cs 4.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using HKLib.DB.Model.Entity;
  2. using HKLib.Dto;
  3. using HKLib.Interfaces;
  4. using HKLib.Logic;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace HKCardManager.UserPages
  15. {
  16. public partial class PersonnelEntryPage : UserControl
  17. {
  18. List<string> OrgList = new List<string>();
  19. List<OrgTable> orgTables = new List<OrgTable>();
  20. List<UserInfoModel> userListDtos = new List<UserInfoModel>();
  21. public PersonnelEntryPage()
  22. {
  23. InitializeComponent();
  24. //this.SizeChanged += PersonnelEntryPage_SizeChanged;
  25. comboBox1.SelectedIndex = 0;
  26. orgTables = ServiceHandler.GetOrgList();
  27. orgTables?.ForEach(item =>
  28. {
  29. OrgList.Add(item.Name);
  30. });
  31. comboBox2.DataSource = OrgList;
  32. Task.Factory.StartNew(() =>
  33. {
  34. var res = HKLibHelper.GetUserList("");
  35. res?.ToList()?.ForEach(item =>
  36. {
  37. string status = "";
  38. string cardNum = "";
  39. if (item.Cards != null && item.Cards.Count > 0)
  40. {
  41. cardNum = item.Cards.ElementAt(0).CardNum;
  42. status = ((CarStatus)item.Cards.ElementAt(0).State).ToString();
  43. }
  44. userListDtos.Add(new UserInfoModel()
  45. {
  46. UserName = item.Name,
  47. Phone = item.Phone,
  48. OrgName = item.OrgInfo?.Count > 0 ? item.OrgInfo.ElementAt(0).Name : "",
  49. CardNum = cardNum,
  50. State = status
  51. });
  52. });
  53. //TestData();
  54. this.Invoke(() => { dataGridView1.DataSource = userListDtos; });
  55. });
  56. }
  57. private void TestData()
  58. {
  59. for (int i = 0; i < 10; i++)
  60. {
  61. userListDtos.Add(new UserInfoModel()
  62. {
  63. CardNum = Guid.NewGuid().ToString(),
  64. State = CarStatus.正常.ToString(),
  65. OrgName = "研发部",
  66. Phone = "13545893363",
  67. UserName = $"张{i}"
  68. });
  69. }
  70. }
  71. //private void PersonnelEntryPage_SizeChanged(object? sender, EventArgs e)
  72. //{
  73. // panel1.Left = (this.Width - panel1.Width) / 2;
  74. // panel1.Top = (this.Height - panel1.Height) / 2;
  75. //}
  76. private void button2_Click(object sender, EventArgs e)
  77. {
  78. if (string.IsNullOrEmpty(textBox1.Text.Trim()))
  79. {
  80. MessageLogNotify.GetInstance.Show("请输入姓名");
  81. return;
  82. }
  83. if (!textBox2.Text.Trim().IsMobile())
  84. {
  85. MessageLogNotify.GetInstance.Show("手机号格式不正确");
  86. return;
  87. }
  88. UserDto userDto = new UserDto()
  89. {
  90. Name = textBox1.Text.Trim(),
  91. Phone = textBox2.Text.Trim(),
  92. OrgId = orgTables.FirstOrDefault(p => p.Name == comboBox2.Text)?.SId
  93. };
  94. string OrgName = comboBox2.Text;
  95. Task.Factory.StartNew(() =>
  96. {
  97. if (HKLibHelper.AddUser(userDto))
  98. {
  99. userListDtos.Add(new UserInfoModel()
  100. {
  101. OrgName = OrgName,
  102. Phone = userDto.Phone,
  103. UserName = userDto.Name
  104. });
  105. this.Invoke(() =>
  106. {
  107. //int len = dataGridView1.Rows.Count-1;
  108. //dataGridView1.Rows[len].Cells[0] = userDto.Name;
  109. });
  110. MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 添加成功");
  111. }
  112. else
  113. MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 添加失败,请重试!");
  114. });
  115. }
  116. }
  117. }