ParticleClassificationSelect.cs 5.8 KB

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