using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using QMAPP.Entity; using QMAPP.FJC.Entity.Operation; using QMFrameWork.Data; using QMFrameWork.Common.Serialization; using QM.Common; using QMAPP.WinForm.Common; namespace QMAPP.WinForm.Forms.Mend { public partial class ProductCheckAddForm : Form { CheckWithMaterial searchModel = new CheckWithMaterial(); ProductCheck proCheckInfo = new ProductCheck(); CheckValueItem checkValue = new CheckValueItem(); BasicData basicData = new BasicData(); public ProductCheckAddForm() { InitializeComponent(); this.txtProcessCode.Tag = false; this.txtProcessCode.GotFocus += new EventHandler(this.txtCode_GotFocus); this.txtProcessCode.MouseUp += new MouseEventHandler(this.txtCode_MouseUp); } #region 加载界面 /// /// 加载界面 /// /// /// private void ProductCheckAddForm_Load(object sender, EventArgs e) { new KeyEvent().SetKeyToTxt(this); this.cobResult.Items.Add(new ListItem("0", "合格")); this.cobResult.Items.Add(new ListItem("1", "不合格")); this.cobResult.Items.Add(new ListItem("2", "")); //加载首件过程下拉列表 this.comFirstProduct.DataSource = basicData.GetDictionaryList("PRODUCTCHECKTYPE"); this.comFirstProduct.DisplayMember = "value"; this.comFirstProduct.ValueMember = "key"; this.comFirstProduct.Text = ""; this.txtProcessCode.Focus(); } #endregion #region 回车事件 /// /// 回车事件 /// /// /// private void txtCode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter)//如果输入的是回车键 { GetProduceInfo(); } } #endregion #region 获取条码信息(显示物料等信息、填充Grid) /// /// 获取条码信息(显示) /// private void GetProduceInfo() { if (string.IsNullOrEmpty(txtProcessCode.Text)) { txtProcessCode.Focus(); txtProcessCode.SelectAll(); return; } var pcode = txtProcessCode.Text.Trim().ToUpper(); Product pro = new Product(); pro.PRODUCTCODE = pcode; //先校验 //获取信息 QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent(); Product result = agent.InvokeServiceFunction("ProductBLL_GetByCondition", pro); //校验判断 //存在信息 if (result != null) { this.txtmaterialname.Text = result.MATERIAL_NAME; this.txtMaterialCode.Text = result.MATERIAL_CODE; this.txtProducedate.Text = result.CREATEDATE.ToShortDateString(); searchModel.MATERIAL_CODE = result.MATERIAL_CODE; this.labelError.Text = ""; //List recorders = null;//查询配置表列表 ProductCheck proCheck = new ProductCheck(); proCheck.PRODUCTCODE = pcode; proCheck = agent.InvokeServiceFunction("ProductCheckBLL_Get", proCheck); if (proCheck != null) { this.txtPid.Text = proCheck.PID; searchModel.PRODUCTCHECK_PID = this.txtPid.Text; this.cobResult.SelectedIndex = Convert.ToInt32(proCheck.CHECKRESULT); this.comFirstProduct.SelectedIndex = Convert.ToInt32(proCheck.PRODUCTCHECKTYPE); } else { this.txtPid.Text =""; searchModel.PRODUCTCHECK_PID = this.txtPid.Text; this.cobResult.SelectedIndex = 2; } DGData.AutoGenerateColumns = false; List dataResult = agent.InvokeServiceFunction>("ProductCheckBLL_GetCheckWithMaterialInfo", searchModel); this.DGData.DataSource = dataResult; DGData.ClearSelection(); } else { this.labelError.Text = "此条码信息不存在!"; return; } } #endregion #region 点击编辑或者双击表格 /// /// 点击编辑或者双击表格 /// /// /// private void butEdit_Click(object sender, EventArgs e) { if (this.DGData.SelectedRows.Count > 0) { string checkcode = this.DGData.SelectedRows[0].Cells["CHECKITEMCODE"].Value.ToString(); ProductCheckValuesFrom editForm = new ProductCheckValuesFrom(this); editForm.ShowDialog(); } else { string errorMessae = "请选择编辑的信息或者双击需要编辑的内容"; MessageBox.Show(errorMessae, Resource1.ConfirmTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } #endregion #region 更新Grid目标值 /// /// 更新Grid目标值 /// /// /// public void UpdateGrid(string Checkcode,string InputValue) { for (int i = 0; i < this.DGData.Rows.Count; i++) { if (this.DGData.Rows[i].Cells["CHECKITEMCODE"].Value.ToString() == Checkcode) { this.DGData.Rows[i].Cells["INPUTVALUE"].Value = InputValue; } } } #endregion #region 确认保存 /// /// 确认保存 /// /// /// private void butSave_Click(object sender, EventArgs e) { //窗体数据校验 string errorMessae = ErrorCheck(); if (errorMessae != "") { this.labelError.Text = errorMessae; return; } QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent(); //更新(此PID是T_AW_PRODUCTCHECK主键) if (string.IsNullOrEmpty(this.txtPid.Text)==false) { proCheckInfo.PID = this.txtPid.Text; proCheckInfo.PRODUCTCODE = this.txtProcessCode.Text; proCheckInfo.MATERIAL_CODE = this.txtMaterialCode.Text; proCheckInfo.CHECKRESULT = this.cobResult.SelectedIndex.ToString(); proCheckInfo.PRODUCTCHECKTYPE = this.comFirstProduct.SelectedIndex.ToString(); proCheckInfo.CREATEDATE = DateTime.Now; proCheckInfo.CREATEUSER = ClientContext.LoginInfo.UserID; DataResult result = agent.InvokeServiceFunction>("ProductCheckBLL_UpdateProductCheck", proCheckInfo); } //新建 else { proCheckInfo.PID = Guid.NewGuid().ToString(); proCheckInfo.PRODUCTCODE = this.txtProcessCode.Text; proCheckInfo.MATERIAL_CODE = this.txtMaterialCode.Text; proCheckInfo.CHECKRESULT = this.cobResult.SelectedIndex.ToString(); proCheckInfo.PRODUCTCHECKTYPE = this.comFirstProduct.SelectedIndex.ToString(); proCheckInfo.CREATEDATE = DateTime.Now; proCheckInfo.CREATEUSER = ClientContext.LoginInfo.UserID; DataResult result = agent.InvokeServiceFunction>("ProductCheckBLL_InsertProductCheck", proCheckInfo); } DataTable CheckValueDt = new DataTable(); for (int i = 0; i < this.DGData.Columns.Count; i++) { DataColumn dc = new DataColumn(this.DGData.Columns[i].Name.ToString()); CheckValueDt.Columns.Add(dc); } for (int i = 0; i < this.DGData.Rows.Count; i++) { DataRow dr = CheckValueDt.NewRow(); for (int sub = 0; sub < this.DGData.Columns.Count; sub++) { dr[sub] = Convert.ToString(this.DGData.Rows[i].Cells[sub].Value); } CheckValueDt.Rows.Add(dr); } checkValue.PRODUCTCHECK_PID = proCheckInfo.PID; checkValue.CREATEUSER = ClientContext.LoginInfo.UserID; DataResult InOrUpresult = agent.InvokeServiceFunction>("ProductCheckBLL_EditInsertCheckValueItem", CheckValueDt, checkValue); if (InOrUpresult.IsSuccess ==true )//判断是否投料窗口已做操作 { this.Close(); //提示 this.DialogResult = DialogResult.OK; } } #endregion #region 错误检测 /// ///错误检测 /// /// private string ErrorCheck() { string strMessage = ""; // if (string.IsNullOrEmpty(this.txtProcessCode.Text) == false && string.IsNullOrEmpty(this.txtMaterialCode.Text)==true) { strMessage += "请扫描正确的条码!" + "\r\n"; } // if (string.IsNullOrEmpty(this.txtProcessCode.Text) != false) { strMessage += "请扫描条码!" + "\r\n"; } // if (string.IsNullOrEmpty(this.cobResult.Text.ToString())!=false) { strMessage += "请选择检测结果!" + "\r\n"; } // if (string.IsNullOrEmpty(this.comFirstProduct.Text.ToString()) != false) { strMessage += "请选择抽检类型!" + "\r\n"; } if (string.IsNullOrEmpty(this.txtProcessCode.Text) == false && string.IsNullOrEmpty(this.txtMaterialCode.Text) == false) { int NUM = 0; for (int i = 0; i < this.DGData.Rows.Count; i++) { if (this.DGData.Rows[i].Cells["INPUTVALUE"].Value!=null) { NUM = +1; } } if (NUM == 0) { strMessage += "至少填写一项检测值?" + "\r\n"; } } return strMessage; } #endregion #region 条码框内容全选 /// /// /// /// /// private void txtCode_GotFocus(object sender, EventArgs e) { this.txtProcessCode.Tag = true; this.txtProcessCode.SelectAll(); } /// /// /// /// /// private void txtCode_MouseUp(object sender, MouseEventArgs e) { //if (e.Button == MouseButtons.Left && (bool)this.txtProcessCode.Tag==true) //{ this.txtProcessCode.SelectAll(); //} //this.txtProcessCode.Tag = false; } #endregion #region 点击目标值时候编辑 /// /// 点击目标值时候编辑 /// /// /// private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { DataGridViewCell dgvc = this.DGData.CurrentCell; if (dgvc != null && dgvc.OwningColumn.Name == "INPUTVALUE") { string inputtype = this.DGData.SelectedRows[0].Cells["INPUTTYPE"].Value.ToString(); if (inputtype == "1") { dgvc.ReadOnly = false; Rectangle R = DGData.GetCellDisplayRectangle(dgvc.ColumnIndex, dgvc.RowIndex, false); if (dgvc.Value==null) { dgvc.Value = "OK"; } else { if (dgvc.Value.ToString() == "OK") { dgvc.Value = "NOK"; } else { dgvc.Value = "OK"; } } dgvc.ReadOnly = true; } } } #endregion } }