Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                #region 檢查輸入資料
                ttbToolName.Must(lblToolName);
                ddlType.Must(lblType);

                if (!rbtDisable.Checked && !rbtEnable.Checked)
                {
                    throw new CimesException(TextMessage.Error.T00841(lblStates.Text));
                }


                CurrentToolData.ToolName = ttbToolName.Text.Trim();
                if (CurrentToolData.InfoState == InfoState.NewCreate)
                {
                    if (ToolInfo.GetToolByName(CurrentToolData.ToolName) != null)
                    {
                        throw new CimesException(TextMessage.Error.T00710(CurrentToolData.ToolName));
                    }
                }

                ToolAttributeSetup.ValidateCheck();
                #endregion

                //儲存系統屬性
                _SystemAttribute.SaveSystemAttribute(CurrentToolData);

                //預設ActiveFlag = "F"
                if (CurrentToolData.InfoState == InfoState.NewCreate)
                {
                    CurrentToolData.ActiveFlag = "F";
                    CurrentToolData.Location   = "Warehouse";
                    CurrentToolData.ToolClass  = "DIE";
                }

                CurrentToolData.UsingStatus = (rbtEnable.Checked ? UsingStatus.Enable : UsingStatus.Disable);
                CurrentToolData.ToolTypeSID = ddlType.SelectedItem.Value;
                CurrentToolData.ToolType    = ddlType.SelectedItem.Text;
                if (rbtEnable.Checked)
                {
                    //若啟用,則ActiveFlag=T
                    CurrentToolData.ActiveFlag = "T";
                }
                if (ddlState.SelectedItem != null && !ddlState.SelectedItem.Value.IsNullOrTrimEmpty())
                {
                    CurrentToolData.CurrentState = ddlState.SelectedItem.Text;
                    CurrentToolData.ToolStateSID = ddlState.SelectedItem.Value;
                }
                CurrentToolData.Description = ttbDescr.Text.Trim();

                #region 將使用次數寫至ToolMaster
                DropDownList ddlCountType = (DropDownList)FindControl("PMCounterSetup1$ddlCountType");
                if (ddlCountType != null)
                {
                    CurrentToolData.CountType = ddlCountType.Text;
                }

                TextBox ttbCountRatio = (TextBox)FindControl("PMCounterSetup1$ttbCountRatio");
                if (ttbCountRatio != null)
                {
                    CheckTextBox(ttbCountRatio, GetUIResource("CountRatio"), CheckDataType.GreaterEqualZeroDecimal);
                    CurrentToolData.CountRatio = ttbCountRatio.Text.ToDecimal();
                }

                TextBox ttbTotalCount = (TextBox)FindControl("PMCounterSetup1$ttbTotalCount");
                if (ttbTotalCount != null)
                {
                    CheckTextBox(ttbTotalCount, GetUIResource("TotalCount"), CheckDataType.GreaterEqualZeroDecimal);
                    CurrentToolData.TotalCount = ttbTotalCount.Text.ToDecimal();
                }

                TextBox ttbScrapCount = (TextBox)FindControl("PMCounterSetup1$ttbScrapCount");
                if (ttbScrapCount != null)
                {
                    CheckTextBox(ttbScrapCount, GetUIResource("ScrapCount"), CheckDataType.GreaterEqualZeroDecimal);
                    CurrentToolData.ScrapCount = ttbScrapCount.Text.ToDecimal();
                }
                #endregion

                ToolInfo         toolData       = (ToolInfo)CurrentToolData.DeepCopy();
                bool             bCheckPMSSetup = true;
                TransactionStamp txnStamp       = new TransactionStamp(User.Identity.Name, ProgramRight, ProgramRight, this.ApplicationName);
                using (CimesTransactionScope cts = CimesTransactionScope.Create())
                {
                    //UserDefineColumnSet1.ModifyInfoRecordWithoutUpdate(toolData);
                    if (toolData.InfoState == InfoState.NewCreate)
                    {
                        toolData.InsertImmediately(this.User.Identity.Name, DBCenter.GetSystemTime());
                        LogCenter.LogToDB(toolData, LogCenter.LogIndicator.Default);

                        if (PMSSetupInfo.GetSetupData("TOOL", "Type", toolData.ToolType).Count == 0)
                        {
                            bCheckPMSSetup = false;
                        }
                    }
                    else
                    {
                        if (toolData.UpdateImmediately(this.User.Identity.Name, DBCenter.GetSystemTime()) != 1)
                        {
                            throw new CimesException(TextMessage.Error.T00747(""));
                        }
                        LogCenter.LogToDB(toolData, LogCenter.LogIndicator.Create(ActionType.Set));

                        if (PMSSetupInfo.GetSetupData("TOOL", "Type", toolData.ToolType).Count == 0 && PMSSetupInfo.GetSetupData("TOOL", "ID", toolData.ToolName).Count == 0)
                        {
                            bCheckPMSSetup = false;
                        }
                    }

                    ToolAttributeSetup.ExcuteTransaction(toolData.ID);

                    if (bCheckPMSSetup == true)
                    {
                        PMCounterSetupInterface.SyncSettingToDB(toolData.ID, "ToolID", txnStamp);
                    }
                    cts.Complete();
                }

                CurrentToolData = (ToolInfoEx)toolData.DeepCopy();
                BindDataByCurrentToolData();
                gvToolList.ResetCloneDataSource();
                //QueryAllTool();
                //001
                AllTools = ToolInfoEx.GetToolByToolClass("DIE");

                int index = AllTools.FindIndex(p => p.ID == CurrentToolData.ID);

                //int pageIndex = index / gvToolList.PageSize;
                int selectedIndex = index % gvToolList.PageSize;

                //換頁要放在bind資料前
                //指定選擇行放在bind資料後
                gvToolList.PageIndex = gvToolList.CurrentPageIndex;
                gvToolList.SetDataSource(AllTools, true);
                gvToolList.SelectedIndex = selectedIndex;

                DisableTab();

                _ProgramInformationBlock.ShowMessage(TextMessage.Hint.T00083(""));
            }
            catch (Exception ex)
            {
                HandleError(ex);
            }
        }
Пример #2
0
 private void QueryAllTool()
 {
     AllTools = ToolInfoEx.GetToolByToolClass("DIE");
     AllTools = AllTools.OrderBy(p => p.ToolName).ToList();
     BindGridView();
 }