123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSExtremum
- {
- public partial class MainForm : Form
- {
- public MainForm()
- {
- InitializeComponent();
- }
-
-
- int groupCount = 0;
- GroupBox gp;
- /// <summary>
- /// 添加颗粒直径
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddValue_Click(object sender, EventArgs e)
- {
- string size = txtParticle.Text;
-
- if (!Business.Tools.IsIntOrDouble(size))
- {
- MessageBox.Show("请输入数字!");
- return;
- }
- if (gp == null)
- {
- MessageBox.Show("请添加分组!");
- btnGroup_Click(null, null);
- return;
- }
- Panel panel = (Panel)gp.Controls[0];
- CheckBox checkBox = new CheckBox();
- checkBox.Text = size;
- checkBox.Tag = Convert.ToDouble(size);
- checkBox.Width = 80;
- int chkcount = panel.Controls.Count;
- int row = chkcount / 10;
- int col = chkcount % 10;
- checkBox.Location = new Point(10 + col * 80, row * 35);
-
- panel.Controls.Add(checkBox);
- chkcount = chkcount+1;
-
- }
- /// <summary>
- /// 添加测量结果文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddFile_Click(object sender, EventArgs e)
- {
- if (gp == null)
- {
- MessageBox.Show("请添加分组!");
- btnGroup_Click(null, null);
- return;
- }
- Panel panel = (Panel)gp.Controls[0];
- OpenFileDialog fileDialog = new OpenFileDialog();
- fileDialog.Multiselect = true;
- fileDialog.Title = "请选择测量结果文件";
- fileDialog.Filter = "所有文件(*rst*)|*.rst*"; //设置要选择的文件的类型
- if (fileDialog.ShowDialog() == DialogResult.OK)
- {
- string file = fileDialog.FileName;//返回文件的完整路径
- string path = System.IO.Path.GetDirectoryName(file);
- double[] list = Business.Classify.getClass(path);
- int sel = cobType.SelectedIndex;
- CheckBox checkBox = new CheckBox();
- checkBox.Text =Math.Round( list[sel],2).ToString();
- checkBox.Tag = list;
- checkBox.Width = 80;
- // checkBox.Font = new Font(checkBox.Font.FontFamily, 8, checkBox.Font.Style);
- int chkcount = panel.Controls.Count;
- int row = chkcount / 10;
- int col = chkcount % 10;
- checkBox.Location = new Point(10 + col * 80, row * 35);
- panel.Controls.Add(checkBox);
- chkcount = chkcount + 1;
-
- }
- }
- /// <summary>
- /// 改变颗粒分类
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cobType_SelectedIndexChanged(object sender, EventArgs e)
- {
- foreach (GroupBox group in panel1.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- int sel = cobType.SelectedIndex;
- foreach (var item in panel.Controls)
- {
- CheckBox check = (CheckBox)item;
- if (check.Tag.GetType().Name == "Double[]")
- {
- double[] list = (double[])check.Tag;
- check.Text = Math.Round(list[sel], 2).ToString();
- }
- }
- }
-
- }
- /// <summary>
- /// 删除颗粒
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDel_Click(object sender, EventArgs e)
- {
- DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
- if (dr == DialogResult.No)
- {
- return;
- }
- foreach (GroupBox group in panel1.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- for (int i = panel.Controls.Count - 1; i >= 0; i--)
- {
- CheckBox check = (CheckBox)panel.Controls[i];
- if (check.Checked)
- {
- panel.Controls.RemoveAt(i);
- }
- }
- int chkcount = panel.Controls.Count;
- int rows = 0;
- int cols = 0;
- for (int i = 0; i < chkcount; i++)
- {
- CheckBox check = (CheckBox)panel.Controls[i];
- check.Location = new Point(10 + cols * 80, rows * 35);
- cols++;
- if (cols == 10)
- {
- rows++;
- cols = 0;
- }
- }
-
- }
- }
- /// <summary>
- /// 检验数据有效性,是否位离群值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCheck_Click(object sender, EventArgs e)
- {
- foreach (GroupBox group in panel1.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- int chkcount = panel.Controls.Count;
- if (chkcount < 3)
- {
- MessageBox.Show("试验数据过少。");
- return;
- }
- double[] vs = new double[chkcount];
- 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 };
- for (int i = 0; i < chkcount; i++)
- {
- vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
- }
- int ret = Business.Tools.Grubbls(vs);
- if (ret == 0)
- {
- MessageBox.Show("试验数据有效。");
- }
- else if (ret == 1)
- {
- MessageBox.Show("最大的夹杂物长度值是离群值,试验数据无效。");
- }
- else if (ret == 2)
- {
- MessageBox.Show("最小的夹杂物长度值是离群值,试验数据无效。");
- }
- }
- }
- /// <summary>
- /// 极值分析
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCompute_Click(object sender, EventArgs e)
- {
-
- if (panel1.Controls.Count > 1)
- {
- List<Business.groupInfo> list = new List<Business.groupInfo>();
- List<Business.groupInfo> list1 = new List<Business.groupInfo>() {
- new Business.groupInfo() { values=new double[] {85,25,30,35,40,45,50,55 },groupTitle="DL2" },
- new Business.groupInfo() { values=new double[] {30,10,12,14,16,18,20,25 },groupTitle="LF1" },
- new Business.groupInfo() { values=new double[] {30,0,5,8,20,25,10,15 },groupTitle="LF2" },
- new Business.groupInfo() { values=new double[] {25,10,12,14,18,20,22,24},groupTitle="VD1-2" },
- new Business.groupInfo() { values=new double[] {40,10,15,20,35,24,26,30 },groupTitle="VD2-2" },
- new Business.groupInfo() { values=new double[] {45,10,15,20,25,30,35,29 },groupTitle="VD3" },
- new Business.groupInfo() { values=new double[] {85,10,15,60,55,30,35,40},groupTitle="JZ" }
- };
- foreach (GroupBox group in panel1.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- int chkcount = panel.Controls.Count;
- if (chkcount < 3)
- {
- MessageBox.Show("试验数据过少。");
- return;
- }
- double[] vs = new double[chkcount];
- //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 };
- for (int i = 0; i < chkcount; i++)
- {
- vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
- }
- int ret = Business.Tools.Grubbls(vs);
- if (ret != 0)
- {
- DialogResult dr = MessageBox.Show(group.Text+"试验数据存在离群值,是否继续分析?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
- if (dr == DialogResult.No)
- {
- return;
- }
- }
- Business.groupInfo groupInfo = new Business.groupInfo();
- groupInfo.values = vs;
- groupInfo.groupTitle = group.Text;
- list.Add(groupInfo);
- //GridForm gridForm = new GridForm(gg, group.Text);
- //gridForm.Show();
- }
-
- GroupsGridForm groupsGridForm = new GroupsGridForm(list1);
- groupsGridForm.Show();
- }
- else
- {
- if (panel1.Controls.Count > 0 && panel1.Controls[0].Controls.Count > 0)
- {
-
- Panel panel = (Panel)(panel1.Controls[0].Controls[0]);
- int chkcount = panel.Controls.Count;
- if (chkcount < 3)
- {
- MessageBox.Show("试验数据过少。");
- return;
- }
- double[] vs = new double[chkcount];
- 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 };
- for (int i = 0; i < chkcount; i++)
- {
- vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
- }
- int ret = Business.Tools.Grubbls(vs);
- if (ret != 0)
- {
- DialogResult dr = MessageBox.Show("试验数据存在离群值,是否继续分析?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
- if (dr == DialogResult.No)
- {
- return;
- }
- }
- GridForm gridForm = new GridForm(gg, panel1.Controls[0].Text);
- gridForm.Show();
- }
- }
- }
- /// <summary>
- /// 添加分组
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnGroup_Click(object sender, EventArgs e)
- {
-
- string strTemp = string.Empty;
- InputText inputDialog = new InputText();
- inputDialog.TextHandler = (str) => { strTemp = str; };
- inputDialog.StartPosition = FormStartPosition.CenterParent;
- DialogResult result = inputDialog.ShowDialog();
-
- GroupBox group = new GroupBox();
- group.Width = panel1.Width-20;
- if (groupCount == 0)
- {
- group.Height = 250;
- }
- else
- {
- group.Height = 50;
- panel1.Controls[0].Height = 50;
- }
-
- group.Name = "grp"+ groupCount;
- group.Location = new Point(0, groupCount * 50+ 5);
- group.Text = strTemp;
- foreach (GroupBox item in panel1.Controls)
- {
- ((Panel)item.Controls[0]).BorderStyle = BorderStyle.None;
- }
- Panel panel = new Panel();
- panel.Name= "pan" + groupCount;
- panel.Click += panParticles_Click;
- panel.Dock = DockStyle.Fill;
- panel.BorderStyle = BorderStyle.Fixed3D;
- panel.AutoScroll = true;
- group.Controls.Add(panel);
- panel1.Controls.Add(group);
- gp = group;
- groupCount++;
- }
- /// <summary>
- /// 选择分组
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panParticles_Click(object sender, EventArgs e)
- {
- foreach (GroupBox item in panel1.Controls)
- {
- ((Panel)item.Controls[0]).BorderStyle = BorderStyle.None;
- }
- ((Panel)sender).BorderStyle = BorderStyle.Fixed3D;
- gp = (GroupBox)((Panel)sender).Parent;
- }
- /// <summary>
- /// 删除分组
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDelGrp_Click(object sender, EventArgs e)
- {
- if (panel1.Controls.Count > 0&& gp!=null)
- {
- DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
- if (dr == DialogResult.No)
- {
- return;
- }
- int height = gp.Location.Y;
- panel1.Controls.Remove(gp);
- groupCount--;
- foreach (GroupBox item in panel1.Controls)
- {
- if (item.Location.Y > height)
- {
- item.Location = new Point(item.Location.X, item.Location.Y-50);
- }
- }
- }
-
- }
- }
-
- }
|