using CK.SCP.Models; using CK.SCP.Models.ExchangeCenterTables; using CK.SCP.Utils; using System; using System.Collections.Generic; using System.Data.Entity.Migrations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CK.SCP.Controller { public class SCP_TES_PURCHASE_PRICE { public static void Get_TES_PURCHASE_PRICE_List(TES_PURCHASE_PRICE p_entity, Action>> p_action) { ResultObject> _ret = new ResultObject>(); try { using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { IQueryable q = db.TES_PURCHASE_PRICE; if (!string.IsNullOrEmpty(p_entity.PriceList)) { q = q.Where(p => p.PriceList.Contains(p_entity.PriceList)); } if (!string.IsNullOrEmpty(p_entity.Desc)) { q = q.Where(p => p.Desc.Contains(p_entity.Desc)); } if (!string.IsNullOrEmpty(p_entity.ProductLine)) { q = q.Where(p => p.ProductLine.Contains(p_entity.ProductLine)); } if (!string.IsNullOrEmpty(p_entity.Currency)) { q = q.Where(p => p.Currency.Contains(p_entity.Currency)); } if (!string.IsNullOrEmpty(p_entity.PartCode)) { q = q.Where(p => p.PartCode.Contains(p_entity.PartCode)); } if (!string.IsNullOrEmpty(p_entity.Um)) { q = q.Where(p => p.Um.Contains(p_entity.Um)); } if (!string.IsNullOrEmpty(p_entity.AmountType)) { q = q.Where(p => p.AmountType.Contains(p_entity.AmountType)); } if (p_entity.Amount != 0) { q = q.Where(p => p.Amount == p_entity.Amount); } if (p_entity.UID != 0) { q = q.Where(p => p.UID == p_entity.UID); } if (!string.IsNullOrEmpty(p_entity.CreateUser)) { q = q.Where(p => p.CreateUser.Contains(p_entity.CreateUser)); } if (!string.IsNullOrEmpty(p_entity.Remark)) { q = q.Where(p => p.Remark.Contains(p_entity.Remark)); } if (!string.IsNullOrEmpty(p_entity.CommandType)) { q = q.Where(p => p.CommandType.Contains(p_entity.CommandType)); } if (!string.IsNullOrEmpty(p_entity.Domain)) { q = q.Where(p => p.Domain.Contains(p_entity.Domain)); } if (!string.IsNullOrEmpty(p_entity.Site)) { q = q.Where(p => p.Site.Contains(p_entity.Site)); } if (!string.IsNullOrEmpty(p_entity.SupplierCode)) { q = q.Where(p => p.SupplierCode.Contains(p_entity.SupplierCode)); } if (p_entity.VendAmount != 0) { q = q.Where(p => p.VendAmount == p_entity.VendAmount); } if (p_entity.GUID!= Guid.Empty) { q = q.Where(p => p.GUID == p_entity.GUID); } if (p_entity.TaskID != Guid.Empty) { q = q.Where(p => p.TaskID == p_entity.TaskID); } if (p_entity.Start != DateTime.MinValue) { q = q.Where(p => p.Start.Year == p_entity.Start.Year && p.Start.Month == p_entity.Start.Month && p.Start.Day == p_entity.Start.Day); } if (p_entity.ExpireDate != DateTime.MinValue) { q = q.Where(p => p.ExpireDate.Year == p_entity.ExpireDate.Year && p.ExpireDate.Month == p_entity.ExpireDate.Month && p.ExpireDate.Day == p_entity.ExpireDate.Day); } if (p_entity.CreateTime != DateTime.MinValue) { q = q.Where(p => p.CreateTime.Year == p_entity.CreateTime.Year && p.CreateTime.Day == p_entity.CreateTime.Day && p.CreateTime.Month == p_entity.CreateTime.Month); } _ret.Result = q; _ret.State = ReturnStatus.Succeed; p_action(_ret); } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.ErrorList.Add(e); LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_PURCHASE_PRICE), "Get_TES_PURCHASE_PRICE_List", e.Message); throw e; } } public ResultObject Save_TES_PURCHASE_PRICE(List p_entitys) { ResultObject _ret = new ResultObject(); try { using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { foreach (var itm in p_entitys) { db.TES_PURCHASE_PRICE.AddOrUpdate(itm); } if (db.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; } } } catch (Exception e) { _ret.State = ReturnStatus.Failed; LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_PURCHASE_PRICE), "Save_TES_PURCHASE_PRICE", e.Message); _ret.Result = false; _ret.ErrorList.Add(e); throw e; } return _ret; } public ResultObject Del_TES_PURCHASE_PRICE(List p_entitys) { ResultObject _ret = new ResultObject(); try { using (var db = EntitiesFactory.CreateExchangeCenterInstance()) { foreach (var itm in p_entitys) { db.TES_PURCHASE_PRICE.Remove(itm); } if (db.SaveChanges() != -1) { _ret.State = ReturnStatus.Succeed; _ret.Result = true; } else { _ret.State = ReturnStatus.Failed; _ret.Result = false; } } } catch (Exception e) { _ret.State = ReturnStatus.Failed; _ret.Result = false; _ret.ErrorList.Add(e); LogHelper.Writlog(LogHelper.LogType.Error, typeof(TES_PURCHASE_PRICE), "Del_TES_PURCHASE_PRICE", e.Message); throw e; } return _ret; } } }