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 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 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 GetNeedUpdateItems(ProductShift shift, ProductShift oldshift) { IList updateItems = new List(); //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 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>(method); foreach (var shift in productShifts) { var shiftId = shift.Get("ProductShift_ID"); var productShift_Name = shift.Get("ProductShift_Name"); var wpfUser_ID = shift.Get("WpfUser_ID"); ProductShiftBL.GetInsetShift(wpfUser_ID, shiftId, productShift_Name); } } } }