コード例 #1
0
        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();
        }