Category.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using SourceGrid;
  2. using System;
  3. using System.Collections;
  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. namespace OTSIncAReportApp._1_UI.OTSReportExport
  13. {
  14. public partial class Category : Form
  15. {
  16. List<string> CheckTheOptions = new List<string>();
  17. DataTable ElementList = new DataTable();
  18. public List<string> OutElementList = new List<string>();
  19. /// <summary>
  20. /// 窗体是否修改
  21. /// </summary>
  22. public bool IsModify = false;
  23. public List<string> vs = new List<string>();
  24. private bool isRemove = false;
  25. Hashtable table;
  26. public Category(List<string> a_ElementList,DataTable AllList,bool a_Remove)
  27. {
  28. InitializeComponent();
  29. ElementList = AllList;
  30. CheckTheOptions = a_ElementList;
  31. OutElementList = a_ElementList;
  32. isRemove = a_Remove;
  33. #region 国际化语言
  34. OTSCommon.Language lan = new OTSCommon.Language(this);
  35. table = lan.GetNameTable(this.Name);
  36. #endregion
  37. }
  38. //public Category(List<string> a_ElementList,DataTable AllList, bool a_Remove)
  39. //{
  40. // ElementList = AllList;
  41. // isRemove = a_Remove;
  42. // InitializeComponent();
  43. //}
  44. private void Category_Load(object sender, EventArgs e)
  45. {
  46. if (ElementList != null)
  47. {
  48. if (ElementList.Rows.Count > 0)
  49. {
  50. FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel();
  51. flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight;
  52. flowLayoutPanel.WrapContents = true;
  53. flowLayoutPanel.Dock = DockStyle.Fill;
  54. flowLayoutPanel.AutoScroll = true;
  55. flowLayoutPanel.Padding = new Padding(15);
  56. panel2.Controls.Add(flowLayoutPanel);
  57. for (int i = 0; i < ElementList.Rows.Count; i++)
  58. {
  59. // 添加控件到 FlowLayoutPanel 中
  60. CheckBox box1 = new CheckBox();
  61. box1.Text = ElementList.Rows[i]["StrName"].ToString();
  62. box1.Width = flowLayoutPanel.Width - 30;
  63. if (CheckTheOptions.Count == 0)
  64. {
  65. if (!isRemove)
  66. box1.Checked = true;
  67. else
  68. box1.Checked = false;
  69. }
  70. else
  71. {
  72. for (int a = 0; a < CheckTheOptions.Count; a++)
  73. {
  74. if (ElementList.Rows[i]["STDId"].ToString() == CheckTheOptions[a].ToString())
  75. box1.Checked = true;
  76. }
  77. }
  78. flowLayoutPanel.Controls.Add(box1);
  79. }
  80. this.checkBox_selall.CheckedChanged -= new System.EventHandler(this.checkBox_selall_CheckedChanged);
  81. checkBox_selall.Checked = true;
  82. this.checkBox_selall.CheckedChanged += new System.EventHandler(this.checkBox_selall_CheckedChanged);
  83. }
  84. }
  85. }
  86. private void checkBox_selall_CheckedChanged(object sender, EventArgs e)
  87. {
  88. if (checkBox_selall.Checked)
  89. {
  90. foreach (Control control in panel2.Controls)
  91. {
  92. if (control.GetType() == typeof(FlowLayoutPanel))
  93. {
  94. foreach (Control control1 in control.Controls)
  95. {
  96. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  97. {
  98. ((CheckBox)control1).Checked = true;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. else
  105. {
  106. foreach (Control control in panel2.Controls)
  107. {
  108. if (control.GetType() == typeof(FlowLayoutPanel))
  109. {
  110. foreach (Control control1 in control.Controls)
  111. {
  112. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  113. {
  114. ((CheckBox)control1).Checked = false;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }
  121. /// <summary>
  122. /// 确定按钮
  123. /// </summary>
  124. /// <param name="sender"></param>
  125. /// <param name="e"></param>
  126. private void button3_Click(object sender, EventArgs e)
  127. {
  128. OutElementList.Clear();
  129. vs.Clear();
  130. List<bool> blList = new List<bool>();
  131. foreach (Control control in panel2.Controls)
  132. {
  133. if (control.GetType() == typeof(FlowLayoutPanel))
  134. {
  135. foreach (Control control1 in control.Controls)
  136. {
  137. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  138. {
  139. if (((CheckBox)control1).Checked)
  140. {
  141. blList.Add(true);
  142. OutElementList.Add(control1.Text);
  143. }
  144. else
  145. {
  146. blList.Add(false);
  147. }
  148. }
  149. }
  150. }
  151. }
  152. for (int i=0;i < ElementList.Rows.Count; i++)
  153. {
  154. if(blList[i])
  155. {
  156. vs.Add(ElementList.Rows[i]["STDId"].ToString());
  157. }
  158. }
  159. IsModify = true;
  160. this.Close();
  161. }
  162. /// <summary>
  163. /// 取消按钮
  164. /// </summary>
  165. /// <param name="sender"></param>
  166. /// <param name="e"></param>
  167. private void button4_Click(object sender, EventArgs e)
  168. {
  169. this.Close();
  170. }
  171. }
  172. }