ParticleClassificationSelect.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. namespace OTSIncAReportApp._1_UI.Control_Grids.ParticlesGridDevidePage
  12. {
  13. public partial class ParticleClassificationSelect : Form
  14. {
  15. ParticleData Particledata;
  16. string[] ParticleClassificationSelectedList;
  17. public string ParticleClassificationSelected
  18. {
  19. get;
  20. set;
  21. }
  22. public ParticleClassificationSelect(ParticleData a_Particledata, string a_ParticleClassificationSelected)
  23. {
  24. InitializeComponent();
  25. Particledata = a_Particledata;
  26. ParticleClassificationSelectedList = a_ParticleClassificationSelected.Split('$');
  27. }
  28. private void ParticleClassificationSelect_Load(object sender, EventArgs e)
  29. {
  30. DataTable table = Particledata.GetClassificationOfAllParticles();
  31. if (table != null)
  32. {
  33. if (table.Rows.Count > 0)
  34. {
  35. FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel();
  36. flowLayoutPanel.FlowDirection = FlowDirection.LeftToRight;
  37. flowLayoutPanel.WrapContents = true;
  38. flowLayoutPanel.Dock = DockStyle.Fill;
  39. flowLayoutPanel.AutoScroll = true;
  40. flowLayoutPanel.Padding = new Padding(15);
  41. panel1.Controls.Add(flowLayoutPanel);
  42. foreach (DataRow it in table.Rows)
  43. {
  44. // 添加控件到 FlowLayoutPanel 中
  45. CheckBox box1 = new CheckBox();
  46. box1.Text = it["TypeName"].ToString();
  47. box1.Width = flowLayoutPanel.Width-30;
  48. if (ParticleClassificationSelectedList != null)
  49. {
  50. if (ParticleClassificationSelectedList.Contains(box1.Text))
  51. {
  52. box1.Checked = true;
  53. }
  54. else
  55. {
  56. box1.Checked = false;
  57. }
  58. }
  59. else
  60. {
  61. box1.Checked = false;
  62. }
  63. flowLayoutPanel.Controls.Add(box1);
  64. }
  65. if (ParticleClassificationSelectedList.Count() == table.Rows.Count)
  66. {
  67. this.checkBox_selall.CheckedChanged -= new System.EventHandler(this.checkBox_selall_CheckedChanged);
  68. checkBox_selall.Checked = true;
  69. this.checkBox_selall.CheckedChanged += new System.EventHandler(this.checkBox_selall_CheckedChanged);
  70. }
  71. }
  72. }
  73. }
  74. private void btn_ok_Click(object sender, EventArgs e)
  75. {
  76. ParticleClassificationSelected = "";
  77. foreach (Control control in panel1.Controls)
  78. {
  79. if (control.GetType() == typeof(FlowLayoutPanel))
  80. {
  81. foreach (Control control1 in control.Controls)
  82. {
  83. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  84. {
  85. if (((CheckBox)control1).Checked)
  86. {
  87. ParticleClassificationSelected += control1.Text+ "$";
  88. }
  89. }
  90. }
  91. }
  92. }
  93. if(ParticleClassificationSelected!="")
  94. {
  95. ParticleClassificationSelected = ParticleClassificationSelected.Remove(ParticleClassificationSelected.Length - 1);
  96. }
  97. this.DialogResult = DialogResult.OK;
  98. this.Close();
  99. }
  100. private void btn_cannel_Click(object sender, EventArgs e)
  101. {
  102. this.DialogResult = DialogResult.Cancel;
  103. this.Close();
  104. }
  105. private void ParticleClassificationSelect_FormClosing(object sender, FormClosingEventArgs e)
  106. {
  107. this.Close();
  108. }
  109. private void checkBox_selall_CheckedChanged(object sender, EventArgs e)
  110. {
  111. if(checkBox_selall.Checked)
  112. {
  113. foreach (Control control in panel1.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 = true;
  122. }
  123. }
  124. }
  125. }
  126. }
  127. else
  128. {
  129. foreach (Control control in panel1.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 = false;
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }