/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_MST_0602.cs * 2.功能描述:新建/编辑温湿计信息 * 编辑履历: * 作者 日期 版本 修改内容 * 任海 2014/12/25 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService; namespace Dongke.IBOSS.PRD.Client.SystemModule { /// /// 新建/编辑温湿计信息 /// public partial class F_MST_0602 : FormBase { #region 成员变量 //页面状态 private Constant.FormMode _formStatus; // 温湿计ID private int? _formThermometerID; // 当前编辑实体 private ThermometerEntity _thermometerEntity = new ThermometerEntity(); #endregion #region 构造函数 public F_MST_0602(Constant.FormMode status, int ThermometerID) { InitializeComponent(); this._formStatus = status; this._formThermometerID = ThermometerID; if (this._formStatus == Constant.FormMode.Add) { this.Text = FormTitles.F_MST_0602_ADD; } else { this.Text = FormTitles.F_MST_0602_EDIT; } this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; } #endregion #region 事件处理 /// /// 页面加载事件 /// /// /// private void F_MST_0602_Load(object sender, System.EventArgs e) { try { //如果是修改,要绑定选中的信息 if (this._formStatus == Constant.FormMode.Edit) { this.BindPage(); } //如果是新建,选项默认值设定 if (this._formStatus == Constant.FormMode.Add) { this.cbValueFlag.Checked = true; } this.txtBuildingNo.Focus(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 提交操作 /// /// /// private void btnSave_Click(object sender, System.EventArgs e) { try { //基础数据验证 int ErrorId = ValidationText(); if (ErrorId != Constant.INT_IS_ZERO) { string errorAddress = ""; switch (ErrorId) { case 1: this.txtBuildingNo.Focus(); errorAddress = "楼号"; break; case 3: this.txtFloorNo.Focus(); errorAddress = "楼层"; break; case 6: this.txtLocationCode.Focus(); errorAddress = "位置编码"; break; case 7: this.txtManagerName.Focus(); errorAddress = "责任人"; break; default: break; }; MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } //为实体绑定属性 this.BindEntity(); if (this._formStatus == Constant.FormMode.Add) { int MyReturn = (int)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.AddThermometerEntity(this._thermometerEntity); })); if (MyReturn == Constant.INT_IS_ONE) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "温湿计信息", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.PageInitialization(); } else { MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "温湿计信息", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (this._formStatus == Constant.FormMode.Edit) { int MyReturn = (int)DoAsync(new BaseAsyncMethod(() => { return SystemModuleProxy.Service.UpdateThermometerEntity(this._thermometerEntity); })); if (MyReturn == Constant.INT_IS_ONE) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "温湿计信息", "编辑"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "温湿计信息", "编辑"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体关闭 /// /// /// private void btnCancel_Click(object sender, System.EventArgs e) { this.DialogResult = DialogResult.OK; } /// /// 楼号变更 /// private void txtBuildingNo_TextChanged(object sender, EventArgs e) { this.txtThermometerCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + "-" + this.txtLocationCode.Text.Trim(); } /// /// 楼层变更 /// private void txtFloorNo_TextChanged(object sender, EventArgs e) { this.txtThermometerCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + "-" + this.txtLocationCode.Text.Trim(); } /// /// 位置变更 /// private void txtLocationCode_TextChanged(object sender, EventArgs e) { this.txtThermometerCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + "-" + this.txtLocationCode.Text.Trim(); } #endregion #region 私有方法/函数 /// /// 绑定需要操作的实体信息 /// private void BindPage() { try { if (this._formThermometerID != 0 && this._formThermometerID != null) { this._thermometerEntity.ThermometerID = this._formThermometerID; DataSet srEntity = SystemModuleProxy.Service.GetThermometer(_thermometerEntity); if (srEntity != null && srEntity.Tables.Count != 0 && srEntity.Tables[0].Rows.Count != 0) { DataSet dsEntityData = (DataSet)srEntity; DataRow drEntityRow = dsEntityData.Tables[0].Rows[0]; this.txtBuildingNo.Text = drEntityRow["BuildingNo"].ToString(); this.txtFloorNo.Text = drEntityRow["FloorNo"].ToString(); this.txtLocationCode.Text = drEntityRow["LocationCode"].ToString(); this.txtThermometerCode.Text = drEntityRow["ThermometerCode"].ToString(); this.txtManagerName.Text = drEntityRow["ManagerName"].ToString(); this.txtRemarks.Text = drEntityRow["Remarks"].ToString(); if (Convert.ToInt32(drEntityRow["ValueFlag"]) == Constant.INT_IS_ONE) { this.cbValueFlag.Checked = true; } else { this.cbValueFlag.Checked = false; } //将时间戳给到要修改的实体中 this._thermometerEntity.OPTimeStamp = Convert.ToDateTime(drEntityRow["OPTimeStamp"]); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 为实体绑定页面属性 /// private void BindEntity() { try { this._thermometerEntity.BuildingNo = this.txtBuildingNo.Text.Trim(); this._thermometerEntity.FloorNo = this.txtFloorNo.Text.Trim(); this._thermometerEntity.LocationCode = this.txtLocationCode.Text.Trim(); this._thermometerEntity.ManagerName = this.txtManagerName.Text.Trim(); this._thermometerEntity.Remarks = this.txtRemarks.Text.Trim(); this._thermometerEntity.ThermometerCode = this.txtThermometerCode.Text.Trim(); if (this.cbValueFlag.Checked) { this._thermometerEntity.ValueFlag = 1; } else { this._thermometerEntity.ValueFlag = 0; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 页面控件初始化 /// private void PageInitialization() { this.txtBuildingNo.Text = string.Empty; this.txtFloorNo.Text = string.Empty; this.txtLocationCode.Text = string.Empty; this.txtManagerName.Text = string.Empty; this.txtRemarks.Text = string.Empty; this.txtThermometerCode.Text = string.Empty; } /// /// 验证添加项 /// private int ValidationText() { int ErrorID = 0; if (this.txtBuildingNo.Text == string.Empty) { ErrorID = 1; } if (this.txtFloorNo.Text == string.Empty) { ErrorID = 3; } if (this.txtLocationCode.Text == string.Empty) { ErrorID = 6; } if (this.txtManagerName.Text == string.Empty) { ErrorID = 7; } return ErrorID; } #endregion } }