430 lines
14 KiB
C#
430 lines
14 KiB
C#
|
|
using BLL;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Data.SqlClient;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace FineUIPro.Web.BaseInfo
|
|||
|
|
{
|
|||
|
|
public partial class SafetyProblemNature : PageBase
|
|||
|
|
{
|
|||
|
|
#region 加载
|
|||
|
|
/// <summary>
|
|||
|
|
/// 加载页面
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (!IsPostBack)
|
|||
|
|
{
|
|||
|
|
Funs.DropDownPageSize(this.ddlPageSize);
|
|||
|
|
this.GetButtonPower();
|
|||
|
|
InitTreeMenu();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 加载树
|
|||
|
|
/// <summary>
|
|||
|
|
/// 初始化树
|
|||
|
|
/// </summary>
|
|||
|
|
private void InitTreeMenu()
|
|||
|
|
{
|
|||
|
|
trObj.Nodes.Clear();
|
|||
|
|
trObj.ShowBorder = false;
|
|||
|
|
trObj.ShowHeader = false;
|
|||
|
|
trObj.EnableIcons = true;
|
|||
|
|
trObj.AutoScroll = true;
|
|||
|
|
trObj.EnableSingleClickExpand = true;
|
|||
|
|
TreeNode rootNode = new TreeNode
|
|||
|
|
{
|
|||
|
|
Text = "安全问题性质",
|
|||
|
|
NodeID = "0",
|
|||
|
|
Expanded = true
|
|||
|
|
};
|
|||
|
|
this.trObj.Nodes.Add(rootNode);
|
|||
|
|
BoundTree(rootNode.Nodes, "0");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void BoundTree(TreeNodeCollection nodes, string menuId)
|
|||
|
|
{
|
|||
|
|
var dt = GetNewTraining();
|
|||
|
|
if (dt.Count() > 0)
|
|||
|
|
{
|
|||
|
|
TreeNode tn = null;
|
|||
|
|
foreach (var dr in dt)
|
|||
|
|
{
|
|||
|
|
tn = new TreeNode
|
|||
|
|
{
|
|||
|
|
Text = dr.NatureName,
|
|||
|
|
NodeID = dr.NatureId,
|
|||
|
|
EnableClickEvent = true,
|
|||
|
|
ToolTip = dr.NatureName
|
|||
|
|
};
|
|||
|
|
nodes.Add(tn);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 得到菜单方法
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="parentId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private List<Model.Base_SafetyProblemNature> GetNewTraining()
|
|||
|
|
{
|
|||
|
|
return (from x in Funs.DB.Base_SafetyProblemNature orderby x.NatureCode select x).ToList(); ;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 增加、修改、删除安全问题性质类别
|
|||
|
|
/// <summary>
|
|||
|
|
/// 增加安全问题性质类别
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnNew_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode != null)
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode.NodeID == "0") //根节点或者非末级节点,可以增加
|
|||
|
|
{
|
|||
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SafetyProblemNatureSave.aspx", this.trObj.SelectedNode.NodeID, "编辑 - ")));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("选择的项已是末级!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 修改安全问题性质类别
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnEdit_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode != null)
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode.NodeID != "0") //非根节点可以编辑
|
|||
|
|
{
|
|||
|
|
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SafetyProblemNatureSave.aspx?NatureId={0}", this.trObj.SelectedNode.NodeID, "编辑 - ")));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("根节点无法编辑!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 删除安全问题性质类别
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnDelete_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode != null)
|
|||
|
|
{
|
|||
|
|
var q = BLL.SafetyProblemNatureService.GetNatureById(this.trObj.SelectedNode.NodeID);
|
|||
|
|
|
|||
|
|
if (q != null)
|
|||
|
|
{
|
|||
|
|
BLL.SafetyProblemNatureService.DeleteNature(this.trObj.SelectedNode.NodeID);
|
|||
|
|
InitTreeMenu();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("存在下级菜单或已增加资源数据或者为内置项,不允许删除!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("请选择删除项!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 树点击事件
|
|||
|
|
/// <summary>
|
|||
|
|
/// 树点击事件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void trObj_NodeCommand(object sender, FineUIPro.TreeCommandEventArgs e)
|
|||
|
|
{
|
|||
|
|
BindGrid();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 下拉触发事件
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 适用岗位下拉触发事件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void drp_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
this.BindGrid();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 绑定数据
|
|||
|
|
/// <summary>
|
|||
|
|
/// 绑定数据
|
|||
|
|
/// </summary>
|
|||
|
|
private void BindGrid()
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode != null && !string.IsNullOrEmpty(this.trObj.SelectedNode.NodeID))
|
|||
|
|
{
|
|||
|
|
StringBuilder sb = new StringBuilder();
|
|||
|
|
sb.Append("SELECT item.NatureItemId,item.NatureId,item.NatureItemCode,item.NatureItemType,item.NatureItemContent,item.NatureItemDep,item.CompileMan, item.CompileDate ");
|
|||
|
|
sb.Append("FROM dbo.Base_SafetyProblemNatureItem AS item ");
|
|||
|
|
sb.Append("WHERE item.NatureId=@NatureId ");
|
|||
|
|
|
|||
|
|
List<SqlParameter> listStr = new List<SqlParameter>
|
|||
|
|
{
|
|||
|
|
new SqlParameter("@NatureId", this.trObj.SelectedNode.NodeID)
|
|||
|
|
};
|
|||
|
|
if (!string.IsNullOrEmpty(this.txtNatureItemCode.Text.Trim()))
|
|||
|
|
{
|
|||
|
|
sb.Append("AND NatureItemCode LIKE @NatureItemCode ");
|
|||
|
|
listStr.Add(new SqlParameter("@NatureItemCode", "%" + this.txtNatureItemCode.Text.Trim() + "%"));
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(this.txtNatureItemName.Text.Trim()))
|
|||
|
|
{
|
|||
|
|
sb.Append("AND NatureItemName LIKE @NatureItemName ");
|
|||
|
|
listStr.Add(new SqlParameter("@NatureItemName", "%" + this.txtNatureItemName.Text.Trim() + "%"));
|
|||
|
|
}
|
|||
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|||
|
|
DataTable tb = SQLHelper.GetDataTableRunText(sb.ToString(), parameter);
|
|||
|
|
|
|||
|
|
Grid1.RecordCount = tb.Rows.Count;
|
|||
|
|
var table = this.GetPagedDataTable(Grid1, tb);
|
|||
|
|
|
|||
|
|
Grid1.DataSource = table;
|
|||
|
|
Grid1.DataBind();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 弹出窗关闭事件
|
|||
|
|
protected void Window1_Close(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
InitTreeMenu();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected void Window2_Close(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
BindGrid();
|
|||
|
|
}
|
|||
|
|
#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 查询
|
|||
|
|
/// <summary>
|
|||
|
|
/// 查询
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
this.BindGrid();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 增加、修改、删除明细信息
|
|||
|
|
#region 新增明细
|
|||
|
|
/// <summary>
|
|||
|
|
/// 新增明细
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnNewDetail_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode != null)
|
|||
|
|
{
|
|||
|
|
if (this.trObj.SelectedNode.Nodes.Count == 0)
|
|||
|
|
{
|
|||
|
|
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("SafetyProblemNatureItemSave.aspx?NatureId={0}", this.trObj.SelectedNode.NodeID, "编辑 - ")));
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("请选择末级节点!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 编辑明细
|
|||
|
|
protected void btnEditDetail_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
this.EditData();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
|||
|
|
{
|
|||
|
|
this.EditData();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 右键编辑事件
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnMenuEdit_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
this.EditData();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 编辑数据方法
|
|||
|
|
/// </summary>
|
|||
|
|
private void EditData()
|
|||
|
|
{
|
|||
|
|
if (Grid1.SelectedRowIndexArray.Length == 0)
|
|||
|
|
{
|
|||
|
|
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
string Id = this.trObj.SelectedNode.Nodes.Count == 0 ? this.trObj.SelectedNode.NodeID : string.Empty;
|
|||
|
|
string itemId = Grid1.SelectedRowID;
|
|||
|
|
//itemId = itemId.Substring(0, itemId.IndexOf("_"));
|
|||
|
|
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("SafetyProblemNatureItemSave.aspx?NatureItemId={0}&NatureId={1}", itemId, Id, "编辑 - ")));
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 删除明细
|
|||
|
|
// 删除数据
|
|||
|
|
protected void btnDeleteDetail_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();
|
|||
|
|
//rowID = rowID.Substring(0, rowID.IndexOf("_"));
|
|||
|
|
|
|||
|
|
var getD = BLL.SafetyProblemNatureItemService.GetNatureItemById(rowID);
|
|||
|
|
if (getD != null)
|
|||
|
|
{
|
|||
|
|
BLL.LogService.AddSys_Log(this.CurrUser, getD.NatureItemCode, getD.NatureItemId, BLL.Const.SafetyProblemNatureMenuId, BLL.Const.BtnDelete);
|
|||
|
|
BLL.SafetyProblemNatureItemService.DeleteNatureItemById(rowID);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
BindGrid();
|
|||
|
|
ShowNotify("删除数据成功!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region 按钮权限
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取按钮权限
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="button"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private void GetButtonPower()
|
|||
|
|
{
|
|||
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SafetyProblemNatureMenuId);
|
|||
|
|
if (buttonList.Count() > 0)
|
|||
|
|
{
|
|||
|
|
if (buttonList.Contains(BLL.Const.BtnAdd))
|
|||
|
|
{
|
|||
|
|
this.btnNew.Hidden = false;
|
|||
|
|
this.btnNewDetail.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
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 导出
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
protected void btnOut_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Response.ClearContent();
|
|||
|
|
string filename = Funs.GetNewFileName();
|
|||
|
|
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("安全问题性质" + filename, System.Text.Encoding.UTF8) + ".xls");
|
|||
|
|
Response.ContentType = "application/excel";
|
|||
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|||
|
|
this.Grid1.PageSize = Grid1.RecordCount;
|
|||
|
|
BindGrid();
|
|||
|
|
Response.Write(GetGridTableHtml(Grid1));
|
|||
|
|
Response.End();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|