Example #1
0
        /// <summary>
        /// 輸入機加批號
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ttbLot_TextChanged(object sender, EventArgs e)
        {
            try
            {
                #region 驗證批號存在性
                _LotData = LotInfoEx.GetLotByLot(ttbLot.Text);

                if (_LotData == null)
                {
                    //[00030]{0}:{1}不存在!
                    throw new Exception(TextMessage.Error.T00030(lblLot.Text, ttbLot.Text));
                }
                #endregion

                #region 驗證批號狀態,Run的批號
                if (_LotData.Status != LotDefaultStatus.Run.ToString())
                {
                    //狀態為{0},不可執行
                    throw new Exception(RuleMessage.Error.C10003(_LotData.Status));
                }
                #endregion

                #region 驗證currentRule
                if (_LotData.CurrentRuleName != _ProgramInformationBlock.ProgramRight)
                {
                    //該批號作業為XXXX,不為此功能,請遵循作業規範
                    throw new Exception(RuleMessage.Error.C10004(_LotData.CurrentRuleName));
                }
                #endregion

                #region 維修原因碼(DropDownList):依照原因碼工作站設定,帶出原因碼
                ddlRepairReasonCode.Items.Clear();

                List <BusinessReason> reasonList = ReasonCategoryInfo.GetOperationRuleCategoryReasonsWithReasonDescr(_LotData.CurrentRuleName, _LotData.OperationName, "Default", ReasonMode.Category);

                if (reasonList.Count > 0)
                {
                    ddlRepairReasonCode.DataSource     = reasonList;
                    ddlRepairReasonCode.DataTextField  = "ReasonDescription";
                    ddlRepairReasonCode.DataValueField = "ReasonCategorySID";
                    ddlRepairReasonCode.DataBind();

                    if (ddlRepairReasonCode.Items.Count != 1)
                    {
                        ddlRepairReasonCode.Items.Insert(0, "");
                    }
                    else
                    {
                        ddlRepairReasonCode.SelectedIndex = 0;
                    }
                }
                else
                {
                    //[00641]規則:{0} 工作站:{1} 使用的原因碼未設定,請洽IT人員!
                    throw new Exception(TextMessage.Error.T00641(ProgramRight, _LotData.OperationName));
                }
                #endregion

                //取得工件序號
                var componentDataList = ComponentInfoEx.GetDataByCurrentLot(_LotData.Lot);
                if (componentDataList.Count > 0)
                {
                    ttbItemSN.Text = componentDataList[0].ComponentID;
                }

                //取得送待判原因
                var lotDefectData = LotDefectInfoEx.GetDataByLotAndComponentID(_LotData.Lot, ttbItemSN.Text);
                if (lotDefectData != null)
                {
                    _DefectJudgementData = CSTWIPDefectJudgementInfo.GetDataByWIPDefectSID(lotDefectData.DefectSID);

                    if (_DefectJudgementData != null)
                    {
                        ttbJudgeReason.Text = _DefectJudgementData.Reason;
                    }
                }

                ttbRepairDescr.Text = "";
                btnOK.Enabled       = true;
            }
            catch (Exception ex)
            {
                ClearField();
                AjaxFocus(ttbLot);
                HandleError(ex);
            }
        }
