541 lines
20 KiB
C#
541 lines
20 KiB
C#
using BLL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using AspNet = System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.BaseInfo
|
|
{
|
|
public partial class SafetyProblemClassify : 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.ClassifyName,
|
|
NodeID = dr.ClassifyId,
|
|
EnableClickEvent = true,
|
|
ToolTip = dr.ClassifyName
|
|
};
|
|
nodes.Add(tn);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到菜单方法
|
|
/// </summary>
|
|
/// <param name="parentId"></param>
|
|
/// <returns></returns>
|
|
private List<Model.Base_SafetyProblemClassify> GetNewTraining()
|
|
{
|
|
return (from x in Funs.DB.Base_SafetyProblemClassify orderby x.ClassifyCode 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("SafetyProblemClassifySave.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("SafetyProblemClassifySave.aspx?ClassifyId={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.SafetyProblemClassifyService.GetClassifyById(this.trObj.SelectedNode.NodeID);
|
|
|
|
if (q != null)
|
|
{
|
|
BLL.SafetyProblemClassifyService.DeleteClassify(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.ClassifyItemId,item.ClassifyId,item.ClassifyItemCode,item.ClassifyItemName,item.CompileMan, item.CompileDate ");
|
|
sb.Append("FROM dbo.Base_SafetyProblemClassifyItem AS item ");
|
|
sb.Append("WHERE item.ClassifyId=@ClassifyId ");
|
|
|
|
List<SqlParameter> listStr = new List<SqlParameter>
|
|
{
|
|
new SqlParameter("@ClassifyId", this.trObj.SelectedNode.NodeID)
|
|
};
|
|
if (!string.IsNullOrEmpty(this.txtClassifyItemCode.Text.Trim()))
|
|
{
|
|
sb.Append("AND ClassifyItemCode LIKE @ClassifyItemCode ");
|
|
listStr.Add(new SqlParameter("@ClassifyItemCode", "%" + this.txtClassifyItemCode.Text.Trim() + "%"));
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtClassifyItemName.Text.Trim()))
|
|
{
|
|
sb.Append("AND ClassifyItemName LIKE @ClassifyItemName ");
|
|
listStr.Add(new SqlParameter("@ClassifyItemName", "%" + this.txtClassifyItemName.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("SafetyProblemClassifyItemSave.aspx?ClassifyId={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 itemId = Grid1.SelectedRowID;
|
|
//itemId = itemId.Substring(0, itemId.IndexOf("_"));
|
|
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("SafetyProblemClassifyItemSave.aspx?ClassifyItemId={0}", itemId, "编辑 - ")));
|
|
}
|
|
#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.SafetyProblemClassifyItemService.GetClassifyItemById(rowID);
|
|
if (getD != null)
|
|
{
|
|
BLL.LogService.AddSys_Log(this.CurrUser, getD.ClassifyItemCode, getD.ClassifyItemId, BLL.Const.SafetyProblemClassifyMenuId, BLL.Const.BtnDelete);
|
|
BLL.SafetyProblemClassifyItemService.DeleteClassifyItemById(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.SafetyProblemClassifyMenuId);
|
|
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();
|
|
}
|
|
|
|
#region 导出方法
|
|
///// <summary>
|
|
///// 导出方法
|
|
///// </summary>
|
|
///// <param name="grid"></param>
|
|
///// <returns></returns>
|
|
//public static string GetGridTableHtml(Grid grid, int count)
|
|
//{
|
|
// StringBuilder sb = new StringBuilder();
|
|
// sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
|
|
// sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
|
|
// sb.Append("<tr>");
|
|
// foreach (GridColumn column in grid.Columns)
|
|
// {
|
|
// if (column.ColumnIndex < count)
|
|
// {
|
|
// sb.AppendFormat("<td>{0}</td>", column.HeaderText);
|
|
// }
|
|
// }
|
|
// sb.Append("</tr>");
|
|
// foreach (GridRow row in grid.Rows)
|
|
// {
|
|
// sb.Append("<tr>");
|
|
// foreach (GridColumn column in grid.Columns)
|
|
// {
|
|
// if (column.ColumnIndex < count)
|
|
// {
|
|
// string html = row.Values[column.ColumnIndex].ToString();
|
|
// if (column.ColumnID == "tfNumber" && (row.FindControl("lbNumber") as AspNet.Label) != null)
|
|
// {
|
|
// html = (row.FindControl("lbNumber") as AspNet.Label).Text;
|
|
// }
|
|
// if (column.ColumnID == "tfCompanyTrainingItemCode" && (row.FindControl("lbCompanyTrainingItemCode") as AspNet.Label) != null)
|
|
// {
|
|
// html = (row.FindControl("lbCompanyTrainingItemCode") as AspNet.Label).Text;
|
|
// }
|
|
// if (column.ColumnID == "tfCompanyTrainingItemName" && (row.FindControl("lbCompanyTrainingItemName") as AspNet.Label) != null)
|
|
// {
|
|
// html = (row.FindControl("lbCompanyTrainingItemName") as AspNet.Label).Text;
|
|
// }
|
|
// if (column.ColumnID == "tfCompileMan" && (row.FindControl("lbCompileMan") as AspNet.Label) != null)
|
|
// {
|
|
// html = (row.FindControl("lbCompileMan") as AspNet.Label).Text;
|
|
// }
|
|
// if (column.ColumnID == "tfCompileDate" && (row.FindControl("lbCompileDate") as AspNet.Label) != null)
|
|
// {
|
|
// html = (row.FindControl("lbCompileDate") as AspNet.Label).Text;
|
|
// }
|
|
// sb.AppendFormat("<td>{0}</td>", html);
|
|
// }
|
|
// }
|
|
|
|
// sb.Append("</tr>");
|
|
// }
|
|
|
|
// sb.Append("</table>");
|
|
|
|
// return sb.ToString();
|
|
//}
|
|
#endregion
|
|
|
|
///// <summary>
|
|
///// 行事件
|
|
///// </summary>
|
|
///// <param name="sender"></param>
|
|
///// <param name="e"></param>
|
|
//protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
|
|
//{
|
|
// if (e.CommandName == "Attach")
|
|
// {
|
|
// string attUrl = this.Grid1.Rows[e.RowIndex].Values[this.Grid1.Columns.Count - 1].ToString();
|
|
// try
|
|
// {
|
|
|
|
// string url = Funs.RootPath + attUrl;
|
|
// FileInfo info = new FileInfo(url);
|
|
// string savedName = Path.GetFileName(url);
|
|
// if (!info.Exists || string.IsNullOrEmpty(savedName))
|
|
// {
|
|
// url = Funs.RootPath + "Images//Null.jpg";
|
|
// info = new FileInfo(url);
|
|
// }
|
|
|
|
// if (Path.GetExtension(savedName) == ".mp4" || Path.GetExtension(savedName).ToLower() == ".mp4" || Path.GetExtension(savedName) == ".m4v")
|
|
// {
|
|
// string mpUrl = HttpUtility.UrlEncode(attUrl.Replace('\\', '/'));
|
|
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/AttachFile/player.aspx?url={0}", attUrl.Replace('\\', '/'), "播放 - "), "播放视频", 700, 560));
|
|
// }
|
|
// else
|
|
// {
|
|
// string fileName = Path.GetFileName(url);
|
|
// long fileSize = info.Length;
|
|
// System.Web.HttpContext.Current.Response.Clear();
|
|
// //System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
|
|
// System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
|
|
// System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
|
// System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
|
|
// System.Web.HttpContext.Current.Response.TransmitFile(url, 0, fileSize);
|
|
// System.Web.HttpContext.Current.Response.Flush();
|
|
// System.Web.HttpContext.Current.Response.End();
|
|
// }
|
|
// }
|
|
// catch (Exception)
|
|
// {
|
|
|
|
// }
|
|
// }
|
|
//}
|
|
}
|
|
} |