using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; using System.Collections; using MapGoogle; using System.IO; using System.Threading; using Telerik.WinControls.UI; using System.Windows.Forms; using SafeMobileLib; namespace Safedispatch_4_0 { public class ONOFFData { public String Name { get; set; } public String Time { get; set; } public String Status { get; set; } public Double lat { get; set; } public Double lng { get; set; } public Int32 sc_id { get; set; } public Int32 timeGMT { get; set; } } public class SpeedData { public String Name { get; set; } public String Speed { get; set; } public String Time { get; set; } public String Data { get; set; } public String Address { get; set; } public Int32 sc_id { get; set; } public Int32 timeGMT { get; set; } public Double lat { get; set; } public Double lng { get; set; } } public class FleetData { public String Name { get; set; } public String Distance { get; set; } public String Trips { get; set; } public String Start { get; set; } public String Stop { get; set; } } public class LandData { public String Name { get; set; } public String LandName { get; set; } public String Time { get; set; } public String LandType { get; set; } } public class SMS_Location { public String Name { get; set; } public String Time { get; set; } public String Data { get; set; } public String Address { get; set; } public String Text_mess { get; set; } public Int32 sc_id { get; set; } public Int32 timeGMT { get; set; } public Double lat { get; set; } public Double lng { get; set; } } public class PositionData { public Double Lat { get; set; } public Double Lng { get; set; } public String Address { get; set; } public Int32 TimeGMT { get; set; } public car_state_e Type { get; set; } // 0 = no name 1= stop 2 = road distance public Int32 Speed { get; set; } public PositionData(Double _lat, Double _lng, String _address, Int32 _timeGMT, car_state_e _type, Int32 _speed) { Lat = _lat; Lng = _lng; Address = _address; TimeGMT = _timeGMT; Type = _type; Speed = _speed; } } public class DistanceCalc { private Double Lat,Lng,Lat2,Lng2; public DistanceCalc(Double _lat, Double _lng, Double _lat2, Double _lng2) { Lat = _lat; Lng = _lng; Lat2 = _lat2; Lng2 = _lng2; } public double GetDistance() { double pi = 3.1415926535897932384626433832795; double rad = 180 / pi; double dist = (3958 * pi * Math.Sqrt((Lat2 - Lat) * (Lat2 - Lat) + Math.Cos(Lat2 / rad) * Math.Cos(Lat / rad) * (Lng2 - Lng) * (Lng2 - Lng)) / 180); return Math.Round(((dist * 1.609344) * 1000)) / 1000; } } public class EndOfDayData { public String Trip { get; set; } public String StartTime { get; set; } public String StopTime { get; set; } public String StartAddress { get; set; } public String StopAddress { get; set; } public String Distance { get; set; } } public class StopData { public String Data { get; set; } public String Time { get; set; } public String Location { get; set; } public String Duration { get; set; } public Int32 timeGMT = 0; public Double unique_id = 0; public Int32 unit_sc_id { get; set;} public String unit_name { get; set; } } public class FleetIdandPos { public String Name; public ArrayList Position; } /* public class RadCustomComboBoxItem : RadListDataItem { private RadCheckBoxElement checkBoxElement = new RadCheckBoxElement(); public bool IsChecked { get { return this.checkBoxElement.IsChecked; } set { this.checkBoxElement.IsChecked = value; } } public RadCustomComboBoxItem(string text) : base(text) { } public RadCustomComboBoxItem(string text, MouseEventHandler OnClick) : base(text, OnClick) { } protected override void CreateChildElements() { base.CreateChildElements(); this.Children[2].Children[1].Margin = new Padding(15, 0, 0, 0); checkBoxElement.StretchHorizontally = false; checkBoxElement.StretchVertically = false; this.Children.Add(checkBoxElement); } } */ [DataObject] public class ONOFFDataObj { [DataObjectMethod(DataObjectMethodType.Select)] public List GetALL() { return MainForm2.ONOFFList; } } [DataObject] public class SpeedDataObj { [DataObjectMethod(DataObjectMethodType.Select)] public List GetALL() { return MainForm2.SpeedingList; } } [DataObject] public class LandDataObj { [DataObjectMethod(DataObjectMethodType.Select)] public List GetALL() { return MainForm2.LandList; } } [DataObject] public class EndOfDayDataObj { [DataObjectMethod(DataObjectMethodType.Select)] public List GetALL() { CalcStops calcStop = new CalcStops(null, true);//mapControl calcStop.get_position(MainForm2.PositionList); calcStop.calculate_zone(); calcStop.calc_zone_with_delta2(); try { calcStop.create_stop_list(); } catch (Exception ex) { // throw new ArgumentException("Database connection failed"); SM.Debug("Error create stop list: "+ex.ToString()); } if (MainForm2.StartStop) { calcStop.StartStopCalc(); calcStop.StartStopCalcPosition(); } // calcul distanta ArrayList DriveList = new ArrayList(); Boolean first = true; Double distance = .01f; distance = 0; //Double LatStart = 0, LngStart = 0, LatStop = 0, LngStop = 0; Int32 timeStart = 0, timeStop = 0, oldStop =0; Int32 totaltime = 0, timeforStartCalc = 0; SM.Debug("Stop Count:" + calcStop.StopsList.Count); if (calcStop.StopsList.Count > 1) { Stops prevObj = null; foreach (Stops obj in calcStop.StopsList) { if (prevObj != null) { if (!((prevObj.type == car_state_e.CAR_STOP) && (obj.type == car_state_e.CAR_START))) { if (first) { timeStart = prevObj.stop; first = false; } else timeStart = oldStop; timeStop = obj.start; oldStop = obj.stop; distance = calcStop.calcDistance(timeStart, timeStop); DriveList.Add(distance); } else { first = true; } } prevObj = obj; } } //loaddata Int32 RowNumber = 0; Int32 count3 = -1; Double difidx = .01f; Boolean lastStopIsStop = false; Int32 lastStopTimeStop = 0; Double total = 0; String lastStopNameStop = ""; ArrayList numbers = new ArrayList(); //calcul addressa Google if (!MainForm2.LATLNGforDinamicReports) { try { if ((MainForm2.MapType == MapTYPE.ArcGis) || (MainForm2.MapType == MapTYPE.Google)) { foreach (Stops obj3 in calcStop.StopsList) { MainForm2.AddrGISQueue.Enqueue(new AddrAndID(Convert.ToInt32(obj3.name), obj3.lat, obj3.lng)); MainForm2.IdReportHS.Add(obj3.name, "no address"); } bool retrynew = true; int cntmax = 0; foreach (String obj in MainForm2.IdReportHS.Keys) numbers.Add(obj); while (retrynew) { cntmax++; retrynew = false; foreach (String obj in numbers) { if ((String)MainForm2.IdReportHS[obj] == "no address") { SM.Debug("Sta 240 msecunda"); Thread.Sleep(240); retrynew = true; } } if (cntmax > 10) retrynew = false; } } } catch (Exception ex) { SM.Debug("Erorr on compute adress for report:" + ex.ToString()); } } //Load list for reports var Ret = new List(); Boolean jumpstop = true; EndOfDayData tmpData = null; foreach (Stops obj3 in calcStop.StopsList) { if (obj3.type == car_state_e.CAR_START) { try { tmpData = new EndOfDayData(); RowNumber++; tmpData.Trip = Convert.ToString(RowNumber); //tmpData.StartTime = (new ConvertDT().GetDTLocalFromSeconds(obj3.stop)).ToString(); if (MainForm2.is24hours) tmpData.StartTime = (new ConvertDT().GetDTLocalFromSeconds(obj3.stop)).ToString("MM/dd/yyyy HH:mm:ss"); else tmpData.StartTime = (new ConvertDT().GetDTLocalFromSeconds(obj3.stop)).ToString("MM/dd/yyyy hh:mm:ss tt"); timeforStartCalc = obj3.stop; if (!MainForm2.LATLNGforDinamicReports) { if ((MainForm2.MapType == MapTYPE.Google) || (MainForm2.MapType == MapTYPE.ArcGis)) tmpData.StartAddress = MainForm2.IdReportHS[obj3.name].ToString(); } else { tmpData.StartAddress = "LAT:" + Math.Round(obj3.lat, 5).ToString() + " , LNG:" + Math.Round(obj3.lng, 5).ToString(); } lastStopIsStop = false; jumpstop = false; } catch (Exception ex) { SM.Debug("Address null exceptie la getlist:" + ex.ToString()); } } else { if (!jumpstop) { try { if (lastStopIsStop) { tmpData = new EndOfDayData(); RowNumber++; tmpData.Trip = Convert.ToString(RowNumber); //tmpData.StartTime = (new ConvertDT().GetDTLocalFromSeconds(lastStopTimeStop)).ToString(); if (MainForm2.is24hours) tmpData.StartTime = (new ConvertDT().GetDTLocalFromSeconds(lastStopTimeStop)).ToString("MM/dd/yyyy HH:mm:ss"); else tmpData.StartTime = (new ConvertDT().GetDTLocalFromSeconds(lastStopTimeStop)).ToString("MM/dd/yyyy hh:mm:ss tt"); timeforStartCalc = lastStopTimeStop; tmpData.StartAddress = lastStopNameStop; } count3++; if (tmpData != null) { totaltime+= (obj3.start-timeforStartCalc); tmpData.StopTime = (new ConvertDT().GetDTLocalFromSeconds(obj3.start)).ToString(); if (!MainForm2.LATLNGforDinamicReports) { if ((MainForm2.MapType == MapTYPE.Google) || (MainForm2.MapType == MapTYPE.ArcGis)) tmpData.StopAddress = MainForm2.IdReportHS[obj3.name].ToString(); } else tmpData.StopAddress = "LAT:" + Math.Round(obj3.lat, 5).ToString() + " , LNG:" + Math.Round(obj3.lng, 5).ToString(); difidx = (Double)DriveList[count3]; total += difidx; if (MainForm2.isInMile) tmpData.Distance = (Math.Round(((difidx * 0.621371192) * 1000)) / 1000).ToString(); else tmpData.Distance = difidx.ToString(); if (tmpData != null) Ret.Add(tmpData); } lastStopIsStop = true; lastStopTimeStop = obj3.stop; if (!MainForm2.LATLNGforDinamicReports) { if ((MainForm2.MapType == MapTYPE.Google) || (MainForm2.MapType == MapTYPE.ArcGis)) lastStopNameStop = MainForm2.IdReportHS[obj3.name].ToString(); } else lastStopNameStop = "LAT:" + Math.Round(obj3.lat, 5).ToString() + " , LNG:" + Math.Round(obj3.lng, 5).ToString(); } catch (Exception ex) { SM.Debug("eroare DriverList= " + ex.ToString()); } } jumpstop = false; } } if (RowNumber > 0) { tmpData = new EndOfDayData(); tmpData.Trip = ""; tmpData.StartTime = "Total time:"; SM.Debug("Total time is:"+totaltime); tmpData.StartAddress = String.Format("{0:00}", (int)(totaltime / 3600)) + ":" + String.Format("{0:00}", ((int)(((int)(totaltime % 3600)) / 60))) + ":" + String.Format("{0:00}", ((int)(totaltime % 60))); tmpData.StopTime = ""; tmpData.StopAddress = "Total distance:"; if (MainForm2.isInMile) tmpData.Distance = (Math.Round(((total * 0.621371192) * 1000)) / 1000).ToString(); else tmpData.Distance = total.ToString(); Ret.Add(tmpData); } //de la google address if ((MainForm2.MapType == MapTYPE.Google)||(MainForm2.MapType == MapTYPE.ArcGis)) { foreach (String obj in numbers) MainForm2.IdReportHS.Remove(obj); numbers.Clear(); } return Ret; } } [DataObject] public class StopDataObj { [DataObjectMethod(DataObjectMethodType.Select)] public List GetALL() { if (!MainForm2.IsHistroyNotStop) // aici prelucrez date cand e raport de stop sau IDLE { CalcStops calcStop = new CalcStops(null, true);//mapControl calcStop.get_position(MainForm2.PositionList); try { if (!MainForm2.IsIdle) { calcStop.calculate_zone(); calcStop.calc_zone_with_delta2(); calcStop.create_stop_list(); } else { calcStop.create_stop_list_EON(MainForm2.IDLETime); } } catch (Exception ex) { SM.Debug("Database connection failed:"+ex.ToString()); } if (MainForm2.StartStop) { calcStop.StartStopCalc(); calcStop.StartStopCalcPosition(); } ArrayList numbers = new ArrayList(); //calcul addressa Google if (!MainForm2.LATLNGforDinamicReports) { try { if ((MainForm2.MapType == MapTYPE.ArcGis) || (MainForm2.MapType == MapTYPE.Google)) { foreach (Stops obj3 in calcStop.StopsList) { MainForm2.AddrGISQueue.Enqueue(new AddrAndID(Convert.ToInt32(obj3.name), obj3.lat, obj3.lng)); MainForm2.IdReportHS.Add(obj3.name, "no address"); } bool retrynew = true; int cntmax = 0; foreach (String obj in MainForm2.IdReportHS.Keys) numbers.Add(obj); while (retrynew) { cntmax++; retrynew = false; foreach (String obj in numbers) { if ((String)MainForm2.IdReportHS[obj] == "no address") { SM.Debug("Sta 180 msec"); Thread.Sleep(180); retrynew = true; } } if (cntmax > 10) retrynew = false; } } } catch (Exception ex) { SM.Debug("Erorr on compute adress for report:" + ex.ToString()); } } int countStops = -1; long stoptime, starttime; StopData tmpData = null; Int32 RowNumber = 0; var Ret = new List(); Int64 diffTime; foreach (Stops obj3 in calcStop.StopsList) { countStops++; if (obj3.type == car_state_e.CAR_STOP) { tmpData = new StopData(); try { RowNumber++; tmpData.Data = (new ConvertDT().GetDTLocalFromSeconds(obj3.start)).Date.ToShortDateString(); tmpData.Time = new ConvertDT().TimeOfDayHHMMLocal((Int32)obj3.start,!MainForm2.is24hours); if (!MainForm2.LATLNGforDinamicReports) { if ((MainForm2.MapType == MapTYPE.Google) || (MainForm2.MapType == MapTYPE.ArcGis)) tmpData.Location = MainForm2.IdReportHS[obj3.name].ToString(); } else tmpData.Location = "LAT:" + Math.Round(obj3.lat, 5).ToString() + " , LNG:" + Math.Round(obj3.lng, 5).ToString(); stoptime = obj3.stop; starttime = obj3.start; if (countStops < (calcStop.StopsList.Count - 1)) { if (((Stops)(calcStop.StopsList[countStops + 1])).type == car_state_e.CAR_START) stoptime = ((Stops)(calcStop.StopsList[countStops + 1])).stop; } diffTime = stoptime - starttime; Int32 Hour = (Int32)(diffTime / 3600); Int32 Minute = (Int32)((diffTime - Hour * 3600) / 60); String toReturn = ""; if (Hour >= 10) toReturn = toReturn + Hour.ToString() + ":"; else toReturn = toReturn + "0" + Hour.ToString() + ":"; if (Minute >= 10) toReturn = toReturn + Minute.ToString(); else toReturn = toReturn + "0" + Minute.ToString(); tmpData.Duration = toReturn; } catch (Exception ex) { SM.Debug("EX:"+ex.ToString()); } Ret.Add(tmpData); } } //de la google address if ((MainForm2.MapType == MapTYPE.Google) || (MainForm2.MapType == MapTYPE.ArcGis)) { foreach (String obj in numbers) MainForm2.IdReportHS.Remove(obj); numbers.Clear(); } return Ret; } else // aici prelucrez date cand e raport de history { return MainForm2.HistDataReport; } } } [DataObject] public class FleetDataObj { [DataObjectMethod(DataObjectMethodType.Select)] public List GetALL() { Double distance = .001f; Double AllDistance = .001f; var Ret = new List(); if (!MainForm2.IsSMSLocationNotFleet) { foreach (FleetIdandPos veh in MainForm2.FleetPosList) { CalcStops calcStop = new CalcStops(null, true);//mapControl calcStop.get_position(veh.Position); try { MainForm2.NameReport = veh.Name; calcStop.calculate_zone(); calcStop.calc_zone_with_delta2(); calcStop.create_stop_list(); } catch (Exception ex) { SM.Debug("Database connection failed" + ex.ToString()); } if (MainForm2.StartStop) { calcStop.StartStopCalc(); calcStop.StartStopCalcPosition(); } //distance AllDistance = 0; Boolean first = true; distance = 0; Int32 timeStart = 0, timeStop = 0, oldStop = 0; if (calcStop.StopsList.Count > 1) { Stops prevObj = null; foreach (Stops obj in calcStop.StopsList) { if (prevObj != null) { if (!((prevObj.type == car_state_e.CAR_STOP) && (obj.type == car_state_e.CAR_START))) { AllDistance += distance; if (first) { timeStart = prevObj.stop; first = false; } else timeStart = oldStop; timeStop = obj.start; oldStop = obj.stop; AllDistance += calcStop.calcDistance(timeStart, timeStop); //DriveList.Add(distance); } else { first = true; } } prevObj = obj; } } int startnr = 0; Stops prevStopObj = null; foreach (Stops obj in calcStop.StopsList) { if (obj.type == car_state_e.CAR_START) startnr++; if (prevStopObj != null) if ((prevStopObj.type == car_state_e.CAR_STOP) && (obj.type == car_state_e.CAR_STOP)) startnr++; prevStopObj = obj; } FleetData tmpData = new FleetData(); tmpData.Name = veh.Name; if (MainForm2.isInMile) tmpData.Distance = (Math.Round(((AllDistance * 0.621371192) * 1000)) / 1000).ToString(); else tmpData.Distance = AllDistance.ToString(); if ((calcStop.StopsList.Count == 0) || (calcStop.StopsList.Count == 1)) tmpData.Trips = "0"; else tmpData.Trips = startnr.ToString(); tmpData.Start = ""; tmpData.Stop = ""; if ((calcStop.StopsList.Count != 0) && (calcStop.StopsList.Count != 1)) { if (MainForm2.is24hours) { tmpData.Start = (new ConvertDT().GetDTLocalFromSeconds(((Stops)(calcStop.StopsList[0])).stop)).ToString("MM/dd/yyyy HH:mm:ss"); tmpData.Stop = (new ConvertDT().GetDTLocalFromSeconds(((Stops)(calcStop.StopsList[calcStop.StopsList.Count - 1])).start)).ToString("MM/dd/yyyy HH:mm:ss"); } else { tmpData.Start = (new ConvertDT().GetDTLocalFromSeconds(((Stops)(calcStop.StopsList[0])).stop)).ToString("MM/dd/yyyy hh:mm:ss tt"); tmpData.Stop = (new ConvertDT().GetDTLocalFromSeconds(((Stops)(calcStop.StopsList[calcStop.StopsList.Count - 1])).start)).ToString("MM/dd/yyyy hh:mm:ss tt"); } } Ret.Add(tmpData); } } else { foreach (SMS_Location sms_obj in MainForm2.SMSLocList) { FleetData tmpData = new FleetData(); tmpData.Name = sms_obj.Name; tmpData.Start = sms_obj.Data; tmpData.Stop = sms_obj.Address; tmpData.Trips = sms_obj.Time; tmpData.Distance = sms_obj.Text_mess; Ret.Add(tmpData); } } return Ret; } } }