using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using BLL; namespace FineUIPro.Web.Customization.CNCCG.HSSE.Check { public partial class SafetyOfficerCheck : PageBase { /// /// 页面加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ////权限按钮方法 this.GetButtonPower(); this.btnNew.OnClientClick = Window1.GetShowReference("SafetyOfficerCheckEdit.aspx") + "return false;"; if (this.CurrUser != null && this.CurrUser.PageSize.HasValue) { Grid1.PageSize = this.CurrUser.PageSize.Value; } this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 this.BindGrid(); } } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var menuid = Const.Check_SafetyOfficerCheckMenuId; var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, menuid); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; } } } #endregion /// /// 获取整改前图片(放于Img中) /// /// /// protected string ConvertImageUrlByImage(object SafetyOfficerCheckId) { string url = string.Empty; 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; } //httpUrl = "http://localhost:2372/"; if (SafetyOfficerCheckId != null) { var model = Funs.DB.Check_SafetyOfficerCheck.FirstOrDefault(x => x.SafetyOfficerCheckId == SafetyOfficerCheckId.ToString()); if (model != null) { url = BLL.UploadAttachmentService.ShowImage(httpUrl, model.ImageUrl); } } return url; } #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT CASE WHEN State='0' then '待提交' when State='1' then '待生成日常巡检' when State='2' then '已生成日常巡检' END as StatesNr,F.State,F.CompileDate,F.SafetyOfficerCheckId,F.ImageUrl,F.HandleIdea, CompileManUser.UserName as CompileManUser, rUser.UserName as rUser FROM Check_SafetyOfficerCheck as F LEFT JOIN Sys_User AS CompileManUser ON F.CompileMan =CompileManUser.UserId LEFT JOIN Sys_User AS rUser ON F.ReceiveMan =rUser.UserId left join Project_ProjectUser AS PUser on F.ReceiveMan=PUser.UserId WHERE 1=1 "; var userId = CurrUser.UserId; if (!string.IsNullOrEmpty(CurrUser.LoginProjectId)) { strSql += " and PUser.ProjectId='" + CurrUser.LoginProjectId + "' "; } List listStr = new List(); //发送文件页面 //管理员可以看到所有 if (userId == Const.sysglyId || userId == Const.hfnbdId) { } else { //不是管理员只能看到自己编制的或接收人是自己的 strSql += " AND (CompileMan = @CompileMan or ReceiveMan=@ReceiveMan) "; listStr.Add(new SqlParameter("@CompileMan", CurrUser.UserId)); listStr.Add(new SqlParameter("@ReceiveMan", CurrUser.UserId)); } if (!string.IsNullOrEmpty(ckState.SelectedValue)) { strSql += " AND F.State = @State"; listStr.Add(new SqlParameter("@State", ckState.SelectedValue)); } strSql += " order by CompileDate "; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #region 分页 排序 /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { this.BindGrid(); } #endregion #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var getV = Funs.DB.Check_SafetyOfficerCheck.FirstOrDefault(x => x.SafetyOfficerCheckId == rowID); if (getV != null) { BLL.SafetyOfficerCheckService.Delete(rowID); } } this.BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region 生成日常巡检 protected void btnbtnMenuGenerate_Click(object sender, EventArgs e) { string id = Grid1.SelectedRowID; var model = Funs.DB.Check_SafetyOfficerCheck.FirstOrDefault(x => x.SafetyOfficerCheckId == id); if (model!=null) { //判断是否有权限生成 if (model.State!="1") { ShowNotify("当前状态不是待生成,不允许该操作!", MessageBoxIcon.Warning); return; } if (model.ReceiveMan!=CurrUser.UserId) { ShowNotify("您不是当前接收人,无权限执行该操作!", MessageBoxIcon.Warning); return; } } this.Window1.Title = "生成日常巡检"; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SafetyOfficerCheckView.aspx?SafetyOfficerCheckId={0}&type=1", id, "查看 - "))); } #endregion #region 编辑 /// /// 双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { string id = Grid1.SelectedRowID; var model = Funs.DB.Check_SafetyOfficerCheck.FirstOrDefault(x => x.SafetyOfficerCheckId == id); if (model != null) { //判断是否有权限生成 if (model.State == "2") { ShowNotify("已生成日常巡检,不允许编辑操作!", MessageBoxIcon.Warning); return; } } this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; var model = Funs.DB.Check_SafetyOfficerCheck.FirstOrDefault(x => x.SafetyOfficerCheckId == id); if (model != null) { var userId = CurrUser.UserId; //待提交 if (model.State == "0" && (model.CompileMan==CurrUser.UserId || userId == Const.sysglyId || userId == Const.hfnbdId)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SafetyOfficerCheckEdit.aspx?SafetyOfficerCheckId={0}", id, "编辑 - "))); } //否则是详情页 else { //否则是查看页面 this.Window1.Title = "详情"; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SafetyOfficerCheckView.aspx?SafetyOfficerCheckId={0}", id, "查看 - "))); } } } #endregion } }