/// <summary> /// 准备要存储的数据 /// </summary> /// <returns></returns> private ModelCOM_SETTINGS PrepaireModelCOM232_SETTINGS() { try { Log.Info(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //创建数据实例 ModelCOM_SETTINGS modelCom232Settings = new ModelCOM_SETTINGS(); //上位机编码 modelCom232Settings.F_WORKSTATION_ID = lueF_WORKSTATION_ID.EditValue.ToString(); //串口类型 modelCom232Settings.F_TYPE = cbbF_TYPE.Text; //串口号 modelCom232Settings.F_COM_CODE = txtF_COM_CODE.Text.ToUpper(); //波特率 modelCom232Settings.F_BAUDRATE = decimal.Parse(cbbF_BAUDRATE.Text); //数据位 modelCom232Settings.F_DATABIT = decimal.Parse(cbbF_DATABIT.Text); //奇偶校验 modelCom232Settings.F_ODDEVENCHECK = cbbF_ODDEVENCHECK.SelectedIndex; //停止位 modelCom232Settings.F_STOPBIT = decimal.Parse(cbbF_STOPBIT.Text) * 10; //据流控制 modelCom232Settings.F_STREAMCONTROL = cbbF_STREAMCONTROL.SelectedIndex; //创建时间 DateTime opTime = DateTime.Now; modelCom232Settings.F_CREATE_TIME = opTime; //操作员 modelCom232Settings.F_OPERATOR_ID = AppGlobal.GUserId; //操作时间 modelCom232Settings.F_OPERATIONTIME = opTime; //是否删除 modelCom232Settings.F_DEL = 0; return(modelCom232Settings); } 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 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> /// <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; } }
/// <summary> /// 将具体信息显示在编辑控件 /// </summary> private void FillDataToDisplayControls() { try { Log.Info(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); string wrokstationId = lueF_WORKSTATION_ID.EditValue.ToString(); //如果为空则返回 if (string.IsNullOrEmpty(wrokstationId)) { return; } string comId = gvList.GetFocusedRowCellValue("F_COM_CODE").ToString(); ModelCOM_SETTINGS modelCom232Settings = _bllComSettings.GetModel(wrokstationId, comId); //有数据情况下绑定 if (modelCom232Settings == null) { return; } //端口类型 cbbF_TYPE.Text = modelCom232Settings.F_TYPE; //编号 txtF_COM_CODE.Text = modelCom232Settings.F_COM_CODE; //波特率 cbbF_BAUDRATE.Text = modelCom232Settings.F_BAUDRATE.ToString(); //数据位 cbbF_DATABIT.Text = modelCom232Settings.F_DATABIT.ToString(); //奇偶校验 cbbF_ODDEVENCHECK.SelectedIndex = (int)modelCom232Settings.F_ODDEVENCHECK; //停止位 if (modelCom232Settings.F_STOPBIT == 10) { cbbF_STOPBIT.SelectedIndex = 0; } else if (modelCom232Settings.F_STOPBIT == 15) { cbbF_STOPBIT.SelectedIndex = 1; } else if (modelCom232Settings.F_STOPBIT == 20) { cbbF_STOPBIT.SelectedIndex = 2; } //停止位 cbbF_STREAMCONTROL.SelectedIndex = int.Parse(modelCom232Settings.F_STREAMCONTROL.ToString()); } catch (Exception ex) { Log.Error(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }