ParticleClassificationSelect.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. }
  66. }
  67. }
  68. private void btn_ok_Click(object sender, EventArgs e)
  69. {
  70. ParticleClassificationSelected = "";
  71. foreach (Control control in panel1.Controls)
  72. {
  73. if (control.GetType() == typeof(FlowLayoutPanel))
  74. {
  75. foreach (Control control1 in control.Controls)
  76. {
  77. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  78. {
  79. if (((CheckBox)control1).Checked)
  80. {
  81. ParticleClassificationSelected += control1.Text+ "$";
  82. }
  83. }
  84. }
  85. }
  86. }
  87. if(ParticleClassificationSelected!="")
  88. {
  89. ParticleClassificationSelected = ParticleClassificationSelected.Remove(ParticleClassificationSelected.Length - 1);
  90. }
  91. this.DialogResult = DialogResult.OK;
  92. this.Close();
  93. }
  94. private void btn_cannel_Click(object sender, EventArgs e)
  95. {
  96. this.DialogResult = DialogResult.Cancel;
  97. this.Close();
  98. }
  99. private void ParticleClassificationSelect_FormClosing(object sender, FormClosingEventArgs e)
  100. {
  101. this.Close();
  102. }
  103. private void checkBox_selall_CheckedChanged(object sender, EventArgs e)
  104. {
  105. if(checkBox_selall.Checked)
  106. {
  107. foreach (Control control in panel1.Controls)
  108. {
  109. if (control.GetType() == typeof(FlowLayoutPanel))
  110. {
  111. foreach (Control control1 in control.Controls)
  112. {
  113. if (control1.GetType() == typeof(System.Windows.Forms.CheckBox))
  114. {
  115. ((CheckBox)control1).Checked = true;
  116. }
  117. }
  118. }
  119. }
  120. }
  121. else
  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 = false;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }