/// <summary> /// 添加与编辑SUPPLIERS记录 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="model">SUPPLIERS表实体</param> /// <param name="content">更新说明</param> /// <param name="isCache">是否更新缓存</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Save(Page page, SUPPLIERS 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 ? "添加" : "编辑") + "SUPPLIERS记录成功,ID为【" + model.Id + "】"; } //添加用户访问记录 UseLogBll.GetInstence().Save(page, content); } } catch (Exception e) { var result = "执行SUPPLIERSBll.Save()函数出错!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <returns>DataAccess.Model.SUPPLIERS</returns> public DataAccess.Model.SUPPLIERS GetModelForCache(long id) { try { //从缓存中读取指定Id记录 var model = GetModelForCache(x => x.Id == id); if (model == null) { //从数据库中读取 var tem = SUPPLIERS.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缓存中获取SUPPLIERS表记录时出现异常", e); return(null); } }
/// <summary> /// 将SUPPLIERS记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.SUPPLIERS) /// </summary> /// <param name="model">SubSonic插件生成的实体</param> /// <returns>DataAccess.Model.SUPPLIERS</returns> public DataAccess.Model.SUPPLIERS Transform(SUPPLIERS model) { if (model == null) { return(null); } return(new DataAccess.Model.SUPPLIERS { Id = model.Id, SUP_ID = model.SUP_ID, SUP_NAME = model.SUP_NAME, SUP_NICKNAME = model.SUP_NICKNAME, SUP_TYPE = model.SUP_TYPE, SUP_ADD = model.SUP_ADD, SUP_TEL = model.SUP_TEL, SUP_Email = model.SUP_Email, SUP_ZIP = model.SUP_ZIP, SUP_Contact = model.SUP_Contact, SUP_Mobile = model.SUP_Mobile, SUP_CODE_ID = model.SUP_CODE_ID, SUP_BankName = model.SUP_BankName, SUP_BankID = model.SUP_BankID, SUP_PASSWORD = model.SUP_PASSWORD, Send_DAY = model.Send_DAY, CRT_DATETIME = model.CRT_DATETIME, CRT_USER_ID = model.CRT_USER_ID, MOD_DATETIME = model.MOD_DATETIME, MOD_USER_ID = model.MOD_USER_ID, LAST_UPDATE = model.LAST_UPDATE, }); }
/// <summary> /// 获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <param name="isCache">是否从缓存中读取</param> /// <returns>DataAccess.Model.SUPPLIERS</returns> public DataAccess.Model.SUPPLIERS 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 = SUPPLIERS.SingleOrDefault(x => x.Id == id); if (model == null) { return(null); } else { //对查询出来的实体进行转换 return(Transform(model)); } } }
/// <summary> /// 读取某个固定字段的值 /// </summary> /// <param name="conditionColName"></param> /// <param name="value"></param> /// <returns></returns> public string GetModelSingleValue(string colunm, Expression <Func <SUPPLIERS, bool> > expression) { var model = new SUPPLIERS(expression); string result = ""; switch (colunm) { case "SUP_ID": result = model.SUP_ID; break; case "SUP_NAME": result = model.SUP_NAME; break; case "SUP_NICKNAME": result = model.SUP_NICKNAME; break; case "SUP_TYPE": result = model.SUP_TYPE.ToString(); break; case "SUP_ADD": result = model.SUP_ADD; break; case "SUP_TEL;": result = model.SUP_TEL; break; case "SUP_Email": result = model.SUP_Email; break; case "SUP_ZIP": result = model.SUP_ZIP; break; case "SUP_Contact": result = model.SUP_Contact; break; case "SUP_Mobile": result = model.SUP_Mobile; break; case "SUP_BankName": result = model.SUP_BankName; break; case "Send_DAY": result = model.Send_DAY.ToString(); break; default: result = ""; break; } return(result); }
public ActionResult DeleteConfirmed(int id) { SUPPLIERS sUPPLIERS = db.SUPPLIERS.Find(id); db.SUPPLIERS.Remove(sUPPLIERS); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "SUPPLIER_ID,SUPPLIERS_NAME,ADDRESS,PHONE_NUMBER,isActive")] SUPPLIERS sUPPLIERS) { if (ModelState.IsValid) { db.Entry(sUPPLIERS).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sUPPLIERS)); }
public ActionResult Create([Bind(Include = "SUPPLIER_ID,SUPPLIERS_NAME,ADDRESS,PHONE_NUMBER,isActive")] SUPPLIERS sUPPLIERS) { if (ModelState.IsValid) { db.SUPPLIERS.Add(sUPPLIERS); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sUPPLIERS)); }
// GET: SUPPLIERS/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SUPPLIERS sUPPLIERS = db.SUPPLIERS.Find(id); if (sUPPLIERS == null) { return(HttpNotFound()); } return(View(sUPPLIERS)); }
/// <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(SUPPLIERS.Exists(x => x.Id == id)); }
/// <summary> /// 获取SUP_BankName字段值 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="pkValue">主键Id</param> /// <param name="isCache">是否从缓存中读取</param> /// <returns></returns> public string GetSUP_BankName(Page page, int pkValue, bool isCache = true) { //判断是否启用缓存 if (isCache && CommonBll.IsUseCache()) { //从缓存中获取实体 var model = GetModelForCache(pkValue); return(model == null ? "" : model.SUP_BankName); } else { //从数据库中查询 var model = SUPPLIERS.SingleOrDefault(x => x.Id == pkValue); return(model == null ? "" : model.SUP_BankName); } }
/// <summary> /// 获取数据表中的某个值——从数据库中查询,如果使用了缓存,删除成功后会清空本表的所有缓存记录,然后重新加载进缓存 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="expression">条件语句</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Delete(Page page, Expression <Func <SUPPLIERS, bool> > expression, bool isAddUseLog = true) { //执行删除 SUPPLIERS.Delete(expression); //判断是否启用缓存 if (CommonBll.IsUseCache()) { //清空当前表所有缓存记录 DelAllCache(); //重新载入缓存 GetList(); } if (isAddUseLog) { //添加用户操作记录 UseLogBll.GetInstence().Save(page, "{0}删除了SUPPLIERS表记录!"); } }
/// <summary> /// 从IIS缓存中获取SUPPLIERS表记录 /// </summary> /// <param name="isCache">是否从缓存中读取</param> public IList <DataAccess.Model.SUPPLIERS> 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.SUPPLIERS>)obj); } } else { //定义临时实体集 IList <DataAccess.Model.SUPPLIERS> list = null; //获取全表缓存加载条件表达式 var exp = GetExpression <SUPPLIERS>(); //如果条件为空,则查询全表所有记录 if (exp == null) { //从数据库中获取所有记录 var all = SUPPLIERS.All(); list = all == null ? null : Transform(all.ToList()); } else { //从数据库中查询出指定条件的记录,并转换为指定实体集 var all = SUPPLIERS.Find(exp); list = all == null ? null : Transform(all); } return(list); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取SUPPLIERS表记录时出现异常", e); } return(null); }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(SUPPLIERS model) { SetModelForCache(Transform(model)); }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="conditionColName">条件列名</param> /// <param name="value">条件值</param> /// <returns>DataAccess.Model.SUPPLIERS</returns> public DataAccess.Model.SUPPLIERS GetModelForCache(string conditionColName, object value) { try { //从缓存中获取List var list = GetList(); DataAccess.Model.SUPPLIERS model = null; Expression <Func <SUPPLIERS, bool> > expression = null; //返回指定条件的实体 switch (conditionColName) { case "Id": model = list.SingleOrDefault(x => x.Id == (int)value); expression = x => x.Id == (int)value; break; case "SUP_ID": model = list.SingleOrDefault(x => x.SUP_ID == (string)value); expression = x => x.SUP_ID == (string)value; break; case "SUP_NAME": model = list.SingleOrDefault(x => x.SUP_NAME == (string)value); expression = x => x.SUP_NAME == (string)value; break; case "SUP_NICKNAME": model = list.SingleOrDefault(x => x.SUP_NICKNAME == (string)value); expression = x => x.SUP_NICKNAME == (string)value; break; case "SUP_TYPE": model = list.SingleOrDefault(x => x.SUP_TYPE == (int)value); expression = x => x.SUP_TYPE == (int)value; break; case "SUP_ADD": model = list.SingleOrDefault(x => x.SUP_ADD == (string)value); expression = x => x.SUP_ADD == (string)value; break; case "SUP_TEL": model = list.SingleOrDefault(x => x.SUP_TEL == (string)value); expression = x => x.SUP_TEL == (string)value; break; case "SUP_Email": model = list.SingleOrDefault(x => x.SUP_Email == (string)value); expression = x => x.SUP_Email == (string)value; break; case "SUP_ZIP": model = list.SingleOrDefault(x => x.SUP_ZIP == (string)value); expression = x => x.SUP_ZIP == (string)value; break; case "SUP_Contact": model = list.SingleOrDefault(x => x.SUP_Contact == (string)value); expression = x => x.SUP_Contact == (string)value; break; case "SUP_Mobile": model = list.SingleOrDefault(x => x.SUP_Mobile == (string)value); expression = x => x.SUP_Mobile == (string)value; break; case "SUP_CODE_ID": model = list.SingleOrDefault(x => x.SUP_CODE_ID == (string)value); expression = x => x.SUP_CODE_ID == (string)value; break; case "SUP_BankName": model = list.SingleOrDefault(x => x.SUP_BankName == (string)value); expression = x => x.SUP_BankName == (string)value; break; case "SUP_BankID": model = list.SingleOrDefault(x => x.SUP_BankID == (string)value); expression = x => x.SUP_BankID == (string)value; break; case "SUP_PASSWORD": model = list.SingleOrDefault(x => x.SUP_PASSWORD == (string)value); expression = x => x.SUP_PASSWORD == (string)value; break; case "Send_DAY": model = list.SingleOrDefault(x => x.Send_DAY == (int)value); expression = x => x.Send_DAY == (int)value; break; case "CRT_DATETIME": model = list.SingleOrDefault(x => x.CRT_DATETIME == (DateTime)value); expression = x => x.CRT_DATETIME == (DateTime)value; break; case "CRT_USER_ID": model = list.SingleOrDefault(x => x.CRT_USER_ID == (string)value); expression = x => x.CRT_USER_ID == (string)value; break; case "MOD_DATETIME": model = list.SingleOrDefault(x => x.MOD_DATETIME == (DateTime)value); expression = x => x.MOD_DATETIME == (DateTime)value; break; case "MOD_USER_ID": model = list.SingleOrDefault(x => x.MOD_USER_ID == (string)value); expression = x => x.MOD_USER_ID == (string)value; break; case "LAST_UPDATE": model = list.SingleOrDefault(x => x.LAST_UPDATE == (DateTime)value); expression = x => x.LAST_UPDATE == (DateTime)value; break; default: return(null); } if (model == null) { //从数据库中读取 var tem = SUPPLIERS.SingleOrDefault(expression); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取SUPPLIERS表记录时出现异常", e); return(null); } }
/// <summary> /// 数据保存 /// </summary> /// <returns></returns> public override string Save() { string result = string.Empty; int id = ConvertHelper.Cint0(hidId.Text); try { #region 数据验证 if (string.IsNullOrEmpty(SUP_ID.Text.Trim())) { return(SUP_ID.Label + "不能为空!"); } if (string.IsNullOrEmpty(SUP_NAME.Text.Trim())) { return(SUP_NAME.Label + "不能为空!"); } if (string.IsNullOrEmpty(SUP_NICKNAME.Text.Trim())) { return(SUP_NICKNAME.Label + "不能为空!"); } if (string.IsNullOrEmpty(SUP_TYPE.SelectedValue) || SUP_TYPE.SelectedValue == "0") { return(SUP_TYPE.Label + "不能为空!"); } var sSUP_ID = StringHelper.Left(SUP_ID.Text, 50); if (SUPPLIERSBll.GetInstence().Exist(x => x.SUP_ID == sSUP_ID) && id == 0) { return(SUP_ID.Label + "已存在!请重新输入!"); } var sSUP_NAME = StringHelper.Left(SUP_NAME.Text, 50); if (SUPPLIERSBll.GetInstence().Exist(x => x.SUP_NAME == sSUP_NAME) && id == 0) { return(SUP_NAME.Label + "已存在!请重新输入!"); } //var sMeno = StringHelper.Left(UNIT_MENO.Text, 40); //if (UNIT_MENO.Text.Trim().Length > 40) //{ // return UNIT_MENO.Label + "超长!"; //} #endregion #region 赋值 var model = new SUPPLIERS(x => x.Id == id); //var OlUser = new OnlineUsers(x => x.UserHashKey == Session[OnlineUsersTable.UserHashKey].ToString()); var OlUser = OnlineUsersBll.GetInstence().GetModelForCache(x => x.UserHashKey == OnlineUsersBll.GetInstence().GetUserHashKey()); //var OlUser = OnlineUsers.SingleOrDefault(x => x.UserHashKey == Session[OnlineUsersTable.UserHashKey].ToString()); model.SUP_ID = sSUP_ID; model.SUP_NAME = sSUP_NAME; model.SUP_NICKNAME = SUP_NICKNAME.Text; model.SUP_TYPE = ConvertHelper.Cint(SUP_TYPE.SelectedValue); model.SUP_ADD = SUP_ADD.Text; model.SUP_TEL = SUP_TEL.Text; model.SUP_Email = SUP_Email.Text; model.SUP_ZIP = SUP_ZIP.Text; model.SUP_Contact = SUP_Contact.Text; model.SUP_Mobile = SUP_Mobile.Text; model.SUP_CODE_ID = SUP_CODE_ID.Text; model.SUP_BankName = SUP_BankName.Text; model.SUP_BankID = SUP_BankID.Text; model.SUP_PASSWORD = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(SUP_PASSWORD.Text, "MD5"); model.Send_DAY = ConvertHelper.Cint(Send_DAY.Text); if (id == 0) { model.CRT_DATETIME = ConvertHelper.StringToDatetime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); model.CRT_USER_ID = OlUser.Manager_LoginName; } else { model.CRT_DATETIME = model.CRT_DATETIME; model.CRT_USER_ID = model.CRT_USER_ID; } //model.CRT_USER_ID = ""; model.MOD_DATETIME = ConvertHelper.StringToDatetime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); model.MOD_USER_ID = OlUser.Manager_LoginName; //model.MOD_USER_ID = ""; model.LAST_UPDATE = ConvertHelper.StringToDatetime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); #endregion ////---------------------------------------------------------- ////存储到数据库 SUPPLIERSBll.GetInstence().Save(this, model); } catch (Exception e) { result = "保存失败!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } return(result); }