using Forks.EnterpriseServices.DataDictionary;
using Forks.EnterpriseServices.DomainObjects2;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ButcherFactory.BO
{
  [MapToTable("Butcher_SegmentProduction")]
  [DBIndex("IDX_Butcher_SegmentProduction_Clustered", "GroupID", false, 0)]
  [DBIndexType("IDX_Butcher_SegmentProduction_Clustered", IndexType.Clustered)]
  public class SegmentProduction : SyncBill
  {
    public string BarCode { get; set; }

    [NonDmoProperty]
    public string ShortCode
    {
      get
      {
        if (string.IsNullOrEmpty(BarCode))
          return null;
        if (BarCode.Length > 4)
            return BarCode.Substring(BarCode.Length - 4);
        return BarCode;
      }
    }

    public long? WorkUnit_ID { get; set; }

    public long ProductBatch_ID { get; set; }

    public long Goods_ID { get; set; }

    [DbColumn(DefaultValue = 0)]
    public long TotalCode_ID { get; set; }

    [NonDmoProperty]
    public bool Select { get; set; }

  [ReferenceTo(typeof(TotalCode), "BarCode")]
  [Join("TotalCode_ID", "ID")]
    public string TotalCode_Code { get; set; }

    public decimal Weight { get; set; }

    [ReferenceTo(typeof(Goods), "Name")]
    [Join("Goods_ID", "ID")]
    public string Goods_Name { get; set; }

    [ReferenceTo(typeof(Goods), "Spec")]
    [Join("Goods_ID", "ID")]
    public string Goods_Spec { get; set; }

    [ReferenceTo(typeof(Goods), "Code")]
    [Join("Goods_ID", "ID")]
    public string Goods_Code { get; set; }

    [ReferenceTo(typeof(Goods), "GoodsType")]
    [Join("Goods_ID", "ID")]
    public short? GoodsType { get; set; }
    
    [ReferenceTo(typeof(Goods), "CustomerDefine")]
    [Join("Goods_ID", "ID")]
    public string Goods_CustomerDefine { get; set; }

    [DbColumn(DefaultValue = 0)]
    public bool NoTotalCode { get; set; }

    public long? GroupID { get; set; }

    public bool Submited { get; set; }

    ////挂起状态
    //public bool TrunOut { get; set; }

    public long? TrunOutID { get; set; }

    [DbColumn(DefaultValue = false)]
    public bool InStored { get; set; }

    [DbColumn(DefaultValue = 0)]
    public bool StandardPic { get; set; }

    public string MsgID { get; set; }

    [ReferenceTo(typeof(Goods), "MainUnit")]
    [Join("Goods_ID", "ID")]
    public string MainUnit { get; set; }

    [ReferenceTo(typeof(Goods), "ShotPrintName")]
    [Join("Goods_ID", "ID")]
    public string ShotPrintName { get; set; }

    public decimal? StatisticNumber { get; set; }
    public string Identify { get; set; }
    public string IdentifyRemark { get; set; }

    public DateTime? ButcherDate { get; set; }
  }

  [MapToTable("Butcher_SegmentLog")]
  [KeyField("ID", KeyGenType.identity)]
  public class SegmentLog
  {
    private SegmentLog()
    { }

    public SegmentLog(string barCode,string action)
    {
      Time = DateTime.Now;
      BarCode = barCode;
      Action = action;
    }

    public long ID { get; set; }

    public string Message { get; set; }

    public string BarCode { get; set; }

    public string Action { get; set; }

    public DateTime Time { get; set; }
  }

  [MapToTable("Butcher_SegmentGoodsProductNumLog")]
  [KeyField("ID", KeyGenType.identity)]
  public class SegmentGoodsProductNumLog
  {
    public long ID { get; set; }

    public long Goods_ID { get; set; }

    public string Goods_Code { get; set; }

    public decimal Number { get; set; }

    private DateTime mTime = DateTime.Now;
    [DbColumn(DbType = SqlDbType.DateTime)]
    public DateTime Time
    {
      get { return mTime; }
      set { mTime = value; }
    }

    public string Goods_Name { get; set; }
  }

  public class ProductTask
  {
    public string Item { get; set; }

    public decimal? Need { get; set; }

    public decimal? Done { get; set; }

    public decimal? Last
    {
      get
      {
        if (Need.HasValue && Done.HasValue)
          return Need.Value - Done.Value;
        return null;
      }
    }
  }

  public class ProductTaskFull
  {
    public string Goods_Name { get; set; }
    public string Goods_Code { get; set; }
    public decimal? OrderNumber { get; set; }
    public decimal FinishNumber { get; set; }
    public decimal? LastNumber
    {
      get
      {
        if (OrderNumber.HasValue)
          return OrderNumber.Value - FinishNumber;
        return null;
      }
    }
    public decimal? OrderWeight { get; set; }
    public decimal FinishWeight { get; set; }
    public decimal? LastWeight
    {
      get
      {
        if (OrderWeight.HasValue)
          return OrderWeight.Value - FinishWeight;
        return null;
      }
    }
  }


  public class WeightDetail
  {
    public int No { get; set; }
  
    public decimal Weight { get; set; }
    
  }
}
