Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123 рядки
4.2 KiB

  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. }