ldj/WcfService1/BLL/lLot.cs

361 lines
9.4 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);
}
2023-09-04 22:41:19 +08:00
internal DataTable getLotGoodsType(int lotId)
{
return _obj.getLotGoodsType(lotId);
}
internal DataTable getFreeGoodsType()
{
return _obj.getFreeGoodsType();
}
internal bool newGoodTypeLot(int[] goodsType, int lotId)
{
GoodTypeLot gl = new GoodTypeLot();
foreach(int i in goodsType)
{
gl.goodsType=i;
gl.lotId = lotId;
gl.Add();
}
return true;
}
internal bool deleteGoodsTypeLot(int id)
{
GoodTypeLot gl = new GoodTypeLot(id);
return gl.Delete() > 0;
}
2023-05-23 16:13:17 +08:00
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);
}
2024-02-06 19:36:47 +08:00
// internal Dictionary<int,string> getSKU(Dictionary<string, string> skuValues, string goodsId)
internal Dictionary<int, string> getSKU(string prdDate, string goodsId, string batch )
{
goodsId = goodsId.Trim();
Dictionary<string, string> skuValues = getSku(prdDate, goodsId, batch);
2023-12-03 22:13:49 +08:00
WmsGoods wg = new WmsGoods(goodsId);
log.Debug( string.Format(" to get goodsId sku of {0}, expireDays {1}" , goodsId,wg.expiryDays));
2023-12-03 22:13:49 +08:00
string skuCode = "";
2023-05-23 16:13:17 +08:00
int lotId = 0;
DataTable lotAtts = getLotAtts(goodsId);
LotAtt la;
2023-12-03 22:13:49 +08:00
if (wg.expiryDays > 0)
{
foreach (DataRow dr in lotAtts.Rows)
{
la = new LotAtt(dr);
2023-05-23 16:13:17 +08:00
2023-12-03 22:13:49 +08:00
if (skuValues.Keys.Contains(la.attName))
{
skuCode += string.Format("{0}:{1};", la.attName, skuValues[la.attName]);
}
2023-05-23 16:13:17 +08:00
2023-12-03 22:13:49 +08:00
}
}
2023-05-23 16:13:17 +08:00
Dictionary<int, string> dic = new Dictionary<int, string>();
2023-09-04 22:41:19 +08:00
skuCode = string.Format("{0}:{1};", "goodsId", goodsId) + skuCode;
2023-05-23 16:13:17 +08:00
int pjCount = lotAtts.Rows.Count;
2023-09-04 22:41:19 +08:00
log.Debug(string.Format("sku lot att count {0},getSKU sku code {1}",pjCount, skuCode ));
2023-05-23 16:13:17 +08:00
if (pjCount == 0) //没有批次定义
{
return dic;
}
else
{
2023-11-21 19:18:23 +08:00
lotId = Convert.ToInt32(lotAtts.Rows[0]["lotId"].ToString());
2023-05-23 16:13:17 +08:00
}
2023-09-04 22:41:19 +08:00
log.Debug(string.Format("lot id {0} ", lotId));
2023-12-03 22:13:49 +08:00
2023-05-23 16:13:17 +08:00
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)
{
2023-09-04 22:41:19 +08:00
_sku = new Sku(skuCode);
2023-05-23 16:13:17 +08:00
int skuId = 0;
2023-09-04 22:41:19 +08:00
log.Debug(string.Format("to get sku by skucode {0} ...and skuId is {1}", skuCode, skuObj.ID));
if (skuObj.ID > 0)
{
skuId = skuObj.ID;
}
else
{
skuObj.skuCode = skuCode;
skuObj.goodsId = goodsId;
skuObj.lotId = lotId;
skuObj.ownerCode = ownerCode;
2023-05-23 16:13:17 +08:00
2023-09-04 22:41:19 +08:00
DataTable dtAtts = lotAtt.queryByLotId(lotId);
using (TransactionScope scope = new TransactionScope())
{
2023-11-21 19:18:23 +08:00
try
{
skuId = skuObj.Add();
}catch(Exception e)
{
log.Error(e);
log.Error(skuObj);
}
2023-09-04 22:41:19 +08:00
log.Debug(string.Format(" new skuId is {0}", skuId));
2023-05-23 16:13:17 +08:00
SkuValue sv = new SkuValue();
sv.skuId = skuId;
sv.operater = operId;
2023-09-04 22:41:19 +08:00
if (skuValues != null && skuValues.Count > 0)
foreach (string key in skuValues.Keys)
{
DataRow[] drs = dtAtts.Select("attName ='" + key + "'");
log.Debug(string.Format(" to get LotAtt {0},result count {1},value is {2}", "attName ='" + key + "'", drs.Length, skuValues[key]));
if (drs.Length > 0)
{
LotAtt la = new LotAtt(drs[0]);
sv.attID = la.ID;
log.Debug(string.Format(" sv.attID {0}", sv.attID));
}
sv.value = skuValues[key];
if(string.IsNullOrEmpty(sv.value))
{
throw new Exception(String.Format("入库批次信息错误,缺少 {0}", key));
}
log.Debug(string.Format(" sv.value {0}", sv.value));
sv.Add();
}
2023-05-23 16:13:17 +08:00
2023-09-04 22:41:19 +08:00
scope.Complete();
2023-05-23 16:13:17 +08:00
2023-09-04 22:41:19 +08:00
}
}
2023-05-23 16:13:17 +08:00
return skuId;
}
2024-02-06 19:36:47 +08:00
Dictionary<string, string> getSku(string prdDate,string goodsId,string batch)
{
// DateTime pDate = Util.pareseDateString(prdDate);
string validDate = getDateStr(getValidDate(prdDate, goodsId));
batch = string.IsNullOrEmpty(batch) ? prdDate : batch;
Dictionary<string, string> sku = new Dictionary<string, string>();
sku[WmsConstants.SKU_RESEVRED_PRDDATE_ATTNAME] = prdDate;
sku[WmsConstants.SKU_RESEVRED_EXPIREDATE_ATTNAME] = validDate;
sku[WmsConstants.SKU_RESEVRED_BATCH_ATTNAME] = batch;
return sku;
}
2023-05-23 16:13:17 +08:00
}
}