ldj/WcfService1/BLL/lLot.cs

287 lines
6.5 KiB
C#
Raw Normal View History

2023-05-23 16:13:17 +08:00

/// <summary>
///LOGIC CLASS FOR TABLE t_Lot
///By wm with codesmith.
///on 08/03/2018
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeiNiu.wms.Data.Model;
using System.Data;
using System.Transactions;
using DeiNiu.Utils;
namespace DeiNiu.wms.Logical
{
[Serializable]
public class lLot :lbase
{
Lot _obj;
public lLot()
{
initialize();
}
public Lot LotObj
{
get
{
if (_obj == null)
{
_obj = new Lot();
}
_obj.operater = operId;
return _obj;
}
}
LotAtt _lotAtt;
public LotAtt lotAtt
{
get
{
if (_lotAtt == null)
{
_lotAtt = new LotAtt();
}
_lotAtt.operater = operId;
return _lotAtt;
}
}
Sku _sku;
public Sku skuObj
{
get
{
if (_sku == null)
{
_sku = new Sku();
}
_sku.operater = operId;
return _sku;
}
}
public lLot(int operId)
: base(operId)
{
initialize();
}
/// <summary>
/// get all data
/// </summary>
public DataSet getAllData()
{
return _obj.Query();
}
/// <summary>
/// get all data
/// </summary>
public DataSet getAllActiveData()
{
return _obj.QueryActived();
}
/// <summary>
/// get a record by id
/// </summary>
public void initialize(int id)
{
_obj = id != 0 ? new Lot(id) : new Lot();
}
/// <summary>
/// get a record by id 0
/// </summary>
public void initialize()
{
initialize(0);
}
/// <summary>
/// get a record by id
/// </summary>
public void initialize(DataRow dr)
{
_obj = new Lot(dr);
}
protected override DeiNiu.Data.BaseObject.BaseModel getModel()
{
return _obj;
}
//begin cust db operation, query, excute sql etc.
/// <summary>
/// update in a transaction scrop
/// </summary>
public void update()
{
if (valid())
{
using (TransactionScope scope = new TransactionScope())
{
_obj.Update();
scope.Complete();
}
}
}
private bool valid()
{
return true;
}
internal int newLot(Data.Model.Lot lot)
{
int id = lot.Add();
if (id <= 0)
{
return -1;
}
LotAtt la = new LotAtt();
la.lotId = id;
la.operater = operId;
la.attName = WmsConstants.SKU_RESEVRED_BATCH_ATTNAME;
la.attType = 0;
la.Add();
la.attName = WmsConstants.SKU_RESEVRED_PRDDATE_ATTNAME;
la.attType = 2;
la.Add();
la.attName = WmsConstants.SKU_RESEVRED_EXPIREDATE_ATTNAME;
la.attType = 2;
la.Add();
return id;
}
internal DataTable getLotAtts(string goodsId)
{
return lotAtt.getAttByGoodId(goodsId);
// WmsGoods goods = new WmsGoods(goodsId);
// return lotAtt.queryByLotId(goods.lotId);
}
internal Dictionary<int,string> getSKU(Dictionary<string, string> skuValues, string goodsId)
{
string skuCode = "";
int lotId = 0;
DataTable lotAtts = getLotAtts(goodsId);
LotAtt la;
foreach (DataRow dr in lotAtts.Rows)
{
la = new LotAtt(dr);
if (skuValues.Keys.Contains(la.attName))
{
skuCode += string.Format("{0}:{1};", la.attName, skuValues[la.attName]);
}
}
Dictionary<int, string> dic = new Dictionary<int, string>();
skuCode = string.Format("{0}:{1};", "goodsId", goodsId) + skuCode;
int pjCount = lotAtts.Rows.Count;
if (pjCount == 0) //没有批次定义
{
return dic;
}
else
{
lotId = Convert.ToInt16(lotAtts.Rows[0]["lotId"].ToString());
}
WmsGoods wg = new WmsGoods(goodsId);
int skuId= getSKU(skuCode, skuValues, lotId, goodsId, wg.ownerCode);
dic[skuId] = skuCode;
return dic;
}
internal int getSKU(string skuCode, Dictionary<string, string> skuValues, int lotId, string goodsId, string ownerCode)
{
_sku = new Sku(skuCode);
int skuId = 0;
if (skuObj.ID > 0)
{
skuId = skuObj.ID;
}
else
{
skuObj.skuCode = skuCode;
skuObj.goodsId = goodsId;
skuObj.lotId = lotId;
skuObj.ownerCode = ownerCode;
DataTable dtAtts = lotAtt.queryByLotId(lotId);
using (TransactionScope scope = new TransactionScope())
{
skuId= skuObj.Add();
SkuValue sv = new SkuValue();
sv.skuId = skuId;
sv.operater = operId;
if(skuValues!=null && skuValues.Count>0)
foreach (string key in skuValues.Keys)
{
DataRow[] drs = dtAtts.Select("attName ='" + key + "'");
if (drs.Length > 0)
{
LotAtt la = new LotAtt(drs[0]);
sv.attID = la.ID;
}
sv.value = skuValues[key];
sv.Add();
}
scope.Complete();
}
}
return skuId;
}
}
}