/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_1702.cs * 2.功能描述:新建/编辑温湿记录信息 * 编辑履历: * 作者 日期 版本 修改内容 * 庄天威 2014/11/18 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.Client.DataModels; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService; using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService; namespace Dongke.IBOSS.PRD.Client.PMModule { public partial class F_PM_1702 : FormBase { #region 成员变量 // 窗体模式ID private Constant.FormMode _formType; // 操作实体ID private DateTime? _recordTime; // 操作实体信息 private CelsiusRecordEntity _crEntity = new CelsiusRecordEntity(); // 页面数据源 private DataTable _dtSourse; #endregion #region 构造函数 public F_PM_1702(Constant.FormMode formType, DateTime recordTime) { InitializeComponent(); _formType = formType; _recordTime = recordTime; } #endregion #region 事件处理 private void F_PM_1702_Load(object sender, EventArgs e) { try { if (this._formType == Constant.FormMode.Add) { this.Text = FormTitles.F_PM_1702_ADD; this.dgvCelsiusRecord.AllowUserToDeleteRows = true; } else if (this._formType == Constant.FormMode.Edit) { this.Text = FormTitles.F_PM_1702_EDIT; this.dtpRecordTime.Enabled = false; this.btnAddDetail.Enabled = false; this.btnAddDetail.Visible = false; } //设定按钮的文本值 this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CANCEL; this.dgvCelsiusRecord.AutoGenerateColumns = false; this.BindPage(); this.dgvCelsiusRecord.IsSetInputColumnsColor = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void btnAddDetail_Click(object sender, EventArgs e) { try { ThermometerEntity TEntity = new ThermometerEntity(); TEntity.SelectUserId = LogInUserInfo.CurrentUser.CurrentUserEntity.UserID; TEntity.ValueFlag = 1; DataSet dsThermometer = SystemModuleProxy.Service.GetThermometer(TEntity); if (dsThermometer != null && dsThermometer.Tables.Count != 0) { foreach (DataRow drFor in dsThermometer.Tables[0].Rows) { DataRow drNewFor = _dtSourse.NewRow(); drNewFor["ThermometerID"] = drFor["ThermometerID"]; drNewFor["ThermometerCode"] = drFor["ThermometerCode"]; _dtSourse.Rows.Add(drNewFor); } } if (this._dtSourse.Rows.Count > 0) { this.dtpRecordTime.Enabled = false; this.btnAddDetail.Enabled = false; this.dgvCelsiusRecord.IsSetInputColumnsColor = true; } else { // 提示未查找到数据 MessageBox.Show(Messages.MSG_CMN_I002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void btnSubmit_Click(object sender, EventArgs e) { try { //首先验证数据合法性 //if (this.ValidationInput() == false) //{ // return; //} //进行添加操作 int ReturnRow = (int)DoAsync(() => { return EntityToServer(); }); if (ReturnRow > 0) { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "温湿记录", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "温湿记录", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void btnClose_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; } #endregion #region 私有方法/函数 /// /// 绑定需要操作的实体信息 /// private void BindPage() { try { if (this._recordTime != null) { this._crEntity.InsertTime = this._recordTime; } else { this._crEntity.InsertTime = this.dtpRecordTime.Value; } this._crEntity.PurviewType = 12;// 操作权限 DataSet dsCelsius = PMModuleProxy.Service.GetCelsiusRecord(this._crEntity); if (dsCelsius != null && dsCelsius.Tables.Count != 0) { this.dgvCelsiusRecord.DataSource = dsCelsius.Tables[0]; this.dtpRecordTime.Value = Convert.ToDateTime(this._recordTime); this._dtSourse = dsCelsius.Tables[0]; } } catch (Exception ex) { throw ex; } } /// /// 验证必填项 /// /// 是否通过 private bool ValidationInput() { try { if (this.dgvCelsiusRecord.Rows.Count == 0) { this.btnAddDetail.Focus(); return false; } foreach (DataGridViewRow gvrFor in this.dgvCelsiusRecord.Rows) { if (gvrFor.Cells["Celsius"].Value == DBNull.Value || gvrFor.Cells["Celsius"].Value == null || gvrFor.Cells["Humidity"].Value == DBNull.Value || gvrFor.Cells["Humidity"].Value == null) { this.dgvCelsiusRecord.Rows[gvrFor.Index].Selected = true; return false; } } return true; } catch (Exception ex) { throw ex; } } /// /// 与服务交互操作 /// /// private int EntityToServer() { try { DateTime dt = this.dtpRecordTime.Value; dt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0); return PMModuleProxy.Service.EditCelsiusRecord(dt, (DataTable)this.dgvCelsiusRecord.DataSource); } catch (Exception ex) { throw ex; } } #endregion } }