Category.cs 6.0 KB

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