Category.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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(20, 10, 20, 25);
  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 - 40;
  63. box1.Height = 25;
  64. Font font = new Font("宋体", 15, FontStyle.Regular);
  65. box1.Font = font;
  66. if (CheckTheOptions.Count == 0)
  67. {
  68. if (!isRemove)
  69. box1.Checked = true;
  70. else
  71. box1.Checked = false;
  72. }
  73. else
  74. {
  75. for (int a = 0; a < CheckTheOptions.Count; a++)
  76. {
  77. if (ElementList.Rows[i]["STDId"].ToString() == CheckTheOptions[a].ToString())
  78. box1.Checked = true;
  79. }
  80. }
  81. flowLayoutPanel.Controls.Add(box1);
  82. }
  83. Panel panel = new Panel();
  84. panel.Size = new Size(10, 10);
  85. panel.BackColor = Color.Transparent;
  86. flowLayoutPanel.Controls.Add(panel);
  87. this.checkBox_selall.CheckedChanged -= new System.EventHandler(this.checkBox_selall_CheckedChanged);
  88. checkBox_selall.Checked = true;
  89. this.checkBox_selall.CheckedChanged += new System.EventHandler(this.checkBox_selall_CheckedChanged);
  90. }
  91. }
  92. }
  93. private void checkBox_selall_CheckedChanged(object sender, EventArgs e)
  94. {
  95. if (checkBox_selall.Checked)
  96. {
  97. foreach (Control control in panel2.Controls)
  98. {
  99. if (control.GetType() == typeof(FlowLayoutPanel))
  100. {
  101. foreach (Control control1 in control.Controls)
  102. {
  103. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  104. {
  105. ((CheckBox)control1).Checked = true;
  106. }
  107. }
  108. }
  109. }
  110. }
  111. else
  112. {
  113. foreach (Control control in panel2.Controls)
  114. {
  115. if (control.GetType() == typeof(FlowLayoutPanel))
  116. {
  117. foreach (Control control1 in control.Controls)
  118. {
  119. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  120. {
  121. ((CheckBox)control1).Checked = false;
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. /// <summary>
  129. /// 确定按钮
  130. /// </summary>
  131. /// <param name="sender"></param>
  132. /// <param name="e"></param>
  133. private void button3_Click(object sender, EventArgs e)
  134. {
  135. OutElementList.Clear();
  136. vs.Clear();
  137. List<bool> blList = new List<bool>();
  138. foreach (Control control in panel2.Controls)
  139. {
  140. if (control.GetType() == typeof(FlowLayoutPanel))
  141. {
  142. foreach (Control control1 in control.Controls)
  143. {
  144. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  145. {
  146. if (((CheckBox)control1).Checked)
  147. {
  148. blList.Add(true);
  149. OutElementList.Add(control1.Text);
  150. }
  151. else
  152. {
  153. blList.Add(false);
  154. }
  155. }
  156. }
  157. }
  158. }
  159. for (int i=0;i < ElementList.Rows.Count; i++)
  160. {
  161. if(blList[i])
  162. {
  163. vs.Add(ElementList.Rows[i]["STDId"].ToString());
  164. }
  165. }
  166. IsModify = true;
  167. this.Close();
  168. }
  169. /// <summary>
  170. /// 取消按钮
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void button4_Click(object sender, EventArgs e)
  175. {
  176. this.Close();
  177. }
  178. }
  179. }