using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BLL;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.ZHGL.ProjectAccident
{
public partial class AccidentStatistics : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
////权限按钮方法
this.GetButtonPower();
this.btnNew.OnClientClick = Window1.GetShowReference("AccidentStatisticsEdit.aspx") + "return false;";
if (this.CurrUser != null && this.CurrUser.PageSize.HasValue)
{
Grid1.PageSize = this.CurrUser.PageSize.Value;
}
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = @"SELECT S.AccidentStatisticsId,S.ProjectId,P.ProjectName,S.UnitId,u.UnitName,S.Person,S.CompileDate,S.AttachUrl,S.Treatment,"
+ @"(CASE WHEN S.States = " + BLL.Const.State_0 + " OR S.States IS NULL THEN '待['+OperateUser.UserName+']提交' WHEN S.States = " + BLL.Const.State_2 + " THEN '审核/审批完成' ELSE '待['+OperateUser.UserName+']办理' END) AS FlowOperateName"
+ @" FROM dbo.ProjectAccident_AccidentStatistics AS S"
+ @" LEFT JOIN dbo.Base_Project AS P ON P.ProjectId=S.ProjectId"
+ @" LEFT JOIN dbo.Base_Unit AS U ON U.UnitId=S.UnitId"
+ @" LEFT JOIN Sys_FlowOperate AS FlowOperate ON S.AccidentStatisticsId = FlowOperate.DataId AND FlowOperate.IsClosed <> 1"
+ @" LEFT JOIN Sys_User AS OperateUser ON FlowOperate.OperaterId = OperateUser.UserId WHERE 1= 1 ";
List listStr = new List();
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
strSql += " AND (P.ProjectName LIKE @Name OR u.UnitName LIKE @Name OR S.Person LIKE @Name OR S.Treatment LIKE @Name)";
listStr.Add(new SqlParameter("@Name", "%" + this.txtName.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
///
/// 分页
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
///
/// 分页显示条数下拉框
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
///
/// 批量删除
///
///
///
protected void btnDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
///
/// 右键编辑事件
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
///
/// Grid行双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
///
/// 删除方法
///
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var getD = BLL.AccidentStatisticsService.GetAccidentStatisticsById(rowID);
if (getD != null)
{
BLL.LogService.AddSys_Log(this.CurrUser, null, getD.AccidentStatisticsId, BLL.Const.ServerAccidentStatisticsMenuId, BLL.Const.BtnDelete);
BLL.AccidentStatisticsService.DeleteAccidentStatisticsById(rowID);
}
}
BindGrid();
ShowNotify("删除数据成功!");
}
}
///
/// 关闭弹出窗
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
///
/// 编辑数据方法
///
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInParent("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
var accidentReport = BLL.AccidentStatisticsService.GetAccidentStatisticsById(Id);
if (accidentReport != null)
{
if (this.btnMenuEdit.Hidden || accidentReport.States == BLL.Const.State_2) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("AccidentStatisticsView.aspx?AccidentStatisticsId={0}", Id, "查看 - ")));
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("AccidentStatisticsEdit.aspx?AccidentStatisticsId={0}", Id, "编辑 - ")));
}
}
}
#region 查询
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region 获取按钮权限
///
/// 获取按钮权限
///
///
///
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ServerAccidentStatisticsMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
}
}
#endregion
#region 导出按钮
/// 导出按钮
///
///
///
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;
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
///
/// 导出方法
///
///
///
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
MultiHeaderTable mht = new MultiHeaderTable();
mht.ResolveMultiHeaderTable(Grid1.Columns);
sb.Append("");
sb.Append("
");
foreach (List
");
return sb.ToString();
}
#region 多表头处理
///
/// 多表头处理
///
public class MultiHeaderTable
{
// 包含 rowspan,colspan 的多表头,方便生成 HTML 的 table 标签
public List> MultiTable = new List>();
// 最终渲染的列数组
public List Columns = new List();
public void ResolveMultiHeaderTable(GridColumnCollection columns)
{
List