protected void btnOK_Click(object sender, EventArgs e) { try { if (_ProcessLot == null) { throw new RuleCimesException(TextMessage.Error.T00826(lblUnPackingInventoryLot.Text)); } // 定義交易戳記 var txnStamp = new TransactionStamp(User.Identity.Name, ProgramRight, ProgramRight, ApplicationName); using (var cts = CimesTransactionScope.Create()) { // 將入庫批取消完工 WIPTransaction.UndoFinish(_ProcessLot, txnStamp); var unPackingLot = LotInfo.GetLotByLot(ttbBoxNo.Text.Trim()); // 取得拆包Component var lstUnPackingComp = unPackingLot.GetLotAllComponents(); // 將轉為子單元的批號還原,例如可使用於拆包 var txn = WIPTxn.Default.ConvertToLot(unPackingLot, lstUnPackingComp, txnStamp); txn.LotList.ForEach(lot => { //寫入WMSMaster & Detail var wmsMaster = CSTWMSMastInfo.GetMaterialLotDataByMaterialLot(lot["INVLOT"].ToString()); if (wmsMaster == null) { wmsMaster = InfoCenter.Create <CSTWMSMastInfo>(); wmsMaster.Lot = lot["INVLOT"].ToString(); 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["INVLOT"].ToString(); wmsDetail.ComponentID = comp.ComponentID; wmsDetail.Quantity = comp.ComponentQuantity; wmsDetail.InsertToDB(txnStamp.UserID, txnStamp.RecordTime); }); WIPTransaction.TerminateLot(lot, txnStamp); }); cts.Complete(); } // 返回定義的預設網頁 ReturnToPortal(); } catch (Exception ex) { HandleError(ex); } }