Esempio n. 1
0
        public PartialViewResult _LabSheetsTranferred(int SamplingPlanID)
        {
            ViewBag.SamplingPlanController      = _SamplingPlanController;
            ViewBag.AdminContactModelList       = null;
            ViewBag.IsSamplingPlanner           = false;
            ViewBag.LabSheetModelAndA1SheetList = null;
            ViewBag.LastAnalyzeMethod           = AnalyzeMethodEnum.Error;
            ViewBag.LastSampleMatrix            = SampleMatrixEnum.Error;
            ViewBag.LastLaboratory                  = LaboratoryEnum.Error;
            ViewBag.MWQMSampleModelList             = new List <MWQMSampleModel>();
            ViewBag.SubsectorMWQMSiteModelList      = new List <SubsectorMWQMSiteModel>();
            ViewBag.SamplingPlanModel               = null;
            ViewBag.LabSheetSiteMonitoredCountsList = null;

            List <LabSheetModelAndA1Sheet> labSheetModelAndA1SheetList = new List <LabSheetModelAndA1Sheet>();

            SamplingPlanService SamplingPlanService = new SamplingPlanService(_TVItemService.LanguageRequest, _TVItemService.User);
            LabSheetService     labSheetService     = new LabSheetService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMRunService      mwqmRunService      = new MWQMRunService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMSampleService   mwqmSampleService   = new MWQMSampleService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMSiteService     mwqmSiteService     = new MWQMSiteService(_TVItemService.LanguageRequest, _TVItemService.User);

            ContactModel contactModel = _ContactService.GetContactLoggedInDB();

            SamplingPlanModel SamplingPlanModel = SamplingPlanService.GetSamplingPlanModelWithSamplingPlanIDDB(SamplingPlanID);

            if (string.IsNullOrWhiteSpace(SamplingPlanModel.Error))
            {
                ViewBag.SamplingPlanModel = SamplingPlanModel;

                ViewBag.IsSamplingPlanner = false;
                if (contactModel.SamplingPlanner_ProvincesTVItemID.Contains(SamplingPlanModel.ProvinceTVItemID.ToString()))
                {
                    ViewBag.IsSamplingPlanner = true;
                }
                else
                {
                    List <ContactModel> adminContactModelList = _ContactService.GetAdminContactModelListDB();
                    ViewBag.AdminContactModelList = adminContactModelList;
                }

                List <LabSheetModel> labSheetModelList = labSheetService.GetLabSheetModelListWithSamplingPlanIDAndLabSheetStatusDB(SamplingPlanID, LabSheetStatusEnum.Transferred);
                foreach (LabSheetModel labSheetModel in labSheetModelList)
                {
                    LabSheetModelAndA1Sheet labSheetModelAndA1Sheet = new LabSheetModelAndA1Sheet();
                    labSheetModelAndA1Sheet.LabSheetModel   = labSheetModel;
                    labSheetModelAndA1Sheet.LabSheetA1Sheet = labSheetService.ParseLabSheetA1WithLabSheetID(labSheetModel.LabSheetID);
                    labSheetModelAndA1SheetList.Add(labSheetModelAndA1Sheet);
                }
                ViewBag.LabSheetModelAndA1SheetList = labSheetModelAndA1SheetList;

                if (labSheetModelAndA1SheetList.Count > 0)
                {
                    MWQMRunModel mwqmRunModelLast = mwqmRunService.GetMWQMRunModelLastWithSubsectorTVItemIDDB(labSheetModelAndA1SheetList[0].LabSheetModel.SubsectorTVItemID);
                    if (string.IsNullOrWhiteSpace(mwqmRunModelLast.Error))
                    {
                        if (mwqmRunModelLast.AnalyzeMethod != null)
                        {
                            ViewBag.LastAnalyzeMethod = (AnalyzeMethodEnum)mwqmRunModelLast.AnalyzeMethod;
                        }
                        if (mwqmRunModelLast.SampleMatrix != null)
                        {
                            ViewBag.LastSampleMatrix = (SampleMatrixEnum)mwqmRunModelLast.SampleMatrix;
                        }
                        if (mwqmRunModelLast.Laboratory != null)
                        {
                            ViewBag.LastLaboratory = (LaboratoryEnum)mwqmRunModelLast.Laboratory;
                        }
                    }
                }

                List <MWQMSampleModel> mwqmSampleModelList = new List <MWQMSampleModel>();
                foreach (LabSheetModelAndA1Sheet labSheetModelAndA1Sheet in labSheetModelAndA1SheetList)
                {
                    int Year  = 0;
                    int Month = 0;
                    int Day   = 0;
                    if (int.TryParse(labSheetModelAndA1Sheet.LabSheetA1Sheet.RunYear, out Year))
                    {
                        if (int.TryParse(labSheetModelAndA1Sheet.LabSheetA1Sheet.RunMonth, out Month))
                        {
                            if (int.TryParse(labSheetModelAndA1Sheet.LabSheetA1Sheet.RunDay, out Day))
                            {
                                MWQMRunModel mwqmRunModelNew = new MWQMRunModel()
                                {
                                    SubsectorTVItemID = labSheetModelAndA1Sheet.LabSheetA1Sheet.SubsectorTVItemID,
                                    DateTime_Local    = new DateTime(Year, Month, Day),
                                    RunSampleType     = labSheetModelAndA1Sheet.LabSheetA1Sheet.SampleType,
                                    RunNumber         = labSheetModelList[0].RunNumber,
                                };

                                MWQMRunModel mwqmRunModel = mwqmRunService.GetMWQMRunModelExistDB(mwqmRunModelNew);
                                if (string.IsNullOrWhiteSpace(mwqmRunModel.Error))
                                {
                                    List <MWQMSampleModel> mwqmSampleModelList2 = mwqmSampleService.GetMWQMSampleModelListWithMWQMRunTVItemIDDB(mwqmRunModel.MWQMRunTVItemID);
                                    foreach (MWQMSampleModel mwqmSampleModel in mwqmSampleModelList2)
                                    {
                                        mwqmSampleModelList.Add(mwqmSampleModel);
                                    }
                                }
                            }
                        }
                    }
                }
                ViewBag.MWQMSampleModelList = mwqmSampleModelList;


                if (labSheetModelAndA1SheetList.Count > 0)
                {
                    List <SubsectorMWQMSiteModel> subsectorMWQMSiteModelList = new List <SubsectorMWQMSiteModel>();

                    foreach (LabSheetModelAndA1Sheet labSheetModelAndA1Sheet in labSheetModelAndA1SheetList)
                    {
                        List <MWQMSiteModel> mwqmSiteModelList = mwqmSiteService.GetMWQMSiteModelListWithSubsectorTVItemIDDB(labSheetModelAndA1Sheet.LabSheetA1Sheet.SubsectorTVItemID);
                        subsectorMWQMSiteModelList.Add(new SubsectorMWQMSiteModel()
                        {
                            Subsector = labSheetModelAndA1Sheet.LabSheetA1Sheet.SubsectorName, MWQMSiteModelList = mwqmSiteModelList
                        });
                    }

                    ViewBag.SubsectorMWQMSiteModelList = subsectorMWQMSiteModelList;
                }

                List <LabSheetSiteMonitoredCounts> labSheetSiteMonitoredCountsList = labSheetService.GetLabSheetIDListAndCountSamplesWithSamplingPlanIDDB(SamplingPlanID);
                ViewBag.LabSheetSiteMonitoredCountsList = labSheetSiteMonitoredCountsList;
            }

            return(PartialView());
        }
Esempio n. 2
0
        public void GetNextLabSheet()
        {
            string retStr = "";

            try
            {
                using (WebClient webClient = new WebClient())
                {
                    WebProxy webProxy = new WebProxy();
                    webClient.Proxy = webProxy;

                    string FullLabSheetText = webClient.DownloadString(new Uri("http://cssplabsheet.azurewebsites.net/GetNextLabSheet.aspx"));

                    if (FullLabSheetText.Length > 0)
                    {
                        int    posStart = FullLabSheetText.IndexOf("OtherServerLabSheetID|||||[") + 27;
                        int    posEnd   = FullLabSheetText.IndexOf("]", posStart);
                        string OtherServerLabSheetIDTxt = FullLabSheetText.Substring(posStart, posEnd - posStart);
                        int    OtherServerLabSheetID    = int.Parse(OtherServerLabSheetIDTxt);

                        posStart = FullLabSheetText.IndexOf("SubsectorTVItemID|||||[") + 23;
                        posEnd   = FullLabSheetText.IndexOf("]", posStart);
                        string SubsectorTVItemIDTxt = FullLabSheetText.Substring(posStart, posEnd - posStart);
                        int    SubsectorTVItemID    = int.Parse(SubsectorTVItemIDTxt);

                        TVItem             tvItemSubsector    = new TVItem();
                        TVItem             tvItemCountry      = new TVItem();
                        TVItem             tvItemProvince     = new TVItem();
                        LabSheetAndA1Sheet labSheetAndA1Sheet = new LabSheetAndA1Sheet();
                        using (TransactionScope ts = new TransactionScope())
                        {
                            LabSheetService labSheetService = new LabSheetService(LanguageEnum.en, _User);

                            LabSheet labSheetRet = labSheetService.AddOrUpdateLabSheetDB(FullLabSheetText);
                            if (!string.IsNullOrWhiteSpace(labSheetRet.Error))
                            {
                                richTextBoxStatus.AppendText("Lab sheet adding error OtherServerLabSheetID [" + OtherServerLabSheetID.ToString() + "]" + labSheetRet.Error + "]\r\n");
                                return;
                            }

                            TVItemService tvItemService = new TVItemService(LanguageEnum.en, _User);

                            tvItemSubsector = tvItemService.GetTVItemModelWithTVItemIDDB(SubsectorTVItemID);
                            if (!string.IsNullOrWhiteSpace(tvItemSubsector.Error))
                            {
                                richTextBoxStatus.AppendText("Lab sheet parsing error OtherServerLabSheetID [" + OtherServerLabSheetID.ToString() + "]" + tvItemSubsector.Error + "]\r\n");
                                return;
                            }

                            List <TVItem> tvItemList = tvItemService.GetParentsTVItemList(tvItemSubsector.TVPath);
                            foreach (TVItem tvItem in tvItemList)
                            {
                                if (tvItem.TVType == TVTypeEnum.Province)
                                {
                                    tvItemProvince = tvItem;
                                }
                                if (tvItem.TVType == TVTypeEnum.Country)
                                {
                                    tvItemCountry = tvItem;
                                }
                            }

                            labSheetAndA1Sheet.LabSheet        = labSheetRet;
                            labSheetAndA1Sheet.LabSheetA1Sheet = labSheetService.ParseLabSheetA1WithLabSheetID(labSheetRet.LabSheetID);
                            if (!string.IsNullOrWhiteSpace(labSheetAndA1Sheet.LabSheetA1Sheet.Error))
                            {
                                richTextBoxStatus.AppendText("Lab sheet parsing error OtherServerLabSheetID [" + OtherServerLabSheetID.ToString() + "]" + labSheetAndA1Sheet.LabSheetA1Sheet.Error + "]\r\n");
                                richTextBoxStatus.AppendText("Full Lab Sheet Text below\r\n");
                                richTextBoxStatus.AppendText("---------------- Start of full lab sheet text -----------\r\n");
                                richTextBoxStatus.AppendText(FullLabSheetText);
                                richTextBoxStatus.AppendText("---------------- End of full lab sheet text -----------\r\n");
                                retStr = UpdateOtherServerWithOtherServerLabSheetIDAndLabSheetStatus(OtherServerLabSheetID, LabSheetStatusEnum.Error);
                                if (!string.IsNullOrWhiteSpace(retStr))
                                {
                                    richTextBoxStatus.AppendText("Error updating other server lab sheet [" + retStr + "]");
                                }
                                return;
                            }

                            string retStr2 = UploadLabSheetDetailInDB(labSheetAndA1Sheet);
                            if (!string.IsNullOrWhiteSpace(retStr2))
                            {
                                // Error message already sent to richTextboxStatus
                                retStr = UpdateOtherServerWithOtherServerLabSheetIDAndLabSheetStatus(OtherServerLabSheetID, LabSheetStatusEnum.Error);
                                if (!string.IsNullOrWhiteSpace(retStr))
                                {
                                    richTextBoxStatus.AppendText("Error updating other server lab sheet [" + retStr + "]");
                                }
                                return;
                            }

                            ts.Complete();
                        }

                        string href = "http://wmon01dtchlebl2/csspwebtools/en-CA/#!View/" + (tvItemCountry.TVText + "-" + tvItemProvince.TVText).Replace(" ", "-") + "|||" + tvItemProvince.TVItemID.ToString() + "|||010003030200000000000000000000";

                        if (labSheetAndA1Sheet.LabSheetA1Sheet.LabSheetA1MeasurementList.Where(c => c.MPN != null && c.MPN >= MPNLimitForEmail).Any())
                        {
                            SendNewLabSheetEmailBigMPN(href, tvItemProvince, tvItemSubsector, labSheetAndA1Sheet);
                        }
                        else
                        {
                            SendNewLabSheetEmail(href, tvItemProvince, tvItemSubsector, labSheetAndA1Sheet);
                        }

                        retStr = UpdateOtherServerWithOtherServerLabSheetIDAndLabSheetStatus(OtherServerLabSheetID, LabSheetStatusEnum.Transferred);
                        if (!string.IsNullOrWhiteSpace(retStr))
                        {
                            richTextBoxStatus.AppendText("Error updating other server lab sheet [" + retStr + "]");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errrrrr = ex.Message;
            }
        }
Esempio n. 3
0
        public PartialViewResult _LabSheetsHistoryDetail(int SamplingPlanID, int LabSheetID)
        {
            ViewBag.SamplingPlanController  = _SamplingPlanController;
            ViewBag.AdminContactModelList   = null;
            ViewBag.IsSamplingPlanner       = false;
            ViewBag.LabSheetModelAndA1Sheet = null;
            ViewBag.AnalyzeMethod           = AnalyzeMethodEnum.Error;
            ViewBag.SampleMatrix            = SampleMatrixEnum.Error;
            ViewBag.Laboratory        = LaboratoryEnum.Error;
            ViewBag.MWQMSiteModelList = new List <MWQMSiteModel>();

            SamplingPlanService SamplingPlanService = new SamplingPlanService(_TVItemService.LanguageRequest, _TVItemService.User);
            LabSheetService     labSheetService     = new LabSheetService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMRunService      mwqmRunService      = new MWQMRunService(_TVItemService.LanguageRequest, _TVItemService.User);
            MWQMSiteService     mwqmSiteService     = new MWQMSiteService(_TVItemService.LanguageRequest, _TVItemService.User);

            ContactModel contactModel = _ContactService.GetContactLoggedInDB();


            SamplingPlanModel SamplingPlanModel = SamplingPlanService.GetSamplingPlanModelWithSamplingPlanIDDB(SamplingPlanID);

            if (string.IsNullOrWhiteSpace(SamplingPlanModel.Error))
            {
                ViewBag.IsSamplingPlanner = false;
                if (contactModel.SamplingPlanner_ProvincesTVItemID.Contains(SamplingPlanModel.ProvinceTVItemID.ToString()))
                {
                    ViewBag.IsSamplingPlanner = true;
                }
                else
                {
                    List <ContactModel> adminContactModelList = _ContactService.GetAdminContactModelListDB();
                    ViewBag.AdminContactModelList = adminContactModelList;
                }

                LabSheetModel           labSheetModel           = labSheetService.GetLabSheetModelWithLabSheetIDDB(LabSheetID);
                LabSheetModelAndA1Sheet labSheetModelAndA1Sheet = new LabSheetModelAndA1Sheet();
                labSheetModelAndA1Sheet.LabSheetModel   = labSheetModel;
                labSheetModelAndA1Sheet.LabSheetA1Sheet = labSheetService.ParseLabSheetA1WithLabSheetID(labSheetModel.LabSheetID);
                ViewBag.LabSheetModelAndA1Sheet         = labSheetModelAndA1Sheet;

                if (labSheetModel.MWQMRunTVItemID != null)
                {
                    MWQMRunModel mwqmRunModel = mwqmRunService.GetMWQMRunModelWithMWQMRunTVItemIDDB((int)labSheetModel.MWQMRunTVItemID);
                    if (string.IsNullOrWhiteSpace(mwqmRunModel.Error))
                    {
                        if (mwqmRunModel.AnalyzeMethod != null)
                        {
                            ViewBag.AnalyzeMethod = (AnalyzeMethodEnum)mwqmRunModel.AnalyzeMethod;
                        }
                        if (mwqmRunModel.SampleMatrix != null)
                        {
                            ViewBag.SampleMatrix = (SampleMatrixEnum)mwqmRunModel.SampleMatrix;
                        }
                        if (mwqmRunModel.Laboratory != null)
                        {
                            ViewBag.Laboratory = (LaboratoryEnum)mwqmRunModel.Laboratory;
                        }
                    }
                }

                List <MWQMSiteModel> mwqmSiteModelList = mwqmSiteService.GetMWQMSiteModelListWithSubsectorTVItemIDDB(labSheetModelAndA1Sheet.LabSheetA1Sheet.SubsectorTVItemID);

                ViewBag.MWQMSiteModelList = mwqmSiteModelList;
            }

            return(PartialView());
        }