增加进度计划编制导出功能
This commit is contained in:
@@ -3,6 +3,7 @@ using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
@@ -27,7 +28,7 @@ namespace FineUIPro.Web.JDGL.Check
|
||||
|
||||
private void BindGrid()
|
||||
{
|
||||
DataTable table = BLL.WorkPackageService.GetAllTreeDataTable(this.CurrUser.LoginProjectId);
|
||||
DataTable table = BLL.WorkPackageService.GetAllTreeDataTable(this.CurrUser.LoginProjectId, string.Empty);
|
||||
Grid1.DataSource = table;
|
||||
Grid1.DataBind();
|
||||
for (int i = 0; i < this.Grid1.Rows.Count; i++)
|
||||
@@ -38,7 +39,7 @@ namespace FineUIPro.Web.JDGL.Check
|
||||
cbIsMileStone.Visible = false;
|
||||
foreach (GridColumn column in Grid1.Columns)
|
||||
{
|
||||
if (column.ColumnIndex != 0)
|
||||
if (column.ColumnIndex != 0 && column.ColumnIndex != 1)
|
||||
{
|
||||
this.Grid1.Rows[i].CellCssClasses[column.ColumnIndex] = "f-grid-cell-uneditable";
|
||||
}
|
||||
@@ -98,7 +99,7 @@ namespace FineUIPro.Web.JDGL.Check
|
||||
Model.WBS_WorkPackage workPackage = workPackages.FirstOrDefault(x => x.WorkPackageId == this.Grid1.Rows[i].DataKeys[2].ToString());
|
||||
if (workPackage != null)
|
||||
{
|
||||
string weights = values.Value<string>("Weights");
|
||||
string weights = values.Value<string>("JDWeights");
|
||||
string unit = values.Value<string>("Unit");
|
||||
string planProjectQuantity = values.Value<string>("PlanProjectQuantity");
|
||||
string realProjectQuantity = values.Value<string>("RealProjectQuantity");
|
||||
@@ -107,7 +108,7 @@ namespace FineUIPro.Web.JDGL.Check
|
||||
string realStartDate = values.Value<string>("RealStartDate");
|
||||
string preWorkCode = values.Value<string>("PreWorkCode");
|
||||
System.Web.UI.WebControls.CheckBox cbIsMileStone = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsMileStone"));
|
||||
workPackage.Weights = Funs.GetNewDecimal(weights);
|
||||
workPackage.JDWeights = Funs.GetNewDecimal(weights);
|
||||
workPackage.Unit = unit;
|
||||
workPackage.PlanProjectQuantity = Funs.GetNewDecimal(planProjectQuantity);
|
||||
workPackage.RealProjectQuantity = Funs.GetNewDecimal(realProjectQuantity);
|
||||
@@ -171,5 +172,190 @@ namespace FineUIPro.Web.JDGL.Check
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 导出(excel按钮)
|
||||
protected void btnOutExcel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.Grid1.Rows.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataTable table = BLL.WorkPackageService.GetAllTreeDataTable(this.CurrUser.LoginProjectId, "Out");
|
||||
string projectNmae = BLL.ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId);
|
||||
if (!string.IsNullOrEmpty(projectNmae))
|
||||
{
|
||||
projectNmae = "(" + projectNmae + ")";
|
||||
}
|
||||
string rootPath = Server.MapPath("~/");
|
||||
string initTemplatePath = string.Empty;
|
||||
string uploadfilepath = string.Empty;
|
||||
string newUrl = string.Empty;
|
||||
string filePath = string.Empty;
|
||||
initTemplatePath = Const.JDPlanTemplateUrl;
|
||||
uploadfilepath = rootPath + initTemplatePath;
|
||||
newUrl = uploadfilepath.Replace(".xls", projectNmae + ".xls");
|
||||
File.Copy(uploadfilepath, newUrl);
|
||||
// 第一步:读取文件流
|
||||
NPOI.SS.UserModel.IWorkbook workbook;
|
||||
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
|
||||
}
|
||||
|
||||
// 创建单元格样式
|
||||
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
|
||||
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.None;
|
||||
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.None;
|
||||
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.None;
|
||||
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.None;
|
||||
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
|
||||
var font = workbook.CreateFont();
|
||||
font.FontHeightInPoints = 12;
|
||||
font.IsBold = true;
|
||||
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
|
||||
cellStyle0.SetFont(font);
|
||||
|
||||
// 第二步:创建新数据行
|
||||
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheet("Sheet1");
|
||||
NPOI.SS.UserModel.IRow row1 = sheet.CreateRow(1);
|
||||
NPOI.SS.UserModel.ICell cell2;
|
||||
// 添加测试数据
|
||||
cell2 = row1.CreateCell(14);
|
||||
cell2.CellStyle = cellStyle0;
|
||||
cell2.SetCellValue("123");
|
||||
var font2 = workbook.CreateFont();
|
||||
font2.FontHeightInPoints = 10;
|
||||
|
||||
|
||||
|
||||
// 创建单元格样式
|
||||
NPOI.SS.UserModel.ICellStyle cellStyle1 = workbook.CreateCellStyle();
|
||||
cellStyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle1.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
|
||||
cellStyle1.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
|
||||
var font3 = workbook.CreateFont();
|
||||
font3.FontHeightInPoints = 14;
|
||||
cellStyle1.SetFont(font3);
|
||||
|
||||
NPOI.SS.UserModel.ICellStyle cellStyle2 = workbook.CreateCellStyle();
|
||||
cellStyle2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
|
||||
cellStyle2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
|
||||
cellStyle2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
|
||||
cellStyle2.SetFont(font3);
|
||||
|
||||
int rowCount = 1;
|
||||
NPOI.SS.UserModel.IRow row;
|
||||
NPOI.SS.UserModel.ICell cell;
|
||||
|
||||
#region 填充内容
|
||||
foreach (DataRow tr in table.Rows)
|
||||
{
|
||||
row = sheet.CreateRow(rowCount);
|
||||
cell = row.CreateCell(0);
|
||||
cell.CellStyle = cellStyle2;
|
||||
cell.SetCellValue(tr["Code"].ToString());
|
||||
cell = row.CreateCell(1);
|
||||
cell.CellStyle = cellStyle2;
|
||||
cell.SetCellValue(tr["Name"].ToString());
|
||||
cell = row.CreateCell(2);
|
||||
cell.CellStyle = cellStyle1;
|
||||
cell.SetCellValue(tr["PreWorkCode"].ToString());
|
||||
cell = row.CreateCell(3);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (!string.IsNullOrEmpty(tr["IsMileStone"].ToString()) && Convert.ToBoolean(tr["IsMileStone"].ToString()) == true)
|
||||
{
|
||||
cell.SetCellValue("是");
|
||||
}
|
||||
cell = row.CreateCell(4);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (!string.IsNullOrEmpty(tr["JDWeights"].ToString()))
|
||||
{
|
||||
cell.SetCellValue(decimal.Round(Convert.ToDecimal(tr["JDWeights"]), 2).ToString("0.##"));
|
||||
}
|
||||
cell = row.CreateCell(5);
|
||||
cell.CellStyle = cellStyle1;
|
||||
cell.SetCellValue(tr["Unit"].ToString());
|
||||
cell = row.CreateCell(6);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (!string.IsNullOrEmpty(tr["PlanProjectQuantity"].ToString()))
|
||||
{
|
||||
cell.SetCellValue(decimal.Round(Convert.ToDecimal(tr["PlanProjectQuantity"]), 2).ToString("0.##"));
|
||||
}
|
||||
cell = row.CreateCell(7);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (!string.IsNullOrEmpty(tr["PlanCost"].ToString()))
|
||||
{
|
||||
cell.SetCellValue(decimal.Round(Convert.ToDecimal(tr["PlanCost"]), 2).ToString("0.##"));
|
||||
}
|
||||
cell = row.CreateCell(8);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (!string.IsNullOrEmpty(tr["RealProjectQuantity"].ToString()))
|
||||
{
|
||||
cell.SetCellValue(decimal.Round(Convert.ToDecimal(tr["RealProjectQuantity"]), 2).ToString("0.##"));
|
||||
}
|
||||
cell = row.CreateCell(9);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (tr["PlanStartDate"] != null)
|
||||
{
|
||||
cell.SetCellValue(string.Format("{0:yyyy-MM-dd}", tr["PlanStartDate"]));
|
||||
}
|
||||
cell = row.CreateCell(10);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (tr["PlanEndDate"] != null)
|
||||
{
|
||||
cell.SetCellValue(string.Format("{0:yyyy-MM-dd}", tr["PlanEndDate"]));
|
||||
}
|
||||
cell = row.CreateCell(11);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (tr["RealStartDate"] != null)
|
||||
{
|
||||
cell.SetCellValue(string.Format("{0:yyyy-MM-dd}", tr["RealStartDate"]));
|
||||
}
|
||||
cell = row.CreateCell(12);
|
||||
cell.CellStyle = cellStyle1;
|
||||
if (tr["RealEndDate"] != null)
|
||||
{
|
||||
cell.SetCellValue(string.Format("{0:yyyy-MM-dd}", tr["RealEndDate"]));
|
||||
}
|
||||
rowCount++;
|
||||
}
|
||||
#endregion
|
||||
// 第三步:写入文件流
|
||||
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
workbook.Write(stream);
|
||||
workbook.Close();
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowNotify("没有数据,无法导出!", MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user