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; namespace MES.ThinClient.Main { public partial class FMAILoadSelectMO : BaseForm { private Midea.MES.ThinClient.PDA.Main.WebService.WebService _service = new Midea.MES.ThinClient.PDA.Main.WebService.WebService(); /// <summary> /// 数据源 /// </summary> private DataTable g_dtSource = null; /// <summary> /// 将派工的信息加载到List,然后操作List /// </summary> private List<ScheduledMOModel> g_Molist = null; #region 构造函数 public FMAILoadSelectMO() { BaseForm.menuName = "选择作业号"; InitializeComponent(); this.g_dtSource = new DataTable(); this.g_Molist = new List<ScheduledMOModel>(); } #endregion #region 初始化 private void FMAILoadSelectMO_Load(object sender, EventArgs e) { _service.Url = LoginInfo.Current.Url; AutoConnent.Interval = 10 * 1000; AutoConnent.Enabled = true; this.dtPicker.Value = DateTime.Now; this.LoadLine(); this.InitGrid(); this.lblMsg.Text = ""; } #endregion #region InitGrid 初始化Grid标题信息 /// <summary> /// 初始化Grid标题信息 /// </summary> private void InitGrid() { this.g_dtSource.Clear(); this.g_dtSource.Columns.Add("seq", typeof(string)).ReadOnly = true; this.g_dtSource.Columns.Add("LineCode", typeof(string)).ReadOnly = true; this.g_dtSource.Columns.Add("MOName", typeof(string)).ReadOnly = true; this.g_dtSource.Columns.Add("ScheduledQty", typeof(string)).ReadOnly = true; this.g_dtSource.Columns.Add("MitemCode", typeof(string)).ReadOnly = true; this.g_dtSource.Columns.Add("ID", typeof(string)).ReadOnly = true; this.dgInfo.DataSource = this.g_dtSource; DataGridTableStyle dgtStyle = new DataGridTableStyle(); if (this.dgInfo.TableStyles.Count == 0) { this.dgInfo.TableStyles.Add(dgtStyle); dgtStyle.GridColumnStyles[0].HeaderText = "序号"; dgtStyle.GridColumnStyles[0].MappingName = "seq"; dgtStyle.GridColumnStyles[0].NullText = ""; dgtStyle.GridColumnStyles[0].Width = 30; dgtStyle.GridColumnStyles[1].HeaderText = "线体"; dgtStyle.GridColumnStyles[1].MappingName = "LineCode"; dgtStyle.GridColumnStyles[1].NullText = ""; dgtStyle.GridColumnStyles[1].Width = 60; dgtStyle.GridColumnStyles[2].HeaderText = "作业号"; dgtStyle.GridColumnStyles[2].MappingName = "MOName"; dgtStyle.GridColumnStyles[2].NullText = ""; dgtStyle.GridColumnStyles[2].Width = 80; dgtStyle.GridColumnStyles[3].HeaderText = "排产数量"; dgtStyle.GridColumnStyles[3].MappingName = "ScheduledQty"; dgtStyle.GridColumnStyles[3].NullText = ""; dgtStyle.GridColumnStyles[3].Width = 40; //不显示 - 传第2个界面 dgtStyle.GridColumnStyles[4].HeaderText = "物料编码"; dgtStyle.GridColumnStyles[4].MappingName = "MitemCode"; dgtStyle.GridColumnStyles[4].NullText = ""; dgtStyle.GridColumnStyles[4].Width = 0; dgtStyle.GridColumnStyles[5].HeaderText = "ID"; dgtStyle.GridColumnStyles[5].MappingName = "ID"; dgtStyle.GridColumnStyles[5].NullText = ""; dgtStyle.GridColumnStyles[5].Width = 0; } } #endregion #region 网络监测 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 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), btnSubmit, "Button", "Enabled", "true"); return true; } catch { //this.Invoke(new SetAttributeDelegate(SetAttribute), lblNetMsg, "Label", "ForeColor", Color.Red.ToArgb().ToString()); this.Invoke(new SetAttributeDelegate(SetAttribute), btnSubmit, "Button", "Enabled", "false"); return false; } } private void AutoConnent_Tick(object sender, EventArgs e) { this.checkConnent(); } private void FMAILoadSelectMO_Closing(object sender, CancelEventArgs e) { AutoConnent.Enabled = false; AutoConnent.Dispose(); } #region 提示信息 /// <summary> /// 设置提示信息 /// </summary> /// <param name="strMsg">内容</param> /// <param name="color">颜色</param> private void SetMsg(string strMsg, Color color) { this.lblMsg.ForeColor = color; this.lblMsg.Text = strMsg; } #endregion #region 加载产线 private void LoadLine() { this.cbLineCode.Items.Clear(); this.cbLineCode.Text = string.Empty; try { _service.Url = LoginInfo.Current.Url; OutputWebMessage output = this._service.Scheduling_GetLineCode(Convert.ToInt32(LoginInfo.Current.OrgID)); if (output != null && output.IsSuccess == true) { if (output.ExtendData != null) { List<ScheduledMOModel> listdata = output.ExtendData as List<ScheduledMOModel>; List<string> Line = new List<string>(); Line = listdata.Select(m => m.LineCode).ToList(); foreach (var item in Line) { this.cbLineCode.Items.Add(item); } //DataTable dt = output.ExtendData as DataTable; //for (int i = 0; i < dt.Rows.Count; i++) //{ // //this.cbLineCode.Items.Add(new ItemObject() { ItemValue = dt.Rows[i]["ID"], ItemText = dt.Rows[i]["LineCode"].ToString() }); // this.cbLineCode.Items.Add(dt.Rows[i]["LineCode"].ToString()); //} } else { SetMsg("没有线体信息!", Color.Red); return; } } else { SetMsg(output.ErrorMessage, Color.Red); return; } } catch (Exception ex) { SetMsg(ex.Message, Color.Red); return; } } #endregion #region 加载派工信息 private void GetScheduled(int invOrgID, string lineID, DateTime dateSchedule) { try { _service.Url = LoginInfo.Current.Url; OutputWebMessage output = this._service.Scheduling_GetScheduled(invOrgID, lineID, dateSchedule); if (output != null && output.IsSuccess == true) { if (output.ExtendData != null) { g_Molist.Clear(); g_Molist = output.ExtendData as List<ScheduledMOModel>; //加载设备 this.cbdevice.Items.Clear(); List<string> device = new List<string>(); device = g_Molist.Select(m=>m.ResourcesCode).Distinct().ToList(); if (device.Count < 1) { SetMsg("没有设备信息!", Color.Red); return; } else { foreach (var item in device) { this.cbdevice.Items.Add(item); } } } else { SetMsg("没有派工相关信息!", Color.Red); return; } } else { SetMsg(output.ErrorMessage, Color.Red); return; } } catch (Exception ex) { SetMsg(ex.Message, Color.Red); return; } } #endregion #region 退出、取消 private void btnExit_Click_1(object sender, EventArgs e) { this.Close(); } #endregion #region 确定 private void btnSubmit_Click(object sender, EventArgs e) { //载入扫描飞达和栈位界面 this.SetMsg("", Color.Blue); if (this.dgInfo.CurrentRowIndex != -1) { DataRow dr = g_dtSource.Rows[this.dgInfo.CurrentRowIndex]; string mitemCode = dr["MitemCode"].ToString(); //物料编码 string deviceCode = cbdevice.Text; //设备 string dtlID = dr["ID"].ToString(); //工单明细ID string MOName = dr["MOName"].ToString(); //工单 string ScheduledQty = dr["ScheduledQty"].ToString(); //工单 if (string.IsNullOrEmpty(mitemCode) || string.IsNullOrEmpty(deviceCode) || string.IsNullOrEmpty(dtlID) || string.IsNullOrEmpty(MOName)) { this.SetMsg("没有正常获取信息!", Color.Red); return; } //载入扫描飞达和栈位界面 FMAILoadScan fm = new FMAILoadScan(mitemCode, deviceCode, dtlID, MOName, ScheduledQty); fm.ShowDialog(); } else { this.SetMsg("请选择工单信息!", Color.Red); } } #endregion #region 根据焦点状态改变背景色 private void Control_GotFocus(object sender) { if (sender is ComboBox) { ((ComboBox)sender).SelectAll(); ((ComboBox)sender).BackColor = Color.GreenYellow; } } private void Control_LostFocus(object sender) { if (sender is ComboBox) { ((ComboBox)sender).BackColor = Color.Yellow; } } #endregion #region 回车焦点 private void dtPicker_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != '\r') { return; } this.cbLineCode.Focus(); } private void cbLineCode_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != '\r') { return; } this.cbdevice.Focus(); } #endregion #region 日期选择事件 private void dtPicker_ValueChanged(object sender, EventArgs e) { if (this.cbLineCode.Text != "") { GetScheduled(Convert.ToInt32(LoginInfo.Current.OrgID), this.cbLineCode.Text, this.dtPicker.Value); } } #endregion #region 线体选择事件 private void cbLineCode_SelectedValueChanged(object sender, EventArgs e) { if (this.cbLineCode.Text != "") { GetScheduled(Convert.ToInt32(LoginInfo.Current.OrgID), this.cbLineCode.Text, this.dtPicker.Value); } } #endregion #region 设备选择事件-过滤当前派工数据 private void cbdevice_SelectedValueChanged(object sender, EventArgs e) { if (this.cbdevice.Text != "") { List<ScheduledMOModel> tmp_Molist = new List<ScheduledMOModel>(this.g_Molist.Where(m => m.ResourcesCode == this.cbdevice.Text)); //加载列表信息 this.g_dtSource.Rows.Clear(); foreach (var item in tmp_Molist) { this.g_dtSource.Rows.Add(item.Seq, item.LineCode, item.MOName, item.ScheduledQty, item.MitemCode, item.ID); } } } #endregion #region 选中整行 private void dgInfo_CurrentCellChanged(object sender, EventArgs e) { this.dgInfo.Select(this.dgInfo.CurrentRowIndex); } #endregion } }