/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_2602.cs * 2.功能描述:新增注浆盘点单 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2015/05/13 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Reflection; using System.Text; 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.Controls; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.Basics.Library; namespace Dongke.IBOSS.PRD.Client.PMModule { /// /// 新增注浆盘点单 /// public partial class F_PM_2602 : DKFormBase { #region 成员变量 private DataTable _dtGrid = null; private int _checkedID = 0; private string _userCodeValue; private bool _ShowFlag = true; #endregion #region 构造函数 public F_PM_2602() { InitializeComponent(); this.btnClose.Text = ButtonText.BTN_CLOSE; this.btnSave.Text = ButtonText.BTN_SAVE; } public F_PM_2602(int id) { InitializeComponent(); this.btnClose.Text = ButtonText.BTN_CLOSE; this.btnSave.Text = ButtonText.BTN_SAVE; this._checkedID = id; //this.dkProcedureSearchBox.Enabled = false; this.scbGoods.Enabled = false; this.scbGoodsType.Enabled = false; this.chkDateTime.Enabled = false; this.txtBUILDINGNO.Enabled = false; this.txtFLOORNO.Enabled = false; } #endregion #region 事件 /// /// 关闭按钮事件 /// /// /// private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 窗体加载事件 /// /// /// private void F_PM_2102_Load(object sender, EventArgs e) { // 初始化时间控件为当前日期 this.dtpDateStart.Value = DateTime.Now.Date; this.dtpDateEnd.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); this.dtpDateStart.ValueChanged += dtpDateStart_ValueChanged; this.dtpDateEnd.ValueChanged += dtpDateStart_ValueChanged; //this.dkProcedureSearchBox.TextChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged); this.scbGoods.SearchedItemChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged); this.scbGoodsType.SearchedItemChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged); this.dgvFunctionUsers.AutoGenerateColumns = false; if (_checkedID > 0) { this.Text = "编辑盘点单"; ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GBChecked"; cre.Name = "GetGBCheckedInfoForUpdate"; cre.Properties["CheckedID"] = _checkedID; ServiceResultEntity sre = PMModuleProxyNew.Service.HandleRequest(cre); if (sre != null && sre.Data != null && sre.Data.Tables.Count > 1 && sre.Data.Tables[0].Rows.Count > 0) { this.Text += "【" + sre.Data.Tables[0].Rows[0]["gbcheckedno"] + "】"; this.txtInvoiceName.Text = sre.Data.Tables[0].Rows[0]["gbcheckname"].ToString(); this.txtRemarks.Text = sre.Data.Tables[0].Rows[0]["remarks"].ToString(); this._dtGrid = sre.Data.Tables[1]; } } else { this._dtGrid = new DataTable("CheckedUser"); this._dtGrid.Columns.Add("UserID", typeof(int)); this._dtGrid.Columns.Add("UserCode", typeof(string)); this._dtGrid.Columns.Add("UserName", typeof(string)); } this.dgvFunctionUsers.DataSource = this._dtGrid; } void dtpDateStart_ValueChanged(object sender, EventArgs e) { dkProcedureSearchBox_TextChanged(sender, e); } void dkProcedureSearchBox_TextChanged(object sender, EventArgs e) { string remarks = null; //if (!string.IsNullOrWhiteSpace(this.dkProcedureSearchBox.Text)) //{ // remarks = "盘点工序: " + this.dkProcedureSearchBox.Text; //} if (chkDateTime.Checked) { if (remarks != null) { remarks += "\r\n"; } remarks += "注浆时间: " + this.dtpDateStart.Value.ToString("yyyy-MM-dd HH:mm:ss") + " 至 " + this.dtpDateEnd.Value.ToString("yyyy-MM-dd HH:mm:ss"); } if (!string.IsNullOrWhiteSpace(this.scbGoodsType.Text)) { if (remarks != null) { remarks += "\r\n"; } remarks += "产品类别: " + this.scbGoodsType.Text; } if (!string.IsNullOrWhiteSpace(this.scbGoods.Text)) { if (remarks != null) { remarks += "\r\n"; } remarks += "产品编码: " + this.scbGoods.Text; } if (!string.IsNullOrWhiteSpace(this.txtBUILDINGNO.Text)) { if (remarks != null) { remarks += "\r\n"; } remarks += "楼号: " + this.txtBUILDINGNO.Text.Trim(); } if (!string.IsNullOrWhiteSpace(this.txtFLOORNO.Text)) { if (remarks != null) { remarks += "\r\n"; } remarks += "楼层: " + this.txtFLOORNO.Text.Trim(); } this.txtRemarks.Text = remarks; } /// /// 保存按钮事件 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { // 自动生成的备注会超长 if (this.txtRemarks.Text.Length > 500) { MessageBox.Show("备注的内容超过最大长度【500个字】,请重新输入", this.Text , MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); this.txtRemarks.Focus(); return; } // 删除空白行 DataRow[] rows = this._dtGrid.Select("userid is null"); if (rows != null && rows.Length > 0) { foreach (DataRow item in rows) { item.Delete(); } } this._dtGrid.AcceptChanges(); ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "GBChecked"; cre.Name = "SaveGBChecked"; cre.Data = new DataSet(); cre.Data.Merge(this._dtGrid); cre.Properties["CheckedID"] = _checkedID; cre.Properties["CheckedName"] = this.txtInvoiceName.Text.Trim(); cre.Properties["Remarks"] = this.txtRemarks.Text.Trim(); if (_checkedID == 0) { cre.Properties["GoodsCodeList"] = this.scbGoods.CheckedPKMember; cre.Properties["GoodsTypeCode"] = scbGoodsType.SearchedValue + ""; if (chkDateTime.Checked) { cre.Properties["DateBegin"] = this.dtpDateStart.Value; cre.Properties["DateEnd"] = this.dtpDateEnd.Value; } cre.Properties["BUILDINGNO"] = this.txtBUILDINGNO.Text.Trim(); cre.Properties["FLOORNO"] = this.txtFLOORNO.Text.Trim(); } ServiceResultEntity returnValue = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { return PMModuleProxyNew.Service.HandleRequest(cre); })); if (returnValue != null && returnValue.Status == Constant.ServiceResultStatus.Success) { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else { // 提示信息 MessageBox.Show("保存失败", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 完成复选框改变事件 /// /// /// private void chkDateTime_CheckedChanged(object sender, EventArgs e) { dtpDateStart.Enabled = chkDateTime.Checked; dtpDateEnd.Enabled = chkDateTime.Checked; dkProcedureSearchBox_TextChanged(sender, e); } private void dgvFunctionUsers_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { try { if (this.dgvFunctionUsers.Rows.Count <= 1) { return; } DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex]; if ("UserCode".Equals(columnItem.Name)) { _userCodeValue = this.dgvFunctionUsers.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void dgvFunctionUsers_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { //if (e.Row.Index != -1) //{ // DataTable dt = this.dgvFunctionUsers.DataSource as DataTable; // string userID = dt.Rows[e.Row.Index]["userID"].ToString(); // DataRow[] isR = this._dtGrid.Select("UserID=" + userID); // isR[0].Delete(); // this.btnSave.Enabled = true; //} } private void dgvFunctionUsers_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (this.dgvFunctionUsers.Rows.Count <= 1 || !_ShowFlag) { return; } DataGridViewRow rowItem = this.dgvFunctionUsers.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvFunctionUsers.Columns[e.ColumnIndex]; //string OrganizationName = this.dgvFunctionUsers.Rows[e.RowIndex].Cells["OrganizationName"].Value.ToString(); // 用编号获取产品信息 if ("UserCode".Equals(columnItem.Name)) { _ShowFlag = false; DataTable dtNew = FormUtility.BindUserRowDataSource(this.dgvFunctionUsers, e.RowIndex, columnItem.Name, _userCodeValue); if (dtNew != null && dtNew.Rows.Count > 0) { foreach (DataRow r in dtNew.Rows) { DataRow[] isR = _dtGrid.Select("UserID=" + r["UserID"]); if (isR.Length == 0) { DataRow drNew = _dtGrid.NewRow(); drNew["UserID"] = r["UserID"]; drNew["UserCode"] = r["UserCode"]; drNew["UserName"] = r["UserName"]; _dtGrid.Rows.Add(drNew); dgvFunctionUsers.Rows[e.RowIndex].Cells["UserCode"].ReadOnly = true; // BindReadOnly(); } } } this.btnSave.Enabled = DataJudge.IsChange(_dtGrid); //this.dgvFunctionUsers.Rows[e.RowIndex].Cells["FunctionCode"].Value = this._functionCode; //this._dtDataGird.AcceptChanges(); // 设置可输入单元格的颜色 this.dgvFunctionUsers.IsSetInputColumnsColor = true; } _ShowFlag = true; } catch (Exception ex) { //_ShowFlag = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } #endregion } }