Exemple #1
0
        public void TVItemController__content_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                // Arrange
                controllerAction = "_content";
                contactModel     = contactModelListGood[0];

                // Act
                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    // Arrange
                    TVItemModel tvItemModelRoot = tvItemService.GetRootTVItemModelDB();
                    string      Q = "!View/" + tvItemModelRoot.TVText + "|||" + tvItemModelRoot.TVItemID;

                    // Act
                    PartialViewResult partialViewResult = controller._content(Q) as PartialViewResult;

                    // Assert
                    // Assert
                    URLModel urlModel = (URLModel)partialViewResult.ViewBag.URLModel;
                    Assert.IsNotNull(partialViewResult);
                    Assert.AreEqual(2, urlModel.TVTextList.Count);
                    Assert.AreEqual("!View", urlModel.TVTextList[0]);
                    Assert.AreEqual(tvItemModelRoot.TVText, urlModel.TVTextList[1]);
                    Assert.AreEqual(1, urlModel.TVItemIDList.Count);
                    Assert.AreEqual(tvItemModelRoot.TVItemID, urlModel.TVItemIDList[0]);
                    Assert.AreEqual(StartVarShow, urlModel.VariableShow);

                    TVItemModel tvItemModelLocationCurrent = (TVItemModel)partialViewResult.ViewBag.TVItemModelLocationCurrent;
                    Assert.IsNotNull(tvItemModelLocationCurrent);
                    Assert.AreEqual(1, tvItemModelLocationCurrent.TVItemID);

                    List <TabInfo> tabInfoList = (List <TabInfo>)partialViewResult.ViewBag.TabInfoList;
                    Assert.IsNotNull(tabInfoList);
                    Assert.AreEqual(2, tabInfoList.Count);
                }
            }
        }
Exemple #2
0
        public void HomeController__View_Country_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                // Arrange
                controllerAction = "_View";
                contactModel     = contactModelListGood[0];

                // Act
                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    // Act
                    TVItemModel tvItemModelCountry = randomService.RandomTVItem(TVTypeEnum.Country);

                    // Assert
                    Assert.AreEqual("", tvItemModelCountry.Error);

                    // Act
                    string            Q = "!View/" + tvItemModelCountry.TVText + "|||" + tvItemModelCountry.TVItemID;
                    PartialViewResult partialViewResult = controller._View(Q) as PartialViewResult;

                    // Assert
                    URLModel urlModel = (URLModel)partialViewResult.ViewBag.URLModel;
                    Assert.IsNotNull(partialViewResult);
                    Assert.AreEqual(2, urlModel.TVTextList.Count);
                    Assert.AreEqual("!View", urlModel.TVTextList[0]);
                    Assert.AreEqual(tvItemModelCountry.TVText, urlModel.TVTextList[1]);
                    Assert.AreEqual(1, urlModel.TVItemIDList.Count);
                    Assert.AreEqual(tvItemModelCountry.TVItemID, urlModel.TVItemIDList[0]);
                    Assert.AreEqual(StartVarShow, urlModel.VariableShow);

                    TVItemModel tvItemModel = (TVItemModel)partialViewResult.ViewBag.TVItemModelLocationCurrent;
                    Assert.IsNotNull(tvItemModel);
                    Assert.AreEqual(tvItemModelCountry.TVItemID, tvItemModel.TVItemID);
                    Assert.AreEqual(tvItemModelCountry.TVPath, tvItemModel.TVPath);
                    Assert.AreEqual(tvItemModelCountry.TVText, tvItemModel.TVText);
                }
            }
        }
        public void FileController_FileEditSaveJSON_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                controllerAction = "FileEditSaveJSON";
                contactModel     = contactModelListGood[0];

                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    TVItemModel tvItemModelMunicipality = randomService.RandomTVItem(TVTypeEnum.Municipality);
                    Assert.AreEqual("", tvItemModelMunicipality.Error);

                    TVItemModel tvItemModelTVFile = tvItemService.PostAddChildTVItemDB(tvItemModelMunicipality.TVItemID, randomService.RandomString("FileName ", 20), TVTypeEnum.File);
                    Assert.AreEqual("", tvItemModelTVFile.Error);

                    TVFileModel tvFileModel = randomService.RandomTVFileModel(tvItemModelTVFile, true);
                    Assert.AreEqual("", tvFileModel.Error);

                    System.Web.Mvc.FormCollection fc = new System.Web.Mvc.FormCollection();
                    fc.Add("TVFileTVItemID", tvFileModel.TVFileTVItemID.ToString());
                    if (tvFileModel.FilePurpose == FilePurposeEnum.Information)
                    {
                        fc.Add("FilePurpose", ((int)FilePurposeEnum.Generated).ToString());
                    }
                    else
                    {
                        fc.Add("FilePurpose", ((int)FilePurposeEnum.Information).ToString());
                    }
                    fc.Add("FileDescription", randomService.RandomString("Bonjour ", 100));
                    fc.Add("SaveAsFileName", randomService.RandomString("aaa ", 20));
                    fc.Add("FromWater", true.ToString());

                    JsonResult jsonResult = controller.FileEditSaveJSON(fc) as JsonResult;
                    Assert.IsNotNull(jsonResult);
                    string retStr = (string)jsonResult.Data;
                    Assert.AreEqual("", retStr);
                }
            }
        }
Exemple #4
0
        public PartialViewResult _tabContent(string Q)
        {
            SetArgs(Q);
            ViewBag.URLModel = urlModel;

            TVItemModel tvItemModelLocationCurrent = _TVItemService.GetTVItemModelWithTVItemIDDB(urlModel.TVItemIDList[0]);

            ViewBag.TVItemModelLocationCurrent = tvItemModelLocationCurrent;

            TVAuthEnum tvAuth = _TVItemService.GetTVAuthWithTVItemIDAndLoggedInUser(urlModel.TVItemIDList[0], null, null, null);

            ViewBag.TVAuth = tvAuth;

            List <TabInfo> tabInfoList = GetTab1ViewTVItemInfoDB(tvItemModelLocationCurrent, tvAuth);

            ViewBag.TabInfoList = tabInfoList;

            ViewBag.TVItemController = _TVItemController;

            return(PartialView());
        }
        public JsonResult GetMapInfoJSON(string Q)
        {
            SetArgs(Q);
            ViewBag.URLModel = urlModel;

            bool AllSites = (GetURLVarShowEnumStr(URLVarShowEnum.ShowAll) == "1" ? false : true);

            TVItemModel tvItemModelLocationCurrent = _TVItemService.GetTVItemModelWithTVItemIDDB(urlModel.TVItemIDList[0]);

            TVAuthEnum tvAuth = _TVItemService.GetTVAuthWithTVItemIDAndLoggedInUser(urlModel.TVItemIDList[0], null, null, null);

            List <TabInfo> Tab1ViewTVItemInfoList = GetTab1ViewTVItemInfoDB(tvItemModelLocationCurrent, tvAuth);

            TVTypeEnum ShowTVType = Tab1ViewTVItemInfoList[int.Parse(Tab1ViewTVItemInfoList[0].Active)].ShowTVType;

            // Year, Month, Day not used
            int NumberOfSamples = int.Parse(GetURLVarShowEnumStr(URLVarShowEnum.NumberOfSampleDecade) + GetURLVarShowEnumStr(URLVarShowEnum.NumberOfSampleUnit));
            List <TVLocation> tvLocationList = _MapInfoService.GetMapInfoDB(urlModel.TVItemIDList[0], ShowTVType, 2000, 1, 1, NumberOfSamples, AllSites);

            return(Json(tvLocationList, JsonRequestBehavior.AllowGet));
        }
Exemple #6
0
        public OpenDataStat GetOpenDataStatDB(int TVItemID)
        {
            string routineTxt = ((int)SampleTypeEnum.Routine).ToString() + ",";

            TVItemModel tvItemModel = _TVItemService.GetTVItemModelWithTVItemIDDB(TVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModel.Error))
            {
                return new OpenDataStat()
                       {
                           Error = tvItemModel.Error
                       }
            }
            ;

            using (CSSPDBEntities dd = new CSSPDBEntities())
            {
                OpenDataStat openDataStat = (from c in dd.TVItems
                                             let samples = (from d in dd.TVItems
                                                            from s in dd.MWQMSamples
                                                            where d.TVItemID == s.MWQMSiteTVItemID &&
                                                            d.TVPath.StartsWith(c.TVPath) &&
                                                            d.TVType == (int)TVTypeEnum.MWQMSite &&
                                                            s.SampleTypesText.Contains(routineTxt)
                                                            select new { s.UseForOpenData })
                                                           let totalSampleCount = (from s in samples select s).Count()
                                                                                  let useForOpenDataSampleCount = (from s in samples
                                                                                                                   where s.UseForOpenData == true
                                                                                                                   select s).Count()
                                                                                                                  where c.TVItemID == TVItemID
                                                                                                                  select new OpenDataStat
                {
                    Error = "",
                    TotalNumberOfSamples = totalSampleCount,
                    NumberOfUseForOpenDataSamples = useForOpenDataSampleCount,
                }).FirstOrDefault <OpenDataStat>();

                return(openDataStat);
            }
        }
Exemple #7
0
        public ActionResult _mwqmSite(string Q)
        {
            List <string> OptionListTxt = new List <string>()
            {
                "10", "15", "20", "25", "30", "35", "40"
            };

            SetArgs(Q);
            ViewBag.URLModel = urlModel;

            if (!OptionListTxt.Contains(urlModel.VariableShow.Substring(0, 2)))
            {
                urlModel.VariableShow = "30" + urlModel.VariableShow.Substring(2);
            }

            ViewBag.MWQMController = _MWQMController;

            MWQMSiteModel mwqmSiteModel = _MWQMSiteService.GetMWQMSiteModelWithMWQMSiteTVItemIDDB(urlModel.TVItemIDList[0]);

            ViewBag.MWQMSiteModelCurrent = mwqmSiteModel;

            TVItemModel tvItemModelCurrent = _TVItemService.GetTVItemModelWithTVItemIDDB(urlModel.TVItemIDList[0]);

            ViewBag.TVItemModelCurrent = tvItemModelCurrent;

            ViewBag.NumberOfSample = int.Parse(GetURLVarShowEnumStr(URLVarShowEnum.NumberOfSampleDecade) + GetURLVarShowEnumStr(URLVarShowEnum.NumberOfSampleUnit));

            ViewBag.IsMoreInfo = (GetURLVarShowEnumStr(URLVarShowEnum.ShowMoreInfo) == "0" ? false : true);

            List <MapInfoPointModel> mapInfoPointModelList = _MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelCurrent.TVItemID, TVTypeEnum.MWQMSite, MapInfoDrawTypeEnum.Point);
            MapInfoPointModel        mapInfoPointModel     = new MapInfoPointModel();

            if (mapInfoPointModelList.Count > 0)
            {
                mapInfoPointModel = mapInfoPointModelList[0];
            }

            ViewBag.MapInfoPointModel = mapInfoPointModel;
            return(PartialView());
        }
        public void BoxModelController__boxModelResults_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                // Arrange
                controllerAction = "_boxModelResults";

                // Act
                SetupTest(contactModelListGood[0], culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    // Act
                    TVItemModel tvItemModelMunicipality = randomService.RandomTVItem(TVTypeEnum.Municipality);

                    // Assert
                    Assert.AreEqual("", tvItemModelMunicipality.Error);

                    // Act
                    TVItemModel tvItemModelInfrastructure = tvItemService.PostAddChildTVItemDB(tvItemModelMunicipality.TVItemID, "Infras ", TVTypeEnum.Infrastructure);

                    // Assert
                    Assert.AreEqual("", tvItemModelInfrastructure.Error);

                    // Act
                    BoxModelModel boxModelModelRet = randomService.RandomBoxModelModel(tvItemModelInfrastructure, true);

                    // Act
                    PartialViewResult partialViewResult = controller._boxModelResults(boxModelModelRet.BoxModelID) as PartialViewResult;

                    // Assert
                    Assert.IsNotNull(partialViewResult);
                    List <BoxModelResultModel> boxModelResultModelList = (List <BoxModelResultModel>)partialViewResult.ViewBag.BoxModelResultModelList;
                    Assert.IsNotNull(boxModelResultModelList);
                    Assert.AreEqual(5, boxModelResultModelList.Count);
                    Assert.AreEqual(boxModelModelRet.BoxModelID, boxModelResultModelList[0].BoxModelID);
                    Assert.AreEqual(BoxModelResultTypeEnum.Dilution, boxModelResultModelList[0].BoxModelResultType);
                }
            }
        }
        public void FileController__fileImport_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                controllerAction = "_fileImport";
                contactModel     = contactModelListGood[0];

                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    TVItemModel tvItemModel = tvItemService.GetRootTVItemModelDB();
                    Assert.AreEqual("", tvItemModel.Error);

                    PartialViewResult partialViewResult = controller._fileImport(tvItemModel.TVItemID) as PartialViewResult;
                    Assert.IsNotNull(partialViewResult);

                    List <FilePurposeAndText> filePurposeAndTextList = (List <FilePurposeAndText>)partialViewResult.ViewBag.FilePurposeAndTextList;
                    Assert.IsNotNull(filePurposeAndTextList);
                }
            }
        }
        public MWQMPlanSubsectorModel AddMWQMPlanSubsectorModel()
        {
            MWQMPlanModel labContractModel = labContractServiceTest.AddMWQMPlanModel();

            if (!string.IsNullOrWhiteSpace(labContractModel.Error))
            {
                return new MWQMPlanSubsectorModel()
                       {
                           Error = labContractModel.Error
                       }
            }
            ;

            TVItemModel tvItemModelSubsector = randomService.RandomTVItem(TVTypeEnum.Subsector);

            if (!string.IsNullOrWhiteSpace(tvItemModelSubsector.Error))
            {
                return new MWQMPlanSubsectorModel()
                       {
                           Error = tvItemModelSubsector.Error
                       }
            }
            ;

            labContractSubsectorModelNew.MWQMPlanID        = labContractModel.MWQMPlanID;
            labContractSubsectorModelNew.SubsectorTVItemID = tvItemModelSubsector.TVItemID;
            FillMWQMPlanSubsectorModel(labContractSubsectorModelNew);

            MWQMPlanSubsectorModel labContractModelRet = labContractSubsectorService.PostAddMWQMPlanSubsectorDB(labContractSubsectorModelNew);

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

            CompareMWQMPlanSubsectorModels(labContractSubsectorModelNew, labContractModelRet);

            return(labContractModelRet);
        }
        public PartialViewResult _fileList(string Q)
        {
            ViewBag.URLModel               = null;
            ViewBag.TVFileModelList        = null;
            ViewBag.FilePurposeAndTextList = null;
            ViewBag.TVItemModel            = null;
            ViewBag.TVAuth = null;
            //ViewBag.Tab1ViewTVItemInfoList = null;
            ViewBag.NumberOfSample = null;
            ViewBag.IsShowMoreInfo = null;

            SetArgs(Q);
            ViewBag.URLModel = urlModel;

            List <TVFileModel> tvFileModelList = _TVFileService.GetTVFileModelListWithParentTVItemIDDB(urlModel.TVItemIDList[0]);

            ViewBag.TVFileModelList = tvFileModelList;

            List <FilePurposeAndText> filePurposeAndTextList = FillFilePurposeAndTextList();

            ViewBag.FilePurposeAndTextList = filePurposeAndTextList.OrderBy(c => c.FilePurposeText).ToList();

            TVItemModel tvItemModel = _TVItemService.GetTVItemModelWithTVItemIDDB(urlModel.TVItemIDList[0]);

            ViewBag.TVItemModel = tvItemModel;

            TVAuthEnum tvAuth = _TVItemService.GetTVAuthWithTVItemIDAndLoggedInUser(urlModel.TVItemIDList[0], null, null, null);

            ViewBag.TVAuth = tvAuth;

            //List<TabInfo> Tab1ViewTVItemInfoList = GetTab1ViewTVItemInfoDB(tvItemModel, tvAuth);
            //ViewBag.Tab1ViewTVItemInfoList = Tab1ViewTVItemInfoList;

            ViewBag.NumberOfSample = int.Parse(GetURLVarShowEnumStr(URLVarShowEnum.NumberOfSampleDecade) + GetURLVarShowEnumStr(URLVarShowEnum.NumberOfSampleUnit));

            ViewBag.IsShowMoreInfo = (GetURLVarShowEnumStr(URLVarShowEnum.ShowMoreInfo) == "0" ? false : true);

            return(PartialView());
        }
        public TVFileModel GetTVFileModelMWQMSitesAndPolSourceSites(int ProvinceTVItemID)
        {
            TVItemModel tvItemModelProv = _TVItemService.GetTVItemModelWithTVItemIDDB(ProvinceTVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelProv.Error))
            {
                return(new TVFileModel()
                {
                    Error = tvItemModelProv.Error
                });
            }

            if (tvItemModelProv.TVType != TVTypeEnum.Province)
            {
                return(new TVFileModel()
                {
                    Error = string.Format(ServiceRes.ShouldContainTVTypeOf_, TVTypeEnum.Province.ToString())
                });
            }

            string Init = GetInit(ProvinceTVItemID);

            string ServerPath = _TVFileService.GetServerFilePath(ProvinceTVItemID);

            string FileName = $"MWQMSitesAndPolSourceSites_{Init}.kml";

            TVFileModel tvFileModel = _TVFileService.GetTVFileModelWithServerFilePathAndServerFileNameDB(ServerPath, FileName);

            if (!string.IsNullOrWhiteSpace(tvFileModel.Error))
            {
                return(new TVFileModel()
                {
                    Error = tvFileModel.Error
                });
            }

            return(tvFileModel);
        }
Exemple #13
0
        public void TVItemController__MovingTVItemSelect_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                // Arrange
                controllerAction = "_MovingTVItemSelect";
                contactModel     = contactModelListGood[0];

                // Act
                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    // Act
                    TVItemModel tvItemModelRoot = controller._TVItemService.GetRootTVItemModelDB();

                    // Assert
                    Assert.AreEqual("", tvItemModelRoot.Error);

                    // Act
                    List <TVItemModel> tvItemModelCountryList = controller._TVItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelRoot.TVItemID, TVTypeEnum.Country);

                    // Assert
                    Assert.IsTrue(tvItemModelCountryList.Count > 0);

                    // Act
                    PartialViewResult partialViewResult = controller._MovingTVItemSelect(tvItemModelRoot.TVItemID, TVTypeEnum.Country) as PartialViewResult;

                    // Assert
                    Assert.IsNotNull(partialViewResult);

                    List <TVItemModel> tvItemModelList = (List <TVItemModel>)partialViewResult.ViewBag.TVItemModelList;
                    Assert.IsNotNull(tvItemModelList);
                    Assert.IsTrue(tvItemModelList.Count > 0);
                    Assert.IsTrue(tvItemModelList.Where(c => c.TVText == "Canada").Any());
                }
            }
        }
Exemple #14
0
        public PartialViewResult _mwqmRunAddOrModify(int MWQMRunTVItemID, int SubsectorTVItemID)
        {
            ViewBag.MWQMController         = _MWQMController;
            ViewBag.SubsectorTVItemID      = SubsectorTVItemID;
            ViewBag.SamplingContactTVText  = null;
            ViewBag.ValidatorContactTVText = null;
            ViewBag.TVItemModelContactLabValidatorOptionList = null;

            MWQMRunModel mwqmRunModel = _MWQMRunService.GetMWQMRunModelWithMWQMRunTVItemIDDB(MWQMRunTVItemID);

            ViewBag.MWQMRunModel = mwqmRunModel;

            TVItemModel tvItemModelMWQMrun = _TVItemService.GetTVItemModelWithTVItemIDDB(MWQMRunTVItemID);

            if (mwqmRunModel.LabSampleApprovalContactTVItemID > 0)
            {
                TVItemModel tvItemModel = _TVItemService.GetTVItemModelWithTVItemIDDB((int)mwqmRunModel.LabSampleApprovalContactTVItemID);
                ViewBag.ValidatorContactTVText = tvItemModel.TVText;
            }

            List <MWQMSampleModel> mwqmSampleModelList = _MWQMSampleService.GetMWQMSampleModelListWithMWQMRunTVItemIDDB(MWQMRunTVItemID);

            ViewBag.MWQMSampleModelList = mwqmSampleModelList;

            TVItemModel tvItemModelRoot = _TVItemService.GetRootTVItemModelDB();

            if (string.IsNullOrWhiteSpace(tvItemModelRoot.Error))
            {
                List <TVItemModel> tvItemModelContactLabValidatorOptionList = _TVItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelRoot.TVItemID, TVTypeEnum.Contact);
                ViewBag.TVItemModelContactLabValidatorOptionList = tvItemModelContactLabValidatorOptionList;
            }

            List <TVItemModel> tvItemModelMWQMSiteList = _TVItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelMWQMrun.ParentID, TVTypeEnum.MWQMSite);

            ViewBag.TVItemModelMWQMSiteList = tvItemModelMWQMSiteList;

            return(PartialView());
        }
Exemple #15
0
        public void TVItemController__TVItemMoreInfo_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                controllerAction = "_TVItemMoreInfo";
                contactModel     = contactModelListGood[0];

                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    TVItemModel tvItemModelRoot = tvItemService.GetRootTVItemModelDB();
                    Assert.AreEqual("", tvItemModelRoot.Error);
                    string Q = "";

                    PartialViewResult partialViewResult = controller._TVItemMoreInfo(Q, tvItemModelRoot.TVItemID, 0) as PartialViewResult;

                    List <TVItemStatModel> tvItemStatModelList = (List <TVItemStatModel>)partialViewResult.ViewBag.TVItemStatModelList;
                    Assert.IsNotNull(tvItemStatModelList);
                    Assert.AreEqual(tvItemModelRoot.TVItemID, tvItemStatModelList[0].TVItemID);

                    TVItemMoreInfoInfrastructureModel tvItemMoreInfoInfrastructureModel = (TVItemMoreInfoInfrastructureModel)partialViewResult.ViewBag.TVItemMoreInfoInfrastructureModel;
                    Assert.IsNull(tvItemMoreInfoInfrastructureModel);

                    TVItemMoreInfoMikeScenarioModel tvItemMoreInfoMikeScenarioModel = (TVItemMoreInfoMikeScenarioModel)partialViewResult.ViewBag.TVItemMoreInfoMikeScenarioModel;
                    Assert.IsNull(tvItemMoreInfoMikeScenarioModel);

                    TVItemMoreInfoPolSourceSiteModel tvItemMoreInfoPolSourceSiteModel = (TVItemMoreInfoPolSourceSiteModel)partialViewResult.ViewBag.TVItemMoreInfoPolSourceSiteModel;
                    Assert.IsNull(tvItemMoreInfoPolSourceSiteModel);

                    TVItemMoreInfoMWQMSiteModel tvItemMoreInfoMWQMSiteModel = (TVItemMoreInfoMWQMSiteModel)partialViewResult.ViewBag.TVItemMoreInfoMWQMSiteModel;
                    Assert.IsNull(tvItemMoreInfoMWQMSiteModel);

                    TVItemModel tvItemModel = (TVItemModel)partialViewResult.ViewBag.TVItemModel;
                    Assert.IsNull(tvItemMoreInfoMWQMSiteModel);
                }
            }
        }
Exemple #16
0
        public PartialViewResult _mwqmSiteAddOrModify(int SubsectorTVItemID, int MWQMSiteTVItemID)
        {
            ViewBag.SubsectorTVItemID = SubsectorTVItemID;
            ViewBag.MWQMSiteTVItemID  = MWQMSiteTVItemID;
            ViewBag.MapInfoPointModel = null;
            ViewBag.TVItemModel       = null;

            ViewBag.MWQMController = _MWQMController;

            MWQMSiteModel mwqmSiteModel = _MWQMSiteService.GetMWQMSiteModelWithMWQMSiteTVItemIDDB(MWQMSiteTVItemID);

            ViewBag.MWQMSiteModel = mwqmSiteModel;

            MapInfoPointModel mapInfoPointModel = _MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(MWQMSiteTVItemID, TVTypeEnum.MWQMSite, MapInfoDrawTypeEnum.Point).FirstOrDefault();

            ViewBag.MapInfoPointModel = mapInfoPointModel;

            TVItemModel tvItemModel = _TVItemService.GetTVItemModelWithTVItemIDDB(MWQMSiteTVItemID);

            ViewBag.TVItemModel = tvItemModel;

            return(PartialView());
        }
        public void ReportService_GetReportRoot_FileModelListUnderTVItemIDDB_Error_Allowable_ParentTagItem_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                SetupTest(contactModelListGood[0], culture);

                TVItemModel tvItemModelRoot = tvItemService.GetRootTVItemModelDB();
                Assert.AreEqual("", tvItemModelRoot.Error);

                List <TVItemModel> testTVItemModelList = new List <TVItemModel>()
                {
                    tvItemModelRoot
                };

                foreach (TVItemModel tvItemModel in testTVItemModelList)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("|||Loop Root_File " + culture.TwoLetterISOLanguageName);
                    sb.AppendLine("Root_File_ID");
                    sb.AppendLine("|||");

                    LanguageEnum Language      = (culture.TwoLetterISOLanguageName == "fr" ? LanguageEnum.fr : LanguageEnum.en);
                    string       TagText       = sb.ToString();
                    int          UnderTVItemID = tvItemModel.TVItemID;
                    string       ParentTagItem = "Municipality";
                    bool         CountOnly     = false;
                    int          Take          = 10;
                    string       TagItem       = "Root_File";

                    List <string> AllowableParentTagItemList = reportServiceRoot._ReportBaseService.GetAllowableParentTagItem(TagItem);

                    List <ReportRoot_FileModel> ReportRoot_FileModelList = reportServiceRoot_File.GetReportRoot_FileModelListUnderTVItemIDDB(Language, TagText, UnderTVItemID, ParentTagItem, CountOnly, Take);
                    Assert.IsTrue(ReportRoot_FileModelList.Count > 0);
                    Assert.AreEqual(string.Format(ServiceRes.AllowableParentTagItemFor_Are_, TagItem, String.Join(",", AllowableParentTagItemList)), ReportRoot_FileModelList[0].Root_File_Error);
                }
            }
        }
        public void BoxModelController_CopyBoxModelScenarioJSON_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                // Arrange
                controllerAction = "CopyBoxModelScenarioJSON";

                // Act
                SetupTest(contactModelListGood[0], culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    // Act
                    TVItemModel tvItemModelMunicipality = randomService.RandomTVItem(TVTypeEnum.Municipality);

                    // Assert
                    Assert.AreEqual("", tvItemModelMunicipality.Error);

                    // Act
                    TVItemModel tvItemModelInfrastructure = tvItemService.PostAddChildTVItemDB(tvItemModelMunicipality.TVItemID, "Infras ", TVTypeEnum.Infrastructure);

                    // Assert
                    Assert.AreEqual("", tvItemModelInfrastructure.Error);

                    // Act
                    BoxModelModel boxModelModelRet = randomService.RandomBoxModelModel(tvItemModelInfrastructure, true);

                    // Act
                    JsonResult jsonResult = controller.CopyBoxModelScenarioJSON(boxModelModelRet.BoxModelID) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    string retStr = (string)jsonResult.Data;
                    Assert.AreEqual("", retStr);
                }
            }
        }
        public RatingCurveModel AddRatingCurveModel()
        {
            TVItemModel tvItemModel = randomService.RandomTVItem(TVTypeEnum.HydrometricSite);

            Assert.AreEqual("", tvItemModel.Error);

            HydrometricSiteModel hydrometricSiteModel = hydrometricSiteService.GetHydrometricSiteModelWithHydrometricSiteTVItemIDDB(tvItemModel.TVItemID);

            Assert.AreEqual("", hydrometricSiteModel.Error);

            ratingCurveModelNew.HydrometricSiteID = hydrometricSiteModel.HydrometricSiteID;
            FillRatingCurveModel(ratingCurveModelNew);

            RatingCurveModel ratingCurveModelRet = ratingCurveService.PostAddRatingCurveDB(ratingCurveModelNew);

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

            CompareRatingCurveModels(ratingCurveModelNew, ratingCurveModelRet);

            return(ratingCurveModelRet);
        }
        public void MapController_GetParentLatLng_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                // Arrange
                controllerAction = "GetParentLatLng";
                contactModel     = contactModelListGood[0];

                // Act
                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    // Act
                    TVItemModel tvItemModelMunicipality = randomService.RandomTVItem(TVTypeEnum.Municipality);

                    // Assert
                    Assert.AreEqual("", tvItemModelMunicipality.Error);

                    // Act
                    List <MapInfoPointModel> mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelMunicipality.TVItemID, TVTypeEnum.Municipality, MapInfoDrawTypeEnum.Point);

                    // Assert
                    Assert.AreEqual(1, mapInfoPointModelList.Count);

                    // Act
                    JsonResult jsonResult = controller.GetParentLatLng(tvItemModelMunicipality.TVItemID) as JsonResult;

                    // Assert
                    Assert.IsNotNull(jsonResult);
                    CoordModel coordModel = (CoordModel)jsonResult.Data;
                    Assert.AreEqual(mapInfoPointModelList[0].Lat, coordModel.Lat);
                    Assert.AreEqual(mapInfoPointModelList[0].Lng, coordModel.Lng);
                }
            }
        }
        private bool GenerateHTMLSUBSECTOR_POLLUTION_SOURCE_SITES_COMPACT(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_COMPACT.ToString()));

            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 <MapInfo>      mapInfoActiveList      = new List <MapInfo>();
            List <MapInfoPoint> mapInfoPointActiveList = new List <MapInfoPoint>();

            //using (CSSPDBEntities db2 = new CSSPDBEntities())
            //{
            //    mapInfoActiveList = (from c in db2.MapInfos
            //                         from a in TVItemIDPolSourceSiteActiveList
            //                         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();

            //}

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

            sbTemp.AppendLine($@"|||TableCaption| { TaskRunnerServiceRes.PollutionSourcesSiteInventory }|||");

            sbTemp.AppendLine($@"<table class=""PolSourceSiteCompact"">");
            sbTemp.AppendLine($@"   <tr> ");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.Site }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.IN }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.Type }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.Path }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.Prob }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.Risk }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.Lat }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.Long }</th>");
            sbTemp.AppendLine($@"       <th class=""allBordersNoWrap"">{ TaskRunnerServiceRes.ObsDate }</th>");
            sbTemp.AppendLine($@"   </tr>");

            using (CSSPDBEntities db = new CSSPDBEntities())
            {
                var tvItemSS = (from t in db.TVItems
                                from tl in db.TVItemLanguages
                                where t.TVItemID == tl.TVItemID &&
                                tl.Language == (int)language &&
                                t.TVType == (int)TVTypeEnum.Subsector &&
                                t.IsActive == true &&
                                t.TVItemID == TVItemID
                                select new { t, tl }).FirstOrDefault();

                var PollutionSourceSiteList = (from t in db.TVItems
                                               from tl in db.TVItemLanguages
                                               from mi in db.MapInfos
                                               from mip in db.MapInfoPoints
                                               from pss in db.PolSourceSites
                                               let address = (from a in db.Addresses
                                                              let muni = (from cl in db.TVItemLanguages where cl.TVItemID == a.MunicipalityTVItemID && cl.Language == (int)LanguageEnum.en select cl.TVText).FirstOrDefault <string>()
                                                                         let add = a.StreetNumber + " " + a.StreetName + " --- " + muni
                                                                                   where a.AddressTVItemID == t.TVItemID
                                                                                   select new { add }).FirstOrDefault()
                                                             let pso = (from pso in db.PolSourceObservations
                                                                        where pso.PolSourceSiteID == pss.PolSourceSiteID
                                                                        orderby pso.ObservationDate_Local descending
                                                                        select new { pso }).FirstOrDefault()
                                                                       let psi = (from psi in db.PolSourceObservationIssues
                                                                                  where psi.PolSourceObservationID == pso.pso.PolSourceObservationID
                                                                                  orderby psi.Ordinal ascending
                                                                                  select new { psi }).ToList()
                                                                                 where t.TVItemID == tl.TVItemID &&
                                                                                 mi.TVItemID == t.TVItemID &&
                                                                                 mip.MapInfoID == mi.MapInfoID &&
                                                                                 t.TVItemID == pss.PolSourceSiteTVItemID &&
                                                                                 tl.Language == (int)LanguageEnum.en &&
                                                                                 t.TVPath.StartsWith(tvItemSS.t.TVPath + "p") &&
                                                                                 t.TVType == (int)TVTypeEnum.PolSourceSite &&
                                                                                 t.IsActive == true &&
                                                                                 mi.MapInfoDrawType == (int)MapInfoDrawTypeEnum.Point &&
                                                                                 mi.TVType == (int)TVTypeEnum.PolSourceSite
                                                                                 orderby tl.TVText
                                                                                 select new { t, tl, mip, address.add, pss, pso, psi }).ToList();

                foreach (var polSourceSite in PollutionSourceSiteList.Where(c => c.t.ParentID == tvItemSS.t.TVItemID))
                {
                    string SS   = tvItemSS.tl.TVText.Replace(",", "_");
                    string Desc = "";
                    if (SS.Contains(" "))
                    {
                        Desc = SS.Substring(SS.IndexOf(" "));
                        Desc = Desc.Trim();
                        Desc = Desc.Replace("(", "").Replace(")", "");
                        SS   = SS.Substring(0, SS.IndexOf(" "));
                    }
                    string   PSS     = "P" + (polSourceSite.pss != null && polSourceSite.pss.Site != null ? polSourceSite.pss.Site.ToString().Replace(",", "_") : "");
                    string   OBSDate = (polSourceSite.pso != null && polSourceSite.pso.pso.ObservationDate_Local != null ? polSourceSite.pso.pso.ObservationDate_Local.ToString("yyyy-MM-dd") : "");
                    string   PSTVT   = polSourceSite.tl.TVText;
                    string[] PSArr   = PSTVT.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
                    string   PSType  = "";
                    string   PSPath  = "";
                    string   PSProb  = "";
                    string   PSRisk  = "";
                    if (PSArr.Length > 0)
                    {
                        PSType = PSArr[0];
                        if (PSType.Contains(" - "))
                        {
                            PSType = PSType.Substring(PSType.IndexOf(" - ") + 3);
                        }
                    }
                    if (PSArr.Length > 1)
                    {
                        PSPath = PSArr[1];
                    }
                    if (PSArr.Length > 2)
                    {
                        PSRisk = PSArr[2];
                    }
                    string Lat = (polSourceSite.mip != null ? polSourceSite.mip.Lat.ToString("F5") : "");
                    string Lng = (polSourceSite.mip != null ? polSourceSite.mip.Lng.ToString("F5") : "");
                    string URL = @"http://131.235.1.167/csspwebtools/en-CA/#!View/a|||" + polSourceSite.t.TVItemID.ToString() + @"|||30010100004000000000000000000000";

                    string TVText = "";

                    int IN = 0;
                    foreach (var psi in polSourceSite.psi)
                    {
                        if (psi != null && psi.psi != null)
                        {
                            IN += 1;
                            List <string> ObservationInfoList = (string.IsNullOrWhiteSpace(psi.psi.ObservationInfo) ? new List <string>() : psi.psi.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", "     Source");
                                }
                                break;

                                case "250":
                                {
                                    Temp = Temp.Replace("Pathway", "     Pathway");
                                }
                                break;

                                case "900":
                                {
                                    Temp = Temp.Replace("Status", "     Status");
                                    if (!string.IsNullOrWhiteSpace(Temp))
                                    {
                                        PSProb = Temp.Replace("Status:", "");
                                        PSProb = PSProb.Trim();
                                        if (PSProb.Contains(" "))
                                        {
                                            PSProb = PSProb.Substring(0, PSProb.IndexOf(" "));
                                        }
                                    }
                                }
                                break;

                                case "910":
                                {
                                    Temp = Temp.Replace("Risk", "     Risk");
                                }
                                break;

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

                        string TVT = (polSourceSite.pso != null && polSourceSite.pso.pso.Observation_ToBeDeleted != null ? polSourceSite.pso.pso.Observation_ToBeDeleted : "");

                        string TempISS = (!string.IsNullOrWhiteSpace(TVT) ? TVT.Replace(",", "_") + " ----- " : "") + TVText;

                        string ISS = TempISS.Replace("\r", "   ").Replace("\n", "").Replace("empty", "").Replace("Empty", "").Replace("\r", "   ").Replace("\n", "");

                        if (SS.Length == 0)
                        {
                            SS = " ";
                        }
                        if (Desc.Length == 0)
                        {
                            Desc = " ";
                        }
                        if (PSS.Length == 0)
                        {
                            PSS = " ";
                        }
                        if (PSType.Length == 0)
                        {
                            PSType = " ";
                        }
                        if (PSPath.Length == 0)
                        {
                            PSPath = " ";
                        }
                        if (PSProb.Length == 0)
                        {
                            PSProb = " ";
                        }
                        if (Lat.Length == 0)
                        {
                            Lat = " ";
                        }
                        if (Lng.Length == 0)
                        {
                            Lng = " ";
                        }
                        if (OBSDate.Length == 0)
                        {
                            OBSDate = " ";
                        }
                        if (URL.Length == 0)
                        {
                            URL = " ";
                        }

                        sbTemp.AppendLine($@"   <tr>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ PSS }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ IN }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ PSType }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ PSPath }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ PSProb }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ PSRisk }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ Lat }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ Lng }</td>");
                        sbTemp.AppendLine($@"       <td class=""allBordersNoWrap"">{ OBSDate }</td>");
                        sbTemp.AppendLine($@"   </tr>");
                    }
                }
            }

            sbTemp.AppendLine($@"</table>");

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

            return(true);
        }
        private void GenerateWorksheetAContent(WorksheetPart worksheetPart, int SheetOrdinal)
        {
            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?>()
            {
                30D
            };

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

            SheetData sheetData = new SheetData();

            BaseEnumService   baseEnumService   = new BaseEnumService(_TaskRunnerBaseService._BWObj.appTaskModel.Language);
            TVItemService     tvItemService     = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TVItemStatService tvItemStatService = new TVItemStatService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

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

            List <TVItemModel> tvItemModelAreaList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelProvince.TVItemID, TVTypeEnum.Area);


            foreach (TVItemModel tvItemModelArea in tvItemModelAreaList)
            {
                //tvItemStatService.SetTVItemStatForTVItemIDAndParentsTVItemID(tvItemModelArea.TVItemID);

                XlsxBase.CurrentRowHeight                = 24D;
                XlsxBase.CurrentFontSize                 = 18;
                XlsxBase.CurrentBorderStyleValue         = BorderStyleValues.Thick;
                XlsxBase.CurrentBottomBorder             = true;
                XlsxBase.CurrentBorderColor              = System.Drawing.Color.Green;
                XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Center;

                row = XlsxBase.AddRow();
                string URL = _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelArea);
                XlsxBase.CurrentFontColor = System.Drawing.Color.Blue;
                cell = XlsxBase.AddCellHyperlink(hyperlinks, row, tvItemModelArea.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() + ":B" + XlsxBase.CurrentRow.ToString()
                };

                mergeCells.Append(mergeCell);

                XlsxBase.CurrentRowHeight = 16D;
                XlsxBase.CurrentFontSize  = 12;
                XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Center;

                List <TVItemStatModel> tvItemStatModelList = tvItemStatService.GetTVItemStatModelListWithTVItemIDDB(tvItemModelArea.TVItemID);

                int count = 0;
                foreach (TVItemStatModel tvItemStatModel in tvItemStatModelList)
                {
                    count += 1;
                    row    = XlsxBase.AddRow();

                    if (count % 5 == 0)
                    {
                        XlsxBase.CurrentBorderStyleValue = BorderStyleValues.Thin;
                        XlsxBase.CurrentBottomBorder     = true;
                    }
                    else
                    {
                        XlsxBase.CurrentBorderStyleValue = null;
                        XlsxBase.CurrentBottomBorder     = false;
                    }
                    XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Right;
                    cell = XlsxBase.AddCellString(row, baseEnumService.GetEnumText_TVTypeEnum(tvItemStatModel.TVType));

                    XlsxBase.CurrentHorizontalAlignmentValue = HorizontalAlignmentValues.Center;
                    cell = XlsxBase.AddCellNumber(row, tvItemStatModel.ChildCount.ToString());

                    sheetData.Append(row);
                }

                XlsxBase.CurrentBorderStyleValue = null;
                XlsxBase.CurrentBottomBorder     = false;

                for (int i = 0; i < 2; i++)
                {
                    row  = XlsxBase.AddRow();
                    cell = XlsxBase.AddCellString(row, null);
                    sheetData.Append(row);
                }
            }

            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;
        }
Exemple #23
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);
        }
Exemple #24
0
        private void GenerateCountryDocument(Document document)
        {
            Body      body      = new Body();
            Paragraph paragraph = new Paragraph();
            Run       run       = new Run();
            Table     table     = new Table();
            TableRow  tableRow  = new TableRow();
            TableCell tableCell = new TableCell();
            string    URL       = "";

            BaseEnumService   baseEnumService   = new BaseEnumService(_TaskRunnerBaseService._BWObj.appTaskModel.Language);
            TVItemService     tvItemService     = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            TVItemStatService tvItemStatService = new TVItemStatService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);

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

            if (!string.IsNullOrWhiteSpace(tvItemModelCounty.Error))
            {
                paragraph = DocxBase.AddParagraph(body);
                DocxBase.AddRunWithCurrentParagraphStyle(paragraph, tvItemModelCounty.Error);
            }

            DocxBase.CurrentParagraphStyle     = ParagraphStyleEnum.Heading1;
            DocxBase.CurrentJustificationValue = JustificationValues.Center;
            paragraph = DocxBase.AddParagraph(body);

            URL = _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelCounty);
            run = DocxBase.AddRunHyperlink(paragraph, URL, tvItemModelCounty.TVText);

            List <TVItemModel> tvItemModelProvinceList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelCounty.TVItemID, TVTypeEnum.Province);

            foreach (TVItemModel tvItemModelProvince in tvItemModelProvinceList)
            {
                //tvItemStatService.SetTVItemStatForTVItemIDAndParentsTVItemID(tvItemModelProvince.TVItemID);

                DocxBase.CurrentParagraphStyle = ParagraphStyleEnum.Heading2;
                paragraph = DocxBase.AddParagraph(body);

                URL = _TaskRunnerBaseService.GetUrlFromTVItem(tvItemModelProvince);
                run = DocxBase.AddRunHyperlink(paragraph, URL, tvItemModelProvince.TVText);

                DocxBase.CurrentTableStyle = TableStyleEnum.ListTable7Colorful_Accent5;
                table    = DocxBase.AddTableStyle(body);
                tableRow = DocxBase.AddTableRow(table);

                // Doing Items
                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "Items");

                // Doing Count
                tableCell = DocxBase.AddTableCell(tableRow);
                paragraph = DocxBase.AddTableCellParagraph(tableCell);
                run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "Count");

                List <TVItemStatModel> tvItemStatModelList = tvItemStatService.GetTVItemStatModelListWithTVItemIDDB(tvItemModelProvince.TVItemID);

                int count = 0;
                foreach (TVItemStatModel tvItemStatModel in tvItemStatModelList)
                {
                    count   += 1;
                    tableRow = DocxBase.AddTableRow(table);

                    // Doing Item
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);
                    run       = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, baseEnumService.GetEnumText_TVTypeEnum(tvItemStatModel.TVType));

                    // Doing number
                    tableCell = DocxBase.AddTableCell(tableRow);
                    paragraph = DocxBase.AddTableCellParagraph(tableCell);

                    run = DocxBase.AddRunWithCurrentParagraphStyle(paragraph, tvItemStatModel.ChildCount.ToString());
                }
            }

            DocxBase.CurrentParagraphStyle     = ParagraphStyleEnum.Normal;
            DocxBase.CurrentJustificationValue = JustificationValues.Left;
            paragraph = DocxBase.AddParagraph(body);

            paragraph = DocxBase.AddParagraph(body);

            DocxBase.AddRunWithCurrentParagraphStyle(paragraph, "Etc ... ");

            DocxBase.AddSectionProp(body);

            document.Append(body);
        }
        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);
        }
        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);
        }
        private bool GenerateHTMLSubsectorMWQMSites(FileInfo fi, StringBuilder sbHTML, string parameters, ReportTypeModel reportTypeModel)
        {
            string NotUsed  = "";
            int    TVItemID = 0;

            Random random        = new Random();
            string FileNameExtra = "";

            for (int i = 0; i < 10; i++)
            {
                FileNameExtra = FileNameExtra + (char)random.Next(97, 122);
            }

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

            if (!GetTopHTML(sbHTML))
            {
                return(false);
            }

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

            if (!int.TryParse(GetParameters("TVItemID", ParamValueList), out TVItemID))
            {
                NotUsed = string.Format(TaskRunnerServiceRes.CouldNotFind__, TaskRunnerServiceRes.Parameter, TaskRunnerServiceRes.TVItemID);
                _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("CouldNotFind__", TaskRunnerServiceRes.Parameter, TaskRunnerServiceRes.TVItemID);
                return(false);
            }

            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>     tvItemModelListMWQMSites = _TVItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelSubsector.TVItemID, TVTypeEnum.MWQMSite).Where(c => c.IsActive == true).ToList();
            List <MWQMSiteModel>   mwqmSiteModelList        = _MWQMSiteService.GetMWQMSiteModelListWithSubsectorTVItemIDDB(TVItemID);
            List <MWQMRunModel>    mwqmRunModelList         = _MWQMRunService.GetMWQMRunModelListWithSubsectorTVItemIDDB(TVItemID);
            List <MWQMSampleModel> mwqmSampleModelList      = _MWQMSampleService.GetMWQMSampleModelListWithSubsectorTVItemIDDB(TVItemID);

            sbHTML.AppendLine($@" <h3>{ TaskRunnerServiceRes.MWQMSiteSampleDataAvailability }</h3>");
            sbHTML.AppendLine($@" <table cellpadding=""5"">");
            sbHTML.AppendLine($@" <tr>");
            sbHTML.AppendLine($@" <th>{ TaskRunnerServiceRes.Site }</th>");
            bool FirstHit = false;

            for (int year = DateTime.Now.Year; year > 1975; year--)
            {
                if (year % 5 == 0)
                {
                    FirstHit = true;
                    int colSpan = 5;
                    if (year == 1980)
                    {
                        colSpan = 4;
                    }
                    sbHTML.AppendLine($@" <th class=""textAlignLeftAndLeftBorder"" colspan=""{ colSpan }"">{ year }</th>");
                }
                if (!FirstHit)
                {
                    sbHTML.AppendLine($@" <th>&nbsp;</th>");
                }
            }
            sbHTML.AppendLine($@" </tr>");
            int countSite = 0;

            foreach (MWQMSiteModel mwqmSiteModel in mwqmSiteModelList)
            {
                TVItemModel tvItemModel = tvItemModelListMWQMSites.Where(c => c.TVItemID == mwqmSiteModel.MWQMSiteTVItemID).FirstOrDefault();
                if (tvItemModel != null)
                {
                    if (tvItemModel.IsActive)
                    {
                        countSite += 1;
                        string bottomClass = "";
                        if (countSite % 5 == 0)
                        {
                            bottomClass = "bottomBorder";
                        }
                        sbHTML.AppendLine($@" <tr>");
                        sbHTML.AppendLine($@" <td class=""{ bottomClass }"">{ mwqmSiteModel.MWQMSiteTVText }</td>");
                        for (int year = DateTime.Now.Year; year > 1979; year--)
                        {
                            string leftClass  = year % 5 == 0 ? "leftBorder" : "";
                            bool   hasSamples = mwqmSampleModelList.Where(c => c.MWQMSiteTVItemID == mwqmSiteModel.MWQMSiteTVItemID && c.SampleDateTime_Local.Year == year && c.SampleTypesText.Contains(((int)SampleTypeEnum.Routine).ToString())).Any();
                            if (hasSamples)
                            {
                                if (leftClass != "")
                                {
                                    if (bottomClass != "")
                                    {
                                        sbHTML.AppendLine($@" <td class=""bggreenfLeftAndBottomBorder"">&nbsp;</td>");
                                    }
                                    else
                                    {
                                        sbHTML.AppendLine($@" <td class=""bggreenfLeftBorder"">&nbsp;</td>");
                                    }
                                }
                                else
                                {
                                    if (bottomClass != "")
                                    {
                                        sbHTML.AppendLine($@" <td class=""bggreenfBottomBorder"">&nbsp;</td>");
                                    }
                                    else
                                    {
                                        sbHTML.AppendLine($@" <td class=""bggreenf"">&nbsp;</td>");
                                    }
                                }
                            }
                            else
                            {
                                if (leftClass != "")
                                {
                                    if (bottomClass != "")
                                    {
                                        sbHTML.AppendLine($@" <td class=""leftAndBottomBorder"">&nbsp;</td>");
                                    }
                                    else
                                    {
                                        sbHTML.AppendLine($@" <td class=""leftBorder"">&nbsp;</td>");
                                    }
                                }
                                else
                                {
                                    if (bottomClass != "")
                                    {
                                        sbHTML.AppendLine($@" <td class=""bottomBorder"">&nbsp;</td>");
                                    }
                                    else
                                    {
                                        sbHTML.AppendLine($@" <td>&nbsp;</td>");
                                    }
                                }
                            }
                        }
                        sbHTML.AppendLine($@" </tr>");
                    }
                }
            }
            sbHTML.AppendLine($@" </table>");

            sbHTML.AppendLine(@"<span>|||PageBreak|||</span>");

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

            // ---------------------------------------------------------------------------------------------
            // MWQM Sites Summary
            // ---------------------------------------------------------------------------------------------

            //------------------------------------------------------------------------------
            // doing number of sites by year
            //------------------------------------------------------------------------------

            List <int> YearList     = new List <int>();
            List <int> CountPerYear = new List <int>();

            for (int i = 1980; i < DateTime.Now.Year + 1; i++)
            {
                YearList.Add(i);
                int count = (from s in mwqmSiteModelList
                             from samp in mwqmSampleModelList
                             where s.MWQMSiteTVItemID == samp.MWQMSiteTVItemID &&
                             samp.SampleDateTime_Local.Year == i
                             select s.MWQMSiteTVItemID).Distinct().Count();

                CountPerYear.Add(count);
            }

            Microsoft.Office.Interop.Excel._Application xlApp     = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook     workbook  = xlApp.Workbooks.Add();
            Microsoft.Office.Interop.Excel.Worksheet    worksheet = workbook.Worksheets.get_Item(1);

            Microsoft.Office.Interop.Excel.ChartObjects xlCharts  = (Microsoft.Office.Interop.Excel.ChartObjects)worksheet.ChartObjects();
            Microsoft.Office.Interop.Excel.ChartObject  chart     = xlCharts.Add(100, 100, 600, 200);
            Microsoft.Office.Interop.Excel.Chart        chartPage = chart.Chart;

            chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered;

            Microsoft.Office.Interop.Excel.SeriesCollection seriesCollection = chartPage.SeriesCollection();
            Microsoft.Office.Interop.Excel.Series           series           = seriesCollection.NewSeries();

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

            series.XValues = YearList.ToArray();
            series.Values  = CountPerYear.ToArray();

            chartPage.ApplyLayout(9, Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered);
            chartPage.ChartTitle.Select();
            xlApp.Selection.Delete();
            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue).AxisTitle.Select();
            xlApp.Selection.Delete();
            chartPage.Legend.Select();
            xlApp.Selection.Delete();
            //chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).TickLabelSpacing = 5;
            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).MajorTickMark = Microsoft.Office.Interop.Excel.Constants.xlOutside;
            chartPage.Parent.RoundedCorners = true;

            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary).AxisTitle.Text = TaskRunnerServiceRes.NumberOfMWQMSitesByYear;

            // need to save the file with a unique name under the TVItemID
            FileInfo fiImageNumberOfSitesByYearStat = new FileInfo(fi.DirectoryName + @"\NumberOfSitesByYearStat" + FileNameExtra + ".png");

            DirectoryInfo di = new DirectoryInfo(fi.DirectoryName);

            if (!di.Exists)
            {
                try
                {
                    di.Create();
                }
                catch (Exception ex)
                {
                    NotUsed = string.Format(TaskRunnerServiceRes.CouldNotCreateDirectory__, di.FullName, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
                    _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("CouldNotCreateDirectory__", di.FullName, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
                    return(false);
                }
            }

            chartPage.Export(fiImageNumberOfSitesByYearStat.FullName, "PNG", false);


            //------------------------------------------------------------------------------
            // doing number of runs by year
            //------------------------------------------------------------------------------
            YearList     = new List <int>();
            CountPerYear = new List <int>();

            for (int i = 1980; i < DateTime.Now.Year + 1; i++)
            {
                YearList.Add(i);
                int count = (from r in mwqmRunModelList
                             from samp in mwqmSampleModelList
                             where r.MWQMRunTVItemID == samp.MWQMRunTVItemID &&
                             samp.SampleDateTime_Local.Year == i
                             select r.MWQMRunTVItemID).Distinct().Count();

                CountPerYear.Add(count);
            }

            chart     = xlCharts.Add(100, 100, 600, 200);
            chartPage = chart.Chart;

            chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered;

            seriesCollection = chartPage.SeriesCollection();
            series           = seriesCollection.NewSeries();

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

            series.XValues = YearList.ToArray();
            series.Values  = CountPerYear.ToArray();

            chartPage.ApplyLayout(9, Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered);
            chartPage.ChartTitle.Select();
            xlApp.Selection.Delete();
            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue).AxisTitle.Select();
            xlApp.Selection.Delete();
            chartPage.Legend.Select();
            xlApp.Selection.Delete();
            //chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).TickLabelSpacing = 5;
            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).MajorTickMark = Microsoft.Office.Interop.Excel.Constants.xlOutside;
            chartPage.Parent.RoundedCorners = true;

            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary).AxisTitle.Text = TaskRunnerServiceRes.NumberOfMWQMRunsByYear;

            // need to save the file with a unique name under the TVItemID
            FileInfo fiImageNumberOfRunsByYearStat = new FileInfo(fi.DirectoryName + @"\NumberOfRunsByYearStat" + FileNameExtra + ".png");

            di = new DirectoryInfo(fi.DirectoryName);

            if (!di.Exists)
            {
                try
                {
                    di.Create();
                }
                catch (Exception ex)
                {
                    NotUsed = string.Format(TaskRunnerServiceRes.CouldNotCreateDirectory__, di.FullName, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
                    _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("CouldNotCreateDirectory__", di.FullName, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
                    return(false);
                }
            }

            chartPage.Export(fiImageNumberOfRunsByYearStat.FullName, "PNG", false);

            //------------------------------------------------------------------------------
            // doing number of samples by year
            //------------------------------------------------------------------------------
            YearList     = new List <int>();
            CountPerYear = new List <int>();

            for (int i = 1980; i < DateTime.Now.Year + 1; i++)
            {
                YearList.Add(i);
                int count = (from samp in mwqmSampleModelList
                             where samp.SampleDateTime_Local.Year == i
                             select samp.MWQMSampleID).Distinct().Count();

                CountPerYear.Add(count);
            }

            chart     = xlCharts.Add(100, 100, 600, 200);
            chartPage = chart.Chart;

            chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered;

            seriesCollection = chartPage.SeriesCollection();
            series           = seriesCollection.NewSeries();

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

            series.XValues = YearList.ToArray();
            series.Values  = CountPerYear.ToArray();

            chartPage.ApplyLayout(9, Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered);
            chartPage.ChartTitle.Select();
            xlApp.Selection.Delete();
            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlValue).AxisTitle.Select();
            xlApp.Selection.Delete();
            chartPage.Legend.Select();
            xlApp.Selection.Delete();
            //chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).TickLabelSpacing = 5;
            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory).MajorTickMark = Microsoft.Office.Interop.Excel.Constants.xlOutside;
            chartPage.Parent.RoundedCorners = true;

            chartPage.Axes(Microsoft.Office.Interop.Excel.XlAxisType.xlCategory, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary).AxisTitle.Text = TaskRunnerServiceRes.NumberOfSamplesByYear;

            // need to save the file with a unique name under the TVItemID
            FileInfo fiImageNumberOfSamplesByYearStat = new FileInfo(fi.DirectoryName + @"\NumberOfSamplesByYearStat" + FileNameExtra + ".png");

            di = new DirectoryInfo(fi.DirectoryName);

            if (!di.Exists)
            {
                try
                {
                    di.Create();
                }
                catch (Exception ex)
                {
                    NotUsed = string.Format(TaskRunnerServiceRes.CouldNotCreateDirectory__, di.FullName, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
                    _TaskRunnerBaseService._BWObj.TextLanguageList = _TaskRunnerBaseService.GetTextLanguageFormat2List("CouldNotCreateDirectory__", di.FullName, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
                    return(false);
                }
            }

            chartPage.Export(fiImageNumberOfSamplesByYearStat.FullName, "PNG", false);


            if (workbook != null)
            {
                workbook.Close(false);
            }
            if (xlApp != null)
            {
                xlApp.Quit();
            }

            sbHTML.AppendLine($@" <h3>{ TaskRunnerServiceRes.MWQMSitesSummary }</h3>");
            sbHTML.AppendLine($@" <br /");
            sbHTML.AppendLine($@" <h4>{ TaskRunnerServiceRes.NumberOfMWQMSitesByYear }</h4>");
            sbHTML.AppendLine($@"<div class=""textAlignCenter"">|||Image|FileName,{ fiImageNumberOfSitesByYearStat.FullName }|width,400|height,150|||</div>");
            sbHTML.AppendLine($@" <h4>{ TaskRunnerServiceRes.NumberOfMWQMRunsByYear }</h4>");
            sbHTML.AppendLine($@"<div class=""textAlignCenter"">|||Image|FileName,{ fiImageNumberOfRunsByYearStat.FullName }|width,400|height,150|||</div>");
            sbHTML.AppendLine($@" <h4>{ TaskRunnerServiceRes.NumberOfSamplesByYear }</h4>");
            sbHTML.AppendLine($@"<div class=""textAlignCenter"">|||Image|FileName,{ fiImageNumberOfSamplesByYearStat.FullName }|width,400|height,150|||</div>");

            sbHTML.AppendLine(@"<span>|||PageBreak|||</span>");

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

            sbHTML.AppendLine($@" <h3>{ TaskRunnerServiceRes.MWQMSitesInformation }</h3>");
            sbHTML.AppendLine($@" <table cellpadding=""5"" class=""textAlignCenter"">");
            sbHTML.AppendLine($@" <tr>");
            sbHTML.AppendLine($@" <th colspan=""2"">{ TaskRunnerServiceRes.Site }</th>");
            sbHTML.AppendLine($@" <th>{ TaskRunnerServiceRes.Coordinates }</th>");
            sbHTML.AppendLine($@" <th>{ TaskRunnerServiceRes.Description }</th>");
            sbHTML.AppendLine($@" <th>{ TaskRunnerServiceRes.Photos }</th>");
            sbHTML.AppendLine($@" </tr>");
            foreach (MWQMSiteModel mwqmSiteModel in mwqmSiteModelList)
            {
                TVItemModel tvItemModel = tvItemModelListMWQMSites.Where(c => c.TVItemID == mwqmSiteModel.MWQMSiteTVItemID).FirstOrDefault();
                if (tvItemModel != null)
                {
                    if (tvItemModel.IsActive)
                    {
                        string classificationLetter = "";
                        string classificationColor  = "";

                        classificationLetter = GetLastClassificationInitial(mwqmSiteModel.MWQMSiteLatestClassification);
                        classificationColor  = GetLastClassificationColor(mwqmSiteModel.MWQMSiteLatestClassification);

                        sbHTML.AppendLine($@" <tr>");
                        sbHTML.AppendLine($@" <td>{ mwqmSiteModel.MWQMSiteTVText }</td>");
                        sbHTML.AppendLine($@" <td class=""{ classificationColor }"">{ classificationLetter }</td>");

                        List <MapInfoPointModel> mapInfoPointModelList = _MapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(mwqmSiteModel.MWQMSiteTVItemID, TVTypeEnum.MWQMSite, MapInfoDrawTypeEnum.Point);
                        if (mapInfoPointModelList.Count > 0)
                        {
                            sbHTML.AppendLine($@" <td>{ mapInfoPointModelList[0].Lat.ToString("F5") } { mapInfoPointModelList[0].Lng.ToString("F5") }</td>");
                        }
                        else
                        {
                            sbHTML.AppendLine($@" <td>&nbsp;</td>");
                        }
                        sbHTML.AppendLine($@" <td class=""textAlignLeft"">{ mwqmSiteModel.MWQMSiteDescription }</td>");
                        sbHTML.AppendLine($@" <td>Photo</td>");
                        sbHTML.AppendLine($@" </tr>");
                    }
                }
            }
            sbHTML.AppendLine($@" </table>");


            sbHTML.AppendLine(@"<span>|||PageBreak|||</span>");

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


            List <MWQMSiteModel> mwqmSiteModelList2 = (from s in mwqmSiteModelList
                                                       from t in tvItemModelListMWQMSites
                                                       where s.MWQMSiteTVItemID == t.TVItemID &&
                                                       t.IsActive == true
                                                       orderby s.MWQMSiteTVText
                                                       select s).ToList();

            int  skip     = 0;
            int  take     = 15;
            bool HasData  = true;
            int  countRun = 0;

            while (HasData)
            {
                countRun += 1;

                if (countRun > 2)
                {
                    break;
                }

                List <MWQMRunModel> mwqmRunModelList2 = mwqmRunModelList.Where(c => c.RunSampleType == SampleTypeEnum.Routine).OrderByDescending(c => c.DateTime_Local).Skip(skip).Take(take).ToList();
                if (mwqmRunModelList2.Count > 0)
                {
                    sbHTML.AppendLine($@" <h4>{ TaskRunnerServiceRes.ActiveMWQMSites }&nbsp;&nbsp;{ TaskRunnerServiceRes.FCDensities }&nbsp;&nbsp;&nbsp;({ TaskRunnerServiceRes.Routine })&nbsp;&nbsp;&nbsp;{ mwqmRunModelList2[0].DateTime_Local.ToString("yyyy MMMM dd") } { TaskRunnerServiceRes.To } { mwqmRunModelList2[mwqmRunModelList2.Count -1].DateTime_Local.ToString("yyyy MMMM dd") }</h4>");
                    sbHTML.AppendLine($@" <table class=""FCSalTempDataTableClass"">");
                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <th class=""rightBottomBorder"">{ TaskRunnerServiceRes.Site }</th>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        sbHTML.AppendLine($@" <th class=""bottomBorder"">{ mwqmRunModel.DateTime_Local.ToString("yyyy") }<br />{ mwqmRunModel.DateTime_Local.ToString("MMM") }<br />{ mwqmRunModel.DateTime_Local.ToString("dd") }</th>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    foreach (MWQMSiteModel mwqmSiteModel in mwqmSiteModelList2)
                    {
                        sbHTML.AppendLine($@" <tr>");
                        sbHTML.AppendLine($@" <td class=""rightBorder"">{ mwqmSiteModel.MWQMSiteTVText }</td>");
                        foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                        {
                            float?value = (from s in mwqmSampleModelList
                                           where s.MWQMRunTVItemID == mwqmRunModel.MWQMRunTVItemID &&
                                           s.MWQMSiteTVItemID == mwqmSiteModel.MWQMSiteTVItemID
                                           select s.FecCol_MPN_100ml).FirstOrDefault();

                            string valueStr = value != null ? (value == 1 ? "< 2" : ((float)value).ToString("F0")) : "--";
                            sbHTML.AppendLine($@" <td>{ valueStr }</td>");
                        }
                        sbHTML.AppendLine($@" </tr>");
                    }
                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <td class=""topRightBorder"">{ TaskRunnerServiceRes.StartTide }<br />{ TaskRunnerServiceRes.EndTide }</td>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        string StartTide = GetTideInitial(mwqmRunModel.Tide_Start);
                        string EndTide   = GetTideInitial(mwqmRunModel.Tide_End);
                        sbHTML.AppendLine($@" <td class=""topRightBorder"">{ StartTide }<br />{ EndTide }</td>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <td class=""topRightBorder"">{ TaskRunnerServiceRes.Rain }(mm)<br />{ TaskRunnerServiceRes.Minus1Day }<br />{ TaskRunnerServiceRes.Minus2Day }<br />{ TaskRunnerServiceRes.Minus3Day }<br />{ TaskRunnerServiceRes.Minus4Day }<br />{ TaskRunnerServiceRes.Minus5Day }</td>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        string RainDay1 = mwqmRunModel.RainDay1_mm != null ? ((double)mwqmRunModel.RainDay1_mm).ToString("F0") : "--";
                        string RainDay2 = mwqmRunModel.RainDay2_mm != null ? ((double)mwqmRunModel.RainDay2_mm).ToString("F0") : "--";
                        string RainDay3 = mwqmRunModel.RainDay3_mm != null ? ((double)mwqmRunModel.RainDay3_mm).ToString("F0") : "--";
                        string RainDay4 = mwqmRunModel.RainDay4_mm != null ? ((double)mwqmRunModel.RainDay4_mm).ToString("F0") : "--";
                        string RainDay5 = mwqmRunModel.RainDay5_mm != null ? ((double)mwqmRunModel.RainDay5_mm).ToString("F0") : "--";
                        sbHTML.AppendLine($@" <td class=""topRightBorder"">&nbsp;<br />{ RainDay1 }<br />{ RainDay2 }<br />{ RainDay3 }<br />{ RainDay4 }<br />{ RainDay5 }</td>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    sbHTML.AppendLine($@" </table>");

                    sbHTML.AppendLine(@"<span>|||PageBreak|||</span>");

                    skip += take;
                }
                else
                {
                    HasData = false;
                }
            }

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


            skip     = 0;
            take     = 15;
            HasData  = true;
            countRun = 0;
            while (HasData)
            {
                countRun += 1;

                if (countRun > 2)
                {
                    break;
                }

                List <MWQMRunModel> mwqmRunModelList2 = mwqmRunModelList.Where(c => c.RunSampleType == SampleTypeEnum.Routine).OrderByDescending(c => c.DateTime_Local).Skip(skip).Take(take).ToList();
                if (mwqmRunModelList2.Count > 0)
                {
                    sbHTML.AppendLine($@" <h4>{ TaskRunnerServiceRes.ActiveMWQMSites }&nbsp;&nbsp;{ TaskRunnerServiceRes.Salinity }&nbsp;&nbsp;&nbsp;({ TaskRunnerServiceRes.Routine })&nbsp;&nbsp;&nbsp;{ mwqmRunModelList2[0].DateTime_Local.ToString("yyyy MMMM dd") } { TaskRunnerServiceRes.To } { mwqmRunModelList2[mwqmRunModelList2.Count - 1].DateTime_Local.ToString("yyyy MMMM dd") }</h4>");
                    sbHTML.AppendLine($@" <table class=""FCSalTempDataTableClass"">");
                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <th class=""rightBottomBorder"">{ TaskRunnerServiceRes.Site }</th>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        sbHTML.AppendLine($@" <th class=""bottomBorder"">{ mwqmRunModel.DateTime_Local.ToString("yyyy") }<br />{ mwqmRunModel.DateTime_Local.ToString("MMM") }<br />{ mwqmRunModel.DateTime_Local.ToString("dd") }</th>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    foreach (MWQMSiteModel mwqmSiteModel in mwqmSiteModelList2)
                    {
                        sbHTML.AppendLine($@" <tr>");
                        sbHTML.AppendLine($@" <td class=""rightBorder"">{ mwqmSiteModel.MWQMSiteTVText }</td>");
                        foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                        {
                            float?value = (float?)(from s in mwqmSampleModelList
                                                   where s.MWQMRunTVItemID == mwqmRunModel.MWQMRunTVItemID &&
                                                   s.MWQMSiteTVItemID == mwqmSiteModel.MWQMSiteTVItemID
                                                   select s.Salinity_PPT).FirstOrDefault();

                            string valueStr = value != null ? (value == 1 ? "< 2" : ((float)value).ToString("F0")) : "--";
                            sbHTML.AppendLine($@" <td>{ valueStr }</td>");
                        }
                        sbHTML.AppendLine($@" </tr>");
                    }
                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <td class=""topRightBorder"">{ TaskRunnerServiceRes.StartTide }<br />{ TaskRunnerServiceRes.EndTide }</td>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        string StartTide = GetTideInitial(mwqmRunModel.Tide_Start);
                        string EndTide   = GetTideInitial(mwqmRunModel.Tide_End);
                        sbHTML.AppendLine($@" <td class=""topRightBorder"">{ StartTide }<br />{ EndTide }</td>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <td class=""topRightBorder"">{ TaskRunnerServiceRes.Rain }(mm)<br />{ TaskRunnerServiceRes.Minus1Day }<br />{ TaskRunnerServiceRes.Minus2Day }<br />{ TaskRunnerServiceRes.Minus3Day }<br />{ TaskRunnerServiceRes.Minus4Day }<br />{ TaskRunnerServiceRes.Minus5Day }</td>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        string RainDay1 = mwqmRunModel.RainDay1_mm != null ? ((double)mwqmRunModel.RainDay1_mm).ToString("F0") : "--";
                        string RainDay2 = mwqmRunModel.RainDay2_mm != null ? ((double)mwqmRunModel.RainDay2_mm).ToString("F0") : "--";
                        string RainDay3 = mwqmRunModel.RainDay3_mm != null ? ((double)mwqmRunModel.RainDay3_mm).ToString("F0") : "--";
                        string RainDay4 = mwqmRunModel.RainDay4_mm != null ? ((double)mwqmRunModel.RainDay4_mm).ToString("F0") : "--";
                        string RainDay5 = mwqmRunModel.RainDay5_mm != null ? ((double)mwqmRunModel.RainDay5_mm).ToString("F0") : "--";
                        sbHTML.AppendLine($@" <td class=""topRightBorder"">&nbsp;<br />{ RainDay1 }<br />{ RainDay2 }<br />{ RainDay3 }<br />{ RainDay4 }<br />{ RainDay5 }</td>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    sbHTML.AppendLine($@" </table>");

                    sbHTML.AppendLine(@"<span>|||PageBreak|||</span>");

                    skip += take;
                }
                else
                {
                    HasData = false;
                }
            }

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


            skip     = 0;
            take     = 15;
            HasData  = true;
            countRun = 0;
            while (HasData)
            {
                countRun += 1;

                if (countRun > 2)
                {
                    break;
                }

                List <MWQMRunModel> mwqmRunModelList2 = mwqmRunModelList.Where(c => c.RunSampleType == SampleTypeEnum.Routine).OrderByDescending(c => c.DateTime_Local).Skip(skip).Take(take).ToList();
                if (mwqmRunModelList2.Count > 0)
                {
                    sbHTML.AppendLine($@" <h4>{ TaskRunnerServiceRes.ActiveMWQMSites }&nbsp;&nbsp;{ TaskRunnerServiceRes.Temperature }&nbsp;&nbsp;&nbsp;({ TaskRunnerServiceRes.Routine })&nbsp;&nbsp;&nbsp;{ mwqmRunModelList2[0].DateTime_Local.ToString("yyyy MMMM dd") } { TaskRunnerServiceRes.To } { mwqmRunModelList2[mwqmRunModelList2.Count - 1].DateTime_Local.ToString("yyyy MMMM dd") }</h4>");
                    sbHTML.AppendLine($@" <table class=""FCSalTempDataTableClass"">");
                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <th class=""rightBottomBorder"">{ TaskRunnerServiceRes.Site }</th>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        sbHTML.AppendLine($@" <th class=""bottomBorder"">{ mwqmRunModel.DateTime_Local.ToString("yyyy") }<br />{ mwqmRunModel.DateTime_Local.ToString("MMM") }<br />{ mwqmRunModel.DateTime_Local.ToString("dd") }</th>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    foreach (MWQMSiteModel mwqmSiteModel in mwqmSiteModelList2)
                    {
                        sbHTML.AppendLine($@" <tr>");
                        sbHTML.AppendLine($@" <td class=""rightBorder"">{ mwqmSiteModel.MWQMSiteTVText }</td>");
                        foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                        {
                            float?value = (float?)(from s in mwqmSampleModelList
                                                   where s.MWQMRunTVItemID == mwqmRunModel.MWQMRunTVItemID &&
                                                   s.MWQMSiteTVItemID == mwqmSiteModel.MWQMSiteTVItemID
                                                   select s.WaterTemp_C).FirstOrDefault();

                            string valueStr = value != null ? (value == 1 ? "< 2" : ((float)value).ToString("F0")) : "--";
                            sbHTML.AppendLine($@" <td>{ valueStr }</td>");
                        }
                        sbHTML.AppendLine($@" </tr>");
                    }
                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <td class=""topRightBorder"">{ TaskRunnerServiceRes.StartTide }<br />{ TaskRunnerServiceRes.EndTide }</td>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        string StartTide = GetTideInitial(mwqmRunModel.Tide_Start);
                        string EndTide   = GetTideInitial(mwqmRunModel.Tide_End);
                        sbHTML.AppendLine($@" <td class=""topRightBorder"">{ StartTide }<br />{ EndTide }</td>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    sbHTML.AppendLine($@" <tr>");
                    sbHTML.AppendLine($@" <td class=""topRightBorder"">{ TaskRunnerServiceRes.Rain }(mm)<br />{ TaskRunnerServiceRes.Minus1Day }<br />{ TaskRunnerServiceRes.Minus2Day }<br />{ TaskRunnerServiceRes.Minus3Day }<br />{ TaskRunnerServiceRes.Minus4Day }<br />{ TaskRunnerServiceRes.Minus5Day }</td>");
                    foreach (MWQMRunModel mwqmRunModel in mwqmRunModelList2)
                    {
                        string RainDay1 = mwqmRunModel.RainDay1_mm != null ? ((double)mwqmRunModel.RainDay1_mm).ToString("F0") : "--";
                        string RainDay2 = mwqmRunModel.RainDay2_mm != null ? ((double)mwqmRunModel.RainDay2_mm).ToString("F0") : "--";
                        string RainDay3 = mwqmRunModel.RainDay3_mm != null ? ((double)mwqmRunModel.RainDay3_mm).ToString("F0") : "--";
                        string RainDay4 = mwqmRunModel.RainDay4_mm != null ? ((double)mwqmRunModel.RainDay4_mm).ToString("F0") : "--";
                        string RainDay5 = mwqmRunModel.RainDay5_mm != null ? ((double)mwqmRunModel.RainDay5_mm).ToString("F0") : "--";
                        sbHTML.AppendLine($@" <td class=""topRightBorder"">&nbsp;<br />{ RainDay1 }<br />{ RainDay2 }<br />{ RainDay3 }<br />{ RainDay4 }<br />{ RainDay5 }</td>");
                    }
                    sbHTML.AppendLine($@" </tr>");

                    sbHTML.AppendLine($@" </table>");

                    sbHTML.AppendLine(@"<span>|||PageBreak|||</span>");

                    skip += take;
                }
                else
                {
                    HasData = false;
                }
            }


            sbHTML.AppendLine($@"|||FileNameExtra|Random,{ FileNameExtra }|||");

            sbHTML.AppendLine(@"<span>|||PageBreak|||</span>");

            if (!GetBottomHTML(sbHTML, fi, parameters))
            {
                return(false);
            }

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

            return(true);
        }
Exemple #28
0
        public MWQMSiteModel PostDeleteMWQMSiteDB(int MWQMSiteID)
        {
            ContactOK contactOK = IsContactOK();

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

            MWQMSite mwqmSiteToDelete = GetMWQMSiteWithMWQMSiteIDDB(MWQMSiteID);

            if (mwqmSiteToDelete == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToDelete, ServiceRes.MWQMSite)));
            }

            int TVItemIDToDelete = mwqmSiteToDelete.MWQMSiteTVItemID;

            using (TransactionScope ts = new TransactionScope())
            {
                db.MWQMSites.Remove(mwqmSiteToDelete);
                string retStr = DoDeleteChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("MWQMSites", mwqmSiteToDelete.MWQMSiteID, LogCommandEnum.Delete, mwqmSiteToDelete);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                List <MWQMSiteStartEndDateModel> mwqmsiteStartEndDateModelList = _MWQMSiteStartEndDateService.GetMWQMSiteStartEndDateModelListWithMWQMSiteTVItemIDDB(mwqmSiteToDelete.MWQMSiteTVItemID);

                foreach (MWQMSiteStartEndDateModel mwqmSiteStartEndDateModel in mwqmsiteStartEndDateModelList)
                {
                    MWQMSiteStartEndDateModel mwqmSiteStartEndDateModelRet = _MWQMSiteStartEndDateService.PostDeleteMWQMSiteStartEndDateDB(mwqmSiteStartEndDateModel.MWQMSiteStartEndDateID);
                    if (!string.IsNullOrWhiteSpace(mwqmSiteStartEndDateModelRet.Error))
                    {
                        return(ReturnError(mwqmSiteStartEndDateModelRet.Error));
                    }
                }

                List <MapInfoModel> mapInfoModelList = _MapInfoService.GetMapInfoModelListWithTVItemIDDB(mwqmSiteToDelete.MWQMSiteID);

                foreach (MapInfoModel mapInfoModel in mapInfoModelList)
                {
                    MapInfoModel mapInfoModelRet = _MapInfoService.PostDeleteMapInfoDB(mapInfoModel.MapInfoID);
                    if (!string.IsNullOrWhiteSpace(mapInfoModelRet.Error))
                    {
                        return(ReturnError(mapInfoModelRet.Error));
                    }
                }

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

                ts.Complete();
            }

            return(ReturnError(""));
        }
Exemple #29
0
        // Post
        public MWQMSiteModel MWQMSiteSaveAllDB(FormCollection fc)
        {
            //int tempInt = 0;
            int    SubsectorTVItemID   = 0;
            int    MWQMSiteTVItemID    = 0;
            bool   IsActive            = true;
            string MWQMSiteTVText      = "";
            string MWQMSiteNumber      = "";
            string MWQMSiteDescription = "";
            double Lat     = 0.0D;
            double Lng     = 0.0D;
            int    tempInt = 0;

            ContactOK contactOK = IsContactOK();

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

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

            TVItemModel tvItemModelSubsector = _TVItemService.GetTVItemModelWithTVItemIDDB(SubsectorTVItemID);

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

            int.TryParse(fc["MWQMSiteTVItemID"], out MWQMSiteTVItemID);
            // could be 0 if 0 then we need to add the new MWQMSite

            MWQMSiteModel mwqmSiteNewOrToChange = new MWQMSiteModel();

            if (fc["IsActive"] != null)
            {
                IsActive = true;
            }
            else
            {
                IsActive = false;
            }

            if (MWQMSiteTVItemID != 0)
            {
                mwqmSiteNewOrToChange = GetMWQMSiteModelWithMWQMSiteTVItemIDDB(MWQMSiteTVItemID);
                if (!string.IsNullOrWhiteSpace(mwqmSiteNewOrToChange.Error))
                {
                    return(ReturnError(mwqmSiteNewOrToChange.Error));
                }
            }

            mwqmSiteNewOrToChange.DBCommand = DBCommandEnum.Original;

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

            if (MWQMSiteTVText.Contains("#"))
            {
                return(ReturnError(string.Format(ServiceRes.NameOfItemShouldNotContainThe_Character, "#")));
            }

            mwqmSiteNewOrToChange.MWQMSiteTVText = MWQMSiteTVText;

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

            mwqmSiteNewOrToChange.MWQMSiteNumber = MWQMSiteNumber;

            List <TVItemModel> tvItemModelMWQMSiteList = _TVItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(SubsectorTVItemID, TVTypeEnum.MWQMSite);

            foreach (TVItemModel tvItemModelMWQMSite in tvItemModelMWQMSiteList)
            {
                if (tvItemModelMWQMSite.TVItemID != MWQMSiteTVItemID)
                {
                    MWQMSiteModel mwqmSiteModel = GetMWQMSiteModelWithMWQMSiteTVItemIDDB(tvItemModelMWQMSite.TVItemID);
                    if (!string.IsNullOrWhiteSpace(mwqmSiteModel.Error))
                    {
                        return(ReturnError(mwqmSiteModel.Error));
                    }

                    if (mwqmSiteModel.MWQMSiteNumber == MWQMSiteNumber)
                    {
                        return(ReturnError(string.Format(ServiceRes.MWQMSiteNumberHasToBeUniqueForSubsector)));
                    }
                }
            }

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

            mwqmSiteNewOrToChange.MWQMSiteDescription = MWQMSiteDescription;

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

            mwqmSiteNewOrToChange.MWQMSiteLatestClassification = (MWQMSiteLatestClassificationEnum)tempInt;

            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
                }
            };

            MWQMSiteModel mwqmSiteModelRet = new MWQMSiteModel();

            using (TransactionScope ts = new TransactionScope())
            {
                if (MWQMSiteTVItemID == 0)
                {
                    TVItemModel tvItemModelNewMWQMSite = _TVItemService.PostAddChildTVItemDB(SubsectorTVItemID, MWQMSiteTVText, TVTypeEnum.MWQMSite);
                    if (!string.IsNullOrWhiteSpace(tvItemModelNewMWQMSite.Error))
                    {
                        return(ReturnError(tvItemModelNewMWQMSite.Error));
                    }

                    mwqmSiteNewOrToChange.MWQMSiteTVItemID = tvItemModelNewMWQMSite.TVItemID;

                    mwqmSiteModelRet = PostAddMWQMSiteDB(mwqmSiteNewOrToChange);
                    if (!string.IsNullOrWhiteSpace(mwqmSiteModelRet.Error))
                    {
                        return(ReturnError(mwqmSiteModelRet.Error));
                    }
                }
                else
                {
                    mwqmSiteModelRet = PostUpdateMWQMSiteDB(mwqmSiteNewOrToChange);
                    if (!string.IsNullOrWhiteSpace(mwqmSiteModelRet.Error))
                    {
                        return(ReturnError(mwqmSiteModelRet.Error));
                    }
                }


                List <MapInfoPointModel> mapInfoPointModelList = _MapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(mwqmSiteModelRet.MWQMSiteTVItemID, TVTypeEnum.MWQMSite, MapInfoDrawTypeEnum.Point);
                if (mapInfoPointModelList.Count == 0)
                {
                    MapInfoModel mapInfoModelRet = _MapInfoService.CreateMapInfoObjectDB(coordList, MapInfoDrawTypeEnum.Point, TVTypeEnum.MWQMSite, mwqmSiteModelRet.MWQMSiteTVItemID);
                    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 tvItemModel = _TVItemService.GetTVItemModelWithTVItemIDDB(mwqmSiteModelRet.MWQMSiteTVItemID);
                if (!string.IsNullOrWhiteSpace(tvItemModel.Error))
                {
                    return(ReturnError(tvItemModel.Error));
                }

                tvItemModel.IsActive = IsActive;
                tvItemModel.TVText   = MWQMSiteTVText;

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

                ts.Complete();
            }
            return(mwqmSiteModelRet);
        }
Exemple #30
0
        public void Generate(FileInfo fi)
        {
            TVItemService  tvItemService  = new TVItemService(_TaskRunnerBaseService._BWObj.appTaskModel.Language, _TaskRunnerBaseService._User);
            MapInfoService mapInfoService = new MapInfoService(_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 sbKMZ = new StringBuilder();

            sbKMZ.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
            sbKMZ.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"">");
            sbKMZ.AppendLine(@"<Document>");
            sbKMZ.AppendLine(@"	<name>" + _TaskRunnerBaseService.generateDocParams.FileName + "</name>");

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

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

            sbKMZ.AppendLine(@"	<Folder>");
            sbKMZ.AppendLine(@"	<name>Province</name>");

            // Doing Point
            sbKMZ.AppendLine(@"	<Placemark>");
            sbKMZ.AppendLine(@"	<name>" + tvItemModelProvince.TVText + "</name>");
            sbKMZ.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>");
            sbKMZ.AppendLine(@"	<Point>");
            sbKMZ.AppendLine(@"		<coordinates>"+ mapInfoPointModelList[0].Lng + "," + mapInfoPointModelList[0].Lat + ",0</coordinates>");
            sbKMZ.AppendLine(@"	</Point>");
            sbKMZ.AppendLine(@"	</Placemark>");

            // Doing Polygon
            sbKMZ.AppendLine(@"	<Placemark>");
            sbKMZ.AppendLine(@"		<name>"+ tvItemModelProvince.TVText + " (poly)</name>");
            sbKMZ.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>");
            sbKMZ.AppendLine(@"		<Polygon>");
            sbKMZ.AppendLine(@"			<outerBoundaryIs>");
            sbKMZ.AppendLine(@"				<LinearRing>");
            sbKMZ.AppendLine(@"					<coordinates>");
            sbKMZ.AppendLine(@"		"+ (mapInfoPointModelList[0].Lng - 0.1) + "," + (mapInfoPointModelList[0].Lat - 0.1) + ",0");
            sbKMZ.AppendLine(@"		"+ (mapInfoPointModelList[0].Lng + 0.1) + "," + (mapInfoPointModelList[0].Lat - 0.1) + ",0");
            sbKMZ.AppendLine(@"		"+ (mapInfoPointModelList[0].Lng + 0.1) + "," + (mapInfoPointModelList[0].Lat + 0.1) + ",0");
            sbKMZ.AppendLine(@"		"+ (mapInfoPointModelList[0].Lng - 0.1) + "," + (mapInfoPointModelList[0].Lat + 0.1) + ",0");
            sbKMZ.AppendLine(@"		"+ (mapInfoPointModelList[0].Lng - 0.1) + "," + (mapInfoPointModelList[0].Lat - 0.1) + ",0");
            sbKMZ.AppendLine(@"					</coordinates>");
            sbKMZ.AppendLine(@"				</LinearRing>");
            sbKMZ.AppendLine(@"			</outerBoundaryIs>");
            sbKMZ.AppendLine(@"		</Polygon>");
            sbKMZ.AppendLine(@"	</Placemark>");

            sbKMZ.AppendLine(@" <Folder>");
            sbKMZ.AppendLine(@"	<name>Areas</name>");
            List <TVItemModel> tvItemModelAreaList = tvItemService.GetChildrenTVItemModelListWithTVItemIDAndTVTypeDB(tvItemModelProvince.TVItemID, TVTypeEnum.Area);

            foreach (TVItemModel tvItemModelArea in tvItemModelAreaList)
            {
                // Doing point
                sbKMZ.AppendLine(@"	<Placemark>");
                sbKMZ.AppendLine(@"	<name>" + tvItemModelArea.TVText + "</name>");
                sbKMZ.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>");

                mapInfoPointModelList = mapInfoService._MapInfoPointService.GetMapInfoPointModelListWithTVItemIDAndTVTypeAndMapInfoDrawTypeDB(tvItemModelArea.TVItemID, TVTypeEnum.Area, MapInfoDrawTypeEnum.Point);

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

                // Doing Polygon
                sbKMZ.AppendLine(@"	<Placemark>");
                sbKMZ.AppendLine(@"		<name>"+ tvItemModelArea.TVText + " (poly)</name>");
                sbKMZ.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>");
                sbKMZ.AppendLine(@"		<Polygon>");
                sbKMZ.AppendLine(@"			<outerBoundaryIs>");
                sbKMZ.AppendLine(@"				<LinearRing>");
                sbKMZ.AppendLine(@"					<coordinates>");

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

                sbKMZ.AppendLine(@"					</coordinates>");
                sbKMZ.AppendLine(@"				</LinearRing>");
                sbKMZ.AppendLine(@"			</outerBoundaryIs>");
                sbKMZ.AppendLine(@"		</Polygon>");
                sbKMZ.AppendLine(@"	</Placemark>");
            }
            sbKMZ.AppendLine(@" </Folder>");

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

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

            StreamWriter sw = fi.CreateText();

            sw.Write(sbKMZ.ToString());

            sw.Close();
        }