示例#1
0
        /// <summary>
        /// 来料接收
        /// </summary>
        private void tsbReceiveMaterial_Click(object sender, EventArgs e)
        {
            ReceiveMaterialEntity receiveMaterial = new ReceiveMaterialEntity();

            if (lueShiftName.Text == "")
            {
                MessageBox.Show("班次信息不能为空!");
            }
            if (txtOperatorNumber.Text == "")
            {
                MessageBox.Show("员工号不能为空!");
            }

            #region 把视图上显示的数据填充到Table中
            int count = 0;
            this.gdvMaterialDefault.RefreshData();
            DataTable dataTable = CreatTable();
            for (int i = 0; i < gdvMaterialDefault.RowCount; i++)
            {
                bool   bSelected  = false;
                string isSelected = gdvMaterialDefault.GetRowCellValue(i, "IsSelected").ToString();
                if (!bool.TryParse(isSelected, out bSelected))
                {
                    bSelected = false;
                }
                if (bSelected) //如果被选中
                {
                    //SAP_ISSURE_KEY
                    //W.MBLNR          AS 来料单号,
                    //W.MATNR          AS 物料规格,
                    //W.MATXT          AS 物料描述,
                    //W.CHARG          AS 物料批号
                    //W.AUFNR          AS 工单号码,
                    //W.ERFME          AS 计量单位,
                    //W.ERFMG          AS 实领数量,
                    //W.LLIEF          AS 批次供应商
                    string strRowId           = gdvMaterialDefault.GetRowCellValue(i, "ROWNUM").ToString();
                    string strSap_issureKey   = gdvMaterialDefault.GetRowCellValue(i, "SAP_ISSURE_KEY").ToString();
                    string strOrderNumber     = gdvMaterialDefault.GetRowCellValue(i, "AUFNR").ToString();
                    string strMATNR           = gdvMaterialDefault.GetRowCellValue(i, "MATNR").ToString();
                    string strCHARG           = gdvMaterialDefault.GetRowCellValue(i, "CHARG").ToString();
                    string strMATXT           = gdvMaterialDefault.GetRowCellValue(i, "MATXT").ToString();
                    string strAUFNR           = gdvMaterialDefault.GetRowCellValue(i, "AUFNR").ToString();
                    string strERFME           = gdvMaterialDefault.GetRowCellValue(i, "ERFME").ToString();
                    string strERFMG           = gdvMaterialDefault.GetRowCellValue(i, "ERFMG").ToString();
                    string strLLIEF           = gdvMaterialDefault.GetRowCellValue(i, "LLIEF").ToString();
                    string strOperation       = gdvMaterialDefault.GetRowCellValue(i, "Operation").ToString();
                    string strOnlineWarehouse = gdvMaterialDefault.GetRowCellValue(i, "OnlineWarehouse").ToString();

                    //工序线边仓不能为空
                    if (strOperation == "" || strOnlineWarehouse == "")
                    {
                        string erroMessage = string.Format("必须为序号为{0}的记录设置工序名称和线上仓名称!", strRowId);
                        MessageBox.Show(erroMessage);
                        return;
                    }

                    string factoryNumber = receiveMaterial.GetFactoryByOrderNumber(strOrderNumber);
                    string factoryOnline = receiveMaterial.GetFactoryByStore(strOnlineWarehouse);
                    //判断工单信息和仓位信息对应的工厂是否一致
                    if (factoryNumber != factoryOnline)
                    {
                        string erroMessage = string.Format("不能将序号{0}的物料接收到指定的线边仓!", strRowId);
                        MessageBox.Show(erroMessage);
                        return;
                    }


                    dataTable.Rows.Add();
                    dataTable.Rows[count]["SAP_ISSURE_KEY"]  = gdvMaterialDefault.GetRowCellValue(i, "SAP_ISSURE_KEY").ToString();;
                    dataTable.Rows[count]["MBLNR"]           = gdvMaterialDefault.GetRowCellValue(i, "MBLNR").ToString();
                    dataTable.Rows[count]["MATNR"]           = gdvMaterialDefault.GetRowCellValue(i, "MATNR").ToString();
                    dataTable.Rows[count]["CHARG"]           = gdvMaterialDefault.GetRowCellValue(i, "CHARG").ToString();
                    dataTable.Rows[count]["MATXT"]           = gdvMaterialDefault.GetRowCellValue(i, "MATXT").ToString();
                    dataTable.Rows[count]["AUFNR"]           = gdvMaterialDefault.GetRowCellValue(i, "AUFNR").ToString();
                    dataTable.Rows[count]["ERFME"]           = gdvMaterialDefault.GetRowCellValue(i, "ERFME").ToString();
                    dataTable.Rows[count]["ERFMG"]           = gdvMaterialDefault.GetRowCellValue(i, "ERFMG").ToString();
                    dataTable.Rows[count]["LLIEF"]           = gdvMaterialDefault.GetRowCellValue(i, "LLIEF").ToString();
                    dataTable.Rows[count]["Operation"]       = gdvMaterialDefault.GetRowCellValue(i, "Operation").ToString();
                    dataTable.Rows[count]["OnlineWarehouse"] = gdvMaterialDefault.GetRowCellValue(i, "OnlineWarehouse").ToString();
                    dataTable.Rows[count]["SHIFT_NAME"]      = lueShiftName.Text;
                    dataTable.Rows[count]["OPERATOR"]        = PropertyService.Get(PROPERTY_FIELDS.USER_NAME);
                    dataTable.Rows[count]["EDIT_TIMEZONE"]   = PropertyService.Get(PROPERTY_FIELDS.TIMEZONE);

                    count++;
                }
            }
            #endregion


            if (dataTable.Rows.Count > 0)
            {
                receiveMaterial.ReceiveLineMaterial(dataTable);

                if (receiveMaterial.ErrorMsg == "")
                {
                    MessageBox.Show("信息保存成功!");
                    BindMaterialDetail();
                }
                else
                {
                    MessageService.ShowError(receiveMaterial.ErrorMsg);
                }
            }
            else
            {
                MessageBox.Show("必须选择一条数据!");
            }
        }