Exemple #1
0
        public tblCalf BuildFromRawCalf(RawCalf rawCalf, Herd herd)
        {
            var calfBirthYear = (short)(rawCalf.BirthDate.Year);
            var newCalf       = new tblCalf
            {
                Calf_SN          = rawCalf.CalfSN,
                Dam_SN           = rawCalf.DamSN,
                CalfHerd_SN      = herd.HerdSN,
                HerdtraxAnimalId = rawCalf.HerdtraxAnimalId,
                CalfBirthYr_Num  = calfBirthYear,
                CalfTag_Num      = int.Parse(rawCalf.TagNumber),
                CalfYr_Code      = YearLetterCode(calfBirthYear),
                DNA_Tag          = string.IsNullOrEmpty(rawCalf.DNATag) ? (int?)null : int.Parse(rawCalf.DNATag),
                Birth_Date       = rawCalf.BirthDate,
                Birth_Wt         = rawCalf.BirthWt == 0 ? (short?)null : (short)rawCalf.BirthWt,
                Sex_Code         = rawCalf.SexCode,
                Cull_Pull_Flag   = rawCalf.EaseScore > 0,
                Udder_Score      = rawCalf.UdderScore == 0 ? (byte?)null : (byte)rawCalf.UdderScore,
            };

            // Twin stuff
            if (!string.IsNullOrEmpty(rawCalf.TwinType))
            {
                newCalf.Twin_Flag        = true;
                newCalf.HerdtraxTwinType = rawCalf.TwinType;

                if (rawCalf.SiblingCalfAnimalId > 0)
                {
                    RawCalf sib = herd.Calves.First(c => c.HerdtraxAnimalId == rawCalf.SiblingCalfAnimalId);
                    newCalf.CalfTwin_SN = sib.CalfSN;
                }

                if (rawCalf.SurrogateDam_SN > 0)
                {
                    //RawCalf sib = herd.Calves.First(c => c.HerdtraxAnimalId == rawCalf.SiblingCalfAnimalId);
                    //newCalf.CalfTwin_SN = sib.CalfSN;
                    newCalf.GraftedFromDam_SN = rawCalf.SurrogateDam_SN;
                    newCalf.Grafted_Flag      = true;
                }
            }
            return(newCalf);
        }
Exemple #2
0
        private void ValidateCalf(RawCalf rawCalf, Herd herd)
        {
            // Calf Registration # should be null
            if (!string.IsNullOrWhiteSpace(rawCalf.RegistrationNumber))
            {
                AddIssue(rawCalf,
                         string.Format("Calf registration number ({0}) should not exist for new calves.",
                                       rawCalf.RegistrationNumber));
            }

            // Herdtrax Animal Id
            if (rawCalf.HerdtraxAnimalId == 0)
            {
                AddIssue(rawCalf,
                         string.Format("Herdtrax Animal Id is required for every calf. Its missing for calf with VID {0}",
                                       rawCalf.VID));
            }
            else
            {
                tblCalf dbCalf = _bbModel.tblCalves.FirstOrDefault(c => c.HerdtraxAnimalId == rawCalf.HerdtraxAnimalId);
                if (dbCalf != null)
                {
                    AddIssue(rawCalf,
                             string.Format(
                                 "Animal Id already exists. This import progam is not prepared to UPDATE... only INSERTS.  Calf_SN:{0}",
                                 dbCalf.Calf_SN));
                }
            }

            // Sex
            if (string.IsNullOrWhiteSpace(rawCalf.Gender))
            {
                AddIssue(rawCalf, string.Format("No gender (Calf-M/Calf-F)."));
            }

            if ((rawCalf.SexCode != "F") && (rawCalf.SexCode != "M"))
            {
                AddIssue(rawCalf,
                         string.Format("Missing or invalid sex code - {0},  Herdtrax Gender:{1}", rawCalf.SexCode,
                                       rawCalf.Gender));
            }

            // Date
            if (rawCalf.BirthDate == DateTime.MinValue)
            {
                AddIssue(rawCalf, string.Format("Birth date is missing."));
            }

            // Weight
            if ((rawCalf.BirthWt > 0) && ((rawCalf.BirthWt < 20) || (rawCalf.BirthWt > 150)))
            {
                AddIssue(rawCalf, string.Format("Birth weight is out of range ({0})", rawCalf.BirthWt));
            }

            // Ease (we have true/false for assisted birth flag)
            if ((rawCalf.EaseScore < 0) || (rawCalf.EaseScore > 1))
            {
                AddIssue(rawCalf, string.Format("Calving ease is out of range ({0})", rawCalf.EaseScore));
            }

            // Udder
            if ((rawCalf.UdderScore < 0) || (rawCalf.UdderScore > 4))
            {
                AddIssue(rawCalf, string.Format("Udder score is out of range ({0})", rawCalf.UdderScore));
            }

            // Tag
            if (string.IsNullOrWhiteSpace(rawCalf.TagNumber))
            {
                AddIssue(rawCalf, string.Format("Calf tag number is null or missing"));
            }
            else
            {
                int tagnum;
                if (!int.TryParse(rawCalf.TagNumber, out tagnum))
                {
                    AddIssue(rawCalf, string.Format("Calf tag number is not a real number {0}.", rawCalf.TagNumber));
                }
                else
                {
                    tblCalf dbCalf = _bbModel.tblCalves.FirstOrDefault(
                        c =>
                        c.CalfHerd_SN == herd.HerdSN && c.CalfBirthYr_Num == rawCalf.BirthDate.Year &&
                        c.CalfTag_Num == tagnum);
                    if (dbCalf != null)
                    {
                        AddIssue(rawCalf,
                                 string.Format("Calf exists: HerdSN:{0}  BirthYrNum:{1}  TagNumber{2}.  Calf_SN={3}",
                                               herd.HerdSN, rawCalf.BirthDate.Year, rawCalf.TagNumber, dbCalf.Calf_SN));
                    }
                }
            }

            // DNA tag
            if (!string.IsNullOrEmpty(rawCalf.DNATag))
            {
                int dnatag;
                if (!int.TryParse(rawCalf.DNATag, out dnatag))
                {
                    AddIssue(rawCalf, string.Format("Calf DNA tag is not numeric {0}.", rawCalf.DNATag));
                }
                else
                {
                    tblCalf dbCalf = _bbModel.tblCalves.FirstOrDefault(
                        c => c.DNA_Tag == dnatag);
                    if (dbCalf != null)
                    {
                        AddIssue(rawCalf,
                                 string.Format(
                                     "DNA tag {0} already exists: HerdSN:{1}  BirthYrNum:{2}  TagNumber{3}.  Calf_SN={4}",
                                     dnatag,
                                     herd.HerdSN, rawCalf.BirthDate.Year, rawCalf.TagNumber, dbCalf.Calf_SN));
                    }
                }
            }
        }