质量月报

This commit is contained in:
2023-05-25 10:56:16 +08:00
parent 39673dc1eb
commit 9346f075db
10 changed files with 419 additions and 155 deletions
@@ -7,6 +7,8 @@ using System.Text;
using BLL;
using AspNet = System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;
using NPOI.XSSF.UserModel;
using System.IO;
namespace FineUIPro.Web.CQMS.ManageReport
{
@@ -92,10 +94,23 @@ namespace FineUIPro.Web.CQMS.ManageReport
Grid1.DataSource = dt;
Grid1.DataBind();
}
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
DataRowView row = e.DataItem as DataRowView;
if (string.IsNullOrEmpty(row["Unit"].ToString()))
{
foreach (GridColumn column in Grid1.Columns)
{
e.CellCssClasses[column.ColumnIndex] = "f-grid-cell-uneditable";
}
}
int cm = GetCurMonth();
for (int i = 1; i <= 12; i++)
@@ -448,7 +463,7 @@ namespace FineUIPro.Web.CQMS.ManageReport
Funs.DB.SubmitChanges();
List<Model.CQMS_MonthReportItem> ItemList = new List<Model.CQMS_MonthReportItem>();
for (int i = 0; i < 22; i++)
for (int i = 0; i < 28; i++)
{
Model.CQMS_MonthReportItem item = new Model.CQMS_MonthReportItem();
item.MonthReportItemId = SQLHelper.GetNewID(typeof(Model.CQMS_MonthReportItem));
@@ -517,7 +532,7 @@ namespace FineUIPro.Web.CQMS.ManageReport
if (i == 12)
{
item.ReportItem = "检验批次数";
item.Unit = "";
item.Unit = "";
}
if (i == 13)
{
@@ -645,54 +660,54 @@ namespace FineUIPro.Web.CQMS.ManageReport
Model.CQMS_MonthReportItem item = Funs.DB.CQMS_MonthReportItem.FirstOrDefault(x => x.MonthReportItemId == monthReportItemId);
// if (cm == 1)
{
item.Month1 = Funs.GetNewInt(objects["values"]["Month1"].ToString());
item.Month1 = Funs.GetNewDecimal(objects["values"]["Month1"].ToString());
}
// if (cm == 2)
{
item.Month2 = Funs.GetNewInt(objects["values"]["Month2"].ToString());
item.Month2 = Funs.GetNewDecimal(objects["values"]["Month2"].ToString());
}
// if (cm == 3)
{
item.Month3 = Funs.GetNewInt(objects["values"]["Month3"].ToString());
item.Month3 = Funs.GetNewDecimal(objects["values"]["Month3"].ToString());
}
// if (cm == 4)
{
item.Month4 = Funs.GetNewInt(objects["values"]["Month4"].ToString());
item.Month4 = Funs.GetNewDecimal(objects["values"]["Month4"].ToString());
}
// if (cm == 5)
{
item.Month5 = Funs.GetNewInt(objects["values"]["Month5"].ToString());
item.Month5 = Funs.GetNewDecimal(objects["values"]["Month5"].ToString());
}
// if (cm == 6)
{
item.Month6 = Funs.GetNewInt(objects["values"]["Month6"].ToString());
item.Month6 = Funs.GetNewDecimal(objects["values"]["Month6"].ToString());
}
//if (cm == 7)
{
item.Month7 = Funs.GetNewInt(objects["values"]["Month7"].ToString());
item.Month7 = Funs.GetNewDecimal(objects["values"]["Month7"].ToString());
}
// if (cm == 8)
{
item.Month8 = Funs.GetNewInt(objects["values"]["Month8"].ToString());
item.Month8 = Funs.GetNewDecimal(objects["values"]["Month8"].ToString());
}
//if (cm == 9)
{
item.Month9 = Funs.GetNewInt(objects["values"]["Month9"].ToString());
item.Month9 = Funs.GetNewDecimal(objects["values"]["Month9"].ToString());
}
// if (cm == 10)
{
item.Month10 = Funs.GetNewInt(objects["values"]["Month10"].ToString());
item.Month10 = Funs.GetNewDecimal(objects["values"]["Month10"].ToString());
}
//if (cm == 11)
{
item.Month11 = Funs.GetNewInt(objects["values"]["Month11"].ToString());
item.Month11 = Funs.GetNewDecimal(objects["values"]["Month11"].ToString());
}
//if (cm == 12)
{
item.Month12 = Funs.GetNewInt(objects["values"]["Month12"].ToString());
item.Month12 = Funs.GetNewDecimal(objects["values"]["Month12"].ToString());
}
item.YearTotal = Funs.GetNewInt(objects["values"]["YearTotal"].ToString());
item.ProjectTotal = Funs.GetNewInt(objects["values"]["ProjectTotal"].ToString());
item.YearTotal = Funs.GetNewDecimal(objects["values"]["YearTotal"].ToString());
item.ProjectTotal = Funs.GetNewDecimal(objects["values"]["ProjectTotal"].ToString());
Funs.DB.SubmitChanges();
this.ShowNotify("保存成功");
}
@@ -763,60 +778,155 @@ namespace FineUIPro.Web.CQMS.ManageReport
/// <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";
string strSql = @"SELECT item.* ,ISNULL(t.SumProjectTotal,0) AS SumProjectTotal
FROM dbo.CQMS_MonthReportItem item
LEFT JOIN dbo.CQMS_MonthReport r ON r.MonthReportId = item.MonthReportId
LEFT JOIN (SELECT a.ReportItem,ISNULL(SUM(ISNULL(a.ProjectTotal,0)),0) AS SumProjectTotal
FROM dbo.CQMS_MonthReportItem a
LEFT JOIN dbo.CQMS_MonthReport b ON b.MonthReportId = a.MonthReportId
WHERE b.ProjectId=@ProjectId AND b.Years < " + this.tvControlItem.SelectedNode.Text + @"
GROUP BY a.ReportItem )t ON t.ReportItem = item.ReportItem
WHERE r.ProjectId=@ProjectId AND r.MonthReportId=@MonthReportId
ORDER BY item.Sort";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", CurrUser.LoginProjectId));
listStr.Add(new SqlParameter("@MonthReportId", tvControlItem.SelectedNodeID));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
string rootPath = Funs.localRoot + Const.ExcelUrl;
//模板文件
string TempletFileName = Funs.localRoot + "File/Excel/CQMS/质量月报导出模板.xlsx";
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "out.xlsx";
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
XSSFSheet recordSheet = (XSSFSheet)hssfworkbook.GetSheet("质量月报");
for (int i = 0; i < tb.Rows.Count; i++)
{
try
{
if (!string.IsNullOrEmpty(tb.Rows[i]["Unit"].ToString()))
{
var dMonth1 = Funs.GetNewDecimal(tb.Rows[i]["Month1"].ToString());
var dMonth2 = Funs.GetNewDecimal(tb.Rows[i]["Month2"].ToString());
var dMonth3 = Funs.GetNewDecimal(tb.Rows[i]["Month3"].ToString());
var dMonth4 = Funs.GetNewDecimal(tb.Rows[i]["Month4"].ToString());
var dMonth5 = Funs.GetNewDecimal(tb.Rows[i]["Month5"].ToString());
var dMonth6 = Funs.GetNewDecimal(tb.Rows[i]["Month6"].ToString());
var dMonth7 = Funs.GetNewDecimal(tb.Rows[i]["Month7"].ToString());
var dMonth8 = Funs.GetNewDecimal(tb.Rows[i]["Month8"].ToString());
var dMonth9 = Funs.GetNewDecimal(tb.Rows[i]["Month9"].ToString());
var dMonth10 = Funs.GetNewDecimal(tb.Rows[i]["Month10"].ToString());
var dMonth11 = Funs.GetNewDecimal(tb.Rows[i]["Month11"].ToString());
var dMonth12 = Funs.GetNewDecimal(tb.Rows[i]["Month12"].ToString());
var dYearTotal = Funs.GetNewDecimal(tb.Rows[i]["YearTotal"].ToString());
var dProjectTotal = Funs.GetNewDecimal(tb.Rows[i]["ProjectTotal"].ToString());
if (dMonth1.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(3).SetCellValue(dMonth1.Value.ToString("#.##"));
}
if (dMonth2.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(4).SetCellValue(dMonth2.Value.ToString("#.##"));
}
if (dMonth3.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(5).SetCellValue(dMonth3.Value.ToString("#.##"));
}
if (dMonth4.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(6).SetCellValue(dMonth4.Value.ToString("#.##"));
}
if (dMonth5.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(7).SetCellValue(dMonth5.Value.ToString("#.##"));
}
if (dMonth6.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(8).SetCellValue(dMonth6.Value.ToString("#.##"));
}
if (dMonth7.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(9).SetCellValue(dMonth7.Value.ToString("#.##"));
}
if (dMonth8.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(10).SetCellValue(dMonth8.Value.ToString("#.##"));
}
if (dMonth9.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(11).SetCellValue(dMonth9.Value.ToString("#.##"));
}
if (dMonth10.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(12).SetCellValue(dMonth10.Value.ToString("#.##"));
}
if (dMonth11.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(13).SetCellValue(dMonth11.Value.ToString("#.##"));
}
if (dMonth12.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(14).SetCellValue(dMonth12.Value.ToString("#.##"));
}
if (dYearTotal.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(15).SetCellValue(dYearTotal.Value.ToString("#.##"));
}
if (dProjectTotal.HasValue)
{
recordSheet.GetRow(3 + i).GetCell(16).SetCellValue(dProjectTotal.Value.ToString("#.##"));
}
}
}
catch (Exception)
{
}
}
using (FileStream filess = File.OpenWrite(ReportFileName))
{
hssfworkbook.Write(filess);
}
//PageContext.RegisterStartupScript(Window5.GetShowReference(String.Format("../../ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.HJGL_JointInfoReportId, isoId, varValue, this.CurrUser.LoginProjectId)));
FileInfo filet = new FileInfo(ReportFileName);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = 500;
this.BindGrid();
Response.Write(GetGridTableHtml(Grid1));
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=质量月报_" + Server.UrlEncode(DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx"));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
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)
{
if (column.Hidden == false)
{
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.Hidden == false)
{
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
}
}