/// <summary> /// 禁用数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDisabled_Click(object sender, EventArgs e) { try { Log.Info(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //禁用前判断 DialogResult dialogResult = XtraMessageBox.Show("此操作可能导致其他关联数据出错,是否继续?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelCOM_SETTINGS modelCom232Settings = PrepaireModelCOM232_SETTINGS(); //更新数据 bool status = _bllComSettings.Disabled(modelCom232Settings.F_WORKSTATION_ID, modelCom232Settings.F_COM_CODE); //获得当前rowhandle int rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle; if (status) { XtraMessageBox.Show("此数据已禁用。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //刷新数据 gvList_RowClick(this, null); } else { XtraMessageBox.Show("没有数据被更新。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Log.Error(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 检查是否全部输入 /// </summary> /// <returns></returns> private bool CheckNotNullField() { try { Log.Info(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //工作站编号 if (lueF_WORKSTATION_ID.EditValue == null) { XtraMessageBox.Show("工作站编号不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } string workstationId = lueF_WORKSTATION_ID.EditValue.ToString(); if (string.IsNullOrEmpty(workstationId)) { XtraMessageBox.Show("工作站编号不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //类型 if (string.IsNullOrEmpty(cbbF_TYPE.Text)) { XtraMessageBox.Show("端口类型不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //串口号 if (string.IsNullOrEmpty(txtF_COM_CODE.Text)) { XtraMessageBox.Show("串口编号不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //波特率 if (string.IsNullOrEmpty(cbbF_BAUDRATE.Text)) { XtraMessageBox.Show("波特率不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //数据位 if (string.IsNullOrEmpty(cbbF_DATABIT.Text)) { XtraMessageBox.Show("数据位不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //奇偶校验 if (string.IsNullOrEmpty(cbbF_ODDEVENCHECK.Text)) { XtraMessageBox.Show("奇偶校验不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //停止位 if (string.IsNullOrEmpty(cbbF_STOPBIT.Text)) { XtraMessageBox.Show("停止位不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //数据流控制 if (string.IsNullOrEmpty(cbbF_STREAMCONTROL.Text)) { XtraMessageBox.Show("数据流控制不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); } catch (Exception ex) { Log.Error(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { try { Log.Info(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelCOM_SETTINGS modelCom232Settings = PrepaireModelCOM232_SETTINGS(); //判断此数据是否已经存在 bool isDataExist = _bllComSettings.Exists(modelCom232Settings.F_WORKSTATION_ID, modelCom232Settings.F_COM_CODE); //如果存在则更新 if (isDataExist) { //已经存在判断是否更新 DialogResult dialogResult = DevExpress.XtraEditors.XtraMessageBox.Show("当前数据已存在,是否更新?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //更新数据 bool status = _bllComSettings.Update(modelCom232Settings); //获得当前rowhandle int rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle; if (status) { DevExpress.DXCore.Controls.XtraEditors.XtraMessageBox.Show("此数据已更新。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DevExpress.DXCore.Controls.XtraEditors.XtraMessageBox.Show("没有数据被更新,执行中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //插入数据 _bllComSettings.Add(modelCom232Settings); //获得当前rowhandle int rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle + 1; XtraMessageBox.Show("此数据已增加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Log.Error(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }