public PolSourceObservationModel GetPolSourceObservationModelExistDB(PolSourceObservationModel polSourceObservationModel)
        {
            PolSourceObservationModel polSourceObservationModelRet = (from c in db.PolSourceObservations
                                                                      let PolSourceSiteTVItemID = (from p in db.PolSourceSites where p.PolSourceSiteID == c.PolSourceSiteID select p.PolSourceSiteTVItemID).FirstOrDefault()
                                                                                                  let tvText = (from cl in db.TVItemLanguages where cl.Language == (int)LanguageRequest && cl.TVItemID == PolSourceSiteTVItemID select cl.TVText).FirstOrDefault <string>()
                                                                                                               let contactTVText = (from cl in db.TVItemLanguages where cl.Language == (int)LanguageRequest && cl.TVItemID == c.ContactTVItemID select cl.TVText).FirstOrDefault <string>()
                                                                                                                                   where c.PolSourceSiteID == polSourceObservationModel.PolSourceSiteID &&
                                                                                                                                   c.ObservationDate_Local == polSourceObservationModel.ObservationDate_Local
                                                                                                                                   select new PolSourceObservationModel
            {
                Error = "",
                PolSourceObservationID = c.PolSourceObservationID,
                DBCommand = (DBCommandEnum)c.DBCommand,
                PolSourceSiteID = c.PolSourceSiteID,
                PolSourceSiteTVItemID = PolSourceSiteTVItemID,
                PolSourceSiteTVText = tvText,
                ObservationDate_Local = c.ObservationDate_Local,
                ContactTVItemID = c.ContactTVItemID,
                DesktopReviewed = c.DesktopReviewed,
                ContactTVText = contactTVText,
                Observation_ToBeDeleted = c.Observation_ToBeDeleted,
                LastUpdateDate_UTC = c.LastUpdateDate_UTC,
                LastUpdateContactTVItemID = c.LastUpdateContactTVItemID,
            }).FirstOrDefault <PolSourceObservationModel>();

            if (polSourceObservationModelRet == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.PolSourceObservation, ServiceRes.PolSourceSiteTVItemID + "," + ServiceRes.ObservationDate_Local, polSourceObservationModel.PolSourceSiteID + "," + polSourceObservationModel.ObservationDate_Local)));
            }

            return(polSourceObservationModelRet);
        }
        // Check
        public string PolSourceObservationModelOK(PolSourceObservationModel polSourceObservationModel)
        {
            string retStr = FieldCheckNotZeroInt(polSourceObservationModel.PolSourceSiteID, ServiceRes.PolSourceSiteID);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckNotNullDateTime(polSourceObservationModel.ObservationDate_Local, ServiceRes.ObservationDate_Local);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckNotZeroInt(polSourceObservationModel.ContactTVItemID, ServiceRes.ContactTVItemID);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.DBCommandOK(polSourceObservationModel.DBCommand);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            return("");
        }
        public PolSourceObservationModel PostAddPolSourceObservationDB(PolSourceObservationModel polSourceObservationModel)
        {
            string retStr = PolSourceObservationModelOK(polSourceObservationModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            PolSourceSiteService polSourceSiteService = new PolSourceSiteService(LanguageRequest, User);
            PolSourceSiteModel   polSourceSiteModel   = polSourceSiteService.GetPolSourceSiteModelWithPolSourceSiteIDDB(polSourceObservationModel.PolSourceSiteID);

            if (!string.IsNullOrWhiteSpace(polSourceSiteModel.Error))
            {
                return(ReturnError(polSourceSiteModel.Error));
            }

            PolSourceObservation polSourceObservationExist = GetPolSourceObservationExistDB(polSourceObservationModel);

            if (polSourceObservationExist != null)
            {
                return(ReturnError(string.Format(ServiceRes._AlreadyExists, ServiceRes.PolSourceObservation)));
            }

            PolSourceObservation polSourceObservationNew = new PolSourceObservation();

            retStr = FillPolSourceObservation(polSourceObservationNew, polSourceObservationModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.PolSourceObservations.Add(polSourceObservationNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("PolSourceObservations", polSourceObservationNew.PolSourceObservationID, LogCommandEnum.Add, polSourceObservationNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetPolSourceObservationModelWithPolSourceObservationIDDB(polSourceObservationNew.PolSourceObservationID));
        }
        public PolSourceObservation GetPolSourceObservationExistDB(PolSourceObservationModel polSourceObservationModel)
        {
            PolSourceObservation polSourceObservation = (from c in db.PolSourceObservations
                                                         where c.PolSourceSiteID == polSourceObservationModel.PolSourceSiteID &&
                                                         c.ObservationDate_Local == polSourceObservationModel.ObservationDate_Local
                                                         select c).FirstOrDefault <PolSourceObservation>();

            return(polSourceObservation);
        }
        public PolSourceObservationModel PolSourceObservationCopyDB(int PolSourceObservationID)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrWhiteSpace(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            PolSourceObservationModel polSourceObservationModelToCopy = GetPolSourceObservationModelWithPolSourceObservationIDDB(PolSourceObservationID);

            if (!string.IsNullOrWhiteSpace(polSourceObservationModelToCopy.Error))
            {
                return(ReturnError(polSourceObservationModelToCopy.Error));
            }

            List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = _PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(PolSourceObservationID);

            if (polSourceObservationIssueModelList.Count == 0)
            {
                return(ReturnError(string.Format(ServiceRes._ShouldBeMoreThan_, ServiceRes.PolSourceObservationIssue, 0.ToString())));
            }

            PolSourceObservationModel polSourceObservationModelRet = new PolSourceObservationModel();

            using (TransactionScope ts = new TransactionScope())
            {
                polSourceObservationModelToCopy.PolSourceObservationID = 0;
                polSourceObservationModelToCopy.DBCommand             = DBCommandEnum.Original;
                polSourceObservationModelToCopy.ObservationDate_Local = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                polSourceObservationModelRet = PostAddPolSourceObservationDB(polSourceObservationModelToCopy);
                if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error))
                {
                    return(ReturnError(polSourceObservationModelRet.Error));
                }

                foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList)
                {
                    polSourceObservationIssueModel.DBCommand = DBCommandEnum.Original;
                    polSourceObservationIssueModel.PolSourceObservationID      = polSourceObservationModelRet.PolSourceObservationID;
                    polSourceObservationIssueModel.PolSourceObservationIssueID = 0;

                    PolSourceObservationIssueModel polSourceObservationIssueModelRet = _PolSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModel);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                    {
                        return(ReturnError(polSourceObservationIssueModelRet.Error));
                    }
                }

                ts.Complete();
            }
            return(polSourceObservationModelRet);
        }
        public PolSourceObservationModel PostUpdatePolSourceObservationDB(PolSourceObservationModel polSourceObservationModel)
        {
            string retStr = PolSourceObservationModelOK(polSourceObservationModel);

            if (!string.IsNullOrEmpty(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            PolSourceObservation polSourceObservationToUpdate = GetPolSourceObservationWithPolSourceObservationIDDB(polSourceObservationModel.PolSourceObservationID);

            if (polSourceObservationToUpdate == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.PolSourceObservation)));
            }

            retStr = FillPolSourceObservation(polSourceObservationToUpdate, polSourceObservationModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("PolSourceObservations", polSourceObservationToUpdate.PolSourceObservationID, LogCommandEnum.Change, polSourceObservationToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetPolSourceObservationModelWithPolSourceObservationIDDB(polSourceObservationToUpdate.PolSourceObservationID));
        }
Пример #7
0
        public ActionResult _polSourceIssueList(int PolSourceObservationID, int IssueOrdinal)
        {
            ViewBag.PolSourceObservationID             = PolSourceObservationID;
            ViewBag.IssueOrdinal                       = IssueOrdinal;
            ViewBag.PolSourceObservationIssueModelList = null;
            ViewBag.NextIssueOrdinal                   = IssueOrdinal + 1;

            if (PolSourceObservationID == 0)
            {
                return(PartialView());
            }

            PolSourceObservationModel polSourceObservationModel = _PolSourceSiteService._PolSourceObservationService.GetPolSourceObservationModelWithPolSourceObservationIDDB(PolSourceObservationID);

            if (!string.IsNullOrWhiteSpace(polSourceObservationModel.Error))
            {
                return(PartialView());
            }

            List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = _PolSourceSiteService._PolSourceObservationService._PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(PolSourceObservationID);

            if (polSourceObservationIssueModelList.Count == 0)
            {
                return(PartialView());
            }

            ViewBag.PolSourceObservationIssueModelList = polSourceObservationIssueModelList;

            bool hasOrdinal = (from c in polSourceObservationIssueModelList
                               where c.Ordinal == IssueOrdinal
                               select c).Any();

            if (!hasOrdinal)
            {
                if (polSourceObservationIssueModelList.Count > 0)
                {
                    ViewBag.IssueOrdinal = polSourceObservationIssueModelList.Min(c => c.Ordinal);
                }
            }

            if (polSourceObservationIssueModelList.Count > 0)
            {
                ViewBag.NextIssueOrdinal = polSourceObservationIssueModelList.Max(c => c.Ordinal) + 1;
            }

            return(PartialView());
        }
