using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using BLL.OpenService;
namespace BLL
{
public class Common_NoticeService
{
public static Model.SGGLDB db = Funs.DB;
///
/// 记录数
///
private static int count
{
get;
set;
}
///
/// 定义变量
///
private static IQueryable qq = from x in db.Common_Notice orderby x.NoticeCode select x;
///
/// 获取分页列表
///
///
///
///
public static IEnumerable getListData(string systemId, string projectId, string type, string noticeCode, string startTime, string endTime, int startRowIndex, int maximumRows)
{
IQueryable q = qq;
if (type == "0")
{
if (!string.IsNullOrEmpty(projectId))
{
q = q.Where(e => e.SystemId == systemId && e.ProjectId == projectId);
}
else
{
q = q.Where(e => e.SystemId == systemId);
}
}
else
{
if (!string.IsNullOrEmpty(projectId))
{
q = q.Where(e => e.IsRelease == true && (e.AccessSystemId.Contains(systemId + "#") && e.AccessProjectId.Contains(projectId)) ||(e.SystemId == systemId && e.ProjectId == projectId));
}
else
{
q = q.Where(e => e.IsRelease == true && (e.AccessSystemId.Contains(systemId + "#") || e.SystemId == systemId));
}
}
if(!string.IsNullOrEmpty(noticeCode))
{
q = q.Where(e => e.NoticeCode.Contains(noticeCode));
}
if (!string.IsNullOrEmpty(startTime))
{
q = q.Where(e => e.CompileDate >= Funs.GetNewDateTime(startTime));
}
if (!string.IsNullOrEmpty(endTime))
{
q = q.Where(e => e.CompileDate <= Funs.GetNewDateTime(endTime));
}
count = q.Count();
if (count == 0)
{
return new object[] { "" };
}
return from x in q.Skip(startRowIndex).Take(maximumRows)
select new
{
x.NoticeId,
x.NoticeCode,
x.ProjectId,
x.NoticeTitle,
x.MainContent,
x.ClearUpMan,
x.IsRelease,
x.State,
ProjectName = (from y in db.Base_Project where y.ProjectId == x.ProjectId select y.ProjectName).First(),
ClearUpManName = (from y in db.Sys_User where y.UserId == x.ClearUpMan select y.UserName).First(),
SignManName = (from y in db.Sys_User
where y.UserId == (from z in db.Common_NoticeSign where z.NoticeId == x.NoticeId && z.SinaDate == null select z.SignMan).First()
select y.UserName).First(),
x.SystemId,
x.CompileDate,
SystemName= (from y in db.Sys_System where y.SystemId == x.SystemId select y.SystemName).FirstOrDefault(),
x.AccessSystemText,
x.AccessProjectText,
};
}
///
/// 获取列表数
///
///
public static int getListCount(string systemId, string projectId, string type, string noticeCode, string startTime, string endTime)
{
return count;
}
///
/// 根据通知Id获取一个通知信息
///
/// 通知Id
/// 一个通知实体
public static Model.Common_Notice GetNoticeByNoticeId(string noticeId)
{
return Funs.DB.Common_Notice.FirstOrDefault(x => x.NoticeId == noticeId);
}
///
/// 增加通知信息
///
/// 通知实体
public static void AddNotice(Model.Common_Notice notice)
{
Model.Common_Notice newNotice = new Model.Common_Notice();
newNotice.NoticeId = notice.NoticeId;
newNotice.NoticeCode = notice.NoticeCode;
newNotice.ProjectId = notice.ProjectId;
newNotice.NoticeTitle = notice.NoticeTitle;
newNotice.MainContent = notice.MainContent;
newNotice.ClearUpMan = notice.ClearUpMan;
newNotice.AttachUrl = notice.AttachUrl;
newNotice.IsRelease = notice.IsRelease;
newNotice.State = notice.State;
newNotice.SystemId = notice.SystemId;
newNotice.CompileDate = notice.CompileDate;
newNotice.Flag = notice.Flag;
newNotice.AccessProjectId = notice.AccessProjectId;
newNotice.AccessSystemId = notice.AccessSystemId;
newNotice.AccessProjectText = notice.AccessProjectText;
newNotice.AccessSystemText = notice.AccessSystemText;
db.Common_Notice.InsertOnSubmit(newNotice);
db.SubmitChanges();
}
///
/// 修改通知信息
///
/// 通知实体
public static void UpdateNotice(Model.Common_Notice notice)
{
Model.Common_Notice newNotice = db.Common_Notice.FirstOrDefault(e => e.NoticeId == notice.NoticeId);
if (newNotice != null)
{
newNotice.NoticeCode = notice.NoticeCode;
newNotice.ProjectId = notice.ProjectId;
newNotice.NoticeTitle = notice.NoticeTitle;
newNotice.MainContent = notice.MainContent;
newNotice.ClearUpMan = notice.ClearUpMan;
newNotice.AttachUrl = notice.AttachUrl;
newNotice.IsRelease = notice.IsRelease;
newNotice.State = notice.State;
newNotice.SystemId = notice.SystemId;
newNotice.Flag = notice.Flag;
newNotice.AccessProjectId = notice.AccessProjectId;
newNotice.AccessSystemId = notice.AccessSystemId;
newNotice.AccessProjectText = notice.AccessProjectText;
newNotice.AccessSystemText = notice.AccessSystemText;
db.SubmitChanges();
}
}
///
/// 根据通知Id删除一个通知信息
///
/// 通知Id
public static void DeleteNotice(string noticeId)
{
Model.Common_Notice notice = db.Common_Notice.FirstOrDefault(e => e.NoticeId == noticeId);
if (notice != null)
{
db.Common_Notice.DeleteOnSubmit(notice);
db.SubmitChanges();
}
}
///
/// 根据状态选择下一步办理类型
///
///
///
public static List GetNetSignStepByState(string state)
{
List handleSteps=new List();
if (state == Const.Common_Notice_Check)
{
Model.HandleStep step1 = new Model.HandleStep();
step1.Id=Const.Common_Notice_ReCompile;
step1.Name="重新整理";
handleSteps.Add(step1);
Model.HandleStep step2 = new Model.HandleStep();
step2.Id = Const.Common_Notice_Sign;
step2.Name = "签发";
handleSteps.Add(step2);
}
if (state == Const.Common_Notice_Sign)
{
Model.HandleStep step1 = new Model.HandleStep();
step1.Id = Const.Common_Notice_ReCompile;
step1.Name = "重新整理";
handleSteps.Add(step1);
Model.HandleStep step2 = new Model.HandleStep();
step2.Id = Const.Common_Notice_ApproveCompleted;
step2.Name = "审核完结";
handleSteps.Add(step2);
}
return handleSteps;
}
///
/// 根据用户主键获得通知的数量
///
/// 角色
///
public static int GetNoticeCountByUserId(string userId)
{
var q = (from x in Funs.DB.Common_Notice where x.ClearUpMan == userId select x).ToList();
return q.Count();
}
///
/// 获取已发布的审核完结的通知信息
///
/// 通知集合
public static List GetNotices(string systemId, string projectId)
{
var notice = from x in Funs.DB.Common_Notice where x.IsRelease == true select x;
if (!string.IsNullOrEmpty(projectId))
{
notice = notice.Where(e => (e.AccessSystemId.Contains(systemId) && e.AccessProjectId.Contains(projectId)) ||(e.SystemId == systemId && e.ProjectId == projectId));
}
else
{
notice = notice.Where(e => e.AccessSystemId.Contains(systemId) || e.SystemId == systemId);
}
return notice.ToList();
}
///
/// 根据项目ID查询通知信息
///
///
///
public static List GetNoticeByProjectId(string projectId)
{
return (from x in Funs.DB.Common_Notice where x.ProjectId == projectId select x).ToList();
}
}
}