您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PersonnelEntryPage.cs 5.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. public PersonnelEntryPage()
  21. {
  22. InitializeComponent();
  23. #region 禁止更改宽高
  24. // 禁止用户改变DataGridView的所有列的列宽
  25. dataGridView1.AllowUserToResizeColumns = false;
  26. //禁止用户改变DataGridView所有行的行高
  27. dataGridView1.AllowUserToResizeRows = false;
  28. // 禁止用户改变列头的高度
  29. dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  30. // 禁止用户改变列头的宽度
  31. dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
  32. #endregion
  33. this.SizeChanged += PersonnelEntryPage_SizeChanged;
  34. dataGridView1.AutoGenerateColumns = false;
  35. comboBox1.SelectedIndex = 0;
  36. orgTables = ServiceHandler.GetOrgList();
  37. Global.OrgList.Clear();
  38. orgTables?.ForEach(item =>
  39. {
  40. Global.OrgList.Add(item.Name);
  41. });
  42. comboBox2.DataSource = Global.OrgList;
  43. Task.Factory.StartNew(() =>
  44. {
  45. var res = HKLibHelper.GetUserList("");
  46. Global.UserListDtos.Clear();
  47. res?.ToList()?.ForEach(item =>
  48. {
  49. string status = "";
  50. string cardNum = "";
  51. if (item.Cards != null && item.Cards.Count > 0)
  52. {
  53. cardNum = item.Cards.ElementAt(0).CardNum;
  54. status = ((CarStatus)item.Cards.ElementAt(0).State).ToString();
  55. }
  56. Global.UserListDtos.Add(new UserInfoModel()
  57. {
  58. UserName = item.Name,
  59. Phone = item.Phone,
  60. OrgName = item.OrgInfo?.Count > 0 ? item.OrgInfo.ElementAt(0).Name : "",
  61. CardNum = cardNum,
  62. State = status
  63. });
  64. });
  65. //TestData();
  66. this.Invoke(() => { dataGridView1.DataSource = null; dataGridView1.DataSource = Global.UserListDtos; });
  67. });
  68. }
  69. private void TestData()
  70. {
  71. for (int i = 0; i < 10; i++)
  72. {
  73. Global.UserListDtos.Add(new UserInfoModel()
  74. {
  75. CardNum = Guid.NewGuid().ToString(),
  76. State = CarStatus.正常.ToString(),
  77. OrgName = "研发部",
  78. Phone = "13545893363",
  79. UserName = $"张{i}"
  80. });
  81. }
  82. }
  83. private void PersonnelEntryPage_SizeChanged(object? sender, EventArgs e)
  84. {
  85. //panel1.Left = (this.Width - panel1.Width) / 2;
  86. //panel1.Top = (this.Height - panel1.Height) / 2;
  87. var tt1 = dataGridView1.Size;
  88. var tt = this.Size;
  89. }
  90. private void button2_Click(object sender, EventArgs e)
  91. {
  92. if (string.IsNullOrEmpty(textBox1.Text.Trim()))
  93. {
  94. MessageLogNotify.GetInstance.ShowWarning("请输入姓名");
  95. return;
  96. }
  97. if (!string.IsNullOrEmpty(textBox2.Text.Trim()))
  98. {
  99. if (!textBox2.Text.Trim().IsMobile())
  100. {
  101. MessageLogNotify.GetInstance.ShowWarning("手机号格式不正确");
  102. return;
  103. }
  104. }
  105. UserDto userDto = new UserDto()
  106. {
  107. Name = textBox1.Text.Trim(),
  108. Phone = textBox2.Text.Trim(),
  109. OrgId = orgTables.FirstOrDefault(p => p.Name == comboBox2.Text)?.SId
  110. };
  111. string OrgName = comboBox2.Text;
  112. Task.Factory.StartNew(() =>
  113. {
  114. this.Invoke(() => { button2.Enabled = false; });
  115. if (HKLibHelper.AddUser(userDto))
  116. {
  117. Global.UserListDtos.Add(new UserInfoModel()
  118. {
  119. OrgName = OrgName,
  120. Phone = userDto.Phone,
  121. UserName = userDto.Name
  122. });
  123. this.Invoke(() =>
  124. {
  125. dataGridView1.DataSource = null;
  126. dataGridView1.DataSource = Global.UserListDtos;
  127. });
  128. MessageLogNotify.GetInstance.Show($"用户 【{userDto.Name}】 添加成功");
  129. }
  130. else
  131. MessageLogNotify.GetInstance.ShowError($"用户 【{userDto.Name}】 添加失败,请重试!");
  132. this.Invoke(() => { button2.Enabled = true; });
  133. });
  134. }
  135. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  136. {
  137. int index = dataGridView1.CurrentRow.Index;
  138. if (index <= dataGridView1.Rows.Count - 1 && dataGridView1.CurrentCell.Value.ToString() == "删除")
  139. {
  140. MessageLogNotify.GetInstance.Show($"用户名称:{dataGridView1.Rows[index].Cells[0].Value }");
  141. }
  142. }
  143. }
  144. }