Пример #8
0
        public bool CreateQCPolSourceAll()
        {
            if (Cancel)
            {
                return(false);
            }

            lblStatus.Text = "Starting ... CreateSanitaryQC - CreateQCPolSourceAll";
            Application.DoEvents();

            TVItemService tvItemServiceR = new TVItemService(LanguageEnum.en, user);

            TVItemModel tvItemModelRoot = tvItemServiceR.GetRootTVItemModelDB();

            if (!CheckModelOK <TVItemModel>(tvItemModelRoot))
            {
                return(false);
            }

            TVItemModel tvItemModelCanada = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country);

            if (!CheckModelOK <TVItemModel>(tvItemModelCanada))
            {
                return(false);
            }

            TVItemModel tvItemModelQC = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelCanada.TVItemID, "Québec", TVTypeEnum.Province);

            if (!CheckModelOK <TVItemModel>(tvItemModelQC))
            {
                return(false);
            }

            List <TVItemModel> TVItemModelSubsectorList = tvItemServiceR.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelQC.TVItemID, TVTypeEnum.Subsector);

            if (TVItemModelSubsectorList.Count == 0)
            {
                richTextBoxStatus.AppendText("Error: could not find TVItem Subsector for " + tvItemModelQC.TVText + "\r\n");
                return(false);
            }

            List <string> NoSecList = new List <string>()
            {
                "M", "G-00"
            };

            List <TempData.QCSecteurMPol> qcSecteurMPol = new List <TempData.QCSecteurMPol>();

            using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
            {
                qcSecteurMPol = (from c in dbDT.QCSecteurMPols
                                 select c).ToList <TempData.QCSecteurMPol>();
            }

            List <Obs>    obsTypeList = new List <Obs>();
            List <string> sectorList  = new List <string>();
            List <TempData.QCSubsectorAssociation> qcsubsectorAssociationList = new List <TempData.QCSubsectorAssociation>();

            using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
            {
                qcsubsectorAssociationList = (from c in dbDT.QCSubsectorAssociations
                                              select c).ToList <TempData.QCSubsectorAssociation>();
            }

            using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
            {
                sectorList = (from s in dbQC.geo_pollution_p
                              select s.secteur).Distinct().ToList();
            }

            List <string> sectorOrderedList = (from c in sectorList
                                               orderby c
                                               select c).ToList();

            int StartQCCreateSanitarysQC = int.Parse(textBoxQCCreateSanitaryQC.Text);

            int TotalCount = sectorOrderedList.Count();
            int Count      = 0;

            foreach (string sec in sectorOrderedList)
            {
                Count += 1;

                TVItemService                    tvItemService                    = new TVItemService(LanguageEnum.en, user);
                PolSourceSiteService             polSourceSiteService             = new PolSourceSiteService(LanguageEnum.en, user);
                MapInfoService                   mapInfoService                   = new MapInfoService(LanguageEnum.en, user);
                PolSourceObservationService      polSourceObservationService      = new PolSourceObservationService(LanguageEnum.en, user);
                PolSourceObservationIssueService polSourceObservationIssueService = new PolSourceObservationIssueService(LanguageEnum.en, user);

                lblStatus.Text  = (Count * 100 / TotalCount).ToString() + " ... CreateSanitaryQC for sector " + sec;
                lblStatus2.Text = Count + " of " + TotalCount;
                Application.DoEvents();

                textBoxQCCreateSanitaryQC.Text = Count.ToString();

                if (StartQCCreateSanitarysQC > Count)
                {
                    continue;
                }

                if (sec != null)
                {
                    Application.DoEvents();

                    TVItemModel tvItemModelSubsector = new TVItemModel();

                    if (sec.StartsWith("M") || sec.StartsWith("G-00"))
                    {
                    }
                    else
                    {
                        TempData.QCSubsectorAssociation qcsubAss = (from c in qcsubsectorAssociationList
                                                                    where c.QCSectorText == sec
                                                                    select c).FirstOrDefault <TempData.QCSubsectorAssociation>();

                        tvItemModelSubsector = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelQC.TVItemID, qcsubAss.SubsectorText, TVTypeEnum.Subsector);
                        if (!CheckModelOK <TVItemModel>(tvItemModelSubsector))
                        {
                            return(false);
                        }
                    }

                    List <PCCSM.geo_pollution_p> polQCList = new List <PCCSM.geo_pollution_p>();
                    using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
                    {
                        polQCList = (from c in dbQC.geo_pollution_p
                                     where c.secteur == sec &&
                                     c.id_geo_pollution_p != 0 &&
                                     (c.x != null && c.y != null)
                                     //&& c.ex.exlure_importation == false
                                     select c).ToList <PCCSM.geo_pollution_p>();
                    }

                    int countPol      = 0;
                    int totalCountPol = polQCList.Count;
                    foreach (PCCSM.geo_pollution_p pqc in polQCList)
                    {
                        if (Cancel)
                        {
                            return(false);
                        }

                        countPol       += 1;
                        lblStatus2.Text = "Doing " + countPol + " of " + totalCountPol;
                        Application.DoEvents();

                        PolSourceSiteModel polSourceSiteModelNew = new PolSourceSiteModel();

                        string Code = tvItemService.CleanText(pqc.code.ToUpper());
                        List <PolSourceObsInfoEnum> polSourceObsInfoList = GetPolSourceType(Code.Trim(), "--", "QC");

                        string ObservationInfo = (int)polSourceObsInfoList[0] + "," + (int)polSourceObsInfoList[1] + ",";

                        polSourceSiteModelNew.IsPointSource = true;
                        //if (pqc.status == "actif")
                        //{
                        //    polSourceSiteModelNew.IsActive = true;
                        //}
                        //else
                        //{
                        //    polSourceSiteModelNew.IsActive = false;
                        //}
                        polSourceSiteModelNew.Oldsiteid = pqc.id_geo_pollution_p;

                        string SectText = (from c in qcSecteurMPol
                                           where c.geo_pollution_id == pqc.id_geo_pollution_p
                                           select c.Subsector).FirstOrDefault <string>();

                        if (string.IsNullOrWhiteSpace(SectText))
                        {
                            List <MapInfoModel> mapInfoModelList = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)pqc.y, (float)pqc.x, TVTypeEnum.Subsector);

                            foreach (MapInfoModel mapInfoModel in mapInfoModelList)
                            {
                                List <MapInfoPointModel> mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithMapInfoIDDB(mapInfoModel.MapInfoID);

                                List <Coord> coordList2 = new List <Coord>();
                                foreach (MapInfoPointModel mapInfoPointModel in mapInfoPointModelList)
                                {
                                    coordList2.Add(new Coord()
                                    {
                                        Lat = (float)mapInfoPointModel.Lat, Lng = (float)mapInfoPointModel.Lng, Ordinal = mapInfoPointModel.Ordinal
                                    });
                                }

                                if (mapInfoService.CoordInPolygon(coordList2, new Coord()
                                {
                                    Lat = (float)pqc.y, Lng = (float)pqc.x, Ordinal = 0
                                }))
                                {
                                    TVItemModel tvItemModelSS = tvItemService.GetTVItemModelWithTVItemIDDB(mapInfoModel.TVItemID);
                                    SectText = tvItemModelSS.TVText.Substring(0, tvItemModelSS.TVText.IndexOf(" ")).Trim();

                                    using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
                                    {
                                        TempData.QCSecteurMPol qcSecteurMPolExist = (from c in dbDT.QCSecteurMPols
                                                                                     where c.Subsector == SectText &&
                                                                                     c.geo_pollution_id == pqc.id_geo_pollution_p
                                                                                     select c).FirstOrDefault();

                                        if (qcSecteurMPolExist == null)
                                        {
                                            TempData.QCSecteurMPol qcsmpol = new TempData.QCSecteurMPol()
                                            {
                                                geo_pollution_id = pqc.id_geo_pollution_p,
                                                Subsector        = SectText,
                                            };

                                            dbDT.QCSecteurMPols.Add(qcsmpol);
                                            try
                                            {
                                                dbDT.SaveChanges();
                                            }
                                            catch (Exception ex)
                                            {
                                                richTextBoxStatus.AppendText("Error saving new TempData.QCSecteurMPol [" + ex.Message + "]");
                                                return(false);
                                            }
                                        }
                                    }

                                    break;
                                }
                            }

                            if (string.IsNullOrWhiteSpace(SectText))
                            {
                                int   MapInfoID = 0;
                                float MinDist   = 10000000f;
                                foreach (TVItemModel tvItemModel in TVItemModelSubsectorList)
                                {
                                    List <MapInfoPointModel> mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModel.TVItemID, TVTypeEnum.Subsector, MapInfoDrawTypeEnum.Point);

                                    float tempDist = (float)mapInfoService.CalculateDistance(mapInfoPointModelList[0].Lat, mapInfoPointModelList[0].Lng, (double)pqc.y, (double)pqc.x, mapInfoService.R);

                                    if (tempDist < MinDist)
                                    {
                                        MapInfoID = mapInfoPointModelList[0].MapInfoID;
                                        MinDist   = tempDist;
                                    }
                                }

                                MapInfoModel mapInfoModel = mapInfoService.GetMapInfoModelWithMapInfoIDDB(MapInfoID);
                                if (!string.IsNullOrWhiteSpace(mapInfoModel.Error))
                                {
                                    richTextBoxStatus.AppendText("Error [" + mapInfoModel.Error + "]");
                                    return(false);
                                }

                                TVItemModel tvItemModelSS = tvItemService.GetTVItemModelWithTVItemIDDB(mapInfoModel.TVItemID);
                                SectText = tvItemModelSS.TVText.Substring(0, tvItemModelSS.TVText.IndexOf(" ")).Trim();
                            }
                        }

                        if (string.IsNullOrWhiteSpace(SectText))
                        {
                            richTextBoxStatus.AppendText(pqc.y + " " + pqc.x + " " + pqc.id_geo_pollution_p + "\r\n");
                            continue;
                        }

                        tvItemModelSubsector = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelQC.TVItemID, SectText, TVTypeEnum.Subsector);
                        if (!CheckModelOK <TVItemModel>(tvItemModelSubsector))
                        {
                            return(false);
                        }

                        // doing EN TVText
                        string PolSourceSiteTVTextEN = _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[0]);
                        if (polSourceObsInfoList.Count > 1)
                        {
                            if (polSourceObsInfoList[1] != PolSourceObsInfoEnum.Error)
                            {
                                PolSourceSiteTVTextEN += " - " + _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[1]);
                            }
                        }

                        PolSourceSiteTVTextEN = tvItemService.CleanText(PolSourceSiteTVTextEN + " - " + "      ".Substring(0, 6 - pqc.id_geo_pollution_p.ToString().Length) + pqc.id_geo_pollution_p.ToString());

                        Thread.CurrentThread.CurrentCulture   = new CultureInfo("fr-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");

                        // Doing FR TVText
                        PolSourceObservationService polSourceObservationService2 = new PolSourceObservationService(LanguageEnum.fr, user);

                        string PolSourceSiteTVTextFR = _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[0]);
                        if (polSourceObsInfoList.Count > 1)
                        {
                            if (polSourceObsInfoList[1] != PolSourceObsInfoEnum.Error)
                            {
                                PolSourceSiteTVTextFR += " - " + _BaseEnumService.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[1]);
                            }
                        }

                        PolSourceSiteTVTextFR = tvItemService.CleanText(PolSourceSiteTVTextFR + " - " + "      ".Substring(0, 6 - pqc.id_geo_pollution_p.ToString().Length) + pqc.id_geo_pollution_p.ToString());

                        Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA");

                        TVItemModel tvItemModelPolSourceSite = tvItemService.PostCreateTVItem(tvItemModelSubsector.TVItemID, PolSourceSiteTVTextEN, PolSourceSiteTVTextFR, TVTypeEnum.PolSourceSite);
                        if (!CheckModelOK <TVItemModel>(tvItemModelPolSourceSite))
                        {
                            return(false);
                        }

                        List <Coord> coordList = new List <Coord>()
                        {
                            new Coord()
                            {
                                Lat = (float)pqc.y,
                                Lng = (float)pqc.x,
                            }
                        };

                        MapInfoModel mapInfoModelRet = mapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.PolSourceSite, tvItemModelPolSourceSite.TVItemID);
                        if (!CheckModelOK <MapInfoModel>(mapInfoModelRet))
                        {
                            return(false);
                        }

                        polSourceSiteModelNew.PolSourceSiteTVItemID = tvItemModelPolSourceSite.TVItemID;
                        polSourceSiteModelNew.PolSourceSiteTVText   = PolSourceSiteTVTextEN;

                        PolSourceSiteModel polSourceSiteModelRet = polSourceSiteService.GetPolSourceSiteModelWithPolSourceSiteTVItemIDDB(tvItemModelPolSourceSite.TVItemID);
                        if (!string.IsNullOrWhiteSpace(polSourceSiteModelRet.Error))
                        {
                            polSourceSiteModelRet = polSourceSiteService.PostAddPolSourceSiteDB(polSourceSiteModelNew);
                            if (!CheckModelOK <PolSourceSiteModel>(polSourceSiteModelRet))
                            {
                                return(false);
                            }
                        }

                        string TextObs = tvItemService.CleanText(string.IsNullOrEmpty(pqc.description) ? "" : pqc.description);

                        PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel();
                        if (pqc.date_observation == null)
                        {
                            polSourceObservationModelNew.ObservationDate_Local = new DateTime(2050, 1, 1);
                        }
                        else
                        {
                            polSourceObservationModelNew.ObservationDate_Local = (DateTime)(pqc.date_observation.Value).AddHours(1);
                        }

                        string observateur = "unknown";
                        if (pqc.observateur != null)
                        {
                            if (pqc.observateur.Length > 98)
                            {
                                observateur = pqc.observateur.Substring(0, 60);
                            }
                            else
                            {
                                observateur = pqc.observateur;
                            }
                        }

                        string observation = "(empty)";
                        if (pqc.description != null)
                        {
                            observation = Code.ToString().ToUpper() + " - " + pqc.description;
                        }

                        string TVTextInspectorEN = "Inspector " + observateur + " - (QC)";
                        string TVTextInspectorFR = "Inspecteur " + observateur + " - (QC)";

                        TVItemModel tvItemModelContact = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTypeEnum.Contact);
                        if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                        {
                            tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTextInspectorFR, TVTypeEnum.Contact);
                            if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                            {
                                return(false);
                            }
                        }

                        polSourceObservationModelNew.ContactTVItemID = tvItemModelContact.TVItemID;

                        polSourceObservationModelNew.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;
                        polSourceObservationModelNew.Observation_ToBeDeleted = observation;

                        PolSourceObservationModel polSourceObservationModelRet = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew);
                        if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error))
                        {
                            polSourceObservationModelRet = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew);
                            if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                            {
                                return(false);
                            }
                        }

                        PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel()
                        {
                            PolSourceObservationID = polSourceObservationModelNew.PolSourceObservationID,
                            ObservationInfo        = ObservationInfo,
                            PolSourceObsInfoList   = polSourceObsInfoList,
                            Ordinal = 0,
                        };

                        PolSourceObservationIssueModel polSourceObservationIssueModelRet = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew);
                        if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                        {
                            polSourceObservationIssueModelRet = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew);
                            if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                            {
                                return(false);
                            }
                        }

                        // do historic PolSourceObservation

                        List <PCCSM.db_histo_operation> histoPolSourceList = new List <PCCSM.db_histo_operation>();
                        using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
                        {
                            histoPolSourceList = (from c in dbQC.geo_pollution_p
                                                  from h in dbQC.db_histo_operation
                                                  where c.id_geo_pollution_p == h.id_geo_pollution_p &&
                                                  c.id_geo_pollution_p == pqc.id_geo_pollution_p
                                                  select h).ToList();
                        }

                        foreach (PCCSM.db_histo_operation hist in histoPolSourceList)
                        {
                            Application.DoEvents();

                            PolSourceObservationModel polSourceObservationModelNew2 = new PolSourceObservationModel();

                            if (hist.date_operation == null)
                            {
                                polSourceObservationModelNew2.ObservationDate_Local = new DateTime(1900, 1, 1);
                            }
                            else
                            {
                                polSourceObservationModelNew2.ObservationDate_Local = (DateTime)hist.date_operation;
                            }

                            observateur = "unknown";
                            if (hist.auteur != null)
                            {
                                if (hist.auteur.Length > 98)
                                {
                                    observateur = hist.auteur.Substring(0, 60);
                                }
                                else
                                {
                                    observateur = hist.auteur;
                                }
                            }

                            observation = "(vide)";
                            if (hist.description != null)
                            {
                                observation = hist.description;
                            }

                            TVTextInspectorEN = "Inspector " + observateur + " - (QC)";
                            TVTextInspectorFR = "Inspecteur " + observateur + " - (QC)";

                            tvItemModelContact = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTypeEnum.Contact);
                            if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                            {
                                tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTextInspectorFR, TVTypeEnum.Contact);
                                if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                                {
                                    return(false);
                                }
                            }

                            polSourceObservationModelNew2.ContactTVItemID = tvItemModelContact.TVItemID;

                            polSourceObservationModelNew2.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;
                            polSourceObservationModelNew2.Observation_ToBeDeleted = observation;

                            PolSourceObservationModel polSourceObservationModelRet2 = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew2);
                            if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet2.Error))
                            {
                                polSourceObservationModelRet2 = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew2);
                                if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                                {
                                    return(false);
                                }
                            }

                            PolSourceObservationIssueModel polSourceObservationIssueModelNew2 = new PolSourceObservationIssueModel()
                            {
                                PolSourceObservationID = polSourceObservationModelNew2.PolSourceObservationID,
                                ObservationInfo        = ObservationInfo,
                                PolSourceObsInfoList   = polSourceObsInfoList,
                                Ordinal = 0,
                            };

                            PolSourceObservationIssueModel polSourceObservationIssueModelRet2 = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew2);
                            if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet2.Error))
                            {
                                polSourceObservationIssueModelRet2 = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew2);
                                if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }
Пример #9
0
        // Post
        public PolSourceSiteModel PolSourceSiteAddOrModifyDB(FormCollection fc)
        {
            int    tempInt               = 0;
            int    ParentTVItemID        = 0;
            int    PolSourceSiteTVItemID = 0;
            bool   IsActive              = false;
            bool   IsPointSource         = false;
            double Lat = 0.0D;
            double Lng = 0.0D;

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrWhiteSpace(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            if (string.IsNullOrWhiteSpace(fc["ParentTVItemID"]))
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.ParentTVItemID)));
            }

            int.TryParse(fc["ParentTVItemID"], out ParentTVItemID);
            if (ParentTVItemID == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.ParentTVItemID)));
            }

            if (string.IsNullOrWhiteSpace(fc["PolSourceSiteTVItemID"]))
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteTVItemID)));
            }

            int.TryParse(fc["PolSourceSiteTVItemID"], out PolSourceSiteTVItemID);

            // PolSourceSiteTVItemID == 0 ==> Add
            // PolSourceSiteTVItemID > 0 ==> Modify

            TVItemModel tvItemModelPolSource = null;

            if (PolSourceSiteTVItemID != 0)
            {
                tvItemModelPolSource = _TVItemService.GetTVItemModelWithTVItemIDDB(PolSourceSiteTVItemID);
                if (!string.IsNullOrWhiteSpace(tvItemModelPolSource.Error))
                {
                    return(ReturnError(tvItemModelPolSource.Error));
                }
            }

            PolSourceSiteModel polSourceSiteNewOrToChange = new PolSourceSiteModel();

            if (PolSourceSiteTVItemID != 0)
            {
                polSourceSiteNewOrToChange = GetPolSourceSiteModelWithPolSourceSiteTVItemIDDB(PolSourceSiteTVItemID);
                if (!string.IsNullOrWhiteSpace(polSourceSiteNewOrToChange.Error))
                {
                    return(ReturnError(polSourceSiteNewOrToChange.Error));
                }
            }

            polSourceSiteNewOrToChange.DBCommand = DBCommandEnum.Original;

            if (string.IsNullOrWhiteSpace(fc["IsActive"]))
            {
                IsActive = false;
            }
            else
            {
                IsActive = true;
            }

            if (!IsActive)
            {
                int.TryParse(fc["InactiveReason"], out tempInt);
                if (tempInt == 0)
                {
                    return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.InactiveReason)));
                }

                polSourceSiteNewOrToChange.InactiveReason = (PolSourceInactiveReasonEnum)tempInt;
            }
            else
            {
                polSourceSiteNewOrToChange.InactiveReason = null;
            }

            if (string.IsNullOrWhiteSpace(fc["IsPointSource"]))
            {
                IsPointSource = false;
            }
            else
            {
                IsPointSource = true;
            }

            polSourceSiteNewOrToChange.IsPointSource = IsPointSource;

            double.TryParse(fc["Lat"], out Lat);
            if (Lat == 0.0D)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.Lat)));
            }

            double.TryParse(fc["Lng"], out Lng);
            if (Lng == 0.0D)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.Lng)));
            }

            List <Coord> coordList = new List <Coord>()
            {
                new Coord()
                {
                    Lat = (float)Lat, Lng = (float)Lng, Ordinal = 0
                }
            };

            using (TransactionScope ts = new TransactionScope())
            {
                string     ObservationInfo           = ((int)PolSourceObsInfoEnum.SourceStart).ToString() + ",";
                List <int> obsIntList                = ObservationInfo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
                string     ObservationLanguageTVText = ServiceRes.Error;
                string     TVText         = _BaseEnumService.GetEnumText_PolSourceObsInfoTextEnum(PolSourceObsInfoEnum.Error);
                int        NextSiteNumber = 0;

                if (PolSourceSiteTVItemID == 0)
                {
                    NextSiteNumber = GetNextAvailableSiteNumberWithParentTVItemIDDB(ParentTVItemID);

                    polSourceSiteNewOrToChange.Site = NextSiteNumber;

                    TVText = TVText + " - " + "000000".Substring(0, "000000".Length - NextSiteNumber.ToString().Length) + NextSiteNumber.ToString();

                    TVItemModel tvItemModelNewPolSourceSite = _TVItemService.PostAddChildTVItemDB(ParentTVItemID, TVText, TVTypeEnum.PolSourceSite);
                    if (!string.IsNullOrWhiteSpace(tvItemModelNewPolSourceSite.Error))
                    {
                        return(ReturnError(tvItemModelNewPolSourceSite.Error));
                    }

                    polSourceSiteNewOrToChange.PolSourceSiteTVItemID = tvItemModelNewPolSourceSite.TVItemID;
                    polSourceSiteNewOrToChange.PolSourceSiteTVText   = TVText;

                    polSourceSiteNewOrToChange = PostAddPolSourceSiteDB(polSourceSiteNewOrToChange);
                    if (!string.IsNullOrWhiteSpace(polSourceSiteNewOrToChange.Error))
                    {
                        return(ReturnError(polSourceSiteNewOrToChange.Error));
                    }

                    // Automatically add one Pollution Source Observation for today
                    PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel()
                    {
                        DBCommand               = DBCommandEnum.Original,
                        PolSourceSiteID         = polSourceSiteNewOrToChange.PolSourceSiteID,
                        ObservationDate_Local   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day),
                        ContactTVItemID         = contactOK.ContactTVItemID,
                        Observation_ToBeDeleted = "",
                    };

                    PolSourceObservationModel polSourceObservationModelRet = _PolSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error))
                    {
                        return(ReturnError(polSourceObservationModelRet.Error));
                    }

                    // Automatically add one Pollution Source Observation Issue
                    PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel();
                    polSourceObservationIssueModelNew.DBCommand = DBCommandEnum.Original;
                    polSourceObservationIssueModelNew.PolSourceObservationID = polSourceObservationModelRet.PolSourceObservationID;
                    polSourceObservationIssueModelNew.ObservationInfo        = ObservationInfo;
                    polSourceObservationIssueModelNew.Ordinal = 0;

                    PolSourceObservationIssueModel polSourceObservationIssueModelRet = _PolSourceObservationService._PolSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                    {
                        return(ReturnError(polSourceObservationIssueModelRet.Error));
                    }

                    // doing the other language
                    foreach (LanguageEnum lang in LanguageListAllowable.Where(c => c != LanguageRequest))
                    {
                        TVItemService tvItemService = new TVItemService(lang, _TVItemService.User);
                        Thread.CurrentThread.CurrentCulture   = new CultureInfo(lang + "-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang + "-CA");

                        ObservationInfo           = ((int)PolSourceObsInfoEnum.SourceStart).ToString() + ",";
                        ObservationLanguageTVText = ServiceRes.Error;
                        TVText = _BaseEnumService.GetEnumText_PolSourceObsInfoTextEnum(PolSourceObsInfoEnum.Error);

                        TVText = (string.IsNullOrWhiteSpace(TVText) ? ServiceRes.Error : TVText);

                        if (PolSourceSiteTVItemID == 0)
                        {
                            TVText = TVText + " - " + "000000".Substring(0, "000000".Length - NextSiteNumber.ToString().Length) + NextSiteNumber.ToString();
                        }
                        else
                        {
                            TVText = TVText + " - " + "000000".Substring(0, "000000".Length - polSourceSiteNewOrToChange.Site.ToString().Length) + polSourceSiteNewOrToChange.Site.ToString();
                        }

                        TVItemLanguageModel tvItemLanguageModel = new TVItemLanguageModel();
                        tvItemLanguageModel.DBCommand = DBCommandEnum.Original;
                        tvItemLanguageModel.Language  = lang;
                        tvItemLanguageModel.TVText    = TVText;
                        tvItemLanguageModel.TVItemID  = polSourceSiteNewOrToChange.PolSourceSiteTVItemID;

                        TVItemLanguageModel tvItemLanguageModelRet = tvItemService._TVItemLanguageService.PostUpdateTVItemLanguageDB(tvItemLanguageModel);
                        if (!string.IsNullOrWhiteSpace(tvItemLanguageModelRet.Error))
                        {
                            return(ReturnError(tvItemLanguageModelRet.Error));
                        }

                        Thread.CurrentThread.CurrentCulture   = new CultureInfo(LanguageRequest + "-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(LanguageRequest + "-CA");
                    }
                }
                else
                {
                    polSourceSiteNewOrToChange = PostUpdatePolSourceSiteDB(polSourceSiteNewOrToChange);
                    if (!string.IsNullOrWhiteSpace(polSourceSiteNewOrToChange.Error))
                    {
                        return(ReturnError(polSourceSiteNewOrToChange.Error));
                    }
                }

                // Adding map info
                List <MapInfoPointModel> mapInfoPointModelList = _MapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(polSourceSiteNewOrToChange.PolSourceSiteTVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point);
                if (mapInfoPointModelList.Count == 0)
                {
                    MapInfoModel mapInfoModelRet = _MapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.PolSourceSite, polSourceSiteNewOrToChange.PolSourceSiteTVItemID);
                    if (!string.IsNullOrWhiteSpace(mapInfoModelRet.Error))
                    {
                        return(ReturnError(mapInfoModelRet.Error));
                    }
                }
                else
                {
                    mapInfoPointModelList[0].Lat = coordList[0].Lat;
                    mapInfoPointModelList[0].Lng = coordList[0].Lng;

                    MapInfoPointModel mapInfoPointModelRet = _MapInfoService._MapInfoPointService.PostUpdateMapInfoPointDB(mapInfoPointModelList[0]);
                    if (!string.IsNullOrWhiteSpace(mapInfoPointModelRet.Error))
                    {
                        return(ReturnError(mapInfoPointModelRet.Error));
                    }
                }

                TVItemModel tvItemModelPolSourceSite = _TVItemService.GetTVItemModelWithTVItemIDDB(polSourceSiteNewOrToChange.PolSourceSiteTVItemID);
                if (!string.IsNullOrWhiteSpace(tvItemModelPolSourceSite.Error))
                {
                    return(ReturnError(tvItemModelPolSourceSite.Error));
                }

                tvItemModelPolSourceSite.IsActive = IsActive;

                TVItemModel tvItemModelRet = _TVItemService.PostUpdateTVItemDB(tvItemModelPolSourceSite);
                if (!string.IsNullOrWhiteSpace(tvItemModelRet.Error))
                {
                    return(ReturnError(tvItemModelRet.Error));
                }

                ts.Complete();
            }
            return(polSourceSiteNewOrToChange);
        }
        private void GenerateWorksheetAContentSubsectorPollutionSourceFieldSheet(WorksheetPart worksheetPart, Workbook workbook, string SheetName, int SheetOrdinal, bool ActivePollutionSource)
        {
            BaseEnumService      baseEnumService      = new BaseEnumService(_TaskRunnerBaseService._BWObj.appTaskModel.Language);
            TVItemService        tvItemService        = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            PolSourceSiteService polSourceSiteService = new PolSourceSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            //PolSourceObservationService polSourceObservationService = new PolSourceObservationService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            //MWQMSubsectorService mwqmSubsectorService = new MWQMSubsectorService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

            MergeCells mergeCells = new MergeCells();
            Row        row        = new Row();
            Cell       cell       = new Cell();
            Hyperlinks hyperlinks = new Hyperlinks();
            string     Id         = XlsxBase.sheetNameAndIDList[SheetOrdinal].SheetID;

            XlsxBase.CurrentColumn     = 0;
            XlsxBase.CurrentRow        = 0;
            XlsxBase.CurrentColumnProp = 0;
            Worksheet worksheet = new Worksheet()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "x14ac"
                }
            };

            worksheet.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            worksheet.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            worksheet.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

            SheetViews sheetViews = new SheetViews();

            SheetView sheetView = new SheetView()
            {
                TabSelected = true, WorkbookViewId = (UInt32Value)0U
            };
            Selection selection = new Selection()
            {
                ActiveCell = "A1", SequenceOfReferences = new ListValue <StringValue>()
                {
                    InnerText = "A1"
                }
            };

            sheetView.Append(selection);

            sheetViews.Append(sheetView);
            SheetFormatProperties sheetFormatProperties = new SheetFormatProperties()
            {
                DefaultRowHeight = 15D, DyDescent = 0.25D
            };

            Columns        columns         = new Columns();
            List <double?> columnWidthList = new List <double?>()
            {
                7D, 10D, 90D, 12D, 12D, 10D, 14D, 20D
            };

            foreach (double?width in columnWidthList)
            {
                Column colum = XlsxBase.AddColumnProp(columns, width);
            }

            SheetData sheetData = new SheetData();

            TVItemModel tvItemModelSubsector = tvItemService.GetTVItemModelWithTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);

            //MWQMSubsectorModel mwqmSubsectorModel = mwqmSubsectorService.GetMWQMSubsectorModelWithMWQMSubsectorTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);

            XlsxBase.CurrentRowHeight = 28D;
            XlsxBase.CurrentFontSize  = 24;
            XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Center;
            XlsxBase.CurrentBorderStyleValue         = BorderStyleValues.Thin;
            XlsxBase.CurrentBottomBorder             = true;

            row = XlsxBase.AddRow();
            string URL = _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelSubsector);

            XlsxBase.CurrentFontColor = System.Drawing.Color.Blue;
            cell = XlsxBase.AddCellHyperlink(hyperlinks, row, tvItemModelSubsector.TVText, URL);
            XlsxBase.CurrentFontColor = null;
            //cell = XlsxBase.AddCellString(row, tvItemModel.TVText);
            cell = XlsxBase.AddCellString(row, null);
            sheetData.Append(row);

            MergeCell mergeCell = new MergeCell()
            {
                Reference = "A" + XlsxBase.CurrentRow.ToString() + ":H" + XlsxBase.CurrentRow.ToString()
            };

            mergeCells.Append(mergeCell);

            List <TVItemModel> tvItemModelPolSourceList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID, TVTypeEnum.PolSourceSite);

            XlsxBase.CurrentRowHeight                = 24D;
            XlsxBase.CurrentFontSize                 = 18;
            XlsxBase.CurrentBorderStyleValue         = BorderStyleValues.Thin;
            XlsxBase.CurrentBottomBorder             = true;
            XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Center;

            row = XlsxBase.AddRow();
            XlsxBase.CurrentFontColor = null;
            cell = XlsxBase.AddCellString(row, "Site");
            cell = XlsxBase.AddCellString(row, "Type");
            cell = XlsxBase.AddCellString(row, "Observation");
            cell = XlsxBase.AddCellString(row, "Lat");
            cell = XlsxBase.AddCellString(row, "Lng");
            cell = XlsxBase.AddCellString(row, "Active");
            cell = XlsxBase.AddCellString(row, "Update");
            cell = XlsxBase.AddCellString(row, "Civic Address");
            sheetData.Append(row);

            XlsxBase.CurrentRowHeight = 160D;
            XlsxBase.CurrentFontSize  = 12;
            XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Left;

            List <PolSourceSiteModel> polSourceSiteModelList = polSourceSiteService.GetPolSourceSiteModelListWithSubsectorTVItemIDDB(tvItemModelSubsector.TVItemID);

            int countPolSourceSite = 0;

            foreach (PolSourceSiteModel polSourceSiteModel in polSourceSiteModelList.OrderBy(c => c.Site).ToList())
            {
                bool IsActive = (from c in tvItemModelPolSourceList
                                 where c.TVItemID == polSourceSiteModel.PolSourceSiteTVItemID
                                 select c.IsActive).FirstOrDefault();

                if (ActivePollutionSource != IsActive)
                {
                    continue;
                }

                countPolSourceSite += 1;
                PolSourceObservationModel polSourceObservationModel = polSourceSiteService._PolSourceObservationService.GetPolSourceObservationModelLatestWithPolSourceSiteTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);

                List <MapInfoPointModel> mapInfoPointModelList = polSourceSiteService._MapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(polSourceSiteModel.PolSourceSiteTVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point);

                row = XlsxBase.AddRow();

                if (countPolSourceSite % 5 == 0)
                {
                    XlsxBase.CurrentBorderStyleValue = BorderStyleValues.Thin;
                    XlsxBase.CurrentBottomBorder     = true;
                }
                else
                {
                    XlsxBase.CurrentBorderStyleValue = null;
                    XlsxBase.CurrentBottomBorder     = false;
                }

                XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Center;
                cell = XlsxBase.AddCellString(row, polSourceSiteModel.Site.ToString());

                if (polSourceObservationModel != null)
                {
                    List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = polSourceSiteService._PolSourceObservationService._PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(polSourceObservationModel.PolSourceObservationID);

                    string SelectedObservation = "Selected: \r\n";
                    int    PolSourceObsInfoInt = 0;
                    foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList)
                    {
                        List <int> observationInfoList = polSourceObservationIssueModel.ObservationInfo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList().Select(c => int.Parse(c)).ToList();
                        PolSourceObsInfoInt = observationInfoList.Where(c => (c > 10500 && c < 10599) || (c > 15200 && c < 15299)).FirstOrDefault();

                        foreach (PolSourceObsInfoEnum polSourceObsInfo in polSourceObservationIssueModel.PolSourceObsInfoList)
                        {
                            SelectedObservation += baseEnumService.GetEnumText_PolSourceObsInfoReportEnum(polSourceObsInfo);
                        }
                        SelectedObservation += "\r\n\r\n";
                    }
                    if (PolSourceObsInfoInt > 0)
                    {
                        cell = XlsxBase.AddCellString(row, baseEnumService.GetEnumText_PolSourceObsInfoEnum((PolSourceObsInfoEnum)PolSourceObsInfoInt));
                    }
                    else
                    {
                        cell = XlsxBase.AddCellString(row, "Empty");
                    }
                }

                XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Left;
                XlsxBase.WrapText = true;

                if (polSourceObservationModel != null)
                {
                    List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = polSourceSiteService._PolSourceObservationService._PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(polSourceObservationModel.PolSourceObservationID);

                    string SelectedObservation = "Selected: \r\n";
                    int    PolSourceObsInfoInt = 0;
                    foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList)
                    {
                        List <int> observationInfoList = polSourceObservationIssueModel.ObservationInfo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList().Select(c => int.Parse(c)).ToList();
                        foreach (PolSourceObsInfoEnum polSourceObsInfo in polSourceObservationIssueModel.PolSourceObsInfoList)
                        {
                            SelectedObservation += baseEnumService.GetEnumText_PolSourceObsInfoReportEnum(polSourceObsInfo);
                        }
                        SelectedObservation += "\r\n\r\n";
                    }
                    if (PolSourceObsInfoInt > 0)
                    {
                        cell = XlsxBase.AddCellString(row, "Written: \r\n" + (string.IsNullOrWhiteSpace(polSourceObservationModel.Observation_ToBeDeleted) ? "" : polSourceObservationModel.Observation_ToBeDeleted.ToString()) + "\r\n\r\n"
                                                      + SelectedObservation);
                    }
                    else
                    {
                        cell = XlsxBase.AddCellString(row, "Written: \r\n\r\n" + SelectedObservation);
                    }
                }

                XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Center;
                Alignment alignment1 = new Alignment()
                {
                    WrapText = true
                };

                if (mapInfoPointModelList.Count > 0)
                {
                    cell = XlsxBase.AddCellString(row, mapInfoPointModelList[0].Lat.ToString("F5"));
                    cell = XlsxBase.AddCellString(row, mapInfoPointModelList[0].Lng.ToString("F5"));
                }
                else
                {
                    cell = XlsxBase.AddCellString(row, "");
                    cell = XlsxBase.AddCellString(row, "");
                }

                TVItemModel tvItemModelPolSource = tvItemService.GetTVItemModelWithTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);

                cell = XlsxBase.AddCellString(row, tvItemModelPolSource.IsActive.ToString());
                cell = XlsxBase.AddCellString(row, polSourceObservationModel.ObservationDate_Local.ToString("yyyy MMM dd"));
                cell = XlsxBase.AddCellString(row, "empty");

                sheetData.Append(row);
            }

            if (countPolSourceSite > 0)
            {
                DefinedNames definedNames1 = new DefinedNames();
                DefinedName  definedName1  = new DefinedName()
                {
                    Name = "_xlnm._FilterDatabase", LocalSheetId = (UInt32Value)0U, Hidden = true
                };
                definedName1.Text = "'" + SheetName + "'" + "!$A$2:$H$" + (countPolSourceSite + 2).ToString();

                definedNames1.Append(definedName1);
                workbook.Append(definedNames1);

                AutoFilter autoFilter = new AutoFilter()
                {
                    Reference = "a2:B" + (countPolSourceSite + 2).ToString()
                };
                worksheet.Append(autoFilter);
            }

            PageMargins pageMargins = new PageMargins()
            {
                Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D
            };
            PageSetup pageSetup = new PageSetup()
            {
                Orientation = OrientationValues.Portrait, Id = "rId" + SheetOrdinal.ToString()
            };

            worksheet.Append(sheetViews);
            worksheet.Append(sheetFormatProperties);

            if (columns.ChildElements.Count > 0)
            {
                worksheet.Append(columns);
            }

            worksheet.Append(sheetData);

            mergeCells.Count = (UInt32Value)((UInt32)mergeCells.ChildElements.Count);
            if (mergeCells.ChildElements.Count > 0)
            {
                worksheet.Append(mergeCells);
            }


            if (XlsxBase.UsedHyperlinkList.Count > 0)
            {
                worksheet.Append(hyperlinks);
            }

            worksheet.Append(pageMargins);
            worksheet.Append(pageSetup);

            worksheetPart.Worksheet = worksheet;
        }
Пример #11
0
        public JsonResult PolSourceObservationAddOrModifyJSON(FormCollection fc)
        {
            PolSourceObservationModel PolSourceObservationModelRet = _PolSourceSiteService._PolSourceObservationService.PolSourceObservationAddOrModifyDB(fc);

            return(Json(PolSourceObservationModelRet.Error, JsonRequestBehavior.AllowGet));
        }
        // Post
        public PolSourceObservationModel PolSourceObservationAddOrModifyDB(FormCollection fc)
        {
            int  PolSourceSiteID        = 0;
            int  PolSourceSiteTVItemID  = 0;
            int  PolSourceObservationID = 0;
            int  Year            = 0;
            int  Month           = 0;
            int  Day             = 0;
            bool DesktopReviewed = false;

            DateTime ObsDate = new DateTime(1900, 1, 1);

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrWhiteSpace(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            if (string.IsNullOrWhiteSpace(fc["PolSourceSiteTVItemID"]))
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteTVItemID)));
            }

            int.TryParse(fc["PolSourceSiteTVItemID"], out PolSourceSiteTVItemID);
            if (PolSourceSiteTVItemID == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteTVItemID)));
            }

            TVItemModel tvItemModelPolSourcSite = _TVItemService.GetTVItemModelWithTVItemIDDB(PolSourceSiteTVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelPolSourcSite.Error))
            {
                return(ReturnError(tvItemModelPolSourcSite.Error));
            }

            if (string.IsNullOrWhiteSpace(fc["PolSourceSiteID"]))
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteID)));
            }

            int.TryParse(fc["PolSourceSiteID"], out PolSourceSiteID);
            if (PolSourceSiteID == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceSiteID)));
            }

            if (string.IsNullOrWhiteSpace(fc["PolSourceObservationID"]))
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.PolSourceObservationID)));
            }

            int.TryParse(fc["PolSourceObservationID"], out PolSourceObservationID);

            // PolSourceObservationID == 0 ==> Add
            // PolSourceObservationID > 0 ==> Modify

            PolSourceObservationModel polSourceObservationModelToAddOrChange = new PolSourceObservationModel();

            if (PolSourceObservationID > 0)
            {
                polSourceObservationModelToAddOrChange = GetPolSourceObservationModelWithPolSourceObservationIDDB(PolSourceObservationID);
                if (!string.IsNullOrWhiteSpace(polSourceObservationModelToAddOrChange.Error))
                {
                    return(ReturnError(polSourceObservationModelToAddOrChange.Error));
                }
            }

            int.TryParse(fc["ObsYear"], out Year);
            if (Year == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.Year)));
            }

            int.TryParse(fc["ObsMonth"], out Month);
            if (Month == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.Month)));
            }

            int.TryParse(fc["ObsDay"], out Day);
            if (Day == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.Day)));
            }

            ObsDate = new DateTime(Year, Month, Day);

            if (fc["DesktopReviewed"] != null)
            {
                DesktopReviewed = true;
            }

            //PolSourceObservationModel polSourceObservationModelRet = new PolSourceObservationModel();
            using (TransactionScope ts = new TransactionScope())
            {
                PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel()
                {
                    DBCommand               = DBCommandEnum.Original,
                    PolSourceSiteID         = PolSourceSiteID,
                    ObservationDate_Local   = ObsDate,
                    ContactTVItemID         = contactOK.ContactTVItemID,
                    DesktopReviewed         = DesktopReviewed,
                    Observation_ToBeDeleted = "",
                };

                if (PolSourceObservationID == 0) // new
                {
                    polSourceObservationModelToAddOrChange = PostAddPolSourceObservationDB(polSourceObservationModelNew);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationModelToAddOrChange.Error))
                    {
                        return(ReturnError(polSourceObservationModelToAddOrChange.Error));
                    }

                    string     ObservationInfo = ((int)PolSourceObsInfoEnum.SourceStart).ToString() + ",";
                    List <int> obsIntList      = ObservationInfo.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();

                    PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel();
                    polSourceObservationIssueModelNew.DBCommand = DBCommandEnum.Original;
                    polSourceObservationIssueModelNew.PolSourceObservationID = polSourceObservationModelToAddOrChange.PolSourceObservationID;
                    polSourceObservationIssueModelNew.ObservationInfo        = ObservationInfo;
                    polSourceObservationIssueModelNew.Ordinal = 0;

                    PolSourceObservationIssueModel polSourceObservationIssueModelRet = _PolSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                    {
                        return(ReturnError(polSourceObservationIssueModelRet.Error));
                    }

                    // doing the other language
                    foreach (LanguageEnum lang in LanguageListAllowable.Where(c => c != LanguageRequest))
                    {
                        TVItemService tvItemService = new TVItemService(lang, _PolSourceObservationIssueService.User);
                        Thread.CurrentThread.CurrentCulture   = new CultureInfo(lang + "-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang + "-CA");

                        ObservationInfo = ((int)PolSourceObsInfoEnum.SourceStart).ToString() + ",";
                        string ObservationLanguageTVText = ServiceRes.Error;
                        string TVText = _BaseEnumService.GetEnumText_PolSourceObsInfoTextEnum(PolSourceObsInfoEnum.Error);;

                        TVText = (string.IsNullOrWhiteSpace(TVText) ? ServiceRes.Error : TVText);

                        int Site = GetSiteWithPolSourceSiteID(PolSourceSiteID);

                        TVText = TVText + " - " + "000000".Substring(0, "000000".Length - Site.ToString().Length) + Site.ToString();

                        TVItemLanguageModel tvItemLanguageModel = new TVItemLanguageModel();
                        tvItemLanguageModel.DBCommand = DBCommandEnum.Original;
                        tvItemLanguageModel.Language  = lang;
                        tvItemLanguageModel.TVText    = TVText;
                        tvItemLanguageModel.TVItemID  = PolSourceSiteID;

                        TVItemLanguageModel tvItemLanguageModelRet = tvItemService._TVItemLanguageService.PostUpdateTVItemLanguageDB(tvItemLanguageModel);
                        if (!string.IsNullOrWhiteSpace(tvItemLanguageModelRet.Error))
                        {
                            return(ReturnError(tvItemLanguageModelRet.Error));
                        }

                        Thread.CurrentThread.CurrentCulture   = new CultureInfo(LanguageRequest + "-CA");
                        Thread.CurrentThread.CurrentUICulture = new CultureInfo(LanguageRequest + "-CA");
                    }
                }
                else
                {
                    polSourceObservationModelNew.PolSourceObservationID = polSourceObservationModelToAddOrChange.PolSourceObservationID;
                    polSourceObservationModelToAddOrChange = PostUpdatePolSourceObservationDB(polSourceObservationModelNew);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationModelToAddOrChange.Error))
                    {
                        return(ReturnError(polSourceObservationModelToAddOrChange.Error));
                    }
                }

                ts.Complete();
            }
            return(polSourceObservationModelToAddOrChange);
        }
        // Fill
        public string FillPolSourceObservation(PolSourceObservation polSourceObservation, PolSourceObservationModel polSourceObservationModel, ContactOK contactOK)
        {
            polSourceObservation.DBCommand               = (int)polSourceObservationModel.DBCommand;
            polSourceObservation.PolSourceSiteID         = polSourceObservationModel.PolSourceSiteID;
            polSourceObservation.ObservationDate_Local   = polSourceObservationModel.ObservationDate_Local;
            polSourceObservation.Observation_ToBeDeleted = polSourceObservationModel.Observation_ToBeDeleted;
            polSourceObservation.ContactTVItemID         = polSourceObservationModel.ContactTVItemID;
            polSourceObservation.DesktopReviewed         = polSourceObservationModel.DesktopReviewed;
            polSourceObservation.LastUpdateDate_UTC      = DateTime.UtcNow;
            if (contactOK == null)
            {
                polSourceObservation.LastUpdateContactTVItemID = 2;
            }
            else
            {
                polSourceObservation.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
Пример #14
0
        public bool CreateSanitaryBC()
        {
            lblStatus.Text = "Starting ... CreateSanitaryBC";
            Application.DoEvents();

            if (Cancel)
            {
                return(false);
            }

            TVItemService   tvItemServiceR  = new TVItemService(LanguageEnum.en, user);
            BaseEnumService _BaseEnumSerice = new BaseEnumService(LanguageEnum.en);

            TVItemModel tvItemModelRoot = tvItemServiceR.GetRootTVItemModelDB();

            if (!CheckModelOK <TVItemModel>(tvItemModelRoot))
            {
                return(false);
            }

            TVItemModel tvItemModelCanada = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country);

            if (!CheckModelOK <TVItemModel>(tvItemModelCanada))
            {
                return(false);
            }

            TVItemModel tvItemModelBC = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelCanada.TVItemID, "British Columbia", TVTypeEnum.Province);

            if (!CheckModelOK <TVItemModel>(tvItemModelBC))
            {
                return(false);
            }

            List <TVItemModel> TVItemModelSubsectorList = tvItemServiceR.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelBC.TVItemID, TVTypeEnum.Subsector);

            if (TVItemModelSubsectorList.Count == 0)
            {
                richTextBoxStatus.AppendText("Error: could not find TVItem Subsector for " + tvItemModelBC.TVText + "\r\n");
                return(false);
            }

            List <TempData.BCPolSource> bcPolSourceList = new List <TempData.BCPolSource>();

            using (TempData.TempDataToolDBEntities dbDT = new TempData.TempDataToolDBEntities())
            {
                bcPolSourceList = (from c in dbDT.BCPolSources
                                   orderby c.BCPolSourceID
                                   select c).ToList <TempData.BCPolSource>();
            }

            int StartBCCreateSanitarysBC = int.Parse(textBoxBCCreateSanitaryBC.Text);

            int TotalCount = bcPolSourceList.Count();
            int Count      = 0;

            foreach (TempData.BCPolSource bcps in bcPolSourceList)
            {
                if (Cancel)
                {
                    return(false);
                }

                Count         += 1;
                lblStatus.Text = Count + " of " + TotalCount + " ... LoadSanitary BC";
                Application.DoEvents();

                textBoxBCCreateSanitaryBC.Text = Count.ToString();

                if (StartBCCreateSanitarysBC > Count)
                {
                    continue;
                }

                TVItemService tvItemService = new TVItemService(LanguageEnum.en, user);
                PolSourceObservationService      polSourceObservationService      = new PolSourceObservationService(LanguageEnum.en, user);
                PolSourceObservationIssueService polSourceObservationIssueService = new PolSourceObservationIssueService(LanguageEnum.en, user);
                PolSourceSiteService             polSourceSiteService             = new PolSourceSiteService(LanguageEnum.en, user);
                MapInfoService mapInfoService = new MapInfoService(LanguageEnum.en, user);

                PolSourceSiteModel polSourceSiteModelNew = new PolSourceSiteModel();

                polSourceSiteModelNew.Oldsiteid = int.Parse(bcps.Key_.Substring(2));

                string LCODE = tvItemService.CleanText(bcps.LCode);
                string ICODE = tvItemService.CleanText(bcps.ICode);

                if (LCODE.Trim() == "")
                {
                    LCODE = "--";
                }

                if (ICODE.Trim() == "")
                {
                    ICODE = "--";
                }

                List <PolSourceObsInfoEnum> polSourceObsInfoList = GetPolSourceType(LCODE.Trim(), ICODE.Trim(), "BC");

                string ObservationInfo = ((int)polSourceObsInfoList[0]).ToString() + "," + ((int)polSourceObsInfoList[1]).ToString() + ",";

                List <MapInfoModel> mapInfoModelListSubsector = new List <MapInfoModel>();
                if (bcps.Y_calc == 48.984828948974609f && bcps.X_calc == -123.02297973632812f)
                {
                    mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB(49.01f, (float)bcps.X_calc, TVTypeEnum.Subsector);
                }
                else if (bcps.Y_calc == 49.3099250793457f && bcps.X_calc == -121.77302551269531f)
                {
                    mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)bcps.Y_calc, (float)-122.2, TVTypeEnum.Subsector);
                }
                else if (bcps.Y_calc == 48.3582878112793f && bcps.X_calc == -123.73906707763672f)
                {
                    mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)bcps.Y_calc, (float)-123.72, TVTypeEnum.Subsector);
                }
                else if (bcps.Y_calc == 51.266487121582031f && bcps.X_calc == -128.20162963867187f)
                {
                    mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)bcps.Y_calc, (float)-128, TVTypeEnum.Subsector);
                }
                else if (bcps.Y_calc == 55.91217041015625f && bcps.X_calc == -130.01992797851562f)
                {
                    mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)bcps.Y_calc, (float)-129, TVTypeEnum.Subsector);
                }
                else if (bcps.Y_calc == 55.912052154541016f && bcps.X_calc == -130.01669311523437f)
                {
                    mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)bcps.Y_calc, (float)-129, TVTypeEnum.Subsector);
                }
                else
                {
                    mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)bcps.Y_calc, (float)bcps.X_calc, TVTypeEnum.Subsector);
                }

                if (mapInfoModelListSubsector.Count == 0)
                {
                    richTextBoxStatus.AppendText("GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB did not find anything\r\n");
                    return(false);
                }

                // doing EN TVText
                string PolSourceSiteTVTextEN = _BaseEnumSerice.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[0]);
                if (polSourceObsInfoList.Count > 1)
                {
                    if (polSourceObsInfoList[1] != PolSourceObsInfoEnum.Error)
                    {
                        PolSourceSiteTVTextEN += " - " + _BaseEnumSerice.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[1]);
                    }
                }

                int Site = (int)bcps.OBJECTID;

                PolSourceSiteTVTextEN = tvItemService.CleanText(PolSourceSiteTVTextEN + " - " + "      ".Substring(0, 6 - Site.ToString().Length) + Site.ToString());

                Thread.CurrentThread.CurrentCulture   = new CultureInfo("fr-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");

                // Doing FR TVText
                PolSourceObservationService polSourceObservationService2 = new PolSourceObservationService(LanguageEnum.fr, user);

                string PolSourceSiteTVTextFR = _BaseEnumSerice.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[0]);
                if (polSourceObsInfoList.Count > 1)
                {
                    if (polSourceObsInfoList[1] != PolSourceObsInfoEnum.Error)
                    {
                        PolSourceSiteTVTextFR += " - " + _BaseEnumSerice.GetEnumText_PolSourceObsInfoEnum(polSourceObsInfoList[1]);
                    }
                }

                PolSourceSiteTVTextFR = tvItemService.CleanText(PolSourceSiteTVTextFR + " - " + "      ".Substring(0, 6 - Site.ToString().Length) + Site.ToString());

                Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA");

                TVItemModel tvItemModelPolSourceSite = tvItemService.PostCreateTVItem(mapInfoModelListSubsector[0].TVItemID, PolSourceSiteTVTextEN, PolSourceSiteTVTextFR, TVTypeEnum.PolSourceSite);
                if (!CheckModelOK <TVItemModel>(tvItemModelPolSourceSite))
                {
                    return(false);
                }

                List <Coord> coordList = new List <Coord>()
                {
                    new Coord()
                    {
                        Lat = (float)bcps.Y_calc,
                        Lng = (float)bcps.X_calc,
                    }
                };

                MapInfoModel mapInfoModelRet = mapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.PolSourceSite, tvItemModelPolSourceSite.TVItemID);
                if (!CheckModelOK <MapInfoModel>(mapInfoModelRet))
                {
                    return(false);
                }

                polSourceSiteModelNew.PolSourceSiteTVItemID = tvItemModelPolSourceSite.TVItemID;
                polSourceSiteModelNew.PolSourceSiteTVText   = PolSourceSiteTVTextEN;
                polSourceSiteModelNew.Site      = Site;
                polSourceSiteModelNew.Oldsiteid = Site;

                PolSourceSiteModel polSourceSiteModelRet = polSourceSiteService.GetPolSourceSiteModelWithPolSourceSiteTVItemIDDB(tvItemModelPolSourceSite.TVItemID);
                if (!string.IsNullOrWhiteSpace(polSourceSiteModelRet.Error))
                {
                    polSourceSiteModelRet = polSourceSiteService.PostAddPolSourceSiteDB(polSourceSiteModelNew);
                    if (!CheckModelOK <PolSourceSiteModel>(polSourceSiteModelRet))
                    {
                        return(false);
                    }
                }

                PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel();
                if (bcps.yyyymmdd == null)
                {
                    polSourceObservationModelNew.ObservationDate_Local = new DateTime(2050, 1, 1);
                }
                else
                {
                    polSourceObservationModelNew.ObservationDate_Local = (DateTime)bcps.yyyymmdd;
                }

                string Inspector = "unknown";
                if (!string.IsNullOrWhiteSpace(bcps.Verified))
                {
                    Inspector = bcps.Verified + " - (BC)";
                }

                string TVTextInspectorEN = "Inspector " + Inspector;
                string TVTextInspectorFR = "Inspecteur " + Inspector;

                TVItemModel tvItemModelContactRet = tvItemService.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTypeEnum.Contact);
                if (!string.IsNullOrWhiteSpace(tvItemModelContactRet.Error))
                {
                    tvItemModelContactRet = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVTextInspectorEN, TVTextInspectorFR, TVTypeEnum.Contact);
                    if (!CheckModelOK <TVItemModel>(tvItemModelContactRet))
                    {
                        return(false);
                    }
                }

                polSourceObservationModelNew.ContactTVItemID = tvItemModelContactRet.TVItemID;
                string Observation = "(empty)";
                if (!string.IsNullOrWhiteSpace(bcps.Remarks))
                {
                    Observation = LCODE.Trim().ToUpper() + " - " + ICODE.Trim().ToUpper() + " - " + bcps.Remarks;
                }
                polSourceObservationModelNew.Observation_ToBeDeleted = Observation;
                polSourceObservationModelNew.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;

                PolSourceObservationModel polSourceObservationModelRet = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew);
                if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error))
                {
                    polSourceObservationModelRet = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew);
                    if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                    {
                        return(false);
                    }
                }

                PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel()
                {
                    PolSourceObservationID = polSourceObservationModelNew.PolSourceObservationID,
                    ObservationInfo        = ObservationInfo,
                    PolSourceObsInfoList   = polSourceObsInfoList,
                    Ordinal = 0,
                };

                PolSourceObservationIssueModel polSourceObservationIssueModelRet = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew);
                if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                {
                    polSourceObservationIssueModelRet = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew);
                    if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public void Generate(FileInfo fi)
        {
            BaseEnumService       baseEnumService       = new BaseEnumService(_TaskRunnerBaseService._BWObj.appTaskModel.Language);
            TVItemService         tvItemService         = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MapInfoService        mapInfoService        = new MapInfoService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            PolSourceSiteService  polSourceSiteService  = new PolSourceSiteService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            InfrastructureService infrastructureService = new InfrastructureService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

            if (_TaskRunnerBaseService._BWObj.appTaskModel.Language == "fr")
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo("fr-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-CA");
            }
            else
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-CA");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-CA");
            }

            TVFileService tvFileService  = new TVFileService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            string        ServerFilePath = tvFileService.GetServerFilePath(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);

            DirectoryInfo di = new DirectoryInfo(ServerFilePath);

            if (!di.Exists)
            {
                di.Create();
            }

            if (fi.Exists)
            {
                fi.Delete();
            }

            StringBuilder sbKML = new StringBuilder();

            sbKML.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            sbKML.AppendLine(@"<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"">");
            sbKML.AppendLine(@"<Document>");
            sbKML.AppendLine(@"	<name>" + _TaskRunnerBaseService.generateDocParams.FileName + "</name>");

            sbKML.AppendLine(@"    <StyleMap id=""msn_ylw-pushpin"">");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>normal</key>");
            sbKML.AppendLine(@"			<styleUrl>#sn_ylw-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>highlight</key>");
            sbKML.AppendLine(@"			<styleUrl>#sh_ylw-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"	</StyleMap>");
            sbKML.AppendLine(@"	<Style id=""sh_ylw-pushpin"">");
            sbKML.AppendLine(@"		<IconStyle>");
            sbKML.AppendLine(@"			<scale>1.2</scale>");
            sbKML.AppendLine(@"		</IconStyle>");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff00ff00</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>0000ff00</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");
            sbKML.AppendLine(@"	<Style id=""sn_ylw-pushpin"">");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff00ff00</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>0000ff00</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");

            sbKML.AppendLine(@"    <StyleMap id=""msn_grn-pushpin"">");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>normal</key>");
            sbKML.AppendLine(@"			<styleUrl>#sn_grn-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"		<Pair>");
            sbKML.AppendLine(@"			<key>highlight</key>");
            sbKML.AppendLine(@"			<styleUrl>#sh_grn-pushpin</styleUrl>");
            sbKML.AppendLine(@"		</Pair>");
            sbKML.AppendLine(@"	</StyleMap>");
            sbKML.AppendLine(@"	<Style id=""sh_grn-pushpin"">");
            sbKML.AppendLine(@"		<IconStyle>");
            sbKML.AppendLine(@"			<scale>1.2</scale>");
            sbKML.AppendLine(@"		</IconStyle>");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff0000ff</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>000000ff</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");
            sbKML.AppendLine(@"	<Style id=""sn_grn-pushpin"">");
            sbKML.AppendLine(@"		<LineStyle>");
            sbKML.AppendLine(@"			<color>ff0000ff</color>");
            sbKML.AppendLine(@"			<width>1.5</width>");
            sbKML.AppendLine(@"		</LineStyle>");
            sbKML.AppendLine(@"		<PolyStyle>");
            sbKML.AppendLine(@"			<color>000000ff</color>");
            sbKML.AppendLine(@"		</PolyStyle>");
            sbKML.AppendLine(@"	</Style>");

            TVItemModel tvItemModelSubsector = tvItemService.GetTVItemModelWithTVItemIDDB(_TaskRunnerBaseService._BWObj.appTaskModel.TVItemID);
            List <MapInfoPointModel> mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.Subsector, MapInfoDrawTypeEnum.Point);

            sbKML.AppendLine(@"	<Folder>");
            sbKML.AppendLine(@"	<name>Subsector</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");

            // Doing Point
            sbKML.AppendLine(@"	<Placemark>");
            sbKML.AppendLine(@"	<name>" + tvItemModelSubsector.TVText + "</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
            //sbKMZ.AppendLine(@"	<description>");
            //sbKMZ.AppendLine(@"<![CDATA[");
            //sbKMZ.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelRoot) + @""">" + tvItemModelRoot.TVText + "</a>");
            //sbKMZ.AppendLine(@"]]>");
            //sbKMZ.AppendLine(@"	</description>");
            sbKML.AppendLine(@"	<Point>");
            sbKML.AppendLine(@"		<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
            sbKML.AppendLine(@"	</Point>");
            sbKML.AppendLine(@"	</Placemark>");

            // Doing Polygon
            sbKML.AppendLine(@"	<Placemark>");
            sbKML.AppendLine(@"		<name>"+ tvItemModelSubsector.TVText + " (poly)</name>");
            sbKML.AppendLine(@"	    <visibility>0</visibility>");
            sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
            //sbKMZ.AppendLine(@"	<description>");
            //sbKMZ.AppendLine(@"<![CDATA[");
            //sbKMZ.AppendLine(@"<a href=""" + _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelCountry) + @""">" + tvItemModelCountry.TVText + "</a>");
            //sbKMZ.AppendLine(@"]]>");
            //sbKMZ.AppendLine(@"	</description>");
            sbKML.AppendLine(@"		<Polygon>");
            sbKML.AppendLine(@"			<outerBoundaryIs>");
            sbKML.AppendLine(@"				<LinearRing>");
            sbKML.AppendLine(@"					<coordinates>");

            mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.Subsector, MapInfoDrawTypeEnum.Polygon);
            foreach (MapInfoPointModel mapInfoPointModel in mapInfoPointModelList)
            {
                sbKML.AppendLine(mapInfoPointModel.Lng + "," + mapInfoPointModel.Lat + ",0 ");
            }

            sbKML.AppendLine(@"					</coordinates>");
            sbKML.AppendLine(@"				</LinearRing>");
            sbKML.AppendLine(@"			</outerBoundaryIs>");
            sbKML.AppendLine(@"		</Polygon>");
            sbKML.AppendLine(@"	</Placemark>");

            // Doing Municipalities
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>Municipalities</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            List <TVItemModel> tvItemModelMunicipalityList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.Municipality);

            foreach (TVItemModel tvItemModelMunicipality in tvItemModelMunicipalityList)
            {
                sbKML.AppendLine(@" <Folder>");
                sbKML.AppendLine(@"	<name>" + tvItemModelMunicipality.TVText + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + tvItemModelMunicipality.TVText + " ( Point)</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelMunicipality.TVItemID, TVTypeEnum.Municipality, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");

                List <TVItemModel> tvItemModelInfrastructureList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelMunicipality.TVItemID, TVTypeEnum.Infrastructure);

                List <InfrastructureModel> infrastructureModelList = new List <InfrastructureModel>();

                foreach (TVItemModel tvItemModelInfrastructure in tvItemModelInfrastructureList)
                {
                    infrastructureModelList.Add(infrastructureService.GetInfrastructureModelWithInfrastructureTVItemIDDB(tvItemModelInfrastructure.TVItemID));
                }

                // Doing WWTP
                foreach (InfrastructureModel infrastructureModel in infrastructureModelList.Where(c => c.InfrastructureType == InfrastructureTypeEnum.WWTP).ToList())
                {
                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>" + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                    sbKML.AppendLine(@"	<description>");
                    sbKML.AppendLine(@"<![CDATA[");
                    sbKML.AppendLine(@"<pre>");
                    sbKML.AppendLine(@"Alarm System Type: " + baseEnumService.GetEnumText_AlarmSystemTypeEnum(infrastructureModel.AlarmSystemType) + "\r\n");
                    sbKML.AppendLine(@"Can overflow: " + infrastructureModel.CanOverflow.ToString() + "\r\n");
                    sbKML.AppendLine(@"Category: " + infrastructureModel.InfrastructureCategory + "\r\n");
                    sbKML.AppendLine(@"Collection System Type: " + baseEnumService.GetEnumText_CollectionSystemTypeEnum(infrastructureModel.CollectionSystemType) + "\r\n");
                    sbKML.AppendLine(@"Comments: " + infrastructureModel.Comment + "\r\n");
                    sbKML.AppendLine(@"DesignFlow (m3/day): " + infrastructureModel.DesignFlow_m3_day + "\r\n");
                    sbKML.AppendLine(@"Disinfection Type: " + baseEnumService.GetEnumText_DisinfectionTypeEnum(infrastructureModel.DisinfectionType) + "\r\n");
                    sbKML.AppendLine(@"Infrastructure Type: " + baseEnumService.GetEnumText_InfrastructureTypeEnum(infrastructureModel.InfrastructureType) + "\r\n");
                    sbKML.AppendLine(@"Average Flow (m3/day): " + infrastructureModel.AverageFlow_m3_day + "\r\n");
                    sbKML.AppendLine(@"AverageFlow_m3_day: " + infrastructureModel.PeakFlow_m3_day + "\r\n");
                    sbKML.AppendLine(@"Percent Flow Of Total (%): " + infrastructureModel.PercFlowOfTotal + "\r\n");
                    sbKML.AppendLine(@"Population Served: " + infrastructureModel.PopServed + "\r\n");
                    sbKML.AppendLine(@"Time Zone: " + infrastructureModel.TimeOffset_hour + "\r\n");
                    sbKML.AppendLine(@"Treatment Type: " + baseEnumService.GetEnumText_TreatmentTypeEnum(infrastructureModel.TreatmentType) + "\r\n");

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.WasteWaterTreatmentPlant, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureList.Count > 0)
                    {
                        sbKML.AppendLine(@"Latitude Longitude: " + mapInfoPointModelInfrastructureList[0].Lat + " " + mapInfoPointModelInfrastructureList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Latitude Longitude: \r\n");
                    }

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureOutfallList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureOutfallList.Count > 0)
                    {
                        sbKML.AppendLine(@"Outfall: Latitude Longitude: " + mapInfoPointModelInfrastructureOutfallList[0].Lat + " " + mapInfoPointModelInfrastructureOutfallList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Outfall: Latitude Longitude: \r\n");
                    }
                    sbKML.AppendLine("\r\n\r\n");
                    sbKML.AppendLine("Outfall Information\r\n\r\n");
                    sbKML.AppendLine(@"Average Depth (m): " + infrastructureModel.AverageDepth_m + "\r\n");
                    sbKML.AppendLine(@"Decay Rate (/day): " + infrastructureModel.DecayRate_per_day + "\r\n");
                    sbKML.AppendLine(@"Distance From Shore (m): " + infrastructureModel.DistanceFromShore_m + "\r\n");
                    sbKML.AppendLine(@"Far Field Velocity (m/s): " + infrastructureModel.FarFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Horizontal Angle (deg): " + infrastructureModel.HorizontalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"Near Field Velocity (m/s): " + infrastructureModel.NearFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Number Of Ports: " + infrastructureModel.NumberOfPorts + "\r\n");
                    sbKML.AppendLine(@"Port Diameter (m): " + infrastructureModel.PortDiameter_m + "\r\n");
                    sbKML.AppendLine(@"Port Elevation (m): " + infrastructureModel.PortElevation_m + "\r\n");
                    sbKML.AppendLine(@"Port Spacing (m): " + infrastructureModel.PortSpacing_m + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Concentration (FC /100 ml): " + infrastructureModel.ReceivingWater_MPN_per_100ml + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Salinity (PSU): " + infrastructureModel.ReceivingWaterSalinity_PSU + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Temperature (ºC): " + infrastructureModel.ReceivingWaterTemperature_C + "\r\n");
                    sbKML.AppendLine(@"Vertical Angle (deg): " + infrastructureModel.VerticalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"</pre>");
                    sbKML.AppendLine(@"]]>");
                    sbKML.AppendLine(@"	</description>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureList[0].Lng + "," + mapInfoPointModelInfrastructureList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");

                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>Outfall " + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_grn-pushpin</styleUrl>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureOutfallList[0].Lng + "," + mapInfoPointModelInfrastructureOutfallList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");
                }

                // Doing LS
                foreach (InfrastructureModel infrastructureModel in infrastructureModelList.Where(c => c.InfrastructureType == InfrastructureTypeEnum.LiftStation).ToList())
                {
                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>" + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                    sbKML.AppendLine(@"	<description>");
                    sbKML.AppendLine(@"<![CDATA[");
                    sbKML.AppendLine(@"<pre>");
                    sbKML.AppendLine(@"Alarm System Type: " + baseEnumService.GetEnumText_AlarmSystemTypeEnum(infrastructureModel.AlarmSystemType) + "\r\n");
                    sbKML.AppendLine(@"Can overflow: " + infrastructureModel.CanOverflow.ToString() + "\r\n");
                    sbKML.AppendLine(@"Category: " + infrastructureModel.InfrastructureCategory + "\r\n");
                    sbKML.AppendLine(@"Collection System Type: " + baseEnumService.GetEnumText_CollectionSystemTypeEnum(infrastructureModel.CollectionSystemType) + "\r\n");
                    sbKML.AppendLine(@"Comments: " + infrastructureModel.Comment + "\r\n");
                    sbKML.AppendLine(@"Infrastructure Type: " + baseEnumService.GetEnumText_InfrastructureTypeEnum(infrastructureModel.InfrastructureType) + "\r\n");
                    sbKML.AppendLine(@"Percent Flow Of Total (%): " + infrastructureModel.PercFlowOfTotal + "\r\n");

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.LiftStation, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureList.Count > 0)
                    {
                        sbKML.AppendLine(@"Latitude Longitude: " + mapInfoPointModelInfrastructureList[0].Lat + " " + mapInfoPointModelInfrastructureList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Latitude Longitude: \r\n");
                    }

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureOutfallList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureOutfallList.Count > 0)
                    {
                        sbKML.AppendLine(@"Outfall: Latitude Longitude: " + mapInfoPointModelInfrastructureOutfallList[0].Lat + " " + mapInfoPointModelInfrastructureOutfallList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Outfall: Latitude Longitude: \r\n");
                    }
                    sbKML.AppendLine("\r\n\r\n");
                    sbKML.AppendLine("Outfall Information\r\n\r\n");
                    sbKML.AppendLine(@"Average Depth (m): " + infrastructureModel.AverageDepth_m + "\r\n");
                    sbKML.AppendLine(@"Decay Rate (/day): " + infrastructureModel.DecayRate_per_day + "\r\n");
                    sbKML.AppendLine(@"Distance From Shore (m): " + infrastructureModel.DistanceFromShore_m + "\r\n");
                    sbKML.AppendLine(@"Far Field Velocity (m/s): " + infrastructureModel.FarFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Horizontal Angle (deg): " + infrastructureModel.HorizontalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"Near Field Velocity (m/s): " + infrastructureModel.NearFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Number Of Ports: " + infrastructureModel.NumberOfPorts + "\r\n");
                    sbKML.AppendLine(@"Port Diameter (m): " + infrastructureModel.PortDiameter_m + "\r\n");
                    sbKML.AppendLine(@"Port Elevation (m): " + infrastructureModel.PortElevation_m + "\r\n");
                    sbKML.AppendLine(@"Port Spacing (m): " + infrastructureModel.PortSpacing_m + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Concentration (FC /100 ml): " + infrastructureModel.ReceivingWater_MPN_per_100ml + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Salinity (PSU): " + infrastructureModel.ReceivingWaterSalinity_PSU + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Temperature (ºC): " + infrastructureModel.ReceivingWaterTemperature_C + "\r\n");
                    sbKML.AppendLine(@"Vertical Angle (deg): " + infrastructureModel.VerticalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"</pre>");
                    sbKML.AppendLine(@"]]>");
                    sbKML.AppendLine(@"	</description>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureList[0].Lng + "," + mapInfoPointModelInfrastructureList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");

                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>Outfall " + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_grn-pushpin</styleUrl>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureOutfallList[0].Lng + "," + mapInfoPointModelInfrastructureOutfallList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");
                }

                // Doing Line Overflow
                foreach (InfrastructureModel infrastructureModel in infrastructureModelList.Where(c => c.InfrastructureType == InfrastructureTypeEnum.LineOverflow).ToList())
                {
                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>" + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                    sbKML.AppendLine(@"	<description>");
                    sbKML.AppendLine(@"<![CDATA[");
                    sbKML.AppendLine(@"<pre>");
                    sbKML.AppendLine(@"Alarm System Type: " + baseEnumService.GetEnumText_AlarmSystemTypeEnum(infrastructureModel.AlarmSystemType) + "\r\n");
                    sbKML.AppendLine(@"Can overflow: " + infrastructureModel.CanOverflow.ToString() + "\r\n");
                    sbKML.AppendLine(@"Category: " + infrastructureModel.InfrastructureCategory + "\r\n");
                    sbKML.AppendLine(@"Collection System Type: " + baseEnumService.GetEnumText_CollectionSystemTypeEnum(infrastructureModel.CollectionSystemType) + "\r\n");
                    sbKML.AppendLine(@"Comments: " + infrastructureModel.Comment + "\r\n");
                    sbKML.AppendLine(@"Infrastructure Type: " + baseEnumService.GetEnumText_InfrastructureTypeEnum(infrastructureModel.InfrastructureType) + "\r\n");
                    sbKML.AppendLine(@"Percent Flow Of Total (%): " + infrastructureModel.PercFlowOfTotal + "\r\n");

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.LineOverflow, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureList.Count > 0)
                    {
                        sbKML.AppendLine(@"Latitude Longitude: " + mapInfoPointModelInfrastructureList[0].Lat + " " + mapInfoPointModelInfrastructureList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Latitude Longitude: \r\n");
                    }

                    List <MapInfoPointModel> mapInfoPointModelInfrastructureOutfallList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(infrastructureModel.InfrastructureTVItemID, TVTypeEnum.Outfall, MapInfoDrawTypeEnum.Point);

                    if (mapInfoPointModelInfrastructureOutfallList.Count > 0)
                    {
                        sbKML.AppendLine(@"Outfall: Latitude Longitude: " + mapInfoPointModelInfrastructureOutfallList[0].Lat + " " + mapInfoPointModelInfrastructureOutfallList[0].Lng + "\r\n");
                    }
                    else
                    {
                        sbKML.AppendLine("Outfall: Latitude Longitude: \r\n");
                    }
                    sbKML.AppendLine("\r\n\r\n");
                    sbKML.AppendLine("Outfall Information\r\n\r\n");
                    sbKML.AppendLine(@"Average Depth (m): " + infrastructureModel.AverageDepth_m + "\r\n");
                    sbKML.AppendLine(@"Decay Rate (/day): " + infrastructureModel.DecayRate_per_day + "\r\n");
                    sbKML.AppendLine(@"Distance From Shore (m): " + infrastructureModel.DistanceFromShore_m + "\r\n");
                    sbKML.AppendLine(@"Far Field Velocity (m/s): " + infrastructureModel.FarFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Horizontal Angle (deg): " + infrastructureModel.HorizontalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"Near Field Velocity (m/s): " + infrastructureModel.NearFieldVelocity_m_s + "\r\n");
                    sbKML.AppendLine(@"Number Of Ports: " + infrastructureModel.NumberOfPorts + "\r\n");
                    sbKML.AppendLine(@"Port Diameter (m): " + infrastructureModel.PortDiameter_m + "\r\n");
                    sbKML.AppendLine(@"Port Elevation (m): " + infrastructureModel.PortElevation_m + "\r\n");
                    sbKML.AppendLine(@"Port Spacing (m): " + infrastructureModel.PortSpacing_m + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Concentration (FC /100 ml): " + infrastructureModel.ReceivingWater_MPN_per_100ml + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Salinity (PSU): " + infrastructureModel.ReceivingWaterSalinity_PSU + "\r\n");
                    sbKML.AppendLine(@"Receiving Water Temperature (ºC): " + infrastructureModel.ReceivingWaterTemperature_C + "\r\n");
                    sbKML.AppendLine(@"Vertical Angle (deg): " + infrastructureModel.VerticalAngle_deg + "\r\n");
                    sbKML.AppendLine(@"</pre>");
                    sbKML.AppendLine(@"]]>");
                    sbKML.AppendLine(@"	</description>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureList[0].Lng + "," + mapInfoPointModelInfrastructureList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");

                    sbKML.AppendLine(@"	<Placemark>");
                    sbKML.AppendLine(@"	<name>Outfall " + tvItemModelInfrastructureList.Where(c => c.TVItemID == infrastructureModel.InfrastructureTVItemID).Select(c => c.TVText).FirstOrDefault() + "</name>");
                    sbKML.AppendLine(@"	<visibility>0</visibility>");
                    sbKML.AppendLine(@"<styleUrl>#msn_grn-pushpin</styleUrl>");

                    sbKML.AppendLine(@"		<Point>");
                    sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelInfrastructureOutfallList[0].Lng + "," + mapInfoPointModelInfrastructureOutfallList[0].Lat + ",0</coordinates>");
                    sbKML.AppendLine(@"		</Point>");
                    sbKML.AppendLine(@"	</Placemark>");
                }
                sbKML.AppendLine(@" </Folder>");
            }
            sbKML.AppendLine(@" </Folder>");

            // Doing Short Pollution Source Site
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>Short Pollution Source Sites</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            List <PolSourceSiteModel> polSourceSiteModelList = polSourceSiteService.GetPolSourceSiteModelListWithSubsectorTVItemIDDB(tvItemModelSubsector.TVItemID);

            foreach (PolSourceSiteModel polSourceSiteModel in polSourceSiteModelList.OrderBy(c => c.Site).ToList())
            {
                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + polSourceSiteModel.Site.ToString() + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                sbKML.AppendLine(@"	<description>");
                sbKML.AppendLine(@"<![CDATA[");
                sbKML.AppendLine(@"<pre>");

                PolSourceObservationModel polSourceObservationModel = polSourceSiteService._PolSourceObservationService.GetPolSourceObservationModelLatestWithPolSourceSiteTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);
                if (polSourceObservationModel != null)
                {
                    List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = polSourceSiteService._PolSourceObservationService._PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(polSourceObservationModel.PolSourceObservationID);

                    string SelectedObservation = "Selected: \r\n";
                    foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList)
                    {
                        foreach (PolSourceObsInfoEnum polSourceObsInfo in polSourceObservationIssueModel.PolSourceObsInfoList)
                        {
                            SelectedObservation += baseEnumService.GetEnumText_PolSourceObsInfoReportEnum(polSourceObsInfo);
                        }
                        SelectedObservation += "\r\n\r\n";
                    }

                    sbKML.AppendLine("Written: \r\n" + (string.IsNullOrWhiteSpace(polSourceObservationModel.Observation_ToBeDeleted) ? "" : polSourceObservationModel.Observation_ToBeDeleted.ToString()) + "\r\n\r\n" + SelectedObservation);
                }
                else
                {
                    string SelectedObservation = "Selected: \r\n";
                    sbKML.AppendLine("Written: \r\n\r\n" + SelectedObservation);
                }

                sbKML.AppendLine(@"</pre>");
                sbKML.AppendLine(@"]]>");
                sbKML.AppendLine(@"	</description>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(polSourceSiteModel.PolSourceSiteTVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");
            }
            sbKML.AppendLine(@" </Folder>");

            // Doing Long Pollution Source Site
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>Long Pollution Source Sites</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            polSourceSiteModelList = polSourceSiteService.GetPolSourceSiteModelListWithSubsectorTVItemIDDB(tvItemModelSubsector.TVItemID);

            foreach (PolSourceSiteModel polSourceSiteModel in polSourceSiteModelList.OrderBy(c => c.Site).ToList())
            {
                TVItemModel tvItemModelPolSourceSite = tvItemService.GetTVItemModelWithTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);

                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + tvItemModelPolSourceSite.TVText + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");
                sbKML.AppendLine(@"	<description>");
                sbKML.AppendLine(@"<![CDATA[");
                sbKML.AppendLine(@"<pre>");

                PolSourceObservationModel polSourceObservationModel = polSourceSiteService._PolSourceObservationService.GetPolSourceObservationModelLatestWithPolSourceSiteTVItemIDDB(polSourceSiteModel.PolSourceSiteTVItemID);
                if (polSourceObservationModel != null)
                {
                    List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = polSourceSiteService._PolSourceObservationService._PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithPolSourceObservationIDDB(polSourceObservationModel.PolSourceObservationID);

                    string SelectedObservation = "Selected: \r\n";
                    foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList)
                    {
                        foreach (PolSourceObsInfoEnum polSourceObsInfo in polSourceObservationIssueModel.PolSourceObsInfoList)
                        {
                            SelectedObservation += baseEnumService.GetEnumText_PolSourceObsInfoReportEnum(polSourceObsInfo);
                        }
                        SelectedObservation += "\r\n\r\n";
                    }

                    sbKML.AppendLine("Written: \r\n" + (string.IsNullOrWhiteSpace(polSourceObservationModel.Observation_ToBeDeleted) ? "" : polSourceObservationModel.Observation_ToBeDeleted.ToString()) + "\r\n\r\n" + SelectedObservation);
                }
                else
                {
                    string SelectedObservation = "Selected: \r\n";
                    sbKML.AppendLine("Written: \r\n\r\n" + SelectedObservation);
                }

                sbKML.AppendLine(@"</pre>");
                sbKML.AppendLine(@"]]>");
                sbKML.AppendLine(@"	</description>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelPolSourceSite.TVItemID, TVTypeEnum.PolSourceSite, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");
            }
            sbKML.AppendLine(@" </Folder>");


            // Doing MWQM Site
            sbKML.AppendLine(@" <Folder>");
            sbKML.AppendLine(@"	<name>MWQM Sites</name>");
            sbKML.AppendLine(@"	<visibility>0</visibility>");
            List <TVItemModel> tvItemModelMWQMSiteList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.MWQMSite);

            foreach (TVItemModel tvItemModelMWQMSite in tvItemModelMWQMSiteList)
            {
                // Doing point
                sbKML.AppendLine(@"	<Placemark>");
                sbKML.AppendLine(@"	<name>" + tvItemModelMWQMSite.TVText + "</name>");
                sbKML.AppendLine(@"	<visibility>0</visibility>");
                sbKML.AppendLine(@"<styleUrl>#msn_ylw-pushpin</styleUrl>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelMWQMSite.TVItemID, TVTypeEnum.MWQMSite, MapInfoDrawTypeEnum.Point);

                sbKML.AppendLine(@"		<Point>");
                sbKML.AppendLine(@"			<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
                sbKML.AppendLine(@"		</Point>");
                sbKML.AppendLine(@"	</Placemark>");
            }
            sbKML.AppendLine(@" </Folder>");

            sbKML.AppendLine(@"	</Folder>");

            sbKML.AppendLine(@"</Document>");
            sbKML.AppendLine(@"</kml>");

            StreamWriter sw = fi.CreateText();

            sw.Write(sbKML.ToString());
            sw.Close();
        }
Пример #16
0
        public bool CreateQCPolSourceNullAll()
        {
            lblStatus.Text = "Starting ... CreateSanitaryQC - CreateQCPolSourceNullAll";
            Application.DoEvents();

            if (Cancel)
            {
                return(false);
            }

            TVItemService tvItemServiceR = new TVItemService(LanguageEnum.en, user);

            TVItemModel tvItemModelRoot = tvItemServiceR.GetRootTVItemModelDB();

            if (!CheckModelOK <TVItemModel>(tvItemModelRoot))
            {
                return(false);
            }

            TVItemModel tvItemModelCanada = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, "Canada", TVTypeEnum.Country);

            if (!CheckModelOK <TVItemModel>(tvItemModelCanada))
            {
                return(false);
            }

            TVItemModel tvItemModelQC = tvItemServiceR.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelCanada.TVItemID, "Québec", TVTypeEnum.Province);

            if (!CheckModelOK <TVItemModel>(tvItemModelQC))
            {
                return(false);
            }

            List <TVItemModel> TVItemModelSubsectorList = tvItemServiceR.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelQC.TVItemID, TVTypeEnum.Subsector);

            if (TVItemModelSubsectorList.Count == 0)
            {
                richTextBoxStatus.AppendText("Error: could not find TVItem Subsector for " + tvItemModelQC.TVText + "\r\n");
                return(false);
            }

            List <MapInfo> mapInfoList = (from c in TVItemModelSubsectorList
                                          from m in tvItemServiceR.db.MapInfos
                                          where c.TVItemID == m.TVItemID &&
                                          m.MapInfoDrawType == (int)MapInfoDrawTypeEnum.Polygon
                                          select m).ToList();

            List <TVItemSubsectorAndCoordCentroid> TVItemSubsectorAndCoordCentroidList = (from c in mapInfoList
                                                                                          let lat = (c.LatMax - c.LatMin) / 2 + c.LatMin
                                                                                                    let lng = (c.LngMax - c.LngMin) / 2 + c.LngMin
                                                                                                              select new TVItemSubsectorAndCoordCentroid
            {
                TVItemID = c.TVItemID,
                Lat = (float)lat,
                Lng = (float)lng,
            }).ToList();

            List <string> sectorList = new List <string>();

            using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
            {
                sectorList = (from s in dbQC.geo_pollution_p
                              select s.secteur).Distinct().ToList();
            }

            List <string> sectorOrderedList = (from c in sectorList
                                               orderby c
                                               select c).ToList();

            Application.DoEvents();

            List <PCCSM.geo_pollution_p> polQCList = new List <PCCSM.geo_pollution_p>();

            using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
            {
                polQCList = (from c in dbQC.geo_pollution_p
                             where c.secteur == null &&
                             c.id_geo_pollution_p != 0 &&
                             (c.x != null && c.y != null)
                             select c).ToList <PCCSM.geo_pollution_p>();
            }

            int TotalCount = polQCList.Count();
            int Count      = 0;

            foreach (PCCSM.geo_pollution_p pqc in polQCList)
            {
                Count         += 1;
                lblStatus.Text = (Count * 100 / TotalCount).ToString() + "... CreateSanitaryQC for sector " + pqc.secteur;
                Application.DoEvents();

                TVItemService                    tvItemService                    = new TVItemService(LanguageEnum.en, user);
                PolSourceSiteService             polSourceSiteService             = new PolSourceSiteService(LanguageEnum.en, user);
                MapInfoService                   mapInfoService                   = new MapInfoService(LanguageEnum.en, user);
                PolSourceObservationService      polSourceObservationService      = new PolSourceObservationService(LanguageEnum.en, user);
                PolSourceObservationIssueService polSourceObservationIssueService = new PolSourceObservationIssueService(LanguageEnum.en, user);

                PolSourceSiteModel polSourceSiteModelNew = new PolSourceSiteModel();

                string Code = tvItemService.CleanText(pqc.code.ToUpper());

                List <PolSourceObsInfoEnum> polSourceObsInfoList = GetPolSourceType(Code.Trim(), "", "QC");
                string ObservationInfo = (int)polSourceObsInfoList[0] + "," + (int)polSourceObsInfoList[1] + ",";
                polSourceSiteModelNew.IsPointSource = true;
                //if (pqc.status == "actif")
                //{
                //    polSourceSiteModelNew.IsActive = true;
                //}
                //else
                //{
                //    polSourceSiteModelNew.IsActive = false;
                //}
                polSourceSiteModelNew.InactiveReason = PolSourceInactiveReasonEnum.Error;
                polSourceSiteModelNew.Oldsiteid      = pqc.id_geo_pollution_p;

                // Pollution Source Type
                string PolSourceSiteTVText = tvItemService.CleanText(Code + "      ".Substring(0, 6 - pqc.id_geo_pollution_p.ToString().Length) + pqc.id_geo_pollution_p.ToString());

                List <MapInfoModel> mapInfoModelListSubsector = mapInfoService.GetMapInfoModelWithLatAndLngInPolygonWithTVTypeDB((float)pqc.y, (float)pqc.x, TVTypeEnum.Subsector);
                int TempTVItemID = 0;
                if (mapInfoModelListSubsector.Count == 0)
                {
                    float SmallestDistance = 100000000f;
                    foreach (TVItemSubsectorAndCoordCentroid tvItemSubsectorAndCoordCentroid in TVItemSubsectorAndCoordCentroidList)
                    {
                        float TempDistance = (float)mapInfoService.CalculateDistance((double)pqc.y, (double)pqc.x, (double)tvItemSubsectorAndCoordCentroid.Lat, (double)tvItemSubsectorAndCoordCentroid.Lng, mapInfoService.R);
                        if (SmallestDistance > TempDistance)
                        {
                            TempTVItemID     = tvItemSubsectorAndCoordCentroid.TVItemID;
                            SmallestDistance = TempDistance;
                        }
                    }
                }
                else
                {
                    TempTVItemID = mapInfoModelListSubsector[0].TVItemID;
                }

                if (TempTVItemID == 0)
                {
                    richTextBoxStatus.AppendText("TempTVItemID equal 0");
                    return(false);
                }

                TVItemModel tvItemModelPolSourceSite = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(TempTVItemID, PolSourceSiteTVText, TVTypeEnum.PolSourceSite);
                if (!CheckModelOK <TVItemModel>(tvItemModelPolSourceSite))
                {
                    tvItemModelPolSourceSite = tvItemService.PostCreateTVItem(TempTVItemID, PolSourceSiteTVText, PolSourceSiteTVText, TVTypeEnum.PolSourceSite);
                    if (!CheckModelOK <TVItemModel>(tvItemModelPolSourceSite))
                    {
                        return(false);
                    }
                }
                ;

                List <Coord> coordList = new List <Coord>()
                {
                    new Coord()
                    {
                        Lat = (float)pqc.y,
                        Lng = (float)pqc.x,
                    }
                };

                MapInfoModel mapInfoModelRet = mapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.PolSourceSite, tvItemModelPolSourceSite.TVItemID);
                if (!CheckModelOK <MapInfoModel>(mapInfoModelRet))
                {
                    return(false);
                }

                polSourceSiteModelNew.PolSourceSiteTVItemID = tvItemModelPolSourceSite.TVItemID;
                polSourceSiteModelNew.PolSourceSiteTVText   = PolSourceSiteTVText;

                PolSourceSiteModel polSourceSiteModelRet = polSourceSiteService.GetPolSourceSiteModelWithPolSourceSiteTVItemIDDB(tvItemModelPolSourceSite.TVItemID);
                if (!string.IsNullOrWhiteSpace(polSourceSiteModelRet.Error))
                {
                    polSourceSiteModelRet = polSourceSiteService.PostAddPolSourceSiteDB(polSourceSiteModelNew);
                    if (!CheckModelOK <PolSourceSiteModel>(polSourceSiteModelRet))
                    {
                        return(false);
                    }
                }

                string TVTextObservation = tvItemService.CleanText(string.IsNullOrEmpty(pqc.description) ? "" : pqc.description);;

                PolSourceObservationModel polSourceObservationModelNew = new PolSourceObservationModel();
                if (pqc.date_observation == null)
                {
                    polSourceObservationModelNew.ObservationDate_Local = new DateTime(1970, 1, 1);
                }
                else
                {
                    polSourceObservationModelNew.ObservationDate_Local = (DateTime)(pqc.date_observation.Value).AddHours(1);
                }
                string Observateur = "";
                if (pqc.observateur != null)
                {
                    if (pqc.observateur.Length > 98)
                    {
                        Observateur = pqc.observateur.Substring(0, 60);
                    }
                    else
                    {
                        Observateur = pqc.observateur;
                    }
                }

                string TVText = "Inspector " + Observateur;
                TVText = (TVText.Length > 50 ? TVText.Substring(0, 50) : TVText);
                TVItemModel tvItemModelContact = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVText, TVTypeEnum.Contact);
                if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                {
                    tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVText, TVText, TVTypeEnum.Contact);
                    if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                    {
                        return(false);
                    }
                }

                polSourceObservationModelNew.ContactTVItemID         = tvItemModelContact.TVItemID;
                polSourceObservationModelNew.Observation_ToBeDeleted = TVTextObservation;
                polSourceObservationModelNew.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;

                PolSourceObservationModel polSourceObservationModelRet = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew);
                if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet.Error))
                {
                    PolSourceObservationModel polSourceObservationModel = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew);
                    if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModel))
                    {
                        return(false);
                    }
                }

                PolSourceObservationIssueModel polSourceObservationIssueModelNew = new PolSourceObservationIssueModel()
                {
                    PolSourceObservationID = polSourceObservationModelNew.PolSourceObservationID,
                    ObservationInfo        = ObservationInfo,
                    PolSourceObsInfoList   = polSourceObsInfoList,
                    Ordinal = 0,
                };

                PolSourceObservationIssueModel polSourceObservationIssueModelRet = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew);
                if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet.Error))
                {
                    polSourceObservationIssueModelRet = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew);
                    if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet))
                    {
                        return(false);
                    }
                }

                // do historic PolSourceObservation

                List <PCCSM.db_histo_operation> histoPolSourceList = new List <PCCSM.db_histo_operation>();
                using (PCCSM.pccsmEntities dbQC = new PCCSM.pccsmEntities())
                {
                    histoPolSourceList = (from c in dbQC.geo_pollution_p
                                          from h in dbQC.db_histo_operation
                                          where c.id_geo_pollution_p == h.id_geo_pollution_p &&
                                          c.id_geo_pollution_p == pqc.id_geo_pollution_p
                                          select h).ToList();
                }

                foreach (PCCSM.db_histo_operation hist in histoPolSourceList)
                {
                    Application.DoEvents();

                    PolSourceObservationModel polSourceObservationModelNew2 = new PolSourceObservationModel();
                    if (hist.date_operation == null)
                    {
                        polSourceObservationModelNew2.ObservationDate_Local = new DateTime(1970, 1, 1);
                    }
                    else
                    {
                        polSourceObservationModelNew2.ObservationDate_Local = (DateTime)hist.date_operation;
                    }
                    if (hist.auteur != null)
                    {
                        if (hist.auteur.Length > 98)
                        {
                            Observateur = hist.auteur.Substring(0, 60);
                        }
                        else
                        {
                            Observateur = hist.auteur;
                        }
                    }

                    TVText = "Inspector " + Observateur;
                    TVText = (TVText.Length > 50 ? TVText.Substring(0, 50) : TVText);
                    TVItemModel tvItemModelContact2 = tvItemService.GetChildTVItemModelWithTVItemIDAndTVTextStartWithAndTVTypeDB(tvItemModelRoot.TVItemID, TVText, TVTypeEnum.Contact);
                    if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                    {
                        tvItemModelContact = tvItemService.PostCreateTVItem(tvItemModelRoot.TVItemID, TVText, TVText, TVTypeEnum.Contact);
                        if (!CheckModelOK <TVItemModel>(tvItemModelContact))
                        {
                            return(false);
                        }
                    }

                    polSourceObservationModelNew2.ContactTVItemID = tvItemModelContact2.TVItemID;

                    polSourceObservationModelNew2.Observation_ToBeDeleted = TVTextObservation;
                    polSourceObservationModelNew2.PolSourceSiteID         = polSourceSiteModelRet.PolSourceSiteID;

                    PolSourceObservationModel polSourceObservationModelRet2 = polSourceObservationService.GetPolSourceObservationModelExistDB(polSourceObservationModelNew2);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationModelRet2.Error))
                    {
                        polSourceObservationModelRet2 = polSourceObservationService.PostAddPolSourceObservationDB(polSourceObservationModelNew2);
                        if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                        {
                            return(false);
                        }
                    }

                    PolSourceObservationIssueModel polSourceObservationIssueModelNew2 = new PolSourceObservationIssueModel()
                    {
                        PolSourceObservationID = polSourceObservationModelNew2.PolSourceObservationID,
                        ObservationInfo        = ObservationInfo,
                        PolSourceObsInfoList   = polSourceObsInfoList,
                        Ordinal = 0,
                    };

                    PolSourceObservationIssueModel polSourceObservationIssueModelRet2 = polSourceObservationIssueService.GetPolSourceObservationIssueModelExistDB(polSourceObservationIssueModelNew2);
                    if (!string.IsNullOrWhiteSpace(polSourceObservationIssueModelRet2.Error))
                    {
                        polSourceObservationIssueModelRet2 = polSourceObservationIssueService.PostAddPolSourceObservationIssueDB(polSourceObservationIssueModelNew2);
                        if (!CheckModelOK <PolSourceObservationModel>(polSourceObservationModelRet2))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Пример #17
0
        private bool GenerateHTMLSUBSECTOR_POLLUTION_SOURCE_SITES(StringBuilder sbTemp)
        {
            int          Percent  = 10;
            string       NotUsed  = "";
            LanguageEnum language = _TaskRunnerBaseService._BWObj.appTaskModel.Language;

            _TaskRunnerBaseService.SendPercentToDB(_TaskRunnerBaseService._BWObj.appTaskModel.AppTaskID, Percent);
            _TaskRunnerBaseService.SendStatusTextToDB(_TaskRunnerBaseService.GetTextLanguageFormat1List("Creating_", ReportGenerateObjectsKeywordEnum.SUBSECTOR_POLLUTION_SOURCE_SITES.ToString()));


            //sbTemp.AppendLine("<h2>SUBSECTOR_POLLUTION_SOURCE_SITES - Not implemented</h2>");

            List <string> ParamValueList = Parameters.Split("|||".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();

            // TVItemID and Year already loaded

            TVItemModel tvItemModelSubsector = _TVItemService.GetTVItemModelWithTVItemIDDB(TVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelSubsector.Error))
            {
                NotUsed = string.Format(TaskRunnerServiceRes.CouldNotFind_With_Equal_, TaskRunnerServiceRes.TVItem, TaskRunnerServiceRes.TVItemID, TVItemID.ToString());
                _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat3List("CouldNotFind_With_Equal_", TaskRunnerServiceRes.TVItem, TaskRunnerServiceRes.TVItemID, TVItemID.ToString());
                return(false);
            }

            string ServerPath = _TVFileService.GetServerFilePath(tvItemModelSubsector.TVItemID);

            _TaskRunnerBaseService.SendPercentToDB(_TaskRunnerBaseService._BWObj.appTaskModel.AppTaskID, 5);

            List <TVItemModel>                    tvItemModelListPolSourceSite       = _TVItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.PolSourceSite);
            List <PolSourceSiteModel>             polSourceSiteModelList             = _PolSourceSiteService.GetPolSourceSiteModelListWithSubsectorTVItemIDDB(TVItemID).OrderBy(c => c.Site).ToList();
            List <PolSourceObservationModel>      polSourceObservationModelList      = _PolSourceObservationService.GetPolSourceObservationModelListWithSubsectorTVItemIDDB(TVItemID);
            List <PolSourceObservationIssueModel> polSourceObservationIssueModelList = _PolSourceObservationIssueService.GetPolSourceObservationIssueModelListWithSubsectorTVItemIDDB(TVItemID);
            List <int> TVItemIDPolSourceSiteActiveList   = tvItemModelListPolSourceSite.Where(c => c.IsActive == true).Select(c => c.TVItemID).ToList();
            List <int> TVItemIDPolSourceSiteInactiveList = tvItemModelListPolSourceSite.Where(c => c.IsActive == false).Select(c => c.TVItemID).ToList();
            List <int> TVItemIDCivicAddressList          = polSourceSiteModelList.Where(c => c.CivicAddressTVItemID != null && c.CivicAddressTVItemID != 0).Where(c => c != null).Select(c => (int)c.CivicAddressTVItemID).ToList();
            List <int> TVItemIDContactList = polSourceObservationModelList.Select(c => c.ContactTVItemID).ToList();

            List <Address>        addressList              = new List <Address>();
            List <MapInfo>        mapInfoActiveList        = new List <MapInfo>();
            List <MapInfo>        mapInfoInactiveList      = new List <MapInfo>();
            List <MapInfoPoint>   mapInfoPointActiveList   = new List <MapInfoPoint>();
            List <MapInfoPoint>   mapInfoPointInactiveList = new List <MapInfoPoint>();
            List <TVItemLanguage> countryList              = new List <TVItemLanguage>();
            List <TVItemLanguage> provinceList             = new List <TVItemLanguage>();
            List <TVItemLanguage> municipalityList         = new List <TVItemLanguage>();
            List <TVItemLanguage> contactList              = new List <TVItemLanguage>();

            using (CSSPDBEntities db2 = new CSSPDBEntities())
            {
                addressList = (from c in db2.Addresses
                               from a in TVItemIDCivicAddressList
                               where c.AddressTVItemID == a
                               select c).ToList();

                List <int> countryTVItemIDList      = addressList.Select(c => c.CountryTVItemID).ToList();
                List <int> provinceTVItemIDList     = addressList.Select(c => c.ProvinceTVItemID).ToList();
                List <int> municipalityTVItemIDList = addressList.Select(c => c.MunicipalityTVItemID).ToList();

                countryList = (from c in db2.TVItemLanguages
                               from a in countryTVItemIDList
                               where c.TVItemID == a &&
                               c.Language == (int)language
                               select c).ToList();

                provinceList = (from c in db2.TVItemLanguages
                                from a in provinceTVItemIDList
                                where c.TVItemID == a &&
                                c.Language == (int)language
                                select c).ToList();

                municipalityList = (from c in db2.TVItemLanguages
                                    from a in municipalityTVItemIDList
                                    where c.TVItemID == a &&
                                    c.Language == (int)language
                                    select c).ToList();

                contactList = (from c in db2.TVItemLanguages
                               from a in TVItemIDContactList
                               where c.TVItemID == a &&
                               c.Language == (int)language
                               select c).ToList();


                mapInfoActiveList = (from c in db2.MapInfos
                                     from a in TVItemIDPolSourceSiteActiveList
                                     where c.TVItemID == a
                                     select c).ToList();

                mapInfoInactiveList = (from c in db2.MapInfos
                                       from a in TVItemIDPolSourceSiteInactiveList
                                       where c.TVItemID == a
                                       select c).ToList();

                List <int> mapInfoIDActiveList = mapInfoActiveList.Select(c => c.MapInfoID).ToList();

                mapInfoPointActiveList = (from c in db2.MapInfoPoints
                                          from a in mapInfoIDActiveList
                                          where c.MapInfoID == a
                                          select c).ToList();

                List <int> mapInfoIDInactiveList = mapInfoInactiveList.Select(c => c.MapInfoID).ToList();

                mapInfoPointInactiveList = (from c in db2.MapInfoPoints
                                            from a in mapInfoIDInactiveList
                                            where c.MapInfoID == a
                                            select c).ToList();
            }

            _TaskRunnerBaseService.SendPercentToDB(_TaskRunnerBaseService._BWObj.appTaskModel.AppTaskID, 10);

            //sbTemp.AppendLine(@"<p>|||PAGE_BREAK|||</p>");
            //sbTemp.AppendLine("");
            //sbTemp.AppendLine($@"<h1 style=""text-align: center"">{ tvItemModelSubsector.TVText }</h1>");
            //sbTemp.AppendLine($@"<h2 style=""text-align: center"">{ TaskRunnerServiceRes.ActivePollutionSourceSites }</h2>");
            foreach (TVItemModel tvItemModelPSSActive in tvItemModelListPolSourceSite.Where(c => c.IsActive == true))
            {
                PolSourceSiteModel polSourceSiteModel = polSourceSiteModelList.Where(c => c.PolSourceSiteTVItemID == tvItemModelPSSActive.TVItemID).FirstOrDefault();

                if (polSourceSiteModel != null)
                {
                    sbTemp.AppendLine($@"<div>");
                    sbTemp.AppendLine($@"<p>");
                    sbTemp.AppendLine($@"<strong>{ TaskRunnerServiceRes.Site }</strong>: { polSourceSiteModel.Site }&nbsp;&nbsp;&nbsp;&nbsp;");

                    MapInfo mapInfo = mapInfoActiveList.Where(c => c.TVItemID == tvItemModelPSSActive.TVItemID).FirstOrDefault();
                    if (mapInfo != null)
                    {
                        List <MapInfoPoint> mapInfoPointListCurrent = mapInfoPointActiveList.Where(c => c.MapInfoID == mapInfo.MapInfoID).ToList();
                        if (mapInfoPointListCurrent.Count > 0)
                        {
                            sbTemp.AppendLine($@"<span><strong>{ TaskRunnerServiceRes.Lat } { TaskRunnerServiceRes.Long }</strong>: { mapInfoPointListCurrent[0].Lat.ToString("F5") } { mapInfoPointListCurrent[0].Lng.ToString("F5") }</span>");
                        }
                    }
                    else
                    {
                        sbTemp.AppendLine($@"<span><strong>{ TaskRunnerServiceRes.Lat } { TaskRunnerServiceRes.Long }</strong>: --- ---</span>");
                    }
                    sbTemp.AppendLine($@"</p>");


                    if (polSourceSiteModel.CivicAddressTVItemID != null)
                    {
                        if (polSourceSiteModel.CivicAddressTVItemID != 0)
                        {
                            Address address = addressList.Where(c => c.AddressTVItemID == ((int)polSourceSiteModel.CivicAddressTVItemID)).FirstOrDefault();
                            if (address != null)
                            {
                                sbTemp.AppendLine($@"<p>");
                                if (_TaskRunnerBaseService._BWObj.appTaskModel.Language == LanguageEnum.fr)
                                {
                                    string CountryText      = countryList.Where(c => c.TVItemID == address.CountryTVItemID).Select(c => c.TVText).FirstOrDefault();
                                    string ProvinceText     = provinceList.Where(c => c.TVItemID == address.ProvinceTVItemID).Select(c => c.TVText).FirstOrDefault();
                                    string MunicipalityText = municipalityList.Where(c => c.TVItemID == address.MunicipalityTVItemID).Select(c => c.TVText).FirstOrDefault();
                                    string StreetTypeText   = _BaseEnumService.GetEnumText_StreetTypeEnum((StreetTypeEnum)address.StreetType);
                                    string AddressText      = $" { address.StreetNumber} { address.StreetName } { StreetTypeText }, { MunicipalityText }, { ProvinceText }, { CountryText }";
                                    sbTemp.AppendLine($@"<strong>{ TaskRunnerServiceRes.CivicAddress }</strong>: { AddressText }");
                                }
                                else
                                {
                                    string CountryText      = countryList.Where(c => c.TVItemID == address.CountryTVItemID).Select(c => c.TVText).FirstOrDefault();
                                    string ProvinceText     = provinceList.Where(c => c.TVItemID == address.ProvinceTVItemID).Select(c => c.TVText).FirstOrDefault();
                                    string MunicipalityText = municipalityList.Where(c => c.TVItemID == address.MunicipalityTVItemID).Select(c => c.TVText).FirstOrDefault();
                                    string StreetTypeText   = _BaseEnumService.GetEnumText_StreetTypeEnum((StreetTypeEnum)address.StreetType);
                                    string AddressText      = $" { address.StreetNumber}, { StreetTypeText } { address.StreetName }, { MunicipalityText }, { ProvinceText }, { CountryText }";
                                    sbTemp.AppendLine($@"<strong>{ TaskRunnerServiceRes.CivicAddress }</strong>: { AddressText }");
                                }
                                sbTemp.AppendLine($@"</p>");
                            }
                        }
                    }

                    PolSourceObservationModel polSourceObservationModel = polSourceObservationModelList.Where(c => c.PolSourceSiteID == polSourceSiteModel.PolSourceSiteID).OrderByDescending(c => c.ObservationDate_Local).FirstOrDefault();

                    if (polSourceObservationModel != null)
                    {
                        sbTemp.AppendLine($@"<p>");
                        string ContactObsText = contactList.Where(c => c.TVItemID == polSourceObservationModel.ContactTVItemID).Select(c => c.TVText).FirstOrDefault();
                        sbTemp.AppendLine($@"<strong>{ TaskRunnerServiceRes.LastObservationDate }</strong>: { polSourceObservationModel.ObservationDate_Local.ToString("yyyy MMMM dd") } <strong>{ TaskRunnerServiceRes.by }</strong>: { ContactObsText }");
                        sbTemp.AppendLine($@"</p>");

                        int IssueNumber = 0;
                        foreach (PolSourceObservationIssueModel polSourceObservationIssueModel in polSourceObservationIssueModelList.Where(c => c.PolSourceObservationID == polSourceObservationModel.PolSourceObservationID).OrderBy(c => c.Ordinal).ToList())
                        {
                            IssueNumber += 1;
                            string TVText = "";
                            sbTemp.AppendLine($@"<p><strong>{ TaskRunnerServiceRes.Issue }</strong>: { IssueNumber }</p>");
                            sbTemp.AppendLine($@"<blockquote>");
                            List <string> ObservationInfoList = (string.IsNullOrWhiteSpace(polSourceObservationIssueModel.ObservationInfo) ? new List <string>() : polSourceObservationIssueModel.ObservationInfo.Trim().Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList());

                            for (int i = 0, countObs = ObservationInfoList.Count; i < countObs; i++)
                            {
                                string Temp = _BaseEnumService.GetEnumText_PolSourceObsInfoReportEnum((PolSourceObsInfoEnum)int.Parse(ObservationInfoList[i]));
                                switch (ObservationInfoList[i].Substring(0, 3))
                                {
                                case "101":
                                {
                                    Temp = Temp.Replace("Source", "<br /><strong>Source</strong>");
                                }
                                break;

                                //case "153":
                                //    {
                                //        Temp = Temp.Replace("Dilution Analyses", "     Dilution Analyses");
                                //    }
                                //    break;
                                case "250":
                                {
                                    Temp = Temp.Replace("Pathway", "<br /><strong>Pathway</strong>");
                                }
                                break;

                                case "900":
                                {
                                    Temp = Temp.Replace("Status", "<br /><strong>Status</strong>");
                                }
                                break;

                                case "910":
                                {
                                    Temp = Temp.Replace("Risk", "<br /><strong>Risk</strong>");
                                }
                                break;

                                case "110":
                                case "120":
                                case "122":
                                case "151":
                                case "152":
                                case "153":
                                case "155":
                                case "156":
                                case "157":
                                case "163":
                                case "166":
                                case "167":
                                case "170":
                                case "171":
                                case "172":
                                case "173":
                                case "176":
                                case "178":
                                case "181":
                                case "182":
                                case "183":
                                case "185":
                                case "186":
                                case "187":
                                case "190":
                                case "191":
                                case "192":
                                case "193":
                                case "194":
                                case "196":
                                case "198":
                                case "199":
                                case "220":
                                case "930":
                                {
                                    //Temp = @"<span class=""hidden"">" + Temp + "</span>";
                                }
                                break;

                                default:
                                    break;
                                }
                                TVText = TVText + Temp;
                            }

                            sbTemp.AppendLine($@"{ TVText }");
                            if (polSourceObservationIssueModel.ExtraComment != null)
                            {
                                if (polSourceObservationIssueModel.ExtraComment.Length > 0)
                                {
                                    sbTemp.AppendLine($@"<p><strong>{ TaskRunnerServiceRes.ExtraComment }</strong></p>");
                                    sbTemp.AppendLine($@"<p>");
                                    sbTemp.AppendLine($@"{ polSourceObservationIssueModel.ExtraComment }");
                                    sbTemp.AppendLine($@"</p>");
                                }
                            }
                            sbTemp.AppendLine($@"</blockquote>");
                        }
                    }

                    sbTemp.AppendLine($@"</div>");
                    sbTemp.AppendLine($@"<hr />");
                }
            }

            Percent = 98;
            _TaskRunnerBaseService.SendPercentToDB(_TaskRunnerBaseService._BWObj.appTaskModel.AppTaskID, Percent);

            return(true);
        }
Пример #18
0
        public JsonResult PolSourceObservationDeleteJSON(int PolSourceObservationID)
        {
            PolSourceObservationModel polSourceObservationModel = _PolSourceSiteService._PolSourceObservationService.PostDeletePolSourceObservationDB(PolSourceObservationID);

            return(Json(polSourceObservationModel.Error, JsonRequestBehavior.AllowGet));
        }