ParticleClassificationSelect.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using OTSIncAReportApp.DataOperation.DataAccess;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using static DevExpress.Diagram.Core.Native.Either;
  12. namespace OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage
  13. {
  14. public partial class ParticleClassificationSelect : Form
  15. {
  16. ParticleData Particledata;
  17. string[] ParticleClassificationSelectedList;
  18. public string ParticleClassificationSelected
  19. {
  20. get;
  21. set;
  22. }
  23. public ParticleClassificationSelect(ParticleData a_Particledata, string a_ParticleClassificationSelected)
  24. {
  25. InitializeComponent();
  26. Particledata = a_Particledata;
  27. ParticleClassificationSelectedList = a_ParticleClassificationSelected.Split('$');
  28. }
  29. private void ParticleClassificationSelect_Load(object sender, EventArgs e)
  30. {
  31. DataTable table = Particledata.GetClassificationOfAllParticles();
  32. //for (int i = 0; i < 30; i++)
  33. //{
  34. // DataRow row = table.NewRow();
  35. // row["TypeName"] = "aa" + i.ToString();
  36. // table.Rows.Add(row);
  37. //}
  38. if (table != null)
  39. {
  40. if (table.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(20, 10, 20, 25);
  48. panel1.Controls.Add(flowLayoutPanel);
  49. foreach (DataRow it in table.Rows)
  50. {
  51. // 添加控件到 FlowLayoutPanel 中
  52. CheckBox box1 = new CheckBox();
  53. box1.Text = it["TypeName"].ToString();
  54. box1.Width = flowLayoutPanel.Width-40;
  55. box1.Height = 25;
  56. Font font= new Font("宋体", 15, FontStyle.Regular);
  57. box1.Font = font;
  58. if (ParticleClassificationSelectedList != null)
  59. {
  60. if (ParticleClassificationSelectedList.Contains(box1.Text))
  61. {
  62. box1.Checked = true;
  63. }
  64. else
  65. {
  66. box1.Checked = false;
  67. }
  68. }
  69. else
  70. {
  71. box1.Checked = false;
  72. }
  73. flowLayoutPanel.Controls.Add(box1);
  74. }
  75. if (ParticleClassificationSelectedList.Count() == table.Rows.Count)
  76. {
  77. this.checkBox_selall.CheckedChanged -= new System.EventHandler(this.checkBox_selall_CheckedChanged);
  78. checkBox_selall.Checked = true;
  79. this.checkBox_selall.CheckedChanged += new System.EventHandler(this.checkBox_selall_CheckedChanged);
  80. }
  81. }
  82. }
  83. }
  84. private void btn_ok_Click(object sender, EventArgs e)
  85. {
  86. ParticleClassificationSelected = "";
  87. foreach (Control control in panel1.Controls)
  88. {
  89. if (control.GetType() == typeof(FlowLayoutPanel))
  90. {
  91. foreach (Control control1 in control.Controls)
  92. {
  93. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  94. {
  95. if (((CheckBox)control1).Checked)
  96. {
  97. ParticleClassificationSelected += control1.Text+ "$";
  98. }
  99. }
  100. }
  101. }
  102. }
  103. if(ParticleClassificationSelected!="")
  104. {
  105. ParticleClassificationSelected = ParticleClassificationSelected.Remove(ParticleClassificationSelected.Length - 1);
  106. }
  107. this.DialogResult = DialogResult.OK;
  108. this.Close();
  109. }
  110. private void btn_cannel_Click(object sender, EventArgs e)
  111. {
  112. this.DialogResult = DialogResult.Cancel;
  113. this.Close();
  114. }
  115. private void ParticleClassificationSelect_FormClosing(object sender, FormClosingEventArgs e)
  116. {
  117. this.Close();
  118. }
  119. private void checkBox_selall_CheckedChanged(object sender, EventArgs e)
  120. {
  121. if(checkBox_selall.Checked)
  122. {
  123. foreach (Control control in panel1.Controls)
  124. {
  125. if (control.GetType() == typeof(FlowLayoutPanel))
  126. {
  127. foreach (Control control1 in control.Controls)
  128. {
  129. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  130. {
  131. ((CheckBox)control1).Checked = true;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. else
  138. {
  139. foreach (Control control in panel1.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. ((CheckBox)control1).Checked = false;
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }