private void ShowEdit() { var t = TerminalInstance.Find(f => f.id == ParseInt(Utility.Decrypt(hidID.Value))); if (null != t) { txtNumber.Value = t.Number; //txtSatellite.Value = t.Satellite; txtSimcard.Value = t.Sim; if (t.Type == TerminalTypes.DX) { _dx_normal.Checked = true; } else if (t.Type == TerminalTypes.DXE) { _dx.Checked = true; } else { _ld.Checked = true; } } else { ShowNotification("./terminal_list.aspx", "Error: Cannot edit null object of Terminal.", false); } }
/// <summary> /// 处理数据并更新终端和设备的状态 /// </summary> /// <param name="obj"></param> private void HandleDataStatus(TX300 obj) { var sim = GetSimFromData(obj); var terminal = TerminalInstance.Find(f => f.Sim.Equals(sim)); if (null == terminal) { return; } var equipment = EquipmentInstance.Find(f => f.TB_Terminal.Sim.Equals(sim) && f.Deleted == false); HandleOnline(sim, obj.CommandID); SaveTX300History(obj, (null == equipment ? "" : EquipmentInstance.GetFullNumber(equipment))); // 卫星数据只有0x1000和0x6007(0x6007会有0xEE00存在)两种 switch (obj.CommandID) { case 0x1000: Handle0x1000(obj, equipment); break; case 0x6007: Handle0x6007(obj, equipment); break; case 0xEE00: Handle0xEE00(obj, equipment); // 483130433130372007600140A5 // 5831304331303530076001403F break; } }
private void NewTerminal() { TB_Terminal t = null; // 如果没有输入Sim卡号码则查询是否具有相同终端号码的记录 if (string.IsNullOrEmpty(txtSimcard.Value.Trim())) { t = TerminalInstance.Find(f => f.Number.Equals(txtNumber.Value.Trim()) && f.Delete == false); } else { // 如果有Sim卡号码输入则查询终端或Sim卡号码是否有相同记录存在 t = TerminalInstance.Find(f => (f.Number.Equals(txtNumber.Value.Trim()) || f.Sim.Equals(txtSimcard.Value.Trim())) && f.Delete == false); } if (null != t) { ShowNotification("./terminal_register.aspx", "Terminal exist: " + TerminalInstance.ToString(t), false); } else { t = TerminalInstance.GetObject(); BuildObject(t); TerminalInstance.Add(t); SaveHistory(new TB_AccountHistory { ActionId = ActionInstance.Find(f => f.Name.Equals("AddTerminal")).id, ObjectA = TerminalInstance.ToString(t) }); ShowNotification("./terminal_list.aspx", "You added a new terminal: " + TerminalInstance.ToString(t)); } }
private void EditTerminal() { var id = ParseInt(Utility.Decrypt(hidID.Value)); var t = TerminalInstance.Find(f => (f.Number.Equals(txtNumber.Value.Trim()) || f.Sim.Equals(txtSimcard.Value.Trim())) && f.id != id && f.Delete == false); if (null == t) { t = TerminalInstance.Find(f => f.id == ParseInt(Utility.Decrypt(hidID.Value))); if (null != t) { BuildObject(t); Update(t); SaveHistory(new TB_AccountHistory { ActionId = ActionInstance.Find(f => f.Name.Equals("EditTerminal")).id, ObjectA = TerminalInstance.ToString(t) }); ShowNotification("./terminal_list.aspx", "You changed terminal: " + TerminalInstance.ToString(t)); } else { ShowNotification("./terminal_list.aspx", "Error: Cannot edit null object of Terminal.", false); } } else { ShowNotification("./terminal_register.aspx?key=" + Utility.UrlEncode(hidID.Value), "Error: New terminal number or sim card number has exists: " + TerminalInstance.ToString(t), false); } }
/// <summary> /// 根据TX300数据包更新终端和设备的在线状态 /// </summary> /// <param name="tx300"></param> private void HandleTX300Status(TX300 tx300, AsyncUserDataBuffer data) { var sim = GetSimFromData(tx300); var equipment = EquipmentInstance.Find(f => f.TB_Terminal.Sim.Equals(sim)); var terminal = TerminalInstance.Find(f => f.Sim.Equals(sim)); // 终端不存在的话,不用再继续处理数据了 if (null == terminal) { return; } HandleOnline(sim, tx300.CommandID, data); if (tx300.CommandID != 0xAA00) { SaveTX300History(tx300, data.ReceiveTime, (null == equipment ? "" : EquipmentInstance.GetFullNumber(equipment))); // TX10G的数据 if (tx300.CommandID == 0x7010 || tx300.CommandID == 0x7020 || tx300.CommandID == 0x7030) { HandleTX10G(tx300, data); } else { // 根据命令的不同处理各个命令详情 HandleCommand(tx300, equipment, terminal); } } }
protected void btnSatelliteStopping_Click(object sender, EventArgs e) { var value = hidBoundSatellite.Value.Trim(); if (string.IsNullOrEmpty(value)) { ShowNotification("./terminal_list.aspx", "Cannot find object with null parameter.", false); } else { var id = int.Parse(value); var terminal = TerminalInstance.Find(f => f.id == id); if (null == terminal) { ShowNotification("./terminal_list.aspx", "Terminal is not exist.", false); } else { // 更新终端的连接为卫星停止状态 TerminalInstance.Update(f => f.id == terminal.id, act => { act.OnlineStyle = (byte)LinkType.SATELLITE_STOP; }); // 更新设备的连接为卫星停止状态 EquipmentInstance.Update(f => f.Terminal == terminal.id, act => { act.OnlineStyle = (byte)LinkType.SATELLITE_STOP; }); ShowNotification("./terminal_list.aspx", "You have stopped satellite " + terminal.TB_Satellite.CardNo, true); } } }
protected void btUnbindEquipment_Click(object sender, EventArgs e) { var value = hidBoundSatellite.Value.Trim(); if (string.IsNullOrEmpty(value)) { return; } var id = int.Parse(value); var terminal = TerminalInstance.Find(f => f.id == id); if (null == terminal) { return; } var equipment = EquipmentInstance.Find(f => f.Terminal == id && f.Deleted == false); // 更新设备的终端为空并清空设备的相应值 EquipmentInstance.Update(f => f.Terminal == id && f.Deleted == false, act => { act.Terminal = (int?)null; act.GpsAddress = ""; act.LastAction = ""; act.LastActionBy = ""; act.LastActionTime = (DateTime?)null; act.Latitude = 0.0; act.Longitude = 0.0; act.OnlineStyle = (byte?)null; act.OnlineTime = (DateTime?)null; act.Runtime = 0; act.Socket = 0; act.Port = 0; act.IP = ""; act.LockStatus = "00"; act.Rpm = 0; act.Signal = 0; act.Voltage = "G0000"; }); // 更新终端的绑定状态为false TerminalInstance.Update(f => f.id == id, act => { act.HasBound = false; }); // 保存解绑终端历史 SaveHistory(new TB_AccountHistory() { ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id, ObjectA = "unbind terminal " + terminal.Number + " and equipment " + EquipmentInstance.GetFullNumber(equipment) }); ShowNotification("./terminal_list.aspx", "You have unbind the terminal and equipment."); }
protected void bt_Test_Click(object sender, EventArgs e) { if (!HasSessionLose) { if ("" != hidID.Value) { var id = int.Parse(Utility.Decrypt(hidID.Value)); var terminal = TerminalInstance.Find(f => f.id == id && f.Delete == false); if (null != terminal) { if (terminal.HasBound.Value == false) { ShowNotification("./terminal_list.aspx", "No equipment bind on this terminal.", false); } else { var test = StatusInstance.Find(f => f.IsItTesting == true); if (null == test) { ShowNotification("Situation code is not exist.", "", false); } else { var equip = terminal.TB_Equipment.FirstOrDefault(); if (null != equip) { EquipmentInstance.Update(f => f.id == equip.id, act => { act.Status = StatusInstance.Find(f => f.IsItTesting == true).id; }); SaveHistory(new TB_AccountHistory { ActionId = ActionInstance.Find(f => f.Name.Equals("EditTerminal")).id, ObjectA = EquipmentInstance.GetFullNumber(equip) + ", " + terminal.Number + ", set to test mode" }); ShowNotification("./terminal_list.aspx", EquipmentInstance.GetFullNumber(equip) + ", " + terminal.Number + ", set to test mode"); } else { ShowNotification("./terminal_list.aspx", "No equipment bind on this terminal.", false); } } } } else { ShowNotification("./terminal_list.aspx", "Terminal is not exist.", false); } } } }
/// <summary> /// 解绑终端和卫星模块 /// </summary> private void UnboundSatellite() { var id = int.Parse(hidBoundSatellite.Value.Trim()); var t = TerminalInstance.Find(f => f.id == id); if (null == t) { ShowNotification("./terminal_list.aspx", "Unbind fail: Terminal not exists.", false); } else { if ((int?)null == t.Satellite) { ShowNotification("./terminal_list.aspx", "Unbind fail: No Satellite bound on it.", false); } else { string satno = t.TB_Satellite.CardNo; TerminalInstance.Update(f => f.id == t.id, act => { act.Satellite = (int?)null; // 更新终端的链接为OFF if (act.OnlineStyle == (byte)LinkType.SATELLITE) { act.OnlineStyle = (byte?)null; } // 更新卫星功能为false act.SatelliteStatus = false; }); // 更新设备的链接为OFF EquipmentInstance.Update(f => f.Terminal == t.id, act => { if (act.OnlineStyle == (byte)LinkType.SATELLITE) { act.OnlineStyle = (byte?)null; } act.SatelliteStatus = false; }); SatelliteInstance.Update(f => f.id == t.Satellite, act => { act.Bound = false; }); // 发送解绑卫星模块的命令 SendDD02Command(false, t); SaveHistory(new TB_AccountHistory() { ActionId = ActionInstance.Find(f => f.Name.Equals("UnbindSat")).id, ObjectA = "Ter: " + t.Number + " unbind Sat: " + satno }); ShowNotification("./terminal_list.aspx", "Ter: " + t.Number + " unbind Sat: " + satno + " OK!"); } } }
/// <summary> /// 显示已选择的终端的信息 /// </summary> private void ShowTerminalInfo() { var id = int.Parse(Utility.Decrypt(hidTerminalId.Value)); var terminal = TerminalInstance.Find(f => f.id == id); if (null == terminal) { ShowNotification("./terminal_list.aspx", "Error: terminal not exist.", false); } else { hiddenType.Value = terminal.Type.Value.ToString(); terType.InnerText = Wbs.Protocol.TerminalTypes.GetTerminalType(terminal.Type.Value); terminalinfo.Rows[1].Cells[1].InnerText = terminal.Number; terminalinfo.Rows[1].Cells[3].InnerText = terminal.Sim; terminalinfo.Rows[1].Cells[5].InnerText = (int?)null == terminal.Satellite ? "-" : terminal.TB_Satellite.CardNo; terminalinfo.Rows[2].Cells[1].InnerText = terminal.Firmware; terminalinfo.Rows[2].Cells[3].InnerText = (DateTime?)null == terminal.OnlineTime ? "-" : terminal.OnlineTime.Value.ToString("yyyy/MM/dd HH:mm:ss"); terminalinfo.Rows[2].Cells[5].InnerHtml = Utility.GetOnlineStyle(terminal.OnlineStyle, terminal.OnlineTime, false); } }
private void BindEquipment(int terminal, int equipment) { var ter = TerminalInstance.Find(f => f.id == terminal); if (null == ter) { ShowNotification("./terminal_list.aspx", "Error: Cannot find the terminal.", false); return; } else if (ter.HasBound == true) { ShowNotification("./terminal_list.aspx", "Error: The terminal \"" + ter.Number + "\" has been bound before this time.", false); return; } var equ = EquipmentInstance.Find(f => f.id == equipment && f.Deleted == false); if (null == equ) { ShowNotification("./terminal_list.aspx", "Error: Cannot find the equipment.", false); return; } else if (equ.Terminal > 0) { ShowNotification("./terminal_list.aspx", "Error: The equipment \"" + EquipmentInstance.GetFullNumber(equ) + "\" has bound an other terminal: \"" + equ.TB_Terminal.Number + "\".", false); return; } // 开始绑定流程 var storage = StatusInstance.Find(f => f.IsItInventory == true); EquipmentInstance.Update(f => f.id == equ.id && f.Deleted == false, act => { act.Terminal = ter.id; // 更新设备的相应信息为终端的信息 act.OnlineStyle = ter.OnlineStyle; act.OnlineTime = ter.OnlineTime; act.Socket = ter.Socket; // 新品等待入库的,绑定终端之后直接确定为库存状态 act.Status = storage.id; }); TerminalInstance.Update(f => f.id == ter.id, act => { act.HasBound = true; }); // 保存入库信息 var history = StoreInstance.GetObject(); history.Equipment = equ.id; history.Status = storage.id; history.Stocktime = DateTime.Now; // 绑定终端时,入库次数不变 history.StoreTimes = equ.StoreTimes; history.Warehouse = equ.Warehouse; StoreInstance.Add(history); // 保存操作历史记录 SaveHistory(new TB_AccountHistory() { ActionId = ActionInstance.Find(f => f.Name.Equals("Bind")).id, ObjectA = "bind equipment " + EquipmentInstance.GetFullNumber(equ) + " and terminal " + ter.Number }); ShowNotification("./terminal_list.aspx", "You have bound \"" + ter.Number + "\" on equipment \"" + EquipmentInstance.GetFullNumber(equ) + "\""); }
protected void btBoundSatellite_Click(object sender, EventArgs e) { var value = hidBoundSatellite.Value.Trim(); if (string.IsNullOrEmpty(value)) { return; } // 为终端绑定卫星模块 var index = value.IndexOf(','); if (index < 0) { // 没有,分割的是解绑卫星模块 UnboundSatellite(); return; } var tid = value.Substring(0, index); var gid = value.Substring(index + 1); gid = Utility.Decrypt(gid); var t = TerminalInstance.Find(f => f.id == int.Parse(tid)); if (null == t) { ShowNotification("./terminal_list.aspx", "Bound fail: Terminal not exists.", false); } else { if (t.Satellite != (int?)null) { ShowNotification("./terminal_list.aspx", "Terminal \"" + t.Number + "\" has bound Satellite: " + t.TB_Satellite.CardNo, false); } else { var g = SatelliteInstance.Find(f => f.id == int.Parse(gid)); if (null == g) { ShowNotification("./terminal_list.aspx", "No Satellite info exists.", false); } else { if (g.Bound == true) { var gt = TerminalInstance.Find(f => f.TB_Satellite.id == g.id); ShowNotification("./terminal_list.aspx", "Satellite \"" + g.CardNo + "\" has bound on Terminal: " + gt.Number, false); } else { TerminalInstance.Update(f => f.id == t.id, act => { act.Satellite = g.id; }); t = TerminalInstance.Find(f => f.id == t.id); SatelliteInstance.Update(f => f.id == g.id, act => { act.Bound = true; }); // 发送绑定卫星模块的命令 SendDD02Command(true, t); // 保存绑定卫星模块的历史记录 SaveHistory(new TB_AccountHistory() { ActionId = ActionInstance.Find(f => f.Name.Equals("BindSat")).id, ObjectA = TerminalInstance.ToString(t) }); //ShowTerminals(); ShowNotification("./terminal_list.aspx", "Terminal \"" + t.Number + "\" bound Satellite \"" + g.CardNo + "\" OK!"); } } } } }
/// <summary> /// 保存设备的更改信息 /// </summary> private void SaveChanges() { var id = ParseInt(Utility.Decrypt(_key)); var equipment = EquipmentInstance.Find(f => f.id == id && f.Deleted == false); bool needSave = false; string msg = ""; int wh = 0, md = 0; if (null != equipment) { msg = EquipmentInstance.GetFullNumber(equipment); var tmp = int.Parse(hidWarehouse.Value); if (tmp > 0) { var oh = WarehouseInstance.Find(f => f.id == equipment.Warehouse); var nh = WarehouseInstance.Find(f => f.id == tmp && f.Delete == false); msg += ", " + oh.Name + " to " + nh.Name; //equipment.Warehouse = tmp; wh = tmp; needSave = true; } tmp = int.Parse(selectedModel.Value); if (tmp > 0) { var om = ModelInstance.Find(f => f.id == equipment.Model); var nm = ModelInstance.Find(f => f.id == tmp && f.Delete == false); msg += ", " + om.Code + " to " + nm.Code; //equipment.Model = tmp; md = tmp; needSave = true; } tmp = int.Parse(hidFunctional.Value); if (tmp != 0 && tmp != int.Parse(oldFunc.Value)) { msg += ", " + Utility.GetEquipmentFunctional(equipment.Functional.Value) + " to " + Utility.GetEquipmentFunctional((byte)tmp); equipment.Functional = (byte)tmp; needSave = true; } var num = number.Value.Trim(); if (!string.IsNullOrEmpty(num)) { if (!num.Equals(equipment.Number)) { msg += ", Number: " + equipment.Number + " to " + num; equipment.Number = num; needSave = true; } } //tmp = int.Parse(Utility.Decrypt(Utility.UrlDecode(oldTerminal.Value))); var n = string.IsNullOrEmpty(newTerminal.Value) ? 0 : int.Parse(Utility.Decrypt(Utility.UrlDecode(newTerminal.Value))); TB_Terminal newOne = null; if (n > 0) { msg += ", Terminal: "; // 更新旧终端为未绑定状态 if ((int?)null != equipment.Terminal) { var ter = equipment.TB_Terminal.Number; TerminalInstance.Update(f => f.id == equipment.Terminal, act => { act.HasBound = false; }); // 保存旧终端的解绑状态 SaveHistory(new TB_AccountHistory() { ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id, ObjectA = "unbind terminal " + ter + " and equipment " + EquipmentInstance.GetFullNumber(equipment) }); msg += ter + "(unbind) to "; } newOne = TerminalInstance.Find(f => f.id == n); msg += newOne.Number + "(bind)"; equipment.Terminal = n; // 更新新终端的绑定状态 TerminalInstance.Update(f => f.id == n, act => { act.HasBound = true; }); // 保存新终端的绑定状态 SaveHistory(new TB_AccountHistory() { ActionId = ActionInstance.Find(f => f.Name.Equals("Unbind")).id, ObjectA = "bind terminal " + newOne.Number + " and equipment " + EquipmentInstance.GetFullNumber(equipment) }); needSave = true; } if (needSave) { EquipmentInstance.Update(f => f.id == equipment.id && f.Deleted == false, act => { if (md > 0) { //if (act.Model != equipment.Model) act.Model = md; } if (wh > 0) { //if (act.Warehouse != equipment.Warehouse) act.Warehouse = wh; } if (!act.Number.Equals(equipment.Number)) { act.Number = equipment.Number; } if (act.Functional != equipment.Functional) { act.Functional = equipment.Functional; } if (act.Terminal != equipment.Terminal) { act.Terminal = equipment.Terminal; act.Socket = newOne.Socket; act.OnlineTime = newOne.OnlineTime; act.OnlineStyle = newOne.OnlineStyle; } }); // 保存更改设备信息的历史 SaveHistory(new TB_AccountHistory() { ActionId = ActionInstance.Find(f => f.Name.Equals("EditEquipmentInfo")).id, ObjectA = msg }); ShowNotification("./equipment_setting.aspx?key=" + Utility.UrlEncode(_key), "You have saved the equipment info.", true); } } else { ShowNotification("./equipment_setting.aspx?key=" + Utility.UrlEncode(_key), "Not found the equipment", false); } }