using System; using System.Linq; using System.Collections.Generic; using System.Text; using Npgsql; using System.Collections; using System.Data; namespace SafeMobileLib { public class DBReportingManager : DBmanager { public DBReportingManager(string p_server, string p_dbname, string p_user, string p_password, string p_port) : base(p_server, p_dbname, p_user, p_password, p_port) { } public List get_ALLAlarm(String glwhere, Boolean is24hours, Boolean isInMile, Boolean DayFirst, Hashtable VehIDHash, Hashtable ZoneIDHash, Hashtable LandIDHash, Hashtable vehicleHT, string milesh, string kmh) { int sc_id = 0, timeGMT = 0, zone_id = 0, speed = 0, telemetry_id = 0, action = 0, type = 0; String tmpglwhere = glwhere; List HistDataReport = new List(); try { //get all energ alarm using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = $"SELECT sc_id, timeGMT FROM emergalarm {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { timeGMT = Convert.ToInt32(dr["timeGMT"]); HistDataReport.Add(new StopData { Location = timeGMT.GetRegionalFormat(is24hours, DayFirst), Duration = "", Time = "Emergency", Data = (String)VehIDHash[sc_id], timeGMT = timeGMT }); } } } } command = $"SELECT sc_id,zone_id,action,timeGMT,type FROM geozoneinout {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { timeGMT = Convert.ToInt32(dr["timeGMT"]); zone_id = Convert.ToInt32(dr["zone_id"]); action = Convert.ToInt32(dr["action"]); type = Convert.ToInt32(dr["type"]); string descStr = ((uint)action == 1) ? "OUT " : "IN "; if (type == 1) { if (ZoneIDHash[zone_id] != null) descStr = descStr + ((ZoneClass)ZoneIDHash[zone_id]).Name; } else { if (LandIDHash[zone_id] != null) descStr = descStr + ((String)LandIDHash[zone_id]); } HistDataReport.Add(new StopData { Location = timeGMT.GetRegionalFormat(is24hours, DayFirst), Duration = descStr, Time = "Geo-Fence", Data = (String)VehIDHash[sc_id], timeGMT = timeGMT }); } } } } command = $"SELECT timeGMT,sc_id,speed FROM speedalarm {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { timeGMT = Convert.ToInt32(dr["timeGMT"]); speed = Convert.ToInt32(dr["speed"]); HistDataReport.Add(new StopData { Location = timeGMT.GetRegionalFormat(is24hours, DayFirst), Duration = (isInMile) ? ((int)(speed * 0.621371192)).ToString() + " " + milesh : speed.ToString() + " " + kmh, Time = "Speeding", Data = (String)VehIDHash[sc_id], timeGMT = timeGMT }); } } } } if (tmpglwhere != "") tmpglwhere = tmpglwhere + " and alarm =1"; else tmpglwhere = " where alarm = 1"; command = $"SELECT sc_id,timeGMT,telemetry_id FROM telemetry_history {tmpglwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { telemetry_id = Convert.ToInt32(dr["telemetry_id"]); timeGMT = Convert.ToInt32(dr["timeGMT"]); // get action name var list = ((VehicleForReports)vehicleHT[(String)VehIDHash[sc_id]]).telemList; string actionName = list.Where(x => x.Id == telemetry_id).Select(x => x.Name).FirstOrDefault(); HistDataReport.Add(new StopData { Location = timeGMT.GetRegionalFormat(is24hours, DayFirst), Duration = actionName, Time = "Telemetry", Data = (String)VehIDHash[sc_id], timeGMT = timeGMT }); } } } } } HistDataReport.Sort(delegate (StopData li1, StopData li2) { // -1 is for descending order return (-1) * (li1.timeGMT.CompareTo(li2.timeGMT)); }); } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return HistDataReport; } public List get_Speeding(String glwhere, Boolean is24hours, Boolean isInMile, Hashtable VehIDHash) { List SpeedingList = new List(); Int32 count50000 = 0; Int32 sc_id = 0; try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = $"SELECT timeGMT,sc_id,speed,address,lat,lng FROM speedalarm {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { count50000++; sc_id = Convert.ToInt32(dr["sc_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { SpeedingList.Add(new SpeedData { Name = (String)VehIDHash[sc_id], Speed = (isInMile) ? ((int)(dr.GetInt32(2) * 0.621371192)).ToString() : dr.GetInt32(2).ToString(), Time = dr.GetInt32(0).TimeOfDayHHMMLocal(!is24hours), Data = dr.GetInt32(0).GetDTLocalFromSeconds().Date.ToShortDateString(), Address = dr.GetString(3), sc_id = sc_id, timeGMT = dr.GetInt32(0), lat = (dr.IsDBNull(4) ? 0 : dr.GetDouble(4)), lng = (dr.IsDBNull(5) ? 0 : dr.GetDouble(5)) }); if (count50000 > 50000) break; } } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return SpeedingList; } public List get_LANDANDZONE(String glwhere, rep_type typ, Boolean is24hours, Boolean DayFirst, Hashtable VehIDHash, Hashtable ZoneIDHash, Hashtable LandIDHash) { List LandList = new List(); String newglwhere = glwhere; String ToAdd = " type=2 "; if (typ == rep_type.GEOFENC) ToAdd = " type=1 "; if (newglwhere.Length > 1) newglwhere = newglwhere + " and " + ToAdd; else newglwhere = " where " + ToAdd; try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = $"SELECT sc_id,zone_id,action,timeGMT FROM geozoneinout {newglwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { int sc_id = 0, zone_id = 0; using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id"]); zone_id = Convert.ToInt32(dr["zone_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { LandData tmp = new LandData(); tmp.Name = (String)VehIDHash[sc_id]; tmp.LandType = Convert.ToInt32(dr["action"]) == 1 ? "OUT" : "IN"; tmp.Time = Convert.ToInt32(dr["timeGMT"]).GetRegionalFormat(is24hours, DayFirst); tmp.LandName = sc_id.TimeOfDayHHMMLocal(); if (typ == rep_type.GEOFENC) { if (ZoneIDHash[zone_id] != null) tmp.LandName = ((ZoneClass)ZoneIDHash[zone_id]).Name; } else { if (LandIDHash[zone_id] != null) tmp.LandName = (String)LandIDHash[zone_id]; } LandList.Add(tmp); } } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return LandList; } public List get_log_view_all(String glwhere, Boolean is24hours, Boolean DayFirst, Hashtable VehIMEIHash) { String tmpname = ""; string Stat = ""; string imei = ""; int timeGMT = 0; List ONOFFList = new List(); try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = $"SELECT imei,timeGMT,status FROM logmototurbo {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { NpgsqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { imei = dr["imei"].ToString(); timeGMT = Convert.ToInt32(dr["timeGMT"]); tmpname = ""; if (VehIMEIHash[imei] != null) tmpname = (VehIMEIHash[imei] as String); if (tmpname != "") { switch (dr.GetInt32(2)) { case 0: Stat = "OFF"; break; case 1: Stat = "ON"; break; case 9: Stat = "MADE OFF"; break; case 10: Stat = "MADE ON"; break; } ONOFFList.Add( new ONOFFData { Name = tmpname, Time = timeGMT.GetRegionalFormat(is24hours, DayFirst), Status = Stat }); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return ONOFFList; } public List get_EMERG(String glwhere, Boolean is24hours, Hashtable VehIDHash) { List ONOFFList = new List(); int timeGMT = 0, sc_id = 0; try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = $"SELECT timeGMT,sc_id,address,lat,lng FROM emergalarm {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { string formatDateTime = is24hours ? "MM/dd/yyyy HH:mm:ss" : "MM/dd/yyyy hh:mm:ss tt"; while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { timeGMT = Convert.ToInt32(dr["timegmt"]); ONOFFList.Add( new ONOFFData { Name = (String)VehIDHash[sc_id], Time = timeGMT.GetDTLocalFromSeconds().ToString(formatDateTime), Status = dr["address"].ToString(), sc_id = sc_id, lat = Convert.ToDouble(dr["lat"]), lng = Convert.ToDouble(dr["lng"]), timeGMT = timeGMT }); } } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return ONOFFList; } private BatchHistoryData GetData(NpgsqlDataReader dr, bool isInMile, bool is24hours, bool getAddress = false) { int timegmt = 0; double lat = 0, lng = 0; BatchHistoryData batchHistObj = null; try { lat = Convert.ToDouble(dr["lat"]); lng = Convert.ToDouble(dr["lng"]); timegmt = Convert.ToInt32(dr["timegmt"]); batchHistObj = new BatchHistoryData { Department = dr["department"].ToString(), Unit = dr["unit"].ToString(), Location = ((getAddress && dr["address"] != DBNull.Value) ? dr["address"].ToString() : "LAT:" + Math.Round(lat, 5).ToString() + " , LNG:" + Math.Round(lat, 5).ToString()), Speed = (isInMile) ? ((int)(Convert.ToInt32(dr["speed"]) * 0.621371192)).ToString() : Convert.ToInt32(dr["speed"]).ToString(), Lat = lat, Lng = lng, Address = dr["address"].ToString(), Time = timegmt.TimeOfDayHHMMSSLocal(!is24hours), Date = timegmt.GetDTLocalFromSeconds().Date.ToShortDateString() }; } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return batchHistObj; } private string FormatCommandBatchHistory(string sc_ids, int startdate, int enddate, bool isInMile, bool is24hours, int limit = Int32.MaxValue, bool getAddress = false, bool getOnlyValidPositions = false) { string address = ""; string join_getiing_address = ""; string onlyValidPositions = ""; if (getAddress) { address = ",a.address"; join_getiing_address = "LEFT JOIN address a ON a.lat = ROUND(z.lat::numeric, 4) AND a.lng = ROUND(z.lng::numeric, 4) "; } if (getOnlyValidPositions) { onlyValidPositions = " AND m.lat <> 0.0 AND m.lng <> 0.0 "; } string command = $" SELECT x.grp_name as department, x.veh_name as unit, z.lat, z.lng, z.timegmt, z.speed {address} " + " FROM " + " (SELECT m.sc_id, m.timegmt, m.lat, m.lng, m.speed " + " FROM messages m " + $" WHERE m.timegmt BETWEEN {startdate} AND {enddate} " + $" {onlyValidPositions}" + $" AND m.sc_id IN ({sc_ids}) { (limit != Int32.MaxValue ? $"LIMIT {limit}" : "")} " + " )z " + " INNER JOIN " + " ( " + " SELECT sh.sc_id, v.name as veh_name, g.name as grp_name " + $" FROM (SELECT * FROM subscriber_history WHERE sc_id IN ({sc_ids})) sh " + " INNER JOIN vehicle v ON v.id = sh.veh_id " + " INNER JOIN vehicle_group vg ON sh.sc_id = vg.sc_id " + " INNER JOIN groups g ON vg.grp_ip = g.id " + " ) x ON z.sc_id = x.sc_id " + $"{join_getiing_address}" + " ORDER BY x.grp_name, x.veh_name, z.timegmt "; return command; } public List getBatchHistory(string sc_ids, int startdate, int enddate , bool isInMile, bool is24hours, int limit = Int32.MaxValue, bool getAddress = false, bool getOnlyValidPositions = false) { var list = new List(); using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = FormatCommandBatchHistory(sc_ids, startdate, enddate, isInMile, is24hours, limit, getAddress, getOnlyValidPositions); using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { cmd.CommandTimeout = 1200; using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { BatchHistoryData data = GetData(dr, isInMile, is24hours, getAddress); list.Add(data); } } } } return list; } public void saveBatchHistoryToCsv(string filePath, List excludeColumns, string sc_ids, int startdate, int enddate, bool isInMile, bool is24hours, int limit = Int32.MaxValue, bool getAddress = false, bool getOnlyValidPositions = false) { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = FormatCommandBatchHistory(sc_ids, startdate, enddate, isInMile, is24hours, limit, getAddress, getOnlyValidPositions); using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { cmd.CommandTimeout = 1200; using (NpgsqlDataReader dr = cmd.ExecuteReader()) { // Being a huge report we get record by record and save them into file (without keep them). using (System.IO.StreamWriter sw = new System.IO.StreamWriter(filePath, false)) { //================ // write header //================ Utils.HeaderToCsv(sw, excludeColumns); while (dr.Read()) { //================ // write rows //================ BatchHistoryData data = GetData(dr, isInMile, is24hours, getAddress); Utils.RowToCsv(sw, data, excludeColumns); } } } } } } public List get_History(String glwhere, Boolean compAddress, Boolean forceLATLNG, Boolean is24hours, Boolean isInMile, ref int cntaddr, ref Queue AddrGISQueue, ref Hashtable IdReportHS) { List HistDataReport = new List(); string latlng = ""; try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = "SELECT timeGMT,address,speed,lat,lng,scevtime, sc_id, W.name, W.driver_id FROM messages " + $" INNER JOIN vehicle W on sc_id = W.id {glwhere} ORDER BY timeGMT DESC"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { cmd.CommandTimeout = 1200; using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { double lat = Convert.ToDouble(dr["lat"]); double lng = Convert.ToDouble(dr["lng"]); String Address = ""; latlng = "LAT:" + Math.Round(lat, 5).ToString() + " , LNG:" + Math.Round(lat, 5).ToString(); if (!forceLATLNG) { if (!dr.IsDBNull(1)) Address = dr["address"].ToString(); if ((lat == 0.0) || (lng == 0.0)) Address = "NO GPS FIX"; else if ((Address == "") || (Address == " ")) { if (compAddress) { cntaddr++; IdReportHS[cntaddr.ToString()] = string.Format("no address ({0})", latlng); AddrGISQueue.Enqueue(new AddrAndID(cntaddr, lat, lng)); Address = cntaddr.ToString(); } else Address = latlng; } } else Address = latlng; HistDataReport.Add(new StopData { Location = Address, Duration = (isInMile) ? ((int)(Convert.ToInt32(dr["speed"]) * 0.621371192)).ToString() : Convert.ToInt32(dr["speed"]).ToString(), Time = Convert.ToInt32(dr["timeGMT"]).TimeOfDayHHMMSSLocal(!is24hours), Data = (Convert.ToInt32(dr["timeGMT"]).GetDTLocalFromSeconds()).Date.ToShortDateString(), unit_sc_id = Convert.ToInt32(dr["sc_id"]), unit_name = dr["name"].ToString(), unique_id = Convert.ToDouble(dr["scevtime"]) }); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return HistDataReport; } public List get_TelemHist_alarm_event(String glwhere, Hashtable VehIDHash, Hashtable vehicleHT) { List SpeedingList = new List(); try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = $"SELECT timegmt,sc_id,telemetry_id,address,lat,lng FROM telemetry_history {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { int timeGMT = 0, sc_id = 0, telemetry_id = 0; while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { timeGMT = Convert.ToInt32(dr["timegmt"]); telemetry_id = Convert.ToInt32(dr["telemetry_id"]); // get action name var list = ((VehicleForReports)vehicleHT[(String)VehIDHash[sc_id]]).telemList; string actionName = list.Where(x => x.Id == telemetry_id).Select(x => x.Name).FirstOrDefault(); SpeedingList.Add(new SpeedData { Name = (String)VehIDHash[sc_id], Speed = actionName, Time = timeGMT.TimeOfDayHHMMSSLocal(false), Data = (timeGMT.GetDTLocalFromSeconds()).Date.ToShortDateString(), Address = dr["address"].ToString(), sc_id = sc_id, timeGMT = timeGMT, lat = Convert.ToDouble(dr["lat"]), lng = Convert.ToDouble(dr["lng"]) }); } } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return SpeedingList; } public List get_SMS_Location(String glwhere, Boolean is24hours, Hashtable VehIDHash) { List SMSLocList = new List(); try { using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = $"SELECT timeGMT,sc_id_sour,mess,address,lat,lng FROM sms {glwhere} ORDER BY timeGMT desc"; using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { int sc_id = 0, timeGMT = 0; while (dr.Read()) { sc_id = Convert.ToInt32(dr["sc_id_sour"]); if (VehIDHash.ContainsKey(sc_id) && (String)VehIDHash[sc_id] != "") { timeGMT = Convert.ToInt32(dr["timeGMT"]); SMSLocList.Add(new SMS_Location { Name = (String)VehIDHash[sc_id], Text_mess = dr["mess"].ToString(), Time = timeGMT.TimeOfDayHHMMLocal(!is24hours), Data = (timeGMT.GetDTLocalFromSeconds()).Date.ToShortDateString(), Address = dr["address"].ToString(), sc_id = sc_id, timeGMT = timeGMT, lat = Convert.ToDouble(dr["lat"]), lng = Convert.ToDouble(dr["lng"]) }); } } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return SMSLocList; } public List get_Ticketing(String glwhere, Boolean is24hours) { List SpeedingList = new List(); try { string command = "select veh.name, jt.ticket_id, jts.status, jt.start_time, jt.end_time " + "from jobtickets jt " + "inner join " + "( " + "select ticket_id, max(modified_date) as modified_date,job_Status,sc_id from jobtickets_log " + "group by ticket_id,sc_id,job_status " + ") jtl on jtl.ticket_id = jt.ticket_id and jtl.job_status = jt.job_status and jtl.sc_id = jt.sc_id " + "inner join jobticketstatusesset jts on jts.status_id = jt.job_status " + "inner join vehicle veh on veh.id = jt.sc_id " + glwhere + " order by jt.ticket_id desc "; using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { var tmp = new SpeedData { Name = dr["name"].ToString(), Speed = dr["ticket_id"].ToString(), Time = dr["status"].ToString(), Data = (dr["start_time"].ToString() == "") ? "" : Convert.ToInt32(dr["start_time"]).GetDTLocalFromSeconds().Date.ToShortDateString(), Address = (dr["end_time"].ToString() == "") ? "" : Convert.ToInt32(dr["end_time"]).GetDTLocalFromSeconds().Date.ToShortDateString(), }; if (tmp.Name != "") SpeedingList.Add(tmp); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return SpeedingList; } public List getUserReportTime() { List UserReportTimeList = new List(); try { string command = "SELECT user_id, value, login FROM \"userSettings\"" + " INNER JOIN " + " ( " + "SELECT DISTINCT(userid) AS uid FROM reports " + " ) r ON r.uid = user_id " + " INNER JOIN users u on u.userid = user_id " + " WHERE key='reportTime'"; using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { NpgsqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { int seconds = 0; string value = dr["value"].ToString(); Int32.TryParse(value, out seconds); DateTime DT = DateTime.Today.AddSeconds(seconds); UserReportTimeList.Add(new UserReportTime { UserID = Convert.ToInt32(dr["user_id"]), UserName = dr["login"].ToString(), HH = DT.Hour, MM = DT.Minute, ReportExecuted = false }); } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return UserReportTimeList; } public ArrayList get_position_for_report(Int32 timeMIN, Int32 timeMAX, Int32 sc_id) { ArrayList ret = new ArrayList(); try { Double scevtimemin = 0, scevtimemax = 0; scevtimemin = sc_id * 10000000000 + timeMIN; scevtimemax = sc_id * 10000000000 + timeMAX; using (NpgsqlConnection connection = new NpgsqlConnection()) { connection.ConnectionString = getConnectionString(); connection.Open(); string command = String.Format("SELECT timeGMT , address , lat , lng , di , speed FROM messages WHERE scevtime >{0} and scevtime <{1} ORDER by scevtime", scevtimemin, scevtimemax); using (NpgsqlCommand cmd = new NpgsqlCommand(command, connection)) { using (NpgsqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { double lat = Convert.ToDouble(dr["lat"]); double lng = Convert.ToDouble(dr["lng"]); string address = dr.IsDBNull(1) ? "" : dr["address"].ToString(); int speed = Convert.ToInt32(dr["speed"]); int timeGMT = Convert.ToInt32(dr["timeGMT"]); if (lat != 0 && lng != 0) ret.Add(new PositionData(lat, lng, address, timeGMT, car_state_e.CAR_RUNNING, speed)); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message, ConsoleColor.Red); } return ret; } } }