ldj/WcfService1/BLL/lTmsLineDetail.cs

286 lines
6.3 KiB
C#
Raw Normal View History

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

/// <summary>
///LOGIC CLASS FOR TABLE t_tmsLineDetail
///By wm with codesmith.
///on 07/23/2017
/// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeiNiu.wms.Data.Model;
using System.Data;
using System.Transactions;
namespace DeiNiu.wms.Logical
{
[Serializable]
public class lTmsLineDetail : lbase
{
TmsLineDetail _obj;
public lTmsLineDetail()
{
initialize();
}
public lTmsLineDetail(int operId)
: base(operId)
{
initialize();
}
public TmsLineDetail getTmsLineDetail
{
get
{
return _obj;
}
}
/// <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 TmsLineDetail(id) : new TmsLineDetail();
}
/// <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 TmsLineDetail(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()
{
using (TransactionScope scope = new TransactionScope())
{
//Node tmp = new Node();
//tmp.parentid = 1;
//tmp.name = "test trans" + DateTime.Now;
//tmp.description = "this is for transTest";
//tmp.Add();
_obj.Update();
scope.Complete();
}
}
public DataTable getAllLines(string custName)
{
if (string.IsNullOrEmpty(custName))
{
return new Node().queryChildsByFlag(3001);
}
else
{
return _obj.getLinesByCust(custName);
}
}
internal bool addLineCust(int lineNo, string custId, int order)
{
try
{
using (TransactionScope scope = new TransactionScope())
{
if (order > 0)
{
int cnt = _obj.getLineDetailCount(lineNo);
if (order <= cnt)
{
updateLineCustOrder(lineNo,0, cnt+1, order);
}
}
order = order < 0 ? 1 : order;
TmsLineDetail td = new TmsLineDetail();
td.lineId = lineNo;
td.custId = custId;
td.lineOrder = order;
td.operater = operId;
td.Add();
_obj.Update();
scope.Complete();
return true;
}
}
catch (Exception e)
{
return false;
}
}
internal bool updateLineCustOrder(int id, int order)
{
TmsLineDetail td = new TmsLineDetail(id);
td.lineOrder = order;
td.operater = operId;
return td.Update() > 0;
}
internal bool updateLineCustOrder(int lineId, int detailId, int orderOld, int orderNew)
{
int cnt = _obj.getLineDetailCount(lineId);
int start = 0;
int end = 0;
int value = 0;
if (orderOld == -1) // new cust to line
{
return true;
}
if (orderNew > orderOld) // all items plus -1 ,,, 50 ->60
{
start = orderOld + 1;
end = orderNew;
value = -1;
}
else if (orderNew < orderOld) //all items plus 1 ,,,60 -->50
{
start = orderNew;
end = orderOld - 1;
value = 1;
}
else if (orderNew == orderOld) //all items plus 1 ,, new one
{
start = orderNew - 1;
end = orderOld + 1;
value = 1;
}
try
{
using (TransactionScope scope = new TransactionScope())
{
_obj.updateCustOrders(lineId, start, end, value);
if (detailId > 0)
{
updateLineCustOrder(detailId, orderNew);
}
scope.Complete();
return true;
}
}
catch (Exception e)
{
return false;
}
}
internal bool removeCust(int lineDetailId)
{
_obj = new TmsLineDetail(lineDetailId);
return _obj.Delete() > 0;
}
internal bool reOrderLine(int lineId)
{
DataTable dt = getTmsLineDetail.queryByLineID(lineId);
int i = 1;
try
{
using (TransactionScope scope = new TransactionScope())
{
foreach (DataRow dr in dt.Rows)
{
_obj = new TmsLineDetail(dr);
_obj.lineOrder = i;
int k= _obj.Update();
i++;
}
scope.Complete();
return true;
}
}
catch (Exception e)
{
return false;
}
}
}
}