Ejemplo n.º 1
0
        protected void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                ttbEquipmentName.Must(lblEquipment);
                ttbDevice1.Must(lblDevice1);

                //料號1一定要有資料
                if (_DeviceInfo1 == null)
                {
                    throw new RuleCimesException(TextMessage.Error.T00826(lblDevice1.Text));
                }

                //一定要輸入一種料號
                if (_dtVerifiy1 == null)
                {
                    throw new RuleCimesException(TextMessage.Error.T00826(lblDevice1.Text));
                }

                //若有輸入料號1則需驗證應領數量與領用數量是否相同
                if (_dtVerifiy1 != null)
                {
                    _dtVerifiy1.Rows.LoopDo <DataRow>((p, i) =>
                    {
                        if (p["NEEDQTY"].ToDecimal() != p["EQPTOOLCOUNT"].ToDecimal())
                        {
                            throw new RuleCimesException(RuleMessage.Error.C10141(_EquipmentInfo.EquipmentName, _DeviceInfo1.DeviceName, p["TOOLTYPE"].ToString(), p["NEEDQTY"].ToString()));
                        }
                    });
                }

                //若有輸入料號2則需驗證應領數量與領用數量是否相同
                if (_dtVerifiy2 != null)
                {
                    _dtVerifiy2.Rows.LoopDo <DataRow>((p, i) =>
                    {
                        if (p["NEEDQTY"].ToDecimal() != p["EQPTOOLCOUNT"].ToDecimal())
                        {
                            throw new RuleCimesException(RuleMessage.Error.C10141(_EquipmentInfo.EquipmentName, _DeviceInfo1.DeviceName, p["TOOLTYPE"].ToString(), p["NEEDQTY"].ToString()));
                        }
                    });
                }

                string           sReleaseID = DBCenter.GetSystemID();
                TransactionStamp txnStamp   = new TransactionStamp(User.Identity.Name, ProgramRight, ProgramRight, ApplicationName);
                using (var cts = CimesTransactionScope.Create())
                {
                    //先將舊的資料刪除
                    var lstEqpToolRelease = CSTEquipmentToolReleaseInfo.GetDataByEquipment(_EquipmentInfo.EquipmentName);
                    lstEqpToolRelease.ForEach(p => {
                        p.DeleteFromDB();
                        LogCenter.LogToDB(p, LogCenter.LogIndicator.Create(ActionType.Remove, txnStamp.UserID, txnStamp.RecordTime));
                    });

                    var lstEqpTool = EquipToolInfo.GetByEquipmentName(_EquipmentInfo.EquipmentName);
                    lstEqpTool.ForEach(p => {
                        //取得配件資訊
                        var toolInfo = ToolInfo.GetToolByName(p.ToolName);
                        //新增至CST_EQP_TOOL_RELEASE的Info物件
                        var eqpToolReleaseInfo           = InfoCenter.Create <CSTEquipmentToolReleaseInfo>();
                        eqpToolReleaseInfo.EquipmentName = _EquipmentInfo.EquipmentName;
                        eqpToolReleaseInfo.ToolName      = toolInfo.ToolName;
                        eqpToolReleaseInfo.HEAD          = toolInfo["HEAD"].ToString();
                        eqpToolReleaseInfo.RELEASEID     = sReleaseID;
                        eqpToolReleaseInfo["OPERATION"]  = toolInfo.UserDefineColumn08;
                        eqpToolReleaseInfo.InsertToDB(txnStamp.UserID, txnStamp.RecordTime);
                        LogCenter.LogToDB(eqpToolReleaseInfo, LogCenter.LogIndicator.Create(ActionType.Add, txnStamp.UserID, txnStamp.RecordTime));
                        //異動Tool的RELEASEID欄位
                        TMSTransaction.ModifyToolSystemAttribute(toolInfo, "RELEASEID", sReleaseID, txnStamp);
                    });

                    //先將舊的資料刪除
                    var lstEqpDeviceRelease = CSTEquipmentDeviceReleaseInfo.GetDataByEquipment(_EquipmentInfo.EquipmentName);
                    lstEqpDeviceRelease.ForEach(p => {
                        p.DeleteFromDB();
                        LogCenter.LogToDB(p, LogCenter.LogIndicator.Create(ActionType.Remove, txnStamp.UserID, txnStamp.RecordTime));
                    });

                    if (_dtVerifiy1 != null)
                    {
                        //新增至CST_EQP_DEVICE_RELEASE的Info物件
                        var eqpDeviceReleaseInfo = InfoCenter.Create <CSTEquipmentDeviceReleaseInfo>();
                        eqpDeviceReleaseInfo.EquipmentName = _EquipmentInfo.EquipmentName;
                        eqpDeviceReleaseInfo.DeviceName    = _DeviceInfo1.DeviceName;
                        eqpDeviceReleaseInfo.RELEASEID     = sReleaseID;
                        eqpDeviceReleaseInfo.InsertToDB(txnStamp.UserID, txnStamp.RecordTime);
                        LogCenter.LogToDB(eqpDeviceReleaseInfo, LogCenter.LogIndicator.Create(ActionType.Add, txnStamp.UserID, txnStamp.RecordTime));
                    }

                    if (_dtVerifiy2 != null)
                    {
                        //新增至CST_EQP_DEVICE_RELEASE的Info物件
                        var eqpDeviceReleaseInfo = InfoCenter.Create <CSTEquipmentDeviceReleaseInfo>();
                        eqpDeviceReleaseInfo.EquipmentName = _EquipmentInfo.EquipmentName;
                        eqpDeviceReleaseInfo.DeviceName    = _DeviceInfo2.DeviceName;
                        eqpDeviceReleaseInfo.RELEASEID     = sReleaseID;
                        eqpDeviceReleaseInfo.InsertToDB(txnStamp.UserID, txnStamp.RecordTime);
                        LogCenter.LogToDB(eqpDeviceReleaseInfo, LogCenter.LogIndicator.Create(ActionType.Add, txnStamp.UserID, txnStamp.RecordTime));
                    }
                    cts.Complete();
                }

                ((ProgramInformationBlock)ProgramInformationBlock1).ShowMessage(TextMessage.Hint.T00057(GetUIResource("ToolVerifiy")));
                ClearField();
                AjaxFocus(ttbEquipmentName);
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 輸入機台
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ttbEquipment_TextChanged(object sender, EventArgs e)
        {
            try
            {
                //清除資料
                _EquipData = null;
                ttbToolName.Text = "";
                _ToolList = new List<ToolInfoEx>();
                gvQuery.SetDataSource(_ToolList, true);

                //確認機台編號是否有輸入
                ttbEquipment.Must(lblEquipment);

                _EquipData = EquipmentInfo.GetEquipmentByName(ttbEquipment.Text);

                #region 驗證機台正確性
                if (_EquipData == null)
                {
                    //[00885]機台{0}不存在!
                    throw new Exception(TextMessage.Error.T00885(ttbEquipment.Text));
                }
                #endregion

                #region 驗證機台啟用狀態
                if (_EquipData.UsingStatus == UsingStatus.Disable)
                {
                    //機台:{0}已停用,如需使用,請至"機台資料維護"啟用!!
                    throw new Exception(RuleMessage.Error.C10025(_EquipData.EquipmentName));
                }
                #endregion

                #region 取得已上機的刀具資料
                var equipTools = EquipToolInfo.GetByEquipmentName(_EquipData.EquipmentName);
                if (equipTools.Count == 0)
                {
                    //機台編號:{0} 沒有刀具上機資料!!
                    throw new Exception(RuleMessage.Error.C10147(_EquipData.EquipmentName));
                }

                equipTools.ForEach(equipTool =>
                {
                    //取得刀具資料
                    var toolData = ToolInfo.GetToolByName(equipTool.ToolName).ChangeTo<ToolInfoEx>();

                    //確認刀具零組件是否存在
                    if (toolData == null)
                    {
                        // [00030]{0}:{1}不存在!
                        throw new Exception(TextMessage.Error.T00030(lblToolName.Text, ttbToolName.Text));
                    }

                    //確認刀具零組件狀態是否可使用,僅USED可執行
                    if (toolData.CurrentState != "USED")
                    {
                        //刀具零組件狀態為{0},不可執行此功能!!
                        throw new Exception(RuleMessage.Error.C10129(toolData.CurrentState));
                    }

                    #region 確認刀具零組件是否啟用
                    if (toolData.UsingStatus == UsingStatus.Disable)
                    {
                        //刀具零組件:{0}已停用,如需使用,請至"刀具零組件進料作業"啟用!!
                        throw new Exception(RuleMessage.Error.C10128(toolData.ToolName));
                    }
                    #endregion

                    _ToolList.Add(toolData);
                });

                #endregion

                gvQuery.SetDataSource(_ToolList, true);
                btnOK.Enabled = true;

                AjaxFocus(ttbToolName);
            }
            catch (Exception ex)
            {
                ClearField();
                AjaxFocus(ttbEquipment);
                HandleError(ex);
            }
        }