MainForm.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace OTSExtremum
  12. {
  13. public partial class MainForm : Form
  14. {
  15. public MainForm()
  16. {
  17. InitializeComponent();
  18. }
  19. int groupCount = 0;
  20. GroupBox gp;
  21. /// <summary>
  22. /// 添加颗粒直径
  23. /// </summary>
  24. /// <param name="sender"></param>
  25. /// <param name="e"></param>
  26. private void btnAddValue_Click(object sender, EventArgs e)
  27. {
  28. string size = txtParticle.Text;
  29. if (!Business.Tools.IsIntOrDouble(size))
  30. {
  31. MessageBox.Show("请输入数字!");
  32. return;
  33. }
  34. if (gp == null)
  35. {
  36. MessageBox.Show("请添加分组!");
  37. btnGroup_Click(null, null);
  38. return;
  39. }
  40. Panel panel = (Panel)gp.Controls[0];
  41. CheckBox checkBox = new CheckBox();
  42. checkBox.Text = size;
  43. checkBox.Tag = Convert.ToDouble(size);
  44. checkBox.Width = 80;
  45. int chkcount = panel.Controls.Count;
  46. int row = chkcount / 10;
  47. int col = chkcount % 10;
  48. checkBox.Location = new Point(10 + col * 80, row * 35);
  49. panel.Controls.Add(checkBox);
  50. chkcount = chkcount+1;
  51. }
  52. /// <summary>
  53. /// 添加测量结果文件
  54. /// </summary>
  55. /// <param name="sender"></param>
  56. /// <param name="e"></param>
  57. private void btnAddFile_Click(object sender, EventArgs e)
  58. {
  59. if (gp == null)
  60. {
  61. MessageBox.Show("请添加分组!");
  62. btnGroup_Click(null, null);
  63. return;
  64. }
  65. Panel panel = (Panel)gp.Controls[0];
  66. OpenFileDialog fileDialog = new OpenFileDialog();
  67. fileDialog.Multiselect = true;
  68. fileDialog.Title = "请选择测量结果文件";
  69. fileDialog.Filter = "所有文件(*rst*)|*.rst*"; //设置要选择的文件的类型
  70. if (fileDialog.ShowDialog() == DialogResult.OK)
  71. {
  72. string file = fileDialog.FileName;//返回文件的完整路径
  73. string path = System.IO.Path.GetDirectoryName(file);
  74. double[] list = Business.Classify.getClass(path);
  75. int sel = cobType.SelectedIndex;
  76. CheckBox checkBox = new CheckBox();
  77. checkBox.Text =Math.Round( list[sel],2).ToString();
  78. checkBox.Tag = list;
  79. checkBox.Width = 80;
  80. // checkBox.Font = new Font(checkBox.Font.FontFamily, 8, checkBox.Font.Style);
  81. int chkcount = panel.Controls.Count;
  82. int row = chkcount / 10;
  83. int col = chkcount % 10;
  84. checkBox.Location = new Point(10 + col * 80, row * 35);
  85. panel.Controls.Add(checkBox);
  86. chkcount = chkcount + 1;
  87. }
  88. }
  89. /// <summary>
  90. /// 改变颗粒分类
  91. /// </summary>
  92. /// <param name="sender"></param>
  93. /// <param name="e"></param>
  94. private void cobType_SelectedIndexChanged(object sender, EventArgs e)
  95. {
  96. foreach (GroupBox group in panel1.Controls)
  97. {
  98. Panel panel = (Panel)group.Controls[0];
  99. int sel = cobType.SelectedIndex;
  100. foreach (var item in panel.Controls)
  101. {
  102. CheckBox check = (CheckBox)item;
  103. if (check.Tag.GetType().Name == "Double[]")
  104. {
  105. double[] list = (double[])check.Tag;
  106. check.Text = Math.Round(list[sel], 2).ToString();
  107. }
  108. }
  109. }
  110. }
  111. /// <summary>
  112. /// 删除颗粒
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void btnDel_Click(object sender, EventArgs e)
  117. {
  118. DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  119. if (dr == DialogResult.No)
  120. {
  121. return;
  122. }
  123. foreach (GroupBox group in panel1.Controls)
  124. {
  125. Panel panel = (Panel)group.Controls[0];
  126. for (int i = panel.Controls.Count - 1; i >= 0; i--)
  127. {
  128. CheckBox check = (CheckBox)panel.Controls[i];
  129. if (check.Checked)
  130. {
  131. panel.Controls.RemoveAt(i);
  132. }
  133. }
  134. int chkcount = panel.Controls.Count;
  135. int rows = 0;
  136. int cols = 0;
  137. for (int i = 0; i < chkcount; i++)
  138. {
  139. CheckBox check = (CheckBox)panel.Controls[i];
  140. check.Location = new Point(10 + cols * 80, rows * 35);
  141. cols++;
  142. if (cols == 10)
  143. {
  144. rows++;
  145. cols = 0;
  146. }
  147. }
  148. }
  149. }
  150. /// <summary>
  151. /// 检验数据有效性,是否位离群值
  152. /// </summary>
  153. /// <param name="sender"></param>
  154. /// <param name="e"></param>
  155. private void btnCheck_Click(object sender, EventArgs e)
  156. {
  157. foreach (GroupBox group in panel1.Controls)
  158. {
  159. Panel panel = (Panel)group.Controls[0];
  160. int chkcount = panel.Controls.Count;
  161. if (chkcount < 3)
  162. {
  163. MessageBox.Show("试验数据过少。");
  164. return;
  165. }
  166. double[] vs = new double[chkcount];
  167. double[] gg = { 140, 240, 532, 205, 150, 110, 200, 180, 220, 300, 70, 390, 100, 90, 320, 190, 250, 150, 280, 250, 490, 120, 500, 200 };
  168. for (int i = 0; i < chkcount; i++)
  169. {
  170. vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
  171. }
  172. int ret = Business.Tools.Grubbls(vs);
  173. if (ret == 0)
  174. {
  175. MessageBox.Show("试验数据有效。");
  176. }
  177. else if (ret == 1)
  178. {
  179. MessageBox.Show("最大的夹杂物长度值是离群值,试验数据无效。");
  180. }
  181. else if (ret == 2)
  182. {
  183. MessageBox.Show("最小的夹杂物长度值是离群值,试验数据无效。");
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// 极值分析
  189. /// </summary>
  190. /// <param name="sender"></param>
  191. /// <param name="e"></param>
  192. private void btnCompute_Click(object sender, EventArgs e)
  193. {
  194. if (panel1.Controls.Count > 1)
  195. {
  196. List<Business.groupInfo> list = new List<Business.groupInfo>();
  197. List<Business.groupInfo> list1 = new List<Business.groupInfo>() {
  198. new Business.groupInfo() { values=new double[] {85,25,30,35,40,45,50,55 },groupTitle="DL2" },
  199. new Business.groupInfo() { values=new double[] {30,10,12,14,16,18,20,25 },groupTitle="LF1" },
  200. new Business.groupInfo() { values=new double[] {30,0,5,8,20,25,10,15 },groupTitle="LF2" },
  201. new Business.groupInfo() { values=new double[] {25,10,12,14,18,20,22,24},groupTitle="VD1-2" },
  202. new Business.groupInfo() { values=new double[] {40,10,15,20,35,24,26,30 },groupTitle="VD2-2" },
  203. new Business.groupInfo() { values=new double[] {45,10,15,20,25,30,35,29 },groupTitle="VD3" },
  204. new Business.groupInfo() { values=new double[] {85,10,15,60,55,30,35,40},groupTitle="JZ" }
  205. };
  206. foreach (GroupBox group in panel1.Controls)
  207. {
  208. Panel panel = (Panel)group.Controls[0];
  209. int chkcount = panel.Controls.Count;
  210. if (chkcount < 3)
  211. {
  212. MessageBox.Show("试验数据过少。");
  213. return;
  214. }
  215. double[] vs = new double[chkcount];
  216. //double[] gg = { 140, 240, 532, 205, 150, 110, 200, 180, 220, 300, 70, 390, 100, 90, 320, 190, 250, 150, 280, 250, 490, 120, 500, 200 };
  217. for (int i = 0; i < chkcount; i++)
  218. {
  219. vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
  220. }
  221. int ret = Business.Tools.Grubbls(vs);
  222. if (ret != 0)
  223. {
  224. DialogResult dr = MessageBox.Show(group.Text+"试验数据存在离群值,是否继续分析?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  225. if (dr == DialogResult.No)
  226. {
  227. return;
  228. }
  229. }
  230. Business.groupInfo groupInfo = new Business.groupInfo();
  231. groupInfo.values = vs;
  232. groupInfo.groupTitle = group.Text;
  233. list.Add(groupInfo);
  234. //GridForm gridForm = new GridForm(gg, group.Text);
  235. //gridForm.Show();
  236. }
  237. GroupsGridForm groupsGridForm = new GroupsGridForm(list1);
  238. groupsGridForm.Show();
  239. }
  240. else
  241. {
  242. if (panel1.Controls.Count > 0 && panel1.Controls[0].Controls.Count > 0)
  243. {
  244. Panel panel = (Panel)(panel1.Controls[0].Controls[0]);
  245. int chkcount = panel.Controls.Count;
  246. if (chkcount < 3)
  247. {
  248. MessageBox.Show("试验数据过少。");
  249. return;
  250. }
  251. double[] vs = new double[chkcount];
  252. double[] gg = { 140, 240, 532, 205, 150, 110, 200, 180, 220, 300, 70, 390, 100, 90, 320, 190, 250, 150, 280, 250, 490, 120, 500, 200 };
  253. for (int i = 0; i < chkcount; i++)
  254. {
  255. vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
  256. }
  257. int ret = Business.Tools.Grubbls(vs);
  258. if (ret != 0)
  259. {
  260. DialogResult dr = MessageBox.Show("试验数据存在离群值,是否继续分析?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  261. if (dr == DialogResult.No)
  262. {
  263. return;
  264. }
  265. }
  266. GridForm gridForm = new GridForm(gg, panel1.Controls[0].Text);
  267. gridForm.Show();
  268. }
  269. }
  270. }
  271. /// <summary>
  272. /// 添加分组
  273. /// </summary>
  274. /// <param name="sender"></param>
  275. /// <param name="e"></param>
  276. private void btnGroup_Click(object sender, EventArgs e)
  277. {
  278. string strTemp = string.Empty;
  279. InputText inputDialog = new InputText();
  280. inputDialog.TextHandler = (str) => { strTemp = str; };
  281. inputDialog.StartPosition = FormStartPosition.CenterParent;
  282. DialogResult result = inputDialog.ShowDialog();
  283. GroupBox group = new GroupBox();
  284. group.Width = panel1.Width-20;
  285. if (groupCount == 0)
  286. {
  287. group.Height = 250;
  288. }
  289. else
  290. {
  291. group.Height = 50;
  292. panel1.Controls[0].Height = 50;
  293. }
  294. group.Name = "grp"+ groupCount;
  295. group.Location = new Point(0, groupCount * 50+ 5);
  296. group.Text = strTemp;
  297. foreach (GroupBox item in panel1.Controls)
  298. {
  299. ((Panel)item.Controls[0]).BorderStyle = BorderStyle.None;
  300. }
  301. Panel panel = new Panel();
  302. panel.Name= "pan" + groupCount;
  303. panel.Click += panParticles_Click;
  304. panel.Dock = DockStyle.Fill;
  305. panel.BorderStyle = BorderStyle.Fixed3D;
  306. panel.AutoScroll = true;
  307. group.Controls.Add(panel);
  308. panel1.Controls.Add(group);
  309. gp = group;
  310. groupCount++;
  311. }
  312. /// <summary>
  313. /// 选择分组
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. private void panParticles_Click(object sender, EventArgs e)
  318. {
  319. foreach (GroupBox item in panel1.Controls)
  320. {
  321. ((Panel)item.Controls[0]).BorderStyle = BorderStyle.None;
  322. }
  323. ((Panel)sender).BorderStyle = BorderStyle.Fixed3D;
  324. gp = (GroupBox)((Panel)sender).Parent;
  325. }
  326. /// <summary>
  327. /// 删除分组
  328. /// </summary>
  329. /// <param name="sender"></param>
  330. /// <param name="e"></param>
  331. private void btnDelGrp_Click(object sender, EventArgs e)
  332. {
  333. if (panel1.Controls.Count > 0&& gp!=null)
  334. {
  335. DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  336. if (dr == DialogResult.No)
  337. {
  338. return;
  339. }
  340. int height = gp.Location.Y;
  341. panel1.Controls.Remove(gp);
  342. groupCount--;
  343. foreach (GroupBox item in panel1.Controls)
  344. {
  345. if (item.Location.Y > height)
  346. {
  347. item.Location = new Point(item.Location.X, item.Location.Y-50);
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }