public void LabSheet_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    LabSheetController labSheetController = new LabSheetController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(labSheetController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, labSheetController.DatabaseType);

                    LabSheet labSheetLast = new LabSheet();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        LabSheetService labSheetService = new LabSheetService(query, db, ContactID);
                        labSheetLast = (from c in db.LabSheets select c).FirstOrDefault();
                    }

                    // ok with LabSheet info
                    IHttpActionResult jsonRet = labSheetController.GetLabSheetWithID(labSheetLast.LabSheetID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <LabSheet> Ret = jsonRet as OkNegotiatedContentResult <LabSheet>;
                    LabSheet labSheetRet = Ret.Content;
                    Assert.AreEqual(labSheetLast.LabSheetID, labSheetRet.LabSheetID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = labSheetController.Put(labSheetRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <LabSheet> labSheetRet2 = jsonRet2 as OkNegotiatedContentResult <LabSheet>;
                    Assert.IsNotNull(labSheetRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because LabSheetID of 0 does not exist
                    labSheetRet.LabSheetID = 0;
                    IHttpActionResult jsonRet3 = labSheetController.Put(labSheetRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <LabSheet> labSheetRet3 = jsonRet3 as OkNegotiatedContentResult <LabSheet>;
                    Assert.IsNull(labSheetRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
        private string UpdateLabSheetAcceptedOrRejectedByForOtherServerLabSheetID()
        {
            int    OtherServerLabSheetID = -1;
            string AcceptedOrRejectedBy  = "";
            string RejectReason          = "";

            int.TryParse(Request.Params["OtherServerLabSheetID"], out OtherServerLabSheetID);
            if (OtherServerLabSheetID == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "OtherServerLabSheetID"));
            }

            if (string.IsNullOrWhiteSpace(Request.Params["AcceptedOrRejectedBy"]))
            {
                return(string.Format(LabSheetViewRes._IsRequired, "AcceptedOrRejectedBy"));
            }

            AcceptedOrRejectedBy = Request.Params["AcceptedOrRejectedBy"];

            if (string.IsNullOrWhiteSpace(Request.Params["RejectReason"]))
            {
                return(string.Format(LabSheetViewRes._IsRequired, "RejectReason"));
            }

            RejectReason = Request.Params["RejectReason"];

            using (CSSPEntities db = new CSSPEntities())
            {
                LabSheet labSheet = (from c in db.LabSheets
                                     where c.OtherServerLabSheetID == OtherServerLabSheetID
                                     select c).FirstOrDefault();

                if (labSheet == null)
                {
                    return("NO");
                }
                else
                {
                    labSheet.AcceptedOrRejectedBy         = AcceptedOrRejectedBy;
                    labSheet.AcceptedOrRejectedDate_Local = DateTime.Now;
                    labSheet.RejectReason = RejectReason;

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        return(ex.Message + " ---- " + (ex.InnerException == null ? "" : ex.InnerException.Message));
                    }
                }
            }

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

                using (TransactionScope ts = new TransactionScope())
                {
                    LabSheet labSheet = (from c in labSheetService.db.LabSheets
                                         select c).FirstOrDefault();

                    if (labSheet != null)
                    {
                        labSheet.LabSheetStatus = (int)LabSheetStatusEnum.Transferred;
                        try
                        {
                            labSheetService.db.SaveChanges();
                        }
                        catch (Exception)
                        {
                            Assert.IsTrue(false);
                        }
                    }

                    PartialViewResult partialViewResult = controller._LabSheetsTranferred(labSheet.MWQMPlanID) as PartialViewResult;
                    Assert.IsNotNull(partialViewResult);

                    MWQMPlanController MWQMPlanControllerRet = (MWQMPlanController)partialViewResult.ViewBag.MWQMPlanController;
                    Assert.IsNotNull(MWQMPlanControllerRet);

                    List <ContactModel> AdminContactModelListRet = (List <ContactModel>)partialViewResult.ViewBag.AdminContactModelList;
                    Assert.IsNull(AdminContactModelListRet); // because IsMWQMPlanner == true

                    bool IsMWQMPlannerRet = (bool)partialViewResult.ViewBag.IsMWQMPlanner;
                    Assert.IsTrue(IsMWQMPlannerRet);

                    List <LabSheetModelAndA1Sheet> LabSheetModelAndA1SheetListRet = (List <LabSheetModelAndA1Sheet>)partialViewResult.ViewBag.LabSheetModelAndA1SheetList;
                    Assert.IsTrue(LabSheetModelAndA1SheetListRet.Count > 0);

                    AnalyzeMethodEnum LastAnalyzeMethodRet = (AnalyzeMethodEnum)partialViewResult.ViewBag.LastAnalyzeMethod;
                    Assert.AreEqual(AnalyzeMethodEnum.Error, LastAnalyzeMethodRet);

                    SampleMatrixEnum LastSampleMatrixRet = (SampleMatrixEnum)partialViewResult.ViewBag.LastSampleMatrix;
                    Assert.AreEqual(SampleMatrixEnum.Error, LastSampleMatrixRet);

                    LaboratoryEnum LastLaboratoryRet = (LaboratoryEnum)partialViewResult.ViewBag.LastLaboratory;
                    Assert.AreEqual(LaboratoryEnum.Error, LastLaboratoryRet);
                }
            }
        }
        public IHttpActionResult GetLabSheetWithID([FromUri] int LabSheetID, [FromUri] string lang = "en", [FromUri] string extra = "")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                LabSheetService labSheetService = new LabSheetService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                labSheetService.Query = labSheetService.FillQuery(typeof(LabSheet), lang, 0, 1, "", "", extra);

                if (labSheetService.Query.Extra == "A")
                {
                    LabSheetExtraA labSheetExtraA = new LabSheetExtraA();
                    labSheetExtraA = labSheetService.GetLabSheetExtraAWithLabSheetID(LabSheetID);

                    if (labSheetExtraA == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(labSheetExtraA));
                }
                else if (labSheetService.Query.Extra == "B")
                {
                    LabSheetExtraB labSheetExtraB = new LabSheetExtraB();
                    labSheetExtraB = labSheetService.GetLabSheetExtraBWithLabSheetID(LabSheetID);

                    if (labSheetExtraB == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(labSheetExtraB));
                }
                else
                {
                    LabSheet labSheet = new LabSheet();
                    labSheet = labSheetService.GetLabSheetWithLabSheetID(LabSheetID);

                    if (labSheet == null)
                    {
                        return(NotFound());
                    }

                    return(Ok(labSheet));
                }
            }
        }
Exemplo n.º 5
0
        private string UpdateLabSheetStatusForOtherServerLabSheetID()
        {
            int OtherServerLabSheetID = -1;
            int TempInt = -10;
            LabSheetStatusEnum LabSheetStatus = LabSheetStatusEnum.Error;

            int.TryParse(Request.Params["OtherServerLabSheetID"], out OtherServerLabSheetID);
            if (OtherServerLabSheetID == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "OtherServerLabSheetID"));
            }

            int.TryParse(Request.Params["LabSheetStatus"], out TempInt);
            if (TempInt == -10)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "LabSheetStatus"));
            }

            LabSheetStatus = (LabSheetStatusEnum)TempInt;

            using (CSSPEntities db = new CSSPEntities())
            {
                LabSheet labSheet = (from c in db.LabSheets
                                     where c.OtherServerLabSheetID == OtherServerLabSheetID
                                     select c).FirstOrDefault();

                if (labSheet == null)
                {
                    return("NO");
                }
                else
                {
                    labSheet.LabSheetStatus = (int)LabSheetStatus;
                }

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(ex.Message + " ---- " + (ex.InnerException == null ? "" : ex.InnerException.Message));
                }
            }

            return("");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates an [LabSheet](CSSPModels.LabSheet.html) item in CSSPDB
        /// </summary>
        /// <param name="labSheet">Is the LabSheet item the client want to add to CSSPDB. What's important here is the LabSheetID</param>
        /// <returns>true if LabSheet item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        public bool Update(LabSheet labSheet)
        {
            labSheet.ValidationResults = Validate(new ValidationContext(labSheet), ActionDBTypeEnum.Update);
            if (labSheet.ValidationResults.Count() > 0)
            {
                return(false);
            }

            db.LabSheets.Update(labSheet);

            if (!TryToSave(labSheet))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Tries to execute the CSSPDB transaction (add/delete/update) on an [LabSheet](CSSPModels.LabSheet.html) item
        /// </summary>
        /// <param name="labSheet">Is the LabSheet item the client want to add to CSSPDB. What's important here is the LabSheetID</param>
        /// <returns>true if LabSheet item was updated to CSSPDB, false if an error happened during the DB requested transtaction</returns>
        private bool TryToSave(LabSheet labSheet)
        {
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                labSheet.ValidationResults = new List <ValidationResult>()
                {
                    new ValidationResult(ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""))
                }.AsEnumerable();
                return(false);
            }

            return(true);
        }
        public void LabSheet_Controller_GetLabSheetWithID_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    LabSheetController labSheetController = new LabSheetController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(labSheetController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, labSheetController.DatabaseType);

                    LabSheet labSheetFirst = new LabSheet();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        LabSheetService labSheetService = new LabSheetService(new Query(), db, ContactID);
                        labSheetFirst = (from c in db.LabSheets select c).FirstOrDefault();
                    }

                    // ok with LabSheet info
                    IHttpActionResult jsonRet = labSheetController.GetLabSheetWithID(labSheetFirst.LabSheetID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <LabSheet> Ret = jsonRet as OkNegotiatedContentResult <LabSheet>;
                    LabSheet labSheetRet = Ret.Content;
                    Assert.AreEqual(labSheetFirst.LabSheetID, labSheetRet.LabSheetID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Not Found
                    IHttpActionResult jsonRet2 = labSheetController.GetLabSheetWithID(0);
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <LabSheet> labSheetRet2 = jsonRet2 as OkNegotiatedContentResult <LabSheet>;
                    Assert.IsNull(labSheetRet2);

                    NotFoundResult notFoundRequest = jsonRet2 as NotFoundResult;
                    Assert.IsNotNull(notFoundRequest);
                }
            }
        }
        public IHttpActionResult Delete([FromBody] LabSheet labSheet, [FromUri] string lang = "en")
        {
            using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
            {
                LabSheetService labSheetService = new LabSheetService(new Query()
                {
                    Language = (lang == "fr" ? LanguageEnum.fr : LanguageEnum.en)
                }, db, ContactID);

                if (!labSheetService.Delete(labSheet))
                {
                    return(BadRequest(String.Join("|||", labSheet.ValidationResults)));
                }
                else
                {
                    labSheet.ValidationResults = null;
                    return(Ok(labSheet));
                }
            }
        }
Exemplo n.º 10
0
        public void LabSheetAndA1Sheet_Every_Property_Has_Get_Set_Test()
        {
            LabSheet val1 = new LabSheet();

            labSheetAndA1Sheet.LabSheet = val1;
            Assert.AreEqual(val1, labSheetAndA1Sheet.LabSheet);
            LabSheetA1Sheet val2 = new LabSheetA1Sheet();

            labSheetAndA1Sheet.LabSheetA1Sheet = val2;
            Assert.AreEqual(val2, labSheetAndA1Sheet.LabSheetA1Sheet);
            bool val3 = true;

            labSheetAndA1Sheet.HasErrors = val3;
            Assert.AreEqual(val3, labSheetAndA1Sheet.HasErrors);
            IEnumerable <ValidationResult> val12 = new List <ValidationResult>()
            {
                new ValidationResult("First CSSPError Message")
            }.AsEnumerable();

            labSheetAndA1Sheet.ValidationResults = val12;
            Assert.AreEqual(val12, labSheetAndA1Sheet.ValidationResults);
        }
Exemplo n.º 11
0
        private string GetNextAvailableLabSheet()
        {
            StringBuilder sb = new StringBuilder();

            using (CSSPEntities db = new CSSPEntities())
            {
                LabSheet labSheet = (from c in db.LabSheets
                                     where c.LabSheetStatus == (int)LabSheetStatusEnum.Created
                                     orderby c.FileLastModifiedDate_Local
                                     select c).FirstOrDefault();

                if (labSheet != null)
                {
                    sb.AppendLine("OtherServerLabSheetID|||||[" + labSheet.OtherServerLabSheetID + "]");
                    sb.AppendLine("SamplingPlanName|||||[" + labSheet.SamplingPlanName + "]");
                    sb.AppendLine("Year|||||[" + labSheet.Year + "]");
                    sb.AppendLine("Month|||||[" + labSheet.Month + "]");
                    sb.AppendLine("Day|||||[" + labSheet.Day + "]");
                    sb.AppendLine("RunNumber|||||[" + labSheet.RunNumber + "]");
                    sb.AppendLine("SubsectorTVItemID|||||[" + labSheet.SubsectorTVItemID + "]");
                    sb.AppendLine("SamplingPlanType|||||[" + labSheet.SamplingPlanType + "]");
                    sb.AppendLine("SampleType|||||[" + labSheet.SampleType + "]");
                    sb.AppendLine("LabSheetType|||||[" + labSheet.LabSheetType + "]");
                    sb.AppendLine("LabSheetStatus|||||[" + labSheet.LabSheetStatus + "]");
                    sb.AppendLine("FileName|||||[" + labSheet.FileName + "]");
                    sb.AppendLine("FileLastModifiedDate_Local|||||["
                                  + labSheet.FileLastModifiedDate_Local.Year + ","
                                  + labSheet.FileLastModifiedDate_Local.Month + ","
                                  + labSheet.FileLastModifiedDate_Local.Day + ","
                                  + labSheet.FileLastModifiedDate_Local.Hour + ","
                                  + labSheet.FileLastModifiedDate_Local.Minute + ","
                                  + labSheet.FileLastModifiedDate_Local.Second + ","
                                  + "]");
                    sb.AppendLine("FileContent|||||[" + labSheet.FileContent + "]");
                }
            }

            return(sb.ToString());
        }
        public void LabSheet_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    LabSheetController labSheetController = new LabSheetController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(labSheetController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, labSheetController.DatabaseType);

                    LabSheet labSheetLast = new LabSheet();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        LabSheetService labSheetService = new LabSheetService(query, db, ContactID);
                        labSheetLast = (from c in db.LabSheets select c).FirstOrDefault();
                    }

                    // ok with LabSheet info
                    IHttpActionResult jsonRet = labSheetController.GetLabSheetWithID(labSheetLast.LabSheetID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <LabSheet> Ret = jsonRet as OkNegotiatedContentResult <LabSheet>;
                    LabSheet labSheetRet = Ret.Content;
                    Assert.AreEqual(labSheetLast.LabSheetID, labSheetRet.LabSheetID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Post to return CSSPError because LabSheetID exist
                    IHttpActionResult jsonRet2 = labSheetController.Post(labSheetRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <LabSheet> labSheetRet2 = jsonRet2 as OkNegotiatedContentResult <LabSheet>;
                    Assert.IsNull(labSheetRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest2);

                    // Post to return newly added LabSheet
                    labSheetRet.LabSheetID                = 0;
                    labSheetController.Request            = new System.Net.Http.HttpRequestMessage();
                    labSheetController.Request.RequestUri = new System.Uri("http://localhost:5000/api/labSheet");
                    IHttpActionResult jsonRet3 = labSheetController.Post(labSheetRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <LabSheet> labSheetRet3 = jsonRet3 as CreatedNegotiatedContentResult <LabSheet>;
                    Assert.IsNotNull(labSheetRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    IHttpActionResult jsonRet4 = labSheetController.Delete(labSheetRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <LabSheet> labSheetRet4 = jsonRet4 as OkNegotiatedContentResult <LabSheet>;
                    Assert.IsNotNull(labSheetRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
Exemplo n.º 13
0
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string         retStr         = "";
            Enums          enums          = new Enums(LanguageRequest);
            LabSheetDetail labSheetDetail = validationContext.ObjectInstance as LabSheetDetail;

            labSheetDetail.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (labSheetDetail.LabSheetDetailID == 0)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetDetailID"), new[] { "LabSheetDetailID" }));
                }

                if (!(from c in db.LabSheetDetails select c).Where(c => c.LabSheetDetailID == labSheetDetail.LabSheetDetailID).Any())
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "LabSheetDetail", "LabSheetDetailID", labSheetDetail.LabSheetDetailID.ToString()), new[] { "LabSheetDetailID" }));
                }
            }

            LabSheet LabSheetLabSheetID = (from c in db.LabSheets where c.LabSheetID == labSheetDetail.LabSheetID select c).FirstOrDefault();

            if (LabSheetLabSheetID == null)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "LabSheet", "LabSheetID", labSheetDetail.LabSheetID.ToString()), new[] { "LabSheetID" }));
            }

            SamplingPlan SamplingPlanSamplingPlanID = (from c in db.SamplingPlans where c.SamplingPlanID == labSheetDetail.SamplingPlanID select c).FirstOrDefault();

            if (SamplingPlanSamplingPlanID == null)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", labSheetDetail.SamplingPlanID.ToString()), new[] { "SamplingPlanID" }));
            }

            TVItem TVItemSubsectorTVItemID = (from c in db.TVItems where c.TVItemID == labSheetDetail.SubsectorTVItemID select c).FirstOrDefault();

            if (TVItemSubsectorTVItemID == null)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SubsectorTVItemID", labSheetDetail.SubsectorTVItemID.ToString()), new[] { "SubsectorTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Subsector,
                };
                if (!AllowableTVTypes.Contains(TVItemSubsectorTVItemID.TVType))
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "SubsectorTVItemID", "Subsector"), new[] { "SubsectorTVItemID" }));
                }
            }

            if (labSheetDetail.Version < 1 || labSheetDetail.Version > 5)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Version", "1", "5"), new[] { "Version" }));
            }

            if (labSheetDetail.RunDate.Year == 1)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "RunDate"), new[] { "RunDate" }));
            }
            else
            {
                if (labSheetDetail.RunDate.Year < 1980)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "RunDate", "1980"), new[] { "RunDate" }));
                }
            }

            if (string.IsNullOrWhiteSpace(labSheetDetail.Tides))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "Tides"), new[] { "Tides" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Tides) && (labSheetDetail.Tides.Length < 1 || labSheetDetail.Tides.Length > 7))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Tides", "1", "7"), new[] { "Tides" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.SampleCrewInitials) && labSheetDetail.SampleCrewInitials.Length > 20)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SampleCrewInitials", "20"), new[] { "SampleCrewInitials" }));
            }

            if (labSheetDetail.WaterBathCount != null)
            {
                if (labSheetDetail.WaterBathCount < 1 || labSheetDetail.WaterBathCount > 3)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "WaterBathCount", "1", "3"), new[] { "WaterBathCount" }));
                }
            }

            if (labSheetDetail.IncubationBath1StartTime != null && ((DateTime)labSheetDetail.IncubationBath1StartTime).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath1StartTime", "1980"), new[] { "IncubationBath1StartTime" }));
            }

            if (labSheetDetail.IncubationBath2StartTime != null && ((DateTime)labSheetDetail.IncubationBath2StartTime).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath2StartTime", "1980"), new[] { "IncubationBath2StartTime" }));
            }

            if (labSheetDetail.IncubationBath3StartTime != null && ((DateTime)labSheetDetail.IncubationBath3StartTime).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath3StartTime", "1980"), new[] { "IncubationBath3StartTime" }));
            }

            if (labSheetDetail.IncubationBath1EndTime != null && ((DateTime)labSheetDetail.IncubationBath1EndTime).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath1EndTime", "1980"), new[] { "IncubationBath1EndTime" }));
            }

            if (labSheetDetail.IncubationBath2EndTime != null && ((DateTime)labSheetDetail.IncubationBath2EndTime).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath2EndTime", "1980"), new[] { "IncubationBath2EndTime" }));
            }

            if (labSheetDetail.IncubationBath3EndTime != null && ((DateTime)labSheetDetail.IncubationBath3EndTime).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "IncubationBath3EndTime", "1980"), new[] { "IncubationBath3EndTime" }));
            }

            if (labSheetDetail.IncubationBath1TimeCalculated_minutes != null)
            {
                if (labSheetDetail.IncubationBath1TimeCalculated_minutes < 0 || labSheetDetail.IncubationBath1TimeCalculated_minutes > 10000)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IncubationBath1TimeCalculated_minutes", "0", "10000"), new[] { "IncubationBath1TimeCalculated_minutes" }));
                }
            }

            if (labSheetDetail.IncubationBath2TimeCalculated_minutes != null)
            {
                if (labSheetDetail.IncubationBath2TimeCalculated_minutes < 0 || labSheetDetail.IncubationBath2TimeCalculated_minutes > 10000)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IncubationBath2TimeCalculated_minutes", "0", "10000"), new[] { "IncubationBath2TimeCalculated_minutes" }));
                }
            }

            if (labSheetDetail.IncubationBath3TimeCalculated_minutes != null)
            {
                if (labSheetDetail.IncubationBath3TimeCalculated_minutes < 0 || labSheetDetail.IncubationBath3TimeCalculated_minutes > 10000)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IncubationBath3TimeCalculated_minutes", "0", "10000"), new[] { "IncubationBath3TimeCalculated_minutes" }));
                }
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.WaterBath1) && labSheetDetail.WaterBath1.Length > 10)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "WaterBath1", "10"), new[] { "WaterBath1" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.WaterBath2) && labSheetDetail.WaterBath2.Length > 10)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "WaterBath2", "10"), new[] { "WaterBath2" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.WaterBath3) && labSheetDetail.WaterBath3.Length > 10)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "WaterBath3", "10"), new[] { "WaterBath3" }));
            }

            if (labSheetDetail.TCField1 != null)
            {
                if (labSheetDetail.TCField1 < -10 || labSheetDetail.TCField1 > 40)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCField1", "-10", "40"), new[] { "TCField1" }));
                }
            }

            if (labSheetDetail.TCLab1 != null)
            {
                if (labSheetDetail.TCLab1 < -10 || labSheetDetail.TCLab1 > 40)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCLab1", "-10", "40"), new[] { "TCLab1" }));
                }
            }

            if (labSheetDetail.TCField2 != null)
            {
                if (labSheetDetail.TCField2 < -10 || labSheetDetail.TCField2 > 40)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCField2", "-10", "40"), new[] { "TCField2" }));
                }
            }

            if (labSheetDetail.TCLab2 != null)
            {
                if (labSheetDetail.TCLab2 < -10 || labSheetDetail.TCLab2 > 40)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCLab2", "-10", "40"), new[] { "TCLab2" }));
                }
            }

            if (labSheetDetail.TCFirst != null)
            {
                if (labSheetDetail.TCFirst < -10 || labSheetDetail.TCFirst > 40)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCFirst", "-10", "40"), new[] { "TCFirst" }));
                }
            }

            if (labSheetDetail.TCAverage != null)
            {
                if (labSheetDetail.TCAverage < -10 || labSheetDetail.TCAverage > 40)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "TCAverage", "-10", "40"), new[] { "TCAverage" }));
                }
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.ControlLot) && labSheetDetail.ControlLot.Length > 100)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ControlLot", "100"), new[] { "ControlLot" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Positive35) && (labSheetDetail.Positive35.Length < 1 || labSheetDetail.Positive35.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Positive35", "1", "1"), new[] { "Positive35" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.NonTarget35) && (labSheetDetail.NonTarget35.Length < 1 || labSheetDetail.NonTarget35.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "NonTarget35", "1", "1"), new[] { "NonTarget35" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Negative35) && (labSheetDetail.Negative35.Length < 1 || labSheetDetail.Negative35.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Negative35", "1", "1"), new[] { "Negative35" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1Positive44_5) && (labSheetDetail.Bath1Positive44_5.Length < 1 || labSheetDetail.Bath1Positive44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1Positive44_5", "1", "1"), new[] { "Bath1Positive44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2Positive44_5) && (labSheetDetail.Bath2Positive44_5.Length < 1 || labSheetDetail.Bath2Positive44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2Positive44_5", "1", "1"), new[] { "Bath2Positive44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3Positive44_5) && (labSheetDetail.Bath3Positive44_5.Length < 1 || labSheetDetail.Bath3Positive44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3Positive44_5", "1", "1"), new[] { "Bath3Positive44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1NonTarget44_5) && (labSheetDetail.Bath1NonTarget44_5.Length < 1 || labSheetDetail.Bath1NonTarget44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1NonTarget44_5", "1", "1"), new[] { "Bath1NonTarget44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2NonTarget44_5) && (labSheetDetail.Bath2NonTarget44_5.Length < 1 || labSheetDetail.Bath2NonTarget44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2NonTarget44_5", "1", "1"), new[] { "Bath2NonTarget44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3NonTarget44_5) && (labSheetDetail.Bath3NonTarget44_5.Length < 1 || labSheetDetail.Bath3NonTarget44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3NonTarget44_5", "1", "1"), new[] { "Bath3NonTarget44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1Negative44_5) && (labSheetDetail.Bath1Negative44_5.Length < 1 || labSheetDetail.Bath1Negative44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1Negative44_5", "1", "1"), new[] { "Bath1Negative44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2Negative44_5) && (labSheetDetail.Bath2Negative44_5.Length < 1 || labSheetDetail.Bath2Negative44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2Negative44_5", "1", "1"), new[] { "Bath2Negative44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3Negative44_5) && (labSheetDetail.Bath3Negative44_5.Length < 1 || labSheetDetail.Bath3Negative44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3Negative44_5", "1", "1"), new[] { "Bath3Negative44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Blank35) && (labSheetDetail.Blank35.Length < 1 || labSheetDetail.Blank35.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Blank35", "1", "1"), new[] { "Blank35" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath1Blank44_5) && (labSheetDetail.Bath1Blank44_5.Length < 1 || labSheetDetail.Bath1Blank44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath1Blank44_5", "1", "1"), new[] { "Bath1Blank44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath2Blank44_5) && (labSheetDetail.Bath2Blank44_5.Length < 1 || labSheetDetail.Bath2Blank44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath2Blank44_5", "1", "1"), new[] { "Bath2Blank44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Bath3Blank44_5) && (labSheetDetail.Bath3Blank44_5.Length < 1 || labSheetDetail.Bath3Blank44_5.Length > 1))
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "Bath3Blank44_5", "1", "1"), new[] { "Bath3Blank44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Lot35) && labSheetDetail.Lot35.Length > 20)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Lot35", "20"), new[] { "Lot35" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Lot44_5) && labSheetDetail.Lot44_5.Length > 20)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Lot44_5", "20"), new[] { "Lot44_5" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.Weather) && labSheetDetail.Weather.Length > 250)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "Weather", "250"), new[] { "Weather" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.RunComment) && labSheetDetail.RunComment.Length > 250)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "RunComment", "250"), new[] { "RunComment" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.RunWeatherComment) && labSheetDetail.RunWeatherComment.Length > 250)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "RunWeatherComment", "250"), new[] { "RunWeatherComment" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.SampleBottleLotNumber) && labSheetDetail.SampleBottleLotNumber.Length > 20)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SampleBottleLotNumber", "20"), new[] { "SampleBottleLotNumber" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.SalinitiesReadBy) && labSheetDetail.SalinitiesReadBy.Length > 20)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "SalinitiesReadBy", "20"), new[] { "SalinitiesReadBy" }));
            }

            if (labSheetDetail.SalinitiesReadDate != null && ((DateTime)labSheetDetail.SalinitiesReadDate).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "SalinitiesReadDate", "1980"), new[] { "SalinitiesReadDate" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.ResultsReadBy) && labSheetDetail.ResultsReadBy.Length > 20)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ResultsReadBy", "20"), new[] { "ResultsReadBy" }));
            }

            if (labSheetDetail.ResultsReadDate != null && ((DateTime)labSheetDetail.ResultsReadDate).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "ResultsReadDate", "1980"), new[] { "ResultsReadDate" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheetDetail.ResultsRecordedBy) && labSheetDetail.ResultsRecordedBy.Length > 20)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "ResultsRecordedBy", "20"), new[] { "ResultsRecordedBy" }));
            }

            if (labSheetDetail.ResultsRecordedDate != null && ((DateTime)labSheetDetail.ResultsRecordedDate).Year < 1980)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "ResultsRecordedDate", "1980"), new[] { "ResultsRecordedDate" }));
            }

            if (labSheetDetail.DailyDuplicateRLog != null)
            {
                if (labSheetDetail.DailyDuplicateRLog < 0 || labSheetDetail.DailyDuplicateRLog > 100)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DailyDuplicateRLog", "0", "100"), new[] { "DailyDuplicateRLog" }));
                }
            }

            if (labSheetDetail.DailyDuplicatePrecisionCriteria != null)
            {
                if (labSheetDetail.DailyDuplicatePrecisionCriteria < 0 || labSheetDetail.DailyDuplicatePrecisionCriteria > 100)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "DailyDuplicatePrecisionCriteria", "0", "100"), new[] { "DailyDuplicatePrecisionCriteria" }));
                }
            }

            if (labSheetDetail.IntertechDuplicateRLog != null)
            {
                if (labSheetDetail.IntertechDuplicateRLog < 0 || labSheetDetail.IntertechDuplicateRLog > 100)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IntertechDuplicateRLog", "0", "100"), new[] { "IntertechDuplicateRLog" }));
                }
            }

            if (labSheetDetail.IntertechDuplicatePrecisionCriteria != null)
            {
                if (labSheetDetail.IntertechDuplicatePrecisionCriteria < 0 || labSheetDetail.IntertechDuplicatePrecisionCriteria > 100)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "IntertechDuplicatePrecisionCriteria", "0", "100"), new[] { "IntertechDuplicatePrecisionCriteria" }));
                }
            }

            if (labSheetDetail.LastUpdateDate_UTC.Year == 1)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (labSheetDetail.LastUpdateDate_UTC.Year < 1980)
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == labSheetDetail.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", labSheetDetail.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    labSheetDetail.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                labSheetDetail.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Validate function for all LabSheetService commands
        /// </summary>
        /// <param name="validationContext">System.ComponentModel.DataAnnotations.ValidationContext (Describes the context in which a validation check is performed.)</param>
        /// <param name="actionDBType">[ActionDBTypeEnum] (CSSPEnums.ActionDBTypeEnum.html) action type to validate</param>
        /// <returns>IEnumerable of ValidationResult (Where ValidationResult is a container for the results of a validation request.)</returns>
        private IEnumerable <ValidationResult> Validate(ValidationContext validationContext, ActionDBTypeEnum actionDBType)
        {
            string   retStr   = "";
            Enums    enums    = new Enums(LanguageRequest);
            LabSheet labSheet = validationContext.ObjectInstance as LabSheet;

            labSheet.HasErrors = false;

            if (actionDBType == ActionDBTypeEnum.Update || actionDBType == ActionDBTypeEnum.Delete)
            {
                if (labSheet.LabSheetID == 0)
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetID"), new[] { "LabSheetID" }));
                }

                if (!(from c in db.LabSheets select c).Where(c => c.LabSheetID == labSheet.LabSheetID).Any())
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "LabSheet", "LabSheetID", labSheet.LabSheetID.ToString()), new[] { "LabSheetID" }));
                }
            }

            if (labSheet.OtherServerLabSheetID < 1)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MinValueIs_, "OtherServerLabSheetID", "1"), new[] { "OtherServerLabSheetID" }));
            }

            SamplingPlan SamplingPlanSamplingPlanID = (from c in db.SamplingPlans where c.SamplingPlanID == labSheet.SamplingPlanID select c).FirstOrDefault();

            if (SamplingPlanSamplingPlanID == null)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "SamplingPlan", "SamplingPlanID", labSheet.SamplingPlanID.ToString()), new[] { "SamplingPlanID" }));
            }

            if (string.IsNullOrWhiteSpace(labSheet.SamplingPlanName))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanName"), new[] { "SamplingPlanName" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheet.SamplingPlanName) && (labSheet.SamplingPlanName.Length < 1 || labSheet.SamplingPlanName.Length > 250))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "SamplingPlanName", "1", "250"), new[] { "SamplingPlanName" }));
            }

            if (labSheet.Year < 1980)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MinValueIs_, "Year", "1980"), new[] { "Year" }));
            }

            if (labSheet.Month < 1 || labSheet.Month > 12)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Month", "1", "12"), new[] { "Month" }));
            }

            if (labSheet.Day < 1 || labSheet.Day > 31)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "Day", "1", "31"), new[] { "Day" }));
            }

            if (labSheet.RunNumber < 1 || labSheet.RunNumber > 100)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._ValueShouldBeBetween_And_, "RunNumber", "1", "100"), new[] { "RunNumber" }));
            }

            TVItem TVItemSubsectorTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.SubsectorTVItemID select c).FirstOrDefault();

            if (TVItemSubsectorTVItemID == null)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "SubsectorTVItemID", labSheet.SubsectorTVItemID.ToString()), new[] { "SubsectorTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Subsector,
                };
                if (!AllowableTVTypes.Contains(TVItemSubsectorTVItemID.TVType))
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "SubsectorTVItemID", "Subsector"), new[] { "SubsectorTVItemID" }));
                }
            }

            if (labSheet.MWQMRunTVItemID != null)
            {
                TVItem TVItemMWQMRunTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.MWQMRunTVItemID select c).FirstOrDefault();

                if (TVItemMWQMRunTVItemID == null)
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "MWQMRunTVItemID", (labSheet.MWQMRunTVItemID == null ? "" : labSheet.MWQMRunTVItemID.ToString())), new[] { "MWQMRunTVItemID" }));
                }
                else
                {
                    List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                    {
                        TVTypeEnum.MWQMRun,
                    };
                    if (!AllowableTVTypes.Contains(TVItemMWQMRunTVItemID.TVType))
                    {
                        labSheet.HasErrors = true;
                        yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "MWQMRunTVItemID", "MWQMRun"), new[] { "MWQMRunTVItemID" }));
                    }
                }
            }

            retStr = enums.EnumTypeOK(typeof(SamplingPlanTypeEnum), (int?)labSheet.SamplingPlanType);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SamplingPlanType"), new[] { "SamplingPlanType" }));
            }

            retStr = enums.EnumTypeOK(typeof(SampleTypeEnum), (int?)labSheet.SampleType);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "SampleType"), new[] { "SampleType" }));
            }

            retStr = enums.EnumTypeOK(typeof(LabSheetTypeEnum), (int?)labSheet.LabSheetType);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetType"), new[] { "LabSheetType" }));
            }

            retStr = enums.EnumTypeOK(typeof(LabSheetStatusEnum), (int?)labSheet.LabSheetStatus);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LabSheetStatus"), new[] { "LabSheetStatus" }));
            }

            if (string.IsNullOrWhiteSpace(labSheet.FileName))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FileName"), new[] { "FileName" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheet.FileName) && (labSheet.FileName.Length < 1 || labSheet.FileName.Length > 250))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._LengthShouldBeBetween_And_, "FileName", "1", "250"), new[] { "FileName" }));
            }

            if (labSheet.FileLastModifiedDate_Local.Year == 1)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FileLastModifiedDate_Local"), new[] { "FileLastModifiedDate_Local" }));
            }
            else
            {
                if (labSheet.FileLastModifiedDate_Local.Year < 1980)
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "FileLastModifiedDate_Local", "1980"), new[] { "FileLastModifiedDate_Local" }));
                }
            }

            if (string.IsNullOrWhiteSpace(labSheet.FileContent))
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "FileContent"), new[] { "FileContent" }));
            }

            //FileContent has no StringLength Attribute

            if (labSheet.AcceptedOrRejectedByContactTVItemID != null)
            {
                TVItem TVItemAcceptedOrRejectedByContactTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.AcceptedOrRejectedByContactTVItemID select c).FirstOrDefault();

                if (TVItemAcceptedOrRejectedByContactTVItemID == null)
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "AcceptedOrRejectedByContactTVItemID", (labSheet.AcceptedOrRejectedByContactTVItemID == null ? "" : labSheet.AcceptedOrRejectedByContactTVItemID.ToString())), new[] { "AcceptedOrRejectedByContactTVItemID" }));
                }
                else
                {
                    List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                    {
                        TVTypeEnum.Contact,
                    };
                    if (!AllowableTVTypes.Contains(TVItemAcceptedOrRejectedByContactTVItemID.TVType))
                    {
                        labSheet.HasErrors = true;
                        yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "AcceptedOrRejectedByContactTVItemID", "Contact"), new[] { "AcceptedOrRejectedByContactTVItemID" }));
                    }
                }
            }

            if (labSheet.AcceptedOrRejectedDateTime != null && ((DateTime)labSheet.AcceptedOrRejectedDateTime).Year < 1980)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "AcceptedOrRejectedDateTime", "1980"), new[] { "AcceptedOrRejectedDateTime" }));
            }

            if (!string.IsNullOrWhiteSpace(labSheet.RejectReason) && labSheet.RejectReason.Length > 250)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._MaxLengthIs_, "RejectReason", "250"), new[] { "RejectReason" }));
            }

            if (labSheet.LastUpdateDate_UTC.Year == 1)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes._IsRequired, "LastUpdateDate_UTC"), new[] { "LastUpdateDate_UTC" }));
            }
            else
            {
                if (labSheet.LastUpdateDate_UTC.Year < 1980)
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._YearShouldBeBiggerThan_, "LastUpdateDate_UTC", "1980"), new[] { "LastUpdateDate_UTC" }));
                }
            }

            TVItem TVItemLastUpdateContactTVItemID = (from c in db.TVItems where c.TVItemID == labSheet.LastUpdateContactTVItemID select c).FirstOrDefault();

            if (TVItemLastUpdateContactTVItemID == null)
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult(string.Format(CSSPServicesRes.CouldNotFind_With_Equal_, "TVItem", "LastUpdateContactTVItemID", labSheet.LastUpdateContactTVItemID.ToString()), new[] { "LastUpdateContactTVItemID" }));
            }
            else
            {
                List <TVTypeEnum> AllowableTVTypes = new List <TVTypeEnum>()
                {
                    TVTypeEnum.Contact,
                };
                if (!AllowableTVTypes.Contains(TVItemLastUpdateContactTVItemID.TVType))
                {
                    labSheet.HasErrors = true;
                    yield return(new ValidationResult(string.Format(CSSPServicesRes._IsNotOfType_, "LastUpdateContactTVItemID", "Contact"), new[] { "LastUpdateContactTVItemID" }));
                }
            }

            retStr = "";      // added to stop compiling CSSPError
            if (retStr != "") // will never be true
            {
                labSheet.HasErrors = true;
                yield return(new ValidationResult("AAA", new[] { "AAA" }));
            }
        }
        public void LabSheet_Controller_GetLabSheetList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    LabSheetController labSheetController = new LabSheetController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(labSheetController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, labSheetController.DatabaseType);

                    LabSheet labSheetFirst = new LabSheet();
                    int      count         = -1;
                    Query    query         = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        LabSheetService labSheetService = new LabSheetService(query, db, ContactID);
                        labSheetFirst = (from c in db.LabSheets select c).FirstOrDefault();
                        count         = (from c in db.LabSheets select c).Count();
                        count         = (query.Take > count ? count : query.Take);
                    }

                    // ok with LabSheet info
                    IHttpActionResult jsonRet = labSheetController.GetLabSheetList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <LabSheet> > ret = jsonRet as OkNegotiatedContentResult <List <LabSheet> >;
                    Assert.AreEqual(labSheetFirst.LabSheetID, ret.Content[0].LabSheetID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <LabSheet> labSheetList = new List <LabSheet>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        LabSheetService labSheetService = new LabSheetService(query, db, ContactID);
                        labSheetList = (from c in db.LabSheets select c).OrderBy(c => c.LabSheetID).Skip(0).Take(2).ToList();
                        count        = (from c in db.LabSheets select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with LabSheet info
                        jsonRet = labSheetController.GetLabSheetList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <LabSheet> >;
                        Assert.AreEqual(labSheetList[0].LabSheetID, ret.Content[0].LabSheetID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with LabSheet info
                            IHttpActionResult jsonRet2 = labSheetController.GetLabSheetList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <LabSheet> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <LabSheet> >;
                            Assert.AreEqual(labSheetList[1].LabSheetID, ret2.Content[0].LabSheetID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
 public LabSheetTest()
 {
     labSheet       = new LabSheet();
     labSheetExtraA = new LabSheetExtraA();
     labSheetExtraB = new LabSheetExtraB();
 }
Exemplo n.º 17
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;
            }
        }
Exemplo n.º 18
0
        private string GetterLabSheetAcceptedOrRejectedBy()
        {
            int                  tempInt          = -1;
            string               SamplingPlanName = "";
            int                  Year             = -1;
            int                  Month            = -1;
            int                  Day                        = -1;
            int                  RunNumber                  = -1;
            int                  SubsectorTVItemID          = -1;
            DateTime             SampleDate_Local           = new DateTime(2050, 1, 1);
            SamplingPlanTypeEnum SamplingPlanType           = SamplingPlanTypeEnum.Error;
            SampleTypeEnum       SampleType                 = SampleTypeEnum.Error;
            LabSheetTypeEnum     LabSheetType               = LabSheetTypeEnum.Error;
            DateTime             FileLastModifiedDate_Local = new DateTime(2050, 1, 1);
            StringBuilder        sb = new StringBuilder();

            SamplingPlanName = Request.Params["SamplingPlanName"];
            if (string.IsNullOrWhiteSpace(SamplingPlanName))
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SamplingPlanName"));
            }

            int.TryParse(Request.Params["Year"], out Year);
            if (Year == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Year"));
            }

            int.TryParse(Request.Params["Month"], out Month);
            if (Month == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Month"));
            }

            int.TryParse(Request.Params["Day"], out Day);
            if (Day == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Day"));
            }

            int.TryParse(Request.Params["RunNumber"], out RunNumber);
            if (RunNumber == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "RunNumber"));
            }

            int.TryParse(Request.Params["SubsectorTVItemID"], out SubsectorTVItemID);
            if (SubsectorTVItemID == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SubsectorTVItemID"));
            }

            int.TryParse(Request.Params["SamplingPlanType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SamplingPlanType"));
            }
            SamplingPlanType = (SamplingPlanTypeEnum)tempInt;

            int.TryParse(Request.Params["SampleType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SampleType"));
            }
            SampleType = (SampleTypeEnum)tempInt;

            int.TryParse(Request.Params["LabSheetType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "LabSheetType"));
            }
            LabSheetType = (LabSheetTypeEnum)tempInt;

            using (CSSPEntities db = new CSSPEntities())
            {
                LabSheet labSheet = (from c in db.LabSheets
                                     where c.SamplingPlanName == SamplingPlanName &&
                                     c.Year == Year &&
                                     c.Month == Month &&
                                     c.Day == Day &&
                                     c.RunNumber == RunNumber &&
                                     c.SubsectorTVItemID == SubsectorTVItemID &&
                                     c.SamplingPlanType == (int)SamplingPlanType &&
                                     c.SampleType == (int)SampleType &&
                                     c.LabSheetType == (int)LabSheetType
                                     select c).FirstOrDefault();

                if (labSheet != null)
                {
                    sb.AppendLine("OtherServerLabSheetID|||||[" + labSheet.OtherServerLabSheetID + "]");
                    sb.AppendLine("AcceptedOrRejectedBy|||||[" + labSheet.AcceptedOrRejectedBy + "]");
                    sb.AppendLine("Year|||||[" + labSheet.AcceptedOrRejectedDate_Local.Value.Year + "]");
                    sb.AppendLine("Month|||||[" + labSheet.AcceptedOrRejectedDate_Local.Value.Month + "]");
                    sb.AppendLine("Day|||||[" + labSheet.AcceptedOrRejectedDate_Local.Value.Day + "]");
                    sb.AppendLine("Hour|||||[" + labSheet.AcceptedOrRejectedDate_Local.Value.Hour + "]");
                    sb.AppendLine("Minute|||||[" + labSheet.AcceptedOrRejectedDate_Local.Value.Minute + "]");
                    sb.AppendLine("RejectReason|||||[" + labSheet.RejectReason + "]");
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 19
0
        private string DoesLabSheetExist()
        {
            int                  tempInt          = -1;
            string               SamplingPlanName = "";
            int                  Year             = -1;
            int                  Month            = -1;
            int                  Day                        = -1;
            int                  RunNumber                  = -1;
            int                  SubsectorTVItemID          = -1;
            DateTime             SampleDate_Local           = new DateTime(2050, 1, 1);
            SamplingPlanTypeEnum SamplingPlanType           = SamplingPlanTypeEnum.Error;
            SampleTypeEnum       SampleType                 = SampleTypeEnum.Error;
            LabSheetTypeEnum     LabSheetType               = LabSheetTypeEnum.Error;
            DateTime             FileLastModifiedDate_Local = new DateTime(2050, 1, 1);

            SamplingPlanName = Request.Params["SamplingPlanName"];
            if (string.IsNullOrWhiteSpace(SamplingPlanName))
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SamplingPlanName"));
            }

            int.TryParse(Request.Params["Year"], out Year);
            if (Year == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Year"));
            }

            int.TryParse(Request.Params["Month"], out Month);
            if (Month == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Month"));
            }

            int.TryParse(Request.Params["Day"], out Day);
            if (Day == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Day"));
            }

            int.TryParse(Request.Params["RunNumber"], out RunNumber);
            if (RunNumber == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "RunNumber"));
            }

            int.TryParse(Request.Params["SubsectorTVItemID"], out SubsectorTVItemID);
            if (SubsectorTVItemID == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SubsectorTVItemID"));
            }

            int.TryParse(Request.Params["SamplingPlanType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SamplingPlanType"));
            }
            SamplingPlanType = (SamplingPlanTypeEnum)tempInt;

            int.TryParse(Request.Params["SampleType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SampleType"));
            }
            SampleType = (SampleTypeEnum)tempInt;

            int.TryParse(Request.Params["LabSheetType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "LabSheetType"));
            }
            LabSheetType = (LabSheetTypeEnum)tempInt;

            using (CSSPEntities db = new CSSPEntities())
            {
                LabSheet labSheet = (from c in db.LabSheets
                                     where c.SamplingPlanName == SamplingPlanName &&
                                     c.Year == Year &&
                                     c.Month == Month &&
                                     c.Day == Day &&
                                     c.RunNumber == RunNumber &&
                                     c.SubsectorTVItemID == SubsectorTVItemID &&
                                     c.SamplingPlanType == (int)SamplingPlanType &&
                                     c.SampleType == (int)SampleType &&
                                     c.LabSheetType == (int)LabSheetType
                                     select c).FirstOrDefault();

                if (labSheet == null)
                {
                    return("[" + ((int)LabSheetStatusEnum.Error).ToString() + "]");
                }
                else
                {
                    return("[" + labSheet.LabSheetStatus.ToString() + "]");
                }
            }
        }
Exemplo n.º 20
0
        private string FillLabSheet()
        {
            int    tempInt          = -1;
            string SamplingPlanName = "";
            int    Year             = -1;
            int    Month            = -1;
            int    Day               = -1;
            int    RunNumber         = -1;
            int    SubsectorTVItemID = -1;
            SamplingPlanTypeEnum SamplingPlanType = SamplingPlanTypeEnum.Error;
            SampleTypeEnum       SampleType       = SampleTypeEnum.Error;
            LabSheetTypeEnum     LabSheetType     = LabSheetTypeEnum.Error;
            string   FileName = "";
            string   FileLastModifiedDate_LocalText = "";
            DateTime FileLastModifiedDate_Local     = new DateTime(2050, 1, 1);
            string   FileContent = "";

            SamplingPlanName = Request.Params["SamplingPlanName"];
            if (string.IsNullOrWhiteSpace(SamplingPlanName))
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SamplingPlanName"));
            }

            int.TryParse(Request.Params["Year"], out Year);
            if (Year == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Year"));
            }

            int.TryParse(Request.Params["Month"], out Month);
            if (Month == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Month"));
            }

            int.TryParse(Request.Params["Day"], out Day);
            if (Day == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "Day"));
            }

            int.TryParse(Request.Params["RunNumber"], out RunNumber);
            if (RunNumber == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "RunNumber"));
            }

            int.TryParse(Request.Params["SubsectorTVItemID"], out SubsectorTVItemID);
            if (SubsectorTVItemID == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SubsectorTVItemID"));
            }

            int.TryParse(Request.Params["SamplingPlanType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SamplingPlanType"));
            }
            SamplingPlanType = (SamplingPlanTypeEnum)tempInt;

            int.TryParse(Request.Params["SampleType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "SampleType"));
            }
            SampleType = (SampleTypeEnum)tempInt;

            int.TryParse(Request.Params["LabSheetType"], out tempInt);
            if (tempInt == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "LabSheetType"));
            }
            LabSheetType = (LabSheetTypeEnum)tempInt;

            FileName = Request.Params["FileName"];
            if (string.IsNullOrWhiteSpace(FileName))
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileName"));
            }

            if (FileName.EndsWith("_S.txt"))
            {
                return(LabSheetViewRes.OnlyLabSheetEndingWithStxtIsAllowed);
            }

            FileLastModifiedDate_LocalText = Request.Params["FileLastModifiedDate_Local"];
            List <string> stringList = FileLastModifiedDate_LocalText.Split(",".ToCharArray(), StringSplitOptions.None).ToList();
            int           FileYear   = -1;

            int.TryParse(stringList[0], out FileYear);
            if (FileYear == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileLastModifiedDate_Local Year not valid"));
            }

            int FileMonth = -1;

            int.TryParse(stringList[1], out FileMonth);
            if (FileMonth == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileLastModifiedDate_Local Month not valid"));
            }

            int FileDay = -1;

            int.TryParse(stringList[2], out FileDay);
            if (FileDay == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileLastModifiedDate_Local Day not valid"));
            }

            int FileHour = -1;

            int.TryParse(stringList[3], out FileHour);
            if (FileHour == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileLastModifiedDate_Local Hour not valid"));
            }

            int FileMinute = -1;

            int.TryParse(stringList[4], out FileMinute);
            if (FileMinute == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileLastModifiedDate_Local Minute not valid"));
            }

            int FileSecond = -1;

            int.TryParse(stringList[5], out FileSecond);
            if (FileSecond == -1)
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileLastModifiedDate_Local Second not valid"));
            }

            FileLastModifiedDate_Local = new DateTime(FileYear, FileMonth, FileDay, FileHour, FileMinute, FileSecond);

            FileContent = Request.Params["FileContent"];
            if (string.IsNullOrWhiteSpace(FileContent))
            {
                return(string.Format(LabSheetViewRes._IsRequired, "FileContent"));
            }

            using (CSSPEntities db = new CSSPEntities())
            {
                LabSheet labSheet = (from c in db.LabSheets
                                     where c.SamplingPlanName == SamplingPlanName &&
                                     c.Year == Year &&
                                     c.Month == Month &&
                                     c.Day == Day &&
                                     c.RunNumber == RunNumber &&
                                     c.SubsectorTVItemID == SubsectorTVItemID &&
                                     c.SamplingPlanType == (int)SamplingPlanType &&
                                     c.SampleType == (int)SampleType &&
                                     c.LabSheetType == (int)LabSheetType &&
                                     c.FileName == FileName
                                     select c).FirstOrDefault();

                if (labSheet == null)
                {
                    labSheet = new LabSheet()
                    {
                        SamplingPlanName = SamplingPlanName,
                        Year             = Year,
                        Month            = Month,
                        Day               = Day,
                        RunNumber         = RunNumber,
                        SubsectorTVItemID = SubsectorTVItemID,
                        SamplingPlanType  = (int)SamplingPlanType,
                        SampleType        = (int)SampleType,
                        LabSheetType      = (int)LabSheetType,
                        FileName          = FileName,
                    };

                    db.LabSheets.Add(labSheet);
                }

                labSheet.LabSheetStatus             = (int)LabSheetStatusEnum.Created;
                labSheet.FileLastModifiedDate_Local = FileLastModifiedDate_Local;
                labSheet.FileContent               = FileContent;
                labSheet.LastUpdateDate_UTC        = DateTime.UtcNow;
                labSheet.LastUpdateContactTVItemID = 2;

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return(ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : ""));
                }
            }

            return("");
        }