275 lines
9.9 KiB
C#
275 lines
9.9 KiB
C#
|
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 <b><script>{0}</script></b> 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);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 遍历节点
|
|||
|
/// </summary>
|
|||
|
/// <param name="nodes"></param>
|
|||
|
/// <param name="parentId"></param>
|
|||
|
/// <param name="type"></param>
|
|||
|
private void BoundTree(TreeNodeCollection nodes)
|
|||
|
{
|
|||
|
List<Model.EMC_ViolationClause> 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点击事件
|
|||
|
/// <summary>
|
|||
|
/// 选择角色事件
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
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<SqlParameter> parms = new List<SqlParameter>();
|
|||
|
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, "编辑 - ")));
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 编辑
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
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, "编辑 - ")));
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 右键编辑事件
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnMenuEdit_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
btnEdit_Click(null, null);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Grid行双击事件
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|||
|
{
|
|||
|
btnEdit_Click(null, null);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 删除数据
|
|||
|
/// <summary>
|
|||
|
/// 批量删除数据
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnDelete_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.DeleteData();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 右键删除事件
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void btnMenuDelete_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.DeleteData();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 删除方法
|
|||
|
/// </summary>
|
|||
|
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 关闭弹出窗口
|
|||
|
/// <summary>
|
|||
|
/// 关闭窗口
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Window1_Close(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.BindGrid(this.tvViolationClause.SelectedNodeID);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|||
|
{
|
|||
|
Grid1.SortDirection = e.SortDirection;
|
|||
|
Grid1.SortField = e.SortField;
|
|||
|
this.BindGrid(this.tvViolationClause.SelectedNodeID);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#region 判断是否可删除
|
|||
|
/// <summary>
|
|||
|
/// 判断是否可以删除
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
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 权限设置
|
|||
|
/// <summary>
|
|||
|
/// 菜单按钮权限
|
|||
|
/// </summary>
|
|||
|
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
|
|||
|
}
|
|||
|
}
|