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.

146 lines
4.5 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 ProductShiftBL
{
public static void GetInsetShift(long WpfUser_ID, long shiftId,string productShift_Name)
{
var proShift = new ProductShift();
proShift.ProductShift_ID = shiftId;
proShift.ProductShift_Name = productShift_Name;
proShift.WpfUser_ID = WpfUser_ID;
Insert(proShift);
}
public static bool Insert(ProductShift shift)
{
string insertSql = InsertUtil.GetInsertSql(TableNames.,
new string[] { "WpfUser_ID", "ProductShift_ID", "ProductShift_Name"},
new string[] { shift.WpfUser_ID.ToString(), shift.ProductShift_ID.ToString(), shift.ProductShift_Name });
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 bool Update(ProductShift shift)
{
var oldUser = Load(shift.WpfUser_ID);
IList<string> needUpdateItems = GetNeedUpdateItems(shift, oldUser);
if (needUpdateItems.Count == 0)
return true;
string updateSql = UpdateUtil.GetUpdateString(TableNames., "WpfUser_ID", shift.WpfUser_ID.ToString(), needUpdateItems.ToArray());
bool success = true;
using (var she = new SqlHelperEx()) {
she.CreateTransaction();
she.ExecuteNonQuery(updateSql, out success);
if (!success) {
she.Rollback();
return false;
} else {
she.Commit();
}
}
return success;
}
public static bool UpdateByProductShift_ID(ProductShift shift)
{
var oldUser = Load(shift.WpfUser_ID);
IList<string> needUpdateItems = GetNeedUpdateItems(shift, oldUser);
if (needUpdateItems.Count == 0)
return true;
string updateSql = UpdateUtil.GetUpdateString(TableNames., "WpfUser_ID", shift.WpfUser_ID.ToString(), needUpdateItems.ToArray());
bool success = true;
using (var she = new SqlHelperEx()) {
she.CreateTransaction();
she.ExecuteNonQuery(updateSql, out success);
if (!success) {
she.Rollback();
return false;
} else {
she.Commit();
}
}
return success;
}
public static ProductShift Load(long userID)
{
return LocalQueryUtil.GetLocalProductShift(userID);
}
private static IList<string> GetNeedUpdateItems(ProductShift shift, ProductShift oldshift)
{
IList<string> updateItems = new List<string>();
//if (shift.ProductShift_Name != oldshift.ProductShift_Name) {
// updateItems.Add("ProductShift_Name");
// updateItems.Add(shift.ProductShift_Name);
//}
//if (shift.RowVersion != oldshift.RowVersion) {
// updateItems.Add("RowVersion");
// updateItems.Add(shift.RowVersion.ToString());
//}
return updateItems;
}
public static void DeleteAll()
{
var sql = SqlUtil.GetDeleteSql(TableNames.);
using (var she = new SqlHelperEx()) {
bool success;
she.CreateTransaction();
she.ExecuteNonQuery(sql, out success);
if (!success)
she.Rollback();
else
she.Commit();
}
}
public static List<ProductShift> LoadProductShifts(long userID)
{
return LocalQueryUtil.GetLocalProductShifts(userID);
}
public static void SyncProductShift()
{
ProductShiftBL.DeleteAll();
string method = "/MainSystem/B3_HaoYue/Rpcs/RpcFun/GetCurrtUserProductShift";
var productShifts = RpcFacade.Call<List<RpcObject>>(method);
foreach (var shift in productShifts) {
var shiftId = shift.Get<long>("ProductShift_ID");
var productShift_Name = shift.Get<string>("ProductShift_Name");
var wpfUser_ID = shift.Get<long>("WpfUser_ID");
ProductShiftBL.GetInsetShift(wpfUser_ID, shiftId, productShift_Name);
}
}
}
}