示例#1
0
        public List <Vaccine> GetVaccinePlan()
        {
            List <Vaccine> rePlan = new List <Vaccine>();

            List <tbVaccine> plan = new BaseRepository()
                                    .GetEntities <tbVaccine>(p => p.planID == this.planID).OrderBy(p => p.day).ToList();

            if (plan.Count == 0)
            {
                return(rePlan);
            }

            var realy = new BaseRepository()
                        .GetEntities <tbInjection>(p => p.PigID == this.ID && p.tbVaccine.planID == this.planID);

            foreach (var p in plan)
            {
                Vaccine v = new Vaccine();
                v.ID   = p.ID;
                v.name = p.name;
                v.planInjectionDate = this.grantDate.AddDays(p.day);

                var r = realy.FirstOrDefault(o => o.vaccineID == p.ID);
                v.realyInjectionDate = (r == null ? null : (DateTime?)r.injectionDate);
                v.injectionID        = (r == null ? -1 : r.ID);
                rePlan.Add(v);
            }

            DateTime[] planDate = plan.Select(p => this.grantDate.AddDays(p.day)).ToArray();
            var        T1       = rePlan.Where(p => p.realyInjectionDate.HasValue).OrderBy(o => o.realyInjectionDate).ToList();
            var        T2       = rePlan.Where(p => !p.realyInjectionDate.HasValue).OrderBy(o => o.planInjectionDate).ToList();

            rePlan = T1.Concat(T2).ToList();
            rePlan[0].reviseInjectionDate = planDate[0];
            for (int i = 1; i < rePlan.Count; i++)
            {
                int delay = 0;
                if (rePlan[i - 1].realyInjectionDate.HasValue)
                {
                    delay = AppGlobal.DateDiff(planDate[i - 1], rePlan[i - 1].realyInjectionDate.Value);
                }
                else
                {
                    delay = AppGlobal.DateDiff(planDate[i - 1], rePlan[i - 1].reviseInjectionDate);
                }

                rePlan[i].reviseInjectionDate = planDate[i].AddDays(delay);
            }

            return(rePlan);
        }
示例#2
0
 /// <summary>
 /// 指定日期的日龄
 /// </summary>
 /// <param name="dt"></param>
 /// <returns></returns>
 public int GetDayOld(DateTime dt)
 {
     return(this.grantDayOld + AppGlobal.DateDiff(this.grantDate, dt));
 }