Category.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. private DataTable ResultLibrary = new DataTable();//测量结果库
  28. public Category(List<string> a_ElementList,DataTable AllList,bool a_Remove,DataTable a_ResultLibrary)
  29. {
  30. InitializeComponent();
  31. ElementList = AllList.Copy();
  32. CheckTheOptions = a_ElementList.Copy();
  33. OutElementList = a_ElementList.Copy();
  34. isRemove = a_Remove;
  35. ResultLibrary = a_ResultLibrary.Copy();
  36. #region 国际化语言
  37. OTSCommon.Language lan = new OTSCommon.Language(this);
  38. table = lan.GetNameTable(this.Name);
  39. #endregion
  40. }
  41. //public Category(List<string> a_ElementList,DataTable AllList, bool a_Remove)
  42. //{
  43. // ElementList = AllList;
  44. // isRemove = a_Remove;
  45. // InitializeComponent();
  46. //}
  47. private void Category_Load(object sender, EventArgs e)
  48. {
  49. if (ElementList != null)
  50. {
  51. if (ElementList.Rows.Count > 0)
  52. {
  53. FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel();
  54. flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight;
  55. flowLayoutPanel.WrapContents = true;
  56. flowLayoutPanel.Dock = DockStyle.Fill;
  57. flowLayoutPanel.AutoScroll = true;
  58. flowLayoutPanel.Padding = new Padding(20, 10, 20, 25);
  59. panel2.Controls.Add(flowLayoutPanel);
  60. for (int i = 0; i < ElementList.Rows.Count; i++)
  61. {
  62. // 添加控件到 FlowLayoutPanel 中
  63. CheckBox box1 = new CheckBox();
  64. box1.Text = ElementList.Rows[i]["StrName"].ToString();
  65. box1.Width = flowLayoutPanel.Width - 40;
  66. box1.Height = 25;
  67. Font font = new Font("宋体", 15, FontStyle.Regular);
  68. box1.Font = font;
  69. if (CheckTheOptions.Count == 0)
  70. {
  71. if (!isRemove)
  72. box1.Checked = true;
  73. else
  74. box1.Checked = false;
  75. }
  76. else
  77. {
  78. for (int a = 0; a < CheckTheOptions.Count; a++)
  79. {
  80. if (ElementList.Rows[i]["STDId"].ToString() == CheckTheOptions[a].ToString())
  81. box1.Checked = true;
  82. }
  83. }
  84. flowLayoutPanel.Controls.Add(box1);
  85. }
  86. if (ResultLibrary.Rows.Count > 0)
  87. {
  88. for (int i = 0; i < ResultLibrary.Rows.Count; i++)
  89. {
  90. // 添加控件到 FlowLayoutPanel 中
  91. CheckBox box1 = new CheckBox();
  92. box1.Text = ResultLibrary.Rows[i][1].ToString();
  93. box1.Width = flowLayoutPanel.Width - 40;
  94. box1.Height = 25;
  95. Font font = new Font("宋体", 15, FontStyle.Regular);
  96. box1.Font = font;
  97. if (CheckTheOptions.Count == 0)
  98. {
  99. if (!isRemove)
  100. box1.Checked = true;
  101. else
  102. box1.Checked = false;
  103. }
  104. else
  105. {
  106. for (int a = 0; a < CheckTheOptions.Count; a++)
  107. {
  108. if (ResultLibrary.Rows[i][0].ToString() == CheckTheOptions[a].ToString())
  109. box1.Checked = true;
  110. }
  111. }
  112. flowLayoutPanel.Controls.Add(box1);
  113. }
  114. }
  115. Panel panel = new Panel();
  116. panel.Size = new Size(10, 10);
  117. panel.BackColor = Color.Transparent;
  118. flowLayoutPanel.Controls.Add(panel);
  119. this.checkBox_selall.CheckedChanged -= new System.EventHandler(this.checkBox_selall_CheckedChanged);
  120. checkBox_selall.Checked = true;
  121. this.checkBox_selall.CheckedChanged += new System.EventHandler(this.checkBox_selall_CheckedChanged);
  122. }
  123. }
  124. }
  125. private void checkBox_selall_CheckedChanged(object sender, EventArgs e)
  126. {
  127. if (checkBox_selall.Checked)
  128. {
  129. foreach (Control control in panel2.Controls)
  130. {
  131. if (control.GetType() == typeof(FlowLayoutPanel))
  132. {
  133. foreach (Control control1 in control.Controls)
  134. {
  135. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  136. {
  137. ((CheckBox)control1).Checked = true;
  138. }
  139. }
  140. }
  141. }
  142. }
  143. else
  144. {
  145. foreach (Control control in panel2.Controls)
  146. {
  147. if (control.GetType() == typeof(FlowLayoutPanel))
  148. {
  149. foreach (Control control1 in control.Controls)
  150. {
  151. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  152. {
  153. ((CheckBox)control1).Checked = false;
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. /// <summary>
  161. /// 确定按钮
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void button3_Click(object sender, EventArgs e)
  166. {
  167. OutElementList.Clear();
  168. vs.Clear();
  169. List<bool> blList = new List<bool>();
  170. foreach (Control control in panel2.Controls)
  171. {
  172. if (control.GetType() == typeof(FlowLayoutPanel))
  173. {
  174. foreach (Control control1 in control.Controls)
  175. {
  176. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  177. {
  178. if (((CheckBox)control1).Checked)
  179. {
  180. blList.Add(true);
  181. OutElementList.Add(control1.Text);
  182. }
  183. else
  184. {
  185. blList.Add(false);
  186. }
  187. }
  188. }
  189. }
  190. }
  191. for (int i=0;i < ElementList.Rows.Count; i++)
  192. {
  193. if(blList[i])
  194. {
  195. vs.Add(ElementList.Rows[i]["STDId"].ToString());
  196. }
  197. }
  198. for (int i = 0; i < ResultLibrary.Rows.Count; i++)
  199. {
  200. if (blList[i])
  201. {
  202. vs.Add(ResultLibrary.Rows[i][0].ToString());
  203. }
  204. }
  205. IsModify = true;
  206. this.Close();
  207. }
  208. /// <summary>
  209. /// 取消按钮
  210. /// </summary>
  211. /// <param name="sender"></param>
  212. /// <param name="e"></param>
  213. private void button4_Click(object sender, EventArgs e)
  214. {
  215. vs.Clear();
  216. vs= CheckTheOptions.Copy();
  217. OutElementList.Clear();
  218. for (int i = 0; i < ElementList.Rows.Count; i++)
  219. {
  220. for (int a = 0; a < CheckTheOptions.Count; a++)
  221. {
  222. if (CheckTheOptions[a] == ElementList.Rows[i]["STDId"].ToString())
  223. {
  224. OutElementList.Add(ElementList.Rows[i]["StrName"].ToString());
  225. }
  226. }
  227. }
  228. this.Close();
  229. }
  230. }
  231. }