using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; namespace MES.ThinClient.APP.Main { public partial class FFinishSnBackInv : BaseForm { #region 属性 private MES.ThinClient.APP.Main.WebService.WebService _service = new MES.ThinClient.APP.Main.WebService.WebService(); /// <summary> /// 数据源 /// </summary> private DataTable g_dtSource = null; FMessageBoxForm msgBox = null; #endregion public FFinishSnBackInv() { BaseForm.menuName = "完工返数采集"; InitializeComponent(); } private void FFinishSnBackInv_Load(object sender, EventArgs e) { _service.Url = LoginInfo.Current.Url; this.InitGrid(); this.InitTransStyle(); if (msgBox == null) msgBox = new FMessageBoxForm(); this.cboInvCode.Enabled = false; this.dgInfo.Visible = false; } #region 初始化datagrid private void InitGrid() { this.g_dtSource = new DataTable(); this.g_dtSource.Columns.Add("ID").ReadOnly = true; this.g_dtSource.Columns.Add("MoName").ReadOnly = true; this.g_dtSource.Columns.Add("MoPlanQty").ReadOnly = true; this.g_dtSource.Columns.Add("CollectionQty").ReadOnly = true; this.g_dtSource.Columns.Add("SYQty").ReadOnly = true; this.g_dtSource.Columns.Add("MoItemName").ReadOnly = true; this.g_dtSource.Columns.Add("MOItemDescription").ReadOnly = true; this.g_dtSource.Columns.Add("MoPlanDate").ReadOnly = true; this.g_dtSource.Columns.Add("MoOffQty").ReadOnly = true; this.g_dtSource.Columns.Add("CurShiftQty").ReadOnly = true; this.g_dtSource.Columns.Add("MoOnQty").ReadOnly = true; this.g_dtSource.DefaultView.AllowNew = false; this.dgInfo.DataSource = this.g_dtSource.DefaultView; #region grid 标题与样式 DataGridTableStyle dg = new DataGridTableStyle(); if (dgInfo.TableStyles.Count == 0) { dg.MappingName = (dgInfo.DataSource as DataView).Table.TableName; this.dgInfo.TableStyles.Add(dg); dg.GridColumnStyles[0].HeaderText = "*"; dg.GridColumnStyles[1].HeaderText = "作业号"; dg.GridColumnStyles[2].HeaderText = "排产量"; dg.GridColumnStyles[3].HeaderText = "已采"; dg.GridColumnStyles[4].HeaderText = "剩余"; dg.GridColumnStyles[5].HeaderText = "装配件编码"; dg.GridColumnStyles[6].HeaderText = "装配件描述"; dg.GridColumnStyles[7].HeaderText = "排产日期"; dg.GridColumnStyles[8].HeaderText = "下线"; dg.GridColumnStyles[9].HeaderText = "当班"; dg.GridColumnStyles[10].HeaderText = "上线"; dg.GridColumnStyles[0].Width = 20; dg.GridColumnStyles[1].Width = 80; dg.GridColumnStyles[2].Width = 50; dg.GridColumnStyles[3].Width = 40; dg.GridColumnStyles[4].Width = 40; dg.GridColumnStyles[5].Width = 100; dg.GridColumnStyles[6].Width = 80; dg.GridColumnStyles[7].Width = 60; dg.GridColumnStyles[8].Width = 40; dg.GridColumnStyles[9].Width = 40; dg.GridColumnStyles[10].Width = 40; for (int i = 0; i <= dgInfo.TableStyles.Count - 1; i++) { dg.GridColumnStyles[i].NullText = string.Empty; } } #endregion } #endregion #region 初始化事物类型 private void InitTransStyle() { ItemObject ioTransType = new ItemObject() { ItemValue = "FINISH_GOOD_INV_BACK", ItemText = "完工返数" }; this.cboTransStyle.Items.Add(ioTransType); this.cboTransStyle.SelectedIndex = 0;//默认为完工返数 this.cboTransStyle.Enabled = false; } #endregion #region 完工返数采集 private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != ‘\r‘ || this.txtBarcode.Text.Trim() == "") { return; } if (this.IsFullWidth(this.txtBarcode.Text.Trim())) { MessageBox.Show("条码中包含全角字符!"); Application.DoEvents(); this.txtBarcode.Focus(); return; } //是否将条码转成大写 this.txtBarcode.Text = this.txtBarcode.Text.ToUpper(); this.cboInvCode.Items.Clear(); this.lblMsg.Text = string.Empty; try { OutputWebMessage output = this._service.FGBackInv_SaveBackInv(this.txtBarcode.Text.Trim(), -1, string.Empty, LoginInfo.Current.UserCode,"BACK", DateTime.Now, LoginInfo.Current.OrgID); if (output != null && output.IsSuccess == true) { if (output.ExtendData != null) { DataTable tableResMoQty = output.ExtendData as DataTable; if (tableResMoQty.Rows.Count > 0) { //string strQty = "0"; //string strSSName = string.Empty; //string strSegName = string.Empty; string strMoName = string.Empty; string strItemDesc = string.Empty; string strItemCode = string.Empty; //string strPlanQty = string.Empty; //string strOnLineQty = string.Empty; //string strOffLineQty = string.Empty; string strMoPlanStartDate = string.Empty; //string strCurShiftQty = string.Empty; if (tableResMoQty.Rows[0]["MONAME"] != DBNull.Value && tableResMoQty.Rows[0]["MONAME"].ToString() != "null") { strMoName = tableResMoQty.Rows[0]["MONAME"].ToString(); } //if (tableResMoQty.Rows[0]["SSNAME"] != DBNull.Value && tableResMoQty.Rows[0]["SSNAME"].ToString() != "null") //{ // strSSName = tableResMoQty.Rows[0]["SSNAME"].ToString(); //} //if (tableResMoQty.Rows[0]["SEGNAME"] != DBNull.Value && tableResMoQty.Rows[0]["SEGNAME"].ToString() != "null") //{ // strSegName = tableResMoQty.Rows[0]["SEGNAME"].ToString(); //} if (tableResMoQty.Rows[0]["ITEMDESC"] != DBNull.Value && tableResMoQty.Rows[0]["ITEMDESC"].ToString() != "null") { strItemDesc = tableResMoQty.Rows[0]["ITEMDESC"].ToString(); } if (tableResMoQty.Rows[0]["ITEMCODE"] != DBNull.Value && tableResMoQty.Rows[0]["ITEMCODE"].ToString() != "null") { strItemCode = tableResMoQty.Rows[0]["ITEMCODE"].ToString(); } //if (tableResMoQty.Rows[0]["OUTPUTQTY"] != DBNull.Value && tableResMoQty.Rows[0]["OUTPUTQTY"].ToString() != "null") //{ // strQty = tableResMoQty.Rows[0]["OUTPUTQTY"].ToString(); //} //if (tableResMoQty.Rows[0]["PLANQTY"] != DBNull.Value && tableResMoQty.Rows[0]["PLANQTY"].ToString() != "null") //{ // strPlanQty = tableResMoQty.Rows[0]["PLANQTY"].ToString(); //} //if (tableResMoQty.Rows[0]["ONLINEQTY"] != DBNull.Value && tableResMoQty.Rows[0]["ONLINEQTY"].ToString() != "null") //{ // strOnLineQty = tableResMoQty.Rows[0]["ONLINEQTY"].ToString(); //} //if (tableResMoQty.Rows[0]["OFFLINEQTY"] != DBNull.Value && tableResMoQty.Rows[0]["OFFLINEQTY"].ToString() != "null") //{ // strOffLineQty = tableResMoQty.Rows[0]["OFFLINEQTY"].ToString(); //} if (tableResMoQty.Rows[0]["DATETIME_SCHE_START"] != DBNull.Value && tableResMoQty.Rows[0]["DATETIME_SCHE_START"].ToString() != "null") { strMoPlanStartDate = tableResMoQty.Rows[0]["DATETIME_SCHE_START"].ToString(); } //if (tableResMoQty.Rows[0]["curshiftqty"] != DBNull.Value && tableResMoQty.Rows[0]["curshiftqty"].ToString() != "null") //{ // strCurShiftQty = tableResMoQty.Rows[0]["curshiftqty"].ToString(); //} //提示 this.DisplayMessage("采集成功!", "OK"); //头信息 //返数数量+1 int temp = string.IsNullOrEmpty(this.lblBackNum.Text) ? 0 : Convert.ToInt32(this.lblBackNum.Text); this.lblBackNum.Text = (temp + 1).ToString(); //子库 if (tableResMoQty.Rows[0]["DefaultInv"] != DBNull.Value && tableResMoQty.Rows[0]["DefaultInv"].ToString() != "null") { this.cboInvCode.Items.Add(tableResMoQty.Rows[0]["DefaultInv"].ToString()); this.cboInvCode.SelectedIndex = 0; } //作业号 this.lblMOName.Text = strMoName; //装配件 this.lblMitemName.Text = strItemDesc; //统计信息 //this.BindCollectQty(strSSName, strSegName, strMoName, strItemCode, strItemDesc, strPlanQty, strQty, strOnLineQty, strOffLineQty, strMoPlanStartDate, strCurShiftQty); } else { //提示 this.DisplayMessage(string.Format("[{0}]采集成功!", this.txtBarcode.Text), "OK"); this.lblMsg.Text = "采集成功!但查询统计信息失败!"; } } //提示 this.DisplayMessage(string.Format("[{0}]采集成功!", this.txtBarcode.Text), "OK"); } else { this.DisplayMessage(string.Format("[{0}]采集失败!{1}", this.txtBarcode.Text, output.ErrorMessage), "Fail"); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); this.lblMsg.Text = ex.Message; } } #endregion #region 更新列表 public void BindCollectQty(string ssname, string segname, string moname, string itemcode, string itemdesc, string planqty, string outputqty, string onlineqty, string offlineqty, string moplanstartdate, string curshiftqty) { try { bool bFlag = false; if (this.g_dtSource != null && g_dtSource.Rows.Count > 0) { //bool bFlag = false; for (int i = 0; i < this.g_dtSource.Rows.Count; i++) { if (this.lblMOName.Text == this.g_dtSource.Rows[i]["MoName"].ToString()) { this.g_dtSource.Columns["CurShiftQty"].ReadOnly = false; this.g_dtSource.Columns["CollectionQty"].ReadOnly = false; this.g_dtSource.Columns["SYQty"].ReadOnly = false; //计划量 int iPlanQty = ConverToInt32(this.g_dtSource.Rows[i]["MOPLANQTY"].ToString(), 0); //工位采集总数量 int iSumQty = ConverToInt32(this.g_dtSource.Rows[i]["CollectionQty"].ToString(), 0); //当班数量 int iShiftCodeQty = ConverToInt32(this.g_dtSource.Rows[i]["CurShiftQty"].ToString(), 0); //临时存放 int iTemp = int.Parse(outputqty) - iSumQty; // 如果差异数值小于0,或者大于2,则重新加载表格 //if (iTemp < 0 || iTemp >= 2) if (iTemp > 0 || iTemp <= -2) break; this.g_dtSource.Rows[i]["CollectionQty"] = outputqty; this.g_dtSource.Rows[i]["CurShiftQty"] = iShiftCodeQty + iTemp; this.g_dtSource.Rows[i]["SYQty"] = (iPlanQty - int.Parse(outputqty)); bFlag = true; this.g_dtSource.Columns["CurShiftQty"].ReadOnly = true; this.g_dtSource.Columns["CollectionQty"].ReadOnly = true; this.g_dtSource.Columns["SYQty"].ReadOnly = true; break; } } } else { bFlag = false; } if (bFlag == false) { //计划量 int iPlanQty = ConverToInt32(planqty, 0); //工位采集总数 int iSumQty = ConverToInt32(outputqty, 0); //剩余量 int iQty = iPlanQty - iSumQty; string strDate = ""; try { strDate = moplanstartdate;//dt.Rows[i]["MOPLANSTARTDATE"].ToString(); } catch { } DataTable dtTmp = this.g_dtSource.Clone(); DataRow[] rows = dtTmp.Select("MONAME=‘" + moname + "‘"); if (rows != null && rows.Length > 0) { if (int.Parse(rows[0]["CurShiftQty"].ToString()) > 0) rows[0]["CurShiftQty"] = Convert.ToInt32(rows[0]["CurShiftQty"]) + Convert.ToInt32(curshiftqty); else rows[0]["CurShiftQty"] = curshiftqty; rows[0]["CollectionQty"] = Convert.ToInt32(rows[0]["CollectionQty"]) + Convert.ToInt32(outputqty); rows[0]["SYQty"] = iPlanQty - Convert.ToInt32(rows[0]["CollectionQty"]); } else { dtTmp.Rows.Add( new object[] { this.g_dtSource.Rows.Count+1, moname, iPlanQty.ToString(), iSumQty.ToString(), iQty.ToString(), itemcode, itemdesc, strDate, offlineqty, curshiftqty, onlineqty }); } this.g_dtSource = dtTmp; DataView dv = new DataView(g_dtSource); dv.AllowNew = false; dv.AllowEdit = false; dv.AllowDelete = false; dgInfo.DataSource = dv; } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } #endregion #region Convert string to Int32 private int ConverToInt32(string s, int defaultvalue) { try { Int32.Parse(s); return Int32.Parse(s); } catch { return defaultvalue; } } #endregion #region 其他事件 private void btnExit_Click(object sender, EventArgs e) { this.Close(); } private void txtBarcode_GotFocus(object sender, EventArgs e) { Control_GotFocus(sender); } private void txtBarcode_LostFocus(object sender, EventArgs e) { Control_LostFocus(sender); } private void FFinishSnBackInv_Closing(object sender, CancelEventArgs e) { AutoConnent.Enabled = false; AutoConnent.Dispose(); } private void AutoConnent_Tick(object sender, EventArgs e) { this.checkConnent(); } private void btnReset_Click(object sender, EventArgs e) { this.cboInvCode.Items.Clear(); this.cboInvCode.Text = string.Empty; this.lblMOName.Text = string.Empty; this.lblMitemName.Text = string.Empty; this.lblBackNum.Text = string.Empty; this.txtBarcode.Text = string.Empty; this.lblMsg.Text = string.Empty; this.g_dtSource.Rows.Clear(); this.txtBarcode.Focus(); } #endregion #region 信息显示 public void DisplayMessage(string message, string type) { this.lblMsg.Text = message; if (type == "OK") { this.lblMsg.ForeColor = Color.Blue; msgBox.ShowSuccess(); } else { this.lblMsg.ForeColor = Color.Red; msgBox.ShowError(); } } #endregion #region 检查是否存在全角字符 /// <summary> /// 检查是否存在全角字符 /// </summary> /// <param name="text"></param> /// <returns></returns> private bool IsFullWidth(string text) { for (int i = 0; i < text.Length; i++) { int count = System.Text.Encoding.Default.GetByteCount(text.Substring(i, 1)); if (count == 2) { return true; } } return false; } #endregion #region TextBox根据焦点状态改变背景色 private void Control_GotFocus(object sender) { if (sender is TextBox) { ((TextBox)sender).SelectAll(); ((TextBox)sender).BackColor = Color.GreenYellow; } } private void Control_LostFocus(object sender) { if (sender is TextBox) { ((TextBox)sender).BackColor = Color.Yellow; } } #endregion #region 网络监测 private bool checkConnent() { try { string testNet = _service.HelloWorld(); this.Invoke(new SetAttributeDelegate(SetAttribute), lblNetMsg, "Label", "ForeColor", Color.PaleGreen.ToArgb().ToString()); this.Invoke(new SetAttributeDelegate(SetAttribute), this.txtBarcode, "TextBox", "Enabled", "true"); return true; } catch { this.Invoke(new SetAttributeDelegate(SetAttribute), lblNetMsg, "Label", "ForeColor", Color.Red.ToArgb().ToString()); this.Invoke(new SetAttributeDelegate(SetAttribute), this.txtBarcode, "TextBox", "Enabled", "false"); return false; } } public delegate void SetAttributeDelegate(Control control, string type, string attribute, string content); public delegate string GetAttributeDelegate(Control control, string type, string attribute); private void SetAttribute(Control control, string type, string attribute, string content) { if (attribute == "ForeColor") { if (type == "Label") { try { ((Label)control).ForeColor = Color.FromArgb(int.Parse(content)); } catch { } } } else if (attribute == "Text") { if (type == "Label") { ((Label)control).Text = content; } else if (type == "Button") { ((Button)control).Text = content; } else if (type == "TextBox") { ((TextBox)control).Text = content; } } else if (attribute == "Enabled") { if (type == "Button") { try { ((Button)control).Enabled = bool.Parse(content); } catch { } } } else if (attribute == "Focus") { if (type == "TextBox") { ((TextBox)control).Focus(); } } } private string GetAttribute(Control control, string type, string attribute) { if (attribute == "Text") { if (type == "ComboBox") { try { return ((ComboBox)control).Text; } catch { } } } return ""; } #endregion } }
时间: 2024-11-04 19:01:34