/// <summary> /// 启动其中的一条记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEnabled_Click(object sender, EventArgs e) { try { Log.Info(this.GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_POWER_SWITCH modelDevPowerSwitch = PreparePowerSwitchinfo(); //更新数据 bool status = _bllDevPowerSwitch.Enabled(modelDevPowerSwitch.F_POWER_ID, modelDevPowerSwitch.F_POWER_SWITCH_ID); if (status) { XtraMessageBox.Show("此数据已启用。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } 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; } //准备要存储的数据 ModelDEV_POWER_SWITCH modelDevPowerSwitch = PreparePowerSwitchinfo(); //判断此数据是否已经存在 bool isDataExist = _bllDevPowerSwitch.Exists(modelDevPowerSwitch.F_POWER_ID, modelDevPowerSwitch.F_POWER_SWITCH_ID); if (isDataExist) { //已经存在判断是否更新 DialogResult dialogResult = XtraMessageBox.Show("当前数据已存在,是否更新?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //更新数据 bool status = _bllDevPowerSwitch.Update(modelDevPowerSwitch); if (status) { XtraMessageBox.Show("此数据已更新。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("没有数据被更新,操作中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { _bllDevPowerSwitch.Add(modelDevPowerSwitch); XtraMessageBox.Show("此数据已增加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } OnSaveBuutonClickedChange(); } 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 btnDelete_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; } //准备要存储的数据 ModelDEV_POWER_SWITCH modelDevPowerSwitch = PreparePowerSwitchinfo(); //判断是否有关系 bool hasRelation = _bllDevPowerSwitch.HasRelation(modelDevPowerSwitch.F_POWER_ID, modelDevPowerSwitch.F_POWER_SWITCH_ID); if (hasRelation) { XtraMessageBox.Show("此设备有和其他设备的关系,不能删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //更新数据 bool status = _bllDevPowerSwitch.Drop(modelDevPowerSwitch.F_POWER_ID, modelDevPowerSwitch.F_POWER_SWITCH_ID); if (status) { XtraMessageBox.Show("此数据已删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("没有数据被更新。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } OnSaveBuutonClickedChange(); } 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 btnEdiSwitch_Click(object sender, EventArgs e) { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); if (txtF_POWER_ID.Text == "") { DevExpress.DXCore.Controls.XtraEditors.XtraMessageBox.Show("请先选择供电柜信息再编辑通道信息。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //准备数据 var modelPowerSwitchStatus = new ModelDEV_POWER_SWITCH(); //供电柜开关操作类 var bllPowerSwitchStatus = new ProxyBllDEV_POWER_SWITCH(); if (gvPowerSwitchInfo.RowCount > 0) { string powerId = gvPowerSwitchInfo.GetFocusedRowCellValue("F_POWER_ID").ToString(); string switchId = gvPowerSwitchInfo.GetFocusedRowCellValue("F_POWER_SWITCH_ID").ToString(); modelPowerSwitchStatus = bllPowerSwitchStatus.GetModel(powerId, switchId); } else { modelPowerSwitchStatus.F_POWER_ID = txtF_POWER_ID.Text; } var frm = new FrmDevPowerSwitchInfo(modelPowerSwitchStatus); frm.SaveHandler += BindPowerSwitchInfoGridView; frm.ShowDialog(); } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 构造函数 /// </summary> /// <param name="modelDevPowerSwitch"></param> public FrmDevPowerSwitchInfo(ModelDEV_POWER_SWITCH modelDevPowerSwitch) : this() { _modelDevPowerSwitch = modelDevPowerSwitch; }
/// <summary> /// 创建存储类 /// </summary> /// <returns></returns> private ModelDEV_POWER_SWITCH PreparePowerSwitchinfo() { ModelDEV_POWER_SWITCH modelDevPowerSwitch = new ModelDEV_POWER_SWITCH(); //供电柜编号 modelDevPowerSwitch.F_POWER_ID = txtF_POWER_ID.Text; //开关序号 modelDevPowerSwitch.F_POWER_SWITCH_ID = txtF_POWER_SWITCH_ID.Text; //通信端口 modelDevPowerSwitch.F_COM_ADDRESS = txtF_COM_ADDRESS.Text.ToUpper(); //通信地址 modelDevPowerSwitch.F_POWER_SWITCH_ADDRESS = decimal.Parse(txtF_POWER_SWITCH_ADDRESS.Text); //通道号 modelDevPowerSwitch.F_HOLDREG = decimal.Parse(txtF_HOLDREG.Text); //校验编号 modelDevPowerSwitch.F_POWER_SWITCH_CALIBRATION = txtF_POWER_SWITCH_CALIBRATION.Text; //开关类型 modelDevPowerSwitch.F_POWER_SWITCH_TYPE = decimal.Parse(lueF_POWER_SWITCH_TYPE.EditValue.ToString()); //供电柜开关状态 modelDevPowerSwitch.F_POWER_SWITCH_STATUS = int.Parse(lueF_POWER_SWITCH_STATUS.EditValue.ToString()); //负荷容量 modelDevPowerSwitch.F_LOAD_CAPACITY = decimal.Parse(txtF_LOAD_CAPACITY.Text); //开关报警阈值(按时长) modelDevPowerSwitch.F_ALARM_LIFEDURANCE = decimal.Parse(txtF_ALARM_LIFEDURANCE.Text); //开关报警阈值(按使用次数) modelDevPowerSwitch.F_ALARM_TIMEDURANCE = decimal.Parse(txtF_ALARM_TIMEDURANCE.Text); //开关动作次数 modelDevPowerSwitch.F_SWITCH_TIMES = decimal.Parse(txtF_SWITCH_TIMES.Text); //供电柜开关状态 modelDevPowerSwitch.F_POWER_SWITCH_STATUS = int.Parse(lueF_POWER_SWITCH_STATUS.EditValue.ToString()); //创建时间 DateTime optDateTime = DateTime.Now; modelDevPowerSwitch.F_CREATE_TIME = optDateTime; //操作员 modelDevPowerSwitch.F_OPERATOR_ID = AppGlobal.GUserId; //操作时间 modelDevPowerSwitch.F_OPERATIONTIME = optDateTime; //是否删除 modelDevPowerSwitch.F_DEL = 0; return(modelDevPowerSwitch); }