protected void btnAdd_Click(object sender, EventArgs e) { try { CurrentToolData = InfoCenter.Create <ToolInfoEx>(); ClearData(); EnableTab(); ddlState.ClearSelection(); var li = ddlState.Items.FindByText("IDLE"); if (li == null) { throw new CimesException(GetUIResource("ToolInitialStateUnSet")); } li.Selected = true; ToolAttributeSetup.BindData("ToolCutterAttribute", CurrentToolData.ID); PMCounterSetupInterface.BindUserControl(PMSType.ToolID, CurrentToolData.ID); //UserDefineColumnSet1.SetControl(BindType.Tool, null); btnSave.Visible = true; btnCancel.Visible = true; Action = "A"; } catch (Exception ex) { HandleError(ex); } }
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); } }
void BindDataByCurrentToolData() { ttbToolName.Text = CurrentToolData.ToolName; ttbToolName.ReadOnly = true; if (CurrentToolData.UsingStatus == UsingStatus.Enable) { rbtEnable.Checked = true; rbtDisable.Checked = false; } else { rbtEnable.Checked = false; rbtDisable.Checked = true; } var li = ddlType.Items.FindByValue(CurrentToolData.ToolTypeSID); if (li != null) { ddlType.ClearSelection(); li.Selected = true; } li = ddlState.Items.FindByValue(CurrentToolData.ToolStateSID); if (li != null) { ddlState.ClearSelection(); li.Selected = true; } DropDownList ddlCountType = (DropDownList)FindControl("PMCounterSetup1$ddlCountType"); if (ddlCountType != null) { li = ddlCountType.Items.FindByValue(CurrentToolData.CountType); if (li != null) { ddlCountType.ClearSelection(); li.Selected = true; } } TextBox ttbCountRatio = (TextBox)FindControl("PMCounterSetup1$ttbCountRatio"); if (ttbCountRatio != null) { ttbCountRatio.Text = CurrentToolData.CountRatio.ToString(); } TextBox ttbTotalCount = (TextBox)FindControl("PMCounterSetup1$ttbTotalCount"); if (ttbTotalCount != null) { ttbTotalCount.Text = CurrentToolData.TotalCount.ToString(); } TextBox ttbScrapCount = (TextBox)FindControl("PMCounterSetup1$ttbScrapCount"); if (ttbScrapCount != null) { ttbScrapCount.Text = CurrentToolData.ScrapCount.ToString(); } ttbDescr.Text = CurrentToolData.Description; ToolAttributeSetup.BindData("ToolAttribute", CurrentToolData.ID); //PMCounterSetupInterface.BindUserControl(PMSType.ToolID, CurrentToolData.ID); //UserDefineColumnSet1.SetControl(BindType.Tool, CurrentToolData); btnSave.Visible = true; btnCancel.Visible = true; Action = "U"; rtsDetail.PurgeToSetByIndex(0); //顯示系統屬性 _SystemAttribute.LoadSystemAttribute(CurrentToolData, "ToolSystemAttribute"); }