Category.cs 7.2 KB

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