using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using WeighBusiness.BO;
|
|
using WeighBusiness.Utils;
|
|
using WeighBusiness.Utils.SqlUtils;
|
|
|
|
namespace WeighBusiness.BL
|
|
{
|
|
public class SynchronousLogBL
|
|
{
|
|
public static bool Insert(SynchronousLog dmo)
|
|
{
|
|
if (dmo.ID > 0)
|
|
return Update(dmo);
|
|
//验证 满足BillTypeID、TerminalBillID为指定值的数据 是否存在。存在则更新
|
|
var oldDmoIfExist = GetSynchronousDmoFromBillID(dmo.BillTypeID, dmo.TerminalBillID);
|
|
if (oldDmoIfExist != null) {
|
|
dmo.ID = oldDmoIfExist.ID;
|
|
return Update(dmo);
|
|
}
|
|
|
|
string insertSql = InsertUtil.GetInsertSql(TableNames.同步日志, new string[] { "BillTypeID", "TerminalBillID", "RemoteBillID" }, new string[] { dmo.BillTypeID.ToString(), dmo.TerminalBillID.ToString(), dmo.RemoteBillID.ToString() });
|
|
if (string.IsNullOrEmpty(insertSql)) {//没有数据要插入时。TODO:是否处理妥当?
|
|
return true;
|
|
}
|
|
|
|
return SqlHelperEx.DoExecuteNonQuery(insertSql);
|
|
}
|
|
|
|
public static bool Update(SynchronousLog dmo)
|
|
{
|
|
var oldDmo = Load(dmo.ID);
|
|
IList<string> needUpdateItems = GetNeedUpdateItems(dmo, oldDmo);
|
|
string updateSql = UpdateUtil.GetUpdateString(TableNames.同步日志, "ID", dmo.ID.ToString(), needUpdateItems.ToArray());
|
|
|
|
if (string.IsNullOrEmpty(updateSql))
|
|
throw new ApplicationException("没有修改!");
|
|
|
|
return SqlHelperEx.DoExecuteNonQuery(updateSql);
|
|
}
|
|
|
|
//public static void Save(SynchronousLog dmo)
|
|
//{
|
|
// if (dmo.ID > 0)
|
|
// Update(dmo);
|
|
// Insert(dmo);
|
|
//}
|
|
|
|
public static bool Delete(long id)
|
|
{
|
|
string deleteSql = DeleteUtil.GetDeleteString(TableNames.同步日志, "TerminalBillID", id.ToString());
|
|
|
|
return SqlHelperEx.DoExecuteNonQuery(deleteSql);
|
|
}
|
|
|
|
private static SynchronousLog Load(long id)
|
|
{
|
|
return SynchronousLogQueryUtil.GetLocalSynchronousLog(id);
|
|
}
|
|
|
|
public static SynchronousLog GetSynchronousDmoFromBillID(short billTypeID, long terminalBillID)
|
|
{
|
|
return SynchronousLogQueryUtil.GetLocalSynchronousLogFromBillID(billTypeID, terminalBillID);
|
|
}
|
|
|
|
private static IList<string> GetNeedUpdateItems(SynchronousLog sl, SynchronousLog oldSl)
|
|
{
|
|
IList<string> updateItems = new List<string>();
|
|
if (sl.BillTypeID != oldSl.BillTypeID) {
|
|
updateItems.Add("BillTypeID");
|
|
updateItems.Add(sl.BillTypeID.ToString());
|
|
}
|
|
if (sl.TerminalBillID != oldSl.TerminalBillID) {
|
|
updateItems.Add("TerminalBillID");
|
|
updateItems.Add(sl.TerminalBillID.ToString());
|
|
}
|
|
if (sl.RemoteBillID != oldSl.RemoteBillID) {
|
|
updateItems.Add("RemoteBillID");
|
|
updateItems.Add(sl.RemoteBillID.ToString());
|
|
}
|
|
if (sl.SynchronousMessage != oldSl.SynchronousMessage) {
|
|
updateItems.Add("SynchronousMessage");
|
|
updateItems.Add(sl.SynchronousMessage);
|
|
}
|
|
return updateItems;
|
|
}
|
|
|
|
public static long[] GetAllNotSynchronousDmo(short billTypeID)
|
|
{
|
|
return SynchronousLogQueryUtil.GetAllNotSynchronousBillIDs(billTypeID);
|
|
}
|
|
}
|
|
}
|