Files
SGGL_HBAZ/SGGL/FineUIPro.Web/HSSE/HazardousMG/HazardProject.aspx.cs
T

342 lines
13 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using NPOI.SS.UserModel;
namespace FineUIPro.Web.HSSE.HazardousMG
{
/// <summary>
/// 危大、超危工程清单页面
/// </summary>
public partial class HazardProject : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
this.BindGrid();
}
}
/// <summary>
/// 新增按钮事件
/// </summary>
protected void btnNew_Click(object sender, EventArgs e)
{
if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
Alert.ShowInTop("请先选择项目!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference("HazardProjectEdit.aspx"));
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
if (this.CurrUser == null || string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
Alert.ShowInTop("请先登录或选择项目!", MessageBoxIcon.Warning);
return;
}
List<Model.HSSE_HazardProject> list = this.GetFilteredList();
Grid1.RecordCount = list.Count;
var table = this.GetPagedDataTable(Grid1, list);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 获取按查询条件过滤后的清单列表
/// </summary>
private List<Model.HSSE_HazardProject> GetFilteredList()
{
List<Model.HSSE_HazardProject> list = BLL.HazardProjectService.GetList(this.CurrUser.LoginProjectId);
////查询条件过滤
string name = this.txtProjectName.Text.Trim();
if (!string.IsNullOrEmpty(name))
{
list = list.Where(x => x.ProjectName.Contains(name)).ToList();
}
if (!string.IsNullOrEmpty(this.ddlRiskLevel.SelectedValue))
{
list = list.Where(x => x.RiskLevel == this.ddlRiskLevel.SelectedValue).ToList();
}
////开工时间范围过滤
if (this.dpStartDateFrom.SelectedDate.HasValue)
{
DateTime startFrom = this.dpStartDateFrom.SelectedDate.Value;
list = list.Where(x => x.StartDate.HasValue && x.StartDate.Value >= startFrom).ToList();
}
if (this.dpStartDateTo.SelectedDate.HasValue)
{
DateTime startTo = this.dpStartDateTo.SelectedDate.Value;
list = list.Where(x => x.StartDate.HasValue && x.StartDate.Value <= startTo).ToList();
}
////结束时间范围过滤
if (this.dpEndDateFrom.SelectedDate.HasValue)
{
DateTime endFrom = this.dpEndDateFrom.SelectedDate.Value;
list = list.Where(x => x.EndDate.HasValue && x.EndDate.Value >= endFrom).ToList();
}
if (this.dpEndDateTo.SelectedDate.HasValue)
{
DateTime endTo = this.dpEndDateTo.SelectedDate.Value;
list = list.Where(x => x.EndDate.HasValue && x.EndDate.Value <= endTo).ToList();
}
return list;
}
/// <summary>
/// 分页事件
/// </summary>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 每页记录数下拉事件
/// </summary>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
this.BindGrid();
}
/// <summary>
/// 排序事件
/// </summary>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 导出
/// </summary>
protected void btnOut_Click(object sender, EventArgs e)
{
List<Model.HSSE_HazardProject> list = this.GetFilteredList();
string[] cols = { "序号", "分部分项工程", "施工内容", "风险等级", "开工时间", "结束时间", "现场负责人", "备注" };
short[] widths = { 8, 30, 40, 16, 16, 16, 16, 30 };
string rootPath = Server.MapPath("~/");
string fullPath = rootPath + BLL.Const.ExcelUrl;
if (!Directory.Exists(fullPath))
{
Directory.CreateDirectory(fullPath);
}
string fileName = "危大超危工程清单" + BLL.Funs.GetNewFileName() + ".xls";
string filePath = fullPath + fileName;
BLL.Common.NPOIExcel excel = new BLL.Common.NPOIExcel();
////表头样式:白字加粗、蓝底、带边框
IFont headerFont = excel.CreateFont();
headerFont.Boldweight = 700;
headerFont.Color = BLL.Common.NPOIColor.WHITE;
ICellStyle headerStyle = excel.CreateCellStyle();
headerStyle.SetFont(headerFont);
headerStyle.FillForegroundColor = BLL.Common.NPOIColor.ROYAL_BLUE;
headerStyle.FillPattern = FillPattern.SolidForeground;
headerStyle.BorderTop = BorderStyle.Thin;
headerStyle.BorderBottom = BorderStyle.Thin;
headerStyle.BorderLeft = BorderStyle.Thin;
headerStyle.BorderRight = BorderStyle.Thin;
////数据样式:带边框
ICellStyle dataStyle = excel.CreateCellStyle();
dataStyle.BorderTop = BorderStyle.Thin;
dataStyle.BorderBottom = BorderStyle.Thin;
dataStyle.BorderLeft = BorderStyle.Thin;
dataStyle.BorderRight = BorderStyle.Thin;
for (int i = 0; i < cols.Length; i++)
{
excel.SetValue(0, i, cols[i]);
excel.SetStyle(0, i, headerStyle);
excel.SetColumnWidth(i, widths[i]);
}
int rowIndex = 1;
foreach (Model.HSSE_HazardProject item in list)
{
excel.SetValue(rowIndex, 0, rowIndex.ToString());
excel.SetValue(rowIndex, 1, item.ProjectName ?? string.Empty);
excel.SetValue(rowIndex, 2, item.WorkContent ?? string.Empty);
excel.SetValue(rowIndex, 3, item.RiskLevel ?? string.Empty);
excel.SetValue(rowIndex, 4, item.StartDate.HasValue ? item.StartDate.Value.ToString("yyyy-MM-dd") : string.Empty);
excel.SetValue(rowIndex, 5, item.EndDate.HasValue ? item.EndDate.Value.ToString("yyyy-MM-dd") : string.Empty);
excel.SetValue(rowIndex, 6, item.ManagerMan ?? string.Empty);
excel.SetValue(rowIndex, 7, item.Remark ?? string.Empty);
for (int i = 0; i < cols.Length; i++)
{
excel.SetStyle(rowIndex, i, dataStyle);
}
rowIndex++;
}
excel.Save(filePath);
FileInfo info = new FileInfo(filePath);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(filePath, 0, fileSize);
Response.Flush();
Response.End();
}
/// <summary>
/// 导入
/// </summary>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window2.GetShowReference("HazardProjectDataIn.aspx"));
}
/// <summary>
/// 导入窗口关闭事件
/// </summary>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 双击行编辑事件
/// </summary>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
/// 右键菜单编辑事件
/// </summary>
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 = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HazardProjectEdit.aspx?HazardProjectId={0}", id)));
}
#endregion
#region
/// <summary>
/// 右键菜单删除事件
/// </summary>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
BLL.HazardProjectService.Delete(rowID);
}
this.BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
#endregion
#region
/// <summary>
/// 右键菜单查看该危大、超危工程关联的安全巡检记录
/// </summary>
protected void btnMenuSafetyPatrol_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(String.Format("window.open('SafetyPatrol.aspx?HazardProjectId={0}', '_blank');", id));
}
/// <summary>
/// 右键菜单查看该危大、超危工程关联的安全防护验收记录
/// </summary>
protected void btnMenuSafetyAcceptance_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(String.Format("window.open('SafetyAcceptance.aspx?HazardProjectId={0}', '_blank');", id));
}
#endregion
#region
/// <summary>
/// 生成现场公示牌二维码(安全员扫码后进入巡检)
/// </summary>
protected void btnQR_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
Model.HSSE_HazardProject info = BLL.HazardProjectService.GetById(id);
if (info != null)
{
////二维码内容:危大工程标识(编号),接入数据库后替换为巡检页面URL
string strValue = "hazard$hid=" + info.HazardProjectId;
string urlName = "hazard$hid=" + info.HazardProjectId;
string title = "危大工程公示牌:" + info.ProjectName;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/Controls/ShowQRImage.aspx?strValue={0}&urlName={1}&title={2}", strValue, urlName, System.Web.HttpUtility.UrlEncode(title)), "公示牌二维码", 340, 400));
}
}
#endregion
}
}