/// <summary> /// 将CONTRACT00记录实体(SubSonic实体)转换为普通的实体(DataAccess.Model.CONTRACT00) /// </summary> /// <param name="model">SubSonic插件生成的实体</param> /// <returns>DataAccess.Model.CONTRACT00</returns> public DataAccess.Model.CONTRACT00 Transform(CONTRACT00 model) { if (model == null) { return(null); } return(new DataAccess.Model.CONTRACT00 { Id = model.Id, CONTRACT_ID = model.CONTRACT_ID, CONTRACT_TITLE = model.CONTRACT_TITLE, CONTRACTP_SIGN = model.CONTRACTP_SIGN, CONTRACTP_STARTTIME = model.CONTRACTP_STARTTIME, CONTRACTP_ENDTIME = model.CONTRACTP_ENDTIME, USABLE = model.USABLE, LOCK = model.LOCK, FIRST_PARTY = model.FIRST_PARTY, SECEND_PARTY = model.SECEND_PARTY, Meno = model.Meno, 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, STATUS = model.STATUS, }); }
/// <summary> /// 添加与编辑CONTRACT00记录 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="model">CONTRACT00表实体</param> /// <param name="content">更新说明</param> /// <param name="isCache">是否更新缓存</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Save(Page page, CONTRACT00 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 ? "添加" : "编辑") + "CONTRACT00记录成功,ID为【" + model.Id + "】"; } //添加用户访问记录 UseLogBll.GetInstence().Save(page, content); } } catch (Exception e) { var result = "执行CONTRACT00Bll.Save()函数出错!"; //出现异常,保存出错日志信息 CommonBll.WriteLog(result, e); } }
/// <summary> /// 获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <param name="isCache">是否从缓存中读取</param> /// <returns>DataAccess.Model.CONTRACT00</returns> public DataAccess.Model.CONTRACT00 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 = CONTRACT00.SingleOrDefault(x => x.Id == id); if (model == null) { return(null); } else { //对查询出来的实体进行转换 return(Transform(model)); } } }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="id">主键Id</param> /// <returns>DataAccess.Model.CONTRACT00</returns> public DataAccess.Model.CONTRACT00 GetModelForCache(long id) { try { //从缓存中读取指定Id记录 var model = GetModelForCache(x => x.Id == id); if (model == null) { //从数据库中读取 var tem = CONTRACT00.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缓存中获取CONTRACT00表记录时出现异常", e); return(null); } }
/// <summary> /// 更新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpdate_CONTRACTP00(object sender, EventArgs e) { string result = ""; result = Contract00Edit(false); int _id = ConvertHelper.Cint(GridViewHelper.GetSelectedKey(Grid1, true)); if (_id < 1) { FineUI.Alert.ShowInParent("请先选中一个合同", FineUI.MessageBoxIcon.Information); return; } if (!String.IsNullOrEmpty(result)) { FineUI.Alert.ShowInParent(result, FineUI.MessageBoxIcon.Information); } else { btnSaveCONTRACT01(); FineUI.Alert.ShowInParent("更新成功", FineUI.MessageBoxIcon.Information); CONTRACT00Bll.GetInstence().BindGrid(Grid1, 0, 0, null); CONTRACT00 model = new CONTRACT00(); LoadCONTRACTP00(model); LoadCONTRACT01(model.CONTRACT_ID); } }
public override void SingleClick(GridRowClickEventArgs e) { //base.SingleClick(e); int _id = ConvertHelper.Cint(GridViewHelper.GetSelectedKey(Grid1, true)); CONTRACT00 model = new CONTRACT00(x => x.Id == _id); LoadCONTRACTP00(model); LoadCONTRACT01(model.CONTRACT_ID); }
/// <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(CONTRACT00.Exists(x => x.Id == id)); }
/// <summary> /// 加载合同主表信息 /// </summary> /// <param name="model"></param> public void LoadCONTRACTP00(CONTRACT00 model) { hidId.Text = model.Id.ToString(); tbxCONTRACT_ID.Text = model.CONTRACT_ID; tbxCONTRACT_TITLE.Text = model.CONTRACT_TITLE; if (model.USABLE == 1) { cbxUSABLE.Checked = true; } else { cbxUSABLE.Checked = false; } if (model.LOCK == 1) { cbxLOCK.Checked = true; } else { cbxLOCK.Checked = false; } if (model == null || String.IsNullOrEmpty(model.CONTRACT_ID)) { dpkCONTRACTP_SIGN.SelectedDate = DateTime.Now; dpkCONTRACTP_STARTTIME.SelectedDate = DateTime.Now; dpkCONTRACTP_ENDTIME.SelectedDate = DateTime.Now; tbxMOD_USER_DATE.Text = DateTime.Now.ToString(); tbxCRT_DATETIME.Text = DateTime.Now.ToString(); } else { dpkCONTRACTP_SIGN.SelectedDate = model.CONTRACTP_SIGN; dpkCONTRACTP_STARTTIME.SelectedDate = model.CONTRACTP_STARTTIME; dpkCONTRACTP_ENDTIME.SelectedDate = model.CONTRACTP_ENDTIME; tbxMOD_USER_DATE.Text = model.MOD_DATETIME.ToString(); tbxCRT_DATETIME.Text = model.CRT_DATETIME.ToString(); } tbxFIRST_PARTY.Text = model.FIRST_PARTY; tbxSECEND_PARTY.SelectedValue = model.SECEND_PARTY; tbxMeno.Text = model.Meno; tbxCRT_USER_ID.Text = model.CRT_USER_ID; tbxMOD_USER_ID.Text = model.CRT_USER_ID; }
/// <summary> /// 获取数据表中的某个值——从数据库中查询,如果使用了缓存,删除成功后会清空本表的所有缓存记录,然后重新加载进缓存 /// </summary> /// <param name="page">当前页面指针</param> /// <param name="expression">条件语句</param> /// <param name="isAddUseLog">是否添加用户操作日志</param> public void Delete(Page page, Expression <Func <CONTRACT00, bool> > expression, bool isAddUseLog = true) { //执行删除 CONTRACT00.Delete(expression); //判断是否启用缓存 if (CommonBll.IsUseCache()) { //清空当前表所有缓存记录 DelAllCache(); //重新载入缓存 GetList(); } if (isAddUseLog) { //添加用户操作记录 UseLogBll.GetInstence().Save(page, "{0}删除了CONTRACT00表记录!"); } }
/// <summary> /// 从IIS缓存中获取CONTRACT00表记录 /// </summary> /// <param name="isCache">是否从缓存中读取</param> public IList <DataAccess.Model.CONTRACT00> 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.CONTRACT00>)obj); } } else { //定义临时实体集 IList <DataAccess.Model.CONTRACT00> list = null; //获取全表缓存加载条件表达式 var exp = GetExpression <CONTRACT00>(); //如果条件为空,则查询全表所有记录 if (exp == null) { //从数据库中获取所有记录 var all = CONTRACT00.All(); list = all == null ? null : Transform(all.ToList()); } else { //从数据库中查询出指定条件的记录,并转换为指定实体集 var all = CONTRACT00.Find(exp); list = all == null ? null : Transform(all); } return(list); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取CONTRACT00表记录时出现异常", e); } return(null); }
/// <summary> /// 更新IIS缓存中指定Id记录 /// </summary> /// <param name="model">记录实体</param> public void SetModelForCache(CONTRACT00 model) { SetModelForCache(Transform(model)); }
/// <summary> /// 从IIS缓存中获取指定Id记录 /// </summary> /// <param name="conditionColName">条件列名</param> /// <param name="value">条件值</param> /// <returns>DataAccess.Model.CONTRACT00</returns> public DataAccess.Model.CONTRACT00 GetModelForCache(string conditionColName, object value) { try { //从缓存中获取List var list = GetList(); DataAccess.Model.CONTRACT00 model = null; Expression <Func <CONTRACT00, bool> > expression = null; //返回指定条件的实体 switch (conditionColName) { case "Id": model = list.SingleOrDefault(x => x.Id == (int)value); expression = x => x.Id == (int)value; break; case "CONTRACT_ID": model = list.SingleOrDefault(x => x.CONTRACT_ID == (string)value); expression = x => x.CONTRACT_ID == (string)value; break; case "CONTRACT_TITLE": model = list.SingleOrDefault(x => x.CONTRACT_TITLE == (string)value); expression = x => x.CONTRACT_TITLE == (string)value; break; case "CONTRACTP_SIGN": model = list.SingleOrDefault(x => x.CONTRACTP_SIGN == (DateTime)value); expression = x => x.CONTRACTP_SIGN == (DateTime)value; break; case "CONTRACTP_STARTTIME": model = list.SingleOrDefault(x => x.CONTRACTP_STARTTIME == (DateTime)value); expression = x => x.CONTRACTP_STARTTIME == (DateTime)value; break; case "CONTRACTP_ENDTIME": model = list.SingleOrDefault(x => x.CONTRACTP_ENDTIME == (DateTime)value); expression = x => x.CONTRACTP_ENDTIME == (DateTime)value; break; case "USABLE": model = list.SingleOrDefault(x => x.USABLE == (byte)value); expression = x => x.USABLE == (byte)value; break; case "LOCK": model = list.SingleOrDefault(x => x.LOCK == (byte)value); expression = x => x.LOCK == (byte)value; break; case "FIRST_PARTY": model = list.SingleOrDefault(x => x.FIRST_PARTY == (string)value); expression = x => x.FIRST_PARTY == (string)value; break; case "SECEND_PARTY": model = list.SingleOrDefault(x => x.SECEND_PARTY == (string)value); expression = x => x.SECEND_PARTY == (string)value; break; case "Meno": model = list.SingleOrDefault(x => x.Meno == (string)value); expression = x => x.Meno == (string)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; case "STATUS": model = list.SingleOrDefault(x => x.STATUS == (byte)value); expression = x => x.STATUS == (byte)value; break; default: return(null); } if (model == null) { //从数据库中读取 var tem = CONTRACT00.SingleOrDefault(expression); if (tem == null) { return(null); } else { //对查询出来的实体进行转换 model = Transform(tem); return(model); } } else { return(model); } } catch (Exception e) { //记录日志 CommonBll.WriteLog("从IIS缓存中获取CONTRACT00表记录时出现异常", e); return(null); } }
/// <summary> /// Contract00保存与更新 /// </summary> /// <param name="isNew"></param> /// <returns></returns> public string Contract00Edit(bool isNew) { string result = ""; result = CheckContract00(); if (!String.IsNullOrEmpty(result)) { return(result); } try { CONTRACT00 model = null; var OlUser = OnlineUsersBll.GetInstence().GetModelForCache(x => x.UserHashKey == Session[OnlineUsersTable.UserHashKey].ToString()); if (isNew == true) { model = new CONTRACT00(); model.SetIsNew(true); model.CONTRACT_ID = tbxCONTRACT_ID.Text; model.CRT_DATETIME = ConvertHelper.StringToDatetime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); model.CRT_USER_ID = OlUser.Manager_LoginName; } else { int _id = ConvertHelper.Cint(hidId.Text.ToString()); model = new CONTRACT00(x => x.Id == _id); model.SetIsNew(false); model.CONTRACT_ID = model.CONTRACT_ID; } model.MOD_DATETIME = ConvertHelper.StringToDatetime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); model.MOD_USER_ID = OlUser.Manager_LoginName; model.CONTRACT_TITLE = tbxCONTRACT_TITLE.Text; if (cbxUSABLE.Checked == true) { model.USABLE = 1; } else { model.USABLE = 0; } if (cbxLOCK.Checked == true) { model.LOCK = 1; } else { model.LOCK = 0; } model.CONTRACTP_SIGN = ConvertHelper.StringToDatetime(dpkCONTRACTP_SIGN.Text.ToString()); model.CONTRACTP_STARTTIME = ConvertHelper.StringToDatetime(dpkCONTRACTP_STARTTIME.Text.ToString()); model.CONTRACTP_ENDTIME = ConvertHelper.StringToDatetime(dpkCONTRACTP_ENDTIME.Text.ToString()); model.FIRST_PARTY = tbxFIRST_PARTY.Text; model.SECEND_PARTY = tbxSECEND_PARTY.SelectedValue.ToString(); model.Meno = tbxMeno.Text; CONTRACT00Bll.GetInstence().Save(this, model); result = ""; } catch (Exception err) { result = "保存失败"; } return(result); }