/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_2102.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_2102 : DKFormBase { #region 成员变量 private DataTable _dtGrid = null; private int _InCheckedID = 0; private string _userCodeValue; private bool _ShowFlag = true; #endregion #region 构造函数 public F_PM_2102() { InitializeComponent(); this.btnClose.Text = ButtonText.BTN_CLOSE; this.btnSave.Text = ButtonText.BTN_SAVE; } public F_PM_2102(int id, string remarks, string incheckname) { InitializeComponent(); this.btnClose.Text = ButtonText.BTN_CLOSE; this.btnSave.Text = ButtonText.BTN_SAVE; this._InCheckedID = id; this.dkProcedureSearchBox.Enabled = false; this.scbGoods.Enabled = false; this.scbGoodsType.Enabled = false; this.chkDateTime.Enabled = false; this.txtInvoiceName.Text = incheckname; this.txtRemarks.Text = remarks; } #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.scbUser.SearchedItemChanged += new System.EventHandler(this.dkProcedureSearchBox_TextChanged); this.dgvFunctionUsers.AutoGenerateColumns = false; DataSet dsInChecked = (DataSet)DoAsync(new BaseAsyncMethod(() => { return PMModuleProxy.Service.GetInCheckedUserList(_InCheckedID); })); if (_InCheckedID > 0) { this.Text = "编辑盘点单"; } this.dgvFunctionUsers.DataSource = dsInChecked.Tables[0]; this._dtGrid = dsInChecked.Tables[0]; } 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.scbUser.Text)) { if (remarks != null) { remarks += "\r\n"; } remarks += "生产工号: " + this.scbUser.Text; } 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(); } } InProductionEntity[] inProductionEntitys = new InProductionEntity[1]; InProductionEntity inProductionEntity = new InProductionEntity(); inProductionEntity.ProcedureIDS = this.dkProcedureSearchBox.ProcedureIDS; inProductionEntity.CompleteProcedureName = this.txtInvoiceName.Text.Trim(); inProductionEntity.ReworkProcedureID = this._InCheckedID; if (!string.IsNullOrWhiteSpace(scbUser.CheckedText)) { inProductionEntity.UserName = scbUser.CheckedValue; } if (!string.IsNullOrWhiteSpace(scbGroutingUser.CheckedText)) { //inProductionEntity.GroutingUserCode = scbGroutingUser.CheckedValue; inProductionEntity.GroutingUserCode = scbGroutingUser.CheckedPKMember; } if (!string.IsNullOrWhiteSpace(scbGroutingLine.CheckedText)) { // inProductionEntity.GroutingLineCode = scbGroutingLine.CheckedValue; inProductionEntity.GroutingLineCode = scbGroutingLine.CheckedPKMember; } this._dtGrid.AcceptChanges(); inProductionEntity.UserTable = this._dtGrid; if (chkDateTime.Checked) { inProductionEntity.StartCompleteDate = this.dtpDateStart.Value; inProductionEntity.EndCompleteDate = this.dtpDateEnd.Value; } inProductionEntity.GoodsCodeList = this.scbGoods.CheckedPKMember; inProductionEntity.GoodsTypeCode = scbGoodsType.SearchedValue + ""; inProductionEntitys[0] = inProductionEntity; int returnValue = (int)DoAsync(new BaseAsyncMethod(() => { return PMModuleProxy.Service.SaveInChecked(inProductionEntitys, this.txtRemarks.Text.Trim()); })); if (returnValue > 0) { // 提示信息 MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建" + this.Text, "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else if (returnValue == 0) { // 提示信息 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 } }