public void listviewBind(string sql) { this.dgv1.AutoGenerateColumns = false; this.dgv1.Rows.Clear(); DataSet ds = MEOsub.QueryPartMiscProcListEPR(sql); DataView dv = ds.Tables[0].DefaultView; int i = 1; foreach (DataRow dr in dv.Table.Rows) { string projectid = dr[1].ToString(); string partno = dr[2].ToString(); string site = dr[0].ToString(); PartParameter pp = PartParameter.Find(0, projectid, partno, site, "weijun.qu"); decimal preQty = 0; decimal singleW = 0; decimal preAlert = 0; if (pp != null) { preQty = pp.PREDICTION_QTY; singleW = pp.WEIGHT_SINGLE; preAlert = pp.PREDICTION_ALERT; } PartRelative pr = new PartRelative(); pr.ERP_PART_NO = partno; pr.STA_PART_NO = partno; pr.SITE = site; pr.PROJECTID = projectid; pr.ACTIVITYSEQ = Convert.ToInt32(Str_activity); string isStandPart = ""; string isMerged = ""; if (pr.IFStandardPart()) { isStandPart = "是"; } if (pr.IFmerged1()) { isMerged = "是"; } string StnPartno = PartRelative.FindRelativeStnPartno(partno, projectid, Convert.ToInt32(Str_activity), site); DataGridViewRow r = new DataGridViewRow(); r.CreateCells(dgv1); r.Cells[1].Value = i.ToString(); r.Cells[2].Value = dr[0].ToString(); r.Cells[3].Value = dr[2].ToString(); r.Cells[4].Value = dr[3].ToString(); r.Cells[5].Value = dr[4].ToString(); dgv1.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; r.Cells[6].Value = pp == null ? string.Empty : pp.PREDICTION_QTY.ToString(); r.Cells[7].Value = pp == null ? string.Empty : pp.WEIGHT_SINGLE.ToString(); r.Cells[8].Value = isMerged; r.Cells[9].Value = isStandPart; r.Cells[10].Value = StnPartno; //r.Cells[8].Value = MeoNo; //r.Cells[9].Value = MeoQty.ToString(); //r.Cells[10].Value = Str_MeoPcs; //r.Cells[11].Value = Str_Meotime; //r.Cells[12].Value = restQty.ToString(); //r.Cells[13].Value = MssQty.ToString(); this.dgv1.Rows.Add(r); i++; } }
private void btn_save_Click(object sender, EventArgs e) { // string projectid = cmb_project.SelectedValue.ToString(); string site = cmb_site.SelectedValue.ToString(); decimal singleWeight = 0; //decimal fpreAlert = 0; decimal fcoe = 0; //decimal.TryParse(sigleWeight, out singleWeight); //decimal.TryParse(preAlert, out fpreAlert); //decimal.TryParse(coe, out fcoe); if (ProjectId == string.Empty) { MessageBox.Show("请选择项目!"); return; } if (dgv1.RowCount == 0) { MessageBox.Show("请选择数据!"); return; } int kqrow; kqrow = dgv1.RowCount - 1; try { //DataSet unitds=PartParameter.QueryPartPara("select name from mm_unit_tab"); #region 循环表,保存数据 for (int i = 0; i <= kqrow; i++) { string partno = dgv1.Rows[i].Cells["零件号"].Value.ToString().Trim(); PartParameter pp = PartParameter.Find(int.Parse(activity), ProjectId, partno, site, LoginUser); PartParameter ppn = new PartParameter(); ppn.PART_NO = partno; ppn.CONTRACT = site; ppn.PROJECTID = ProjectId; ppn.WEIGHT_SINGLE = singleWeight; string preQty = dgv1.Rows[i].Cells["预估量"].Value.ToString().Trim(); decimal fpreQty = string.IsNullOrEmpty(preQty) == true ? 0 : decimal.Parse(preQty); ppn.PREDICTION_QTY = decimal.Round(fpreQty, 2); string preAlert = dgv1.Rows[i].Cells["预警系数"].Value.ToString().Trim(); //decimal fpreAlert = decimal.Parse(preAlert); //ppn.PREDICTION_ALERT = decimal.Round(fpreAlert, 2); //ppn.PREDICTION_ALERT = fpreAlert; //ppn.COEFFICIENT_ERP = fcoe; ppn.DESCRIPTION = ""; ppn.PREDICT_CREATOR = LoginUser; ppn.ECPROJECTID = ecprojectid; ppn.SYSTEMID = int.Parse(activity); //if (dgv1.Rows[i].Cells["分段"].Value != null) // ppn.BLOCKID = dgv1.Rows[i].Cells["分段"].Value.ToString(); ppn.PARTID = int.Parse(dgv1.Rows[i].Cells["序号"].Value.ToString()); #region 判断Unit是否是合格格式 //if (dgv1.Rows[i].Cells[2].Value != null) //{ // string punit = dgv1.Rows[i].Cells[2].Value.ToString().Trim().ToLower(); // DataRow[] pone = unitds.Tables[0].Select("name ='"+punit+"'"); // if (pone.Length != 0) // { // ppn.UNIT = punit; // } // else // { // MessageBox.Show("第"+(i+1)+"行单位名称不规范,请检查!","错误提示"); // dgv1.Rows[i].Selected=true; // return; // } //} #endregion if (pp != null) { if (dgv1.Rows[i].Cells["checkbox"].Value != null) { if (fpreQty > 0 || dgv1.Rows[i].Cells["checkbox"].Value.ToString() == "1") { DateTime cdate = pp.CREATEDATE; int count = ppn.Update(); ppn.LAST_FLAG = 0; ppn.PREDICTION_QTY = pp.PREDICTION_QTY; ppn.PREDICTION_ALERT = pp.PREDICTION_ALERT; ppn.CREATEDATE = cdate; int countnew = 0; if (pp.PREDICTION_QTY != fpreQty) { countnew = ppn.Add(); } if (count == 0) { MessageBox.Show("更新失败"); } } } } else { if (dgv1.Rows[i].Cells["checkbox"].Value != null) { if (fpreQty > 0 || dgv1.Rows[i].Cells["checkbox"].Value.ToString() == "1") { ppn.CREATEDATE = DateTime.Today; ppn.LAST_FLAG = 1; int count = ppn.Add(); if (count == 0) { MessageBox.Show("添加失败"); } } } } } #endregion MessageBox.Show("保存材料预估量成功!! ", "温馨提示!"); } catch (Exception err) { MessageBox.Show("错误原因:" + err.Message, "错误提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } QuerydataBindpara(); }