/// <summary> /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据 /// </summary> /// <param name="pPageIndex">页数</param> /// <param name="pPageSize">每页列表</param> /// <param name="pOrderBy">排序</param> /// <param name="pSortExpression">排序字段</param> /// <param name="pRecordCount">列表行数</param> /// <returns>数据分页</returns> public static List <OfferPriceInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { if (pPageIndex <= 1) { pPageIndex = 1; } List <OfferPriceInfo> list = new List <OfferPriceInfo>(); Query q = OfferPrice.CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression, pOrderBy.ToString()); OfferPriceCollection collection = new OfferPriceCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (OfferPrice offerPrice in collection) { OfferPriceInfo offerPriceInfo = new OfferPriceInfo(); LoadFromDAL(offerPriceInfo, offerPrice); list.Add(offerPriceInfo); } pRecordCount = q.GetRecordCount(); return(list); }
static void Main(string[] args) { #region factory method pattern //contract employee var employee = new FactoryMethod.Employee { //EmployeeTypeID = 1, EmployeeTypeID = 2, Bonus = 100, HourlyPay = 40, HouseAllowance = 40, MedicalAllowance = 30 }; BaseEmployeeFactory empFactory = new EmployeeManagerFactory().CreateFactory(employee); empFactory.ApplySalary(); Console.WriteLine($"Employee: {employee.EmployeeTypeID}{Environment.NewLine} " + $"House Allowance: {employee.HouseAllowance}{Environment.NewLine} " + $"Medical Allowance: {employee.MedicalAllowance}"); #endregion #region Abstract Factory Method var abstractFactoryEmployee = new Employee { }; IComputerFactory factory = new EmployeeSystemFactory().Create(abstractFactoryEmployee); EmployeeSystemManager manager = new EmployeeSystemManager(factory); abstractFactoryEmployee.ComputerDetails = manager.GetSystemDetails(); Console.WriteLine($"Computer Details: {abstractFactoryEmployee.ComputerDetails}{Environment.NewLine} " + $"Job Description: {abstractFactoryEmployee.JobDescription}"); #endregion #region Singleton Pattern /* * Assuming Singleton is created from employee class * we refer to the GetInstance property from the Singleton class */ DesignPatterns.Singleton.Singleton fromEmployee = DesignPatterns.Singleton.Singleton.GetInstance; fromEmployee.PrintDetails("From Employee"); /* * Assuming Singleton is created from student class * we refer to the GetInstance property from the Singleton class */ DesignPatterns.Singleton.Singleton fromStudent = DesignPatterns.Singleton.Singleton.GetInstance; fromStudent.PrintDetails("From Student"); #endregion #region Decorator Pattern ICar car = new Suzuki(); CarDecorator decorator = new OfferPrice(car); Console.WriteLine(string.Format("Make :{0} Price:{1} " + "DiscountPrice : {2}" , decorator.Make, decorator.GetPrice().ToString(), decorator.GetDiscountedPrice().ToString())); #endregion Console.ReadLine(); }
public static void DelOfferPrice(int OfferPriceId) { Query q = OfferPrice.Query(); q.AddWhere(OfferPrice.Columns.OfferPriceId, OfferPriceId); q.QueryType = QueryType.Delete; q.Execute(); }
static void Main(string[] args) { ICar car = new Hyndai(); CarDecorator decorator = new OfferPrice(car); Console.WriteLine(string.Format("Make : {0} , Price : {1} " + "DiscountPrice : {2}", decorator.Make, decorator.GetPrice().ToString(), decorator.GetDiscountedPrice().ToString())); Console.ReadLine(); }
static void Main(string[] args) { ICar car = new Suzuki(); CarDecorator decorator = new OfferPrice(car); Console.WriteLine($"Make: {car.Make} Price: {car.GetPrice().ToString()} " + $"DiscountedPrice: {decorator.GetDiscountedPrice().ToString()}"); }
static void Main(string[] args) { var car = new Suzuki(); var decorator = new OfferPrice(car); Console.WriteLine($"Make {decorator.Make} Price {decorator.GetPrice()} + DiscountedPrice {decorator.GetDiscountedPrice()}"); Console.ReadLine(); }
public void SuzukiMake_ShouldReturn_Sedan_SuzukiGetPrice_ShouldReurn_Price() { ICar car = new Suzuki(); CarDecorator decorator = new OfferPrice(car); string actual = decorator.Make; string expected = car.Make; Assert.Equal(expected, actual); Assert.Equal(car.GetPrice(), decorator.GetPrice()); }
//从后台获取数据 internal static void LoadFromDAL(OfferPriceInfo pOfferPriceInfo, OfferPrice pOfferPrice) { pOfferPriceInfo.offerPriceId = pOfferPrice.OfferPriceId; pOfferPriceInfo.employeeId = pOfferPrice.EmployeeId; pOfferPriceInfo.mainProjectCreateId = pOfferPrice.MainProjectCreateId; pOfferPriceInfo.mainOfferPriceId = pOfferPrice.MainOfferPriceId; pOfferPriceInfo.projectDes = pOfferPrice.ProjectDes; pOfferPriceInfo.sheetNum = pOfferPrice.SheetNum; pOfferPriceInfo.fillTableDate = pOfferPrice.FillTableDate; pOfferPriceInfo.finaceView = pOfferPrice.FinaceView; pOfferPriceInfo.sectionView = pOfferPrice.SectionView; pOfferPriceInfo.mangerView = pOfferPrice.MangerView; pOfferPriceInfo.isApply = pOfferPrice.IsApply; pOfferPriceInfo.isApply1 = pOfferPrice.IsApply1; pOfferPriceInfo.isApply2 = pOfferPrice.IsApply2; pOfferPriceInfo.isOver1 = pOfferPrice.IsOver1; pOfferPriceInfo.isOver2 = pOfferPrice.IsOver2; pOfferPriceInfo.applyTime = pOfferPrice.ApplyTime; pOfferPriceInfo.apply1Time = pOfferPrice.Apply1Time; pOfferPriceInfo.apply2Time = pOfferPrice.Apply2Time; pOfferPriceInfo.sendEmployeeId = pOfferPrice.SendEmployeeId; pOfferPriceInfo.recv1EmployeeId = pOfferPrice.Recv1EmployeeId; pOfferPriceInfo.recv2EmployeeId = pOfferPrice.Recv2EmployeeId; pOfferPriceInfo.sendEmployeeName = pOfferPrice.SendEmployeeName; pOfferPriceInfo.recv1EmployeeName = pOfferPrice.Recv1EmployeeName; pOfferPriceInfo.recv2EmployeeName = pOfferPrice.Recv2EmployeeName; pOfferPriceInfo.preEmployeeId = pOfferPrice.PreEmployeeId; pOfferPriceInfo.preEmployeeName = pOfferPrice.PreEmployeeName; pOfferPriceInfo.preIsApply = pOfferPrice.PreIsApply; pOfferPriceInfo.preIsOver = pOfferPrice.PreIsOver; pOfferPriceInfo.preApplyTime = pOfferPrice.PreApplyTime; pOfferPriceInfo.recvEmployeeId = pOfferPrice.RecvEmployeeId; pOfferPriceInfo.isMain = pOfferPrice.IsMain; pOfferPriceInfo.isMain1 = pOfferPrice.IsMain1; pOfferPriceInfo.isMain2 = pOfferPrice.IsMain2; pOfferPriceInfo.isMain3 = pOfferPrice.IsMain3; pOfferPriceInfo.isNewCreate = pOfferPrice.IsNewCreate; pOfferPriceInfo.isApprove = pOfferPrice.IsApprove; pOfferPriceInfo.approveTime = pOfferPrice.ApproveTime; pOfferPriceInfo.today = pOfferPrice.Today; pOfferPriceInfo.offerPriceTypeId = pOfferPrice.OfferPriceTypeId; pOfferPriceInfo.offerFileId = pOfferPrice.OfferFileId; pOfferPriceInfo.moneySum = pOfferPrice.MoneySum; pOfferPriceInfo.bigMoney = pOfferPrice.BigMoney; pOfferPriceInfo.productMoneySum = pOfferPrice.ProductMoneySum; pOfferPriceInfo.isSignName = pOfferPrice.IsSignName; pOfferPriceInfo.Loaded = true; }
/// <summary> /// 保存 /// </summary> public override void Save() { if (!m_Loaded) //新增 { OfferPrice offerPrice = new OfferPrice(); SaveToDb(this, offerPrice, true); } else //修改 { OfferPrice offerPrice = new OfferPrice(offerPriceId); if (offerPrice.IsNew) { throw new AppException("该数据已经不存在了"); } SaveToDb(this, offerPrice, false); } }
/// <summary> /// 删除 /// </summary> /// <returns>是否成功</returns> public override void Delete() { if (!m_Loaded) { throw new AppException("尚未初始化"); } bool result = (OfferPrice.Delete(OfferPriceId) == 1); //更新缓存 if (result && CachedEntityCommander.IsTypeRegistered(typeof(OfferPriceInfo))) { ResetCache(); } if (!result) { throw new AppException("删除失败,数据可能被删除"); } }
private void LoadFromId(int offerPriceId) { if (CachedEntityCommander.IsTypeRegistered(typeof(OfferPriceInfo))) { OfferPriceInfo offerPriceInfo = Find(GetList(), offerPriceId); if (offerPriceInfo == null) { throw new AppException("未能在缓存中找到相应的键值对象"); } Copy(offerPriceInfo, this); } else { OfferPrice offerPrice = new OfferPrice(offerPriceId); if (offerPrice.IsNew) { throw new AppException("尚未初始化"); } LoadFromDAL(this, offerPrice); } }
//从后台获取数据 internal static void LoadFromDAL(OfferPriceInfo pOfferPriceInfo, OfferPrice pOfferPrice) { pOfferPriceInfo.offerPriceId = pOfferPrice.OfferPriceId; pOfferPriceInfo.employeeId = pOfferPrice.EmployeeId; pOfferPriceInfo.mainProjectCreateId = pOfferPrice.MainProjectCreateId; pOfferPriceInfo.mainOfferPriceId = pOfferPrice.MainOfferPriceId; pOfferPriceInfo.projectDes = pOfferPrice.ProjectDes; pOfferPriceInfo.sheetNum = pOfferPrice.SheetNum; pOfferPriceInfo.fillTableDate = pOfferPrice.FillTableDate; pOfferPriceInfo.finaceView = pOfferPrice.FinaceView; pOfferPriceInfo.sectionView = pOfferPrice.SectionView; pOfferPriceInfo.mangerView = pOfferPrice.MangerView; pOfferPriceInfo.isApply = pOfferPrice.IsApply; pOfferPriceInfo.isApply1 = pOfferPrice.IsApply1; pOfferPriceInfo.isApply2 = pOfferPrice.IsApply2; pOfferPriceInfo.isOver1 = pOfferPrice.IsOver1; pOfferPriceInfo.isOver2 = pOfferPrice.IsOver2; pOfferPriceInfo.applyTime = pOfferPrice.ApplyTime; pOfferPriceInfo.apply1Time = pOfferPrice.Apply1Time; pOfferPriceInfo.apply2Time = pOfferPrice.Apply2Time; pOfferPriceInfo.sendEmployeeId = pOfferPrice.SendEmployeeId; pOfferPriceInfo.recv1EmployeeId = pOfferPrice.Recv1EmployeeId; pOfferPriceInfo.recv2EmployeeId = pOfferPrice.Recv2EmployeeId; pOfferPriceInfo.sendEmployeeName = pOfferPrice.SendEmployeeName; pOfferPriceInfo.recv1EmployeeName = pOfferPrice.Recv1EmployeeName; pOfferPriceInfo.recv2EmployeeName = pOfferPrice.Recv2EmployeeName; pOfferPriceInfo.preEmployeeId = pOfferPrice.PreEmployeeId; pOfferPriceInfo.preEmployeeName = pOfferPrice.PreEmployeeName; pOfferPriceInfo.preIsApply = pOfferPrice.PreIsApply; pOfferPriceInfo.preIsOver = pOfferPrice.PreIsOver; pOfferPriceInfo.preApplyTime = pOfferPrice.PreApplyTime; pOfferPriceInfo.recvEmployeeId = pOfferPrice.RecvEmployeeId; pOfferPriceInfo.isMain = pOfferPrice.IsMain; pOfferPriceInfo.isMain1 = pOfferPrice.IsMain1; pOfferPriceInfo.isMain2 = pOfferPrice.IsMain2; pOfferPriceInfo.isMain3 = pOfferPrice.IsMain3; pOfferPriceInfo.isNewCreate = pOfferPrice.IsNewCreate; pOfferPriceInfo.isApprove = pOfferPrice.IsApprove; pOfferPriceInfo.approveTime = pOfferPrice.ApproveTime; pOfferPriceInfo.today = pOfferPrice.Today; pOfferPriceInfo.offerPriceTypeId = pOfferPrice.OfferPriceTypeId; pOfferPriceInfo.offerFileId = pOfferPrice.OfferFileId; pOfferPriceInfo.moneySum = pOfferPrice.MoneySum; pOfferPriceInfo.bigMoney = pOfferPrice.BigMoney; pOfferPriceInfo.productMoneySum = pOfferPrice.ProductMoneySum; pOfferPriceInfo.isSignName = pOfferPrice.IsSignName; pOfferPriceInfo.Loaded=true; }
/// <summary> /// 保存 /// </summary> public override void Save() { if(!m_Loaded)//新增 { OfferPrice offerPrice=new OfferPrice(); SaveToDb(this, offerPrice,true); } else//修改 { OfferPrice offerPrice=new OfferPrice(offerPriceId); if(offerPrice.IsNew) throw new AppException("该数据已经不存在了"); SaveToDb(this, offerPrice,false); } }
private void LoadFromId(int offerPriceId) { if (CachedEntityCommander.IsTypeRegistered(typeof(OfferPriceInfo))) { OfferPriceInfo offerPriceInfo=Find(GetList(), offerPriceId); if(offerPriceInfo==null) throw new AppException("未能在缓存中找到相应的键值对象"); Copy(offerPriceInfo, this); } else { OfferPrice offerPrice=new OfferPrice( offerPriceId); if(offerPrice.IsNew) throw new AppException("尚未初始化"); LoadFromDAL(this, offerPrice); } }
//数据持久化 internal static void SaveToDb(OfferPriceInfo pOfferPriceInfo, OfferPrice pOfferPrice,bool pIsNew) { pOfferPrice.OfferPriceId = pOfferPriceInfo.offerPriceId; pOfferPrice.EmployeeId = pOfferPriceInfo.employeeId; pOfferPrice.MainProjectCreateId = pOfferPriceInfo.mainProjectCreateId; pOfferPrice.MainOfferPriceId = pOfferPriceInfo.mainOfferPriceId; pOfferPrice.ProjectDes = pOfferPriceInfo.projectDes; pOfferPrice.SheetNum = pOfferPriceInfo.sheetNum; pOfferPrice.FillTableDate = pOfferPriceInfo.fillTableDate; pOfferPrice.FinaceView = pOfferPriceInfo.finaceView; pOfferPrice.SectionView = pOfferPriceInfo.sectionView; pOfferPrice.MangerView = pOfferPriceInfo.mangerView; pOfferPrice.IsApply = pOfferPriceInfo.isApply; pOfferPrice.IsApply1 = pOfferPriceInfo.isApply1; pOfferPrice.IsApply2 = pOfferPriceInfo.isApply2; pOfferPrice.IsOver1 = pOfferPriceInfo.isOver1; pOfferPrice.IsOver2 = pOfferPriceInfo.isOver2; pOfferPrice.ApplyTime = pOfferPriceInfo.applyTime; pOfferPrice.Apply1Time = pOfferPriceInfo.apply1Time; pOfferPrice.Apply2Time = pOfferPriceInfo.apply2Time; pOfferPrice.SendEmployeeId = pOfferPriceInfo.sendEmployeeId; pOfferPrice.Recv1EmployeeId = pOfferPriceInfo.recv1EmployeeId; pOfferPrice.Recv2EmployeeId = pOfferPriceInfo.recv2EmployeeId; pOfferPrice.SendEmployeeName = pOfferPriceInfo.sendEmployeeName; pOfferPrice.Recv1EmployeeName = pOfferPriceInfo.recv1EmployeeName; pOfferPrice.Recv2EmployeeName = pOfferPriceInfo.recv2EmployeeName; pOfferPrice.PreEmployeeId = pOfferPriceInfo.preEmployeeId; pOfferPrice.PreEmployeeName = pOfferPriceInfo.preEmployeeName; pOfferPrice.PreIsApply = pOfferPriceInfo.preIsApply; pOfferPrice.PreIsOver = pOfferPriceInfo.preIsOver; pOfferPrice.PreApplyTime = pOfferPriceInfo.preApplyTime; pOfferPrice.RecvEmployeeId = pOfferPriceInfo.recvEmployeeId; pOfferPrice.IsMain = pOfferPriceInfo.isMain; pOfferPrice.IsMain1 = pOfferPriceInfo.isMain1; pOfferPrice.IsMain2 = pOfferPriceInfo.isMain2; pOfferPrice.IsMain3 = pOfferPriceInfo.isMain3; pOfferPrice.IsNewCreate = pOfferPriceInfo.isNewCreate; pOfferPrice.IsApprove = pOfferPriceInfo.isApprove; pOfferPrice.ApproveTime = pOfferPriceInfo.approveTime; pOfferPrice.Today = pOfferPriceInfo.today; pOfferPrice.OfferPriceTypeId = pOfferPriceInfo.offerPriceTypeId; pOfferPrice.OfferFileId = pOfferPriceInfo.offerFileId; pOfferPrice.MoneySum = pOfferPriceInfo.moneySum; pOfferPrice.BigMoney = pOfferPriceInfo.bigMoney; pOfferPrice.ProductMoneySum = pOfferPriceInfo.productMoneySum; pOfferPrice.IsSignName = pOfferPriceInfo.isSignName; pOfferPrice.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pOfferPrice.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(OfferPriceInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pOfferPriceInfo.offerPriceId = pOfferPrice.OfferPriceId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(OfferPriceInfo))) { ResetCache(); } }
//数据持久化 internal static void SaveToDb(OfferPriceInfo pOfferPriceInfo, OfferPrice pOfferPrice, bool pIsNew) { pOfferPrice.OfferPriceId = pOfferPriceInfo.offerPriceId; pOfferPrice.EmployeeId = pOfferPriceInfo.employeeId; pOfferPrice.MainProjectCreateId = pOfferPriceInfo.mainProjectCreateId; pOfferPrice.MainOfferPriceId = pOfferPriceInfo.mainOfferPriceId; pOfferPrice.ProjectDes = pOfferPriceInfo.projectDes; pOfferPrice.SheetNum = pOfferPriceInfo.sheetNum; pOfferPrice.FillTableDate = pOfferPriceInfo.fillTableDate; pOfferPrice.FinaceView = pOfferPriceInfo.finaceView; pOfferPrice.SectionView = pOfferPriceInfo.sectionView; pOfferPrice.MangerView = pOfferPriceInfo.mangerView; pOfferPrice.IsApply = pOfferPriceInfo.isApply; pOfferPrice.IsApply1 = pOfferPriceInfo.isApply1; pOfferPrice.IsApply2 = pOfferPriceInfo.isApply2; pOfferPrice.IsOver1 = pOfferPriceInfo.isOver1; pOfferPrice.IsOver2 = pOfferPriceInfo.isOver2; pOfferPrice.ApplyTime = pOfferPriceInfo.applyTime; pOfferPrice.Apply1Time = pOfferPriceInfo.apply1Time; pOfferPrice.Apply2Time = pOfferPriceInfo.apply2Time; pOfferPrice.SendEmployeeId = pOfferPriceInfo.sendEmployeeId; pOfferPrice.Recv1EmployeeId = pOfferPriceInfo.recv1EmployeeId; pOfferPrice.Recv2EmployeeId = pOfferPriceInfo.recv2EmployeeId; pOfferPrice.SendEmployeeName = pOfferPriceInfo.sendEmployeeName; pOfferPrice.Recv1EmployeeName = pOfferPriceInfo.recv1EmployeeName; pOfferPrice.Recv2EmployeeName = pOfferPriceInfo.recv2EmployeeName; pOfferPrice.PreEmployeeId = pOfferPriceInfo.preEmployeeId; pOfferPrice.PreEmployeeName = pOfferPriceInfo.preEmployeeName; pOfferPrice.PreIsApply = pOfferPriceInfo.preIsApply; pOfferPrice.PreIsOver = pOfferPriceInfo.preIsOver; pOfferPrice.PreApplyTime = pOfferPriceInfo.preApplyTime; pOfferPrice.RecvEmployeeId = pOfferPriceInfo.recvEmployeeId; pOfferPrice.IsMain = pOfferPriceInfo.isMain; pOfferPrice.IsMain1 = pOfferPriceInfo.isMain1; pOfferPrice.IsMain2 = pOfferPriceInfo.isMain2; pOfferPrice.IsMain3 = pOfferPriceInfo.isMain3; pOfferPrice.IsNewCreate = pOfferPriceInfo.isNewCreate; pOfferPrice.IsApprove = pOfferPriceInfo.isApprove; pOfferPrice.ApproveTime = pOfferPriceInfo.approveTime; pOfferPrice.Today = pOfferPriceInfo.today; pOfferPrice.OfferPriceTypeId = pOfferPriceInfo.offerPriceTypeId; pOfferPrice.OfferFileId = pOfferPriceInfo.offerFileId; pOfferPrice.MoneySum = pOfferPriceInfo.moneySum; pOfferPrice.BigMoney = pOfferPriceInfo.bigMoney; pOfferPrice.ProductMoneySum = pOfferPriceInfo.productMoneySum; pOfferPrice.IsSignName = pOfferPriceInfo.isSignName; pOfferPrice.IsNew = pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pOfferPrice.Save(UserName); } catch (Exception ex) { LogManager.getInstance().getLogger(typeof(OfferPriceInfo)).Error(ex); if (ex.Message.Contains("插入重复键")) //违反了唯一键 { throw new AppException("此对象已经存在"); //此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pOfferPriceInfo.offerPriceId = pOfferPrice.OfferPriceId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(OfferPriceInfo))) { ResetCache(); } }