/// <summary> /// 当已经配置完成后,重新再进入配置界面时,要将之前的参数赋值 /// </summary> private void InitParameter() { if (DockWindow.m_DockParameter.ContainsKey(m_DockNo)) { AgingParameter para = DockWindow.m_DockParameter[m_DockNo] as AgingParameter; int index = -1; for (int i = 0; i < cmPumpType.Items.Count; i++) { if (string.Compare(cmPumpType.Items[i].ToString(), para.PumpType, true) == 0) { index = i; break; } } if (index >= 0) { cmPumpType.SelectedIndex = index; CustomProductID cid = ProductIDConvertor.Name2CustomProductID(para.PumpType); for (int i = 0; i < cmOcclusionLevel.Items.Count; i++) { if (cid == CustomProductID.GrasebyC9) { if (string.Compare(cmOcclusionLevel.Items[i].ToString(), para.C9OclusionLevel.ToString(), true) == 0) { index = i; break; } } else { if (string.Compare(cmOcclusionLevel.Items[i].ToString(), para.OclusionLevel.ToString(), true) == 0) { index = i; break; } } } if (index >= 0) { cmOcclusionLevel.SelectedIndex = index; } } tbRate.Text = para.Rate.ToString(); tbVolume.Text = para.Volume.ToString(); tbCharge.Text = para.ChargeTime.ToString(); tbRecharge.Text = para.RechargeTime.ToString(); } }
/// <summary> /// 选择泵类型,下拉列表框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) { SinglePump pump = null; string strPumpType = string.Empty; int index = 0; CustomProductID cid = CustomProductID.Unknow; for (int i = 0; i < pumplistGrid.Children.Count; i++) { if (pumplistGrid.Children[i] is SinglePump) { pump = pumplistGrid.Children[i] as SinglePump; strPumpType = cmPumpType.Items[cmPumpType.SelectedIndex].ToString(); cid = ProductIDConvertor.Name2CustomProductID(strPumpType); InitPressureLevel(cid); if (cid == CustomProductID.GrasebyF6_Double || cid == CustomProductID.WZS50F6_Double) { if (pump.Tag != null && !string.IsNullOrEmpty(pump.Tag.ToString())) { if (int.TryParse(pump.Tag.ToString(), out index)) { if (index % 2 == 1) { pump.lbPumpType.Content = strPumpType + " 1道"; } else { pump.lbPumpType.Content = strPumpType + " 2道"; } } } pump.EnableCheckBoxClick = true; } else { pump.EnableCheckBoxClick = false; pump.lbPumpType.Content = strPumpType; } } } }
/// <summary> /// 当客户端连入时要发送泵类型信息, /// 如果用户尚未配置,则不用发,留到点开始的时候发 /// </summary> /// <param name="e"></param> private void SendPumpType2Wifi(SocketConnectArgs e) { Controller controller = ControllerManager.Instance().Get(e.ConnectedSocket); if (controller == null) { return; } int dockNo = controller.DockNo; AgingDock dock = m_DockList.Find((x) => { return(x.DockNo == dockNo); }); if (dock == null || dock.ChannelHashRowNo == null || !dock.ChannelHashRowNo.ContainsKey(controller.RowNo)) { return; } AgingParameter para = m_DockParameter[dockNo] as AgingParameter; if (para != null) { CustomProductID cid = ProductIDConvertor.Name2CustomProductID(para.PumpType); ProductID pid = ProductIDConvertor.Custom2ProductID(cid); CommandManage cmdManager = new CommandManage(); int iChannel = (int)dock.ChannelHashRowNo[controller.RowNo]; byte channel = (byte)(iChannel & 0x000000FF); //一旦收到连接,立即发送泵信息,必须要延迟10秒 if (pid == ProductID.Graseby1200En)//英文版的ID和中文的一样 { pid = ProductID.Graseby1200; } cmdManager.SendPumpType(pid, (ushort)m_QueryInterval, e.ConnectedSocket, null, channel); } else { Logger.Instance().Debug("SendPumpType2Wifi()->DefaultParameter is null"); } }
/// <summary> /// 只显示那些用户选中的泵信息 /// </summary> private void LoadDetailList() { //列表中要显示几台泵 int pumpCount = m_PumpLocationList.Count; if (pumpCount <= 0) { Logger.Instance().Info("老化泵数量等于0。"); return; } CustomProductID cid = ProductIDConvertor.Name2CustomProductID(m_Parameter.PumpType); ProductID pid = ProductIDConvertor.Custom2ProductID(cid); if (pid == ProductID.GrasebyF8) { pumpCount = pumpCount * 2;//F8则需要X2 } for (int i = 0; i < pumpCount; i++) { RowDefinition row = new RowDefinition(); row.Height = new GridLength(40); pumpListGrid.RowDefinitions.Add(row); } for (int i = 0; i < pumpCount; i++) { SingleDetail detail = new SingleDetail(); //F6,F8双道泵显示详细内容与其他泵不一样,要体现双道信息 if (cid == CustomProductID.GrasebyF6_Double || cid == CustomProductID.WZS50F6_Double) { if (m_PumpLocationList[i].Item3 % 2 == 0) { detail.lbPumpLocation.Content = string.Format("{0}-{1}-{2}(2道泵)", m_DockNo, m_PumpLocationList[i].Item2, m_PumpLocationList[i].Item3); } else { detail.lbPumpLocation.Content = string.Format("{0}-{1}-{2}(1道泵)", m_DockNo, m_PumpLocationList[i].Item2, m_PumpLocationList[i].Item3); } detail.lbPumpSN.Content = m_PumpLocationList[i].Item4; } else if (cid == CustomProductID.GrasebyF8) { if (i % 2 == 0) { detail.lbPumpLocation.Content = string.Format("{0}-{1}-{2}(1道泵)", m_DockNo, m_PumpLocationList[i / 2].Item2, m_PumpLocationList[i / 2].Item3); } else { detail.lbPumpLocation.Content = string.Format("{0}-{1}-{2}(2道泵)", m_DockNo, m_PumpLocationList[i / 2].Item2, m_PumpLocationList[i / 2].Item3); } detail.lbPumpSN.Content = m_PumpLocationList[i / 2].Item4; } else { detail.lbPumpSN.Content = m_PumpLocationList[i].Item4; detail.lbPumpLocation.Content = string.Format("{0}-{1}-{2}", m_DockNo, m_PumpLocationList[i].Item2, m_PumpLocationList[i].Item3); } detail.Name = "detail" + (i + 1).ToString(); detail.Tag = i + 1; detail.Margin = new Thickness(1, 1, 1, 1); detail.lbNo.Content = string.Format("{0}", i + 1); detail.lbPumpType.Content = m_Parameter.PumpType; detail.lbRate.Content = m_Parameter.Rate.ToString(); AgingPump AgingPump = null; if (cid == CustomProductID.GrasebyF8) { //F8双通道共用一个串口,在查找泵时需要指定通道编号从0开始 AgingPump = m_AgingPumpList.Find((x) => { return(x.DockNo == m_DockNo && x.RowNo == m_PumpLocationList[i / 2].Item2 && x.Channel == m_PumpLocationList[i / 2].Item3 && x.SubChannel == i % 2); }); } else { AgingPump = m_AgingPumpList.Find((x) => { return(x.DockNo == m_DockNo && x.RowNo == m_PumpLocationList[i].Item2 && x.Channel == m_PumpLocationList[i].Item3); }); } if (AgingPump != null) { if (AgingPump.BeginAgingTime.Year > 2000) { detail.lbAgingStartTime.Content = AgingPump.BeginAgingTime.ToString("MM-dd HH:mm:ss"); } if (AgingPump.BeginDischargeTime.Year > 2000) { detail.lbDischargeStartTime.Content = AgingPump.BeginDischargeTime.ToString("MM-dd HH:mm:ss"); } if (AgingPump.BeginLowVoltageTime.Year > 2000) { detail.lbLowVoltageStartTime.Content = AgingPump.BeginLowVoltageTime.ToString("MM-dd HH:mm:ss"); } if (AgingPump.BeginBattaryDepleteTime.Year > 2000) { detail.lbDepleteStartTime.Content = AgingPump.BeginBattaryDepleteTime.ToString("MM-dd HH:mm:ss"); } if (AgingPump.EndAgingTime.Year > 2000) { detail.lbAgingEndTime.Content = AgingPump.EndAgingTime.ToString("MM-dd HH:mm:ss"); } detail.lbAlarm.Content = AgingPump.GetAlarmString(); detail.lbAgingStatus.Content = AgingStatusMetrix.Instance().GetAgingStatus(AgingPump.AgingStatus); if (AgingPump.AgingStatus == EAgingStatus.Unknown) { Logger.Instance().InfoFormat("泵状态显示异常,为未状态开始老化时间={0}", AgingPump.BeginAgingTime.ToString()); } } else { detail.lbAgingStartTime.Content = ""; detail.lbDischargeStartTime.Content = ""; detail.lbLowVoltageStartTime.Content = ""; detail.lbDepleteStartTime.Content = ""; detail.lbAgingEndTime.Content = ""; detail.lbAlarm.Content = ""; detail.lbAgingStatus.Content = ""; } pumpListGrid.Children.Add(detail); Grid.SetRow(detail, i + 1); if (i % 2 == 0) { detail.Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0x00, 0xA2, 0xE8)); } } }
private void OnSave(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbRate.Text.Trim()) || string.IsNullOrEmpty(tbVolume.Text.Trim()) || string.IsNullOrEmpty(tbCharge.Text.Trim()) || string.IsNullOrEmpty(tbRecharge.Text.Trim()) || cmPumpType.SelectedIndex < 0 || cmOcclusionLevel.SelectedIndex < 0 ) { MessageBox.Show("请将参数填写完整"); return; } string szCustomPid = cmPumpType.Items[cmPumpType.SelectedIndex].ToString(); string szPressureLevel = cmOcclusionLevel.Items[cmOcclusionLevel.SelectedIndex].ToString(); decimal rate = Convert.ToDecimal(float.Parse(tbRate.Text).ToString("F1")); decimal volume = Convert.ToDecimal(float.Parse(tbVolume.Text).ToString("F1")); decimal charge = Convert.ToDecimal(tbCharge.Text); CustomProductID cid = ProductIDConvertor.Name2CustomProductID(szCustomPid); OcclusionLevel level = OcclusionLevel.H; C9OcclusionLevel c9Level = C9OcclusionLevel.Level3; if (cid == CustomProductID.GrasebyC9) { if (Enum.IsDefined(typeof(C9OcclusionLevel), szPressureLevel)) { c9Level = (C9OcclusionLevel)Enum.Parse(typeof(C9OcclusionLevel), szPressureLevel); } else { Logger.Instance().ErrorFormat("Configuration::OnSave()->压力转换出错,C9OcclusionLevel={0}", szPressureLevel); } } else { if (Enum.IsDefined(typeof(OcclusionLevel), szPressureLevel)) { level = (OcclusionLevel)Enum.Parse(typeof(OcclusionLevel), szPressureLevel); } else { Logger.Instance().ErrorFormat("Configuration::OnSave()->压力转换出错,OcclusionLevel={0}", szPressureLevel); } } decimal discharge = 0; decimal recharge = Convert.ToDecimal(tbRecharge.Text); Hashtable dockParameter = new Hashtable(); AgingParameter para = new AgingParameter(szCustomPid, rate, volume, charge, discharge, recharge, level, c9Level); for (int i = 0; i < otherDockCheckBoxGrid.Children.Count; i++) { if (otherDockCheckBoxGrid.Children[i] is CheckBox) { CheckBox box = otherDockCheckBoxGrid.Children[i] as CheckBox; if (box.IsChecked.HasValue) { if (box.IsChecked == true) { dockParameter.Add((int)box.Tag, new AgingParameter(para)); //这里需要拷贝一份新的参数 } } } } if (OnSaveConfigration != null) { OnSaveConfigration(this, new ConfigrationArgs(dockParameter)); } this.DialogResult = true; }
/// <summary> /// 当条码枪完成一次扫码,光标自动跳到下一条 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnSerialNoInputComplete(object sender, SerialNoInputArgs e) { if (m_CheckedPumpLocationList.Count <= 0) { return; } if (cmPumpType.SelectedIndex < 0) { return; } string strPumpType = cmPumpType.Items[cmPumpType.SelectedIndex].ToString(); CustomProductID cid = ProductIDConvertor.Name2CustomProductID(strPumpType); int index = m_CheckedPumpLocationList.FindIndex((x) => { return(e.PumpLocation == x); }); if (index >= 0 && index + 1 < m_CheckedPumpLocationList.Count) { if (cid == CustomProductID.GrasebyF6_Double || cid == CustomProductID.WZS50F6_Double) { #region SinglePump pump = null; //第一道泵序列号与第二道 一样 if (index % 2 == 0) { if (m_CheckedPumpLocationList.Count > index + 1) { pump = FindPumpByLocation(m_CheckedPumpLocationList[index + 1]); if (pump != null) { pump.SetSerialNo(e.SerialNo); } } if (m_CheckedPumpLocationList.Count > index + 2) { //光标跳到下一个泵 pump = FindPumpByLocation(m_CheckedPumpLocationList[index + 2]); if (pump != null) { pump.SetCursor(); } } } else { if (m_CheckedPumpLocationList.Count > index - 1) { pump = FindPumpByLocation(m_CheckedPumpLocationList[index - 1]); if (pump != null) { pump.SetSerialNo(e.SerialNo); } } //光标跳到下一个泵 if (m_CheckedPumpLocationList.Count > index + 1) { pump = FindPumpByLocation(m_CheckedPumpLocationList[index + 1]); if (pump != null) { pump.SetCursor(); } } } #endregion } else { SinglePump pump = FindPumpByLocation(m_CheckedPumpLocationList[index + 1]); if (pump != null) { pump.SetCursor(); } } } }