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.BaseInfo { public partial class ViolationClause : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower();//权限设置 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()); InitTreeMenu(); // 绑定表格 //BindGrid(); } } #region 加载树 private void InitTreeMenu() { this.tvViolationClause.Nodes.Clear(); TreeNode rootRole = new TreeNode(); rootRole.Text = "违章条款"; rootRole.NodeID = "0"; rootRole.Expanded = true; this.tvViolationClause.Nodes.Add(rootRole); BoundTree(rootRole.Nodes); } /// /// 遍历节点 /// /// /// /// private void BoundTree(TreeNodeCollection nodes) { List supVio = BLL.ViolationClauseService.GetSupViolationClause(); if (supVio.Count() > 0) { TreeNode tn = null; foreach (var q in supVio) { tn = new TreeNode(); tn.Text = q.ClauseDef; tn.NodeID = q.ViolationClauseId; tn.EnableClickEvent = true; nodes.Add(tn); } } } #endregion #region Tree点击事件 /// /// 选择角色事件 /// /// /// protected void tvViolationClause_NodeCommand(object sender, TreeCommandEventArgs e) { this.BindGrid(this.tvViolationClause.SelectedNodeID); } #endregion private void BindGrid(string supViolationClauseId) { string strSql = @"SELECT ViolationClauseId,ClauseDef,ApplicationDef, (CASE WHEN (DeductionIndividual1=0 OR DeductionIndividual1 IS NULL) THEN 'N/A' ELSE CAST(CAST(DeductionIndividual1 AS REAL) AS VARCHAR) END) AS DeductionIndividual1, (CASE WHEN (DeductionComPany1=0 OR DeductionComPany1 IS NULL) THEN 'N/A' ELSE CAST(CAST(DeductionComPany1 AS REAL) AS VARCHAR) END) AS DeductionComPany1, (CASE WHEN (DeductionIndividual2=0 OR DeductionIndividual2 IS NULL) THEN 'N/A' ELSE CAST(CAST(DeductionIndividual2 AS REAL) AS VARCHAR) END) AS DeductionIndividual2, (CASE WHEN (DeductionComPany2=0 OR DeductionComPany2 IS NULL) THEN 'N/A' ELSE CAST(CAST(DeductionComPany2 AS REAL) AS VARCHAR) END) AS DeductionComPany2, (CASE WHEN (DeductionIndividual3=0 OR DeductionIndividual3 IS NULL) THEN 'N/A' ELSE CAST(CAST(DeductionIndividual3 AS REAL) AS VARCHAR) END) AS DeductionIndividual3, (CASE WHEN (DeductionComPany3=0 OR DeductionComPany3 IS NULL) THEN 'N/A' ELSE CAST(CAST(DeductionComPany3 AS REAL) AS VARCHAR) END) AS DeductionComPany3 FROM dbo.EMC_ViolationClause WHERE SupViolationClause=@SupViolationClause ORDER BY SortIndex"; List parms = new List(); parms.Add(new SqlParameter("@SupViolationClause", supViolationClauseId)); SqlParameter[] parameter = parms.ToArray(); DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 Grid1.DataSource = dt; Grid1.DataBind(); } #region 编辑 protected void btnAdd_Click(object sender, EventArgs e) { if (tvViolationClause.SelectedNodeID=="" || tvViolationClause.SelectedNodeID =="0") { Alert.ShowInParent("Please select Tree Node!"); return; } string Id = tvViolationClause.SelectedNodeID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ViolationClauseEdit.aspx?supViolationClauseId={0}", Id, "编辑 - "))); } /// /// 编辑 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent("Please select at least one record!"); return; } string Id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ViolationClauseEdit.aspx?violationClauseId={0}", Id, "编辑 - "))); } /// /// 右键编辑事件 /// /// /// 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 删除数据 /// /// 批量删除数据 /// /// /// 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 role = BLL.ViolationClauseService.GetViolationClause(rowID); if (role != null) { if (judgementDelete(rowID, false)) { BLL.ViolationClauseService.DeleteViolationClause(rowID); } } } this.BindGrid(this.tvViolationClause.SelectedNodeID); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete Violation Clause"); ShowNotify("Deleted successfully!"); } } #endregion #region 关闭弹出窗口 /// /// 关闭窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { this.BindGrid(this.tvViolationClause.SelectedNodeID); } #endregion /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; this.BindGrid(this.tvViolationClause.SelectedNodeID); } #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; if (Funs.DB.EMC_Punishment.FirstOrDefault(x => x.ViolationClauseId == id) != null) { content = "This role is already in use in [违章条款] and cannot be deleted!"; } 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.ViolationClauseMenuId); 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; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnDelete.Hidden = false; this.btnMenuDelete.Hidden = false; } } } #endregion } }