using System; using System.Collections.Generic; using ProjectBase.Controls; using SIMDP.BLL; using ProjectBase.Data.Pager; using SIMDP.Model; using ProjectBase.Util; using ProjectBase.Data.BaseDAL; using ProjectBase.Data.Logs; using ProjectBase.Data.Redis; using StackExchange.Redis; using System.Windows.Forms; using System.Drawing; using System.Data; using SIMDP.View; using DevExpress.XtraGrid.Views.Grid; namespace SIMDP.Project { public partial class FormCurrentTask : BaseDock { #region 变量声明 private RedisHelper redis = new RedisHelper(0); private bool bNeedVerify = true; public FormCurrentTask() { InitializeComponent(); //当前任务功能 初始化 BindData(); SubScribeEnent(); //条码录入功能 初始化 InitLookUpCtrl(); MainForm.eventUserIdle += new MainForm.delegateResetVertify(ResetVervity);//订阅权限超时事件 SetHeadScannerlabel(); SetFEMScannerlabel(); lookUp_TaskState.EditValueChanged += new System.EventHandler(this.lookUp_TaskState_EditValueChanged); } private void InitLookUpCtrl() { Dictionary linkType2 = new Dictionary(); linkType2.Add("1", "下载AS400数据"); linkType2.Add("5", "调整扫码工位指针"); linkType2.Add("6", "强制写入安装工位"); lookUp_TaskState.Properties.DataSource = linkType2; lookUp_TaskState.Properties.ValueMember = "Key"; lookUp_TaskState.Properties.DisplayMember = "Value"; lookUp_TaskState.EditValue = ""; SmProject.InitColorList(); lookUp_Color.Properties.DataSource = SmProject.ColorList; lookUp_Color.Properties.ValueMember = "Value"; lookUp_Color.Properties.DisplayMember = "Key"; lookUp_Color.EditValue = ""; } private void lookUp_TaskState_EditValueChanged(object sender, EventArgs e) { txt_VINInput.Text = ""; txt_ModelInput.Text = ""; lookUp_Color.Text = ""; txt_VINInput.Enabled = false; txt_ModelInput.Enabled = false; lookUp_Color.Enabled = false; txt_VINInput.EditValueChanged -= txt_VINInput_EditValueChanged; if (lookUp_TaskState.EditValue.ToString() == "") return; if (bNeedVerify) { FormUserVerification form = new FormUserVerification(); form.ShowDialog(); if (form.DialogResult != DialogResult.OK) { lookUp_TaskState.EditValue = ""; return; } else bNeedVerify = false; } //判断是什么模式,给什么输入框 if (lookUp_TaskState.EditValue.ToString() == "1") { lookUp_Color.EditValue = ""; txt_VINInput.Enabled = true; txt_VINInput.Focus(); //this.txt_VINInput.EditValueChanged += new System.EventHandler(InputValueChanged); } else if (lookUp_TaskState.EditValue.ToString() == "5") { lookUp_Color.EditValue = ""; txt_VINInput.Enabled = true; txt_VINInput.Focus(); } else if (lookUp_TaskState.EditValue.ToString() == "6") { txt_VINInput.Enabled = true; txt_VINInput.Focus(); // txt_ModelInput.Enabled = true; lookUp_Color.Enabled = true; txt_VINInput.EditValueChanged += txt_VINInput_EditValueChanged; } else { return; } } private void ResetVervity() { bNeedVerify = true; lookUp_TaskState.EditValue = ""; } #endregion #region 控件方法 private void BindData() { List list = BLLFactory.Instance.GetAll(); gridControl.DataSource = list; label_PageInfo.Text = string.Format("共 {0} 条记录", list.Count); } private void BindData_SetPointer(string vinInput) { List list = BLLFactory.Instance.GetAll(); gridControl.DataSource = list; label_PageInfo.Text = string.Format("共 {0} 条记录", list.Count); MoMtocData moMtocData = BLLFactory.Instance.FindPointerModel(txt_VINInput.Text); if (moMtocData == null) { DevExpress.XtraEditors.XtraMessageBox.Show($"当前输入车号 {txt_VINInput.Text} 未下载AS400数据,请先下载数据!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SysEnvironment.Global_Scanning_Pointer = vinInput; redis.Publish(SysEnvironment.redis_Scanning_Pointer, SysEnvironment.Global_Scanning_Pointer); } private void timerRefresh_Tick(object sender, EventArgs e) { // if (!IsActive) return; BindData(); } private void SubScribeEnent() { //扫码工位标签值 redis.Subscribe(SysEnvironment.redis_Scanning_Pointer, new Action(ScanningPointerChange)); redis.Subscribe(SysEnvironment.redis_Scanning_HeadCode, new Action(ScanningHeadcodeChange)); redis.Subscribe(SysEnvironment.redis_Scanning_FEMCode, new Action(ScanningFEMCodeChange)); redis.Subscribe(SysEnvironment.redis_ScanningMatchRes, new Action(ShowMatchResult)); //拧紧工位标签值 redis.Subscribe(SysEnvironment.redis_Tighting_Pointer, new Action(TightingPointerChange)); redis.Subscribe(SysEnvironment.redis_Tighting_Model, new Action(TightingModelChange)); redis.Subscribe(SysEnvironment.redis_Tighting_Color, new Action(TightingColorChange)); redis.Subscribe(SysEnvironment.redis_ScannerBlock, new Action(ScannerBlockChange)); // redis.Subscribe(SysEnvironment.redis_Tighting_HeadCode, new Action(TightingHeadCodeChange)); // redis.Subscribe(SysEnvironment.redis_Tighting_FEMCode, new Action(TightingFEMCodeChange)); } private void ScanningPointerChange(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { ScanningPointerChange(channel, message); })); return; } lbl_Scanning_Pointer.Text = message.ToString(); } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void ShowMatchResult(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { ShowMatchResult(channel, message); })); return; } if (message.ToString() == "1") { lbl_Scanning_MatchRes.Text = "匹配成功"; lbl_Scanning_MatchRes.ForeColor = Color.Green; } else if (message.ToString() == "0") { lbl_Scanning_MatchRes.Text = "匹配失败"; lbl_Scanning_MatchRes.ForeColor = Color.Red; } else if (message.ToString() == "-1") { lbl_Scanning_MatchRes.Text = "空车架/插车"; lbl_Scanning_MatchRes.ForeColor = Color.Orange; } else if (message.ToString() == "-2") { lbl_Scanning_MatchRes.Text = "匹配中···";//扫码未完成状态 lbl_Scanning_MatchRes.ForeColor = Color.Black; } else if (message.ToString() == "-3") { lbl_Scanning_MatchRes.Text = "";//未连锁状态 lbl_Scanning_MatchRes.ForeColor = Color.Black; } else { lbl_Scanning_MatchRes.Text = "??"; lbl_Scanning_MatchRes.ForeColor = Color.Red; } } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void TightingPointerChange(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { TightingPointerChange(channel, message); })); return; } lbl_Tighting_Pointer.Text = message; } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void TightingModelChange(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { TightingModelChange(channel, message); })); return; } lbl_TightingModel.Text = SmProject.TaskModelDisplay(message); } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void TightingColorChange(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { TightingColorChange(channel, message); })); return; } lbl_TightingColor.Text = SmProject.TaskColorDisplay(message); } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void ScanningHeadcodeChange(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { ScanningHeadcodeChange(channel, message); })); return; } lbl_Scanning_HeadCode.Text = message;//缓存获取 } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void ScanningFEMCodeChange(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { ScanningFEMCodeChange(channel, message); })); return; } lbl_ScanningFEMCode.Text = message;//缓存获取 } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void ScannerBlockChange(RedisChannel channel, RedisValue message) { try { if (InvokeRequired) { BeginInvoke(new Action(() => { ScannerBlockChange(channel, message); })); return; } if (bool.Parse(message.ToString())) lbl_ScannerBlock.Text = "扫码阻塞"; else lbl_ScannerBlock.Text = ""; } catch (Exception ex) { LogHelper.log.Error($"标签值订阅异常:{ex.Message}"); } } private void GridView_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e) { if (gridView.DataSource == null) return; Color foreColor = Color.Brown; Color backColor = Color.LightGreen; //Change the foreground and background colors of selected rows. if (e.RowHandle == ((List)gridView.DataSource).FindIndex(c => c.Vin == SysEnvironment.Global_Scanning_Pointer)) { e.Appearance.ForeColor = foreColor; e.Appearance.BackColor = backColor; /* This property controls whether settings of the RowStyle event have a higher priority than the appearances specified by the GridViewAppearances.EvenRow and GridViewAppearances.OddRow properties. */ e.HighPriority = true; // gridView.FocusedRowHandle = e.RowHandle; if (e.RowHandle > 23) BLLFactory.Instance.AutoDelete(SysEnvironment.Global_Scanning_Pointer); // gridView.TopRowIndex = index;//不要这行 } } private void gridView_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } private void gridView_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo gridHitInfo = new DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo(); Point point = new Point(e.X, e.Y); gridHitInfo = (sender as GridView).CalcHitInfo(point); if (gridHitInfo.Column == null) return; //--获取单元格内容 string copiedData = (sender as GridView).GetRowCellDisplayText(gridHitInfo.RowHandle, gridHitInfo.Column); if (string.IsNullOrEmpty(copiedData)) return; //--复制到剪贴板 Clipboard.Clear(); Clipboard.SetData(DataFormats.Text, copiedData); } if (e.Button == MouseButtons.Left && e.Clicks == 2) { //if (!SysEnvironment.sign_OrderStop)//先判断是不是预约停止模式 //{ // DevExpress.XtraEditors.XtraMessageBox.Show($"当前非预约停止状态,禁止切换任务", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} if (bNeedVerify)//判断是不是有操作权限 { FormUserVerification form = new FormUserVerification(); form.ShowDialog(); if (form.DialogResult != DialogResult.OK) return; else bNeedVerify = false; } DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hInfo = gridView.CalcHitInfo(new Point(e.X, e.Y)); if (hInfo.InRow)//判断光标是否在行范围内 { //获取这个行的vin object dr = gridView.GetRow(hInfo.RowHandle); if (dr == null) return; string svin = ((MoMtocData)dr).Vin.ToString(); if (DevExpress.XtraEditors.XtraMessageBox.Show($"{svin}\n\n设置为扫码工位指针?\n\n", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { LogHelper.log.Info($"【双击调整指针】按钮按下: {SysEnvironment.Global_Scanning_Pointer} -> {svin}"); SysEnvironment.Global_Scanning_Pointer = svin; redis.Publish(SysEnvironment.redis_Scanning_Pointer, SysEnvironment.Global_Scanning_Pointer); } } } } private void txt_VIN_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { btn_Check_RecoverProduce_Click(sender, e); } } private void btn_Check_RecoverProduce_Click(object sender, EventArgs e) { if (lookUp_TaskState.EditValue.ToString() == "") { return; } txt_VINInput.Text = txt_VINInput.Text.Trim(); if (!SysEnvironment.CheckVINRule(txt_VINInput.Text)) { DevExpress.XtraEditors.XtraMessageBox.Show($"当前输入车号不符合规则校验!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { Cursor = Cursors.WaitCursor; LogHelper.log.Info($"【{lookUp_TaskState.Text.Trim()}--操作确认】按钮按下: 当前指针{SysEnvironment.Global_Scanning_Pointer}"); if (lookUp_TaskState.EditValue.ToString() == "1") { SysEnvironment.LastPostResult = new string[10] { "", "", "", "", "", "", "", "", "", "" };//初始化POST结果缓存 BLLFactory.Instance.TruncateTable(); //清空本地数据表 this.btn_Check_RecoverProduce.Text = "远程读取中..."; GetAS400DataJob getAS400DataJob = new GetAS400DataJob(); bool bres = getAS400DataJob.GetAS400(txt_VINInput.Text); if (!bres) { DevExpress.XtraEditors.XtraMessageBox.Show($"无法查询到车号 {txt_VINInput.Text},请确认AS400数据库是否存在此数据", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DevExpress.XtraEditors.XtraMessageBox.Show($"下载完成!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); BindData_SetPointer(txt_VINInput.Text); } else if (lookUp_TaskState.EditValue.ToString() == "5") { MoMtocData moMtocData = BLLFactory.Instance.FindPointerModel(txt_VINInput.Text); if (moMtocData == null) { DevExpress.XtraEditors.XtraMessageBox.Show($"当前输入车号 {txt_VINInput.Text} 未下载AS400数据,请先下载数据!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SysEnvironment.Global_Scanning_Pointer = txt_VINInput.Text; redis.Publish(SysEnvironment.redis_Scanning_Pointer, SysEnvironment.Global_Scanning_Pointer); } else if (lookUp_TaskState.EditValue.ToString() == "6") { if (lookUp_Color.EditValue.ToString() == "") { DevExpress.XtraEditors.XtraMessageBox.Show($"请选择颜色", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } short model = Convert.ToInt16(txt_ModelInput.Text); short color = Convert.ToInt16(lookUp_Color.Text); btn_Check_RecoverProduce.Text = "写入PLC..."; manualForceWrite2Tighting(model, color, txt_VINInput.Text); } } catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show($"操作失败:\n{ex.Message}", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { Cursor = Cursors.Default; btn_Check_RecoverProduce.Text = "操作确认"; txt_VINInput.Focus(); } } private void lbl_headCode_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { //--复制到剪贴板 Clipboard.Clear(); Clipboard.SetData(DataFormats.Text, lbl_Scanning_HeadCode.Text); } if (e.Button == MouseButtons.Left && e.Clicks == 2) { DevExpress.XtraEditors.XtraMessageBox.Show($"当前车头扫码结果队列:\n{PrintQueue(MXComponent_FEM02.SuperQueueScanner.HeadScanQueue)}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void lbl_femCode_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { //--复制到剪贴板 Clipboard.Clear(); Clipboard.SetData(DataFormats.Text, lbl_ScanningFEMCode.Text); } if (e.Button == MouseButtons.Left && e.Clicks == 2) { DevExpress.XtraEditors.XtraMessageBox.Show($"当前FEM扫码结果队列:\n{PrintQueue(MXComponent_FEM02.SuperQueueScanner.FEMScanQueue)}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void lbl_vincode_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { //--复制到剪贴板 Clipboard.Clear(); Clipboard.SetData(DataFormats.Text, lbl_Scanning_Pointer.Text); } } private void labelControl2_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && e.Clicks == 2) { if (!CheckIdentify()) return; if (MXComponent_FEM02.SkipHeadScan) { if (DevExpress.XtraEditors.XtraMessageBox.Show($"开启车头扫码", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) return; } else { if (DevExpress.XtraEditors.XtraMessageBox.Show($"关闭车头扫码", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) return; } MXComponent_FEM02.SkipHeadScan = !MXComponent_FEM02.SkipHeadScan; SetHeadScannerlabel(); string message = MXComponent_FEM02.SkipHeadScan ? "关闭" : "开启"; DevExpress.XtraEditors.XtraMessageBox.Show($"车头扫码已{message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void labelControl3_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && e.Clicks == 2) { if (!CheckIdentify()) return; if (MXComponent_FEM02.SkipFEMScan) { if (DevExpress.XtraEditors.XtraMessageBox.Show($"开启FEM扫码", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) return; } else { if (DevExpress.XtraEditors.XtraMessageBox.Show($"关闭FEM扫码", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes) return; } MXComponent_FEM02.SkipFEMScan = !MXComponent_FEM02.SkipFEMScan; SetFEMScannerlabel(); string message = MXComponent_FEM02.SkipFEMScan ? "关闭" : "开启"; DevExpress.XtraEditors.XtraMessageBox.Show($"FEM扫码已{message}", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void SetHeadScannerlabel() { lbl_HeadScanner.BackColor = MXComponent_FEM02.SkipHeadScan ? Color.LightGray : Color.White; } private void SetFEMScannerlabel() { lbl_FEMScanner.BackColor = MXComponent_FEM02.SkipFEMScan ? Color.LightGray : Color.White; } private void gridView_PLC_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (e.Column.FieldName == "Model") { e.DisplayText = SmProject.ModelDisplayFieldText(e.Value.ToString().Trim()); } if (e.Column.FieldName == "Color") { e.DisplayText = SmProject.ColorDisplayFieldText(e.Value.ToString().Trim()); } } #endregion #region 私有方法 private string PrintQueue(Queue list) { //Console.WriteLine("开始打印队列"); string ss = ""; foreach (string str in list) { ss += str + "\n"; } return ss; } #endregion private void btn_ForceMatch_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(SysEnvironment.Global_Scanning_Pointer)) { DevExpress.XtraEditors.XtraMessageBox.Show($"当前扫码指针为空,请先调整指针", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } MoMtocData task = BLLFactory.Instance.FindPointerModel(SysEnvironment.Global_Scanning_Pointer); if (task == null) { DevExpress.XtraEditors.XtraMessageBox.Show($"当前指针 {SysEnvironment.Global_Scanning_Pointer}未下载数据,请先下载数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (DevExpress.XtraEditors.XtraMessageBox.Show($"是否确认当前扫码工位来车为\n\n{SysEnvironment.Global_Scanning_Pointer}", "强制匹配", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { LogHelper.log.Info($"【匹配指针】按钮按下: 当前指针{SysEnvironment.Global_Scanning_Pointer}"); manualForceMatchSuccess(); } } public delegate void delegateResetVertify2(); public static event delegateResetVertify2 manualForceMatchSuccess; public static event delegateResetVertify2 manualForceReleaseEmpty; public delegate void delegateResetVertify3(short model, short color, string vin); public static event delegateResetVertify3 manualForceWrite2Tighting; private void btn_ReleaseEmpty_Click(object sender, EventArgs e) { if (DevExpress.XtraEditors.XtraMessageBox.Show($"是否强制放行?\n\n当前车头扫码结果:{SysEnvironment.Global_Scanning_HeadCode}", "强制放行", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { LogHelper.log.Info($"【强制放行】按钮按下: 当前指针{SysEnvironment.Global_Scanning_Pointer}"); manualForceReleaseEmpty(); } } private void txt_VINInput_EditValueChanged(object sender, EventArgs e) { if (SysEnvironment.CheckVINRule(txt_VINInput.Text)) { string model = txt_VINInput.Text.Substring(3, 2); txt_ModelInput.Text = SmProject.ListModelContrast.Find(p => p.Model_Code.ToString() == model).PLC_Code.ToString(); } } private void txt_VINInput_Click(object sender, EventArgs e) { txt_VINInput.SelectAll(); } private bool CheckIdentify() { if (bNeedVerify) { FormUserVerification form = new FormUserVerification(); form.ShowDialog(); if (form.DialogResult != DialogResult.OK) { lookUp_TaskState.EditValue = ""; return false; } else bNeedVerify = false; } return true; } } }