private void query_bt_Click(object sender, EventArgs e) { this.defalut_select = radioGroup1.SelectedIndex; if (textBox_ljhao.Text == "") { MessageBox.Show("请输入查询字段"); return; } this.reQuery(); Maticsoft.BLL.test test_bll = new Maticsoft.BLL.test(); string where_string = this.query_wherestring(); this.totle_num = test_bll.GetRecordCount2(where_string); if (this.totle_num % this.cur_page_lenb == 0) { this.totle_page_num = this.totle_num / this.cur_page_lenb; } else { this.totle_page_num = this.totle_num / this.cur_page_lenb + 1; } //int tot_page_index = this.totle_num / this.cur_page_lenb + (this.totle_num % this.cur_page_lenb == 0 ? 0 : 1); string page_info = string.Format("{0}/{1}", 1, totle_page_num); this.labelX1.Text = page_info; this.radioGroup1.SelectedIndex = defalut_select; return; }
private void ShowInfo(int id) { Maticsoft.BLL.test bll = new Maticsoft.BLL.test(); Maticsoft.Model.test model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.lblmeasureb.Text = model.measureb; this.lbltime.Text = model.time.ToString(); this.lblstep1.Text = model.step1; this.lblstep2.Text = model.step2; this.lblstep3.Text = model.step3; this.lblstep4.Text = model.step4; this.lblstep5.Text = model.step5; this.lblOKorNG.Text = model.OKorNG; }
private void QueryFrom_Load(object sender, EventArgs e) { string default_str = ""; Maticsoft.BLL.test test_bll = new Maticsoft.BLL.test(); // 获得最后一条 DataSet ds = test_bll.GetModelListLast(); DataTable dt = ds.Tables[0]; if (dt.Rows.Count == 1) { this.textBox_ljhao.Text = dt.Rows[0]["componentId"].ToString(); } //textBox_ljhao.Text = Program.gdvid; global.CurActive = "QueryFrom"; this.timeselect_dtp.Value = global.startTime; this.dgv.ReadOnly = true; #region 一共有多少 // 下一页 string where_string = this.query_wherestring(); reQuery(); this.totle_num = test_bll.GetRecordCount2(where_string); // 当前多少页面 if (this.totle_num % this.cur_page_lenb == 0) { this.totle_page_num = this.totle_num / this.cur_page_lenb; } else { this.totle_page_num = this.totle_num / this.cur_page_lenb + 1; } string parem_num = string.Format("1/{0}", this.totle_page_num); labelX1.Text = parem_num; #endregion // 添加 智能补全 this.AddAutoComp(); }
private string get_okpara() { string result = ""; radioGroup1.Invoke(new Action(() => { Maticsoft.BLL.test test_bll = new Maticsoft.BLL.test(); radioGroup1.SelectedIndex = 0; string where_string1 = this.query_wherestring(); int tot = test_bll.GetRecordCount2(where_string1); radioGroup1.SelectedIndex = 2; string where_string2 = this.query_wherestring(); int ok_num = test_bll.GetRecordCount2(where_string2); double percent = Convert.ToDouble(ok_num) / Convert.ToDouble(tot); result = string.Format("{0:0.00%}", percent);//得到5.88% radioGroup1.SelectedIndex = 0; })); //MessageBox.Show(result); return(result); }
private void reQuery(bool all = false, string order = "") { string where_string = this.query_wherestring(); // 同步处理好 零件的基础信息的事情 string lijianhao = textBox_ljhao.Text; if (lijianhao != null && lijianhao != "") { this.dealwithcomp(Convert.ToInt32(lijianhao)); } else { return; } #region 构建基本的表形状 DataTable mea_dt = new DataTable(); Maticsoft.BLL.measures mea_bll = new Maticsoft.BLL.measures(); List <Maticsoft.Model.measures> mea_modes = mea_bll.GetModelList(string.Format(" componentId={0} order by step", this.comp_type)); mea_dt.Columns.Add("零件号"); mea_dt.Columns.Add("测量编号"); mea_modes = mea_modes.OrderBy(obj => obj.step).ToList(); foreach (Maticsoft.Model.measures mea_obj in mea_modes) { //string sg = "步骤" + mea_dt.Tables[0].Rows[i]["step"].ToString();// comboBox1.Items.Add() // comboBox1.Text = sg; string sg = mea_obj.CC.ToString(); mea_dt.Columns.Add(sg.ToString()); } mea_dt.Columns.Add("结果"); mea_dt.Columns.Add("测量时间"); if (all == false) { dgv.DataSource = null; dgv.DataSource = mea_dt; for (int i = 0; i < this.dgv.Columns.Count; i++) { this.dgv.Columns[i].SortMode = DataGridViewColumnSortMode.Programmatic; } } dgv.Columns["测量编号"].Width = 140; dgv.Columns["测量时间"].Width = 140; // dgv.AutoGenerateColumns = false; dataGridView1.DataSource = mea_dt.Copy(); #endregion // 查询出来test 数据 Maticsoft.BLL.test test_bll = new Maticsoft.BLL.test(); // List<Maticsoft.Model.test> test_lists = test_bll.GetModelList(where_str); DataSet ds = new DataSet(); DataTable dest_table = null; //DataTable dest_table2 = null; if (all == false) { ds = test_bll.GetListByPage2(where_string, order, cur_page_lenb * cur_page_num, cur_page_lenb); dest_table = dgv.DataSource as DataTable; } else { ds = test_bll.GetListByPage2(where_string, order, 0, 10000); dest_table = dataGridView1.DataSource as DataTable; } DataTable dt = ds.Tables[0]; #region 根据数据 更新表结构 ==== 惰性加入数据 // 放入基础信息 Task <string[]> parent = new Task <string[]>((aa) => { DataTable local_dt = aa as DataTable; int count = local_dt.Rows.Count; string[] ret = new string[count]; dgv.Columns["零件号"].Tag = "PN"; dgv.Columns["测量编号"].Tag = "measureb"; dgv.Columns["测量时间"].Tag = "time"; dgv.Columns["结果"].Tag = "OKorNG"; for (int i = 0; i < count; i++) { DataRow xin_dr = dest_table.NewRow(); xin_dr["零件号"] = local_dt.Rows[i]["PN"]; xin_dr["测量编号"] = local_dt.Rows[i]["measureb"]; xin_dr["测量时间"] = local_dt.Rows[i]["time"]; xin_dr["结果"] = local_dt.Rows[i]["OKorNG"]; dest_table.Rows.Add(xin_dr); //xin_dr.Rows[][] = local_dt.Rows[i][0] new Task((index) => { int ret_i = Convert.ToInt32(index); // Console.WriteLine("试试 " + index); ret[ret_i] = local_dt.Rows[ret_i]["step1"].ToString(); }, i, TaskCreationOptions.AttachedToParent).Start(); } return(ret); }, dt); parent.ContinueWith((t) => { for (int i = 0; i < t.Result.Length; i++) { string[] sp_l = t.Result[i].Split('/'); foreach (Maticsoft.Model.measures mea_obj in mea_modes) { int ret_col_num = 1; bool col_if = int.TryParse(mea_obj.step.ToString(), out ret_col_num); // string sg = "步骤" + mea_obj.CC.ToString(); string sg = mea_obj.CC.ToString(); dgv.Columns[sg].Tag = "step1"; //mea_modes if (col_if && ret_col_num < sp_l.Length + 1) { double stand_info = Convert.ToDouble(mea_obj.standardv); string test_str = sp_l[ret_col_num - 1]; if (test_str == "") { continue; } double test_info = Convert.ToDouble(test_str); dest_table.Rows[i][sg] = sp_l[ret_col_num - 1]; if (all == false) { if (stand_info + Convert.ToDouble(mea_obj.down) > test_info) { dgv.Rows[i].Cells[sg].Style.BackColor = Color.Cyan; } else if (stand_info + Convert.ToDouble(mea_obj.up) < test_info) { dgv.Rows[i].Cells[sg].Style.BackColor = Color.LightSalmon; } else { dgv.Rows[i].Cells[sg].Style.BackColor = Color.Lime; } } else { if (stand_info + Convert.ToDouble(mea_obj.down) > test_info) { dataGridView1.Rows[i].Cells[sg].Style.BackColor = Color.Cyan; } else if (stand_info + Convert.ToDouble(mea_obj.up) < test_info) { dataGridView1.Rows[i].Cells[sg].Style.BackColor = Color.LightSalmon; } else { dataGridView1.Rows[i].Cells[sg].Style.BackColor = Color.Lime; } } } } } // 计算 jisuan(all); }); parent.Start(); #endregion #endregion return; }
private void jisuan(bool all = false) { DataTable dt2 = NewMethod(); //构建一个计算用的表格 Maticsoft.BLL.measures mea_bll = new Maticsoft.BLL.measures(); List <Maticsoft.Model.measures> mea_list = mea_bll.GetModelList(string.Format(" componentId = '{0}' order by step ", this.comp_type)); foreach (Maticsoft.Model.measures mea_obj in mea_list) { // dt2.Columns.Add(new DataColumn("s" + mea_obj.step.ToString(), typeof(Double))); dt2.Columns.Add(new DataColumn(mea_obj.CC.ToString(), typeof(Double))); } // 取得数据。 分解数据。 填充数据 Maticsoft.BLL.test test_bll = new Maticsoft.BLL.test(); string where_string1 = this.query_wherestring(); // radioGroup1.SelectedIndex = 2; DataSet ds = test_bll.GetList3(where_string1); //DataTable dt = this.dgv.DataSource as DataTable; DataTable dt = ds.Tables[0]; List <double[]> bbb = new List <double[]>(); foreach (DataRow dr in dt.Rows) { string step = dr["step1"].ToString(); string[] temp_step = step.Split('/'); if (temp_step.Length == dt2.Columns.Count) { DataRow dr_temp = dt2.NewRow(); for (int i = 0; i < temp_step.Length; i++) { double temp_d = 0; Double.TryParse(temp_step[i], out temp_d); // dr_temp["s" + (i + 1).ToString()] = temp_d; dr_temp[i] = temp_d; Console.WriteLine("temp_step[i] == " + temp_step[i] + " === " + i); } dt2.Rows.Add(dr_temp); //Console.WriteLine(Environment.NewLine); } } /* * CPK=Cp*(1-|Ca|) * Ca (Capability of Accuracy):制程准确度;在衡量「实际平均值」与「规格中心值」之一致性。对於单边规格,因不存在规格中心,因此不存在Ca;对於双边规格,Ca=(ˉx-U)/(T/2)。 * Cp (Capability of Precision):制程精密度;在衡量「规格公差宽度」与「制程变异宽度」之比例。对於单边规格,只有上限和中心值,Cpu = | USL-ˉx | / 3σ 或 只有下限和中心值,Cpl = | ˉx -LSL | / 3σ;对於双边规格:Cp=(USL-LSL) / 6σ=T/6σ * 注意: 计算Cpk时,取样数据至少应有20组数据,而且数据要具有一定代表性。 * * 某零件质量要求为20±0.15,抽样100件,测得:-x =20.05mm;s=0.05mm,求过程能力指数。根据零件的规格要求,Tu=20.15,Tl=19.85 * M=Tu+Tl/2=(20.15+19.85)/2=20.00 * ε=|M- 20.05|=0.05 * T = USL - LSL = 20.15 - 19.85 = 0.3 * CPK = CP*(|1-CA|) * = (T-2ε)/6s = (0.3-2*0.05)/(6*0.05)=(0.3-0.1)/(6*0.05)≈0.67 */ // 分析数据 // mea_list string all_cpk = ""; Dictionary <int, double> cpk_dic = new Dictionary <int, double>(); foreach (DataColumn aa in dt2.Columns) { int step = dt2.Columns.IndexOf(aa); string col_name = aa.ColumnName.Replace("s", ""); //dt2.Columns[1]. // List<Maticsoft.Model.measures> mea_obj = mea_list.Where(x => x.step == Convert.ToInt32(col_name)).Select(x => x).ToList<Maticsoft.Model.measures>(); List <Maticsoft.Model.measures> mea_obj = mea_list.Where(x => x.step == step + 1).Select(x => x).ToList <Maticsoft.Model.measures>(); //string rr = dt2.Select("", aa.ColumnName + " DESC")[0][aa.ColumnName].ToString(); object max = dt2.Compute(string.Format("Max([{0}])", aa.ColumnName), "true"); // MessageBox.Show(max.ToString()); object min = dt2.Compute(string.Format("Min([{0}])", aa.ColumnName), "true"); double sta = Convert.ToDouble(mea_obj[0].standardv); double va_x1 = Convert.ToDouble(max is DBNull ? 0 : max); double va_x2 = Convert.ToDouble(min is DBNull ? 0 : min); double va_x = va_x1 - sta > sta - va_x2 ? va_x1 : va_x2; double va_s = sta - va_x; double tu = sta + Convert.ToDouble(mea_obj[0].up); double ti = sta - Convert.ToDouble(mea_obj[0].down); double v_m = (tu + ti) / 2; double sgm = Math.Abs(sta - va_x); double v_t = tu - ti; double cpk = (v_t - 2 * sgm) / (6 * va_s); Console.WriteLine(string.Format("max == {0} --- min {1}----- {2}::{3}", max, min, mea_obj[0].up, mea_obj[0].down)); Console.WriteLine(Environment.NewLine); Console.WriteLine(string.Format("cpk == {0}", cpk)); all_cpk += " " + aa.ColumnName + "= " + cpk; //cpk_dic.Add(aa.ColumnName, cpk); cpk_dic.Add(step + 1, cpk); } string op = "\t" + get_okpara(); //MessageBox.Show("all_cpk" + all_cpk + " op" + op); label_result.Invoke(new Action(() => { label_result.Text = string.Format("all_cpk" + all_cpk + " op" + op); })); if (all == true) { dataGridView1.Invoke(new Action(() => { #region 添加一行总结 DataTable temp_table = dataGridView1.DataSource as DataTable; int last_row = temp_table.Rows.Count; if (temp_table.Rows[last_row - 1]["零件号"].ToString() == "结果与CPK") { return; } DataRow temp_dr = temp_table.NewRow(); temp_dr["零件号"] = "结果与CPK"; foreach (KeyValuePair <int, double> par in cpk_dic) { // string key_name = par.Key.Replace("s", "步骤"); // string key_name = par.Key; temp_dr[par.Key + 1] = par.Value.ToString("0.00"); } temp_dr["结果"] = op.Replace("\t", ""); temp_table.Rows.Add(temp_dr); dataGridView1.Refresh(); jisuan_f = true; })); } else { } dgv.Invoke(new Action(() => { #region 添加一行总结 DataTable temp_table = dgv.DataSource as DataTable; int last_row = temp_table.Rows.Count; if (last_row >= 1) { if (temp_table.Rows[last_row - 1]["零件号"].ToString() == "结果与CPK") { return; } DataRow temp_dr = temp_table.NewRow(); temp_dr["零件号"] = "结果与CPK"; foreach (KeyValuePair <int, double> par in cpk_dic) { // string key_name = par.Key.Replace("s", "步骤"); temp_dr[par.Key + 1] = par.Value.ToString("0.00"); } temp_dr["结果"] = op.Replace("\t", ""); temp_table.Rows.Add(temp_dr); dgv.Refresh(); } })); #endregion }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtmeasureb.Text.Trim().Length == 0) { strErr += "measureb不能为空!\\n"; } if (!PageValidate.IsDateTime(txttime.Text)) { strErr += "time格式错误!\\n"; } if (this.txtstep1.Text.Trim().Length == 0) { strErr += "step1不能为空!\\n"; } if (this.txtstep2.Text.Trim().Length == 0) { strErr += "step2不能为空!\\n"; } if (this.txtstep3.Text.Trim().Length == 0) { strErr += "step3不能为空!\\n"; } if (this.txtstep4.Text.Trim().Length == 0) { strErr += "step4不能为空!\\n"; } if (this.txtstep5.Text.Trim().Length == 0) { strErr += "step5不能为空!\\n"; } if (this.txtOKorNG.Text.Trim().Length == 0) { strErr += "OKorNG不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string measureb = this.txtmeasureb.Text; DateTime time = DateTime.Parse(this.txttime.Text); string step1 = this.txtstep1.Text; string step2 = this.txtstep2.Text; string step3 = this.txtstep3.Text; string step4 = this.txtstep4.Text; string step5 = this.txtstep5.Text; string OKorNG = this.txtOKorNG.Text; Maticsoft.Model.test model = new Maticsoft.Model.test(); model.measureb = measureb; model.time = time; model.step1 = step1; model.step2 = step2; model.step3 = step3; model.step4 = step4; model.step5 = step5; model.OKorNG = OKorNG; Maticsoft.BLL.test bll = new Maticsoft.BLL.test(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }