using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.EditorManage { public partial class PunchEditorList : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string view = Request.Params["view"]; if (view=="1") { this.btnNew.Hidden = true; this.btnEdit.Hidden = true; this.btnMenuEdit.Hidden = true; this.btnDelete.Hidden = true; this.btnMenuDelete.Hidden = true; } else { GetButtonPower();//权限设置 } btnNew.OnClientClick = Window1.GetShowReference("PunchEditorEdit.aspx?eProjectId=" + Request.Params["eProjectId"]) + "return false;"; btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("Please select at least one item!"); btnDelete.ConfirmText = String.Format("Are you sure you want to delete the selected   rows?", Grid1.GetSelectedCountReference()); this.drpDiscipline.DataValueField = "ConstId"; this.drpDiscipline.DataTextField = "ConstText"; this.drpDiscipline.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.PunchDetails_Discipline); this.drpDiscipline.DataBind(); Funs.FineUIPleaseSelectPunshDiscipline(this.drpDiscipline); this.drpClass.DataValueField = "ConstId"; this.drpClass.DataTextField = "ConstText"; this.drpClass.DataSource = BLL.ConstService.GetConstListByGroupId(BLL.Const.Resourses_Class); this.drpClass.DataBind(); Funs.FineUIPleaseSelectPunshClass(this.drpClass); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT p.PunchId, p.EProjectId,p.Area,p.DisciplineId, p.DisciplineName, p.ActionType, p.ClassId, p.ClassName, p.TagNo, p.RespUnitPerson, p.ResiedById, p.ResiedByName, p.BYC_Person,p.InitiatedByName, p.InitiatedByDate,p.PlanedFinishDate, p.Description, p.CTECheckerId, p.CTECheckerName, p.CTECheckDate, p.OwnerCheckDate, p.Remark FROM dbo.Editor_Punch p WHERE p.EProjectId=@eProjectId "; List listStr = new List(); listStr.Add(new SqlParameter("@eProjectId", Request.Params["eProjectId"])); if (this.drpDiscipline.SelectedValue != BLL.Const._Null) { strSql += " AND p.DisciplineId=@DisciplineId "; listStr.Add(new SqlParameter("@DisciplineId", this.drpDiscipline.SelectedValue)); } if (this.drpClass.SelectedValue != BLL.Const._Null) { strSql += " AND p.ClassId=@ClassId "; listStr.Add(new SqlParameter("@ClassId", this.drpClass.SelectedValue)); } if (!string.IsNullOrEmpty(txtChecker.Text.Trim())) { strSql += " AND p.CTECheckerName LIKE @Checker "; listStr.Add(new SqlParameter("@Checker", this.txtChecker.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 删除数据 /// /// 批量删除数据 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var punch = BLL.PunchService.GetPunchById(rowID); if (punch != null) { if (this.CurrUser.UserName == punch.ResiedByName || this.CurrUser.UserId == BLL.Const.GlyId) { if (judgementDelete(rowID, false)) { BLL.PunchService.DeletePunshById(rowID); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete Punch Editor information"); ShowNotify("Deleted successfully!"); BindGrid(); } } else { ShowAlert("该Punch的Resied By不是您,不能删除!", MessageBoxIcon.Warning); return; } } } } } #endregion #region 分页、排序 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 关闭弹出窗口 /// /// 关闭窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #region 编辑 /// /// 编辑 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("Please select at least one record!"); return; } string eprojectId = Request.Params["eProjectId"]; string Id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PunchEditorEdit.aspx?PunchId={0}&eProjectId={1}", Id, eprojectId, "编辑 - "))); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { btnEdit_Click(null, null); } /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { btnEdit_Click(null, null); } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content); } return false; } } #endregion #region 权限设置 /// /// 菜单按钮权限 /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.PunchMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnEdit.Hidden = false; this.btnMenuEdit.Hidden = false; this.Grid1.EnableRowDoubleClickEvent = true; } else { this.Grid1.EnableRowDoubleClickEvent = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnDelete.Hidden = false; this.btnMenuDelete.Hidden = false; } } } #endregion #region 查询 /// /// 查询 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } #endregion #region 查看 /// /// 查看 /// /// /// protected void btnMenuView_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("Please select at least one record!"); return; } string Id = Grid1.SelectedRowID; var eproject = BLL.EProjectService.GeteProjectById(Id); if (eproject != null) { Window1.Title = "Punch Editor(Job No. " + eproject.ProjectControl_JobNo + ")"; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PunchEditorList.aspx?eProjectId={0}&view=1", Id, "编辑 - "))); } #endregion } }