private void btn_save_Click(object sender, RoutedEventArgs e) { string trcode = tb_code.Text; string trname = tb_name.Text; if (truckId == 0) { TruckInfo trInfo = new TruckInfo() { Createtime = DateTime.Now, Isvalid = 1, Updatetime = DateTime.Now }; trInfo.Truckcode = trcode; trInfo.Truckname = trname; x_tService.Insert(trInfo); } else { x_tService.Update(() => new TruckInfo() { Truckcode = trcode, Truckname = trname }, a => a.Id == truckId); } tb_code.Text = ""; tb_name.Text = ""; MsgBox.Show("保存成功"); if (win_trIndex != null && win_trIndex.IsVisible) { win_trIndex.InitData(); } }
private void btn_reset_Click(object sender, RoutedEventArgs e) { int i = 0; var routeItem = x_rtService.Get(a => a.IsValid == 1 && a.Isstart == 2 && a.HouseId == MainWindow.HouseId).FirstOrDefault(); string routecode = ""; if (routeItem != null) { routecode = routeItem.Routecode; } foreach (TruckInfo item in dataGrid1.Items) { if (item.IsChecked) { i += x_tService.Update(() => new TruckInfo() { Truckstatus = 0, TruckrouteCode = routecode }, a => a.Id == item.Id); } } MsgBox.Show("成功复位了" + i + "个叉车"); InitData(dataPager1.PageIndex); }
public void sp_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (sp_buffer != null && (sp_buffer.Length >= sp_buffer_len || !sp_buffer.StartsWith("AA"))) //清理漏洞数据 { sp_buffer = null; } else if (sp_buffer != null && !sp_buffer.StartsWith("AAAA") && sp_buffer.Length > 2) { sp_buffer = null; } byte[] readBuffer = new byte[sp_read_len]; sp.Read(readBuffer, 0, readBuffer.Length); string readstr = HexHelper.ToHexString(readBuffer); readstr = TrimHelper.Trim(readstr, '0'); showDispatchText("info.原始指令: " + readstr); if (!CheckCRC(readstr)) { bool cangoon = false; string newstr = readstr.Substring(0, readstr.Length); for (int i = 0; i < newstr.Length; i += 2) { char a = newstr[i]; char b = newstr[i + 1]; if (a != '0' || b != '0') { string wd = string.Concat(a, b); if (sp_buffer != null && sp_buffer.StartsWith(sp_start_buf)) { if (sp_buffer.StartsWith(sp_start_buf + sp_start_buf)) { sp_buffer += wd; } else if (wd == sp_start_buf) { sp_buffer += wd; } else { sp_buffer = null; } } else if (wd == sp_start_buf) { sp_buffer = wd; } if (!string.IsNullOrEmpty(sp_buffer)) { if (CheckCRC(sp_buffer)) { cangoon = true; readstr = sp_buffer; sp_buffer = null; } } } else { break; } } if (!cangoon) { showDispatchText("error:反馈指令错误..." + readstr); return; } } TruckLogInfo log = new TruckLogInfo() { Createtime = DateTime.Now, FullCode = readstr }; List <string> list = InstructionHelper.getFromInstuct(readstr); log.Routecode = list[4]; //路径点 log.RunStatus = list[3]; //运行状态 log.Truckcode = list[2]; //叉车编号 bool needlog = false; #region 重复处理 string cacheKey = "listen_route_key" + log.FullCode; object obj = CacheManager.Instance.Get(cacheKey); if (obj != null) { List <TruckLogInfo> tList = obj as List <TruckLogInfo>; var item = tList.Where(a => a.FullCode == readstr).LastOrDefault(); if (item == null) { needlog = true; } } else { List <TruckLogInfo> tList = new List <TruckLogInfo>(); tList.Add(log); CacheManager.Instance.Set(cacheKey, tList, 0, 15); needlog = true; } #endregion if (routeShow != null && routeShow.IsVisible) { Dispatcher.Invoke(new Action(() => { routeShow.ShowTruckPosition(log.Routecode); })); } if (needlog) { x_tlService.Insert(log); if (log.RunStatus != "AA") //叉车接收到启动指令后的返回消息 { //将叉车更新为运行状态 x_tkService.Update(() => new TruckInfo() { Truckstatus = 1, TruckrouteCode = log.Routecode }, a => a.Truckcode == log.Truckcode); } else { int status = 1; if (log.RunStatus == "02") //停止指令 { status = 0; //叉车已停止运行,恢复为可用状态(暂定) } x_tkService.Update(() => new TruckInfo() { Truckstatus = status, TruckrouteCode = log.Routecode }, a => a.Truckcode == log.Truckcode); } } if (log.RunStatus == "AA") //叉车接收到启动指令后的返回消息 { showDispatchText("start.叉车已启动:" + readstr); } else { if (log.RunStatus == "01") { showDispatchText("runing.叉车运行到:" + readstr); } else { showDispatchText("stop.叉车已停止运行:" + readstr); } } }