private void btnQuery_Click(object sender, RoutedEventArgs e) //查询按键对应代码 { if (string.IsNullOrEmpty(textBox.Text)) { //if (datePickerStart.SelectedDate == null || datePickerEnd.SelectedDate == null) //{ // AutoDeleteMessageBox Auto = new AutoDeleteMessageBox(); // 自动关闭窗口 // System.Windows.Forms.MessageBox.Show("输入信息不完全!", "MessageBox"); // return; //} List <ModalWeightInfoTable> templist = new List <ModalWeightInfoTable>(); dal.QueryData(ref templist); weightDtaGrid.ItemsSource = null; weightDtaGrid.ItemsSource = templist; WeightList.Clear(); WeightList = templist; } else { if (datePickerStart.SelectedDate == null ^ datePickerEnd.SelectedDate == null) { AutoDeleteMessageBox Auto = new AutoDeleteMessageBox(); // 自动关闭窗口 System.Windows.Forms.MessageBox.Show("输入信息不完全!", "MessageBox"); return; } } List <ModalWeightInfoTable> MoList = new List <ModalWeightInfoTable>(); if (string.IsNullOrEmpty(textBox.Text) && (datePickerStart.SelectedDate != null || datePickerEnd.SelectedDate != null)) // 按日期查询 { string time1 = datePickerStart.SelectedDate.Value.ToString("yyyy-MM-dd hh:mm:ss"); string time2 = datePickerEnd.SelectedDate.Value.ToString("yyyy-MM-dd hh:mm:ss"); dal.QueryData(time1, time2, ref MoList); WeightList.Clear(); WeightList.AddRange(MoList); } if (!string.IsNullOrEmpty(textBox.Text)) //按条码查询 { if (datePickerStart.SelectedDate == null && datePickerEnd.SelectedDate == null) { dal.QueryData(Int32.Parse(textBox.Text), ref MoList); WeightList.Clear(); WeightList.AddRange(MoList); weightDtaGrid.ItemsSource = null; weightDtaGrid.ItemsSource = WeightList; } else { if ((datePickerStart.SelectedDate != null && datePickerEnd.SelectedDate != null)) { System.Windows.Forms.MessageBox.Show("条码查询和日期查询无法同时进行"); } } } }
private void ElapseSpurtSend(object Sender, ElapsedEventArgs e) { if (timerBool) { lock (timerLock) { if (timerBool) { timerBool = false; int CurrentCount = 0; //喷码枪的初始值是1 string recStr = tcputility.SendAndReceive(String.Format("GET_COUNTER_INFO 1\n")); if (recStr.Contains("ACK-GET_COUNTER_INFO")) { CurrentCount = Convert.ToInt32(recStr.Split(',')[2]); } if (CurrentCount > LastCount) //说明喷码了,或者到了时间间隔跳过了(时间大概20多秒), { List <ModalWeightInfoTable> UnSendList = new List <ModalWeightInfoTable>(); dal.QueryData(tab: 0, ref UnSendList); if (UnSendList == null || UnSendList.Count == 0) { return; } ModalWeightInfoTable moWeiht = UnSendList[0]; string str = Regex.Match(moWeiht.BodyWeight, @"([0-9].[0-9]{1,})").Value.Replace(".", ""); recStr = tcputility.SendAndReceive(String.Format("D{0}{1}\n", str.PadRight(4, '0'), new Random().Next(0, 9))); if (recStr.Contains("ACK-Auto Data Received")) //如果发送成功,记录下来 { LastCount = CurrentCount; this.Dispatcher.Invoke(() => { dal.UpData(moWeiht.Number, 1); List <ModalWeightInfoTable> templist = new List <ModalWeightInfoTable>(); dal.QueryData(ref templist); weightDtaGrid.ItemsSource = null; weightDtaGrid.ItemsSource = templist; WeightList.Clear(); WeightList = templist; SpurtList.Add(new ModalSpurtCodeInfo { Counter = CurrentCount + 1, SpurtCode = str }); SpurtDtaGrid.ItemsSource = null; SpurtDtaGrid.ItemsSource = SpurtList; }); } else { AutoDeleteMessageBox Auto = new AutoDeleteMessageBox(); // 自动关闭窗口 System.Windows.Forms.MessageBox.Show("发送喷码值失败!", "MessageBox"); return; } } timerBool = true; } } } }