Пример #1
0
        private IndividualReport[] CreateNewDayReport()
        {
            IndividualReport[] rp;

            rp = new IndividualReport[10];
            for (int i = 0; i < rp.Length; i++)
            {
                rp[i]        = new IndividualReport();
                rp[i].driver = i;
            }

            return(rp);
        }
Пример #2
0
        private void outputReportToKMLBtn_Click(object sender, EventArgs e)
        {
            string       fileName;
            DialogResult res;

            if (reports.Count == 0)
            {
                return;
            }
            saveFileDialog1.Filter = "KML file (*.KML)|*.KML";
            res = saveFileDialog1.ShowDialog();
            if (res != DialogResult.OK)
            {
                return;
            }
            fileName = saveFileDialog1.FileName;
            IndividualReport.GenerateKML(cfg, reports, fileName);
            //"Completed! The KML file is saved at: "
            MessageBox.Show(KML_SAVE_SUCCESS_STR.Text + fileName, APP_CAPTION_STR.Text);
        }
Пример #3
0
        //public static void GenerateKML(List<IndividualReport[]> reports, string filePath)
        //{

        //    StreamWriter sw = new StreamWriter(filePath);
        //    sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        //    sw.WriteLine("<kml xmlns=\"http://earth.google.com/kml/2.1\">");
        //    sw.WriteLine("<Document>");

        //    sw.WriteLine("<Placemark>");
        //    sw.WriteLine("<color>ffffff00</color>");
        //    sw.WriteLine("<width>6</width>");
        //    sw.WriteLine("<MultiGeometry>");
        //    sw.WriteLine("<LineString>");
        //    sw.WriteLine("<coordinates>");
        //    foreach (IndividualReport[] reportArr in reports)
        //    {
        //        foreach (IndividualReport report in reportArr)
        //        {
        //            report.speedRecords.ForEach(spr =>
        //            {
        //                if (spr.record.lat != 0 || spr.record.lng != 0)
        //                {
        //                    sw.Write(Lib.latlngToString(spr.record.lng) + "," + Lib.latlngToString(spr.record.lat) + " ");
        //                }
        //            });
        //        }
        //    }
        //    sw.WriteLine("</coordinates>");
        //    sw.WriteLine("</LineString>");
        //    sw.WriteLine("</MultiGeometry>");
        //    sw.WriteLine("</Placemark>");


        //    sw.WriteLine("<Folder>");
        //    foreach (IndividualReport[] reportArr in reports)
        //    {
        //        foreach (IndividualReport report in reportArr)
        //        {
        //            report.speedRecords.ForEach(spr =>
        //            {
        //                if (spr.record.lat != 0 || spr.record.lng != 0)
        //                {
        //                    sw.WriteLine("<Placemark>");
        //                    sw.WriteLine("<name>" + spr.record.currentTime.hour + ":" + spr.record.currentTime.min + ":" + spr.record.currentTime.sec + " " + spr.date.Day + "/" + spr.date.Month + "/" + spr.date.Year + " " + spr.record.speed.ToString(".#") + " km/h</name>");
        //                    sw.WriteLine("<Point>");
        //                    sw.WriteLine("<coordinates>" + Lib.latlngToString(spr.record.lng) + ", " + Lib.latlngToString(spr.record.lat) + ",0.0</coordinates>");
        //                    sw.WriteLine("</Point>");
        //                    sw.WriteLine("</Placemark>");
        //                }
        //            });
        //        }
        //    }

        //    sw.WriteLine("</Folder>");
        //    sw.WriteLine("</Document>");
        //    sw.WriteLine("</kml>");

        //    sw.Close();
        //}

        public static void GenerateKML(TRACKER_CONFIG_DATA cfg, List <IndividualReport[]> reports, string filePath)
        {
            StreamWriter  sw;
            DateTime      beginTime, endTime;
            MySpeedRecord beginReport, endReport;
            int           beginDriver, endDriver;

            if ((reports == null) && (reports.Count > 0))
            {
                return;
            }

            sw = new StreamWriter(filePath);
            sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
            sw.WriteLine("<kml>");
            sw.WriteLine("<Document>");
            sw.WriteLine("<Style id=\"s_ylw-pushpin\"><IconStyle><scale>1.1</scale><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href></Icon><hotSpot x=\"20\" y=\"2\" xunits=\"pixels\" yunits=\"pixels\"/></IconStyle></Style>");
            sw.WriteLine("<Style id=\"s_blue-pushpin\"><IconStyle><scale>1.1</scale><Icon><href>https://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href></Icon><hotSpot x=\"20\" y=\"2\" xunits=\"pixels\" yunits=\"pixels\"/></IconStyle></Style>");
            sw.WriteLine("<Style id=\"s_ylw-pushpin_hl\"><IconStyle><scale>1.3</scale><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/red-pushpin.png</href></Icon><hotSpot x=\"20\" y=\"2\" xunits=\"pixels\" yunits=\"pixels\"/></IconStyle></Style>");
            sw.WriteLine("<StyleMap id=\"m_ylw-pushpin\"><Pair><key>normal</key><styleUrl>#s_ylw-pushpin</styleUrl></Pair><Pair><key>highlight</key><styleUrl>#s_ylw-pushpin_hl</styleUrl></Pair><Pair><key>highlight1</key><styleUrl>#s_blue-pushpin</styleUrl></Pair></StyleMap>");

            beginTime   = DateTime.MaxValue;
            beginReport = null;
            beginDriver = 0;
            for (int i = 0; i < 10; i++)
            {
                IndividualReport report = reports[0][i];
                if ((report.speedRecords != null) && (report.speedRecords.Count > 0))
                {
                    if (report.speedRecords[0].GetCurrentTime() < beginTime)
                    {
                        beginTime   = report.speedRecords[0].GetCurrentTime();
                        beginReport = report.speedRecords[0];
                        beginDriver = i;
                    }
                }
            }
            endTime   = DateTime.MinValue;
            endReport = null;
            endDriver = 0;
            for (int i = 0; i < 10; i++)
            {
                IndividualReport report = reports[reports.Count - 1][i];
                if ((report.speedRecords != null) && (report.speedRecords.Count > 0))
                {
                    if (report.speedRecords[report.speedRecords.Count - 1].GetCurrentTime() > endTime)
                    {
                        endTime   = report.speedRecords[report.speedRecords.Count - 1].GetCurrentTime();
                        endReport = report.speedRecords[report.speedRecords.Count - 1];
                        endDriver = i;
                    }
                }
            }

            sw.WriteLine("<Placemark>");
            sw.WriteLine("<name>Điểm xuất phát : " + cfg.plateNo + "</name>");
            sw.WriteLine("<description>");
            sw.WriteLine("Thời gian : " + beginReport.GetCurrentTime().ToString("HH:mm:ss dd/MM/yyyy").Replace('-', '/') + "<br/>");
            sw.WriteLine("Lái xe : " + cfg.driverList[beginDriver].driverName + "<br/>");
            sw.WriteLine("Biển số : " + cfg.plateNo + "<br/>");
            sw.WriteLine("Vận tốc : " + beginReport.record.speed + "<br/>");
            sw.WriteLine("No.Đóng mở : " + beginReport.record.doorOpenCount + "<br/>");
            sw.WriteLine("No.Quá tốc : " + beginReport.record.overSpeedCount + "<br/>");
            sw.WriteLine("No.Dừng đỗ : " + beginReport.record.parkingCount + "<br/>");
            sw.WriteLine("</description>");
            sw.WriteLine("<styleUrl>#s_blue-pushpin</styleUrl>");
            sw.WriteLine("<Point>");
            sw.WriteLine("<coordinates>" + beginReport.record.lng + "," + beginReport.record.lat + "</coordinates>");
            sw.WriteLine("</Point>");
            sw.WriteLine("</Placemark>");

            foreach (IndividualReport[] reportArr in reports)
            {
                for (int i = 0; i < 10; i++)
                {
                    IndividualReport report = reportArr[i];
                    report.speedRecords.ForEach(spr =>
                    {
                        if (spr.record.lat != 0 || spr.record.lng != 0)
                        {
                            sw.WriteLine("<Placemark>");
                            sw.WriteLine("<name>Biển số xe : " + cfg.plateNo + "</name>");
                            sw.WriteLine("<description>");
                            sw.WriteLine("Thời gian : " + spr.GetCurrentTime().ToString("HH:mm:ss dd/MM/yyyy").Replace('-', '/') + "<br/>");
                            sw.WriteLine("Lái xe : " + cfg.driverList[i].driverName + "<br/>");
                            sw.WriteLine("Biển số : " + cfg.plateNo + "<br/>");
                            sw.WriteLine("Vận tốc : " + spr.record.speed + "<br/>");
                            sw.WriteLine("No.Đóng mở : " + spr.record.doorOpenCount + "<br/>");
                            sw.WriteLine("No.Quá tốc : " + spr.record.overSpeedCount + "<br/>");
                            sw.WriteLine("No.Dừng đỗ : " + spr.record.parkingCount + "<br/>");
                            sw.WriteLine("</description>");
                            sw.WriteLine("<styleUrl>#s_ylw-pushpin</styleUrl>");
                            sw.WriteLine("<Point>");
                            sw.WriteLine("<coordinates>" + spr.record.lng + "," + spr.record.lat + "</coordinates>");
                            sw.WriteLine("</Point>");
                            sw.WriteLine("</Placemark>");
                        }
                    });
                }
            }

            sw.WriteLine("<Placemark>");
            sw.WriteLine("<name>Điểm kết thúc : " + cfg.plateNo + "</name>");
            sw.WriteLine("<description>");
            sw.WriteLine("Thời gian : " + endReport.GetCurrentTime().ToString("HH:mm:ss dd/MM/yyyy").Replace('-', '/') + "<br/>");
            sw.WriteLine("Lái xe : " + cfg.driverList[endDriver].driverName + "<br/>");
            sw.WriteLine("Biển số : " + cfg.plateNo + "<br/>");
            sw.WriteLine("Vận tốc : " + endReport.record.speed + "<br/>");
            sw.WriteLine("No.Đóng mở : " + endReport.record.doorOpenCount + "<br/>");
            sw.WriteLine("No.Quá tốc : " + endReport.record.overSpeedCount + "<br/>");
            sw.WriteLine("No.Dừng đỗ : " + endReport.record.parkingCount + "<br/>");
            sw.WriteLine("</description>");
            sw.WriteLine("<styleUrl>#s_blue-pushpin</styleUrl>");
            sw.WriteLine("<Point>");
            sw.WriteLine("<coordinates>" + endReport.record.lng + "," + endReport.record.lat + "</coordinates>");
            sw.WriteLine("</Point>");
            sw.WriteLine("</Placemark>");

            sw.WriteLine("<Placemark>");
            sw.WriteLine("<name>Route</name>");
            sw.WriteLine("<color>ff00ffff</color>");
            sw.WriteLine("<width>6</width>");
            sw.WriteLine("<MultiGeometry>");
            sw.WriteLine("<LineString>");
            sw.WriteLine("<coordinates>");
            foreach (IndividualReport[] reportArr in reports)
            {
                foreach (IndividualReport report in reportArr)
                {
                    report.speedRecords.ForEach(spr =>
                    {
                        if (spr.record.lat != 0 || spr.record.lng != 0)
                        {
                            sw.Write(spr.record.lng + "," + spr.record.lat + ",0.000000" + Environment.NewLine);
                        }
                    });
                }
            }
            sw.WriteLine("</coordinates>");
            sw.WriteLine("</LineString>");
            sw.WriteLine("</MultiGeometry>");
            sw.WriteLine("</Placemark>");

            sw.WriteLine("</Document>");
            sw.WriteLine("</kml>");

            sw.Close();
        }