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 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 GetAllLocalPSInfo(long productShift_ID) { return LocalQueryUtil.GetAllLocalPSInfo(productShift_ID); } public static void SyncProductShiftSet() { var method = "/MainSystem/B3FoodDeepProcess/Rpcs/BaseInfoRpc/GetProductShiftInfo"; var productShiftVersion = RpcFacade.Call>(method); var oldProductShift = PSInfoBL.GetAllLocalPSInfoVersion(); var needInsertPsID = new List(); var needDeleteAndInsertPsID = new List(); if (productShiftVersion.Count > 0) { if (oldProductShift == null || oldProductShift.Count() <= 0) { productShiftVersion.ForEach(x => needInsertPsID.Add(x.Get("ProductShift_ID"))); } else { foreach (var pole in productShiftVersion) { var productShift_ID = pole.Get("ProductShift_ID"); var oldPS = oldProductShift.Where(x => x.ProductShift_ID == productShift_ID); if (oldPS != null && oldPS.Count() > 0 && oldPS.FirstOrDefault().RowVersion != pole.Get("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("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(); foreach (var psID in needInsertPsID) { list.Add(productShiftVersion.Where(x => x.Get("ProductShift_ID") == psID).FirstOrDefault()); } foreach (var detail in list) { var psInfo = new PSInfo(); psInfo.ProductShift_ID = detail.Get("ProductShift_ID"); psInfo.TareSet = detail.Get("TareSet"); psInfo.BillSet = detail.Get("BillSet"); psInfo.WindowSet = detail.Get("WindowSet"); psInfo.Store_ID = detail.Get("Store_ID"); psInfo.RowVersion = detail.Get("RowVersion"); psInfo.GoodsInStore_ID = detail.Get("GoodsInStore_ID"); PSInfoBL.Insert(psInfo); } } } } } }