/// <summary> /// 添加与编辑Adjust01记录 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="model">Adjust01表实体</param> /// <param name="content">更新说明</param> /// <param name="isCache">是否更新缓存</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Save(Page page, Adjust01 model, string content = null, bool isCache = true, bool isAddUseLog = true) { try { //保存 model.Save(); //判断是否启用缓存 if (CommonBll.IsUseCache() && isCache) { SetModelForCache(model); } if (isAddUseLog) { if (string.IsNullOrEmpty(content)) { content = "{0}" + (model.Id == 0 ? "添加" : "编辑") + "Adjust01记录成功,ID为【" + model.Id + "】"; } //添加用户访问记录 UseLogBll.GetInstence().Save(page, content); } } catch (Exception e) { var result = "执行Adjust01Bll.Save()函数出错!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <returns>DataAccess.Model.Adjust01</returns> public DataAccess.Model.Adjust01 GetModelForCache(long id) { try { //从缓存中读取指定Id记录 var model = GetModelForCache(x => x.Id == id); if (model == null) { //从数据库中读取 var tem = Adjust01.SingleOrDefault(x => x.Id == id); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取Adjust01表记录时出现异常", e); return(null); } }
/// <summary> /// 将Adjust01记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.Adjust01) /// </summary> /// <param name="model">SubSonic插件生成的实体</param> /// <returns>DataAccess.Model.Adjust01</returns> public DataAccess.Model.Adjust01 Transform(Adjust01 model) { if (model == null) { return(null); } return(new DataAccess.Model.Adjust01 { Id = model.Id, SHOP_ID = model.SHOP_ID, AD_ID = model.AD_ID, SNo = model.SNo, PROD_ID = model.PROD_ID, QUANTITY = model.QUANTITY, STD_UNIT = model.STD_UNIT, STD_CONVERT = model.STD_CONVERT, STD_QUAN = model.STD_QUAN, STD_PRICE = model.STD_PRICE, COST = model.COST, QUAN1 = model.QUAN1, QUAN2 = model.QUAN2, REASON_ID = model.REASON_ID, MEMO = model.MEMO, BAT_NO = model.BAT_NO, Exp_DateTime = model.Exp_DateTime, }); }
/// <summary> /// 获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <param name="isCache">是否从缓存中读取</param> /// <returns>DataAccess.Model.Adjust01</returns> public DataAccess.Model.Adjust01 GetModel(long id, bool isCache = true) { //判断是否使用缓存 if (CommonBll.IsUseCache() && isCache) { //从缓存中获取List var list = GetList(); if (list == null) { return(null); } else { //在List查询指定主键Id的记录 return(list.SingleOrDefault(x => x.Id == id)); } } else { //从数据库中直接读取 var model = Adjust01.SingleOrDefault(x => x.Id == id); if (model == null) { return(null); } else { //对查询出来的实体进行转换 return(Transform(model)); } } }
/// <summary> /// 子表保存 /// </summary> /// <returns></returns> public string DetailEdit() { JArray jarr = Grid2.GetMergedData(); var OlUser = OnlineUsersBll.GetInstence().GetModelForCache(x => x.UserHashKey == Session[OnlineUsersTable.UserHashKey].ToString()); string result = ""; int n = 0; for (int i = 0; i < jarr.Count; i++) { try { var model2 = new Adjust01(); //string str = jarr[i]["status"].ToString(); if (jarr[i]["status"].ToString().Equals("modified")) { model2.SetIsNew(false); } else if (jarr[i]["status"].ToString().Equals("unchanged")) { continue; } else { model2.SetIsNew(true); } model2.SHOP_ID = jarr[i]["values"]["SHOP_ID01"].ToString(); if (!String.IsNullOrEmpty(jarr[i]["values"]["AD_ID01"].ToString())) { model2.AD_ID = jarr[i]["values"]["AD_ID01"].ToString(); } else { return("保存失败"); } model2.SNo = ConvertHelper.Cint(jarr[i]["values"]["SNo01"].ToString()); model2.PROD_ID = jarr[i]["values"]["PROD_ID01"].ToString(); model2.QUANTITY = ConvertHelper.StringToDecimal(jarr[i]["values"]["QUANTITY01"].ToString()); model2.STD_UNIT = jarr[i]["values"]["STD_UNIT01"].ToString(); model2.STD_CONVERT = ConvertHelper.Cint(jarr[i]["values"]["STD_CONVERT01"].ToString()); model2.STD_QUAN = ConvertHelper.StringToDecimal(jarr[i]["values"]["STD_QUAN01"].ToString()); model2.STD_PRICE = ConvertHelper.StringToDecimal(jarr[i]["values"]["STD_PRICE01"].ToString()); model2.COST = ConvertHelper.StringToDecimal(jarr[i]["values"]["COST01"].ToString()); model2.MEMO = jarr[i]["values"]["MEMO01"].ToString(); Adjust01Bll.GetInstence().Save(this, model2); } catch (Exception err) { n++; result = "明细保存失败" + n + "条"; } } return(result); }
/// <summary> /// 判断指定主键Id的记录是否存在——在IIS缓存或数据库中查找 /// </summary> /// <param name="id">主键Id</param> /// <returns></returns> public bool Exist(int id) { if (id <= 0) { return(false); } //判断是否启用缓存 if (CommonBll.IsUseCache()) { return(Exist(x => x.Id == id)); } //从数据库中查找 return(Adjust01.Exists(x => x.Id == id)); }
/// <summary> /// 获取数据表中的某个值——从数据库中查询,如果使用了缓存,删除成功后会清空本表的所有缓存记录,然后重新加载进缓存 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="expression">条件语句</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Delete(Page page, Expression <Func <Adjust01, bool> > expression, bool isAddUseLog = true) { //执行删除 Adjust01.Delete(expression); //判断是否启用缓存 if (CommonBll.IsUseCache()) { //清空当前表所有缓存记录 DelAllCache(); //重新载入缓存 GetList(); } if (isAddUseLog) { //添加用户操作记录 UseLogBll.GetInstence().Save(page, "{0}删除了Adjust01表记录!"); } }
/// <summary> /// 从IIS缓存中获取Adjust01表记录 /// </summary> /// <param name="isCache">是否从缓存中读取</param> public IList <DataAccess.Model.Adjust01> GetList(bool isCache = true) { try { //判断是否使用缓存 if (CommonBll.IsUseCache() && isCache) { //检查指定缓存是否过期——缓存当天有效,第二天自动清空 if (CommonBll.CheckCacheIsExpired(const_CacheKey_Date)) { //删除缓存 DelAllCache(); } //从缓存中获取DataTable var obj = CacheHelper.GetCache(const_CacheKey); //如果缓存为null,则查询数据库 if (obj == null) { var list = GetList(false); //将查询出来的数据存储到缓存中 CacheHelper.SetCache(const_CacheKey, list); //存储当前时间 CacheHelper.SetCache(const_CacheKey_Date, DateTime.Now); return(list); } //缓存中存在数据,则直接返回 else { return((IList <DataAccess.Model.Adjust01>)obj); } } else { //定义临时实体集 IList <DataAccess.Model.Adjust01> list = null; //获取全表缓存加载条件表达式 var exp = GetExpression <Adjust01>(); //如果条件为空,则查询全表所有记录 if (exp == null) { //从数据库中获取所有记录 var all = Adjust01.All(); list = all == null ? null : Transform(all.ToList()); } else { //从数据库中查询出指定条件的记录,并转换为指定实体集 var all = Adjust01.Find(exp); list = all == null ? null : Transform(all); } return(list); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取Adjust01表记录时出现异常", e); } return(null); }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(Adjust01 model) { SetModelForCache(Transform(model)); }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="conditionColName">条件列名</param> /// <param name="value">条件值</param> /// <returns>DataAccess.Model.Adjust01</returns> public DataAccess.Model.Adjust01 GetModelForCache(string conditionColName, object value) { try { //从缓存中获取List var list = GetList(); DataAccess.Model.Adjust01 model = null; Expression <Func <Adjust01, bool> > expression = null; //返回指定条件的实体 switch (conditionColName) { case "Id": model = list.SingleOrDefault(x => x.Id == (int)value); expression = x => x.Id == (int)value; break; case "SHOP_ID": model = list.SingleOrDefault(x => x.SHOP_ID == (string)value); expression = x => x.SHOP_ID == (string)value; break; case "AD_ID": model = list.SingleOrDefault(x => x.AD_ID == (string)value); expression = x => x.AD_ID == (string)value; break; case "SNo": model = list.SingleOrDefault(x => x.SNo == (int)value); expression = x => x.SNo == (int)value; break; case "PROD_ID": model = list.SingleOrDefault(x => x.PROD_ID == (string)value); expression = x => x.PROD_ID == (string)value; break; case "QUANTITY": model = list.SingleOrDefault(x => x.QUANTITY == (decimal)value); expression = x => x.QUANTITY == (decimal)value; break; case "STD_UNIT": model = list.SingleOrDefault(x => x.STD_UNIT == (string)value); expression = x => x.STD_UNIT == (string)value; break; case "STD_CONVERT": model = list.SingleOrDefault(x => x.STD_CONVERT == (int)value); expression = x => x.STD_CONVERT == (int)value; break; case "STD_QUAN": model = list.SingleOrDefault(x => x.STD_QUAN == (decimal)value); expression = x => x.STD_QUAN == (decimal)value; break; case "STD_PRICE": model = list.SingleOrDefault(x => x.STD_PRICE == (decimal)value); expression = x => x.STD_PRICE == (decimal)value; break; case "COST": model = list.SingleOrDefault(x => x.COST == (decimal)value); expression = x => x.COST == (decimal)value; break; case "QUAN1": model = list.SingleOrDefault(x => x.QUAN1 == (decimal)value); expression = x => x.QUAN1 == (decimal)value; break; case "QUAN2": model = list.SingleOrDefault(x => x.QUAN2 == (decimal)value); expression = x => x.QUAN2 == (decimal)value; break; case "REASON_ID": model = list.SingleOrDefault(x => x.REASON_ID == (string)value); expression = x => x.REASON_ID == (string)value; break; case "MEMO": model = list.SingleOrDefault(x => x.MEMO == (string)value); expression = x => x.MEMO == (string)value; break; case "BAT_NO": model = list.SingleOrDefault(x => x.BAT_NO == (string)value); expression = x => x.BAT_NO == (string)value; break; case "Exp_DateTime": model = list.SingleOrDefault(x => x.Exp_DateTime == (DateTime)value); expression = x => x.Exp_DateTime == (DateTime)value; break; default: return(null); } if (model == null) { //从数据库中读取 var tem = Adjust01.SingleOrDefault(expression); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取Adjust01表记录时出现异常", e); return(null); } }