CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/HSSE/Manager/ManagerMonthCNew.aspx.cs

1027 lines
43 KiB
C#
Raw Normal View History

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;
using Aspose.Words;
using Aspose.Words.Tables;
using System.IO;
namespace FineUIPro.Web.HSSE.Manager
{
public partial class ManagerMonthCNew : PageBase
{
public List<Model.Base_Unit> unitList = new List<Model.Base_Unit>();
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
// 表头过滤
//FilterDataRowItem = FilterDataRowItemImplement;
if (!IsPostBack)
{
unitList = Funs.DB.Base_Unit.ToList();
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
////权限按钮方法
this.GetButtonPower();
this.txtReportDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT MonthReport.MonthReportId,MonthReport.ProjectId,MonthReport.Months,CodeRecords.Code AS MonthReportCode,Users.UserName as ReportManName"
+ @" FROM Manager_MonthReportC AS MonthReport "
+ @" LEFT JOIN Sys_User AS Users ON MonthReport.ReportMan=Users.UserId "
2024-08-27 17:36:01 +08:00
+ @" LEFT JOIN Sys_CodeRecords AS CodeRecords ON MonthReport.MonthReportId=CodeRecords.DataId WHERE MonthReportType='1' ";
List<SqlParameter> listStr = new List<SqlParameter>();
strSql += " AND MonthReport.ProjectId = @ProjectId";
listStr.Add(new SqlParameter("@ProjectId", this.ProjectId));
if (!string.IsNullOrEmpty(this.txtMonthReportCode.Text.Trim()))
{
strSql += " AND CodeRecords.Code LIKE @MonthReportCode";
listStr.Add(new SqlParameter("@MonthReportCode", "%" + this.txtMonthReportCode.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 过滤表头
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 关闭弹出窗
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region Grid双击事件
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
btnMenuModify_Click(null, null);
}
#endregion
#region
/// <summary>
/// 编辑按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuModify_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string MonthReportId = Grid1.SelectedRowID;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManagerMonthCEdit.aspx?MonthReportId={0}", MonthReportId, "编辑 - ")));
//var monthReport = BLL.MonthReportCService.GetMonthReportByMonthReportId(MonthReportId);
//int n = 6; //月报冻结时间
//var sysSet = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_MonthReportFreezeDay).FirstOrDefault();
//if (sysSet != null)
//{
// n = Convert.ToInt32(sysSet.ConstValue);
//}
//if (monthReport != null)
//{
// int d = Convert.ToInt32(DateTime.Now.Day);
// if ((monthReport.Months.Value.Year == DateTime.Now.Year && monthReport.Months.Value.Month == DateTime.Now.Month) ||
// ((monthReport.Months.Value.AddMonths(1).Month == DateTime.Now.Month) && d < n + 1))
// {
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportCEdit.aspx?MonthReportId={0}", MonthReportId, "编辑 - ")));
// }
// else
// {
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportCView.aspx?MonthReportId={0}", MonthReportId, "查看 - ")));
// }
//}
}
#endregion
#region
/// <summary>
/// 批量删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDel_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var mont = BLL.MonthReportCService.GetMonthReportByMonthReportId(rowID);
if (mont != null)
{
2024-08-27 17:36:01 +08:00
InjuryAccidentCService.DeleteInjuryAccidengtByMonthReportId(rowID);
PersonSortCService.DeleteManager_Attempted(rowID);
PersonSortCService.DeleteManager_DrillRecordList(rowID);
PersonSortCService.DeleteManager_EmergencyPlan(rowID);
PersonSortCService.DeleteManager_ProjectAssignment(rowID);
2024-08-26 14:24:39 +08:00
PersonSortCService.DeleteManager_HiddenDanger(rowID);
2024-08-27 17:36:01 +08:00
ComplianceObligationsCService.DeleteComplianceObligationsCByMonthReportId(rowID);
RewardAndPunishSortCService.DeleteRewardAndPunishSortCByMonthReportId(rowID);
PersonSortCService.DeletePersonSortsByMonthReportId(rowID);
HazardSortCService.DeleteHazardSortsByMonthReportId(rowID);
AccidentSortCService.DeleteAccidentSortsByMonthReportId(rowID);
HseCostCService.DeleteHseCostsByMonthReportId(rowID);
TrainSortCService.DeleteTrainSortsByMonthReportId(rowID);
TrainActivitySortCService.DeleteTrainActivitySortsByMonthReportId(rowID);
MeetingSortCService.DeleteMeetingSortsByMonthReportId(rowID);
CheckSortCService.DeleteCheckSortsByMonthReportId(rowID);
CheckDetailSortCService.DeleteCheckDetailSortsByMonthReportId(rowID);
PromotionalActiviteSortCService.DeletePromotionalActiviteSortsByMonthReportId(rowID);
EmergencySortCService.DeleteEmergencySortsByMonthReportId(rowID);
DrillSortCService.DeleteDrillSortsByMonthReportId(rowID);
IncentiveSortCService.DeleteIncentiveSortsByMonthReportId(rowID);
OtherActiveSortCService.DeleteOtherActiveSortsByMonthReportId(rowID);
ActivityDesCService.DeleteActivityDesByMonthReportId(rowID);
OtherManagementCService.DeleteOtherManagementByMonthReportId(rowID);
PlanCService.DeletePlanByMonthReportId(rowID);
ReviewRecordCService.DeleteReviewRecordByMonthReportId(rowID);
FileManageCService.DeleteFileManageByMonthReportId(rowID);
FiveExpenseCService.DeleteFiveExpenseByMonthReportId(rowID);
SubExpenseCService.DeleteSubExpenseByMonthReportId(rowID);
AccidentDesciptionItemCService.DeleteAccidentDesciptionItemByMonthReportId(rowID);
AccidentDesciptionCService.DeleteAccidentDesciptionByMonthReportId(rowID);
OtherWorkCService.DeleteOtherWorkByMonthReportId(rowID);
HazardCService.DeleteHazardByMonthReportId(rowID);
TrainCService.DeleteTrainByMonthReportId(rowID);
CheckCService.DeleteCheckByMonthReportId(rowID);
MeetingCService.DeleteMeetingByMonthReportId(rowID);
ActivitiesCService.DeleteActivitiesByMonthReportId(rowID);
EmergencyPlanCService.DeleteEmergencyPlanByMonthReportId(rowID);
EmergencyExercisesCService.DeleteEmergencyExercisesByMonthReportId(rowID);
CostInvestmentPlanCService.DeleteCostInvestmentPlanByMonthReportId(rowID);
ManageDocPlanCService.DeleteManageDocPlanByMonthReportId(rowID);
OtherWorkPlanCService.DeleteOtherWorkPlanByMonthReportId(rowID);
MonthReportCService.DeleteMonthReportByMonthReportId(rowID);
2024-08-23 08:58:55 +08:00
}
}
BindGrid();
ShowNotify("删除数据成功!(表格数据已重新绑定)");
}
}
#endregion
#region
/// <summary>
/// 新增
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
if (project.StartDate != null)
{
if (!string.IsNullOrEmpty(this.txtReportDate.Text.Trim()))
{
DateTime months = Convert.ToDateTime(this.txtReportDate.Text.Trim() + "-01");
Model.Manager_MonthReportC monthReport = BLL.MonthReportCService.GetMonthReportByMonths(months, this.CurrUser.LoginProjectId);
if (monthReport != null)
{
Alert.ShowInTop("当前月份的月报已存在!", MessageBoxIcon.Warning);
return;
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("MonthReportCEdit.aspx?months={0}", string.Format("{0:yyyy-MM-dd}", months), "编辑 - ")));
}
}
else
{
Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请先设置项目开工时间!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.ManagerMonthCNewMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuModify.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDel.Hidden = false;
}
}
}
#endregion
#region
/// 导出按钮
/// </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("管理月报B" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = 500;
this.BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
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)
{
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)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("lblNumber") as AspNet.Label).Text;
}
sb.AppendFormat("<td>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
#region
protected void btnNew_Click1(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtReportDate.Text.Trim()))
{
DateTime months = Convert.ToDateTime(this.txtReportDate.Text.Trim() + "-01");
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ManagerMonthCEdit.aspx?months={0}", string.Format("{0:yyyy-MM-dd}", months), "添加 - ")));
}
else {
Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
#region
/// <summary>
/// 把单位Id转换为单位名称
/// </summary>
/// <param name="UnitId"></param>
/// <returns></returns>
protected string ConvertUnitName(string UnitId)
{
if (UnitId != null)
{
var u = Funs.DB.Base_Unit.FirstOrDefault(x => x.UnitId == UnitId.ToString());
if (u != null)
{
return u.UnitName;
}
}
return "";
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="value">单元格内的值</param>
/// <param name="doc"></param>
/// <param name="cellWidth"></param>
/// <param name="cellMerge"></param>
/// <param name="CenterPage">有值的话就是序号</param>
/// <param name="cellUnitLeft">字体居左</param>
/// <returns></returns>
public static Cell CreateCell(String value, Document doc, double cellWidth, string cellMerge = "", string CenterPage = "", string cellUnitLeft = "")
{
Cell cell = new Cell(doc);
Paragraph p = new Paragraph(doc);
if (!string.IsNullOrEmpty(cellMerge))
{
if (cellMerge == "0")
{
cell.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;//竖直方向合并的第一个单元格
}
else
{
cell.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;//竖直方向合并的第一个单元格
}
}
else
{
cell.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
}
if (!string.IsNullOrEmpty(CenterPage))
{
//序号
value = " " + value;
}
if (!string.IsNullOrEmpty(cellUnitLeft))
{
p.ParagraphFormat.Alignment = ParagraphAlignment.Left;//表格中字体居左
}
else
{
p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//表格中字体居中
}
p.AppendChild(new Run(doc, value));
cell.CellFormat.Width = cellWidth;
cell.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
//边框宽度
cell.CellFormat.Borders.LineWidth = 0.5;
cell.AppendChild(p);
return cell;
}
/// <summary>
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuOut_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;//安全月报的主键
try
{
string rootPath = Server.MapPath("~/");
string initTemplatePath = string.Empty;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
string filePath = string.Empty;
Model.SGGLDB db = Funs.DB;
initTemplatePath = Const.HseMonthReportNewTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
//根据id获取月报主表数据
var model = db.Manager_MonthReportC.FirstOrDefault(x => x.MonthReportId == Id);
var startDate = Convert.ToDateTime(model.StartDate);
var endDate = Convert.ToDateTime(model.EndDate);
//获取project
var pModel = db.Base_Project.FirstOrDefault(x => x.ProjectId == model.ProjectId);
var urlHz = startDate.ToString("yyyyMMdd") + "-"
+ endDate.ToString("yyyyMMdd");
newUrl = uploadfilepath.Replace("项目安全月报", pModel.ShortName + "项目安全月报(" + model.MonthReportCode + "" + urlHz);
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
//更新书签内容
Document doc = new Aspose.Words.Document(newUrl);
DocumentBuilder builder = new DocumentBuilder(doc);
#region
//业主单位
var unitsYz = (from x in db.Base_Unit
join y in db.Project_ProjectUnit
on x.UnitId equals y.UnitId
where y.ProjectId == this.CurrUser.LoginProjectId && y.UnitType == BLL.Const.ProjectUnitType_4
orderby x.UnitName
select x).FirstOrDefault();
Bookmark bkmark = doc.Range.Bookmarks["username"];
if (bkmark != null)
{
if (unitsYz != null)
{
bkmark.Text = unitsYz.UnitName;
}
//var uModel = db.Sys_User.FirstOrDefault(x => x.UserId == weekModel.CreateMan);
//if (uModel!=null)
//{
// bkmark.Text = uModel.UserName;
//}
}
bkmark = doc.Range.Bookmarks["projectNo"];
if (bkmark != null)
{
bkmark.Text = pModel.ProjectCode;
}
bkmark = doc.Range.Bookmarks["createdate"];
if (bkmark != null)
{
//bkmark.Text = weekModel.CreateDate.ToString().Split(' ')[0].Replace('/', '.');
}
bkmark = doc.Range.Bookmarks["projectname"];
if (bkmark != null)
{
bkmark.Text = pModel.ProjectName;
}
bkmark = doc.Range.Bookmarks["quamanagername"];
if (bkmark != null)
{
var getPUser = Funs.DB.Project_ProjectUser.Where(x => x.ProjectId == model.ProjectId);
////安全经理
var qa = getPUser.FirstOrDefault(x => x.RoleId.Contains(BLL.Const.HSSEManager));
bkmark.Text = db.Sys_User.FirstOrDefault(x => x.UserId == qa.UserId).UserName;
}
bkmark = doc.Range.Bookmarks["reportAlldate"];
//20XX年XX月XX日至20XX年XX月XX日
if (bkmark != null)
{
var sdate = Convert.ToDateTime(model.StartDate);
var edate = Convert.ToDateTime(model.EndDate);
bkmark.Text = sdate.Year + "年" + sdate.Month + "月" + sdate.Day + "日至" +
edate.Year + "年" + edate.Month + "月" + edate.Day + "日";
}
bkmark = doc.Range.Bookmarks["reportindex"];
if (bkmark != null)
{
bkmark.Text = model.MonthReportCode;
}
bkmark = doc.Range.Bookmarks["fromcode"];
//fromcode,项目号-RM-PQM-顺序号
if (bkmark != null)
{
bkmark.Text = pModel.ProjectCode + "-RM-PQM-" + model.MonthReportCode;
}
#endregion
#region 1.
bkmark = doc.Range.Bookmarks["lbProjectName"];
if (bkmark != null)
{
bkmark.Text = pModel.ProjectName;
}
bkmark = doc.Range.Bookmarks["lblMainUnitName"];
if (bkmark != null)
{
var mainUnit = BLL.UnitService.GetThisUnitDropDownList()[0];
if (mainUnit != null)
{
bkmark.Text = mainUnit.UnitName;
}
}
bkmark = doc.Range.Bookmarks["lblProjectAddress"];
if (bkmark != null)
{
bkmark.Text = pModel.ProjectAddress;
}
bkmark = doc.Range.Bookmarks["lblProjectCode"];
if (bkmark != null)
{
bkmark.Text = pModel.ProjectCode;
}
bkmark = doc.Range.Bookmarks["lblContractNo"];
if (bkmark != null)
{
bkmark.Text = pModel.ContractNo;
}
bkmark = doc.Range.Bookmarks["lblProjectType"];
if (bkmark != null)
{
if (!string.IsNullOrEmpty(pModel.ProjectType))
{
var c = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_ProjectType).
FirstOrDefault(x => x.ID == pModel.ProjectType);
if (c != null)
{
bkmark.Text = c.ConstText;
}
}
}
bkmark = doc.Range.Bookmarks["lblWorkRange"];
if (bkmark != null)
{
bkmark.Text = pModel.WorkRange;
}
bkmark = doc.Range.Bookmarks["lblDuration"];
if (bkmark != null)
{
bkmark.Text = pModel.Duration.ToString();
}
bkmark = doc.Range.Bookmarks["lblStartDate"];
if (bkmark != null)
{
bkmark.Text = string.Format("{0:yyyy-MM-dd}", pModel.StartDate);
}
bkmark = doc.Range.Bookmarks["lblEndDate"];
if (bkmark != null)
{
bkmark.Text = string.Format("{0:yyyy-MM-dd}", pModel.EndDate);
}
#endregion
#region 2.HSE人力投入情况
//获取word文档中的第二个表格
int whileIndex = 1;
Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 1, true);
bool isYm = true;
//跳过页眉的表头
while (isYm)
{
if (table.Range.Text.Substring(0, 2) != "单位")
{
whileIndex += 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true);
}
else
{
isYm = false;
}
}
//人力投入情况
var sorts = (from x in db.Manager_PersonSortC
join y in db.Project_ProjectUnit
on x.UnitId equals y.UnitId
where x.MonthReportId == Id && y.ProjectId == this.ProjectId
orderby y.UnitType
select x).ToList();
int numberIndex = 2;
foreach (var item in sorts)
{
//创建行
Row row = new Row(doc);
row.Cells.Add(CreateCell(ConvertUnitName(item.UnitId), doc, table.Rows[1].Cells[0].CellFormat.Width, "", "", "unit"));
row.Cells.Add(CreateCell(item.SumPersonNum.ToString(), doc, table.Rows[1].Cells[1].CellFormat.Width));
row.Cells.Add(CreateCell(item.SumOutPersonNum.ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width));
row.Cells.Add(CreateCell(item.HSEPersonNum.ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width));
row.Cells.Add(CreateCell(item.ContractRange.ToString(), doc, table.Rows[1].Cells[4].CellFormat.Width));
row.Cells.Add(CreateCell(item.Remark.ToString(), doc, table.Rows[1].Cells[5].CellFormat.Width));
table.Rows.Insert(numberIndex, row);
numberIndex++;
}
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
//创建合计
Row rowhj = new Row(doc);
rowhj.Cells.Add(CreateCell("合计", doc, table.Rows[1].Cells[0].CellFormat.Width, "", "", "unit"));
rowhj.Cells.Add(CreateCell((from x in sorts select x.SumPersonNum ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[1].CellFormat.Width));
rowhj.Cells.Add(CreateCell((from x in sorts select x.SumOutPersonNum ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[2].CellFormat.Width));
rowhj.Cells.Add(CreateCell((from x in sorts select x.HSEPersonNum ?? 0).Sum().ToString(), doc, table.Rows[1].Cells[3].CellFormat.Width));
rowhj.Cells.Add(CreateCell("", doc, table.Rows[1].Cells[4].CellFormat.Width));
rowhj.Cells.Add(CreateCell("", doc, table.Rows[1].Cells[5].CellFormat.Width));
table.Rows.Insert(numberIndex, rowhj);
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
#endregion
#region 3.HSE工时/
whileIndex += 1;
bkmark = doc.Range.Bookmarks["MonthHSEDay"];
if (bkmark != null)
{
bkmark.Text = model.MonthHSEDay.ToString();
}
bkmark = doc.Range.Bookmarks["SumHSEDay"];
if (bkmark != null)
{
bkmark.Text = model.SumHSEDay.ToString();
}
bkmark = doc.Range.Bookmarks["MonthHSEWorkDay"];
if (bkmark != null)
{
bkmark.Text = model.MonthHSEWorkDay.ToString();
}
bkmark = doc.Range.Bookmarks["YearHSEWorkDay"];
if (bkmark != null)
{
bkmark.Text = model.YearHSEWorkDay.ToString();
}
bkmark = doc.Range.Bookmarks["SumHSEWorkDay"];
if (bkmark != null)
{
bkmark.Text = model.SumHSEWorkDay.ToString();
}
bkmark = doc.Range.Bookmarks["HseManhours"];
if (bkmark != null)
{
bkmark.Text = model.HseManhours.ToString();
}
bkmark = doc.Range.Bookmarks["SubcontractManHours"];
if (bkmark != null)
{
bkmark.Text = model.SubcontractManHours.ToString();
}
bkmark = doc.Range.Bookmarks["TotalHseManhoursYear"];
if (bkmark != null)
{
bkmark.Text = model.TotalHseManhoursYear.ToString();
}
bkmark = doc.Range.Bookmarks["TotalHseManhours"];
if (bkmark != null)
{
bkmark.Text = model.TotalHseManhours.ToString();
}
#endregion
#region 4.1
whileIndex += 1;
var trainSorts = BLL.TrainSortCService.GetTrainSortsByMonthReportId(Id);
if (trainSorts.Count>0)
{
foreach (var item in trainSorts)
{
if (item.TrainType == "员工入场安全教育")
{
bkmark = doc.Range.Bookmarks["classhours1"];
if (bkmark != null)
{
bkmark.Text = item.TeachHour.ToString();
}
bkmark = doc.Range.Bookmarks["traincounts1"];
if (bkmark != null)
{
bkmark.Text = item.PersonNum.ToString();
}
bkmark = doc.Range.Bookmarks["traincounts4"];
if (bkmark != null)
{
bkmark.Text = item.TotalPersonNum.ToString();
}
}
else if (item.TrainType == "其他安全培训")
{
bkmark = doc.Range.Bookmarks["classhours2"];
if (bkmark != null)
{
bkmark.Text = item.TeachHour.ToString();
}
bkmark = doc.Range.Bookmarks["traincounts2"];
if (bkmark != null)
{
bkmark.Text = item.PersonNum.ToString();
}
bkmark = doc.Range.Bookmarks["traincounts5"];
if (bkmark != null)
{
bkmark.Text = item.TotalPersonNum.ToString();
}
}
else {
bkmark = doc.Range.Bookmarks["classhours3"];
if (bkmark != null)
{
bkmark.Text = item.TeachHour.ToString();
}
bkmark = doc.Range.Bookmarks["traincounts3"];
if (bkmark != null)
{
bkmark.Text = item.PersonNum.ToString();
}
bkmark = doc.Range.Bookmarks["traincounts6"];
if (bkmark != null)
{
bkmark.Text = item.TotalPersonNum.ToString();
}
}
}
bkmark = doc.Range.Bookmarks["traincounts7"];
if (bkmark != null)
{
bkmark.Text = trainSorts.Sum(x => x.TotalPersonNum).ToString();
}
}
#endregion
#region 4.2 HSE会议及检查统计
var checkSorts = BLL.CheckSortCService.GetCheckSortsByMonthReportId(Id);
if (checkSorts.Count > 0)
{
isYm = true;
whileIndex += 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true);
//跳过页眉的表头
while (isYm)
{
if (table.Range.Text.Substring(0, 4) != "检查类型")
{
whileIndex += 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true);
}
else
{
isYm = false;
}
}
numberIndex = 1;
foreach (var item in checkSorts)
{
Row row = new Row(doc);
row.Cells.Add(CreateCell(item.CheckType, doc, table.FirstRow.Cells[0].CellFormat.Width));
row.Cells.Add(CreateCell(item.CheckNumber.ToString(), doc, table.FirstRow.Cells[1].CellFormat.Width));
row.Cells.Add(CreateCell(item.YearCheckNum.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width));
row.Cells.Add(CreateCell(item.TotalCheckNum.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width));
table.Rows.Insert(numberIndex, row);
numberIndex++;
}
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
}
#endregion
#region 4.3
//人力投入情况
var HiddenDangersorts = (from x in db.Manager_HiddenDanger
join y in db.Project_ProjectUnit
on x.UnitId equals y.UnitId
where x.MonthReportId == Id && y.ProjectId == this.ProjectId
orderby y.UnitType
select x).ToList();
if (HiddenDangersorts.Count>0)
{
isYm = true;
whileIndex += 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true);
//跳过页眉的表头
while (isYm)
{
if (table.Range.Text.Substring(0, 2) != "序号")
{
whileIndex += 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, whileIndex, true);
}
else
{
isYm = false;
}
}
numberIndex = 1;
foreach (var item in HiddenDangersorts)
{
Row row = new Row(doc);
row.Cells.Add(CreateCell(numberIndex.ToString(), doc, table.FirstRow.Cells[0].CellFormat.Width));
row.Cells.Add(CreateCell(ConvertUnitName(item.UnitId), doc, table.FirstRow.Cells[1].CellFormat.Width, "", "", "unit"));
row.Cells.Add(CreateCell(item.CommonlyNum.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width));
row.Cells.Add(CreateCell(item.MajorNum.ToString(), doc, table.FirstRow.Cells[3].CellFormat.Width));
row.Cells.Add(CreateCell(item.ReRate.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width));
table.Rows.Insert(numberIndex, row);
numberIndex++;
}
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
//合计
rowhj = new Row(doc);
rowhj.Cells.Add(CreateCell("本月隐患总数", doc, table.FirstRow.Cells[0].CellFormat.Width+table.FirstRow.Cells[1].CellFormat.Width));
rowhj.Cells.Add(CreateCell(model.MonthHdangerCount.ToString(), doc, table.FirstRow.Cells[2].CellFormat.Width));
rowhj.Cells.Add(CreateCell("年度隐患总数", doc, table.FirstRow.Cells[3].CellFormat.Width));
rowhj.Cells.Add(CreateCell(model.YearHdangerCount.ToString(), doc, table.FirstRow.Cells[4].CellFormat.Width));
table.Rows.Insert(numberIndex, rowhj);
//自动设置表格样式
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
}
#endregion
#region 4.4
#endregion
#region
whileIndex = 1;
table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 1, true);
if (unitsYz != null)
{
//业主名称
table.Rows[0].Cells[2].FirstParagraph.Runs[0].Text = unitsYz.UnitName;
}
//项目号
table.Rows[0].Cells[4].FirstParagraph.Runs[0].Text = pModel.ProjectCode;
//项目名称
table.Rows[1].Cells[2].FirstParagraph.Runs[0].Text = pModel.ProjectName;
table.Rows[1].Cells[3].FirstParagraph.Runs[0].Text = pModel.ProjectCode + "-RM-PQM-" + model.MonthReportCode;
//总页数
table.Rows[2].Cells[7].FirstParagraph.Runs[0].Text = doc.PageCount.ToString();
bkmark = doc.Range.Bookmarks["CountPage"];
if (bkmark != null)
{
bkmark.Text = doc.PageCount.ToString();
}
//页眉是第二个表
//tableIndex—要移动的表的索引。
//rowIndex - 表中行的索引。
//columnIndex—表中列的索引。
//字符在单元格中的索引。目前只能指定0移动到单元格的开头或指定 - 1移动到单元格的结尾。
//builder.MoveToCell(1,0,2,0);
//builder.Write(unitsYz.UnitName);
#endregion
doc.Save(newUrl);
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
catch (Exception ex)
{
Alert.ShowInTop(ex.Message, MessageBoxIcon.Warning);
throw;
}
}
#endregion
}
}