/// <summary> /// 将DUE01记录实体由普通的实体(DataAccess.Model.DUE01)转换为SubSonic插件生成的实体 /// </summary> /// <param name="model">普通的实体(DataAccess.Model.DUE01)</param> /// <returns>DUE01</returns> public DUE01 Transform(DataAccess.Model.DUE01 model) { if (model == null) { return(null); } return(new DUE01 { Id = model.Id, SHOP_ID = model.SHOP_ID, TAKEIN_ID = model.TAKEIN_ID, SNO = model.SNO, PROD_ID = model.PROD_ID, STD_UNIT = model.STD_UNIT, STD_QUAN = model.STD_QUAN, STD_PRICE = model.STD_PRICE, TAX = model.TAX, QUAN1 = model.QUAN1, QUAN2 = model.QUAN2, ITEM_DISC_AMT = model.ITEM_DISC_AMT, MEMO = model.MEMO, BAT_NO = model.BAT_NO, COST = model.COST, }); }
/// <summary> /// 返回实体中指定字段名的值 /// </summary> /// <param name="model">实体</param> /// <param name="colName">获取的字段名</param> /// <returns></returns> private object GetFieldValue(DataAccess.Model.DUE01 model, string colName) { if (model == null || string.IsNullOrEmpty(colName)) { return(null); } //返回指定的列值 switch (colName) { case "Id": return(model.Id); case "SHOP_ID": return(model.SHOP_ID); case "TAKEIN_ID": return(model.TAKEIN_ID); case "SNO": return(model.SNO); case "PROD_ID": return(model.PROD_ID); case "STD_UNIT": return(model.STD_UNIT); case "STD_QUAN": return(model.STD_QUAN); case "STD_PRICE": return(model.STD_PRICE); case "TAX": return(model.TAX); case "QUAN1": return(model.QUAN1); case "QUAN2": return(model.QUAN2); case "ITEM_DISC_AMT": return(model.ITEM_DISC_AMT); case "MEMO": return(model.MEMO); case "BAT_NO": return(model.BAT_NO); case "COST": return(model.COST); } return(null); }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(DataAccess.Model.DUE01 model) { //从缓存中读取记录列表 var list = GetList(); //从缓存中删除记录 DelCache(model.Id); //添加记录 list.Add(model); }
/// <summary> /// 给实体赋值 /// </summary> /// <param name="model">实体</param> /// <param name="dic">列名与值</param> public void SetModelValue(DataAccess.Model.DUE01 model, Dictionary <string, object> dic) { if (model == null || dic == null) { return; } //遍历字典,逐个给字段赋值 foreach (var d in dic) { SetModelValue(model, d.Key, d.Value); } }
/// <summary> /// 给实体赋值 /// </summary> /// <param name="model">实体</param> /// <param name="colName">列名</param> /// <param name="value">值</param> public void SetModelValue(DataAccess.Model.DUE01 model, string colName, object value) { if (model == null || string.IsNullOrEmpty(colName)) { return; } //返回指定条件的实体 switch (colName) { case "Id": model.Id = (int)value; break; case "SHOP_ID": model.SHOP_ID = (string)value; break; case "TAKEIN_ID": model.TAKEIN_ID = (string)value; break; case "SNO": model.SNO = (int)value; break; case "PROD_ID": model.PROD_ID = (string)value; break; case "STD_UNIT": model.STD_UNIT = (string)value; break; case "STD_QUAN": model.STD_QUAN = (decimal)value; break; case "STD_PRICE": model.STD_PRICE = (decimal)value; break; case "TAX": model.TAX = (decimal)value; break; case "QUAN1": model.QUAN1 = (decimal)value; break; case "QUAN2": model.QUAN2 = (decimal)value; break; case "ITEM_DISC_AMT": model.ITEM_DISC_AMT = (decimal)value; break; case "MEMO": model.MEMO = (string)value; break; case "BAT_NO": model.BAT_NO = (string)value; break; case "COST": model.COST = (decimal)value; break; } }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="conditionColName">条件列名</param> /// <param name="value">条件值</param> /// <returns>DataAccess.Model.DUE01</returns> public DataAccess.Model.DUE01 GetModelForCache(string conditionColName, object value) { try { //从缓存中获取List var list = GetList(); DataAccess.Model.DUE01 model = null; Expression <Func <DUE01, 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 "TAKEIN_ID": model = list.SingleOrDefault(x => x.TAKEIN_ID == (string)value); expression = x => x.TAKEIN_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 "STD_UNIT": model = list.SingleOrDefault(x => x.STD_UNIT == (string)value); expression = x => x.STD_UNIT == (string)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 "TAX": model = list.SingleOrDefault(x => x.TAX == (decimal)value); expression = x => x.TAX == (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 "ITEM_DISC_AMT": model = list.SingleOrDefault(x => x.ITEM_DISC_AMT == (decimal)value); expression = x => x.ITEM_DISC_AMT == (decimal)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 "COST": model = list.SingleOrDefault(x => x.COST == (decimal)value); expression = x => x.COST == (decimal)value; break; default: return(null); } if (model == null) { //从数据库中读取 var tem = DUE01.SingleOrDefault(expression); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取DUE01表记录时出现异常", e); return(null); } }