/// <summary> /// 启用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEnabled_Click(object sender, EventArgs e) { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_POWER_INFO modelDevPowerBaseinfo = PreparePowerBaseinfo(); //更新数据 bool status = _bllDevPowerInfo.Enabled(modelDevPowerBaseinfo.F_POWER_ID); //获得当前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(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }
/// <summary> /// 准备要操作的ModelPARAMETER_MONITORCOMMON /// </summary> /// <returns></returns> private ModelDEV_POWER_INFO PreparePowerBaseinfo() { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); var modelPowerBaseinfo = new ModelDEV_POWER_INFO(); //供电柜编号或标识 modelPowerBaseinfo.F_POWER_ID = txtF_POWER_ID.Text; //供电柜名称 modelPowerBaseinfo.F_POWER_NAME = txtF_POWER_NAME.Text; //校准编号 modelPowerBaseinfo.F_POWER_CALIBRATION = txtF_POWER_CALIBRATION.Text; //描述信息 modelPowerBaseinfo.F_POWER_DESCRIPTION = txtF_POWER_DESCRIPTION.Text; //创建时间 DateTime optDateTime = DateTime.Now; modelPowerBaseinfo.F_CREATE_TIME = optDateTime; //操作员 modelPowerBaseinfo.F_OPERATOR_ID = AppGlobal.GUserId; //操作时间 modelPowerBaseinfo.F_OPERATIONTIME = optDateTime; //是否删除 modelPowerBaseinfo.F_DEL = 0; return(modelPowerBaseinfo); } catch (Exception ex) { Log.Error(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(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //删除前判断 DialogResult dialogResult = XtraMessageBox.Show("此操作将永久删除数据并有可能导致其他关联数据出错,是否继续?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //若存在开关数据则不能禁用或者删除 int subDataCount; int.TryParse(txtSwitchNum.Text, out subDataCount); if (subDataCount != 0) { XtraMessageBox.Show("有附属信息不能禁用或者删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); gvList_RowClick(this, null); return; } //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_POWER_INFO modelDevPowerBaseinfo = PreparePowerBaseinfo(); //判断是否有关系 bool hasRelation = _bllDevPowerInfo.HasRelation(modelDevPowerBaseinfo.F_POWER_ID); if (hasRelation) { XtraMessageBox.Show("此设备有和其他设备的关系,不能删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //更新数据 bool status = _bllDevPowerInfo.Drop(modelDevPowerBaseinfo.F_POWER_ID); //绑定数据 BindGridview(); if (status) { XtraMessageBox.Show("此数据已删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); gvList_RowClick(this, null); } else { XtraMessageBox.Show("没有数据被删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { Log.Error(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(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //禁用前判断 DialogResult dialogResult = XtraMessageBox.Show("此操作可能导致其他关联数据出错,是否继续?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //若存在开关数据则不能禁用或者删除 int subDataCount; int.TryParse(txtSwitchNum.Text, out subDataCount); if (subDataCount != 0) { XtraMessageBox.Show("有附属信息不能禁用或者删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); gvList_RowClick(this, null); return; } //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_POWER_INFO modelDevPowerBaseinfo = PreparePowerBaseinfo(); //更新数据 bool status = _bllDevPowerInfo.Disabled(modelDevPowerBaseinfo.F_POWER_ID); //获得当前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(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(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelDEV_POWER_INFO modelDevPowerBaseinfo = PreparePowerBaseinfo(); //判断此数据是否已经存在 bool isDataExist = _bllDevPowerInfo.Exists(modelDevPowerBaseinfo.F_POWER_ID); if (isDataExist) { //已经存在判断是否更新 DialogResult dialogResult = XtraMessageBox.Show("当前数据已存在,是否更新?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //更新数据 bool status = _bllDevPowerInfo.Update(modelDevPowerBaseinfo); //获得当前rowhandle int rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle; if (status) { XtraMessageBox.Show("此数据已更新。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("没有数据被更新,操作中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { _bllDevPowerInfo.Add(modelDevPowerBaseinfo); //获得当前rowhandle int rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle + 1; XtraMessageBox.Show("此数据已增加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }