214 lines
6.7 KiB
C#
214 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BarCode.Web.Core;
|
|
using BarCode.Web.Core.Help;
|
|
using BarCode.Web.Core.Internal.Results;
|
|
using BarCode.Web.Domain.Values;
|
|
|
|
namespace BarCode.Web.Domain.Entitys
|
|
{
|
|
/// <summary>
|
|
/// 箱信息头
|
|
/// alter table t_barcode_box_details AUTO_INCREMENT=50000;
|
|
/// </summary>
|
|
|
|
[Serializable]
|
|
[Table("t_barcode_box")]
|
|
public class Box : EntityBase
|
|
{
|
|
/// <summary>
|
|
/// ID
|
|
/// </summary>
|
|
[Column("Id")]
|
|
public override int Id { get; set; }
|
|
/// <summary>
|
|
/// 箱编号
|
|
/// </summary>
|
|
[Column("BoxBillNo")]
|
|
public string BoxBillNo { get; set; } = "";
|
|
/// <summary>
|
|
/// 供应商Code
|
|
/// </summary>
|
|
[Column("SupplierCode")]
|
|
public string SupplierCode { get; set; } = "";
|
|
/// <summary>
|
|
/// 组织Code
|
|
/// </summary>
|
|
[Column("OrgCode")]
|
|
public string OrgCode { get; set; } = "";
|
|
/// <summary>
|
|
/// 公司Id
|
|
/// </summary>
|
|
[Column("CompanyId")]
|
|
public int CompanyId { get; set; } = 0;
|
|
/// <summary>
|
|
/// 箱状态
|
|
/// </summary>
|
|
[Column("Status")]
|
|
public BoxStatus Status { get; set; } = BoxStatus.NoUse;
|
|
/// <summary>
|
|
/// 装箱开始时间
|
|
/// </summary>
|
|
[Column("CartonBeginTime")]
|
|
public DateTime? CartonBeginTime { get; set; }
|
|
/// <summary>
|
|
/// 装箱结束时间(完成装箱时间)
|
|
/// </summary>
|
|
[Column("CartonEndTime")]
|
|
public DateTime? CartonEndTime { get; set; }
|
|
/// <summary>
|
|
/// 装箱用户
|
|
/// </summary>
|
|
[Column("CartonUserId")]
|
|
public int CartonUserId { get; set; } = 0;
|
|
/// <summary>
|
|
/// 箱子创建用户
|
|
/// </summary>
|
|
[Column("CreatorId")]
|
|
public int CreatorId { get; set; } = 0;
|
|
/// <summary>
|
|
/// 创建时间
|
|
/// </summary>
|
|
[Column("CreateTime")]
|
|
public DateTime CreateTime { get; set; } = DateTime.Now;
|
|
/// <summary>
|
|
/// 箱号打印次数
|
|
/// </summary>
|
|
[Column("PrintNumber")]
|
|
public int PrintNumber { get; set; } = 0;
|
|
/// <summary>
|
|
/// 最新打印时间
|
|
/// </summary>
|
|
[Column("PrintTime")]
|
|
public DateTime? PrintTime { get; set; }
|
|
/// <summary>
|
|
/// 明细
|
|
/// </summary>
|
|
public List<BoxDetails> Details { get; set; } = new List<BoxDetails>();
|
|
|
|
public void GenerateNo()
|
|
{
|
|
//用户手动输入了 就不自动生成了
|
|
if (!string.IsNullOrEmpty(this.BoxBillNo)) return;
|
|
|
|
if (this.Id.ToString().Length >= 8)
|
|
{
|
|
this.BoxBillNo = "CTN" + this.Id.ToString();
|
|
return;
|
|
}
|
|
|
|
string idStr = this.Id.ToString();
|
|
while (true)
|
|
{
|
|
idStr = "0" + idStr;
|
|
if (idStr.Length >= 8) break;
|
|
}
|
|
this.BoxBillNo = "CTN" + idStr;
|
|
}
|
|
/// <summary>
|
|
/// 打印
|
|
/// </summary>
|
|
public void Print()
|
|
{
|
|
this.PrintNumber++;
|
|
this.PrintTime = DateTime.Now;
|
|
}
|
|
/// <summary>
|
|
/// 解绑序列号
|
|
/// </summary>
|
|
/// <param name="serialNumber"></param>
|
|
/// <param name="materialNumber"></param>
|
|
/// /// <param name="isNotCount">是否不计数</param>
|
|
public Result UnSerialNumber(string serialNumber, string materialNumber,string isNotCount)
|
|
{
|
|
var detail = this.Details.FirstOrDefault(f => f.MaterialNumber.Equals(materialNumber));
|
|
if (detail == null)
|
|
return Result.ReFailure(ResultCodes.BoxMaterialNoDataError);
|
|
var serial = detail.SerialNumbers.FirstOrDefault(f => f.Equals(serialNumber));
|
|
if (serial == null && isNotCount!="1")
|
|
return Result.ReFailure(ResultCodes.BoxSerialNumberNoDataError);
|
|
detail.SerialNumbers.Remove(serialNumber);
|
|
|
|
|
|
// detail.Qty = detail.SerialNumbers.Count();
|
|
if(isNotCount=="1")
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
detail.Qty = detail.Qty - 1;
|
|
}
|
|
//如果数量为0了就删除这条明细
|
|
if (detail.Qty <= 0)
|
|
this.Details.Remove(detail);
|
|
//如果没有明细了 就把状态改成未使用
|
|
if (detail.Qty <= 0)
|
|
this.Status = BoxStatus.NoUse;
|
|
|
|
////如果数量为0了就删除这条明细
|
|
//if (detail.SerialNumbers.Count() <= 0)
|
|
// this.Details.Remove(detail);
|
|
////如果没有明细了 就把状态改成未使用
|
|
//if (this.Details.Count() <= 0)
|
|
// this.Status = BoxStatus.NoUse;
|
|
|
|
return Result.ReSuccess();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空
|
|
/// </summary>
|
|
public void Clear()
|
|
{
|
|
this.Details.Clear();
|
|
}
|
|
/// <summary>
|
|
/// 装箱
|
|
/// </summary>
|
|
public Result Carton(bool isComplete, int cartonUserId)
|
|
{
|
|
if (this.Status == BoxStatus.Complete)
|
|
return Result.ReFailure(ResultCodes.CartonCompleteError);
|
|
if (this.CartonBeginTime == null) this.CartonBeginTime = DateTime.Now;
|
|
this.CartonUserId = cartonUserId;
|
|
if (isComplete == true)
|
|
{
|
|
//完成装箱
|
|
this.Status = BoxStatus.Complete;
|
|
this.CartonEndTime = DateTime.Now;
|
|
return Result.ReSuccess();
|
|
}
|
|
this.Status = BoxStatus.NoComplete;
|
|
return Result.ReSuccess();
|
|
}
|
|
/// <summary>
|
|
/// 开始装箱
|
|
/// </summary>
|
|
/// <param name="cartonUserId"></param>
|
|
/// <returns></returns>
|
|
public Result BeginCarton(int cartonUserId)
|
|
{
|
|
if (this.Status == BoxStatus.Complete)
|
|
return Result.ReFailure(ResultCodes.CartonCompleteError);
|
|
if (this.CartonBeginTime == null)
|
|
this.CartonBeginTime = DateTime.Now;
|
|
if (this.CartonUserId == 0)
|
|
this.CartonUserId = cartonUserId;
|
|
this.Status = BoxStatus.NoComplete;
|
|
return Result.ReSuccess();
|
|
}
|
|
/// <summary>
|
|
/// 重置
|
|
/// </summary>
|
|
public void Restart()
|
|
{
|
|
this.Status = BoxStatus.NoComplete;
|
|
this.CartonEndTime = null;
|
|
}
|
|
}
|
|
}
|