| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_PC_0101_1_4.cs
- * 2.功能描述:操作时间及备注录入
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2015/09/25 1.00 新建
- *******************************************************************************/
- using System;
- using System.Windows.Forms;
- using System.Data;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- namespace Dongke.IBOSS.PRD.Client.PCModule
- {
- public partial class F_PC_0101_1_4 : FormBase
- {
- #region 成员变量
- // 窗体标题
- private string _titleStr = "";
- private DataTable _dtBindSource = null;
- private string _S_PC_001 = "";
- private int _gridIndex = -1;
- private DataRowView _currentRow = null;
- #endregion
- #region 构造函数
- /// <summary>
- ///
- /// </summary>
- /// <param name="dtBindSource"></param>
- /// <param name="titleStr"></param>
- public F_PC_0101_1_4(DataTable dtBindSource, string titleStr)
- {
- InitializeComponent();
- _dtBindSource = dtBindSource;
- this.Text = titleStr;
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- this.txtGroutingLineCode.Text = dtBindSource.Rows[0]["GroutingLineCode"].ToString();
- }
- #endregion
- #region 事件
- /// <summary>
- /// 保存按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- DataTable dtName = this.dgvGroutingLineDetail.DataSource as DataTable;
- if (this._S_PC_001 == "2")
- {
- DataRow[] drs = dtName.Select("MouldID is null");
- if (drs != null && drs.Length > 0)
- {
- MessageBox.Show("不是所有成型模具都绑定了条码,请绑定条码模具后再保存。", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtBarcode.Focus();
- return;
- }
- }
- else
- {
- DataRow[] drs = dtName.Select("GoodsID is null");
- if (drs != null && drs.Length > 0)
- {
- MessageBox.Show("不是所有成型模具都设置了新的产品型号,请设置新的产品型号后再保存。", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.scbGoods.Focus();
- return;
- }
- if (this._S_PC_001 == "1")
- {
- drs = dtName.Select("MouldID is null");
- if (drs != null && drs.Length > 0)
- {
- DialogResult dialogResult = MessageBox.Show("不是所有成型模具都绑定了条码,是否继续保存?", this.Text,
- MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
- if (dialogResult != System.Windows.Forms.DialogResult.Yes)
- {
- this.txtBarcode.Focus();
- return;
- }
- }
- }
- }
- dtName.TableName = "GMouldRecord";
- //for (int i = 0; i < dtName.Rows.Count; i++)
- //{
- // dtName.Rows[i]["RecordRemarks"] = dtName.Rows[i]["RecordRemarks"] + "->" + this.dkGoodsCode.Text;
- //}
- ServiceResultEntity returnRow = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
- {
- return PCModuleProxy.Service.UpdateLineEndGroutingLineDetail(dtName, scbGoods.SearchedPKMember);
- }));
- if (returnRow != null)
- {
- if (returnRow.Status == Constant.ServiceResultStatus.Success)
- {
- MessageBox.Show(this.Text + "成功", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.DialogResult = DialogResult.OK;
- }
- else if (returnRow.OtherStatus == -500)
- {
- MessageBox.Show("数据已经被修改,请重新编辑", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- MessageBox.Show(returnRow.Message,
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else
- {
- MessageBox.Show(this.Text + "失败", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_PC_0101_1_2_Load(object sender, EventArgs e)
- {
- this.dgvGroutingLineDetail.AutoGenerateColumns = false;
- DateTime accountDate = (DateTime)DoAsync(new BaseAsyncMethod(() =>
- {
- return CommonModuleProxy.Service.GetAccountDate();
- }));
- this.txtDateStart.Value = accountDate;
- this.dgvGroutingLineDetail.DataSource = _dtBindSource;
- // 设置可输入单元格的颜色
- this.dgvGroutingLineDetail.IsSetInputColumnsColor = true;
- DataSet dsSetting = SystemModuleProxy.Service.GetSystemSettingDataByCode(Constant.SettingType.S_PC_001.ToString());
- if (dsSetting != null && dsSetting.Tables[0].Rows.Count > 0)
- {
- this._S_PC_001 = dsSetting.Tables[0].Rows[0]["SettingValue"].ToString();
- }
- if (this._S_PC_001 == "2")
- {
- this.scbGoods.Visible = false;
- }
- }
- /// <summary>
- /// 取消按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 自适应列宽
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAdaptive_Click(object sender, EventArgs e)
- {
- this.dgvGroutingLineDetail.AutoResizeColumns();
- }
- /// <summary>
- /// 设置只读
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvGroutingLineDetail_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
- {
- DataGridView dgv = sender as DataGridView;
- if (dgv == null || dgv.ReadOnly || e.RowIndex < 0)
- {
- return;
- }
- try
- {
- if (string.IsNullOrEmpty(dgv.Rows[e.RowIndex].Cells["MouldID"].Value + ""))
- {
- // 自动生成模具
- dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = false;
- dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = false;
- }
- else
- {
- // 模具档案
- dgv.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = true;
- dgv.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = true;
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 设置非条码模具产品编码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void scbGoods_SearchedItemChanged(object sender, EventArgs e)
- {
- try
- {
- foreach (DataGridViewRow item in this.dgvGroutingLineDetail.Rows)
- {
- DataRowView row = item.DataBoundItem as DataRowView;
- if (row == null || row["MouldID"] + "" != "")
- {
- continue;
- }
- row["GoodsID"] = scbGoods.SearchedPKMember;
- row["GoodsCode"] = scbGoods.SearchedValue + "";
- row["GoodsName"] = scbGoods.SearchedText;
- row["GoodsSpecification"] = scbGoods.SearchedItem["GoodsSpecification"];
- row["RecordRemarks"] = row["OldRecordRemarks"] + "][" + row["GOODSCODE"] + "]";
- row.EndEdit();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- ///// <summary>
- ///// 设置非条码模具产品编码
- ///// </summary>
- ///// <param name="sender"></param>
- ///// <param name="e"></param>
- //private void dkGoodsCode_GoodsValueChanged(object sender, Controls.SearchTextBox.dkGoodsCodeSearchBox.TextChangeEventArgs e)
- //{
- // try
- // {
- // foreach (DataGridViewRow item in this.dgvGroutingLineDetail.Rows)
- // {
- // DataRowView row = item.DataBoundItem as DataRowView;
- // if (row == null || row["MouldID"] + "" != "")
- // {
- // continue;
- // }
- // row["GoodsID"] = scbGoods.SearchedPKMember;
- // row["GoodsCode"] = scbGoods.SearchedValue + "";
- // row["GoodsName"] = scbGoods.SearchedText;
- // row["GoodsSpecification"] = scbGoods.SearchedItem["GoodsSpecification"];
- // row["RecordRemarks"] = row["OldRecordRemarks"] + "][" + row["GOODSCODE"] + "]";
- // row.EndEdit();
- // }
- // }
- // catch (Exception ex)
- // {
- // // 对异常进行共通处理
- // ExceptionManager.HandleEventException(this.ToString(),
- // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- // }
- //}
- /// <summary>
- /// 选择改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvGroutingLineDetail_SelectionChanged(object sender, EventArgs e)
- {
- if (dgvGroutingLineDetail.CurrentRow == null)
- {
- return;
- }
- try
- {
- this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
- this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
- this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 验证模具条码
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- this.btnAddMouldBarcode_Click(null, null);
- }
- }
- /// <summary>
- /// 添加模具
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnAddMouldBarcode_Click(object sender, EventArgs e)
- {
- if (this.txtGMouldCode.Text == "" || this._gridIndex == -1 || this._currentRow == null)
- {
- MessageBox.Show("没有选择模具编号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtGMouldCode.Focus();
- return;
- }
- string barcode = this.txtBarcode.Text.Trim();
- if (barcode == "")
- {
- MessageBox.Show("没有输入模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtBarcode.Focus();
- return;
- }
- try
- {
- string gMouldCode = this.txtGMouldCode.Text;
- DataTable dtInfo = _dtBindSource;
- DataRow[] dr = dtInfo.Select("GroutingMouldCode <> '" + gMouldCode + "' and NewMouldBarcode = '" + barcode + "'");
- if (dr.Length > 0)
- {
- MessageBox.Show("存在相同的模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtBarcode.Focus();
- this.txtBarcode.SelectAll();
- return;
- };
- // 验证模具条码状态
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "PC_Mould";
- cre.Name = "GetMouldData";
- cre.Properties["MouldBarcode"] = barcode;
- ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
- if (sre == null || sre.Data == null || sre.Data.Tables.Count == 0 || sre.Data.Tables[0].Rows.Count == 0)
- {
- MessageBox.Show("无效模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtBarcode.Focus();
- this.txtBarcode.SelectAll();
- return;
- }
- DataRow item = sre.Data.Tables["InfoData"].Rows[0];
- int mouldStatus = Convert.ToInt32(item["MouldStatus"]);
- if (mouldStatus != 1 && mouldStatus != 3)
- {
- MessageBox.Show("此模具当前状态为【" + item["MouldStatusName"] + "】,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtBarcode.Focus();
- this.txtBarcode.SelectAll();
- return;
- }
- //this._currentRow["MouldSource"] = "1";
- //this._currentRow["MOULDID"] = item["MOULDID"];
- //this._currentRow["MOULDCODE"] = item["MOULDCODE"];
- //this._currentRow["NewMouldBarcode"] = item["MOULDBarcode"];
- //this._currentRow["GOODSID"] = item["GOODSID"];
- //this._currentRow["GOODSNAME"] = item["GOODSNAME"];
- //this._currentRow["GOODSCODE"] = item["GOODSCODE"];
- //this._currentRow["GoodsSpecification"] = item["GoodsSpecification"];
- //this._currentRow["GROUTINGCOUNT"] = item["GroutingNum"];
- //this._currentRow["StandardGroutingCount"] = item["StandardGroutingNum"];
- ////this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + item["MOULDBarcode"] + "][" + item["GOODSCODE"] + "]";
- //this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + "][" + item["GOODSCODE"] + "]";
- //this._currentRow.EndEdit();
- //this.txtBarcode.Clear();
- //this.txtBarcode.Focus();
- //if (this._gridIndex + 1 < this.dgvGroutingLineDetail.Rows.Count)
- //{
- // this._gridIndex++;
- //}
- //else
- //{
- // this._gridIndex = 0;
- //}
- int outputCount = Convert.ToInt32(item["OutputCount"]);
- if (outputCount == 1)
- {
- // 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
- if (this._currentRow["MOULDID"] != DBNull.Value)
- {
- //int oldMouldID = Convert.ToInt32(this._currentRow["MOULDID"]);
- DataRow[] rows = dtInfo.Select("MOULDID=" + this._currentRow["MOULDID"]);
- if (rows.Length > 1)
- {
- foreach (DataRow row in rows)
- {
- row["MouldSource"] = "0";
- row["MOULDID"] = DBNull.Value;
- row["MOULDCODE"] = DBNull.Value;
- row["NewMouldBarcode"] = DBNull.Value;
- row["GROUTINGCOUNT"] = 0;
- row["MouldOutputNo"] = DBNull.Value;
- row.EndEdit();
- }
- }
- }
- this._currentRow["MouldSource"] = "1";
- this._currentRow["MOULDID"] = item["MOULDID"];
- this._currentRow["MOULDCODE"] = item["MOULDCODE"];
- this._currentRow["NewMouldBarcode"] = item["MOULDBarcode"];
- this._currentRow["GOODSID"] = item["GOODSID"];
- this._currentRow["GOODSNAME"] = item["GOODSNAME"];
- this._currentRow["GOODSCODE"] = item["GOODSCODE"];
- this._currentRow["GoodsSpecification"] = item["GoodsSpecification"];
- this._currentRow["GROUTINGCOUNT"] = item["GroutingNums"];
- this._currentRow["MouldOutputNo"] = DBNull.Value;
- this._currentRow["StandardGroutingCount"] = item["StandardGroutingNum"];
- //this._currentRow["RecordRemarks"] = this._currentRow["OldRecordRemarks"].ToString() + item["MOULDBarcode"] + "]";
- this._currentRow.EndEdit();
- }
- else
- {
- // 一模多产时,必须绑定连续成型模具编号。 add by chenxy 2018-10-29
- string minGMouldCode = this.txtGMouldCode.Text;
- int maxIndex = Convert.ToInt32(minGMouldCode.Substring(minGMouldCode.Length - 3)) + outputCount;
- string maxGMouldCode = this.txtGroutingLineCode.Text + "-" + maxIndex.ToString("000");
- DataRow[] grows = dtInfo.Select("GroutingMouldCode>='" + minGMouldCode + "' and GroutingMouldCode<'" + maxGMouldCode + "'");
- if (grows.Length != outputCount)
- {
- MessageBox.Show("此模具的产出数量为【" + outputCount + "】,当前成型模具数量不足或编号不连续,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.txtBarcode.Focus();
- this.txtBarcode.SelectAll();
- return;
- }
- //foreach (DataRow row in grows)
- for (int i = 0; i < grows.Length; i++)
- {
- DataRow row = grows[i];
- DataRow itemOutput = sre.Data.Tables["InfoData"].Rows[i];
- // 一模多产时,清除同模具的绑定。 add by chenxy 2018-10-29
- if (row["MOULDID"] != DBNull.Value)
- {
- DataRow[] rows = dtInfo.Select("MOULDID=" + row["MOULDID"]);
- if (rows.Length > 1)
- {
- foreach (DataRow crow in rows)
- {
- crow["MouldSource"] = "0";
- crow["MOULDID"] = DBNull.Value;
- crow["MOULDCODE"] = DBNull.Value;
- crow["NewMouldBarcode"] = DBNull.Value;
- crow["GROUTINGCOUNT"] = 0;
- crow["MouldOutputNo"] = DBNull.Value;
- crow.EndEdit();
- }
- }
- }
- row["MouldSource"] = "1";
- row["MOULDID"] = item["MOULDID"];
- row["MOULDCODE"] = item["MOULDCODE"];
- row["NewMouldBarcode"] = item["MOULDBarcode"];
- row["GOODSID"] = item["GOODSID"];
- row["GOODSNAME"] = item["GOODSNAME"];
- row["GOODSCODE"] = item["GOODSCODE"];
- row["GoodsSpecification"] = item["GoodsSpecification"];
- row["GROUTINGCOUNT"] = itemOutput["GroutingNum"];
- row["MouldOutputNo"] = itemOutput["OutputNo"];
- row["StandardGroutingCount"] = item["StandardGroutingNum"];
- row.EndEdit();
- }
- }
- this.txtBarcode.Clear();
- this.txtBarcode.Focus();
- //if (this._gridIndex + 1 < this.dgvGroutingLineDetail.Rows.Count)
- //{
- // this._gridIndex++;
- //}
- //else
- //{
- // this._gridIndex = 0;
- //}
- if (this._gridIndex + outputCount < this.dgvGroutingLineDetail.Rows.Count)
- {
- this._gridIndex += outputCount;
- }
- else
- {
- this._gridIndex = 0;
- }
- this.dgvGroutingLineDetail.CurrentCell =
- this.dgvGroutingLineDetail.Rows[this._gridIndex].Cells[this.dgvGroutingLineDetail.CurrentCell.ColumnIndex];
- this.txtGMouldCode.Text = dgvGroutingLineDetail.CurrentRow.Cells["GroutingMouldCode"].Value.ToString();
- this._gridIndex = dgvGroutingLineDetail.CurrentRow.Index;
- this._currentRow = dgvGroutingLineDetail.CurrentRow.DataBoundItem as DataRowView;
- }
- catch (Exception ex)
- {
- //_ShowFlag = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- }
- }
|