using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Text; using WMS.Web.Core; namespace WMS.Web.Domain.Entitys { /// /// 箱唛表 /// [Serializable] [Table("t_wms_box_mark")] public class BoxMark : EntityBase { /// /// ID /// public override int Id { get; set; } /// /// 订单编号 /// public string OrderBillNo { get; set; } /// /// 物料编码 /// public string MaterialNumber { get; set; } /// /// 产品数量 /// public decimal ProductQty { get; set; } /// /// 装箱数量 /// public decimal CratingQty { get; set; } /// /// 装箱净重 /// public decimal CratingNetWeightQty { get; set; } /// /// 装箱毛重 /// public decimal CratingGrossWeightQty { get; set; } /// /// 尾箱数量 /// public decimal TailboxQty { get; set; } /// /// 尾箱净重 /// public decimal TailboxNetWeightQty { get; set; } /// /// 尾箱毛重 /// public decimal TailboxGrossWeightQty { get; set; } /// /// 备注 /// public string Remark { get; set; } /// /// 操作人 /// public int CreatorId { get; set; } /// /// 创建时间(生成时间) /// public DateTime CreateTime { get; set; } /// /// 编号集合 /// public List BillNos { get; set; } = new List(); /// /// 创建 /// /// public void Create(int creatorId) { this.CreatorId = creatorId; this.CreateTime = DateTime.Now; } /// /// 生成编号 /// /// /// public void GenerateBillNo(int firstBillNo, int lastBillNo) { if (this.BillNos == null) this.BillNos = new List(); //计算要装的箱数量 var boxCount_tag = this.ProductQty / this.CratingQty; var boxCount = Convert.ToInt32(boxCount_tag); //判断是否存在小数点;true表明有尾箱数,false没有尾箱数 var hasPart = Math.Floor(boxCount_tag) != boxCount_tag; //有小数点向上取整 if (hasPart) boxCount = Convert.ToInt32(Math.Ceiling(boxCount_tag)); for (int i = 1; i <= boxCount; i++) { //添加编号生成 var bill = new BoxMarkBillNo(); bill.Sort = i; if (hasPart && i == boxCount && boxCount>1) bill.IsTail = true; bill.GenerateBillNo(firstBillNo, lastBillNo); this.BillNos.Add(bill); //改变前后的billNo值,新的值再一次被使用 firstBillNo = bill.FirstBillNo; lastBillNo = bill.LastBillNo; } //判断有小数点,那么它就有尾箱,把当前第一条的编号是否是尾箱字段改为true //if (this.BillNos.Count != 0 && hasPart) // this.BillNos[0].IsTail = true; } } }