private void BindEquipmentList() { EquipmentBLL bll = null; List <EquipmentInfo> array = null; bll = BLLFactory.CreateBLL <EquipmentBLL>(); array = bll.GetList(); this.EQID.DataSource = array; this.EQID.DataBind(); }
/// <summary> /// 处理设备的开关机信息 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x5000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 发动机启动/关闭信息 _0x5000 x5000 = new _0x5000(); x5000.Type = obj.TerminalType; x5000.Content = obj.MsgContent; x5000.Unpackage(); HandleEquipmentRuntime(equipment, x5000.WorkTime); if (null != equipment) { string vol = format("G{0}0", ((int)Math.Floor(x5000.GeneratorVoltage * 10)).ToString("000")); using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Voltage = vol; if (x5000.GeneratorVoltage > 20.0) { // 开机的时候清空报警信息 2015/09/24 08:00 act.Alarm = ALARM; } if (x5000.GeneratorVoltage < 20) { act.Rpm = 0; } act.Runtime = equipment.Runtime; act.AccumulativeRuntime = equipment.AccumulativeRuntime; //if (x5000.WorkTime > 0) //{ // // 如果总运转时间大于等于当前服务器中保存的时间则更新,否则不更新 // if (x5000.WorkTime >= act.Runtime) // { // act.Runtime = (int)x5000.WorkTime; // } //} if (x5000.GPSInfo.Available) { act.Latitude = x5000.GPSInfo.Latitude; act.Longitude = x5000.GPSInfo.Longitude; act.GpsUpdated = false; } }); } } if (x5000.GPSInfo.Available) { SaveGpsInfo(x5000.GPSInfo, equipment, obj.TerminalID, "Eng.: " + x5000.State + GetPackageType(obj.ProtocolType)); } }
//public string[] GetBLNoList(string prefixText, int count,int Location, int Line) public string[] GetContainerListByLocLine(string prefixText, int count, string contextKey) { string[] Items = contextKey.Split('|'); EquipmentBLL oEquipmentBLL = new EquipmentBLL(); DataTable dt = oEquipmentBLL.GetContainerList(Convert.ToInt32(Items[0]), Convert.ToInt32(Items[1]), prefixText); string[] ContNos = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { ContNos[i] = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(Convert.ToString(dt.Rows[i]["CntrNo"]), Convert.ToString(dt.Rows[i]["LineID"])); } return(ContNos); }
/// <summary> /// 查询 /// </summary> /// <param name="query"></param> private void Query(string query) { tbodySummary.InnerHtml = ""; List <Work> macs = new List <Work>(); using (var bll = new EquipmentBLL()) { Expression <Func <TB_Equipment, bool> > expression = PredicateExtensions.True <TB_Equipment>(); expression = expression.And(a => a.Deleted == false && a.TB_Terminal.Version == 1); if (!string.IsNullOrEmpty(query)) { string number = query; string mode = ""; int dash = query.LastIndexOf('-'); if (dash > 0) { number = query.Substring(dash + 1); mode = query.Replace(number, ""); expression = expression.And(a => a.Number.Equals(number) && a.TB_EquipmentModel.Code.Equals(mode)); } else { expression = expression.And(a => a.Number.Equals(number)); } } var list = bll.FindList(expression); if (null != list && list.Count() > 0) { foreach (var obj in list) { macs.Add(new Work() { Id = obj.id, MacId = bll.GetFullNumber(obj), Time1 = obj.RegisterTime.Value, Time2 = DateTime.Now }); } } } // 循环统计每一个设备的计算时间 foreach (var mac in macs) { Query(mac); } }
public bool Insert(EquipmentBLL equipment_no) { bool isSuccess = false; SqlConnection conn = new SqlConnection(UserDAL.myconnstrng); try { string sql = "INSERT INTO tbl_Equipment (vehicle_no, genset_no, waterRescue_no, extrication_no, ppe_no, firstAid_no, others_no) VALUES (@vehicle_no, @genset_no, @waterRescue_no, @extrication_no, @ppe_no, @firstAid_no, @others_no)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@vehicle_no", equipment_no.Vehicle_no); cmd.Parameters.AddWithValue("@genset_no", equipment_no.Genset_no); cmd.Parameters.AddWithValue("@waterRescue_no", equipment_no.WaterRescue_no); cmd.Parameters.AddWithValue("@extrication_no", equipment_no.Extrication_no); cmd.Parameters.AddWithValue("@ppe_no", equipment_no.PPE_no); cmd.Parameters.AddWithValue("@firstAid_no", equipment_no.FirstAid_no); cmd.Parameters.AddWithValue("@others_no", equipment_no.Others_no); conn.Open(); int rows = cmd.ExecuteNonQuery(); // If the query is executed successfully then the value to rows will be greaten than 0 else it will be less than 0 if (rows > 0) { // Query successful isSuccess = true; } else { // Query failed isSuccess = false; } } catch (Exception ex) { // Throw message if any error occurs MessageBox.Show(ex.Message, "Insert data in Database Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { conn.Close(); } return(isSuccess); }
/// <summary> /// 处理EE00命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xEE00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0xEE00 xee00 = new _0xEE00(); xee00.Content = obj.MsgContent; xee00.Unpackage(); // 更新终端发送命令的结果 if (null != equipment && xee00.ErrorCommand.Equals("0x6007")) { // 更新锁车状态 using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.LockStatus = xee00.ErrorParamenter; }); } } // 更新命令的发送状态 using (var bll = new CommandBLL()) { bll.Update(f => f.DestinationNo == obj.TerminalID && f.Command == xee00.ErrorCommand && f.ScheduleTime >= DateTime.Now.AddMinutes(-3) && f.Status >= (byte)CommandStatus.SentByTCP && f.Status <= (byte)CommandStatus.SentToDest, act => { byte b = 0x10; switch (xee00.Error) { case 0x20: b = (byte)CommandStatus.EposFail; break; case 0x30: b = (byte)CommandStatus.EngNotStart; break; default: b = (byte)CommandStatus.NoFunction; break; } act.Status = b; }); } }
private bool checkContainerStatus(bool fromSaveButton) { lblError.Text = ""; System.Data.DataSet ds = EquipmentBLL.CheckContainerStatus(txtContainerNo.Text.Trim()); string abbr = string.Empty; try { if (ds.Tables.Count > 0) { abbr = Convert.ToString(ds.Tables[0].Rows[0]["MoveAbbr"]); } } catch { } bool canEditable = false; if (abbr == string.Empty) { GeneralFunctions.RegisterAlertScript(this, "This container-number doesn't exists"); lblError.Text = "This container-number doesn't exists or its movement id is null"; } else { if (abbr.ToUpper() != "RCVE" && abbr.ToUpper() != "OFFH") { GeneralFunctions.RegisterAlertScript(this, "Container status is not RCVE/OFFH and hence repair entry is not possible"); } else { if (!fromSaveButton) { GeneralFunctions.RegisterAlertScript(this, "Container status is RCVE/OFFH."); } canEditable = true; } } return(canEditable); }
private void ShowNotbindEquipments() { var totalRecords = 0; var pageIndex = "" == hidPageIndex.Value ? 1 : int.Parse(hidPageIndex.Value); var list = EquipmentInstance.FindPageList <TB_Equipment>(pageIndex, PageSize, out totalRecords, f => f.Terminal == (int?)null && f.Number.IndexOf(txtEquipment.Value.Trim()) >= 0 && f.Functional == GetEquipmentTypeByTerminalType() && f.Deleted == false, null); var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0); string html = ""; if (totalRecords < 1) { html = "<tr><td colspan=\"9\">No equipment has unbind terminal.</td></tr>"; } else { var cnt = (pageIndex - 1) * PageSize; var n = (int?)null; foreach (var obj in list) { cnt++; html += "<tr style=\"cursor: pointer;\">" + "<td style=\"text-align: center;\">" + " <input type=\"radio\" name=\"bind\" id=\"radio_" + obj.id + "\" />" + "</td>" + "<td style=\"text-align: center;\">" + cnt + "</td>" + "<td>" + (n == obj.Model ? "-" : obj.TB_EquipmentModel.TB_EquipmentType.Code) + "</td>" + "<td>" + EquipmentInstance.GetFullNumber(obj) + "</td>" + "<td style=\"text-align: right;\">" + EquipmentBLL.GetRuntime(obj.Runtime + obj.InitializedRuntime, obj.CompensatedHours.Value) + "</td>" + "<td style=\"text-align: center;\" title=\"" + EquipmentInstance.GetStatusTitle(obj) + "\">" + EquipmentInstance.GetStatus(obj) + "</td>" + "<td>" + (n == obj.Terminal ? "not bind" : obj.TB_Terminal.Number) + "</td>" + "<td>" + (n == obj.Warehouse ? "-" : obj.TB_Warehouse.Name) + "</td>" + "<td>" + obj.GpsAddress + "</td>" + "<td></td>" + "</tr>"; } } tbodyBody.InnerHtml = html; divPagging.InnerHtml = ""; if (totalRecords > 0) { ShowPaggings(pageIndex, totalPages, totalRecords, "./equipment_terminal.aspx", divPagging); } }
/// <summary> /// 处理DD00命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xDD00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0xDD00 xdd00 = new _0xDD00(); xdd00.Content = obj.MsgContent; xdd00.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Signal = xdd00.CSQ; }); } } //if (null != terminal) //{ // TerminalInstance.Update(f => f.id == terminal.id, act => { act.Firmware = xdd00.Firmware; }); //} }
private void BindData() { EquipmentBLL bll = null; DataPage dp = new DataPage(); EquipmentInfo condition = new EquipmentInfo(); string eID = Request.QueryString["eID"]; if (!string.IsNullOrEmpty(eID)) { if (eID.Split('|')[1] == "F") { condition.FACTORYPID = eID.Split('|')[0]; } else { condition.PRODUCTLINEPID = eID.Split('|')[0]; } } try { bll = BLLFactory.CreateBLL <EquipmentBLL>(); condition.ECODE = this.ECODE.Text; condition.ENAME = this.ENAME.Text; PagerHelper.InitPageControl(this.AspNetPager1, dp, true); dp = bll.GetList(condition, dp); List <EquipmentInfo> list = dp.Result as List <EquipmentInfo>; this.GvList.DataSource = list; this.GvList.DataBind(); for (int i = 0; i < this.GvList.Rows.Count; i++) { string click = string.Format("return edit('{0}');", this.GvList.DataKeys[i]["PID"].ToString()); (this.GvList.Rows[i].Cells[7].Controls[0] as WebControl).Attributes.Add("onclick", click); } PagerHelper.SetPageControl(AspNetPager1, dp, true); } catch (Exception ex) { throw ex; } }
public TempEquipment(TB_Equipment obj) { Number = obj.TB_EquipmentModel.Code + obj.Number; Id = obj.id; var n = (int?)null; Terminal = n == obj.Terminal ? "" : obj.TB_Terminal.Number; Sim = n == obj.Terminal ? "" : obj.TB_Terminal.Sim; Satellite = n == obj.Terminal ? "" : (n == obj.TB_Terminal.Satellite ? "" : obj.TB_Terminal.TB_Satellite.CardNo); Functional = Utility.GetEquipmentFunctional(obj.Functional.Value); Worktime = EquipmentBLL.GetRuntime(obj.Runtime + obj.InitializedRuntime, obj.CompensatedHours.Value, true); Latitude = obj.Latitude.Value; Longitude = obj.Longitude.Value; Online = Utility.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false); Lock = obj.LockStatus; Acttime = null == obj.LastActionTime ? 0 : CustomConvert.DateTimeToJavascriptDate(obj.LastActionTime.Value); Voltage = obj.Voltage; Alarm = obj.Alarm; }
/// <summary> /// 处理仪表盘数据 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x6000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x6000 x6000 = new _0x6000(); x6000.Content = obj.MsgContent; x6000.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Rpm = (short)x6000.RPM; // EPOS命令时清空报警 2015/09/24 08:00 act.Alarm = ALARM; }); } } }
/// <summary> /// 处理发送保安命令请求 /// </summary> /// <returns></returns> private string HandleSecurityCommandRequest() { var ret = "[]"; try { var id = ParseInt(Utility.Decrypt(data)); using (var bll = new EquipmentBLL()) { var obj = bll.Find(f => f.id == id && f.Deleted == false); if (null != obj) { if ((int?)null != obj.Terminal) { ret = ""; // 查看是否发送的保安命令 var command = CommandUtility.GetCommand(cmd); if (command.Security && command.Code.Equals("6007")) { ret = HandleSecurityStatus(obj.LockStatus, command.Param); } if (string.IsNullOrEmpty(ret)) { // 查看当前设备的链接状态然后确定命令的发送方式 ret = HandleTerminalCommandRequest(obj.TB_Terminal); } } else { ret = ResponseMessage(-1, "No terminal bond with this equipment."); } } else { ret = ResponseMessage(-1, "Equipment is not exist."); } } } catch (Exception e) { ret = ResponseMessage(-1, "Handle Security command error:" + e.Message); } return(ret); }
/// <summary> /// 处理DD02卫星功能命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xDD02(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0xDD02 xdd02 = new _0xDD02(); xdd02.Content = obj.MsgContent; xdd02.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.SatelliteStatus = xdd02.Status; }); } } if (null != terminal) { using (var bll = new TerminalBLL()) { bll.Update(f => f.id == terminal.id, act => { act.SatelliteStatus = xdd02.Status; }); } } }
/// <summary> /// 处理报警信息 /// </summary> /// <param name="obj"></param> private void Handle0x2000(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { // 报警 _0x2000 x2000 = new _0x2000(); x2000.Content = obj.MsgContent; x2000.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { if (x2000.AlarmBIN[0] == '1') { // Main Power Disconnect act.Voltage = "G0000"; // 主电断报警之后进入睡眠状态 act.OnlineStyle = (byte)LinkType.SLEEP; } // 同时更新设备的报警状态 2015/09/10 14:02 act.Alarm = x2000.AlarmBIN; if (x2000.GPSInfo.Available) { act.Latitude = x2000.GPSInfo.Latitude; act.Longitude = x2000.GPSInfo.Longitude; act.GpsUpdated = false; } }); } } long gps = -1; if (x2000.GPSInfo.Available) { gps = SaveGpsInfo(x2000.GPSInfo, equipment, obj.TerminalID, "Alarm report" + GetPackageType(obj.ProtocolType)); } // 保存报警信息 SaveAlarm(equipment, obj.TerminalID, gps, x2000.AlarmBIN); }
/// <summary> /// 处理保安命令 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0x6007(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0x6007 x6007 = new _0x6007(); x6007.Content = obj.MsgContent; x6007.Unpackage(); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.LockStatus = CustomConvert.GetHex(x6007.Code); if (obj.TerminalType == Protocol.TerminalTypes.DH || obj.TerminalType == Protocol.TerminalTypes.DX) { // EPOS命令时清空报警 2015/09/24 08:00 act.Alarm = ALARM; } }); } } }
private string GetCommandData(TB_HISTORIES data) { var ret = ""; var buffer = Wbs.Utilities.CustomConvert.GetBytes(data.message_content); var start = 0; switch (data.command_id) { case "0xDD00": ret = string.Format("Signal: {0}({1})", buffer[8], Utility.ASU2DBM(buffer[8])); break; case "0x1000": ret = "Please going to page <code>Map</code> to check out the data."; break; case "0x6000": ret = string.Format("RPM: {0}, Fuel: {1}", BitConverter.ToUInt16(buffer, 5), OilTempers.GetOilLeftDX((ushort)(BitConverter.ToUInt16(buffer, 29) * 500 / 1024)).ToString()); break; case "0x6004": start = data.terminal_type == Wbs.Protocol.TerminalTypes.DX ? 5 : 1; ret = string.Format("Worktime: {0}", EquipmentBLL.GetRuntime((int?)BitConverter.ToUInt32(buffer, start), 0.0, true)); break; case "0x600B": ret = string.Format("Worktime: {0}", EquipmentBLL.GetRuntime((int?)BitConverter.ToUInt32(buffer, 0), 0.0, true)); break; case "0x6007": ret = string.Format("Security: {0}", _0x6007.GetSecurity(buffer[1])); break; case "0x3000": ret = string.Format("Security: {0}", _0x3000.GetFlag(buffer[0])); break; case "0xDD02": ret = string.Format("Satellite: {0}", _0xDD02.GetStatus(buffer[0])); break; } return(ret); }
/// <summary> /// 处理CC00命令,这里只处理卫星方式 /// </summary> /// <param name="obj"></param> /// <param name="equipment"></param> /// <param name="terminal"></param> private void Handle0xCC00(TX300 obj, TB_Equipment equipment, TB_Terminal terminal) { _0xCC00 cc00 = new _0xCC00(); cc00.Content = obj.MsgContent; cc00.Unpackage(); HandleEquipmentRuntime(equipment, cc00.WorkTime); if (null != equipment) { using (var bll = new EquipmentBLL()) { bll.Update(f => f.id == equipment.id, act => { act.Runtime = equipment.Runtime; act.AccumulativeRuntime = equipment.AccumulativeRuntime; if ((int?)null != act.Terminal) { act.TB_Terminal.Firmware = cc00.Firmware; } }); } } // 更新最近发送的0xBB0F命令为成功状态 Handle0xBB0FStatus(); // 返回铱星方式的0xCC00数据 //if (obj.ProtocolType == Protocol.ProtocolTypes.SATELLITE) //{ // var cc00 = Get0xCC00(obj); // var cmd = CommandInstance.GetObject(); // cmd.Command = "0xCC00"; // cmd.Content = CustomConvert.GetHex(cc00); // cc00 = null; // cmd.DestinationNo = terminal.Sim + (terminal.Sim.Length < 11 ? "000" : ""); // cmd.Status = (byte)CommandStatus.WaitingForSatellite; // cmd.Terminal = terminal.id; // CommandInstance.Add(cmd); //} }
protected void btSave_Click(object sender, EventArgs e) { // 保存历史 var id = int.Parse(hidPosId.Value); if (id > 0) { if (!string.IsNullOrEmpty(hidAddress.Value)) { // 地址不为空时更新成功 var pos = PositionInstance.Find(f => f.id == id); PositionInstance.Update(f => f.id == id && f.Updated == 1, act => { act.Address = hidAddress.Value; act.Updated = 2; }); // 更新设备的最新定位信息 if (pos.Equipment != (int?)null) { var EquipmentInstance = new EquipmentBLL(); EquipmentInstance.Update(f => f.id == pos.Equipment && f.Deleted == false, act => { act.GpsAddress = hidAddress.Value; act.GpsUpdated = true; }); } } else { // 地址不为空时更新失败,其他时候会将其更新成待更新状态 PositionInstance.Update(f => f.id == id && f.Updated == 1, act => { act.Updated = 3; }); } hidPosId.Value = "0"; } }
/// <summary> /// 根据TX300数据包更新终端和设备的在线状态 /// </summary> /// <param name="tx300"></param> private void HandleTX300Status(TX300 tx300, AsyncUserDataBuffer data) { var sim = GetSimFromData(tx300); using (var ebll = new EquipmentBLL()) { var equipment = ebll.Find(f => f.TB_Terminal.Sim.Equals(sim)); var terminal = new TerminalBLL().Find(f => f.Sim.Equals(sim)); SaveTerminalData(null == terminal ? -1 : terminal.id, sim, data.PackageType, tx300.TotalLength, true, data.ReceiveTime); // 终端不存在的话,不用再继续处理数据了 if (!IsTracker(tx300.CommandID)) { if (null == terminal) { return; } } HandleOnline(sim, tx300.CommandID, data); if (tx300.CommandID != 0xAA00) { // TX10G的数据 if (tx300.CommandID >= 0x7000 && tx300.CommandID <= 0x7040) { HandleTX10G(tx300, data); } else { SaveTX300History(tx300, data.ReceiveTime, (null == equipment ? "" : ebll.GetFullNumber(equipment))); // 根据命令的不同处理各个命令详情 HandleCommand(tx300, equipment, terminal); } } } }
private void HandleEquipmentState(string sender, ushort Command) { var EquipmentInstance = new EquipmentBLL(); EquipmentInstance.Update(f => f.TB_Terminal.Sim.Equals(sender) && f.Deleted == false, act => { act.Socket = 0; act.OnlineTime = DateTime.Now; act.IP = ""; act.Port = 0; act.LastAction = "0x" + CustomConvert.IntToDigit(Command, CustomConvert.HEX, 4); act.LastActionBy = "SMS"; act.LastActionTime = DateTime.Now; if (act.OnlineStyle == (byte)LinkType.OFF && Command == 0x2000) { } else { act.OnlineStyle = (byte)LinkType.SMS; } }); var TerminalInstance = new TerminalBLL(); TerminalInstance.Update(f => f.Sim.Equals(sender), act => { act.Socket = 0; act.OnlineTime = DateTime.Now; if (act.OnlineStyle == (byte)LinkType.OFF && Command == 0x2000) { // 收到报警但此时已经是OFF状态时,不更新在线状态 } else { act.OnlineStyle = (byte)LinkType.SMS; } }); }
/// <summary> /// 导出设备列表到excel /// </summary> /// <param name="bll"></param> /// <param name="excel"></param> private void ExportEquipmentsToExcel(ExcelHandlerBLL bll, TB_ExcelHandler excel) { // data为保存出错时的异常数据 string source = "", data = ""; Application app = null; Workbook book = null; Worksheet sheet = null; try { app = new Application(); book = app.Workbooks.Open(EXCEL_PATH + EXCEL_EQUIPMENTS); sheet = (Worksheet)book.ActiveSheet; app.Visible = false; app.AlertBeforeOverwriting = false; app.DisplayAlerts = false; using (var ebll = new EquipmentBLL()) { int line = 3; int cnt = 0; var n = (int?)null; var list = ebll.FindList(f => f.Deleted == false); foreach (var obj in list) { var x = line + cnt; sheet.Cells[x, 1] = (cnt + 1); sheet.Cells[x, 2] = n == obj.Model ? "-" : obj.TB_EquipmentModel.TB_EquipmentType.Code; sheet.Cells[x, 3] = n == obj.Model ? "-" : ebll.GetFullNumber(obj); sheet.Cells[x, 4] = EverdigmUtils.GetEquipmentFunctional(obj.Functional.Value); sheet.Cells[x, 5] = EquipmentBLL.GetRuntime(obj.Runtime + obj.InitializedRuntime, obj.CompensatedHours.Value); sheet.Cells[x, 6] = ebll.GetEngineState(obj); sheet.Cells[x, 7] = string.IsNullOrEmpty(obj.GpsAddress) ? "-" : obj.GpsAddress; // 状态 sheet.Cells[x, 8] = obj.TB_EquipmentStatusName.Code; // customer sheet.Cells[x, 9] = n == obj.Customer ? "-" : obj.TB_Customer.Code; sheet.Cells[x, 10] = n == obj.Customer ? "-" : obj.TB_Customer.Name; // 终端 var link = EverdigmUtils.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false); link = link.Substring(link.IndexOf('>') + 1); link = link.Substring(0, link.IndexOf('<')); sheet.Cells[x, 11] = string.IsNullOrEmpty(link) ? "-" : link; string alarm = ebll.GetAlarmStatus(obj.Alarm); alarm = alarm.Substring(alarm.IndexOf("title=\"") + 7); alarm = alarm.Substring(0, alarm.IndexOf('"')); sheet.Cells[x, 12] = alarm.Contains("No") ? "-" : alarm; sheet.Cells[x, 13] = null == obj.LastActionTime ? "-" : obj.LastActionTime.Value.ToString("yyyy/MM/dd HH:mm"); sheet.Cells[x, 14] = n == obj.Terminal ? "-" : obj.TB_Terminal.Number; bool sat = n != obj.Terminal && n != obj.TB_Terminal.Satellite; sheet.Cells[x, 15] = sat ? obj.TB_Terminal.TB_Satellite.CardNo : "-"; sheet.Cells[x, 16] = n == obj.Warehouse ? "-" : obj.TB_Warehouse.Name; cnt++; } } // 另存为别的 var date = excel.CreateDate.Value.ToString("yyyyMMdd"); var path = Path.Combine(WEB_PATH, "files\\xls\\", date); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } source = path + "\\Equipments2Excel_" + excel.CreateDate.Value.ToString("yyyyMMdd") + ".xlsx"; if (File.Exists(source)) { File.Delete(source); } book.SaveAs(source); } catch (Exception e) { data = e.StackTrace; ShowUnhandledMessage(format("{0}Equipment to Excel handler error: {1}{2}{3}", Now, e.Message, Environment.NewLine, e.StackTrace)); } finally { // 关闭book if (null != book) { book.Close(); book = null; } // 关闭application if (null != app) { app.Quit(); app = null; } // 释放内存 GC.Collect(); GC.WaitForPendingFinalizers(); } var target = "../" + source.Replace(WEB_PATH, "").Replace("\\", "/"); bll.Update(f => f.id == excel.id, act => { act.Handled = true; act.Target = target; act.Status = (byte)(string.IsNullOrEmpty(data) ? 0 : 1); act.Data = data; }); }
public void ProcessRequest(HttpContext context) { context.Response.ContentEncoding = Encoding.UTF8; context.Response.ContentType = "application/json"; string type = context.Request.QueryString["Type"]; string code = context.Request.QueryString["Code"]; string batchNumber = ""; switch (type) { case "CP": ProducePlanBLL bll = BLLFactory.CreateBLL <ProducePlanBLL>(); ProductInfo result = bll.GetPNameByIDBatchNumber(code); if (result == null) { result = new ProductInfo(); if (result != null) { result.PID = "none"; } } context.Response.Write(LAF.Common.Serialization.JsonConvertHelper.GetSerializes(result)); break; case "CP2": ProducePlanBLL bllGoodInfo = BLLFactory.CreateBLL <ProducePlanBLL>(); GoodInfo resultGoodInfo = bllGoodInfo.GetGoodInfoByBatchNumber(code); if (resultGoodInfo == null) { resultGoodInfo = new GoodInfo(); if (resultGoodInfo != null) { resultGoodInfo.PID = "none"; } } context.Response.Write(LAF.Common.Serialization.JsonConvertHelper.GetSerializes(resultGoodInfo)); break; case "CB": EquipmentBLL bll2 = BLLFactory.CreateBLL <EquipmentBLL>(); EquipmentInfo result2 = bll2.GetInfoByBarCode(code); if (result2 == null) { result2 = new EquipmentInfo(); if (result2 != null) { result2.PID = "none"; } } context.Response.Write(LAF.Common.Serialization.JsonConvertHelper.GetSerializes(result2)); break; case "GX": //根据工位条码获取加工工序 ProcessInfoBLL bll3 = BLLFactory.CreateBLL <ProcessInfoBLL>(); Manage.Entity.MES.ProcessInfo result3 = bll3.GetInfoByWS(code); if (result3 == null) { result3 = new Manage.Entity.MES.ProcessInfo(); if (result3 != null) { result3.PID = "none"; } } context.Response.Write(LAF.Common.Serialization.JsonConvertHelper.GetSerializes(result3)); break; case "GX2": ProcessInfoBLL bll4 = BLLFactory.CreateBLL <ProcessInfoBLL>(); batchNumber = context.Request.QueryString["BatchNumber"]; Manage.Entity.MES.ProcessInfo result4 = bll4.GetInfoByBarCodeAndBatchNumber(code, batchNumber); if (result4 == null) { result4 = new Manage.Entity.MES.ProcessInfo(); if (result4 != null) { result4.PID = "none"; } } context.Response.Write(LAF.Common.Serialization.JsonConvertHelper.GetSerializes(result4)); break; case "PP": ProducePlanBLL ppbll = BLLFactory.CreateBLL <ProducePlanBLL>(); SupplyInfoBLL sibll = BLLFactory.CreateBLL <SupplyInfoBLL>(); string id = context.Request.QueryString["id"]; SupplyInfo siresult = ppbll.GetProducePlanInfoByID(id); if (siresult == null) { siresult = new SupplyInfo(); if (siresult != null) { siresult.PID = "none"; } } else { siresult.Details = sibll.GetMaterialListByBOM(siresult.ProductionID); } context.Response.Write(LAF.Common.Serialization.JsonConvertHelper.GetSerializes(siresult)); break; case "ZJ": QualityCheckBLL qcBll = BLLFactory.CreateBLL <QualityCheckBLL>(); batchNumber = context.Request.QueryString["BatchNumber"]; QualityCheckInfo qualityCheckInfo = qcBll.GetPDInfo(batchNumber); if (qualityCheckInfo == null) { qualityCheckInfo = new QualityCheckInfo(); qualityCheckInfo.ID = "none"; } context.Response.Write(LAF.Common.Serialization.JsonConvertHelper.GetSerializes(qualityCheckInfo)); break; default: break; } }
/// <summary> /// 显示我作为购买者名下的所有设备列表 /// </summary> private void ShowMyDevices() { var items = EquipmentInstance.FindList(f => f.Customer == me.id && f.Deleted == false); var html = ""; foreach (var item in items) { var eng = EquipmentInstance.GetEngStatus(item); html += "<dl class=\"invest-type\" id=\"" + item.id.ToString() + "\">" + " <dt>" + " <span class=\"iconleft\">" + " <img class=\"img-rounded ex\" src=\"" + item.TB_EquipmentModel.TB_EquipmentType.Image + "\">" + " </span>" + EquipmentInstance.GetFullNumber(item) + " <em class=\"status\">" + item.TB_EquipmentModel.TB_EquipmentType.Name + "</em>" + " </dt>" + " <dd>" + " <span class=\"text-" + (eng.Equals("ON") ? "success" : "danger") + "\"><span class=\"signal cell-engine\"></span> Engine " + eng + "</span>" + " <em class=\"status\"><span class=\"glyphicon glyphicon-time\"></span> " + EquipmentBLL.GetRuntime(item.Runtime + item.InitializedRuntime, item.CompensatedHours.Value) + "</em>" + " </dd>" + " <dd>" + " <span class=\"text-info\"><span class=\"signal cell-signal-" + Utility.ASU2Signal(item.Signal.Value) + "\"></span> Signal: " + Utility.ASU2DBM(item.Signal.Value) + "dBm(ASU: " + item.Signal + ")</span>" + " <div class=\"total-num\">" + Utility.GetOnlineStyle(item.OnlineStyle, item.OnlineTime, false) + "</div>" + " </dd>" + " <dd class=\"desc\"><span class=\"glyphicon glyphicon-globe\"></span> " + item.GpsAddress + "</dd>" + "</dl>"; } equipmentItems.InnerHtml = html; }
/// <summary> /// 按照查询条件显示设备列表 /// </summary> private void ShowEquipments() { var query = txtQueryNumber.Value.Trim(); // 模糊查询时页码置为空 if (!string.IsNullOrEmpty(query)) { hidPageIndex.Value = ""; } var totalRecords = 0; var pageIndex = "" == hidPageIndex.Value ? 1 : int.Parse(hidPageIndex.Value); pageIndex = (0 >= pageIndex ? 1 : pageIndex); var type = ParseInt(selectedTypes.Value); var model = ParseInt(selectedModels.Value); var house = ParseInt(hidQueryWarehouse.Value); // 表达式 Expression <Func <TB_Equipment, bool> > expression = PredicateExtensions.True <TB_Equipment>(); expression = expression.And(a => a.TB_EquipmentStatusName.IsItInventory == true && a.Deleted == false && a.StoreTimes == 1 && a.Terminal != (int?)null); if (type > 0) { expression = expression.And(a => a.TB_EquipmentModel.Type == type); } if (model > 0) { expression = expression.And(a => a.Model == model); } if (house > 0) { expression = expression.And(a => a.Warehouse == house); } if (!string.IsNullOrEmpty(query)) { pageIndex = 1; expression = expression.And(a => a.Number.Contains(query)); } var list = EquipmentInstance.FindPageList <TB_Equipment>(pageIndex, PageSize, out totalRecords, expression, null); var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0); hidTotalPages.Value = totalPages.ToString(); string html = ""; if (totalRecords < 1) { html = "<tr><td colspan=\"18\">No records, You can change the condition and try again.</td></tr>"; } else { var cnt = (pageIndex - 1) * PageSize; var n = (int?)null; foreach (var obj in list) { cnt++; // 入库记录 //var _in = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, true); // 出库记录 //var _out = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, false); var id = Utility.UrlEncode(Utility.Encrypt(obj.id.ToString())); html += "<tr>" + "<td class=\"in-tab-txt-b\">" + cnt + "</td>" + "<td class=\"in-tab-txt-b\">" + (n == obj.Model ? "-" : obj.TB_EquipmentModel.TB_EquipmentType.Code) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\" style=\"text-align: left !important;\">" + (n == obj.Model ? "-" : ("<a href=\"./equipment_position.aspx?key=" + id + "\">" + EquipmentInstance.GetFullNumber(obj) + "</a>")) + "</td>" + "<td class=\"in-tab-txt-b\" style=\"text-align: left !important;\">" + Utility.GetEquipmentFunctional(obj.Functional.Value) + "</td>" + "<td class=\"in-tab-txt-b\" style=\"text-align: right !important;\">" + EquipmentBLL.GetRuntime(obj.Runtime + obj.InitializedRuntime, obj.CompensatedHours.Value) + "</td>" + "<td class=\"in-tab-txt-b\">" + EquipmentInstance.GetEngStatus(obj) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\" title=\"" + obj.GpsAddress + "\">" + obj.GpsAddress + "</td>" + "<td class=\"in-tab-txt-rb\" title=\"" + EquipmentInstance.GetStatusTitle(obj) + "\">" + EquipmentInstance.GetStatus(obj) + "</td>" + "<td class=\"in-tab-txt-b\">" + EquipmentInstance.GetOutdoorDays(obj) + "</td>" + "<td class=\"in-tab-txt-rb textoverflow\">" + EquipmentInstance.GetAverageWorktime(obj) + "</td>" + //"<td class=\"in-tab-txt-b textoverflow\">" + (null == _in ? "-" : _in.Stocktime.Value.ToString("yyyy/MM/dd")) + "</td>" + //"<td class=\"in-tab-txt-b\" title=\"" + StoreInstance.GetStatusTitle(_in) + "\">" + StoreInstance.GetStatus(_in) + "</td>" + //"<td class=\"in-tab-txt-b textoverflow\">" + (null == _out ? "-" : _out.Stocktime.Value.ToString("yyyy/MM/dd")) + "</td>" + //"<td class=\"in-tab-txt-b\" title=\"" + StoreInstance.GetStatusTitle(_out) + "\">" + StoreInstance.GetStatus(_out) + "</td>" + "<td class=\"in-tab-txt-rb textoverflow\">" + obj.TB_Warehouse.Name + "</td>" + //"<td class=\"in-tab-txt-b\">" + ((byte?)null == obj.Signal ? "-" : obj.Signal.ToString()) + "</td>" + "<td class=\"in-tab-txt-b\">" + Utility.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\">" + ((DateTime?)null == obj.LastActionTime ? "" : obj.LastActionTime.Value.ToString("yyyy/MM/dd HH:mm")) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\" title=\"" + EquipmentInstance.GetTerinalTitleInfo(obj) + "\">" + (n == obj.Terminal ? "-" : obj.TB_Terminal.Number) + "</td>" + "</tr>"; } } tbodyBody.InnerHtml = html; divPagging.InnerHtml = ""; if (totalRecords > 0) { ShowPaggings(pageIndex, totalPages, totalRecords, "./equipment_in_storage.aspx", divPagging); } }
/// <summary> /// 查询命令历史记录 /// </summary> /// <param name="security">是否查询保安命令</param> /// <returns></returns> private string HandleCommandHistoryRequest(bool security) { var ret = "[]"; try { var id = ParseInt(Utility.Decrypt(data)); using (var ebll = new EquipmentBLL()) { var obj = ebll.Find(f => f.id == id && f.Deleted == false); if (null != obj) { // 终端不为空时才查询 if ((int?)null != obj.Terminal) { var start = DateTime.Parse(GetParamenter("start") + " 00:00:00"); var end = DateTime.Parse(GetParamenter("end") + " 23:59:59"); var sim = obj.TB_Terminal.Sim; if (sim[0] == '8' && sim[1] == '9' && sim.Length < 11) { sim += "000"; } // 查询的命令 //string _command = ""; Command command = null; if (!string.IsNullOrEmpty(cmd)) { command = CommandUtility.GetCommand(cmd); //_command = command.Code; } using (var bll = new CommandBLL()) { var list = bll.FindList <TB_Command>(f => f.DestinationNo.Equals(sim) && f.ScheduleTime >= start && f.ScheduleTime <= end && f.Command != "0xBB0F", "ScheduleTime", true); if (security) { list = list.Where(w => w.Command == "0x6007" || w.Command == "0x4000" || w.Command == "0x3000" || w.Command == "0xDD02"); } else { list = list.Where(w => w.Command != "0x6007" && w.Command != "0x4000" && w.Command != "0x3000" && w.Command != "0xDD02"); } //&& // (string.IsNullOrEmpty(_command) ? f.u_sms_command.IndexOf("0x") >= 0 : f.u_sms_command.IndexOf(_command) >= 0), // "u_sms_schedule_time", true); if (null != command) { list = list.Where(w => w.Command.IndexOf(command.Code) >= 0); if (security && command.Code.Equals("6007")) { list = list.Where(w => w.Content.Substring(w.Content.Length - 2) == command.Param); } else if (security && command.Code.Equals("3000")) { list = list.Where(w => w.Content.Substring(w.Content.Length - 4, 2) == command.Param); } else if (security && command.Code.Equals("4000")) { list = list.Where(w => w.Content.Substring(w.Content.Length - 4, 2) == command.Param); } } if (list.Count() > 0) { // 将command_id替换 //List<Command> commands = CommandUtility.GetCommand(); foreach (var record in list) { string param = ""; if (record.Command == "0x6007") { param = record.Content.Substring(record.Content.Length - 2); } if (record.Command == "0x3000") { param = record.Content.Substring(record.Content.Length - 4, 2); } if (record.Command == "0x4000") { param = record.Content.Substring(record.Content.Length - 4, 2); } if (record.Command == "0xDD02") { param = record.Content.Substring(record.Content.Length - 8, 2); } Command _cmd = CommandUtility.GetCommand(record.Command.Replace("0x", ""), param); var func = (EquipmentFunctional)obj.Functional; var called = (func == EquipmentFunctional.Mechanical || func == EquipmentFunctional.Electric) ? "Equipment" : "Loader"; record.Command = (null == _cmd ? "" : _cmd.Title.Replace("Equipment", called).Replace("Loader", called)); // 加入命令发送者 2015/09/18 10:36 record.Content = (int?)null == record.SendUser ? "Server" : record.TB_Account.Name; } } ret = JsonConverter.ToJson(list); } } else { ret = ResponseMessage(-1, "No terminal bond with this equipment."); } } else { ret = ResponseMessage(-1, "Equipment is not exist."); } } } catch (Exception e) { ret = ResponseMessage(-1, "Handle History request error:" + e.Message); } return(ret); }
public string COPRAR_TXT() { string rpd; int LocationId = Convert.ToInt32(ddlLoc.SelectedValue); int LineID = Convert.ToInt32(ddlLine.SelectedValue); int VesselID = Convert.ToInt32(ddlVessel.SelectedValue); int VoyageID = Convert.ToInt32(ddlVoyage.SelectedValue); //DateTime dt = DateTime.Now; string VCN; string CallSign; string IMONo; string VoyageNo; string Port; string Country; string Containers; string uniqueFileName = Guid.NewGuid().ToString(); //File.Create(Server.MapPath(@"~/Import/COPRARFILE/") + uniqueFileName + "_IMP_EDI.IGM"); string FileName = Server.MapPath(@"~/Import/EDIFile/") + uniqueFileName + "_COPRAR.TXT"; string PCSLogin = Convert.ToString(new DBInteraction().GetPCSLogin(LocationId).Tables[0].Rows[0]["PCSLoginID"]); string CurDate = DateTime.Now.ToString("ddMMyyyy") + "00000001"; string pod = ((TextBox)AutoCompletepPort1.FindControl("txtPort")).Text; pod = pod.Contains(',') ? pod.Split(',')[1] : ""; if (pod == "INCCU1") { rpd = "kopt001"; } else { rpd = "haldia001"; } int PortCode = dbinteract.GetId("Port", pod); StreamWriter writer = new StreamWriter(FileName); // ("myfile.txt") writer.WriteLine(("UNH" + ('' + ("COPRAR" + ('' + ("Advance Container List" + ('' + (CurDate + ('' + (CurDate + ('' + ("9" + ('' + (PCSLogin)))))))))))))); writer.WriteLine(("RPD" + ('' + (rpd)))); //System.Data.DataTable dt = EquipmentBLL.GetOMHinformation(LocationId, LineID, VesselID, VoyageID, PortCode); System.Data.DataSet ds = EquipmentBLL.GetOMHinformation(LocationId, LineID, VesselID, VoyageID, PortCode); //if (ds.Tables[0].Rows.Count > 0) //{ VCN = ds.Tables[0].Rows[0]["VCN"].ToString(); CallSign = ds.Tables[0].Rows[0]["CallSign"].ToString(); IMONo = ds.Tables[0].Rows[0]["IMONumber"].ToString(); VoyageNo = ds.Tables[0].Rows[0]["VoyageNo"].ToString(); Port = ds.Tables[0].Rows[0]["PortCode"].ToString(); Country = ds.Tables[0].Rows[0]["CountryAbbr"].ToString(); Containers = ds.Tables[0].Rows[0]["TotContainers"].ToString(); //} writer.WriteLine(("OMH" + ('' + (VCN + ('' + (CallSign + ('' + (IMONo + ('' + (VoyageNo + ('' + (Port + ('' + (Country + ('' + ("BLA" + ('' + ('' + ('' + ('' + ('' + (Containers)))))))))))))))))))))); DataSet DsContain = EquipmentBLL.GetCOPRARContainerInfo(VesselID, VoyageID, PortCode); //.GetCOPRARContainerInfo(Convert.ToInt32(ddlVessel.SelectedValue), Convert.ToInt32(ddlVoyage.SelectedValue)); // TextShippingCode.Text = Ds.Tables(0).Rows(0).Item("ShippingLineCode") DataTable DtContain = DsContain.Tables[0]; int Srl1 = 0; foreach (DataRow Dr in DtContain.Rows) { Srl1 = (Srl1 + 1); writer.WriteLine(("OMD" + ('' + ("3" + ('' + (Dr["ContainerNo"].ToString() + ('' + (Dr["cstatus"].ToString() + ('' + (Dr["ISOCode"].ToString() + ('' + (Dr["TareWeight"].ToString() + ('' + (Dr["CargoWtTon"].ToString() + ('' + ('' + (Dr["SealNo"].ToString() + ('' + (Dr["loadport"].ToString().Substring(0, 5) + "1" + ('' + (Dr["loadport"].ToString().Substring(0, 5) + "1" + ('' + ('' + (Dr["Commodity"].ToString() + ('' + (Dr["ImpLineBLNo"].ToString() + ('' + ('' + (Dr["ItemLineNo"].ToString() + ('' + ('' + ("12" + ('' + ("BLA" + ('' + ('' + ('' + ('' + (Dr["discport"].ToString() + ('' + (Dr["finalDestination"].ToString().Substring(0, 5) + "1" + ('' + (Dr["TMODE"].ToString() + ('' + (Dr["ICD"].ToString() + ('' + ("1" + ('' + ("" + ('' + ("" + ('' + ("" + ('' + ("" + ('' + ("" + ('' + ("" + ('' + ("" + ('' )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))); } string dt = DateTime.Now.ToString("ddMMyyyyhhmmss"); writer.WriteLine(("UNT" + ('' + (dt)))); writer.Close(); writer.Dispose(); return(FileName); }
private void ShowEquipments() { var query = txtQueryNumber.Value.Trim(); // 模糊查询时页码置为空 if (!string.IsNullOrEmpty(query)) { hidPageIndex.Value = ""; } var totalRecords = 0; var pageIndex = "" == hidPageIndex.Value ? 1 : int.Parse(hidPageIndex.Value); pageIndex = (0 >= pageIndex ? 1 : pageIndex); var type = ParseInt(selectedTypes.Value); var model = ParseInt(selectedModels.Value); var house = 0;//ParseInt(hidQueryWarehouse.Value); var customer = ParseInt(hiddenCustomer.Value); // 表达式 Expression <Func <TB_Equipment, bool> > expression = PredicateExtensions.True <TB_Equipment>(); // 设备类型 if (type > 0) { expression = expression.And(a => a.TB_EquipmentModel.Type == type); } // 设备型号 if (model > 0) { expression = expression.And(a => a.Model == model); } // 仓库 if (house > 0) { expression = expression.And(a => a.Warehouse == house); } // 查询号码 if (!string.IsNullOrEmpty(query)) { expression = expression.And(a => a.Number.Contains(query) || a.TB_Customer.Code.Contains(query)); } // 客户号码 switch (customer) { case 3: // None expression = expression.And(a => a.Customer == (int?)null); break; case 2: // Bound expression = expression.And(a => a.Customer != (int?)null); //if (!string.IsNullOrEmpty(query)) //{ // expression = expression.And(a => a.TB_Customer.Code.Contains(query)); //} break; default: // Default break; } // 终端绑定状态 var terminal = ParseInt(hiddenTerminal.Value.Trim()); switch (terminal) { case 2: // 绑定终端了 expression = expression.And(a => a.Terminal != (int?)null); break; case 3: // 未绑定终端 expression = expression.And(a => a.Terminal == (int?)null); break; default: // 忽略的话就是不查询终端的绑定状态 break; } expression = expression.And(a => a.Deleted == false); var list = EquipmentInstance.FindPageList <TB_Equipment>(pageIndex, PageSize, out totalRecords, expression, null); var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0); hidTotalPages.Value = totalPages.ToString(); string html = ""; if (totalRecords < 1) { html = "<tr><td colspan=\"16\">No records, You can change the condition and try again.</td></tr>"; } else { var cnt = (pageIndex - 1) * PageSize; var n = (int?)null; foreach (var obj in list) { cnt++; // 入库记录 //var _in = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, true); // 出库记录 //var _out = StoreInstance.GetStoreInfo(obj.id, obj.StoreTimes.Value, false); var id = Utility.UrlEncode(Utility.Encrypt(obj.id.ToString())); bool sat = n != obj.Terminal && n != obj.TB_Terminal.Satellite; // 锁车状态和报警信息 string arms = EquipmentInstance.GetLockEffectedStatus(obj); if (string.IsNullOrEmpty(arms)) { arms = EquipmentInstance.GetAlarmStatus(obj.Alarm); } html += "<tr>" + "<td class=\"in-tab-txt-b\">" + cnt + "</td>" + "<td class=\"in-tab-txt-b\">" + (n == obj.Model ? "-" : obj.TB_EquipmentModel.TB_EquipmentType.Code) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\" style=\"text-align: left !important;\">" + (n == obj.Model ? "-" : ("<a href=\"./equipment_position.aspx?key=" + id + "\">" + EquipmentInstance.GetFullNumber(obj) + "</a>")) + "</td>" + "<td class=\"in-tab-txt-b\" style=\"text-align: left !important;\">" + Utility.GetEquipmentFunctional(obj.Functional.Value) + "</td>" + "<td class=\"in-tab-txt-b\" style=\"text-align: right !important;\">" + EquipmentBLL.GetRuntime(obj.Runtime + obj.InitializedRuntime, obj.CompensatedHours.Value) + "</td>" + "<td class=\"in-tab-txt-b\" style=\"padding: 2px !important; vertical-align: middle !important;\">" + EquipmentInstance.GetEngStatus(obj) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\" title=\"" + obj.GpsAddress + "\" style=\"text-align: left !important;\">" + obj.GpsAddress + "</td>" + "<td class=\"in-tab-txt-rb\" title=\"" + EquipmentInstance.GetStatusTitle(obj) + "\">" + EquipmentInstance.GetStatus(obj) + "</td>" + //"<td class=\"in-tab-txt-b\">" + EquipmentInstance.GetOutdoorDays(obj) + "</td>" + //"<td class=\"in-tab-txt-rb textoverflow\">" + EquipmentInstance.GetAverageWorktime(obj) + "</td>" + "<td class=\"in-tab-txt-b\">" + (n == obj.Customer ? "-" : obj.TB_Customer.Code) + "</td>" + "<td class=\"in-tab-txt-rb textoverflow\" style=\"text-align: left !important;\" title=\"" + (n == obj.Customer ? "-" : obj.TB_Customer.Name) + "\">" + (n == obj.Customer ? "-" : obj.TB_Customer.Name) + "</td>" + //"<td class=\"in-tab-txt-b\">" + ((byte?)null == obj.Signal ? "-" : obj.Signal.ToString()) + "</td>" + "<td class=\"in-tab-txt-b\">" + Utility.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime) + "</td>" + "<td class=\"in-tab-txt-b\">" + arms + "</td>" + "<td class=\"in-tab-txt-b textoverflow\">" + ((DateTime?)null == obj.LastActionTime ? "" : obj.LastActionTime.Value.ToString("yyyy/MM/dd HH:mm")) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\" title=\"" + EquipmentInstance.GetTerinalTitleInfo(obj) + "\">" + (n == obj.Terminal ? "-" : obj.TB_Terminal.Number) + "</td>" + "<td class=\"in-tab-txt-rb\" title=\"" + EquipmentInstance.GetSatelliteTitleInfo(obj) + "\"><span class=\"glyphicon glyphicon-" + (sat ? "ok" : "remove") + " text-" + (sat ? "success" : "danger") + "\" aria-hidden=\"true\"></span></td>" + //"<td class=\"in-tab-txt-b textoverflow\">" + (null == _in ? "-" : _in.Stocktime.Value.ToString("yyyy/MM/dd")) + "</td>" + //"<td class=\"in-tab-txt-b\" title=\"" + StoreInstance.GetStatusTitle(_in) + "\">" + StoreInstance.GetStatus(_in) + "</td>" + //"<td class=\"in-tab-txt-b textoverflow\">" + (null == _out ? "-" : _out.Stocktime.Value.ToString("yyyy/MM/dd")) + "</td>" + //"<td class=\"in-tab-txt-b\" title=\"" + StoreInstance.GetStatusTitle(_out) + "\">" + StoreInstance.GetStatus(_out) + "</td>" + "<td class=\"in-tab-txt-b textoverflow\">" + (n == obj.Warehouse ? "-" : obj.TB_Warehouse.Name) + "</td>" + //"<td class=\"in-tab-txt-b\">" + (n == obj.Terminal ? "-" : (n == obj.TB_Terminal.Satellite ? "-" : obj.TB_Terminal.TB_Satellite.CardNo)) + "</td>" + //"<td class=\"in-tab-txt-rb\">" + (n == obj.Terminal ? "-" : obj.TB_Terminal.Sim) + "</td>" + "</tr>"; } } tbodyBody.InnerHtml = html; divPagging.InnerHtml = ""; if (totalRecords > 0) { ShowPaggings(pageIndex, totalPages, totalRecords, "./equipment_inquiry.aspx", divPagging); } }
/// <summary> /// 导出终端列表到excel /// </summary> /// <param name="bll"></param> /// <param name="excel"></param> private void ExportTerminalsToExcel(ExcelHandlerBLL bll, TB_ExcelHandler excel) { string source = "", data = ""; Application app = null; Workbook book = null; Worksheet sheet = null; try { app = new Application(); book = app.Workbooks.Open(EXCEL_PATH + EXCEL_TERMINALS); sheet = (Worksheet)book.ActiveSheet; app.Visible = false; app.AlertBeforeOverwriting = false; app.DisplayAlerts = false; using (var tbll = new TerminalBLL()) { using (var ebll = new EquipmentBLL()) { int line = 2; int cnt = 0; var n = (int?)null; var list = tbll.FindList(f => f.Delete == false); foreach (var obj in list) { var x = line + cnt; sheet.Cells[x, 1] = (cnt + 1); sheet.Cells[x, 2] = obj.Number; sheet.Cells[x, 3] = n == obj.Satellite ? "-" : obj.TB_Satellite.CardNo; sheet.Cells[x, 4] = string.IsNullOrEmpty(obj.Firmware) ? "-" : obj.Firmware; sheet.Cells[x, 5] = obj.Revision; sheet.Cells[x, 6] = TerminalTypes.GetTerminalType(obj.Type.Value); sheet.Cells[x, 7] = obj.ProductionDate.Value.ToString("yyyy/MM/dd"); var e = ebll.Find(d => d.Terminal == obj.id && d.Deleted == false); sheet.Cells[x, 8] = null == e ? "-" : ebll.GetFullNumber(e); var link = EverdigmUtils.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false); link = link.Substring(link.IndexOf('>') + 1); link = link.Substring(0, link.IndexOf('<')); sheet.Cells[x, 9] = string.IsNullOrEmpty(link) ? "-" : link; sheet.Cells[x, 10] = null == obj.OnlineTime ? "-" : obj.OnlineTime.Value.ToString("yyyy/MM/dd HH:mm"); cnt++; } } } // 另存为别的 var date = excel.CreateDate.Value.ToString("yyyyMMdd"); var path = Path.Combine(WEB_PATH, "files\\xls\\", date); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } source = path + "\\Terminals2Excel_" + excel.CreateDate.Value.ToString("yyyyMMdd") + ".xlsx"; if (File.Exists(source)) { File.Delete(source); } book.SaveAs(source); } catch (Exception e) { data = e.StackTrace; ShowUnhandledMessage(format("{0}Terminal to Excel handler error: {1}{2}{3}", Now, e.Message, Environment.NewLine, e.StackTrace)); } finally { // 关闭book if (null != book) { book.Close(); book = null; } // 关闭application if (null != app) { app.Quit(); app = null; } // 释放内存 GC.Collect(); GC.WaitForPendingFinalizers(); } var target = "../" + source.Replace(WEB_PATH, "").Replace("\\", "/"); bll.Update(f => f.id == excel.id, act => { act.Handled = true; act.Status = (byte)(string.IsNullOrEmpty(data) ? 0 : 1); act.Target = target; act.Data = data; }); }
/// <summary> /// 处理新版的卫星通讯协议 /// </summary> /// <param name="data"></param> private void HandleIridiumNewProtocolPackage(IridiumData data) { if (data.Payload[0] == 0x01) { // 新版的卫星通讯协议 uint thisWorkTime = BitConverter.ToUInt32(data.Payload, 13); string locks = CustomConvert.GetHex(data.Payload[1]); string alarms = CustomConvert.IntToDigit(data.Payload[2], CustomConvert.BIN, 8) + CustomConvert.IntToDigit(data.Payload[3], CustomConvert.BIN, 8); IridiumLocation location = new IridiumLocation(); location.LatLng = new byte[IridiumLocation.SIZE]; Buffer.BlockCopy(data.Payload, 4, location.LatLng, 0, IridiumLocation.SIZE); location.Unpackate(); // 通过卫星的IMEI号码查找终端 using (var tbll = new TerminalBLL()) { using (var ebll = new EquipmentBLL()) { var terminal = tbll.Find(f => f.TB_Satellite.CardNo.Equals(data.IMEI)); TB_Equipment equipment = null; if (null != terminal) { // 只有第一版的终端才需要计算补偿时间 var compensated = terminal.Version == 1; tbll.Update(f => f.id == terminal.id, act => { act.OnlineStyle = (byte)LinkType.SATELLITE; // 同时更新终端的最后链接时间 act.OnlineTime = data.Time; }); equipment = ebll.Find(f => f.Terminal == terminal.id); if (null != equipment) { // 旧的运转时间 var oldRuntime = equipment.Runtime; var interval = 0 == oldRuntime ? 0 : (thisWorkTime - oldRuntime); // 粗略增加的小时数,启动时加2小时 var addMin = interval > 60 ? interval / 60 : 1 + (location.EngFlag.Equals("On") ? 1 : 0); int addHour = (int)(interval > 60 ? interval / 60 : 1);// 显示历史记录 string oldCompensated = format("WorkHours {0}, UsedHours {1}, Efficiency {2}, AddHours {3}, Compensated {4}", equipment.WorkHours, equipment.UsedHours, equipment.HourWorkEfficiency, equipment.AddedHours, equipment.CompensatedHours); string newCompensated = ""; // 更新设备的总运转时间 HandleEquipmentRuntime(equipment, thisWorkTime); if (null != equipment) { string calculated = ""; ebll.Update(f => f.id == equipment.id, act => { act.OnlineStyle = (byte)LinkType.SATELLITE; act.OnlineTime = data.Time; // 更新设备的报警状态 2015/09/10 14:04 act.Alarm = alarms; act.LastAction = "0x1000"; act.LastActionBy = "SAT"; act.LastActionTime = data.Time; // 更新定位信息 2015/09/09 23:29 if (location.Available) { act.Latitude = location.Latitude; act.Longitude = location.Longitude; } // 更新启动与否状态 2015/08/31 act.Voltage = location.EngFlag.Equals("On") ? "G2400" : "G0000"; // 更新总运转时间 act.Runtime = equipment.Runtime; act.AccumulativeRuntime = equipment.AccumulativeRuntime; // 更新 version 终端为1的版本的运转时间的补偿 if (compensated && interval > 0) { // 实际工作小时数 act.WorkHours += interval / 60.0; // 实际所用小时数 act.UsedHours += addHour; // 重新计算每小时工作效率 act.HourWorkEfficiency = act.WorkHours / act.UsedHours; // 补偿的小时数 act.AddedHours += addMin / 60.0; // 实际补偿的小时数 act.CompensatedHours = act.AddedHours * act.HourWorkEfficiency; } // 如果回来的运转时间比当前时间大则更新成为On状态 暂时 2015/09/02 //if (worktime > act.Runtime) //{ // // act.Voltage = "G2400"; // act.Runtime = (int)worktime; //} //else //{ // if (worktime > 0) // { // // 运转时间不为零的话,更新运转时间 // act.Runtime = (int)worktime; // } //} // 锁车状态 2015/08/14 if (act.LockStatus != locks) { act.LockStatus = locks; } // 判断锁车的有效状态 if (locks.Equals("40") || locks.Equals("0F") || locks.Equals("FF")) { // 锁车时还有开机状态 if (location.EngFlag.Equals("On")) { // 锁车了,但未关机,还在工作中 if (act.LockEffected == (byte)LockEffect.Locked) { act.LockEffected = (byte)LockEffect.LockedAndStillWork; } else if (act.LockEffected == (byte)LockEffect.LockedAndEngineOff) { // 锁车了且已关机了,此时再开机则需要报警(没锁住车) act.LockEffected = (byte)LockEffect.LockedAndNoEffect; } } else { // 锁车了,且已关机了 if (act.LockEffected == (byte)LockEffect.Locked) { act.LockEffected = (byte)LockEffect.LockedAndEngineOff; } } } }); if (compensated && interval > 0) { equipment = ebll.Find(f => f.id == equipment.id); newCompensated = format("WorkHours {0}, UsedHours {1}, Efficiency {2}, AddHours {3}, Compensated {4}", equipment.WorkHours, equipment.UsedHours, equipment.HourWorkEfficiency, equipment.AddedHours, equipment.CompensatedHours); calculated = format("Compensate changed(interval: {0}){1} from {2}{3} to {4}", interval, Environment.NewLine, oldCompensated, Environment.NewLine, newCompensated); } if (!string.IsNullOrEmpty(calculated)) { OnUnhandledMessage(this, new Sockets.UIEventArgs() { Message = format("{0}{1}{2}", Now, calculated, Environment.NewLine) }); } } } else { OnUnhandledMessage(this, new Sockets.UIEventArgs() { Message = format("{0} Iridium has not bind with any equipment.", Now, Environment.NewLine) }); } } else { OnUnhandledMessage(this, new Sockets.UIEventArgs() { Message = format("{0} Satellite has no terminal, data will save as terminal number: \"{1}\".{2}", Now, data.IMEI.Substring(4), Environment.NewLine) }); } // 保存TX300历史记录 SaveTX300History(new TX300() { CommandID = 0x1000, MsgContent = data.Payload, ProtocolType = ProtocolTypes.SATELLITE, // 默认装载机终端类型 2015/09/22 09:40 TerminalType = null == terminal ? TerminalTypes.LD : terminal.Type.Value, // 没有终端时,用IMEI号码的末尾11位数字表示终端号码 2015/09/22 09:40 TerminalID = null == terminal ? data.IMEI.Substring(4) : terminal.Sim, TotalLength = (ushort)data.Payload.Length }, data.Time, ebll.GetFullNumber(equipment)); try { long?posId = null; if (location.Available) { using (var posbll = new PositionBLL()) { var pos = posbll.GetObject(); pos.Latitude = location.Latitude; pos.Longitude = location.Longitude; pos.NS = location.NSI; pos.EW = location.EWI; pos.StoreTimes = null == equipment ? 0 : equipment.StoreTimes; pos.GpsTime = data.Time; pos.Equipment = null == equipment ? (int?)null : equipment.id; // 没有终端时,用IMEI号码的末尾11位数字表示终端号码 2015/09/22 09:40 pos.Terminal = null == terminal?data.IMEI.Substring(4) : (terminal.Sim.Length < 11 ? (terminal.Sim + "000") : terminal.Sim); pos.Type = location.Report + "(Eng " + location.EngFlag + ")(SAT)"; posbll.Add(pos); posId = pos.id; } } // 处理报警信息 if (alarms != ALARM) { using (var armbll = new AlarmBLL()) { var arm = armbll.GetObject(); arm.Code = alarms; arm.AlarmTime = data.Time; arm.Equipment = null == equipment ? (int?)null : equipment.id; arm.Position = posId; arm.StoreTimes = null == equipment ? 0 : equipment.StoreTimes; // 没有终端时,用IMEI号码的末尾11位数字表示终端号码 2015/09/22 09:40 arm.Terminal = null == terminal?data.IMEI.Substring(4) : (terminal.Sim.Length < 11 ? (terminal.Sim + "000") : terminal.Sim); armbll.Add(arm); } } } catch (Exception e) { OnUnhandledMessage(this, new Sockets.UIEventArgs() { Message = format("{0}{1}{2}{3}", Now, e.Message, Environment.NewLine, e.StackTrace) }); } // 更新卫星方式的命令状态(只处理命令回复的1000,其他的命令在普通命令过程中处理) if (location.ReportType == 1 && data.Payload.Length <= 17) { HandleIridiumCommandResponseed(data); } location.Dispose(); location = null; } } } }