You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

122 lines
4.4 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FireBirdUtil.SqlUtils;
using Forks.JsonRpc.Client;
using Forks.JsonRpc.Client.Data;
using WeighBusiness.BO;
using WeighBusiness.Utils;
using WeighBusiness.Utils.SqlUtils;
namespace WeighBusiness.BL
{
public static class PSInfoBL
{
public static List<PSInfo> GetAllLocalPSInfoVersion()
{
return LocalQueryUtil.GetAllLocalPSInfoVersion();
}
public static bool Insert(PSInfo input)
{
string insertSql = InsertUtil.GetInsertSql(TableNames.,
new string[] { "ProductShift_ID", "Store_ID", "TareSet", "RowVersion", "BillSet", "WindowSet", "GoodsInStore_ID" },
new string[] { input.ProductShift_ID.ToString(), input.Store_ID == null ? "null" : input.Store_ID.ToString(), string.IsNullOrEmpty(input.TareSet) ? "null" : input.TareSet, input.RowVersion.Value.ToString(), string.IsNullOrEmpty(input.BillSet) ? "null" : input.BillSet, string.IsNullOrEmpty(input.WindowSet) ? "null" : input.WindowSet, input.GoodsInStore_ID == null ? "null" : input.GoodsInStore_ID.ToString() });
return ExcuteSql(insertSql);
}
private static bool ExcuteSql(string sql)
{
bool success;
using (var she = new SqlHelperEx()) {
she.CreateTransaction();
she.ExecuteNonQuery(sql, out success);
if (!success)
she.Rollback();
else
she.Commit();
}
return success;
}
public static void Delete(long ID)
{
var sql2 = SqlUtil.GetDeleteSql(TableNames., "where ProductShift_ID=" + ID.ToString());
ExcuteSql(sql2);
}
public static void Delete()
{
var sql2 = SqlUtil.GetDeleteSql(TableNames.);
ExcuteSql(sql2);
}
public static List<PSInfo> GetAllLocalPSInfo(long productShift_ID)
{
return LocalQueryUtil.GetAllLocalPSInfo(productShift_ID);
}
public static void SyncProductShiftSet()
{
var method = "/MainSystem/B3FoodDeepProcess/Rpcs/BaseInfoRpc/GetProductShiftInfo";
var productShiftVersion = RpcFacade.Call<List<RpcObject>>(method);
var oldProductShift = PSInfoBL.GetAllLocalPSInfoVersion();
var needInsertPsID = new List<long?>();
var needDeleteAndInsertPsID = new List<long?>();
if (productShiftVersion.Count > 0) {
if (oldProductShift == null || oldProductShift.Count() <= 0) {
productShiftVersion.ForEach(x => needInsertPsID.Add(x.Get<long?>("ProductShift_ID")));
} else {
foreach (var pole in productShiftVersion) {
var productShift_ID = pole.Get<long?>("ProductShift_ID");
var oldPS = oldProductShift.Where(x => x.ProductShift_ID == productShift_ID);
if (oldPS != null && oldPS.Count() > 0 && oldPS.FirstOrDefault().RowVersion != pole.Get<int?>("RowVersion")) {
needDeleteAndInsertPsID.Add(productShift_ID);
} else if (oldPS == null || oldPS.Count() <= 0) {
needInsertPsID.Add(productShift_ID);
}
}
foreach (var oldVersion in oldProductShift) {
if (!productShiftVersion.Any(x => x.Get<long?>("ProductShift_ID") == oldVersion.ProductShift_ID)) {
PSInfoBL.Delete(oldVersion.ProductShift_ID.Value);
}
}
}
} else {
PSInfoBL.Delete();
}
if (needDeleteAndInsertPsID.Count() > 0) {
foreach (var psID in needDeleteAndInsertPsID) {
PSInfoBL.Delete(psID.Value);
needInsertPsID.Add(psID.Value);
}
}
if (needInsertPsID.Count > 0) {
if (productShiftVersion.Count() > 0) {
var list = new List<RpcObject>();
foreach (var psID in needInsertPsID) {
list.Add(productShiftVersion.Where(x => x.Get<long?>("ProductShift_ID") == psID).FirstOrDefault());
}
foreach (var detail in list) {
var psInfo = new PSInfo();
psInfo.ProductShift_ID = detail.Get<long?>("ProductShift_ID");
psInfo.TareSet = detail.Get<string>("TareSet");
psInfo.BillSet = detail.Get<string>("BillSet");
psInfo.WindowSet = detail.Get<string>("WindowSet");
psInfo.Store_ID = detail.Get<long?>("Store_ID");
psInfo.RowVersion = detail.Get<int?>("RowVersion");
psInfo.GoodsInStore_ID = detail.Get<long?>("GoodsInStore_ID");
PSInfoBL.Insert(psInfo);
}
}
}
}
}
}