using BLL; using Newtonsoft.Json.Linq; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.CQMS.ProjectHighlightsSite { public partial class ProjectHighlightsSitePic : PageBase { #region 定义项 /// /// 项目id /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId) { this.ProjectId = Request.Params["projectId"]; } ////权限按钮方法 this.GetButtonPower(); UpdateProjectHighlightsSiteType(); BLL.ProjectHighlightsSiteService.InitProjectHighlightsSiteTypeNameDropDownList(this.drpMainType, true); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { var q = (from x in Funs.DB.CQMS_ProjectHighlightsSitePic where x.ProjectId == this.ProjectId orderby x.MainType, x.SubType select x).ToList(); if (!string.IsNullOrWhiteSpace(this.drpMainType.SelectedValue) && this.drpMainType.SelectedValue != Const._Null) { q = q.Where(x => x.MainTypeName == this.drpMainType.SelectedValue).ToList(); } if (!string.IsNullOrWhiteSpace(this.drpReport.SelectedValue) && this.drpReport.SelectedValue != Const._Null) { q = q.Where(x => x.IsReport == (this.drpReport.SelectedValue == "1")).ToList(); } if (!string.IsNullOrWhiteSpace(this.drpUploadPic.SelectedValue) && this.drpUploadPic.SelectedValue != Const._Null) { q = q.Where(x => string.IsNullOrWhiteSpace(x.PicUrl) == (this.drpUploadPic.SelectedValue == "0")).ToList(); } Grid1.RecordCount = q.Count(); // 2.获取当前分页数据 var table = GetPagedDataTable(Grid1.PageIndex, Grid1.PageSize); Grid1.DataSource = table; Grid1.DataBind(); PageContext.RegisterStartupScript("showImg();"); } /// /// 项目亮点照片(放于Img中) /// /// /// protected string ConvertImageUrlByImage(object picUrl) { string url = string.Empty; if (picUrl != null && !string.IsNullOrWhiteSpace(picUrl.ToString())) { string httpUrl = string.Empty; var sysSet6 = (from x in Funs.DB.Sys_Set where x.SetName == "程序访问地址" select x).ToList().FirstOrDefault(); if (sysSet6 != null) { httpUrl = sysSet6.SetValue; } url = BLL.UploadAttachmentService.ShowImage(httpUrl, picUrl.ToString()); } return url; } /// /// 分页 /// /// private List GetPagedDataTable(int pageIndex, int pageSize) { List source = (from x in Funs.DB.CQMS_ProjectHighlightsSitePic where x.ProjectId == this.ProjectId orderby x.MainType, x.SubType select x).ToList(); List paged = new List(); if (!string.IsNullOrWhiteSpace(this.drpMainType.SelectedValue) && this.drpMainType.SelectedValue != Const._Null) { source = source.Where(x => x.MainTypeName == this.drpMainType.SelectedValue).ToList(); } if (!string.IsNullOrWhiteSpace(this.drpReport.SelectedValue) && this.drpReport.SelectedValue != Const._Null) { source = source.Where(x => x.IsReport == (this.drpReport.SelectedValue == "1")).ToList(); } if (!string.IsNullOrWhiteSpace(this.drpUploadPic.SelectedValue) && this.drpUploadPic.SelectedValue != Const._Null) { source = source.Where(x => string.IsNullOrWhiteSpace(x.PicUrl) == (this.drpUploadPic.SelectedValue == "0")).ToList(); } int rowbegin = pageIndex * pageSize; int rowend = (pageIndex + 1) * pageSize; if (rowend > source.Count()) { rowend = source.Count(); } for (int i = rowbegin; i < rowend; i++) { paged.Add(source[i]); } return paged; } /// /// 窗口关闭后刷新界面 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } /// /// 维护项目亮点 /// /// /// protected void btnMenuModify_Click(object sender, EventArgs e) { EditData(); } /// /// 双击维护项目亮点 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { btnMenuModify_Click(sender, e); } /// /// 删除项目亮点 /// /// /// protected void btnMenuDel_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); ProjectHighlightsSiteService.ResetProjectHighlightsSitePicById(rowID); } BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } /// /// 维护项目亮点 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length != 1) { Alert.ShowInTop("请选择一条记录", MessageBoxIcon.Warning); return; } if (this.btnMenuModify.Hidden)////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面 { Alert.ShowInTop("抱歉,您无权维护亮点!", MessageBoxIcon.Warning); return; //PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectHighlightsSitePicView.aspx?Id={0}", Grid1.SelectedRowID), "查看项目亮点")); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectHighlightsSitePicEdit.aspx?Id={0}", Grid1.SelectedRowID), "维护项目亮点")); } } /// /// 大类下拉触发事件 /// /// /// protected void drpMainType_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 过滤表头 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } #endregion /// /// 更新项目亮点类型 /// protected void UpdateProjectHighlightsSiteType() { var returnValue = ProjectHighlightsSiteService.UpdateProjectHighlightsSiteTypeFromGroup(this.ProjectId); if (returnValue) { BindGrid(); } else { Alert.ShowInTop("更新项目亮点类型失败", MessageBoxIcon.Success); } } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.ProjectHighlightsSitePicMenuId); if (buttonList.Count() > 0) { //if (buttonList.Contains(BLL.Const.BtnAdd)) //{ // this.btnNew.Hidden = false; //} if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuModify.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDel.Hidden = false; } } } #endregion } }