Example #2
0
        /// <summary>
        /// 確認
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                TransactionStamp txnStamp = new TransactionStamp(User.Identity.Name, ProgramRight, ProgramRight, ApplicationName);

                using (var cts = CimesTransactionScope.Create())
                {
                    if (_SelectLotDatas.Count > 0)
                    {
                        string sLotInString = "";
                        // 組出where in字串
                        _SelectLotDatas.ForEach(p =>
                        {
                            sLotInString += "'" + p.Lot + "',";
                        });
                        sLotInString = sLotInString.EndsWith(",") ? sLotInString.Substring(0, sLotInString.Length - 1) : sLotInString;

                        var    dtInvData = DBCenter.GetDataTable(@"SELECT WO,INVLOT,SUM(QUANTITY) QUANTITY,DEVICE,FACTORY FROM MES_WIP_LOT  WHERE LOT IN(" + sLotInString + ") GROUP BY WO,INVLOT,DEVICE,FACTORY ORDER BY WO");
                        string headerSID = "";
                        string date      = txnStamp.RecordTime.Substring(0, 10).Replace("/", "");
                        string time      = txnStamp.RecordTime.Substring(11).Replace(":", "");
                        string preWo     = string.Empty;
                        int    seq       = 1;
                        // SAI倉位對應表
                        var lstSAIWarehouse = WpcExClassItemInfo.GetInfoByClass("SAIWarehouse");

                        dtInvData.Rows.LoopDo <DataRow>((p, i) =>
                        {
                            string currentWO = p["WO"].ToString();
                            string device    = p["DEVICE"].ToString();
                            string factory   = p["FACTORY"].ToString();
                            string invLot    = p["INVLOT"].ToString();
                            string qty       = p["QUANTITY"].ToString();
                            if (preWo != currentWO)
                            {
                                seq       = 1;
                                headerSID = DBCenter.GetSystemID();
                                DBCenter.ExecuteParse(@"INSERT INTO PPFHK (SID, WDATE, WTIME, BUDAT, AUFNR, FLAG) 
                                    VALUES (#[STRING], #[STRING], #[STRING], #[STRING], #[STRING],'N')", headerSID, date, time, date, currentWO);
                            }
                            //寫入PPFHP
                            //WERKS:Factory
                            //LGORT:入庫倉位
                            //CHARG:INVLOT
                            //MATNR:Device
                            var lstDetail     = _SelectLotDatas.FindAll(select => select.InventoryLot == invLot);
                            var warehouseInfo = lstSAIWarehouse.Find(wpcItem => wpcItem.Remark01 == lstDetail[0].Process && wpcItem.Remark03 == "DEFECT");
                            if (warehouseInfo == null)
                            {
                                //T00555:查無資料,請至系統資料維護新增類別{0}、項目{1}!
                                throw new CimesException(TextMessage.Error.T00555("SAIWarehouse", lstDetail[0].Process + "Remark03:DEFECT"));
                            }
                            DBCenter.ExecuteParse(@"INSERT INTO PPFHP (SID, SEQNR, WDATE, WTIME, MATNR, WERKS, LGORT, CHARG, MENGE, MEINS, FLAG)
                                VALUES (#[STRING], #[DECIMAL], #[STRING], #[STRING], #[STRING], #[STRING], #[STRING], #[STRING], #[STRING], #[STRING], 'N')", headerSID, seq, date, time, device, factory, warehouseInfo.Remark02, invLot, qty, lstDetail[0].Unit);

                            int detailseq = 1;
                            lstDetail.ForEach(lot => {
                                var defectInfo      = CSTWIPDefectJudgementInfo.GetDataByLot(lot.Lot);
                                var reasonGroupInfo = WIPReasonGroupInfoEx.GetReasonGroupByCategory(defectInfo["REASONCATEGORY"].ToString());
                                var reasonGroup     = reasonGroupInfo == null ? "" : reasonGroupInfo.REASONGROUP;
                                //寫入PPBCH
                                DBCenter.ExecuteParse(@"INSERT INTO PPBCH (SID, MATNR, WERKS, CHARG, SEQNO, WDATE, WTIME, CLASS, ATINN, ATWRT, FLAG)
                                    Values (#[STRING], #[STRING], #[STRING], #[STRING], #[DECIMAL], #[STRING], #[STRING], #[STRING], #[STRING], #[STRING], 'N')", headerSID, device, factory, invLot, detailseq, date, time, reasonGroup, defectInfo["REASONCATEGORY"].ToString(), defectInfo.Reason);
                                detailseq += 1;
                            });

                            seq  += 1;
                            preWo = currentWO;
                        });

                        _SelectLotDatas.ForEach(lot =>
                        {
                            //寫入WMSMaster & Detail
                            var wmsMaster = CSTWMSMastInfo.GetMaterialLotDataByMaterialLot(lot.InventoryLot);
                            if (wmsMaster == null)
                            {
                                wmsMaster            = InfoCenter.Create <CSTWMSMastInfo>();
                                wmsMaster.Lot        = lot.InventoryLot;
                                wmsMaster.DeviceName = lot.DeviceName;
                                wmsMaster.RuleName   = txnStamp.RuleName;
                                wmsMaster.InsertToDB(txnStamp.UserID, txnStamp.RecordTime);
                            }
                            //理論上只會有一個Comp
                            lot.GetLotAllComponents().ForEach(comp => {
                                var wmsDetail         = InfoCenter.Create <CSTWMSDetailInfo>();
                                wmsDetail.Lot         = lot.InventoryLot;
                                wmsDetail.ComponentID = comp.ComponentID;
                                wmsDetail.Quantity    = comp.ComponentQuantity;
                                wmsDetail.InsertToDB(txnStamp.UserID, txnStamp.RecordTime);
                            });

                            //將入庫單號回寫到批號身上
                            WIPTransaction.ModifyLotSystemAttribute(lot, "INVNO", ttbDefectNo.Text, txnStamp);

                            //將勾選的批號結批
                            WIPTransaction.TerminateLot(lot, txnStamp);
                        });

                        #region 更新命名規則
                        if (_ExecuteNamingSQLList != null && _ExecuteNamingSQLList.Count > 0)
                        {
                            DBCenter.ExecuteSQL(_ExecuteNamingSQLList);
                        }
                        #endregion

                        cts.Complete();
                    }
                    else
                    {
                        //[00816]請至少選取一個{0}!
                        throw new Exception(TextMessage.Error.T00816(GetUIResource("WorkpieceLot")));
                    }
                }

                ClearField();

                _ProgramInformationBlock.ShowMessage(TextMessage.Hint.T00614(""));
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }