/// <summary> /// 根据初始寄件创建包裹 /// </summary> /// <param name="lot">计费等级量</param> /// <param name="firtSdr">第一个寄件</param> public Parcel(decimal lot, decimal price, SDR firtSdr) : this(lot, price) { Sdrs.Add(firtSdr); Receiver = firtSdr.Receiver; SendDate = firtSdr.SendDate; Prior = firtSdr.Prior; Payway = firtSdr.Payway; firtSdr.Parcel = this; }
/// <summary> /// 移出寄件 /// </summary> /// <param name="sdr"></param> /// <returns>成功:TRUE,失败:FALSE</returns> public bool Remove(SDR sdr) { return Sdrs.Remove(sdr); }
/// <summary> /// 根据寄件查找适合的包裹 /// </summary> /// <param name="sdr">寄件</param> /// <returns>包裹集合</returns> private List<Parcel> FindParcel(SDR sdr) { //必须是相同收件人,相同日期,相同优先级,相同付费方,包裹未满 var ents = Parcels.Where(x => x.Receiver == sdr.Receiver && x.SendDate == sdr.SendDate && x.Prior == sdr.Prior && x.Payway == sdr.Payway && !x.IsFull ).ToList(); return ents; }
/// <summary> /// 添加寄件 /// </summary> /// <param name="sdr">寄件</param> /// <returns>成功:TRUE,失败:FALSE</returns> public bool AddSDR(SDR sdr) { var res = new CheckResult(); foreach (var rule in ParcelRules) { res = rule.Check(sdr); if (!res.IsPass) { return res.IsPass; } } Sdrs.Add(sdr); //设置寄件的包裹属性 sdr.Parcel = this; return res.IsPass; }
/// <summary> /// 反序化对象 /// </summary> /// <param name="SDRstr"></param> /// <returns></returns> public static SDR CreatSDR(string SDRstr) { var props = SDRstr.Split('|'); if (!props.Any()) throw new InvalidDataException("传入数据不合法"); if (props.Count() < 10) throw new InvalidDataException("传入数据必须有10项属性"); if (props[0].Trim() == "0") return null; var entity = new SDR(); entity.SDRNO = props[0].Trim(); entity.Receiver = props[1].Trim(); entity.Prior = props[2].Trim(); entity.SendDate = DateTime.Parse(props[3].Trim()); entity.Payway = props[4].Trim(); entity.IsDelay = props[5].Trim() != "N"; entity.Weight = decimal.Parse(props[6].Trim()); entity.SDRType = props[7].Trim(); entity.Qty = decimal.Parse(props[8].Trim()); entity.Price = decimal.Parse(props[9].Trim()); return entity; }