using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; using Model; using System.IO; namespace FineUIPro.Web.common.Notice { public partial class AddNotice : PageBase { #region 定义项 public string NoticeId { get { return (string)ViewState["NoticeId"]; } set { ViewState["NoticeId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); this.drpClearUpMan.DataTextField = "UserName"; drpClearUpMan.DataValueField = "UserId"; drpClearUpMan.DataSource = (from x in Funs.DB.Sys_User where x.IsPost == true orderby x.UserName select x).ToList(); drpClearUpMan.DataBind(); Funs.FineUIPleaseSelect(this.drpClearUpMan); var systems = Funs.DB.Sys_System.FirstOrDefault(x => x.SystemId == this.CurrUser.LoginSystemId); if (systems != null) { if (systems.SystemType == Const.SystemType_0 || (systems.SystemType == Const.SystemType_1 && systems.IsMoreProject == false)) { this.drpProjects.DataTextField = "ProjectName"; this.drpProjects.DataValueField = "ProjectId"; this.drpProjects.DataSource = (from x in Funs.DB.Base_Project orderby x.StartDate select x).ToList(); this.drpProjects.DataBind(); var systemSelect = (from x in Funs.DB.Sys_System where x.IsEnable == true orderby x.SorIndex select x).ToList(); if (this.CurrUser.LoginSystemId != Const.System_1) { string projectSystemId = (Funs.GetNewInt(this.CurrUser.LoginSystemId) + 1).ToString(); systemSelect = systemSelect = systemSelect.Where(x => (x.SystemId == this.CurrUser.LoginSystemId || x.SystemId == projectSystemId)).OrderBy(x => x.SorIndex).ToList(); } if (systemSelect.Count() > 0) { this.drpSystems.DataTextField = "SystemName"; this.drpSystems.DataValueField = "SystemId"; this.drpSystems.DataSource = systemSelect; this.drpSystems.DataBind(); } } else { this.trProjects.Hidden = true; this.trSystems.Hidden = true; } } this.drpSignMan.DataTextField = "UserName"; drpSignMan.DataValueField = "UserId"; ////签字人 if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { drpSignMan.DataSource = (from x in Funs.DB.Sys_User join y in Funs.DB.Project_User on x.UserId equals y.UserId where (x.IsPost == true && y.ProjectId == this.CurrUser.LoginProjectId) || (x.UserId == Const.GlyId) orderby x.UserName select x).ToList(); } else { drpSignMan.DataSource = (from x in Funs.DB.Sys_User where x.IsPost == true orderby x.UserName select x).ToList(); } drpSignMan.DataBind(); Funs.FineUIPleaseSelect(this.drpSignMan); this.NoticeId = Request.QueryString["noticeId"]; if (!String.IsNullOrEmpty(this.NoticeId)) { this.txtNoticeCode.Readonly = true; Model.Common_Notice notice = BLL.Common_NoticeService.GetNoticeByNoticeId(NoticeId); if (notice != null) { this.txtNoticeCode.Text = notice.NoticeCode; this.txtNoticeTitle.Text = notice.NoticeTitle; if (notice.ClearUpMan != null) { this.drpClearUpMan.SelectedValue = notice.ClearUpMan; } this.drpIsRelease.SelectedValue = notice.IsRelease.ToString(); this.txtMainContent.Text = notice.MainContent; this.drpProjects.SelectedValue = notice.AccessProjectId; this.drpSystems.SelectedValue = notice.AccessSystemId; } } else { this.drpClearUpMan.SelectedValue = this.CurrUser.UserId; } } } private void LoadData() { btnClose.OnClientClick = ActiveWindow.GetHideReference(); } #endregion #region 提交 /// /// 提交按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (this.GetRolePowerBySystemMenuId(BLL.Const.BtnSave)) { SaveData(true); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } /// /// 提交数据 /// private void SaveData(bool isClose) { if (isClose) { if (this.drpClearUpMan.SelectedValue == BLL.Const._Null) { ShowNotify("请选择整理人!", MessageBoxIcon.Warning); return; } if (this.drpSignMan.SelectedValue == BLL.Const._Null) { ShowNotify("请选择办理人员!", MessageBoxIcon.Warning); return; } } Model.Common_Notice notice = new Model.Common_Notice(); if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { notice.ProjectId = this.CurrUser.LoginProjectId;//当前项目 } notice.SystemId = this.CurrUser.LoginSystemId; //当前系统 notice.NoticeCode = this.txtNoticeCode.Text.Trim(); notice.NoticeTitle = this.txtNoticeTitle.Text.Trim(); notice.IsRelease = Convert.ToBoolean(this.drpIsRelease.SelectedValue); if (this.drpClearUpMan.SelectedValue != "0") { notice.ClearUpMan = this.drpClearUpMan.SelectedValue; } else { notice.ClearUpMan = null; } notice.MainContent = this.txtMainContent.Text.Trim(); if (this.drpSignMan.SelectedValue == "0") { notice.State = Const.Common_Notice_Compile; } else { notice.State = Const.Common_Notice_Check; } if (this.drpProjects.SelectedItemArray.Count() > 0) { string projectIds = string.Empty; string projectTexts = string.Empty; foreach (ListItem item in this.drpProjects.SelectedItemArray) { projectIds += item.Value + ","; projectTexts += item.Text + ","; } if (!string.IsNullOrEmpty(projectIds)) { projectIds = projectIds.Substring(0, projectIds.LastIndexOf(",")); } if (!string.IsNullOrEmpty(projectTexts)) { projectTexts = projectTexts.Substring(0, projectTexts.LastIndexOf(",")); } notice.AccessProjectId = projectIds; notice.AccessProjectText = projectTexts; } else { notice.AccessProjectId = this.CurrUser.LoginProjectId; } if (this.drpSystems.SelectedIndexArray.Count() > 0) { string systemIds = string.Empty; string systemTexts = string.Empty; foreach (ListItem item in this.drpSystems.SelectedItemArray) { systemIds += item.Value + ","; systemTexts += item.Text + ","; } if (!string.IsNullOrEmpty(systemIds)) { systemIds = systemIds.Substring(0, systemIds.LastIndexOf(",")); } if (!string.IsNullOrEmpty(systemTexts)) { systemTexts = systemTexts.Substring(0, systemTexts.LastIndexOf(",")); } notice.AccessSystemId = systemIds; notice.AccessSystemText = systemTexts; } else { notice.AccessSystemId = this.CurrUser.LoginSystemId; } string newKeyID = SQLHelper.GetNewID(typeof(Model.Common_Notice)); if (!string.IsNullOrEmpty(NoticeId)) { notice.NoticeId = NoticeId; Model.Common_Notice notice1 = BLL.Common_NoticeService.GetNoticeByNoticeId(NoticeId); BLL.Common_NoticeService.UpdateNotice(notice); if (notice1.State == Const.Common_Notice_ReCompile) { Model.Common_NoticeSign noticeSign1 = BLL.Common_NoticeSignService.GetNoticeSignByNoticeId(NoticeId); noticeSign1.SinaDate = DateTime.Now; noticeSign1.IsAgree = true; BLL.Common_NoticeSignService.UpdateNoticeSign(noticeSign1); } BLL.Sys_LogService.AddLog(this.CurrUser.LoginSystemId, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改通知"); } else { notice.NoticeId = newKeyID; NoticeId = newKeyID; notice.CompileDate = System.DateTime.Now; BLL.Common_NoticeService.AddNotice(notice); BLL.Sys_LogService.AddLog(this.CurrUser.LoginSystemId, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加通知"); } if (this.drpSignMan.SelectedValue != BLL.Const._Null) { Model.Common_NoticeSign noticeSign = new Model.Common_NoticeSign(); noticeSign.NoticeId = notice.NoticeId; noticeSign.SignMan = this.drpSignMan.SelectedValue; noticeSign.SignStep = this.drpSignStep.SelectedValue; BLL.Common_NoticeSignService.AddNoticeSign(noticeSign); } BLL.Sys_LogService.AddLog(this.CurrUser.LoginSystemId, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "编制通知"); if (isClose) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } #endregion #region 上传附件资源 /// /// 上传附件资源 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.NoticeId)) { SaveData(false); } string menuId = string.Empty; if (this.CurrUser.LoginSystemId == Const.System_1) { menuId = BLL.Const.Common_NoticeMenuId; } string edit = "0"; if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, menuId, BLL.Const.BtnSave)) { edit = "1"; } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Notice&menuId={1}&edit={2}", NoticeId, menuId, edit))); } #endregion #region 根据不同的系统id得到该菜单的权限 /// /// 根据不同的系统id得到该菜单的权限 /// /// 按钮类型 /// private bool GetRolePowerBySystemMenuId(string btnType) { bool isRole = false; if (this.CurrUser.LoginSystemId == Const.System_1) { isRole = BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.Common_NoticeMenuId, btnType); } return isRole; } #endregion } }