private void btn_save_Click(object sender, EventArgs e)
        {
            if (ProjectId == string.Empty)
            {
                MessageBox.Show("请选择项目");
                return;
            }
            if (Str_Area == string.Empty)
            {
                MessageBox.Show("请选择区域");
                return;
            }
            if (ActivityName == string.Empty)
            {
                MessageBox.Show("请选择分项");
                return;
            }
            string Site = cmb_site.SelectedValue.ToString();

            if (Site == string.Empty)
            {
                MessageBox.Show("请选择域");
                return;
            }
            int rowcou = dgv1.RowCount;

            if (rowcou == 0)
            {
                MessageBox.Show("请选择所要申请的材料", "操作提示");
                return;
            }

            rowcou = dgv1.RowCount;

            //for (int i = 0; i < rowcou; i++)
            //{

            //    if (dgv1.Rows[i].Cells["序号"].Value == null)
            //    {

            //        MessageBox.Show("第" + (i + 1) + "行请填写材料", "提示");
            //        return;
            //    }


            //}
            SetRowNo();
            for (int i = 0; i < rowcou; i++)
            {
                #region 检查必填项以及数据的合法性
                string rowid = dgv1.Rows[i].Cells["行"].Value.ToString();
                if (dgv1.Rows[i].Cells["申请数量"].Value != null)
                {
                    if (!BaseClass.validateNum(dgv1.Rows[i].Cells["申请数量"].Value.ToString().Trim()))
                    {
                        MessageBox.Show("第 " + rowid + " 行申请数量请填写数字", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }
                    if (dgv1.Rows[i].Cells["申请数量"].Value.ToString().Trim().Contains("-"))
                    {
                        MessageBox.Show("第 " + rowid + " 行申请数量为负,请检查", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("第 " + rowid + " 行请填写申请数量", "提示");
                    //dgv1.Rows[i].Selected = true;
                    dgv1.CurrentCell = dgv1.Rows[i].Cells["申请数量"];
                    return;
                }

                if (dgv1.Rows[i].Cells["MEO_ERP"].Value != null)
                {
                    if (!BaseClass.validateNum(dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString().Trim()))
                    {
                        MessageBox.Show("第 " + rowid + " 行MEO号请填写数字", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }
                }
                else
                {
                    //if (MEOID != "0")
                    //{
                    //    MessageBox.Show("第 " + rowid + " 行请填写MEO号", "提示");
                    //    //dgv1.Rows[i].Selected = true;
                    //    dgv1.CurrentCell = dgv1.Rows[i].Cells["MEO_ERP"];
                    //    return;
                    //}
                }

                if (dgv1.Rows[i].Cells["需求日期"].Value == null)
                {
                    MessageBox.Show("第 " + rowid + " 行请填写需求日期", "提示");
                    dgv1.Rows[i].Selected = true;
                    return;
                }
                if (dgv1.Rows[i].Cells["需求原因"].Value == null)
                {
                    MessageBox.Show("第 " + rowid + " 行请填写需求原因", "提示");
                    dgv1.Rows[i].Selected = true;
                    return;
                }
                if (dgv1.Rows[i].Cells["需求日期"].Value != null)
                {
                    if (Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value.ToString()) < DateTime.Today)
                    {
                        MessageBox.Show("第 " + rowid + " 行需求日期不能小于当前日期", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }
                }
                if (dgv1.Rows[i].Cells["MEO_ERP"].Value != null)
                {
                    string partno = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                    if (MEOsub.meomssExistERP(dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString(), partno) == 0)
                    {
                        MessageBox.Show("第 " + rowid + " 行ERP中的MEO号不存在", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }
                }
                #endregion
            }

            MEOmain MM_MEO     = new MEOmain();
            string  contractno = cmb_site.SelectedValue.ToString();
            MM_MEO.CONTRACT = contractno;
            string drawinfor = txt_designcode.Text.Trim();
            MM_MEO.SYSTEM_ID      = Str_Area;
            MM_MEO.REQUIRE_NO     = MakeMEOManual(int.Parse(cmb_discipline.SelectedValue.ToString()));
            MM_MEO.INFORMATION    = drawinfor;
            MM_MEO.CREATER        = User.cur_user;
            MM_MEO.PARTTYPE_ID    = Str_FX;
            MM_MEO.DISCIPLINEID   = cmb_discipline.SelectedValue.ToString();
            MM_MEO.PROJECT_ID     = ProjectId;
            MM_MEO.ECPROJECTID    = ProjectSystem.FindProjectid(ProjectId).ToString();
            MM_MEO.ERP_DISCIPLINE = Str_Discipline;
            MM_MEO.ERP_PARTTYPE   = ActivityName;

            #region 新增保存MEO
            if (MEOID == "0")
            {
                int mmreqid = MM_MEO.REQUIRE_Add();

                if (mmreqid > 0)
                {
                    #region 保存MEO从表
                    for (int i = 0; i < rowcou; i++)
                    {
                        //string partid = dgv1.Rows[i].Cells["序号"].Value.ToString();
                        string  partno    = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                        string  unitmeas  = dgv1.Rows[i].Cells["单位"].Value.ToString();
                        string  part_desc = dgv1.Rows[i].Cells["零件描述"].Value.ToString();
                        string  reqdate   = dgv1.Rows[i].Cells["需求日期"].Value.ToString();
                        string  reqreason = dgv1.Rows[i].Cells["需求原因"].Value.ToString();
                        string  preQty    = dgv1.Rows[i].Cells["申请数量"].Value.ToString().Trim();
                        string  remark    = dgv1.Rows[i].Cells["备注"].Value.ToString();
                        decimal fpreQty   = decimal.Parse(preQty);
                        MEOsub  MM_submeo = new MEOsub();
                        MM_submeo.REQUIRE_QTY = decimal.Round(fpreQty, 2);
                        //MM_submeo.PART_ID = int.Parse(partid);
                        MM_submeo.REQUIRE_DATE = Convert.ToDateTime(reqdate);
                        MM_submeo.REASON_CODE  = reqreason;
                        MM_submeo.CREATER      = User.cur_user;
                        MM_submeo.REQUIRE_ID   = mmreqid;
                        MM_submeo.PROJECT_ID   = ProjectId;
                        MM_submeo.PART_NO      = partno;
                        MM_submeo.UNIT_MEAS    = unitmeas;
                        MM_submeo.PART_NAME    = part_desc;
                        MM_submeo.REMARK       = remark;
                        MM_submeo.REQUIRELINE_Add();
                    }
                    MEOID = mmreqid.ToString();
                    MessageBox.Show("保存MEO成功!", "提示");
                    lbl_manual.Visible = true;
                    tb_manul.Visible   = true;
                    tb_manul.Text      = MM_MEO.REQUIRE_NO;
                    return;

                    #endregion
                }
                else
                {
                    MessageBox.Show("保存失败!", "提示");
                    return;
                }
            }
            #endregion

            #region 更新保存MEO
            //if (MEOID != "0")
            //{
            //    MM_MEO.REQUIRE_ID = int.Parse(MEOID);
            //    MM_MEO.REQUIRE_Update();
            //    MM_MEO.MEODelete(int.Parse(MEOID));
            //    #region 更新保存MEO从表
            //    for (int i = 0; i < rowcou; i++)
            //    {
            //        //string partid = dgv1.Rows[i].Cells["序号"].Value.ToString();
            //        string reqdate = dgv1.Rows[i].Cells["需求日期"].Value.ToString();
            //        string reqreason = dgv1.Rows[i].Cells["需求原因"].Value.ToString();
            //        string preQty = dgv1.Rows[i].Cells["申请数量"].Value.ToString().Trim();
            //        string meonoerp = "";
            //        if (dgv1.Rows[i].Cells["MEO_ERP"].Value != null)
            //        {
            //            meonoerp = dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString().Trim();
            //        }
            //        decimal fpreQty = decimal.Parse(preQty);
            //        MEOsub MM_submeo = new MEOsub();
            //        MM_submeo.REQUIRE_QTY = decimal.Round(fpreQty, 2);
            //        //MM_submeo.PART_ID = int.Parse(partid);
            //        MM_submeo.REQUIRE_DATE = Convert.ToDateTime(reqdate);
            //        MM_submeo.REASON_CODE = reqreason;
            //        MM_submeo.CREATER = User.cur_user;
            //        MM_submeo.REQUIRE_ID = int.Parse(MEOID);
            //        MM_submeo.PROJECT_ID = ProjectId;
            //        MM_submeo.MEO_ERP = meonoerp;
            //        MM_submeo.REQUIRELINE_Add();
            //    }
            //    MessageBox.Show("保存MEO成功!", "提示");
            //    #endregion
            //}

            #endregion

            //    QuerydataBind();
        }
예제 #2
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (dgv1.RowCount < 1)
            {
                return;
            }

            if (ProjectId == string.Empty)
            {
                MessageBox.Show("请选择项目");
                return;
            }

            int rowcou = dgv1.RowCount;

            if (rowcou == 0)
            {
                MessageBox.Show("请选择所要下发的材料", "操作提示");
                return;
            }

            rowcou = dgv1.RowCount;

            //for (int i = 0; i < rowcou; i++)
            //{

            //    if (dgv1.Rows[i].Cells["序号"].Value == null)
            //    {

            //        MessageBox.Show("第" + (i + 1) + "行请填写材料", "提示");
            //        return;
            //    }


            //}
            SetRowNo();
            try
            {
                for (int i = 0; i < rowcou; i++)
                {
                    #region 检查必填项以及数据的合法性
                    string rowid = dgv1.Rows[i].Cells["行"].Value.ToString();
                    if (dgv1.Rows[i].Cells["需求数量"].Value != null)
                    {
                        if (!BaseClass.validateNum(dgv1.Rows[i].Cells["需求数量"].Value.ToString().Trim()))
                        {
                            MessageBox.Show("第 " + rowid + " 行需求数量请填写数字", "提示");
                            dgv1.Rows[i].Selected = true;
                            return;
                        }
                        if (dgv1.Rows[i].Cells["需求数量"].Value.ToString().Trim().Contains("-"))
                        {
                            MessageBox.Show("第 " + rowid + " 行需求数量为负,请检查", "提示");
                            dgv1.Rows[i].Selected = true;
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("第 " + rowid + " 行请填写需求数量", "提示");
                        //dgv1.Rows[i].Selected = true;
                        dgv1.CurrentCell = dgv1.Rows[i].Cells["需求数量"];
                        return;
                    }

                    //if (dgv1.Rows[i].Cells["MEO_ERP"].Value != null)
                    //{
                    //    if (!BaseClass.validateNum(dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString().Trim()))
                    //    {
                    //        MessageBox.Show("第 " + rowid + " 行MEO号请填写数字", "提示");
                    //        dgv1.Rows[i].Selected = true;
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    //    //if (MEOID != "0")
                    //    //{
                    //    //    MessageBox.Show("第 " + rowid + " 行请填写MEO号", "提示");
                    //    //    //dgv1.Rows[i].Selected = true;
                    //    //    dgv1.CurrentCell = dgv1.Rows[i].Cells["MEO_ERP"];
                    //    //    return;
                    //    //}
                    //}

                    if (dgv1.Rows[i].Cells["需求日期"].Value == null)
                    {
                        MessageBox.Show("第 " + rowid + " 行请填写需求日期", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }
                    //if (dgv1.Rows[i].Cells["需求日期"].Value != null)
                    //{
                    //    if (Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value.ToString()) < DateTime.Today)
                    //    {
                    //        MessageBox.Show("第 " + rowid + " 行需求日期不能小于当前日期", "提示");
                    //        dgv1.Rows[i].Selected = true;
                    //        return;
                    //    }
                    //}
                    if (dgv1.Rows[i].Cells["需求原因"].Value == null)
                    {
                        MessageBox.Show("第 " + rowid + " 行请填写需求原因", "提示");
                        dgv1.Rows[i].Selected = true;
                        return;
                    }

                    if (dgv1.Rows[i].Cells["MEO_ERP"].Value != null)
                    {
                        string partno = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                        if (MEOsub.meomssExistERP(dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString(), partno) == 0)
                        {
                            MessageBox.Show("第 " + rowid + " 行ERP中的MEO号不存在", "提示");
                            dgv1.Rows[i].Selected = true;
                            return;
                        }
                    }
                    #endregion
                }
                for (int i = 0; i < rowcou; i++)
                {
                    #region 循环保存数据
                    string   Rationid   = dgv1.Rows[i].Cells["Ration_id"].Value.ToString();
                    string   contractno = cmb_site.SelectedValue.ToString();
                    string   Partno     = dgv1.Rows[i].Cells["零件号"].Value.ToString();
                    Decimal  Reqqty     = Decimal.Parse(dgv1.Rows[i].Cells["需求数量"].Value.ToString());
                    DateTime ReqDate    = Convert.ToDateTime(dgv1.Rows[i].Cells["需求日期"].Value.ToString());
                    //string purpose = txt_purpose.Text.Trim().ToString();
                    string blockId    = cmb_block.SelectedValue.ToString();
                    string ReasonCode = dgv1.Rows[i].Cells["需求原因"].Value.ToString();
                    //string DesignCode = txt_designcode.Text.Trim().ToString();
                    string ReqNo  = dgv1.Rows[i].Cells["MEO_ERP"].Value.ToString();
                    string remark = dgv1.Rows[i].Cells["备注"].Value.ToString();
                    //string isInventory = chb_useInv.Checked == true ? "是" : "否";
                    string Partname = dgv1.Rows[i].Cells["零件描述"].Value.ToString();
                    string zyname   = dgv1.Rows[i].Cells["dt_zy"].Value.ToString();
                    string qyname   = dgv1.Rows[i].Cells["dt_qy"].Value.ToString();
                    string fxname   = dgv1.Rows[i].Cells["dt_fx"].Value.ToString();
                    string zlname   = dgv1.Rows[i].Cells["dt_zl"].Value.ToString();
                    Ration mp       = new Ration();
                    mp.PROJECT_ID  = ProjectId;
                    mp.RATION_ID   = Convert.ToInt32(Rationid);
                    mp.PART_NO     = Partno;
                    mp.ISSUED_QTY  = decimal.Round(Reqqty, 2);
                    mp.ISSUED_DATE = ReqDate;
                    //mp.IF_INVENTORY = isInventory;
                    //mp.PURPOSE = purpose;
                    mp.BLOCK_ID    = blockId;
                    mp.REASON_CODE = ReasonCode;
                    //mp.DESIGN_CODE = DesignCode;
                    mp.REMARK          = remark;
                    mp.INFORMATION     = remark;
                    mp.CONTRACT        = contractno;
                    mp.CREATER         = User.cur_user;
                    mp.PART_NAME       = Partname;
                    mp.ECPROJECTID     = ecprojectid;
                    mp.PART_ZONE       = qyname;
                    mp.PART_FX         = fxname;
                    mp.PART_DISCIPLINE = zyname;
                    mp.PART_TYPE       = zlname;
                    XmlOper.setXML("Block", blockId);
                    if (Rationid != "0")
                    {
                        //mp.RATION_ID = Convert.ToInt32(lbl_rationid.Text);
                        int n = mp.Update();
                    }
                    else
                    {
                        int n = mp.Add();
                    }
                    #endregion
                }
                MessageBox.Show("保存成功!!!");
            }
            catch (Exception err)
            {
                MessageBox.Show("错误原因:" + err.Message, "错误提示信息",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //    QuerydataBind();
        }