123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Management;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml;
- namespace OTSExtremum
- {
- public partial class ExtremumApp : Form
- {
- public ExtremumApp()
- {
- InitializeComponent();
- }
- int groupCount = 0;
- GroupBox gp;
- #region 单组数据操作方法
- //分类
- int typeIndex = 0;
- /// <summary>
- /// 添加颗粒直径
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddValue_Click(object sender, EventArgs e)
- {
- AddVale(panel1);
- }
- /// <summary>
- /// 添加测量结果文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddFile_Click(object sender, EventArgs e)
- {
- DataReadConfigurationForm dialog = new DataReadConfigurationForm();
- if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- this.Cursor = Cursors.WaitCursor;
- ScanFile(dialog.Filepath, dialog.LoadCount,panel1);
- this.Cursor = Cursors.Default;
- }
- }
- /// <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;
- }
- DelVale(panel1);
- }
- /// <summary>
- /// 检验数据有效性,是否位离群值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCheck_Click(object sender, EventArgs e)
- {
- CheckVale(panel1);
- }
- /// <summary>
- /// 极值分析
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCompute_Click(object sender, EventArgs e)
- {
- int chkcount = panel1.Controls.Count;
-
- 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)panel1.Controls[i]).Text);
- }
- if (!CheckVale(panel1,1))
- {
- return;
- }
- GridForm gridForm = new GridForm(vs, panel1.Controls[0].Text);
- gridForm.Show();
- }
- /// <summary>
- /// 选择分类A
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gbflA_Click(object sender, EventArgs e)
- {
- typeIndex = 0;
- this.rbbtntype.Image = Properties.Resources.A1;
- ListChangedType();
- }
- /// <summary>
- /// 选择分类B
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gbflB_Click(object sender, EventArgs e)
- {
- typeIndex = 1;
- this.rbbtntype.Image = Properties.Resources.B;
- ListChangedType();
- }
- /// <summary>
- /// 选择分类C
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gbflC_Click(object sender, EventArgs e)
- {
- typeIndex = 2;
- this.rbbtntype.Image = Properties.Resources.C1;
- ListChangedType();
- }
- /// <summary>
- /// 选择分类D
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gbflD_Click(object sender, EventArgs e)
- {
- typeIndex = 3;
- this.rbbtntype.Image = Properties.Resources.D;
- ListChangedType();
- }
- /// <summary>
- /// 选择分类DS
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void gbflDS_Click(object sender, EventArgs e)
- {
- typeIndex = 4;
- this.rbbtntype.Image = Properties.Resources.DS;
- ListChangedType();
- }
- /// <summary>
- /// 分类改变后测量结果改变
- /// </summary>
- private void ListChangedType()
- {
- foreach (var item in panel1.Controls)
- {
- CheckBox check = (CheckBox)item;
- if (check.Tag.GetType().Name == "Double[]")
- {
- double[] list = (double[])check.Tag;
- check.Text = Math.Round(list[typeIndex], 2).ToString();
- }
- }
- }
- #endregion
- #region 多组数据操作
- /// <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();
- if (string.IsNullOrEmpty(strTemp))
- {
- return;
- }
- GroupBox group = new GroupBox();
- group.Width = panel2.Width - 20;
- group.Height = 50;
- group.Name = "grp" + groupCount;
- group.Location = new Point(0, groupCount * 50 + 5);
- group.Text = strTemp;
- foreach (GroupBox item in panel2.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);
- panel2.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 panel2.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 (panel2.Controls.Count > 0 && gp != null)
- {
- DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
- if (dr == DialogResult.No)
- {
- return;
- }
- int height = gp.Location.Y;
- panel2.Controls.Remove(gp);
- groupCount--;
- foreach (GroupBox item in panel2.Controls)
- {
- if (item.Location.Y > height)
- {
- item.Location = new Point(item.Location.X, item.Location.Y - 50);
- }
- }
- if (panel2.Controls.Count > 0)
- {
- int c = panel2.Controls.Count - 1;
- gp = (GroupBox)panel2.Controls[c];
- ((Panel)gp.Controls[0]).BorderStyle = BorderStyle.Fixed3D;
- }
- }
- }
- //分类
- int typeIndexGroup = 0;
- /// <summary>
- /// 添加颗粒直径
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddValueGroup_Click(object sender, EventArgs e)
- {
- Panel panel = (Panel)gp.Controls[0];
- AddVale(panel);
- }
- /// <summary>
- /// 添加测量结果文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddFileGroup_Click(object sender, EventArgs e)
- {
- if (gp == null)
- {
- MessageBox.Show("请添加分组!");
- btnGroup_Click(null, null);
- return;
- }
- Panel panel = (Panel)gp.Controls[0];
- DataReadConfigurationForm dialog = new DataReadConfigurationForm();
- if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- this.Cursor = Cursors.WaitCursor;
- ScanFile(dialog.Filepath, dialog.LoadCount, panel);
- this.Cursor = Cursors.Default;
- }
- }
- /// <summary>
- /// 删除颗粒
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnDelGroup_Click(object sender, EventArgs e)
- {
- DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
- if (dr == DialogResult.No)
- {
- return;
- }
- foreach (GroupBox group in panel2.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- DelVale(panel);
- }
- }
- /// <summary>
- /// 检验数据有效性,是否位离群值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCheckGroup_Click(object sender, EventArgs e)
- {
- foreach (GroupBox group in panel2.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- if (!CheckVale(panel))
- {
- break;
- }
- }
- }
- /// <summary>
- /// 极值分析
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnComputeGroup_Click(object sender, EventArgs e)
- {
- if (panel2.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 panel2.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- int chkcount = panel.Controls.Count;
- double[] vs = new double[chkcount];
- for (int i = 0; i < chkcount; i++)
- {
- vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
- }
- if (!CheckVale(panel,1))
- {
- break;
- }
- Business.groupInfo groupInfo = new Business.groupInfo();
- groupInfo.values = vs;
- groupInfo.groupTitle = group.Text;
- list.Add(groupInfo);
-
- }
-
- GroupsGridForm groupsGridForm = new GroupsGridForm(list);
- groupsGridForm.Show();
- }
- }
- /// <summary>
- /// 选择分类A
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void fzflA_Click(object sender, EventArgs e)
- {
- typeIndexGroup = 0;
- this.fztype.Image = Properties.Resources.A1;
- ListChangedTypeGroup();
- }
- /// <summary>
- /// 选择分类B
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void fzflB_Click(object sender, EventArgs e)
- {
- typeIndexGroup = 1;
- this.fztype.Image = Properties.Resources.B;
- ListChangedTypeGroup();
- }
- /// <summary>
- /// 选择分类C
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void fzflC_Click(object sender, EventArgs e)
- {
- typeIndexGroup = 2;
- this.fztype.Image = Properties.Resources.C1;
- ListChangedTypeGroup();
- }
- /// <summary>
- /// 选择分类D
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void fzflD_Click(object sender, EventArgs e)
- {
- typeIndexGroup = 3;
- this.fztype.Image = Properties.Resources.D;
- ListChangedTypeGroup();
- }
- /// <summary>
- /// 选择分类DS
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void fzflDS_Click(object sender, EventArgs e)
- {
- typeIndexGroup = 4;
- this.fztype.Image = Properties.Resources.DS;
- ListChangedTypeGroup();
- }
- /// <summary>
- /// 分类改变后测量结果改变
- /// </summary>
- private void ListChangedTypeGroup()
- {
- foreach (GroupBox group in panel2.Controls)
- {
- Panel panel = (Panel)group.Controls[0];
- int sel = typeIndexGroup;
- 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();
- }
- }
- }
- }
- #endregion
- #region 全局事件
- /// <summary>
- /// 选择单组数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void rbtab1_ActiveChanged(object sender, EventArgs e)
- {
- if (rbtab1.Active)
- {
- panel2.Dock = DockStyle.None;
- panel2.Visible = false;
- panel1.Dock = DockStyle.Fill;
- panel1.Visible = true;
-
- }
- }
- /// <summary>
- /// 选择多组数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void rbtab2_ActiveChanged(object sender, EventArgs e)
- {
- if (rbtab2.Active)
- {
- panel1.Dock = DockStyle.None;
- panel1.Visible = false;
- panel2.Dock = DockStyle.Fill;
- panel2.Visible = true;
- }
- }
- /// <summary>
- /// 窗体加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ExtremumApp_Load(object sender, EventArgs e)
- {
-
- panel2.Dock = DockStyle.None;
- panel2.Visible = false;
- panel1.Dock = DockStyle.Fill;
- panel1.Visible = true;
- //if (!License())
- //{
- // this.Close();
- //}
- }
- /// <summary>
- /// 扫描文件夹添加测量结果
- /// </summary>
- /// <param name="path">文件夹路径</param>
- /// <param name="panel">添加数据的容器</param>
- private void ScanFile(string path,int loadCount,Panel panel)
- {
- //扫描路径
- DirectoryInfo info = new DirectoryInfo(path);
- if (!info.Exists) return;
-
- FileSystemInfo[] files = info.GetFileSystemInfos();
- for (int i = 0; i < files.Length; i++)
- {
- FileInfo file = files[i] as FileInfo;
- //是文件
- if (file != null&& file.Extension== ".rst")
- {
- //string fpath = System.IO.Path.GetDirectoryName(file.Name);
- try
- {
- var dic = Business.Classify.getClassByGroup(file.DirectoryName);
- int sel = typeIndex;
- for (int j = 0; j < loadCount; j++)
- {
- if(j>=dic[sel].Count)
- {
- break;
- }
- CheckBox checkBox = new CheckBox();
- checkBox.Text = Math.Round(dic[sel][j], 2).ToString();
- checkBox.Tag = new double[] {dic[0][j], dic[1][j], dic[2][j], dic[3][j], dic[4][j]};
- 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);
- }
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- }
-
- }
- else ScanFile(files[i].FullName, loadCount, panel);
- }
- }
- /// <summary>
- /// 添加颗粒数据
- /// </summary>
- /// <param name="panel">添加数据的容器</param>
- private void AddVale(Panel panel)
- {
- string strTemp = string.Empty;
- InputValue inputDialog = new InputValue();
- inputDialog.TextHandler = (str) => { strTemp = str; };
- inputDialog.StartPosition = FormStartPosition.CenterParent;
- DialogResult result = inputDialog.ShowDialog();
- string size = strTemp;
- if (!string.IsNullOrEmpty(size))
- {
- for (int i = 0; i < size.Split(',').Length; i++)
- {
- string init = size.Split(',')[i];
- if (!Business.Tools.IsIntOrDouble(init))
- {
- MessageBox.Show("不是数字!");
- continue;
- }
- CheckBox checkBox = new CheckBox();
- checkBox.Text = init;
- checkBox.Tag = Convert.ToDouble(init);
- 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);
- }
- }
- //if (!Business.Tools.IsIntOrDouble(size))
- //{
- // MessageBox.Show("请输入数字!");
- // return;
- //}
- //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);
- }
- /// <summary>
- /// 删除颗粒数据
- /// </summary>
- /// <param name="panel">数据的容器</param>
- private void DelVale(Panel panel)
- {
- 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="panel">数据的容器</param>
- /// <returns></returns>
- private bool CheckVale(Panel panel,int ischeck=0)
- {
- int chkcount = panel.Controls.Count;
- if (chkcount < 3)
- {
- MessageBox.Show("试验数据过少。");
- return false;
- }
- 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&& ischeck==0)
- {
- MessageBox.Show("试验数据有效。");
- return true;
- }
- else if (ret == 1)
- {
- MessageBox.Show("最大的夹杂物长度值【"+ vs.Max().ToString() + "】是离群值,试验数据无效。");
- return false;
- }
- else if (ret == 2)
- {
- MessageBox.Show("最小的夹杂物长度值【" + vs.Min().ToString() + "】是离群值,试验数据无效。");
- return false;
- }
- return true;
- }
- //检测注册
- private bool License()
- {
- //硬件ID
- //string HardwareID = GetLicenseInfo("HardwareID");
- ////创建ManagementObjectSearcher对象
- //ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
- //String strHardDiskID = null;
- ////调用ManagementObjectSearcher类的Get方法取主板号
- //foreach (ManagementObject mo in searcher.Get())
- //{
- // strHardDiskID = mo["SerialNumber"].ToString().Trim();//记录获得的磁盘序列号
- // break;
- //}
- //if (Business.Tools.Base64Decrypt(HardwareID) != strHardDiskID)
- //{
- // MessageBox.Show("未注册!");
- // return false;
- //}
- try
- {
- //有效期
- DateTime ExpireDate = Convert.ToDateTime(Business.Tools.Base64Decrypt(GetLicenseInfo("ExpireDate")));
-
- if (DateTime.Now > ExpireDate)
- {
- MessageBox.Show("已超过使用期限!");
- return false;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("未注册!");
- return false;
- }
- return true;
- }
- public static string GetLicenseInfo(string NodeName)
- {
- string path = Application.StartupPath + "\\LicenseData.xml";
- return Business.Tools.GetXMLInformations(path, NodeName);
- }
-
- #endregion
- }
- }
|