DataGridViewSetColumn.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. namespace LYFZ.ComponentLibrary
  11. {
  12. public partial class DataGridViewSetColumn : LYFZ.ComponentLibrary.BaseContentsFormMain
  13. {
  14. public DataGridViewSetColumn()
  15. {
  16. InitializeComponent();
  17. this.panelEx1.BackColor = UIBlueThemeResources.AreaBackgroundColor;
  18. this.panelEx1.BorderColor = UIBlueThemeResources.BorderAreaColor;
  19. this.panelEx1.BorderStyle = BorderStyle.FixedSingle;
  20. this.Load += DataGridViewSetColumn_Load;
  21. this.btnRevert.Click += btnRevert_Click;
  22. this.btnSaveed.Click += btnSaveed_Click;
  23. this.btnCancel.Click += btnCancel_Click;
  24. }
  25. /// <summary>
  26. /// DataGridView列表参数
  27. /// </summary>
  28. public LYFZ.ComponentLibrary.DataGridViewEc dgvNewData = new DataGridViewEc();
  29. /// <summary>
  30. /// 是否保存
  31. /// </summary>
  32. public bool IsSaveed = false;
  33. /// <summary>
  34. /// 不可操作字段
  35. /// </summary>
  36. public List<string> listEnabled = new List<string>();
  37. /// <summary>
  38. /// 窗体加载事件
  39. /// </summary>
  40. /// <param name="sender"></param>
  41. /// <param name="e"></param>
  42. void DataGridViewSetColumn_Load(object sender, EventArgs e)
  43. {
  44. this.listEnabled.Add("订单类型");
  45. this.listEnabled.Add("拍摄名称");
  46. List<string> listOriginalColumn = new List<string>(this.dgvNewData.dgvCurrentColumnOriginalSet.Trim().Split(','));
  47. List<string> listHideColumn = new List<string>(this.dgvNewData.dgvFixedHideColumn.Trim().Split(','));
  48. LYFZ.ComponentLibrary.CheckBoxEx chk = null;
  49. for (int i = 0; i < listOriginalColumn.Count; i++)
  50. {
  51. if (!string.IsNullOrEmpty(listOriginalColumn[i].Trim()))
  52. {
  53. chk = new CheckBoxEx();
  54. chk.Text = listOriginalColumn[i].Trim();
  55. chk.Name = listOriginalColumn[i].Trim();
  56. chk.Width = 200;
  57. chk.Checked = this.dgvNewData.dictShowColumName.Keys.Contains(listOriginalColumn[i].Trim());
  58. if (chk.Checked)
  59. {
  60. chk.Tag = this.dgvNewData.dictShowColumName[listOriginalColumn[i].Trim()].ToString().Trim();
  61. }
  62. else
  63. {
  64. chk.Tag = "100";
  65. }
  66. if (listHideColumn.Contains(listOriginalColumn[i].Trim()))
  67. {
  68. chk.Visible = false;
  69. }
  70. this.flowLayoutPanel1.Controls.Add(chk);
  71. }
  72. }
  73. for (int i = 0; i < this.dgvNewData.Columns.Count; i++)
  74. {
  75. if (this.dgvNewData.Columns[i].Frozen)
  76. { this.listEnabled.Add(this.dgvNewData.Columns[i].Name.Trim()); }
  77. }
  78. //设置不可点的
  79. foreach (Control control in this.flowLayoutPanel1.Controls)
  80. {
  81. if (control is CheckBoxEx)
  82. {
  83. CheckBoxEx tmp = (CheckBoxEx)control;
  84. if (this.listEnabled.Contains(tmp.Text.Trim()))
  85. { tmp.Enabled = false; }
  86. }
  87. }
  88. //for (int i = 0; i < this.dgvNewData.Columns.Count; i++)
  89. //{
  90. // if (this.dgvNewData.Columns[i].Frozen)
  91. // {
  92. // foreach (Control control in this.flowLayoutPanel1.Controls)
  93. // {
  94. // if (control is CheckBoxEx)
  95. // {
  96. // CheckBoxEx tmp = (CheckBoxEx)control;
  97. // if (tmp.Text.Trim().Equals(this.dgvNewData.Columns[i].Name.Trim()))
  98. // { tmp.Enabled = false; }
  99. // }
  100. // }
  101. // }
  102. //}
  103. }
  104. /// <summary>
  105. /// 还原初始设置
  106. /// </summary>
  107. /// <param name="sender"></param>
  108. /// <param name="e"></param>
  109. void btnRevert_Click(object sender, EventArgs e)
  110. {
  111. if (MessageBoxCustom.Show("您确定要重置为初始设置吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  112. { return; }
  113. /* string StrValue = "";
  114. foreach (Control control in this.flowLayoutPanel1.Controls)
  115. {
  116. if (control is CheckBoxEx)
  117. {
  118. CheckBoxEx tmp = (CheckBoxEx)control;
  119. StrValue += tmp.Text.Trim() + ":" + tmp.Tag.ToString().Trim() + "|";
  120. }
  121. }
  122. if (!LYFZ.DAL.DAL_GridViewDisplayIndex.UpdateGridViewDisplayIndexModel(this.dgvNewData.dgvUserEmployeeID, this.dgvNewData.dgvGuidName, StrValue, LYFZ.DAL.DAL_GridViewDisplayIndex.StrVersionNumber))
  123. */
  124. if (!LYFZ.DAL.DAL_GridViewDisplayIndex.DeleteGridViewDisplayIndexModel(this.dgvNewData.dgvUserEmployeeID, this.dgvNewData.dgvGuidName))
  125. { MessageBoxCustom.Show("重置失败!"); return; }
  126. this.IsSaveed = true;
  127. MessageBoxCustom.Show("重置成功!");
  128. this.Close();
  129. }
  130. /// <summary>
  131. /// 保存
  132. /// </summary>
  133. /// <param name="sender"></param>
  134. /// <param name="e"></param>
  135. void btnSaveed_Click(object sender, EventArgs e)
  136. {
  137. string StrValue = "";
  138. foreach (Control control in this.flowLayoutPanel1.Controls)
  139. {
  140. if (control is CheckBoxEx)
  141. {
  142. CheckBoxEx tmp = (CheckBoxEx)control;
  143. if (tmp.Checked || !tmp.Visible)
  144. { StrValue += tmp.Text.Trim() + ":" + tmp.Tag.ToString().Trim() + "|"; }
  145. }
  146. }
  147. if (!LYFZ.DAL.DAL_GridViewDisplayIndex.UpdateGridViewDisplayIndexModel(this.dgvNewData.dgvUserEmployeeID, this.dgvNewData.dgvGuidName, StrValue, LYFZ.DAL.DAL_GridViewDisplayIndex.StrVersionNumber))
  148. { MessageBoxCustom.Show("保存失败!"); return; }
  149. this.btnCancel.Text = " 关 闭";
  150. this.IsSaveed = true;
  151. MessageBoxCustom.Show("保存成功!");
  152. }
  153. /// <summary>
  154. /// 取消
  155. /// </summary>
  156. /// <param name="sender"></param>
  157. /// <param name="e"></param>
  158. void btnCancel_Click(object sender, EventArgs e)
  159. { this.Close(); }
  160. }
  161. }