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.

137 lines
5.2 KiB

  1. using HKLib.Dto;
  2. using HKLib.Interfaces;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. //using BPA.Helper;
  13. namespace HKCardManager.UserPages
  14. {
  15. public partial class CancellationPage : UserControl
  16. {
  17. public CancellationPage()
  18. {
  19. InitializeComponent();
  20. //this.SizeChanged += CancellationPage_SizeChanged;
  21. }
  22. private void Ref()
  23. {
  24. var res = HKLibHelper.GetUserListSync("");
  25. Global.UserListDtos.Clear();
  26. res?.ToList()?.ForEach(item =>
  27. {
  28. string status = "";
  29. string cardNum = "";
  30. if (item.Cards != null && item.Cards.Count > 0)
  31. {
  32. cardNum = item.Cards.ElementAt(0).CardNum;
  33. status = ((CarStatus)item.Cards.ElementAt(0).State).ToString();
  34. }
  35. Global.UserListDtos.Add(new UserInfoModel()
  36. {
  37. Num = item.Num,
  38. UserName = item.Name,
  39. Phone = item.Phone,
  40. OrgName = item.OrgInfo?.Count > 0 ? item.OrgInfo.ElementAt(0).Name : "",
  41. CardNum = cardNum,
  42. State = status
  43. });
  44. });
  45. }
  46. private async void button2_Click(object sender, EventArgs e)
  47. {
  48. string name = textBox1.Text.Trim();
  49. if (string.IsNullOrEmpty(name))
  50. {
  51. MessageBox.Show("提示!!!\n 请输入用户名...");
  52. MessageLogNotify.GetInstance.ShowWarning("请输入用户名");
  53. return;
  54. }
  55. string TagName = this.Tag.ToString();
  56. if (string.IsNullOrEmpty(TagName))
  57. {
  58. MessageBox.Show("提示!!!\n 功能名称为空,操作失败,请重试...");
  59. MessageLogNotify.GetInstance.ShowError("功能名称为空,操作失败,请重试");
  60. }
  61. else
  62. {
  63. int status = 0;
  64. if (TagName == "销户") status = 3;
  65. else if (TagName == "挂失") status = 2;
  66. else if (TagName == "解挂") status = 1;
  67. //Task.Factory.StartNew(() =>
  68. //{
  69. //this.Invoke(() => { button2.Enabled = false; });
  70. button2.Enabled = false;
  71. Ref();
  72. var temp = Global.UserListDtos.FirstOrDefault(p => p.UserName == name);
  73. if (temp != null)
  74. {
  75. if (temp.State == "作废")
  76. {
  77. MessageBox.Show($"用户【{temp.UserName}】卡片已作废,不允许进行解卦和挂失操作");
  78. return;
  79. }
  80. if (status == 3 && temp.State == "挂失")
  81. {
  82. MessageBox.Show($"用户【{temp.UserName}】挂失状态不能销户");
  83. return;
  84. }
  85. if (!string.IsNullOrEmpty(temp.CardNum))
  86. {
  87. if (MessageBox.Show($"确认是否[{TagName}]用户[{temp.UserName}]!", "操作", MessageBoxButtons.YesNo) == DialogResult.Yes)
  88. {
  89. var res = await HKLibHelper.CardStutasChange(new CardStutasDto()
  90. {
  91. keywrod = name,
  92. Stutas = status
  93. });
  94. if (status == 3)
  95. {
  96. await HKLibHelper.DisableUser(name);
  97. }
  98. if (res)
  99. {
  100. MessageBox.Show($"用户【{temp.UserName}】 {TagName} 成功");
  101. MessageLogNotify.GetInstance.Show($"用户【{temp.UserName}】 {TagName} 成功");
  102. }
  103. else
  104. {
  105. MessageBox.Show($"用户【{temp.UserName}】 {TagName} 失败,请检查名称是否正常");
  106. MessageLogNotify.GetInstance.ShowError($"用户【{temp.UserName}】 {TagName} 失败,请检查名称是否正常");
  107. }
  108. }
  109. }
  110. else
  111. {
  112. MessageBox.Show("提示!!!\n 该用户未注册卡号,请重试...");
  113. MessageLogNotify.GetInstance.ShowError("该用户未注册卡号");
  114. }
  115. }
  116. else
  117. {
  118. MessageBox.Show("提示!!!\n 该用户不存在...");
  119. MessageLogNotify.GetInstance.ShowError("该用户不存在");
  120. }
  121. //this.Invoke(() => { button2.Enabled = true; });
  122. button2.Enabled = true;
  123. //});
  124. }
  125. }
  126. }
  127. }