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.
 

120 lines
3.9 KiB

using System;
using System.Collections.Generic;
using System.Data;
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 LittleCarBL
{
public static List<LittleCar> GetAllLocalLittleCar()
{
return LocalQueryUtil.GetAllLocalLittleCar();
}
public static bool Insert(LittleCar input)
{
string insertSql = InsertUtil.GetInsertSql(TableNames.,
new string[] { "ERP_ID", "Name", "Weight","RowVersion" },
new string[] { input.ERP_ID.ToString(), input.Name, input.Weight.ToString(),input.RowVersion.ToString()});
return ExcuteSql(insertSql);
}
public static void Delete(long ID)
{
var sql2 = SqlUtil.GetDeleteSql(TableNames., "where ERP_ID=" + ID.ToString());
ExcuteSql(sql2);
}
public static void Delete()
{
var sql2 = SqlUtil.GetDeleteSql(TableNames.);
ExcuteSql(sql2);
}
public static decimal? GetWeight(string name)
{
var table = SqlHelperEx.DoQuery(string.Format("select Weight from {0} where Name = '{1}'",TableNames.,name));
if (table.Rows.Count == 0)
return null;
return (decimal?)table.Rows[0][0];
}
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 SyncLittleCar()
{
var method = "/MainSystem/B3FoodDeepProcess/Rpcs/BaseInfoRpc/GetLittleCarRowVersion";
var littleCarVersion = RpcFacade.Call<List<RpcObject>>(method);
var oldLittleCarVersion = LittleCarBL.GetAllLocalLittleCar();
var needInsertCarID = new List<long?>();
var needDeleteAndInsertCarID = new List<long?>();
if (littleCarVersion.Count > 0) {
if (oldLittleCarVersion == null || oldLittleCarVersion.Count() <= 0) {
littleCarVersion.ForEach(x => needInsertCarID.Add(x.Get<long?>("field3")));
} else {
foreach (var map in littleCarVersion) {
var car_ID = map.Get<long>("field3");
var oldVer = oldLittleCarVersion.Where(x => x.ERP_ID == car_ID);
if (oldVer != null && oldVer.Count() > 0 && oldVer.FirstOrDefault().RowVersion != map.Get<int?>("field4")) {
needDeleteAndInsertCarID.Add(car_ID);
} else if (oldVer == null || oldVer.Count() <= 0) {
needInsertCarID.Add(car_ID);
}
}
foreach (var oldVersion in oldLittleCarVersion) {
if (!littleCarVersion.Any(x => x.Get<long>("field3") == oldVersion.ERP_ID)) {
LittleCarBL.Delete(oldVersion.ERP_ID.Value);
}
}
}
} else {
LittleCarBL.Delete();
}
if (needDeleteAndInsertCarID.Count() > 0) {
foreach (var carID in needDeleteAndInsertCarID) {
LittleCarBL.Delete(carID.Value);
needInsertCarID.Add(carID);
}
}
if (needInsertCarID.Count > 0) {
string carMethod = "/MainSystem/B3FoodDeepProcess/Rpcs/BaseInfoRpc/GetLittleCar";
var cars = RpcFacade.Call<IList<RpcObject>>(carMethod, needInsertCarID.ToArray());
if (cars.Count() > 0) {
foreach (var detail in cars) {
var car = new LittleCar();
car.ERP_ID = detail.Get<long?>("field3");
car.Name = detail.Get<string>("field1");
car.Weight = detail.Get<decimal?>("field2");
car.RowVersion = detail.Get<int?>("field4");
LittleCarBL.Insert(car);
}
}
}
}
}
}