DataViewColumnSet.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using LYFZ.Model;
  11. namespace LYFZ.ComponentLibrary
  12. {
  13. public partial class DataViewColumnSet : LYFZ.ComponentLibrary.BaseContentsFormMain
  14. {
  15. public DataViewColumnSet()
  16. {
  17. InitializeComponent();
  18. this.panelEx1.BackColor = UIBlueThemeResources.AreaBackgroundColor;
  19. this.panelEx1.BorderColor = UIBlueThemeResources.BorderAreaColor;
  20. this.panelEx1.BorderStyle = BorderStyle.FixedSingle;
  21. this.Load += DataGridViewSetColumn_Load;
  22. this.btnRevert.Click += btnRevert_Click;
  23. this.btnSaveed.Click += btnSaveed_Click;
  24. this.btnCancel.Click += btnCancel_Click;
  25. }
  26. string dgvUserEmployeeID = "";
  27. string dgvGuidName = "";
  28. private List<string> dataCoumnList = new List<string>();
  29. private List<string> enabledList = new List<string>();
  30. List<Model.TitleColumnDisplay> _TitleColumnDisplayList = new List<Model.TitleColumnDisplay>();
  31. /// <summary>
  32. /// 完全字段集合
  33. /// </summary>
  34. public List<string> DataCoumnList { get => dataCoumnList; set => dataCoumnList = value; }
  35. /// <summary>
  36. /// 不可操作字段
  37. /// </summary>
  38. public List<string> EnabledList { get => enabledList; set => enabledList = value; }
  39. public List<TitleColumnDisplay> TitleColumnDisplayList { get => _TitleColumnDisplayList; set => _TitleColumnDisplayList = value; }
  40. public string DgvUserEmployeeID { get => dgvUserEmployeeID; set => dgvUserEmployeeID = value; }
  41. public string DgvGuidName { get => dgvGuidName; set => dgvGuidName = value; }
  42. /// <summary>
  43. /// 窗体加载事件
  44. /// </summary>
  45. /// <param name="sender"></param>
  46. /// <param name="e"></param>
  47. void DataGridViewSetColumn_Load(object sender, EventArgs e)
  48. {
  49. for (int i = 0; i < this.dataCoumnList.Count; i++)
  50. {
  51. string columnText = this.dataCoumnList[i].Trim();
  52. if (!string.IsNullOrWhiteSpace(columnText))
  53. {
  54. TitleColumnDisplay titleColumn = this._TitleColumnDisplayList.Find(t=>t.ColumnText.ToLower() == columnText.ToLower());
  55. if (titleColumn == null)
  56. {
  57. titleColumn = new TitleColumnDisplay
  58. {
  59. ColumnText = columnText
  60. ,
  61. Index = i
  62. ,
  63. Display = 1
  64. };
  65. }
  66. else {
  67. if (titleColumn.Index <= -99999)
  68. {
  69. titleColumn.Index = i;
  70. }
  71. }
  72. LYFZ.ComponentLibrary.CheckBoxEx chk = chk = new CheckBoxEx();
  73. chk.Tag = titleColumn;
  74. chk.Text = columnText;
  75. chk.Name = columnText;
  76. chk.Width = 200;
  77. chk.Checked = !this._TitleColumnDisplayList.Any(t=>t.ColumnText.ToLower()== columnText.ToLower()&&t.Display==0);
  78. if (this.enabledList.Any(n => n.ToLower() == columnText.ToLower()))
  79. {
  80. chk.Enabled = false;
  81. chk.Checked = true;
  82. }
  83. this.flowLayoutPanel1.Controls.Add(chk);
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// 还原初始设置
  89. /// </summary>
  90. /// <param name="sender"></param>
  91. /// <param name="e"></param>
  92. void btnRevert_Click(object sender, EventArgs e)
  93. {
  94. if (MessageBoxCustom.Show("您确定要重置为初始设置吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  95. {
  96. return;
  97. }
  98. /* List<TitleColumnDisplay> TempTitleColumnDisplayList = new List<TitleColumnDisplay>();
  99. foreach (Control control in this.flowLayoutPanel1.Controls)
  100. {
  101. if (control is CheckBoxEx)
  102. {
  103. CheckBoxEx tmp = (CheckBoxEx)control;
  104. tmp.Checked = true;
  105. TitleColumnDisplay titleColumn = (TitleColumnDisplay)tmp.Tag;
  106. titleColumn.Display = 1;
  107. TempTitleColumnDisplayList.Add(titleColumn);
  108. }
  109. }*/
  110. //if (!LYFZ.DAL.DAL_GridViewDisplayIndex.UpdateGridViewDisplayIndexModel(this.dgvUserEmployeeID, this.dgvGuidName, TitleColumnDisplay.ToTitleColumnDisplayJsonData(TempTitleColumnDisplayList), LYFZ.DAL.DAL_GridViewDisplayIndex.StrVersionNumber))
  111. if(!LYFZ.DAL.DAL_GridViewDisplayIndex.DeleteGridViewDisplayIndexModel(this.dgvUserEmployeeID, this.dgvGuidName))
  112. {
  113. MessageBoxCustom.Show("重置失败!");
  114. return;
  115. }
  116. MessageBoxCustom.Show("重置成功!");
  117. this.DialogResult = DialogResult.OK;
  118. }
  119. /// <summary>
  120. /// 保存
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. void btnSaveed_Click(object sender, EventArgs e)
  125. {
  126. List<TitleColumnDisplay> TempTitleColumnDisplayList = new List<TitleColumnDisplay>();
  127. foreach (Control control in this.flowLayoutPanel1.Controls)
  128. {
  129. if (control is CheckBoxEx)
  130. {
  131. CheckBoxEx tmp = (CheckBoxEx)control;
  132. TitleColumnDisplay titleColumn = (TitleColumnDisplay)tmp.Tag;
  133. if (tmp.Checked)
  134. {
  135. titleColumn.Display = 1;
  136. }
  137. else {
  138. titleColumn.Display = 0;
  139. }
  140. TempTitleColumnDisplayList.Add(titleColumn);
  141. }
  142. }
  143. if (!LYFZ.DAL.DAL_GridViewDisplayIndex.UpdateGridViewDisplayIndexModel(this.dgvUserEmployeeID, this.dgvGuidName, TitleColumnDisplay.ToTitleColumnDisplayJsonData(TempTitleColumnDisplayList), LYFZ.DAL.DAL_GridViewDisplayIndex.StrVersionNumber))
  144. {
  145. MessageBoxCustom.Show("保存失败!");
  146. return;
  147. }
  148. MessageBoxCustom.Show("保存成功!");
  149. this.DialogResult = DialogResult.OK;
  150. }
  151. /// <summary>
  152. /// 取消
  153. /// </summary>
  154. /// <param name="sender"></param>
  155. /// <param name="e"></param>
  156. void btnCancel_Click(object sender, EventArgs e)
  157. {
  158. this.DialogResult = DialogResult.Cancel;
  159. }
  160. }
  161. }