QCM方法结构设计

QCM方法结构设计1 绑定数据的方法 构造器 不要放到 Load 方法中 Load 只是在第一次进入页面时加载 否则就无法正确绑定数据 比如刷新 2 使用带参构造器进行窗体传值 不要在 Load 中调用 另外要考虑调用的构造器是另一个而不是这个的情况 3

大家好,我是讯享网,很高兴认识大家。

1、绑定数据的方法(构造器)不要放到Load方法中,Load只是在第一次进入页面时加载,否则就无法正确绑定数据(比如刷新)

2、使用带参构造器进行窗体传值,不要在Load中调用(另外要考虑调用的构造器是另一个而不是这个的情况)


讯享网

3、将服务调用拆分成单个方法(不要杂糅到一块),方便复用

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Windows.Forms; using DevExpress.XtraEditors; using MESCore; using TRSCore; namespace QCMCore { public partial class frmQCMCOATemplateSetup : BaseFormEdit, IBaseFormFunc { public frmQCMCOATemplateSetup() { InitializeComponent(); } public frmQCMCOATemplateSetup(string FormName, string[] TableKeys) { InitializeComponent(); this.saTableKeys = TableKeys; this.Text = FormName; } #region Variable private bool mbLoadFlag = false; private string[] saTableKeys; #endregion #region Function public Control GetFisrtFocusItem() { try { return this.tabMain; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return null; } } private void InitControl() { try { } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); } } private bool CheckCondition(string FuncName, char ProcStep) { try { switch (CommonFunction.Trim(FuncName)) { case "Create_COA_Template": if (txtCoaTempId.Text == "") { CommonFunction.ShowMsgBox(CommonFunction.GetMessage(108)); txtCoaTempId.Focus(); return false; } switch (CommonFunction.ToChar(CommonFunction.Trim(ProcStep))) { case GlobalConstant.SYS_STEP_CREATE: case GlobalConstant.SYS_STEP_UPDATE: break; case GlobalConstant.SYS_STEP_DELETE: return true; } break; case "Update_Item_List": DataTable dt = (DataTable)gdcItem.DataSource; foreach (DataRow dr in dt.Rows) { if (dr["ITEM_SEQ"].ToString().Trim() == "") { CommonFunction.ShowMsgBox(CommonFunction.GetMessage(108)); return false; } } break; } return true; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } private bool View_COA_Template() { TRSNode in_node = new TRSNode("VIEW_COA_TEMPLATE_IN"); TRSNode out_node = new TRSNode("VIEW_COA_TEMPLATE_OUT"); try { if (saTableKeys != null) { //ClearData('1'); CommonRoutine.SetInMsg(in_node); in_node.ProcStep = '1'; in_node.AddString("NEXT_COA_ID", saTableKeys[1]); if (CommonRoutine.CallService("QCM", "QCM_View_COA_Template", in_node, ref out_node) == false) { return false; } txtCoaTempId.Text = CommonFunction.Trim(out_node.GetString("COA_ID")); txtDesc.Text = CommonFunction.Trim(out_node.GetString("COA_DESC")); txtCustomMatId.Text = CommonFunction.Trim(out_node.GetString("CUSTOM_MAT_ID")); txtCustomer.Text = CommonFunction.Trim(out_node.GetString("CUSTOMER")); txtCreateUser.Text = CommonFunction.Trim(out_node.GetString("CREATE_USER_ID")); txtCreateTime.Text = CommonFunction.Trim(out_node.GetString("CREATE_TIME")); txtUpdateUser.Text = CommonFunction.Trim(out_node.GetString("UPDATE_USER_ID")); txtUpdateTime.Text = CommonFunction.Trim(out_node.GetString("UPDATE_TIME")); //out_node.GetList(0)[i].GetString("ITEM"), //txtCreateUser.Text = CommonFunction.Trim(out_node.GetString("CREATE_USER_ID")); //txtCreateTime.Text = CommonFunction.MakeDateFormat(out_node.GetString("CREATE_TIME")); //txtUpdateUser.Text = CommonFunction.Trim(out_node.GetString("UPDATE_USER_ID")); //txtUpdateTime.Text = CommonFunction.MakeDateFormat(out_node.GetString("UPDATE_TIME")); txtCoaTempId.Enabled = false; View_COA_Template_Item_List(); return true; } else { return false; } } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } private bool View_COA_Template_Item_List() { try { DataTable dt = QCMLIST.ViewQcmCoaTemplate(saTableKeys[1]); DevGridControlHelper.BindData(gdcItem, dt, new int[] { 1, 1, 1, 1, 1 }); return true; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } private bool Update_COA_Template(char ProcStep) { TRSNode in_node = new TRSNode("UPDATE_COA_TEMPLATE_IN"); TRSNode out_node = new TRSNode("CMN_OUT"); try { CommonRoutine.SetInMsg(in_node); string sCoaTempId = txtCoaTempId.Text; string sTempDesc = txtDesc.Text; string sCustomMatId = txtCustomMatId.Text; string sCustomer = txtCustomer.Text; in_node.AddString("COA_ID", sCoaTempId); in_node.AddString("COA_DESC", sTempDesc); in_node.AddString("CUSTOM_MAT_ID", sCustomMatId); in_node.AddString("CUSTOMER", sCustomer); if (CommonRoutine.CallService("QCM", "QCM_Update_COA_Template", in_node, ref out_node) == false) { return false; } return true; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } private bool Update_COA_Template_Item_List() { try { if (gdcItem.DataSource == null)//无数据,直接返回true,避免调用时return,不给保存成功的提示 { return false; } TRSNode in_node = new TRSNode("UPDATE_COA_TEMPLATE_IN"); TRSNode out_node = new TRSNode("UPDATE_COA_TEMPLATE_OUT"); in_node.AddString("COA_ID", CommonFunction.Trim(txtCoaTempId.Text)); CommonRoutine.SetInMsg(in_node); DataTable dtDataEdited = null; dtDataEdited = ((DataTable)gdcItem.DataSource).GetChanges(DataRowState.Added);//得到所有新增的行 //gdcData->gridControl if (dtDataEdited != null) { //in_node = new TRSNode("UPDATE_INSPECTION_ITEM_IN"); in_node = FillUpdateRecords(in_node, dtDataEdited, false, GlobalConstant.SYS_STEP_CREATE); } //Modify record //因更改GCM表记录时,有可能会把主键也更新掉,所以没办法做UPDATE操作,只能先删后加 //Server端也仅支持INSERT和DELETE,GlobalConstant.SYS_STEP_UPDATE直接转化为INSERT dtDataEdited = null; dtDataEdited = ((DataTable)gdcItem.DataSource).GetChanges(DataRowState.Modified);//得到所有修改过的行 if (dtDataEdited != null) { in_node = FillUpdateRecords(in_node, dtDataEdited, true, GlobalConstant.SYS_STEP_DELETE); in_node = FillUpdateRecords(in_node, dtDataEdited, false, GlobalConstant.SYS_STEP_CREATE); } //Deleted record dtDataEdited = null; dtDataEdited = ((DataTable)gdcItem.DataSource).GetChanges(DataRowState.Deleted);//得到所有删除的行 if (dtDataEdited != null) { in_node = FillUpdateRecords(in_node, dtDataEdited, true, GlobalConstant.SYS_STEP_DELETE); in_node.ProcStep = GlobalConstant.SYS_STEP_DELETE; } if (CommonRoutine.CallService("QCM", "QCM_Update_COA_Template_Item", in_node, ref out_node) == false) { return false; } //CommonRoutine.ShowSuccessMsg(out_node); return true; } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); return false; } } private TRSNode FillUpdateRecords(TRSNode in_node, DataTable dtDataEdited, bool bOriginal, char cStep) { TRSNode node; for (int i = 0; i < dtDataEdited.Rows.Count; i++) { node = in_node.AddNode("COA_LIST"); node.ProcStep = cStep; if (bOriginal) { node.AddInt("ITEM_SEQ", dtDataEdited.Rows[i]["ITEM_SEQ", DataRowVersion.Original]); node.AddString("TESTING_ITEM", dtDataEdited.Rows[i]["TESTING_ITEM", DataRowVersion.Original]); node.AddString("TESTING_SPECIFICATION", dtDataEdited.Rows[i]["TESTING_SPECIFICATION", DataRowVersion.Original]); node.AddString("DIMENS", dtDataEdited.Rows[i]["DIMENS", DataRowVersion.Original]); node.AddString("TESTING_METHOD", dtDataEdited.Rows[i]["TESTING_METHOD", DataRowVersion.Original]); } else { node.AddInt("ITEM_SEQ", dtDataEdited.Rows[i]["ITEM_SEQ"]);//根据i行及列名获取值并存入node中 node.AddString("TESTING_ITEM", dtDataEdited.Rows[i]["TESTING_ITEM"]); node.AddString("TESTING_SPECIFICATION", dtDataEdited.Rows[i]["TESTING_SPECIFICATION"]); node.AddString("DIMENS", dtDataEdited.Rows[i]["DIMENS"]); node.AddString("TESTING_METHOD", dtDataEdited.Rows[i]["TESTING_METHOD"]); } } return in_node; } #endregion #region Control Event Function protected override void ExecNewEvent() { CommonFunction.OpenForm(CommonFunction.GetMenuTag(GlobalConstant.FORMID_QCM_COA_TEMPLATE_SETUP), "New COA Template", null); } protected override void ExecRefreshEvent() { if (CommonFunction.ShowMsgBox(CommonFunction.GetMessage(357)) == DialogResult.OK) { View_COA_Template(); } } protected override void ExecSaveEvent() { //Create try { //保存编辑框中做的更新 gdvItem.PostEditor(); gdvItem.UpdateCurrentRow(); if (saTableKeys == null)//新建 { //Update Table if (CheckCondition("Create_COA_Template", GlobalConstant.SYS_STEP_CREATE) == false) { return; } if (Update_COA_Template(GlobalConstant.SYS_STEP_CREATE) == false) { return; } //添加成功,显示成编辑界面 saTableKeys = new string[] { GlobalVariable.gsFactory, this.txtCoaTempId.Text }; this.rpgCreate.Visible = true; this.rpgLifeCycle.Visible = true; this.Text = CommonFunction.FindLanguage("COA Template", CAPTION_TYPE.MENU) + " - " + this.txtCoaTempId.Text; //if (GlobalVariable.gLoginInfo.bListAutoRefresh == true) //{ // btnRefresh.PerformClick(); //} } else//更新 { if (CheckCondition("Create_COA_Template", GlobalConstant.SYS_STEP_UPDATE) == false) { return; } if (Update_COA_Template(GlobalConstant.SYS_STEP_UPDATE) == false) { return; } //if (GlobalVariable.gLoginInfo.bListAutoRefresh == true) //{ // btnRefresh.PerformClick(); //} } //Update Data List //int ActiveRow = 0;//更新后继续focus在原先focus的行 if (CheckCondition("Update_Item_List", GlobalConstant.SYS_STEP_CREATE) == false) //CheckDataCondition不分SYS_STEP_UPDATE还是SYS_STEP_DELETE { return; } if (Update_COA_Template_Item_List() == false) { return; } View_COA_Template(); CommonFunction.ShowMsgBox(CommonFunction.GetMessage(358)); } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); } } protected override void ExecCancelEvent() { if (CommonFunction.ShowMsgBox(CommonFunction.GetMessage(357)) == DialogResult.OK) { View_COA_Template(); } } protected override void ExecTerminateEvent() { // GCM Table try { if (CommonFunction.ShowMsgBox(CommonFunction.GetMessage(54), MessageBoxButtons.YesNo, 2) != DialogResult.Yes) { return; } if (CheckCondition("UPDATE_TABLE", GlobalConstant.SYS_STEP_DELETE) == true) { if (Update_COA_Template(GlobalConstant.SYS_STEP_DELETE) == false) { return; } //删除后提示并返回列表 if (CommonFunction.ShowMsgBox(CommonFunction.GetMessage(359)) != DialogResult.None) { CommonFunction.ActivateForm(CommonFunction.GetMenuTag(GlobalConstant.FORMID_BAS_GCMTable_LIST), "Smark Table List", true); this.Close(); } //if (GlobalVariable.gLoginInfo.bListAutoRefresh == true) //{ // btnRefresh.PerformClick(); //} } } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); } } #endregion #region Control Event private void frmQCMCOATemplateSetup_Load(object sender, EventArgs e) { try { if (mbLoadFlag == false) { InitControl(); View_COA_Template(); mbLoadFlag = true; } } catch (Exception ex) { CommonFunction.ShowMsgBox(ex.Message); } } #endregion } }

讯享网

 

小讯
上一篇 2025-03-18 20:59
下一篇 2025-03-20 13:44

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/23966.html