Beispiel #1
0
        public List <SitesVM> GetSitesFromTable(DataTable TotalSites)
        {
            DirectoryHandler dh              = new DirectoryHandler();
            List <SitesVM>   lstSites        = new List <SitesVM>();
            string           ApplicationPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Substring(8);
            string           AppPath         = ApplicationPath.Remove(ApplicationPath.Length - 24);
            string           Profile         = ApplicationPath.Remove(ApplicationPath.Length - 24);

            if (TotalSites.Rows.Count > 0)
            {
                SitesVM loSite;
                for (int i = 0; i < TotalSites.Rows.Count; i++)
                {
                    loSite           = new SitesVM();
                    loSite.SiteId    = Convert.ToInt64(TotalSites.Rows[i]["SiteId"]);
                    loSite.SiteCode  = TotalSites.Rows[i]["SiteCode"].ToString();
                    loSite.ClusterId = TotalSites.Rows[i]["ClusterId"].ToString();
                    if (TotalSites.Columns.Contains("Scope"))
                    {
                        loSite.Scope = TotalSites.Rows[i]["Scope"].ToString();
                    }
                    if (TotalSites.Columns.Contains("ScopeId"))
                    {
                        loSite.ScopeId = Convert.ToInt64(TotalSites.Rows[i]["ScopeId"].ToString());
                    }



                    loSite.Latitude  = (!string.IsNullOrEmpty(TotalSites.Rows[i]["Latitude"].ToString())) ? Convert.ToDouble(TotalSites.Rows[i]["Latitude"]) : 0;
                    loSite.Longitude = (!string.IsNullOrEmpty(TotalSites.Rows[i]["Longitude"].ToString())) ? Convert.ToDouble(TotalSites.Rows[i]["Longitude"]) : 0;
                    loSite.Tester    = TotalSites.Rows[i]["Tester"] == DBNull.Value ? "" : TotalSites.Rows[i]["Tester"].ToString();
                    loSite.TesterId  = (TotalSites.Columns.Contains("TesterId")) ? TotalSites.Rows[i]["TesterId"] == DBNull.Value ? 0 : Convert.ToInt32(TotalSites.Rows[i]["TesterId"]) : 0;
                    if (!string.IsNullOrEmpty(TotalSites.Rows[i]["SubmittedOn"].ToString()))
                    {
                        loSite.SubmittedOn = Convert.ToDateTime(TotalSites.Rows[i]["SubmittedOn"]);
                    }
                    if (!string.IsNullOrEmpty(TotalSites.Rows[i]["ReceivedOn"].ToString()))
                    {
                        loSite.ReceivedOn = Convert.ToDateTime(TotalSites.Rows[i]["ReceivedOn"]);
                    }
                    loSite.WoRefNo = TotalSites.Rows[i]["WoRefNo"].ToString();
                    if (TotalSites.Rows[i]["AssignedOn"] != DBNull.Value)
                    {
                        loSite.AssignedOn = Convert.ToDateTime(TotalSites.Rows[i]["AssignedOn"]);
                    }
                    if (TotalSites.Rows[i]["CompletedOn"] != DBNull.Value)
                    {
                        loSite.CompletedOn = Convert.ToDateTime(TotalSites.Rows[i]["CompletedOn"]);
                    }



                    // break point
                    if (TotalSites.Columns.Contains("DriveCompletedOn"))
                    {
                        if (TotalSites.Rows[i]["DriveCompletedOn"] != DBNull.Value)
                        {
                            loSite.DriveCompletedOn = Convert.ToDateTime(TotalSites.Rows[i]["DriveCompletedOn"]);
                        }
                    }

                    if (TotalSites.Rows[i]["ScheduledOn"] != DBNull.Value)
                    {
                        loSite.ScheduledOn = Convert.ToDateTime(TotalSites.Rows[i]["ScheduledOn"]);
                    }

                    string TesterPicture = TotalSites.Rows[i]["Status"].ToString();

                    loSite.Status        = TotalSites.Rows[i]["Status"].ToString();
                    loSite.StatusName    = TotalSites.Rows[i]["StatusName"].ToString();
                    loSite.StatusKeyCode = TotalSites.Rows[i]["StatusKeyCode"].ToString();

                    if (TotalSites.Columns.Contains("IsDownloaded") && !string.IsNullOrEmpty(TotalSites.Rows[i]["IsDownloaded"].ToString()))
                    {
                        loSite.IsDownloaded = Convert.ToBoolean(TotalSites.Rows[i]["IsDownloaded"].ToString());
                    }
                    if (TotalSites.Columns.Contains("ReportSubmittedOn") && !string.IsNullOrEmpty(TotalSites.Rows[i]["ReportSubmittedOn"].ToString()))
                    {
                        loSite.ReportSubmittedOn = Convert.ToDateTime(TotalSites.Rows[i]["ReportSubmittedOn"].ToString());
                    }

                    //ReportSubmittedOn
                    loSite.Market = TotalSites.Rows[i]["Market"].ToString();
                    loSite.Region = TotalSites.Rows[i]["Region"].ToString();
                    loSite.Client = TotalSites.Rows[i]["ClientName"].ToString();
                    if (TotalSites.Columns.Contains("ClientPrefix") && !string.IsNullOrEmpty(TotalSites.Rows[i]["ClientPrefix"].ToString()))
                    {
                        loSite.ClientPrefix = TotalSites.Rows[i]["ClientPrefix"].ToString();
                    }
                    if (TotalSites.Columns.Contains("IsActive") && !string.IsNullOrEmpty(TotalSites.Rows[i]["IsActive"].ToString()))
                    {
                        loSite.IsActive = Convert.ToBoolean(TotalSites.Rows[i]["IsActive"].ToString());
                    }

                    //

                    loSite.ZIndex = 1;

                    string cnt = string.Empty;
                    if (loSite.StatusKeyCode == "N/A")
                    {
                        Profile = "/Content/Images/Profile/home-" + loSite.TesterId + ".png";
                        //  string   NewProfilePath = ProfilePath + Profile;
                        if (dh.FileExist(AppPath + Profile))
                        {
                            loSite.MarkerImagePath = Profile;
                        }
                        else
                        {
                            loSite.MarkerImagePath = "/Content/Images/Profile/home-default.png";
                        }

                        cnt = "<b>Tester: </b> " + loSite.Tester + "</br>";
                    }
                    else
                    {
                        if (loSite.StatusKeyCode == "PENDING_SCHEDULED")
                        {
                            loSite.MarkerImagePath = "/Content/Images/Common/PENDING_SCHEDULED.png";//"http://maps.google.com/mapfiles/ms/icons/yellow-dot.png";
                            loSite.MarkerTitle     = "PENDING_SCHEDULED";
                        }
                        else if (loSite.StatusKeyCode == "COMPLETED")
                        {
                            loSite.MarkerImagePath = "/Content/Images/Common/COMPLETED_MARKER.png";// "http://maps.google.com/mapfiles/ms/icons/green-dot.png";
                            loSite.MarkerTitle     = "COMPLETED";
                        }
                        else if (loSite.StatusKeyCode == "IN_PROGRESS")
                        {
                            loSite.MarkerImagePath = "/Content/Images/Common/IN_PROGRESS_MARKER.png";
                            loSite.MarkerTitle     = "IN_PROGRESS";
                        }
                        else if (loSite.StatusKeyCode == "REPORT_SUBMITTED")
                        {
                            loSite.MarkerImagePath = "/Content/Images/Common/REPORT_SUBMITTED_MARKER.png";// "http://maps.google.com/mapfiles/ms/icons/green-dot.png";
                            loSite.MarkerTitle     = "REPORT_SUBMITTED";
                        }
                        else if (loSite.StatusKeyCode == "DRIVE_COMPLETED")
                        {
                            loSite.MarkerImagePath = "/Content/Images/Common/DRIVE_COMPLETED_MARKER.png";// "http://maps.google.com/mapfiles/ms/icons/green-dot.png";
                            loSite.MarkerTitle     = "DRIVE_COMPLETED";
                        }
                        else if (loSite.StatusKeyCode == "PENDING_WITH_ISSUE")
                        {
                            loSite.MarkerImagePath = "/Content/Images/Common/PENDING_WITH_ISSUE_MARKER.png"; //"http://maps.google.com/mapfiles/ms/icons/red-dot.png";
                            loSite.MarkerTitle     = "PENDING_WITH_ISSUE";
                        }
                        else if (loSite.StatusKeyCode == "SCHEDULED")
                        {
                            loSite.MarkerImagePath = "/Content/Images/Common/SCHEDULED_MARKER.png";
                            loSite.MarkerTitle     = "SCHEDULED";

                            if (!string.IsNullOrEmpty(TotalSites.Rows[i]["TesterPicture"].ToString()))
                            {
                                string imgUrl = TotalSites.Rows[i]["TesterPicture"].ToString().Replace("u-", "thumb-");
                                if (imgUrl == "/Content/Images/Profile/Default.svg")
                                {
                                    loSite.MarkerImagePath = "/Content/Images/Profile/defaultThumb.jpg";
                                }
                                else
                                {
                                    loSite.MarkerImagePath = imgUrl;
                                }
                            }
                        }
                        else
                        {
                            loSite.MarkerImagePath = "http://maps.google.com/mapfiles/ms/icons/yellow-dot.png";
                            loSite.MarkerTitle     = loSite.SiteCode;
                        }

                        //cnt = "<div>" + "<b>Site Code: </b> " + loSite.SiteCode + "</br>" + "<b>Region: </b>" + loSite.Region + "</br>" + "<b>Market: </b> " + loSite.Market + "</br>" + "<b>Tester: </b> " + loSite.Tester + "</br>";
                        //cnt = (loSite.SubmittedOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00") ? cnt + "<b>Submitted: </b> " + loSite.SubmittedOn.ToString("MM/dd/yyyy HH:mm") + "</br>" : cnt + "<b>Submitted: </b> " + loSite.ScheduledOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        //if (loSite.ScheduledOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00")
                        //{
                        //    cnt = cnt + "<b>Scheduled: </b> " + loSite.ScheduledOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        //}
                        //else
                        //{
                        //    cnt = cnt + "<b>Scheduled: </b> " + "</br>";
                        //}
                        //if (loSite.CompletedOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00")
                        //{
                        //    cnt = cnt + "<b>Completed: </b> " + loSite.CompletedOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        //}
                        //else
                        //{
                        //    cnt = cnt + "<b>Completed: </b> " + "</br>";
                        //}
                        //cnt = cnt + "</div>";

                        //---------------------------------------------
                        cnt = "<div>" +
                              "<b>Site Code: </b> " + loSite.SiteCode + "</br>" +
                              "<b>Site Status: </b> " + loSite.StatusName + "</br>" +
                              "<b>Site Type: </b> " + loSite.SiteType + "</br>" +
                              "<b>Scope: </b> " + loSite.Scope + "</br>" +
                              "<b>Region: </b>" + loSite.Region + "</br>" +
                              "<b>Market: </b> " + loSite.Market + "</br>" +
                              "<b>Tester: </b> " + loSite.Tester + "</br>";

                        /*Received Date Start*/
                        if (loSite.ReceivedOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00")
                        {
                            cnt = cnt + "<b>Received: </b> " + loSite.ReceivedOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        }
                        else
                        {
                            cnt = cnt + "<b>Received: </b> " + "</br>";
                        }
                        /*Received Date End*/
                        cnt = (loSite.SubmittedOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00") ? cnt + "<b>Submitted: </b> " + loSite.SubmittedOn.ToString("MM/dd/yyyy HH:mm") + "</br>" : cnt + "<b>Submitted: </b> " + loSite.ScheduledOn.ToString("MM/dd/yyyy HH:mm") + "</br>";

                        if (loSite.ScheduledOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00")
                        {
                            cnt = cnt + "<b>Scheduled: </b> " + loSite.ScheduledOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        }
                        else
                        {
                            cnt = cnt + "<b>Scheduled: </b> " + "</br>";
                        }
                        var cd = loSite.DriveCompletedOn.ToString("MM/dd/yyyy HH:mm");
                        /*Drive Completed Date Start*/
                        if (loSite.DriveCompletedOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00")
                        {
                            cnt = cnt + "<b>Drive Completed: </b> " + loSite.DriveCompletedOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        }
                        else
                        {
                            cnt = cnt + "<b>Drive Completed: </b> " + "</br>";
                        }
                        /*Drive Completed Date End*/

                        /*Report Submitted Date Start*/
                        if (loSite.ReportSubmittedOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00")
                        {
                            cnt = cnt + "<b>Report Submitted: </b> " + loSite.ReportSubmittedOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        }
                        else
                        {
                            cnt = cnt + "<b>Report Submitted: </b> " + "</br>";
                        }
                        /*Report Submitted Date End*/
                        if (loSite.CompletedOn.ToString("MM/dd/yyyy HH:mm") != "01/01/0001 00:00")
                        {
                            cnt = cnt + "<b>Completed: </b> " + loSite.CompletedOn.ToString("MM/dd/yyyy HH:mm") + "</br>";
                        }
                        else
                        {
                            cnt = cnt + "<b>Completed: </b> " + "</br>";
                        }
                        cnt = cnt + "</div>";
                    }


                    loSite.InfoWindowContent = cnt;

                    lstSites.Add(loSite);
                }
            }
            return(lstSites);
        }
Beispiel #2
0
        public Response DriveRoute(DriveRoute driveRoute)
        {
            List <Cordinates> cordinates = driveRoute.cordinates;
            List <Cordinates> pathJson   = driveRoute.pathJson;

            Response         res = new Response();
            DirectoryHandler dh  = new DirectoryHandler();

            string CompleteKml = null;

            string ClientPrefix = "";
            string SiteCode     = "";
            long   RouteId      = 0;
            string Delete       = "";

            long   SiteId   = 0;
            string TestType = "";
            int    ScopeId  = 0;
            long   UserId   = 0;
            string Filter   = "";



            ClientPrefix = driveRoute.ClientPrefix;
            SiteCode     = driveRoute.SiteCode;
            RouteId      = driveRoute.RouteId;
            Delete       = "";

            SiteId   = driveRoute.SiteId;
            TestType = driveRoute.TestType;
            ScopeId  = driveRoute.ScopeId;
            UserId   = driveRoute.UserId;
            Filter   = "Insert";

            KML km = new KML();

            try
            {
                CompleteKml += km.Open("Routes", "Routes For Site");

                int count = 1;
                #region Existing File Coordinates
                string Path = "/Content/AirViewLogs/" + ClientPrefix + "/" + SiteCode;
                if (dh.FileExist(HttpContext.Current.Server.MapPath("~" + Path + "/route-" + RouteId + ".kml")))
                {
                    string text;
                    var    fileStream = new FileStream(HttpContext.Current.Server.MapPath("~" + Path + "/route-" + RouteId + ".kml"), FileMode.Open, FileAccess.Read);
                    using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
                    {
                        text = streamReader.ReadToEnd();
                    }

                    MyString ms           = new MyString();
                    string   MyPlacemarks = "";
                    string[] MyPlacemarksSplit;
                    int      MyIndex = 5782;
                    if (Delete != "")
                    {
                        MyPlacemarks      = ms.BetweenTag(text, "Placemark", "&");
                        MyPlacemarksSplit = MyPlacemarks.Split('&');
                        int counter = 0;

                        foreach (var item in MyPlacemarksSplit)
                        {
                            if (item.Contains(Delete))
                            {
                                MyIndex = counter;
                            }
                            counter++;
                        }
                    }

                    string   Cordinate = ms.BetweenTag(text, "coordinates", "&");
                    string   Colors    = ms.BetweenTag(text, "color", "&");
                    string[] ColorsArr = Colors.Split('&');
                    //Cordinate = Cordinate.Replace(",0", ",");
                    //Cordinate = Cordinate.Replace(",-", "-");
                    //Cordinate = Cordinate.Replace("-", ",-");
                    //Cordinate = Cordinate.Replace(",,", ",");
                    string[] Tags = Cordinate.Split('&');
                    string   cords;;
                    string[] Cordinates;

                    for (int i = 0; i < Tags.Length; i++)
                    {
                        if (Delete == "" || (i != MyIndex && MyIndex != 5782))
                        {
                            if (Tags[i].Trim().Length > 0)
                            {
                                cords      = null;
                                Cordinates = Tags[i].Split('\n');
                                for (int j = 0; j < Cordinates.Length; j++)
                                {
                                    if (Cordinates[j].Trim().Length > 0)
                                    {
                                        cords += Cordinates[j] + "0\n";
                                    }
                                }
                                CompleteKml += km.Style("LineId" + count, "LineStyle", "color", "FFA9A9A9", "width", "4");
                                CompleteKml += km.Placemark("LineId" + count, "LineId" + count, "LineString", "relative", cords);
                                count++;
                            }
                        }
                    }
                }
                #endregion


                if (cordinates != null || Delete != "")
                {
                    if (Delete == "")
                    {
                        //  foreach (var jk in cordinates)
                        // {
                        string cords = null;

                        string plotColor = "FFA9A9A9"; //(!string.IsNullOrEmpty(r.Color)) ? r.Color.Replace("#", "") :
                        plotColor = "ff" + plotColor.Substring(4, 2) + plotColor.Substring(2, 2) + plotColor.Substring(0, 2);

                        CompleteKml += km.Style("LineId" + count, "LineStyle", "color", plotColor, "width", "4");
                        foreach (var cor in cordinates)
                        {
                            cords += cor.location.lng + "," + cor.location.lat + ",0\n";
                        }
                        CompleteKml += km.Placemark("LineId" + count, "LineId" + count, "LineString", "relative", cords);
                        // CompleteKml += km.Placemarks("LineId" + count, "#LineStyle", "relativeToGround", cords);
                        count++;
                        // }
                    }

                    AV_DriveRoutesBL drb = new AV_DriveRoutesBL();
                    AV_DriveRoutes   dr  = new AV_DriveRoutes();
                    dr.CreatedDate = DateTime.Now;
                    dr.RouteId     = RouteId;
                    dr.SiteId      = Convert.ToInt64(SiteId);
                    dr.CreatedBy   = UserId;
                    dr.RoutePath   = Path;
                    if (TestType.Length > 1)
                    {
                        dr.TestType = TestType; //.Remove(TestType.Length - 1);
                    }

                    dr.ScopeId = ScopeId;
                    RouteId    = drb.Manage(Filter, dr);

                    if (RouteId > 0)
                    {
                        res.Status = "success";
                        res.Value  = RouteId;

                        CompleteKml += km.Close();
                        dh.CreateDirectory(HttpContext.Current.Server.MapPath(Path));
                        km.SaveKml2(CompleteKml, "route-" + RouteId, HttpContext.Current.Server.MapPath(Path));
                        if (pathJson != null)
                        {
                            string jsonpath = "~" + Path;
                            string fname    = HttpContext.Current.Server.MapPath(jsonpath);
                            if (!Directory.Exists(fname))
                            { // if it doesn't exist, create
                                System.IO.Directory.CreateDirectory(fname);
                            }
                            string json = JsonConvert.SerializeObject(pathJson.ToArray());

                            //write string to file
                            System.IO.File.WriteAllText(fname + "/route-" + RouteId + ".txt", json);
                        }
                    }

                    GC.Collect();
                    GC.WaitForPendingFinalizers();


                    if (Delete == "")
                    {
                        res.Message = "Drive Route Planned Successfully.";
                    }
                    else
                    {
                        res.Message = "Drive Route Deleted Successfully.";
                    }
                }
                else
                {
                    res.Status  = "danger";
                    res.Message = "No Route Selected.";
                }
            }
            catch (Exception ex)
            {
                res.Status  = "danger";
                res.Message = ex.Message;
            }

            //return Json(res, JsonRequestBehavior.AllowGet);
            return(res);
        }