protected void btnSave_Click(object sender, EventArgs e) { if (IsPageValid()) { string strTitle = Request.Form["txtTitle"].ToString(); string str = Request.Form["txtContent"].ToString(); string strSignName = Request.Form["txtSignName"].ToString(); string strNoticeTime = Request.Form["txtNoticeTime"].ToString(); EmployeeInfo em = (EmployeeInfo)Session["Employee"]; NoticeInfo notice = new NoticeInfo(); notice.EmployeeName = em.EmployeeName; notice.NoticeTitle = strTitle; notice.NoticeContent = str; notice.SignName = strSignName; notice.NoticeTime = strNoticeTime; notice.Save(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('发布公告成功!');</script>"); DataTable EmTb = MessageInfo.getEmployeeId(em.EmployeeId); string[] strto = new String[EmTb.Rows.Count]; for (int i = 0; i < EmTb.Rows.Count; i++) { EmployeeInfo ems = new EmployeeInfo(Convert.ToInt32(EmTb.Rows[i]["EmployeeId"])); strto[i] = ems.Qq.ToString(); } MessageInfo.SendMailS(strto, "OA新的消息", "OA有新的公告"); } }
protected void Notice() { int noticeid = NoticeInfo.getMaxNoticeId(); if (noticeid == 0) { lblNotice.Text = ""; } else { NoticeInfo notice = new NoticeInfo(noticeid); lblNotice.Text = notice.NoticeTitle.ToString() + " " + notice.NoticeTime.ToString(); } }
public NoticeInfo GetNoticeInfoById(int NoticeId) { NoticeInfo noticeInfo = null;// try { noticeInfo = new NoticeInfo(NoticeId); } catch (AppException) { return null; } return noticeInfo; }
protected void PageInit() { int noticeid=Convert.ToInt32(Request["NoticeId"].ToString()); if (noticeid == 0) { hTitle.InnerText = ""; lblContent.Text = ""; sName.InnerText = ""; sTime.InnerText = ""; } else { NoticeInfo notice = new NoticeInfo(noticeid); hTitle.InnerText = notice.NoticeTitle.ToString(); lblContent.Text = notice.NoticeContent.ToString(); lblContent.Text = lblContent.Text.Replace(" ", " "); lblContent.Text = lblContent.Text.Replace("\r\n", "<br>"); sName.InnerText = notice.SignName.ToString(); sTime.InnerText = notice.NoticeTime.ToString(); } }
private void LoadFromId(int noticeId) { if (CachedEntityCommander.IsTypeRegistered(typeof(NoticeInfo))) { NoticeInfo noticeInfo = Find(GetList(), noticeId); if (noticeInfo == null) { throw new AppException("未能在缓存中找到相应的键值对象"); } Copy(noticeInfo, this); } else { Notice notice = new Notice(noticeId); if (notice.IsNew) { throw new AppException("尚未初始化"); } LoadFromDAL(this, notice); } }
//数据持久化 internal static void SaveToDb(NoticeInfo pNoticeInfo, Notice pNotice,bool pIsNew) { pNotice.NoticeId = pNoticeInfo.noticeId; pNotice.NoticeContent = pNoticeInfo.noticeContent; pNotice.SignName = pNoticeInfo.signName; pNotice.NoticeTime = pNoticeInfo.noticeTime; pNotice.NoticeTitle = pNoticeInfo.noticeTitle; pNotice.EmployeeName = pNoticeInfo.employeeName; pNotice.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pNotice.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(NoticeInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pNoticeInfo.noticeId = pNotice.NoticeId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(NoticeInfo))) { ResetCache(); } }
/// <summary> /// 批量装载 /// </summary> internal static void LoadFromDALPatch(List< NoticeInfo> pList, NoticeCollection pCollection) { foreach (Notice notice in pCollection) { NoticeInfo noticeInfo = new NoticeInfo(); LoadFromDAL(noticeInfo, notice ); pList.Add(noticeInfo); } }
//从后台获取数据 internal static void LoadFromDAL(NoticeInfo pNoticeInfo, Notice pNotice) { pNoticeInfo.noticeId = pNotice.NoticeId; pNoticeInfo.noticeContent = pNotice.NoticeContent; pNoticeInfo.signName = pNotice.SignName; pNoticeInfo.noticeTime = pNotice.NoticeTime; pNoticeInfo.noticeTitle = pNotice.NoticeTitle; pNoticeInfo.employeeName = pNotice.EmployeeName; pNoticeInfo.Loaded=true; }
/// <summary> /// 复制为另一个对象 /// </summary> /// <param name="pIndustryTypeInfoTo"></param> public void CopyTo(NoticeInfo pNoticeInfoTo) { Copy(this, pNoticeInfoTo); }
public void DeleteById(NoticeInfo pNoticeInfo) { NoticeInfo noticeInfo = new NoticeInfo(pNoticeInfo.NoticeId); noticeInfo.Delete(); }
public List <NoticeInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { return(NoticeInfo.GetPagedList(pPageIndex, pPageSize, pOrderBy, pSortExpression, out pRecordCount)); }
/// <summary> /// 复制一个对象,采用硬编码的方式,避免反射的低效 /// </summary> /// <param name="pIndustryTypeInfoFrom"></param> /// <param name="pIndustryTypeInfoTo"></param> public static void Copy(NoticeInfo pNoticeInfoFrom, NoticeInfo pNoticeInfoTo) { pNoticeInfoTo.NoticeId = pNoticeInfoFrom.noticeId; pNoticeInfoTo.NoticeContent = pNoticeInfoFrom.noticeContent; pNoticeInfoTo.SignName = pNoticeInfoFrom.signName; pNoticeInfoTo.NoticeTime = pNoticeInfoFrom.noticeTime; pNoticeInfoTo.NoticeTitle = pNoticeInfoFrom.noticeTitle; pNoticeInfoTo.EmployeeName = pNoticeInfoFrom.employeeName; pNoticeInfoTo.Loaded=pNoticeInfoFrom.Loaded; }
public object SaveNoticeInfo(NoticeInfo noticeInfo) { noticeInfo.Save(); return noticeInfo . NoticeId; }
public List <NoticeInfo> GetNoticeInfoList() { return(NoticeInfo.GetList()); }
/// <summary> /// 获得数据列表 /// </summary> /// <returns></returns> public static List<NoticeInfo> GetList() { string cacheKey = GetCacheKey(); //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取 if (CachedEntityCommander.IsTypeRegistered(typeof(NoticeInfo)) && CachedEntityCommander.GetCache(cacheKey) != null) { return CachedEntityCommander.GetCache(cacheKey) as List< NoticeInfo>; } else { List< NoticeInfo> list =new List< NoticeInfo>(); NoticeCollection collection=new NoticeCollection(); Query qry = new Query(Notice.Schema); collection.LoadAndCloseReader(qry.ExecuteReader()); foreach(Notice notice in collection) { NoticeInfo noticeInfo= new NoticeInfo(); LoadFromDAL(noticeInfo,notice); list.Add(noticeInfo); } //生成缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(NoticeInfo))) { CachedEntityCommander.SetCache(cacheKey, list); } return list; } }
public object SaveNoticeInfo(NoticeInfo noticeInfo) { noticeInfo.Save(); return(noticeInfo.NoticeId); }
/// <summary> /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据 /// </summary> /// <param name="pPageIndex">页数</param> /// <param name="pPageSize">每页列表</param> /// <param name="pOrderBy">排序</param> /// <param name="pSortExpression">排序字段</param> /// <param name="pRecordCount">列表行数</param> /// <returns>数据分页</returns> public static List<NoticeInfo> GetPagedList(int pPageIndex,int pPageSize,SortDirection pOrderBy,string pSortExpression,out int pRecordCount) { if(pPageIndex<=1) pPageIndex=1; List< NoticeInfo> list = new List< NoticeInfo>(); Query q = Notice .CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression,pOrderBy.ToString()); NoticeCollection collection=new NoticeCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (Notice notice in collection) { NoticeInfo noticeInfo = new NoticeInfo(); LoadFromDAL(noticeInfo, notice); list.Add(noticeInfo); } pRecordCount=q.GetRecordCount(); return list; }