private void LoadFromId(int workToolSumId) { if (CachedEntityCommander.IsTypeRegistered(typeof(WorkToolSumInfo))) { WorkToolSumInfo workToolSumInfo=Find(GetList(), workToolSumId); if(workToolSumInfo==null) throw new AppException("未能在缓存中找到相应的键值对象"); Copy(workToolSumInfo, this); } else { WorkToolSum workToolSum=new WorkToolSum( workToolSumId); if(workToolSum.IsNew) throw new AppException("尚未初始化"); LoadFromDAL(this, workToolSum); } }
//从后台获取数据 internal static void LoadFromDAL(WorkToolSumInfo pWorkToolSumInfo, WorkToolSum pWorkToolSum) { pWorkToolSumInfo.workToolSumId = pWorkToolSum.WorkToolSumId; pWorkToolSumInfo.departName = pWorkToolSum.DepartName; pWorkToolSumInfo.reason = pWorkToolSum.Reason; pWorkToolSumInfo.bigMoney = pWorkToolSum.BigMoney; pWorkToolSumInfo.smaMoney = pWorkToolSum.SmaMoney; pWorkToolSumInfo.moneyStyle = pWorkToolSum.MoneyStyle; pWorkToolSumInfo.useDepartName = pWorkToolSum.UseDepartName; pWorkToolSumInfo.fuTime = pWorkToolSum.FuTime; pWorkToolSumInfo.applyName = pWorkToolSum.ApplyName; pWorkToolSumInfo.state = pWorkToolSum.State; pWorkToolSumInfo.applyTime = pWorkToolSum.ApplyTime; pWorkToolSumInfo.departView = pWorkToolSum.DepartView; pWorkToolSumInfo.managerView = pWorkToolSum.ManagerView; pWorkToolSumInfo.Loaded=true; }
//数据持久化 internal static void SaveToDb(WorkToolSumInfo pWorkToolSumInfo, WorkToolSum pWorkToolSum,bool pIsNew) { pWorkToolSum.WorkToolSumId = pWorkToolSumInfo.workToolSumId; pWorkToolSum.DepartName = pWorkToolSumInfo.departName; pWorkToolSum.Reason = pWorkToolSumInfo.reason; pWorkToolSum.BigMoney = pWorkToolSumInfo.bigMoney; pWorkToolSum.SmaMoney = pWorkToolSumInfo.smaMoney; pWorkToolSum.MoneyStyle = pWorkToolSumInfo.moneyStyle; pWorkToolSum.UseDepartName = pWorkToolSumInfo.useDepartName; pWorkToolSum.FuTime = pWorkToolSumInfo.fuTime; pWorkToolSum.ApplyName = pWorkToolSumInfo.applyName; pWorkToolSum.State = pWorkToolSumInfo.state; pWorkToolSum.ApplyTime = pWorkToolSumInfo.applyTime; pWorkToolSum.DepartView = pWorkToolSumInfo.departView; pWorkToolSum.ManagerView = pWorkToolSumInfo.managerView; pWorkToolSum.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pWorkToolSum.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(WorkToolSumInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pWorkToolSumInfo.workToolSumId = pWorkToolSum.WorkToolSumId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(WorkToolSumInfo))) { ResetCache(); } }
/// <summary> /// 保存 /// </summary> public override void Save() { if(!m_Loaded)//新增 { WorkToolSum workToolSum=new WorkToolSum(); SaveToDb(this, workToolSum,true); } else//修改 { WorkToolSum workToolSum=new WorkToolSum(workToolSumId); if(workToolSum.IsNew) throw new AppException("该数据已经不存在了"); SaveToDb(this, workToolSum,false); } }