Esempio n. 1
0
        /// <summary>
        /// 初始化转返工单数据。
        /// </summary>
        private void InitExchangeData()
        {
            string roomName = this.lueFactoryRoom.Text;
            string roomKey  = Convert.ToString(this.lueFactoryRoom.EditValue);

            //必须选择车间。
            if (string.IsNullOrEmpty(roomKey))
            {
                MessageService.ShowMessage(StringParser.Parse("${res:FanHai.Hemera.Addins.WIP.LotExchgWoMultiForm.Msg001}"), MESSAGEBOX_CAPTION);//请选择工厂车间
                //MessageService.ShowMessage(string.Format("请选择工厂车间。", "提示"));
                lueFactoryRoom.Select();
                return;
            }

            string orderKey   = Convert.ToString(this.teNewWorkorderNo.Tag);
            string orderNo    = Convert.ToString(this.teNewWorkorderNo.Text);
            string partNumber = Convert.ToString(this.lueNewPartNumber.EditValue);
            string proId      = this.teNewProductId.Text;

            if (string.IsNullOrEmpty(orderKey))
            {
                MessageService.ShowMessage(StringParser.Parse("${res:FanHai.Hemera.Addins.WIP.WarehouseCtrl.Msg001}"), MESSAGEBOX_CAPTION);//请输入工单号!
                //MessageService.ShowMessage(string.Format("请输入工单号。"),"提示");
                this.teNewWorkorderNo.Select();
                this.teNewWorkorderNo.SelectAll();
                return;
            }

            if (string.IsNullOrEmpty(partNumber))
            {
                MessageService.ShowMessage(StringParser.Parse("${res:FanHai.Hemera.Addins.WIP.LotExchgWoMultiForm.Msg002}"), MESSAGEBOX_CAPTION);//请选择产品
                //MessageService.ShowMessage(string.Format("请选择产品。"), "提示");
                this.lueNewPartNumber.Select();
                return;
            }

            string val = this.txtPalletNo.Text.Trim();

            //托盘号或批次号为空,直接返回。
            if (string.IsNullOrEmpty(val))
            {
                return;
            }
            DataSet dsReturn     = null;
            string  exchangeName = null;

            //按批次转返工
            if (this.chkIsPallet.Checked == true)
            {
                //转工单操作,判断组件所在当前工序是否允许转工单。
                if (this._flag == ExchangeWoFlag.Exchange)
                {
                    bool isAllowExchangeWO = true;
                    //获取批次对应的工步属性信息
                    dsReturn = this._lotEntity.GetLotRouteAttrData(val);
                    //判断获取的工步属性信息是否存在,若不存在默认为允许转工单
                    if (dsReturn.Tables.Contains("LOT_ROUTE_ATTR") &&
                        dsReturn.Tables["LOT_ROUTE_ATTR"].Rows.Count > 0)
                    {
                        DataRow[] drRouteAttr = dsReturn.Tables["LOT_ROUTE_ATTR"]
                                                .Select(string.Format(" ATTRIBUTE_NAME = '{0}'", "IsAllowExchangeWO"));

                        //判断是否有设置IsAllowExchangeWO属性
                        if (drRouteAttr.Length > 0)
                        {
                            string attrVal = Convert.ToString(drRouteAttr[0]["ATTRIBUTE_VALUE"]);
                            if (!bool.TryParse(attrVal, out isAllowExchangeWO))
                            {
                                isAllowExchangeWO = true;
                            }
                        }
                    }
                    //若设置为true允许进行转工单,反之弹窗提示并返回
                    if (isAllowExchangeWO == false)
                    {
                        MessageService.ShowMessage(string.Format("组件【{0}】当前所在工序不允许转工单!", val), "提示");
                        return;
                    }
                }
                dsReturn     = this._lotEntity.GetExchangeData(string.Empty, val);
                exchangeName = "批次号";
            }
            //按托转返工
            else
            {
                dsReturn     = this._lotEntity.GetExchangeData(val, string.Empty);
                exchangeName = "托号";
            }
            if (!string.IsNullOrEmpty(this._lotEntity.ErrorMsg))
            {
                MessageService.ShowError(this._lotEntity.ErrorMsg);
                return;
            }
            //查询转返工数据出错
            if (dsReturn == null ||
                dsReturn.Tables.Contains(POR_LOT_FIELDS.DATABASE_TABLE_NAME) == false)
            {
                MessageService.ShowError(string.Format("查询{0}数据出错,请重试", this._flagName));
                return;
            }
            DataTable dtTempExchangeData = dsReturn.Tables[POR_LOT_FIELDS.DATABASE_TABLE_NAME];

            if (dtTempExchangeData.Rows.Count <= 0)
            {//不存在数据,给出对应提示。
                MessageService.ShowError(string.Format("{1}【{0}】不存在,请确认!", val, exchangeName));
                return;
            }
            DataRow drTempExchangeData = dtTempExchangeData.Rows[0];
            int     stateFalg          = Convert.ToInt32(drTempExchangeData[POR_LOT_FIELDS.FIELD_STATE_FLAG]);
            string  lotOrderNo         = Convert.ToString(drTempExchangeData[POR_LOT_FIELDS.FIELD_WORK_ORDER_NO]);
            string  palletNo           = Convert.ToString(drTempExchangeData[POR_LOT_FIELDS.FIELD_PALLET_NO]);

            //基础数据配置是否比较工单类型。
            string[]  columns                = new string[] { "IsCompareWorkOrderType" };
            string    category               = BASEDATA_CATEGORY_NAME.ExchangeWoConfig;
            DataTable dtExchangeWoConfig     = BaseData.Get(columns, category);
            bool      isCompareWorkorderType = true;

            if (dtExchangeWoConfig != null && dtExchangeWoConfig.Rows.Count > 0)
            {
                string compareWorkOrderType = Convert.ToString(dtExchangeWoConfig.Rows[0]["IsCompareWorkOrderType"]);
                if (!string.IsNullOrEmpty(compareWorkOrderType))
                {
                    isCompareWorkorderType = Convert.ToBoolean(compareWorkOrderType);
                }
            }
            //转工单:工单类型条件判断
            if (isCompareWorkorderType)
            {
                Hashtable hsOrderType = new Hashtable();
                hsOrderType.Add(POR_WORK_ORDER_FIELDS.FIELD_ORDER_NUMBER, orderNo);
                hsOrderType.Add(POR_WORK_ORDER_FIELDS.FIELD_ORDER_NUMBER + "2", lotOrderNo);
                ExchangeWoEntity exchangewoEntity = new ExchangeWoEntity();
                string           msg = exchangewoEntity.CompareWorkOrderType(hsOrderType);
                if (!string.IsNullOrEmpty(msg))
                {
                    MessageService.ShowError(msg);
                    teNewWorkorderNo.SelectAll();
                    teNewWorkorderNo.Select();
                    return;
                }
            }
            //未包装数据不能返工单。
            if (this._flag == ExchangeWoFlag.Repair && string.IsNullOrEmpty(palletNo))
            {
                MessageService.ShowError(string.Format("{1}【{0}】未包装,不符合{2}作业要求。", val, exchangeName, this._flagName));
                txtPalletNo.SelectAll();
                txtPalletNo.Select();
                return;
            }
            //未入库数据不能返工单。
            else if (this._flag == ExchangeWoFlag.Repair && !string.IsNullOrEmpty(palletNo) && stateFalg <= 10)
            {
                MessageService.ShowError(string.Format("{1}【{0}】未入库,不符合{2}作业要求。", val, exchangeName, this._flagName));
                txtPalletNo.SelectAll();
                txtPalletNo.Select();
                return;
            }
            //已包装数据不能转工单。
            else if (this._flag == ExchangeWoFlag.Exchange && !string.IsNullOrEmpty(palletNo))
            {
                MessageService.ShowError(string.Format("{1}【{0}】已包装,不符合{2}作业要求。", val, exchangeName, this._flagName));
                txtPalletNo.SelectAll();
                txtPalletNo.Select();
                return;
            }//已入库数据不能转工单。
            else if (this._flag == ExchangeWoFlag.Exchange && stateFalg >= 10)
            {
                MessageService.ShowError(string.Format("{1}【{0}】已入库,不符合{2}作业要求。", val, exchangeName, this._flagName));
                txtPalletNo.SelectAll();
                txtPalletNo.Select();
                return;
            }

            //增加新列,用于设置新产品数据。
            if (!dtTempExchangeData.Columns.Contains("NEW_PRO_ID"))
            {
                dtTempExchangeData.Columns.Add("NEW_PRO_ID");
            }
            if (!dtTempExchangeData.Columns.Contains("NEW_PART_NUMBER"))
            {
                dtTempExchangeData.Columns.Add("NEW_PART_NUMBER");
            }
            if (!dtTempExchangeData.Columns.Contains("NEW_WORK_ORDER_NO"))
            {
                dtTempExchangeData.Columns.Add("NEW_WORK_ORDER_NO");
            }
            if (!dtTempExchangeData.Columns.Contains("NEW_WORK_ORDER_KEY"))
            {
                dtTempExchangeData.Columns.Add("NEW_WORK_ORDER_KEY");
            }
            foreach (DataRow drExchangeDataDetail in dtTempExchangeData.Rows)
            {
                //设置明细数据的新工单、产品
                drExchangeDataDetail["NEW_WORK_ORDER_KEY"] = orderKey;
                drExchangeDataDetail["NEW_WORK_ORDER_NO"]  = orderNo;
                drExchangeDataDetail["NEW_PART_NUMBER"]    = partNumber;
                drExchangeDataDetail["NEW_PRO_ID"]         = proId;

                drExchangeDataDetail[POR_LOT_FIELDS.FIELD_FACTORYROOM_KEY]  = roomKey;
                drExchangeDataDetail[POR_LOT_FIELDS.FIELD_FACTORYROOM_NAME] = roomName;
            }
            if (!CheckExchangeData(dtTempExchangeData))
            {
                return;
            }
            dtTempExchangeData.PrimaryKey = new DataColumn[] { dtTempExchangeData.Columns[POR_LOT_FIELDS.FIELD_LOT_KEY] };
            if (dtExchangeData == null)
            {
                dtExchangeData               = dtTempExchangeData.Clone();
                this.gcExchangeWo.MainView   = gvExchangeWo;
                this.gcExchangeWo.DataSource = dtExchangeData;
            }

            dtExchangeData.Merge(dtTempExchangeData, true);
            this.gvExchangeWo.BestFitColumns();

            this.txtPalletNo.Select();
            this.txtPalletNo.SelectAll();
        }