FrmAttendanceConfig.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace LYFZ.Software.MainBusiness.SystemSettings
  7. {
  8. public class FrmAttendanceConfig : LYFZ.Software.UI.SystemSettings.FrmAttendanceConfig
  9. {
  10. BLL.BLL_ErpSystemConfigure bLL_ErpSystemConfigure = new BLL.BLL_ErpSystemConfigure();
  11. List<Model.AttenDance.Model_WifiConfig> wifiList = new List<Model.AttenDance.Model_WifiConfig>();
  12. Model.AttenDance.Model_WifiConfig selectModel = null;
  13. public FrmAttendanceConfig()
  14. {
  15. this.btn_Save.Click += Btn_Save_Click;
  16. this.btn_Close.Click += Btn_Close_Click;
  17. this.btn_Reset.Click += Btn_Reset_Click;
  18. this.dgvWifiList.CellDoubleClick += DgvWifiList_CellContentDoubleClick;
  19. this.dgvWifiList.CellClick += DgvWifiList_CellClick;
  20. InitWifiConfigModelList();
  21. }
  22. private void DgvWifiList_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  23. {
  24. if (e.ColumnIndex == 3)
  25. {
  26. Model.AttenDance.Model_WifiConfig tempMelectModel = wifiList[e.RowIndex];
  27. if (MessageBoxCustom.Show("是否确定删除"+ tempMelectModel.WifiName+"的配置","消息提示", System.Windows.Forms.MessageBoxButtons.OKCancel)== System.Windows.Forms.DialogResult.OK)
  28. {
  29. wifiList.Remove(tempMelectModel);
  30. bLL_ErpSystemConfigure.SaveConfigureInfo(Model.ConfigItemType.AttenDanceSetInfo, JsonConvert.SerializeObject(wifiList), "考勤Wifi配置信息");
  31. if(selectModel!=null&& tempMelectModel == selectModel)
  32. {
  33. selectModel = null;
  34. }
  35. ResetTextBoxValue();
  36. BindWifiConfigModelList();
  37. }
  38. }
  39. }
  40. private void Btn_Reset_Click(object sender, EventArgs e)
  41. {
  42. selectModel = null;
  43. ResetTextBoxValue();
  44. }
  45. private void DgvWifiList_CellContentDoubleClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
  46. {
  47. if (e.ColumnIndex < 3)
  48. {
  49. if (e.RowIndex > -1)
  50. {
  51. selectModel = wifiList[e.RowIndex];
  52. }
  53. else
  54. {
  55. selectModel = null;
  56. }
  57. ResetTextBoxValue();
  58. }
  59. }
  60. void ResetTextBoxValue()
  61. {
  62. if (selectModel == null)
  63. {
  64. tb_Address.Text = "";
  65. tb_Equipment.Text = "";
  66. tb_WifiName.Text = "";
  67. }
  68. else
  69. {
  70. tb_Address.Text = selectModel.WifiAddress;
  71. tb_Equipment.Text = selectModel.WifiDentify;
  72. tb_WifiName.Text = selectModel.WifiName;
  73. }
  74. }
  75. private void Btn_Close_Click(object sender, EventArgs e)
  76. {
  77. this.Close();
  78. }
  79. private void Btn_Save_Click(object sender, EventArgs e)
  80. {
  81. if (selectModel == null)
  82. {
  83. selectModel = new Model.AttenDance.Model_WifiConfig()
  84. {
  85. WifiAddress = tb_Address.Text,
  86. WifiDentify = tb_Equipment.Text,
  87. WifiName = tb_WifiName.Text
  88. };
  89. wifiList.Add(selectModel);
  90. }
  91. else
  92. {
  93. selectModel.WifiAddress = tb_Address.Text;
  94. selectModel.WifiDentify = tb_Equipment.Text;
  95. selectModel.WifiName = tb_WifiName.Text;
  96. }
  97. bLL_ErpSystemConfigure.SaveConfigureInfo(Model.ConfigItemType.AttenDanceSetInfo, JsonConvert.SerializeObject(wifiList),"考勤Wifi配置信息");
  98. selectModel = null;
  99. ResetTextBoxValue();
  100. BindWifiConfigModelList();
  101. }
  102. void InitWifiConfigModelList()
  103. {
  104. Model.Model_ErpSystemConfigure sysConfigure = bLL_ErpSystemConfigure.GetConfigureInfo(Model.ConfigItemType.AttenDanceSetInfo);
  105. if (!string.IsNullOrEmpty(sysConfigure.Sconfig_Value))
  106. {
  107. wifiList = JsonConvert.DeserializeObject<List<Model.AttenDance.Model_WifiConfig>>(sysConfigure.Sconfig_Value);
  108. }
  109. BindWifiConfigModelList();
  110. }
  111. void BindWifiConfigModelList()
  112. {
  113. this.dgvWifiList.Rows.Clear();
  114. foreach (Model.AttenDance.Model_WifiConfig model in wifiList)
  115. {
  116. System.Windows.Forms.DataGridViewRow dgvRow = new System.Windows.Forms.DataGridViewRow();
  117. dgvRow.Cells.Add(new System.Windows.Forms.DataGridViewTextBoxCell());
  118. dgvRow.Cells[0].Value = model.WifiName;
  119. dgvRow.Cells.Add(new System.Windows.Forms.DataGridViewTextBoxCell());
  120. dgvRow.Cells[1].Value = model.WifiDentify;
  121. dgvRow.Cells.Add(new System.Windows.Forms.DataGridViewTextBoxCell());
  122. dgvRow.Cells[2].Value = model.WifiAddress;
  123. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  124. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  125. this.dgvWifiList.DefaultCellStyle = dataGridViewCellStyle1;
  126. dgvRow.Cells.Add(new System.Windows.Forms.DataGridViewLinkCell());
  127. dgvRow.Cells[3].Value = "删除";
  128. this.dgvWifiList.Rows.Add(dgvRow);
  129. }
  130. }
  131. }
  132. }