protected void btnOK_Click(object sender, EventArgs e) { try { // 包裝數量必須符合滿箱數量,否則須拋錯 if (!ckbNoControl.Checked && _PackType == "Standard" && (_PackingList.Count + _RelativePackingList.Count) != ttbMaxPackSize.Text.ToDecimal()) { throw new RuleCimesException(RuleMessage.Error.C10043((_PackingList.Count + _RelativePackingList.Count).ToString(), ttbMaxPackSize.Text)); } // 若包裝方式為左右手,則左右手的輸入數量需相同 if (!ckbNoControl.Checked && _PackType == "Mix" && _PackingList.Count != _RelativePackingList.Count) { throw new RuleCimesException(RuleMessage.Error.C10044(_DeviceName, _PackingList.Count.ToString(), _RelativeDeviceName, _RelativePackingList.Count.ToString())); } // 若包裝方式為左右手,則左右手的輸入數量需相同且需符合滿箱數量乘以二 if (!ckbNoControl.Checked && _PackType == "Mix" && (_PackingList.Count + _RelativePackingList.Count) != (ttbMaxPackSize.Text.ToDecimal() * 2)) { throw new RuleCimesException(RuleMessage.Error.C10043((_PackingList.Count + _RelativePackingList.Count).ToString(), (ttbMaxPackSize.Text.ToDecimal() * 2).ToString())); } if (ddlInspector.SelectedValue.IsNullOrEmpty()) { //[00826] 請輸入{0}! throw new RuleCimesException(TextMessage.Error.T00826(lblInspector.Text), ddlInspector); } var lstSourceLot = new List <LotInfo>(); // 定義交易戳記 var txnStamp = new TransactionStamp(User.Identity.Name, ProgramRight, ProgramRight, ApplicationName); using (var cts = CimesTransactionScope.Create()) { // 若有不同的批號需拆批 _PackingList.Distinct <PackingInfo>(new PackCompare()).ToList().ForEach(p => { lstSourceLot.Add(SplitLot(p.LotInfo, false, txnStamp)); }); // 若有不同的批號需拆批 _RelativePackingList.Distinct <PackingInfo>(new PackCompare()).ToList().ForEach(p => { lstSourceLot.Add(SplitLot(p.LotInfo, true, txnStamp)); }); #region SplitBoxLot List <SqlAgent> splitLotArchiSQLList = new List <SqlAgent>(); var generator = NamingIDGenerator.GetRule("BoxNo"); if (generator == null) { //WRN-00411,找不到可產生的序號,請至命名規則維護設定,規則名稱:{0}!!! throw new Exception(TextMessage.Error.T00437("BoxNo")); } var serialData = generator.GenerateNextIDs(1, lstSourceLot[0], new string[] { }, User.Identity.Name); splitLotArchiSQLList = serialData.Second; var boxNoLotID = serialData.First[0]; var reasonCategoryInfo = ReasonCategoryInfo.GetReasonCategoryByCategoryNameAndReason("Common", "OTHER"); var splitLotData = SplitLotInfo.CreateSplitLotByLotAndQuantity(lstSourceLot[0].Lot, boxNoLotID, 0, 0, reasonCategoryInfo, "SplitBoxLot"); WIPTxn.SplitIndicator splitInd = WIPTxn.SplitIndicator.Create(); WIPTxn.Default.SplitLot(lstSourceLot[0], splitLotData, splitInd, txnStamp); //若子單元為自動產生,更新序號至DB if (splitLotArchiSQLList != null && splitLotArchiSQLList.Count > 0) { DBCenter.ExecuteSQL(splitLotArchiSQLList); } #endregion var targetLot = LotInfo.GetLotByLot(boxNoLotID); // 將批號轉換為另一個批號的子單元,轉換後批號結批,例如可使用於包裝 WIPTxn.Default.ConvertToComponent(targetLot, lstSourceLot, "Box", WIPTxn.ConvertToComponentIndicator.Default, txnStamp); // 紀錄檢驗人員 //WIPTransaction.ModifyLotSystemAttribute(targetLot, "USERDEFINECOL12", ddlInspector.SelectedValue, txnStamp); // 進行Dispatch WIPTransaction.DispatchLot(targetLot, txnStamp); // 刪除暫存檔案 if (_BatchID != "") { CSTWIPPackTempInfo.DeletePackTempByBatchID(_BatchID); } var packInfo = InfoCenter.Create <CSTWIPPackInfo>(); packInfo.BOXNO = boxNoLotID; packInfo.Quantity = _PackingList.Count + _RelativePackingList.Count; packInfo.INSPUSER = ddlInspector.SelectedValue; packInfo.InsertToDB(txnStamp.UserID, txnStamp.RecordTime); _PackingList.ForEach(comp => { var packDataInfo = InfoCenter.Create <CSTWIPPackDataInfo>(); packDataInfo.WIP_PACK_SID = packInfo.ID; packDataInfo.ComponentID = comp.ComponentID; packDataInfo.DMC = comp.DMC; packDataInfo.DeviceName = comp.Device; packDataInfo.Quantity = 1; packDataInfo.InsertToDB(txnStamp.UserID, txnStamp.RecordTime); }); _RelativePackingList.ForEach(comp => { var packDataInfo = InfoCenter.Create <CSTWIPPackDataInfo>(); packDataInfo.WIP_PACK_SID = packInfo.ID; packDataInfo.ComponentID = comp.ComponentID; packDataInfo.DMC = comp.DMC; packDataInfo.DeviceName = comp.Device; packDataInfo.Quantity = 1; packDataInfo.InsertToDB(txnStamp.UserID, txnStamp.RecordTime); }); //工時 _UserWorkTimeList.ForEach(p => { p.InsertToDB(txnStamp.UserID, txnStamp.RecordTime); }); _UserWorkTimeList.Clear(); #region Print _dsReport = new DataSet(); // 取得Report資料 _dsReport = GetRunCardDataSource(targetLot); _dsReport.AcceptChanges(); if (_dsReport.Tables.Count > 0) { string sPrintProgram = "/CustomizeRule/WIPRule/W035View.aspx"; string sHost = Request.Url.Host; string sApplicationPath = Request.ApplicationPath; string ReportPath = "http://" + sHost + sApplicationPath + sPrintProgram; Session["W035View"] = _dsReport; //開啟查詢工單頁面 string openPrintWindow = "window.open('" + ReportPath + "','pop','resizable: yes; status: no; scrollbars:no; menubar:no;toolbar:no;location:no;dialogLeft:10px;dialogTop:10px;dialogHeight:10px;dialogWidth:10px',false);"; ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), Guid.NewGuid().ToString(), openPrintWindow, true); } #endregion cts.Complete(); } // ClearUI不會清除Device資料 ttbDeviceName.Text = ""; ClearField(); //ReturnToPortal(); } catch (Exception ex) { HandleError(ex); } }
protected void ttbWorkpiece_TextChanged(object sender, EventArgs e) { try { // 若卡控需輸入料號 if (ttbDeviceName.Text.Trim().IsNullOrEmpty() && !ckbNoControl.Checked) { throw new RuleCimesException(TextMessage.Error.T00043(lblDeviceName.Text)); } // 取得輸入工件 string inputObject = ttbWorkpiece.Text.Trim(); if (inputObject.IsNullOrEmpty()) { return; } ComponentInfo componentInfo = null; LotInfo lotInfo = null; var lstDMCComponent = ComponentInfoEx.GetComponentByDMCCode(inputObject).OrderBy(p => p.ComponentID).ToList(); if (lstDMCComponent.Count == 0) { var compID = CustomizeFunction.ConvertDMCCode(inputObject); lstDMCComponent = ComponentInfoEx.GetComponentListByComponentID(compID).OrderBy(p => p.ComponentID).ToList(); } lstDMCComponent.ForEach(comp => { // 若DMC是唯一值可以檢查是否已經重複 if (_ProdType == "S" || _ProdType == "B") { // 取得批號資料 lotInfo = LotInfo.GetLotByLot(comp.CurrentLot); // 自動線沒有DMCCode if (lotInfo.UserDefineColumn08 == "Y" && comp["DMC"].ToString().IsNullOrEmpty()) { var txnStamp = new TransactionStamp(User.Identity.Name, ProgramRight, ProgramRight, ApplicationName); using (var cts = CimesTransactionScope.Create()) { WIPTransaction.ModifyLotComponentSystemAttribute(lotInfo, comp, "DMC", inputObject, txnStamp); cts.Complete(); } } #region 檢查子單元資料是否重複 if (lotInfo.DeviceName == _DeviceName) { _PackingList.ForEach(p => { if (p.ComponentID == comp.ComponentID) { throw new RuleCimesException(TextMessage.Error.T00033(lblWorkpiece.Text, comp.ComponentID)); } }); } else if (lotInfo.DeviceName == _RelativeDeviceName) { _RelativePackingList.ForEach(p => { if (p.ComponentID == comp.ComponentID) { throw new RuleCimesException(TextMessage.Error.T00033(lblWorkpiece.Text, comp.ComponentID)); } }); } #endregion componentInfo = comp; } else { if (_PackingList.Find(p => p.ComponentID == comp.ComponentID) == null && _RelativePackingList.Find(p => p.ComponentID == comp.ComponentID) == null && componentInfo == null) { componentInfo = comp; // 取得批號資料 lotInfo = LotInfo.GetLotByLot(componentInfo.CurrentLot); } } }); // 找不到子單元需拋錯 if (componentInfo == null) { throw new RuleCimesException(TextMessage.Error.T00045(GetUIResource("Workpiece"))); } // 找不到批號需拋錯 if (lotInfo == null) { throw new RuleCimesException(TextMessage.Error.T00045(GetUIResource("Lot"))); } // 檢查CurrentRule是否正確 if (lotInfo.CurrentRuleName != ProgramInformationBlock1.ProgramRight) { throw new RuleCimesException(TextMessage.Error.T00384(lotInfo.CurrentRuleName, ProgramInformationBlock1.ProgramRight)); } // 若需卡控 if (!ckbNoControl.Checked) { // 檢查批號型號與輸入的型號是否相同 if (_PackType == "Standard" && lotInfo.DeviceName != _DeviceName) { throw new RuleCimesException(RuleMessage.Error.C10041(_DeviceName)); } // 如果為包裝方式為Mix(左右手),則對應料號與對應料號須符合 if (_PackType == "Mix" && lotInfo.DeviceName != _DeviceName && lotInfo.DeviceName != _RelativeDeviceName) { throw new RuleCimesException(RuleMessage.Error.C10042(_DeviceName, _RelativeDeviceName)); } } var packTempInfo = CSTWIPPackTempInfo.GetPackTempByComponentID(componentInfo.ComponentID); if (packTempInfo != null) { ttbWorkpiece.Text = ""; throw new RuleCimesException(RuleMessage.Error.C10093()); } // 新增PackingInfo物件 var newPackItem = new PackingInfo(); newPackItem.ComponentID = componentInfo.ComponentID; newPackItem.ComponentInfo = componentInfo; newPackItem.LotInfo = lotInfo; newPackItem.DMC = componentInfo["DMC"].ToString(); // 將PackingInfo物件加入包裝清單全域變數 if (_PackType == "Standard" || (_PackType == "Mix" && lotInfo.DeviceName == _DeviceName) || ckbNoControl.Checked) { // 工件數量({0})達到滿箱數量({1}) ! if (!ckbNoControl.Checked && _PackingList.Count >= ttbMaxPackSize.Text.ToDecimal()) { throw new RuleCimesException(RuleMessage.Error.C10092(_PackingList.Count.ToString(), ttbMaxPackSize.Text)); } newPackItem.Device = lotInfo.DeviceName; newPackItem.Item = (_PackingList.Count + 1).ToString(); _PackingList.Add(newPackItem); } // 將PackingInfo物件加入對應料號包裝清單全域變數 else { // 工件數量({0})達到滿箱數量({1}) ! if (!ckbNoControl.Checked && _RelativePackingList.Count >= ttbMaxPackSize.Text.ToDecimal()) { throw new RuleCimesException(RuleMessage.Error.C10092(_RelativePackingList.Count.ToString(), ttbMaxPackSize.Text)); } newPackItem.Device = lotInfo.DeviceName; newPackItem.Item = (_RelativePackingList.Count + 1).ToString(); _RelativePackingList.Add(newPackItem); } // 將目前已經輸入的物件顯示至畫面上 _PackingList = _PackingList.OrderByDescending(p => p.Item.ToDecimal()).ToList(); gvWorkpiece.DataSource = _PackingList; gvWorkpiece.DataBind(); // 將目前已經輸入的物件顯示至畫面上 _RelativePackingList = _RelativePackingList.OrderByDescending(p => p.Item.ToDecimal()).ToList(); gvRelativeWorkpiece.DataSource = _RelativePackingList; gvRelativeWorkpiece.DataBind(); // 清除工件欄位 ttbWorkpiece.Text = ""; // 將指標焦點放工件欄位輸入框 AjaxFocus(ttbWorkpiece); if (_PackingList.Count != 0 || _RelativePackingList.Count != 0) { ttbTempWorkpiece.ReadOnly = true; } else { ttbTempWorkpiece.ReadOnly = false; } // 取得BatchID if (_BatchID == "") { var cstWIPPackTempInfo = InfoCenter.GetBySQL <CSTWIPPackTempInfo>("SELECT * FROM CST_WIP_PACK_TEMP WHERE COMPONENTID = #[STRING]", inputObject); _BatchID = (cstWIPPackTempInfo == null) ? "" : cstWIPPackTempInfo.BatchID; } #region ProcessWorkTime string sysTime = DBCenter.GetSystemTime(); var usrWorkTime = InfoCenter.Create <CSTUserWorkTimeInfo>(); usrWorkTime.WorkOrder = lotInfo.WorkOrder; usrWorkTime.WorkUserID = User.Identity.Name; usrWorkTime.StartTime = _StartTime; usrWorkTime.EndTime = DateTime.Parse(sysTime).AddSeconds(-1).ToString("yyyy/MM/dd HH:mm:ss"); usrWorkTime.EXECUTEFLAG = "N"; usrWorkTime.SHIFTDATE = _ShiftDate; usrWorkTime.SHIFT = _Shift; usrWorkTime.Lot = lotInfo.Lot; usrWorkTime["OPERATION"] = lotInfo.OperationName; _StartTime = sysTime; _UserWorkTimeList.Add(usrWorkTime); #endregion } catch (Exception ex) { HandleError(ex, ttbWorkpiece.ClientID); } }