Basf_FCL/FCL/FineUIPro.Web/CCP/CcpViewList.aspx.cs

934 lines
48 KiB
C#
Raw Normal View History

2024-05-08 10:17:02 +08:00
using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.CCP
{
public partial class CcpViewList : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// 绑定表格
BindGrid();
GetButtonPower();//权限设置
}
}
#region
/// <summary>
/// 绑定CCP_List
/// </summary>
private void BindGrid(int id = 0)
{
string strSql = @"SELECT ID,CCP_No,CPT_No,Contract_No,Contractor_CN+' '+Contractor_Eng as Contractor_Name,Contract_Title,
Created_Time,Pricing_Method,Created_UserName,
(select SUM(Final_SettlementAmount) from CCP_SESList as s where s.CCP_Id=a.ID ) as PaymentAmount
FROM CCP_List as a where 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(txtCCP_No.Text))
{
strSql = strSql + " AND a.CCP_No=@CCP_No";
listStr.Add(new SqlParameter("@CCP_No", txtCCP_No.Text.Trim()));
}
if (!string.IsNullOrEmpty(txtContract_No.Text))
{
strSql = strSql + " AND a.Contract_No=@Contract_No";
listStr.Add(new SqlParameter("@Contract_No", txtContract_No.Text.Trim()));
}
if (id > 0)
{
strSql = strSql + " AND a.Id=@Id";
listStr.Add(new SqlParameter("@Id", id));
}
strSql = strSql + " ORDER BY a.CCP_No ASC";
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = dt.Rows.Count;
var table = this.GetPagedDataTable(Grid1, dt);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 绑定CCP_SESList
/// </summary>
private void BindGrid1(int ccp_Id = 0)
{
string strSql = @"SELECT ID,CCP_No,CCP_Id,CPT_No,CPT_Id,Ses_No,Ses_Id,Contract_No,Contract_Id,Project_Name,
Contractor_Quotation,Incl_Tax,ThirdParty_PriceReview,Con_Days,Reduction,Reduction_Rate,
Deduction_DeductionRate,DelayedDeduction,Final_SettlementAmount,Created_Time,Created_UserId,
Created_UserName,Created_ChineseName
FROM dbo.CCP_SESList
where 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
strSql = strSql + " AND CCP_Id=@ccp_Id";
listStr.Add(new SqlParameter("@ccp_Id", ccp_Id));
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid2.RecordCount = dt.Rows.Count;
Grid2.DataSource = dt;
Grid2.DataBind();
JObject summary = new JObject();
summary.Add("Contractor_Quotation", dt.AsEnumerable().Sum(s => s.Field<decimal>("Contractor_Quotation")).ToString("#,##0.00"));
summary.Add("Incl_Tax", dt.AsEnumerable().Sum(s => s.Field<decimal>("Incl_Tax")).ToString("#,##0.00"));
summary.Add("Reduction", dt.AsEnumerable().Sum(s => s.Field<decimal>("Reduction")).ToString("#,##0.00"));
summary.Add("Deduction_DeductionRate", dt.AsEnumerable().Sum(s => s.Field<decimal>("Deduction_DeductionRate")).ToString("#,##0.00"));
summary.Add("DelayedDeduction", dt.AsEnumerable().Sum(s => s.Field<decimal>("DelayedDeduction")).ToString("#,##0.00"));
summary.Add("Final_SettlementAmount", dt.AsEnumerable().Sum(s => s.Field<decimal>("Final_SettlementAmount")).ToString("#,##0.00"));
Grid2.SummaryData = summary;
for (int i = 0; i < Grid2.Rows.Count; i++)
{
Grid2.Rows[i].Values[9] = string.Format("{0}{1}", Grid2.Rows[i].Values[9], "%");
}
}
#endregion
#region
/// <summary>
/// 关闭窗口1
/// </summary>
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 关闭窗口2
/// </summary>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <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 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 Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <summary>
/// 选择加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
if (!string.IsNullOrEmpty(Grid1.SelectedRowID))
{
BindGrid1(Convert.ToInt32(this.Grid1.SelectedRowID));
}
}
#endregion
#region
/// <summary>
/// 搜索
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtSES_No.Text.Trim()))
{
var sesModel = Funs.DB.CCP_SESList.FirstOrDefault(p => p.Ses_No == txtSES_No.Text.Trim());
if (sesModel != null)
{
var ccpModel = Funs.DB.CCP_List.FirstOrDefault(p => p.ID == sesModel.CCP_Id);
BindGrid(sesModel.CCP_Id);
BindGrid1(sesModel.CCP_Id);
Alert.ShowInTop(string.Format("CCP{0}Contract No{1}Buyer{2}", string.Format("{0:d3}", sesModel.CCP_No), sesModel.Contract_No, ccpModel.Buyer), MessageBoxIcon.Information);
return;
}
else
{
Alert.ShowInTop("CCPContract NoBuyer", MessageBoxIcon.Information);
return;
}
}
else
{
BindGrid();
}
}
#endregion
#region
protected void btnDelete_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Grid1.SelectedRowID))
{
var ccpList = from x in Funs.DB.CCP_List where x.ID == Convert.ToInt32(Grid1.SelectedRowID) select x;
var sesCcpList = from x in Funs.DB.CCP_SESList where x.CCP_Id == Convert.ToInt32(Grid1.SelectedRowID) select x;
Funs.DB.CCP_SESList.DeleteAllOnSubmit(sesCcpList);
Funs.DB.CCP_List.DeleteAllOnSubmit(ccpList);
Funs.DB.SubmitChanges();
BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Delete CCP");
// 重新绑定表格
BindGrid();
BindGrid1(0);
ShowNotify("Delete successfully!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInParent("Please select at least one record!");
return;
}
}
#endregion
#region
/// <summary>
/// 导出
/// </summary>
protected void btnExport_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInParent("Please select at least one record!");
return;
}
int row = Grid1.SelectedRowIndex;
int Id = int.Parse(Grid1.DataKeys[row][0].ToString());
string ContractNo = Grid1.DataKeys[row][1].ToString();
int ccpNo = int.Parse(Grid1.DataKeys[row][2].ToString());
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
//模板文件
string TempletFileName = rootPath + "CCPReport.xlsx";
//导出文件
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string ReportFileName = filePath + "out.xls";
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
XSSFWorkbook hssfworkbook = new XSSFWorkbook(file);
XSSFSheet ws = (XSSFSheet)hssfworkbook.GetSheetAt(0);
var ccp = Funs.DB.CCP_List.FirstOrDefault(x => x.ID == Id);
//获取当前和此CCP之前的信息
var ccpAllLs = Funs.DB.CCP_List.Where(p => p.CCP_No <= ccpNo && p.Contract_Id == ccp.Contract_Id).ToList();
//获取CCP信息
var ccpModel = ccpAllLs.FirstOrDefault(p => p.ID == Id);
if (ccpModel != null)
{
//获取当前和之前所有的ccpses的信息
var ccpAllSesLs = Funs.DB.CCP_SESList.Where(p => ccpAllLs.ConvertAll(s => s.ID).Contains(p.CCP_Id));
//获取CcpSes信息
var ccpSess = ccpAllSesLs.Where(p => p.CCP_Id == Id).OrderBy(p => p.CPT_No).ToList();
if (ccpSess.Count > 0)
{
#region
//承包商名称
if (ws.GetRow(3).GetCell(1) == null) ws.GetRow(3).CreateCell(1);
ws.GetRow(3).GetCell(1).SetCellValue(ccpModel.Contractor_CN + "\n" + ccpModel.Contractor_Eng);
//合同名称
if (ws.GetRow(4).GetCell(1) == null) ws.GetRow(4).CreateCell(1);
ws.GetRow(4).GetCell(1).SetCellValue(ccpModel.Contract_Title);
//合同类型
if (ws.GetRow(5).GetCell(1) == null) ws.GetRow(5).CreateCell(1);
ws.GetRow(5).GetCell(1).SetCellValue(ccpModel.Contract_Type);
//合同计价方式
if (ws.GetRow(6).GetCell(1) == null) ws.GetRow(6).CreateCell(1);
ws.GetRow(6).GetCell(1).SetCellValue(ccpModel.Pricing_Method);
//合同付款条件
if (ws.GetRow(7).GetCell(1) == null) ws.GetRow(7).CreateCell(1);
var payType = ccpModel.Payment_Term == "0" ? "按月" : "按季";
//var payZnum = ccpModel.Payment_Term == "0" ? "三十" : "九十";
//var paynum = ccpModel.Payment_Term == "0" ? "30" : "90";
//var paymentTermExplain = string.Format("合同价款{0}支付,业主将在收到正确的发票原件以后{1}{2})日内支付。", payType, payZnum, paynum);
var paymentTermExplain = string.Format("合同价款{0}支付业主将在收到正确的发票原件以后三十30日内支付。", payType);
ws.GetRow(7).GetCell(1).SetCellValue(paymentTermExplain);
//本次付款确认单的序列号
if (ws.GetRow(9).GetCell(2) == null) ws.GetRow(9).CreateCell(2);
ws.GetRow(9).GetCell(2).SetCellValue(string.Format("{0:d3}", ccpModel.CCP_No));
//已付总金额
var yfzje = 0d;
if (ccpAllSesLs.Count(p => p.CCP_Id != Id) > 0)
{
yfzje = (double)ccpAllSesLs.Where(p => p.CCP_Id != Id).Sum(p => p.Final_SettlementAmount).Value;
}
if (ws.GetRow(11).GetCell(2) == null) ws.GetRow(11).CreateCell(2);
ws.GetRow(11).GetCell(2).SetCellValue(yfzje);
//本次付款金额
if (ws.GetRow(12).GetCell(2) == null) ws.GetRow(12).CreateCell(2);
ws.GetRow(12).GetCell(2).SetCellValue(ccpSess.Count > 0 ? (double)ccpSess.Sum(p => p.Final_SettlementAmount).Value : 0);
#endregion
#region
//承包商代码
if (ws.GetRow(3).GetCell(7) == null) ws.GetRow(3).CreateCell(7);
ws.GetRow(3).GetCell(7).SetCellValue(ccpModel.Vendor_Code);
//合同号
if (ws.GetRow(4).GetCell(7) == null) ws.GetRow(4).CreateCell(7);
ws.GetRow(4).GetCell(7).SetCellValue(ccpModel.Contract_No);
//责任采购员
if (ws.GetRow(5).GetCell(7) == null) ws.GetRow(5).CreateCell(7);
ws.GetRow(5).GetCell(7).SetCellValue(ccpModel.Buyer);
//合同预算值
if (ws.GetRow(6).GetCell(7) == null) ws.GetRow(6).CreateCell(7);
ws.GetRow(6).GetCell(7).SetCellValue((double)ccpModel.Contract_Budget);
//次付款对应的CPT号
var cpts = ccpModel.CPT_No.Split(',').Select(p => string.Format("{0:d3}", int.Parse(p.Split('-').LastOrDefault()))).ToList();
if (ws.GetRow(9).GetCell(7) == null) ws.GetRow(9).CreateCell(7);
ws.GetRow(9).GetCell(7).SetCellValue(string.Join(",", cpts.ToArray()));
#endregion
#region
XSSFSheet wstwo = (XSSFSheet)hssfworkbook.GetSheet("sheet2");
#region
//全局边框靠左
XSSFFont font = (XSSFFont)hssfworkbook.CreateFont();
font.FontHeightInPoints = 10;
font.FontName = "Arial";
ICellStyle style = hssfworkbook.CreateCellStyle();
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
style.VerticalAlignment = VerticalAlignment.Center;
style.Alignment = HorizontalAlignment.Left;
style.WrapText = true;
style.SetFont(font);
//全局边框靠左红色字体
XSSFFont font1 = (XSSFFont)hssfworkbook.CreateFont();
font1.FontHeightInPoints = 10;
font1.FontName = "Arial";
font1.Color = IndexedColors.Red.Index;
ICellStyle style1 = hssfworkbook.CreateCellStyle();
style1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
style1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
style1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
style1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
style1.VerticalAlignment = VerticalAlignment.Center;
style1.Alignment = HorizontalAlignment.Left;
style1.WrapText = true;
style1.SetFont(font1);
//全局边框靠右
XSSFFont rfont = (XSSFFont)hssfworkbook.CreateFont();
rfont.FontHeightInPoints = 10;
rfont.FontName = "Arial";
ICellStyle rstyle = hssfworkbook.CreateCellStyle();
rstyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.VerticalAlignment = VerticalAlignment.Center;
rstyle.Alignment = HorizontalAlignment.Right;
rstyle.WrapText = true;
rstyle.SetFont(font);
//全局边框靠右红色字体
XSSFFont rfont1 = (XSSFFont)hssfworkbook.CreateFont();
rfont1.FontHeightInPoints = 10;
rfont1.FontName = "Arial";
rfont1.Color = IndexedColors.Red.Index;
ICellStyle rstyle1 = hssfworkbook.CreateCellStyle();
rstyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle1.VerticalAlignment = VerticalAlignment.Center;
rstyle1.Alignment = HorizontalAlignment.Right;
rstyle1.WrapText = true;
rstyle1.SetFont(font1);
IDataFormat dataformat = hssfworkbook.CreateDataFormat();
//千分位全局边框靠右
XSSFFont qfont = (XSSFFont)hssfworkbook.CreateFont();
qfont.FontHeightInPoints = 10;
qfont.FontName = "Arial";
ICellStyle qstyle = hssfworkbook.CreateCellStyle();
qstyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.VerticalAlignment = VerticalAlignment.Center;
qstyle.Alignment = HorizontalAlignment.Right;
qstyle.DataFormat = dataformat.GetFormat("#,##0.00");
qstyle.SetFont(qfont);
//千分位全局边框靠右红色字体
XSSFFont qfont1 = (XSSFFont)hssfworkbook.CreateFont();
qfont1.FontHeightInPoints = 10;
qfont1.FontName = "Arial";
qfont1.Color = IndexedColors.Red.Index;
ICellStyle qstyle1 = hssfworkbook.CreateCellStyle();
qstyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.VerticalAlignment = VerticalAlignment.Center;
qstyle1.Alignment = HorizontalAlignment.Right;
qstyle1.DataFormat = dataformat.GetFormat("#,##0.00");
qstyle1.SetFont(qfont1);
//百分比全局边框靠右
XSSFFont bfont = (XSSFFont)hssfworkbook.CreateFont();
bfont.FontHeightInPoints = 10;
bfont.FontName = "Arial";
ICellStyle bstyle = hssfworkbook.CreateCellStyle();
bstyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle.VerticalAlignment = VerticalAlignment.Center;
bstyle.Alignment = HorizontalAlignment.Right;
bstyle.DataFormat = dataformat.GetFormat("0.00%");
bstyle.SetFont(bfont);
//百分比全局边框靠右红色字体
XSSFFont bfont1 = (XSSFFont)hssfworkbook.CreateFont();
bfont1.FontHeightInPoints = 10;
bfont1.FontName = "Arial";
bfont1.Color = IndexedColors.Red.Index;
ICellStyle bstyle1 = hssfworkbook.CreateCellStyle();
bstyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
bstyle1.VerticalAlignment = VerticalAlignment.Center;
bstyle1.Alignment = HorizontalAlignment.Right;
bstyle1.DataFormat = dataformat.GetFormat("0.00%");
bstyle1.SetFont(bfont1);
#endregion
#region
int rowindex = 5;
foreach (var item in ccpSess)
{
//合同号
if (wstwo.GetRow(rowindex).GetCell(0) == null) wstwo.GetRow(rowindex).CreateCell(0);
wstwo.GetRow(rowindex).GetCell(0).SetCellValue(item.Contract_No);
wstwo.GetRow(rowindex).GetCell(0).CellStyle = style;
//CCP No.
if (wstwo.GetRow(rowindex).GetCell(1) == null) wstwo.GetRow(rowindex).CreateCell(1);
wstwo.GetRow(rowindex).GetCell(1).SetCellValue(string.Format("{0:d3}", item.CCP_No));
wstwo.GetRow(rowindex).GetCell(1).CellStyle = style;
//CPT No.
if (wstwo.GetRow(rowindex).GetCell(2) == null) wstwo.GetRow(rowindex).CreateCell(2);
wstwo.GetRow(rowindex).GetCell(2).SetCellValue(item.CPT_No.Split('-').LastOrDefault());
wstwo.GetRow(rowindex).GetCell(2).CellStyle = style;
//SES No.
if (wstwo.GetRow(rowindex).GetCell(3) == null) wstwo.GetRow(rowindex).CreateCell(3);
wstwo.GetRow(rowindex).GetCell(3).SetCellValue(item.Ses_No);
wstwo.GetRow(rowindex).GetCell(3).CellStyle = style;
//项目名称
if (wstwo.GetRow(rowindex).GetCell(4) == null) wstwo.GetRow(rowindex).CreateCell(4);
wstwo.GetRow(rowindex).GetCell(4).SetCellValue(item.Project_Name);
wstwo.GetRow(rowindex).GetCell(4).CellStyle = style;
//承包商报价
if (wstwo.GetRow(rowindex).GetCell(5) == null) wstwo.GetRow(rowindex).CreateCell(5);
wstwo.GetRow(rowindex).GetCell(5).SetCellValue((double)item.Contractor_Quotation);
wstwo.GetRow(rowindex).GetCell(5).CellStyle = item.Contractor_Quotation.Value >= 0 ? qstyle : qstyle1;
//CTE/D审价
if (wstwo.GetRow(rowindex).GetCell(6) == null) wstwo.GetRow(rowindex).CreateCell(6);
wstwo.GetRow(rowindex).GetCell(6).SetCellValue((double)item.Incl_Tax);
wstwo.GetRow(rowindex).GetCell(6).CellStyle = item.Incl_Tax.Value >= 0 ? qstyle : qstyle1;
//第三方审价
if (wstwo.GetRow(rowindex).GetCell(7) == null) wstwo.GetRow(rowindex).CreateCell(7);
wstwo.GetRow(rowindex).GetCell(7).SetCellValue((double)item.ThirdParty_PriceReview);
wstwo.GetRow(rowindex).GetCell(7).CellStyle = item.ThirdParty_PriceReview.Value >= 0 ? qstyle : qstyle1;
//核减额
if (wstwo.GetRow(rowindex).GetCell(8) == null) wstwo.GetRow(rowindex).CreateCell(8);
wstwo.GetRow(rowindex).GetCell(8).SetCellValue((double)item.Reduction);
wstwo.GetRow(rowindex).GetCell(8).CellStyle = item.Reduction.Value >= 0 ? qstyle : qstyle1;
//核减率
if (wstwo.GetRow(rowindex).GetCell(9) == null) wstwo.GetRow(rowindex).CreateCell(9);
wstwo.GetRow(rowindex).GetCell(9).SetCellValue((double)item.Reduction_Rate / 100);
wstwo.GetRow(rowindex).GetCell(9).CellStyle = item.Reduction_Rate.Value >= 0 ? bstyle : bstyle1;
//高核减率扣款
if (wstwo.GetRow(rowindex).GetCell(10) == null) wstwo.GetRow(rowindex).CreateCell(10);
wstwo.GetRow(rowindex).GetCell(10).SetCellValue((double)item.Deduction_DeductionRate);
wstwo.GetRow(rowindex).GetCell(10).CellStyle = item.Deduction_DeductionRate.Value >= 0 ? qstyle : qstyle1;
//SSR结算提交天数
if (wstwo.GetRow(rowindex).GetCell(11) == null) wstwo.GetRow(rowindex).CreateCell(11);
wstwo.GetRow(rowindex).GetCell(11).SetCellValue(item.Con_Days != null ? item.Con_Days.Value : 0);
wstwo.GetRow(rowindex).GetCell(11).CellStyle = item.Con_Days != null && item.Con_Days.Value > 0 ? rstyle : rstyle1;
//延迟扣款
if (wstwo.GetRow(rowindex).GetCell(12) == null) wstwo.GetRow(rowindex).CreateCell(12);
wstwo.GetRow(rowindex).GetCell(12).SetCellValue((double)item.DelayedDeduction);
wstwo.GetRow(rowindex).GetCell(12).CellStyle = item.DelayedDeduction.Value >= 0 ? qstyle : qstyle1;
//最终结算金额(含税)
if (wstwo.GetRow(rowindex).GetCell(13) == null) wstwo.GetRow(rowindex).CreateCell(13);
wstwo.GetRow(rowindex).GetCell(13).SetCellValue((double)item.Final_SettlementAmount);
wstwo.GetRow(rowindex).GetCell(13).CellStyle = item.Final_SettlementAmount >= 0 ? qstyle : qstyle1;
rowindex++;
}
#endregion
#region
//合同号
if (wstwo.GetRow(rowindex).GetCell(0) == null) wstwo.GetRow(rowindex).CreateCell(0);
wstwo.GetRow(rowindex).GetCell(0).SetCellValue("");
wstwo.GetRow(rowindex).GetCell(0).CellStyle = style;
//CCP No.
if (wstwo.GetRow(rowindex).GetCell(1) == null) wstwo.GetRow(rowindex).CreateCell(1);
wstwo.GetRow(rowindex).GetCell(1).SetCellValue("");
wstwo.GetRow(rowindex).GetCell(1).CellStyle = style;
//CPT No.
if (wstwo.GetRow(rowindex).GetCell(2) == null) wstwo.GetRow(rowindex).CreateCell(2);
wstwo.GetRow(rowindex).GetCell(2).SetCellValue("");
wstwo.GetRow(rowindex).GetCell(2).CellStyle = style;
//SES No.
if (wstwo.GetRow(rowindex).GetCell(3) == null) wstwo.GetRow(rowindex).CreateCell(3);
wstwo.GetRow(rowindex).GetCell(3).SetCellValue("");
wstwo.GetRow(rowindex).GetCell(3).CellStyle = style;
//项目名称
if (wstwo.GetRow(rowindex).GetCell(4) == null) wstwo.GetRow(rowindex).CreateCell(4);
wstwo.GetRow(rowindex).GetCell(4).SetCellValue("总计");
wstwo.GetRow(rowindex).GetCell(4).CellStyle = style;
//承包商报价
if (wstwo.GetRow(rowindex).GetCell(5) == null) wstwo.GetRow(rowindex).CreateCell(5);
wstwo.GetRow(rowindex).GetCell(5).SetCellValue((double)ccpSess.Sum(p => p.Contractor_Quotation));
wstwo.GetRow(rowindex).GetCell(5).CellStyle = ccpSess.Sum(p => p.Contractor_Quotation) >= 0 ? qstyle : qstyle1;
//CTE/D审价
if (wstwo.GetRow(rowindex).GetCell(6) == null) wstwo.GetRow(rowindex).CreateCell(6);
wstwo.GetRow(rowindex).GetCell(6).SetCellValue((double)ccpSess.Sum(p => p.Incl_Tax));
wstwo.GetRow(rowindex).GetCell(6).CellStyle = ccpSess.Sum(p => p.Incl_Tax) >= 0 ? qstyle : qstyle1;
//第三方审价
if (wstwo.GetRow(rowindex).GetCell(7) == null) wstwo.GetRow(rowindex).CreateCell(7);
wstwo.GetRow(rowindex).GetCell(7).SetCellValue("");
wstwo.GetRow(rowindex).GetCell(7).CellStyle = style;
//核减额
if (wstwo.GetRow(rowindex).GetCell(8) == null) wstwo.GetRow(rowindex).CreateCell(8);
wstwo.GetRow(rowindex).GetCell(8).SetCellValue((double)ccpSess.Sum(p => p.Reduction));
wstwo.GetRow(rowindex).GetCell(8).CellStyle = ccpSess.Sum(p => p.Reduction) >= 0 ? qstyle : qstyle1;
//核减率
if (wstwo.GetRow(rowindex).GetCell(9) == null) wstwo.GetRow(rowindex).CreateCell(9);
wstwo.GetRow(rowindex).GetCell(9).SetCellValue("");
wstwo.GetRow(rowindex).GetCell(9).CellStyle = style;
//高核减率扣款
if (wstwo.GetRow(rowindex).GetCell(10) == null) wstwo.GetRow(rowindex).CreateCell(10);
wstwo.GetRow(rowindex).GetCell(10).SetCellValue((double)ccpSess.Sum(p => p.Deduction_DeductionRate));
wstwo.GetRow(rowindex).GetCell(10).CellStyle = ccpSess.Sum(p => p.Deduction_DeductionRate) >= 0 ? qstyle : qstyle1;
//SSR结算提交天数
if (wstwo.GetRow(rowindex).GetCell(11) == null) wstwo.GetRow(rowindex).CreateCell(11);
wstwo.GetRow(rowindex).GetCell(11).SetCellValue("");
wstwo.GetRow(rowindex).GetCell(11).CellStyle = style;
//延迟扣款
if (wstwo.GetRow(rowindex).GetCell(12) == null) wstwo.GetRow(rowindex).CreateCell(12);
wstwo.GetRow(rowindex).GetCell(12).SetCellValue((double)ccpSess.Sum(p => p.DelayedDeduction));
wstwo.GetRow(rowindex).GetCell(12).CellStyle = ccpSess.Sum(p => p.DelayedDeduction) >= 0 ? qstyle : qstyle1;
//最终结算金额(含税)
if (wstwo.GetRow(rowindex).GetCell(13) == null) wstwo.GetRow(rowindex).CreateCell(13);
wstwo.GetRow(rowindex).GetCell(13).SetCellValue((double)ccpSess.Sum(p => p.Final_SettlementAmount));
wstwo.GetRow(rowindex).GetCell(13).CellStyle = ccpSess.Sum(p => p.Final_SettlementAmount) >= 0 ? qstyle : qstyle1;
#endregion
#region TT30和BD90
int ttrate = 0;
double ttMount = 0;
int dbrate = 0;
double dbMount = 0;
var ttDbhsl = (ccpSess.Sum(p => p.Contractor_Quotation) - ccpSess.Sum(p => p.Final_SettlementAmount)) / ccpSess.Sum(p => p.Contractor_Quotation) * 100;
if (ttDbhsl < 10)
{
ttrate = 100;
ttMount = (double)ccpSess.Sum(p => p.Final_SettlementAmount);
}
else if (ttDbhsl >= 10 && ttDbhsl < 20)
{
ttrate = 70;
ttMount = (double)ccpSess.Sum(p => p.Final_SettlementAmount) * 0.7;
dbrate = 30;
dbMount = (double)ccpSess.Sum(p => p.Final_SettlementAmount) - ttMount;
}
else
{
ttrate = 50;
ttMount = (double)ccpSess.Sum(p => p.Final_SettlementAmount) / 2;
dbrate = 50;
dbMount = ttMount;
}
//TT30比例
if (wstwo.GetRow(1).GetCell(12) == null) wstwo.GetRow(1).CreateCell(12);
wstwo.GetRow(1).GetCell(12).SetCellValue(ttrate);
wstwo.GetRow(1).GetCell(12).CellStyle = style;
//TT30金额
if (wstwo.GetRow(1).GetCell(13) == null) wstwo.GetRow(1).CreateCell(13);
wstwo.GetRow(1).GetCell(13).SetCellValue(ttMount);
wstwo.GetRow(1).GetCell(13).CellStyle = ttMount >= 0 ? qstyle : qstyle1;
//BD90比例
if (wstwo.GetRow(2).GetCell(12) == null) wstwo.GetRow(2).CreateCell(12);
wstwo.GetRow(2).GetCell(12).SetCellValue(dbrate);
wstwo.GetRow(2).GetCell(12).CellStyle = style;
//BD90金额
if (wstwo.GetRow(2).GetCell(13) == null) wstwo.GetRow(2).CreateCell(13);
wstwo.GetRow(2).GetCell(13).SetCellValue(dbMount);
wstwo.GetRow(2).GetCell(13).CellStyle = dbMount >= 0 ? qstyle : qstyle1;
#endregion
#endregion
ws.ForceFormulaRecalculation = true;
wstwo.ForceFormulaRecalculation = true;
using (FileStream filess = File.OpenWrite(ReportFileName))
{
hssfworkbook.Write(filess);
}
FileInfo filet = new FileInfo(ReportFileName);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(string.Format("{0}-CCP-{1}", ccpModel.Contract_No, string.Format("{0:d3}", ccpModel.CCP_No))) + ".xlsx");
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", filet.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(filet.FullName);
// 停止页面的执行
Response.End();
}
else
{
Alert.ShowInParent("当前CCP没有SES明细信息无法导出!");
return;
}
}
}
/// <summary>
/// 导出ccp列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnExportCcp_Click(object sender, EventArgs e)
{
var fileName = string.Format("{0}_{1}", "CCP", DateTime.Now.ToString("yyyy-MM-dd"));
XSSFWorkbook book = new XSSFWorkbook();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
string strSql = @"SELECT ID,CCP_No,CPT_No,Contract_No,Contractor_CN+' '+Contractor_Eng as Contractor_Name,Contract_Title,Created_Time,Pricing_Method,Created_UserName,(select SUM(Final_SettlementAmount) from CCP_SESList as s where s.CCP_Id=a.ID ) as PaymentAmount FROM CCP_List as a where 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(txtCCP_No.Text))
{
strSql = strSql + " AND a.CCP_No=@CCP_No";
listStr.Add(new SqlParameter("@CCP_No", txtCCP_No.Text.Trim()));
}
if (!string.IsNullOrEmpty(txtContract_No.Text))
{
strSql = strSql + " AND a.Contract_No=@Contract_No";
listStr.Add(new SqlParameter("@Contract_No", txtContract_No.Text.Trim()));
}
strSql = strSql + " ORDER BY a.CCP_No ASC";
SqlParameter[] parameter = listStr.ToArray();
DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter);
if (dt.Rows.Count == 0)
{
Alert.ShowInParent("当前CCP没有无数据无法导出!");
return;
}
//sheet名称
XSSFSheet sheet = (XSSFSheet)book.CreateSheet(fileName);
#region
//列头居中样式
XSSFFont tfont = (XSSFFont)book.CreateFont();
tfont.FontHeightInPoints = 10;
tfont.FontName = "Arial";
tfont.IsBold = true;
ICellStyle titleStyle = book.CreateCellStyle();
titleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
titleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
titleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
titleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
titleStyle.VerticalAlignment = VerticalAlignment.Center;
titleStyle.Alignment = HorizontalAlignment.Center;
titleStyle.WrapText = true;
titleStyle.SetFont(tfont);
//全局边框靠左
XSSFFont font = (XSSFFont)book.CreateFont();
font.FontHeightInPoints = 10;
font.FontName = "Arial";
ICellStyle style = book.CreateCellStyle();
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
style.VerticalAlignment = VerticalAlignment.Center;
style.Alignment = HorizontalAlignment.Left;
style.WrapText = true;
style.SetFont(font);
//全局边框靠右
XSSFFont rfont = (XSSFFont)book.CreateFont();
rfont.FontHeightInPoints = 10;
rfont.FontName = "Arial";
ICellStyle rstyle = book.CreateCellStyle();
rstyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
rstyle.VerticalAlignment = VerticalAlignment.Center;
rstyle.Alignment = HorizontalAlignment.Right;
rstyle.WrapText = true;
rstyle.SetFont(font);
IDataFormat dataformat = book.CreateDataFormat();
//千分位全局边框靠右
XSSFFont qfont = (XSSFFont)book.CreateFont();
qfont.FontHeightInPoints = 10;
qfont.FontName = "Arial";
ICellStyle qstyle = book.CreateCellStyle();
qstyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle.VerticalAlignment = VerticalAlignment.Center;
qstyle.Alignment = HorizontalAlignment.Right;
qstyle.DataFormat = dataformat.GetFormat("#,##0.00");
qstyle.SetFont(qfont);
//千分位全局边框靠右红色字体
XSSFFont qfont1 = (XSSFFont)book.CreateFont();
qfont1.FontHeightInPoints = 10;
qfont1.FontName = "Arial";
qfont1.Color = IndexedColors.Red.Index;
ICellStyle qstyle1 = book.CreateCellStyle();
qstyle1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
qstyle1.VerticalAlignment = VerticalAlignment.Center;
qstyle1.Alignment = HorizontalAlignment.Right;
qstyle1.DataFormat = dataformat.GetFormat("#,##0.00");
qstyle1.SetFont(qfont1);
#endregion
#region
sheet.SetColumnWidth(0, 10 * 256);
sheet.SetColumnWidth(1, 20 * 256);
sheet.SetColumnWidth(2, 70 * 256);
sheet.SetColumnWidth(3, 30 * 256);
sheet.SetColumnWidth(4, 20 * 256);
sheet.SetColumnWidth(5, 30 * 256);
sheet.SetColumnWidth(6, 20 * 256);
sheet.SetColumnWidth(7, 20 * 256);
#endregion
#region
XSSFRow headerRow = (XSSFRow)sheet.CreateRow(0);
headerRow.CreateCell(0).SetCellValue("CCP No");
headerRow.GetCell(0).CellStyle = titleStyle;
headerRow.CreateCell(1).SetCellValue("Contract No");
headerRow.GetCell(1).CellStyle = titleStyle;
headerRow.CreateCell(2).SetCellValue("Contractor Name");
headerRow.GetCell(2).CellStyle = titleStyle;
headerRow.CreateCell(3).SetCellValue("Contract Title");
headerRow.GetCell(3).CellStyle = titleStyle;
headerRow.CreateCell(4).SetCellValue("Created Time");
headerRow.GetCell(4).CellStyle = titleStyle;
headerRow.CreateCell(5).SetCellValue("Pricing Method");
headerRow.GetCell(5).CellStyle = titleStyle;
headerRow.CreateCell(6).SetCellValue("Buyer");
headerRow.GetCell(6).CellStyle = titleStyle;
headerRow.CreateCell(7).SetCellValue("承包商报价");
headerRow.GetCell(7).CellStyle = titleStyle;
headerRow.CreateCell(8).SetCellValue("CTE/D审价");
headerRow.GetCell(8).CellStyle = titleStyle;
headerRow.CreateCell(9).SetCellValue("高核减率扣款");
headerRow.GetCell(9).CellStyle = titleStyle;
headerRow.CreateCell(10).SetCellValue("延迟扣款");
headerRow.GetCell(10).CellStyle = titleStyle;
headerRow.CreateCell(11).SetCellValue("付款金额");
headerRow.GetCell(11).CellStyle = titleStyle;
#endregion
#region
int rowIndex = 1;
if (dt.Rows.Count > 0)
{
var ccpAllLs = dt.AsEnumerable().Select(s => s.Field<int>("ID")).ToList();
//获取当前和之前所有的ccpses的信息
var ccpAllSesLs = Funs.DB.CCP_SESList.Where(p => ccpAllLs.ConvertAll(s => s).Contains(p.CCP_Id));
for (int i = 0; i < dt.Rows.Count; i++)
{
int itemId = !string.IsNullOrEmpty(dt.Rows[i]["ID"].ToString()) ? int.Parse(dt.Rows[i]["ID"].ToString()) : 0;
if (itemId == 0) continue;
//获取CcpSes信息
var ccpSess = ccpAllSesLs.Where(p => p.CCP_Id == itemId).ToList();
//创建行
XSSFRow row = (XSSFRow)sheet.CreateRow(rowIndex);
row.CreateCell(0).SetCellValue(dt.Rows[i]["CCP_No"] != null ? dt.Rows[i]["CCP_No"].ToString() : string.Empty);
row.GetCell(0).CellStyle = style;
row.CreateCell(1).SetCellValue(dt.Rows[i]["Contract_No"] != null ? dt.Rows[i]["Contract_No"].ToString() : string.Empty);
row.GetCell(1).CellStyle = style;
row.CreateCell(2).SetCellValue(dt.Rows[i]["Contractor_Name"] != null ? dt.Rows[i]["Contractor_Name"].ToString() : string.Empty);
row.GetCell(2).CellStyle = style;
row.CreateCell(3).SetCellValue(dt.Rows[i]["Contract_Title"] != null ? dt.Rows[i]["Contract_Title"].ToString() : string.Empty);
row.GetCell(3).CellStyle = style;
row.CreateCell(4).SetCellValue(dt.Rows[i]["Created_Time"] != null ? dt.Rows[i]["Created_Time"].ToString() : string.Empty);
row.GetCell(4).CellStyle = style;
row.CreateCell(5).SetCellValue(dt.Rows[i]["Pricing_Method"] != null ? dt.Rows[i]["Pricing_Method"].ToString() : string.Empty);
row.GetCell(5).CellStyle = style;
row.CreateCell(6).SetCellValue(dt.Rows[i]["Created_UserName"] != null ? dt.Rows[i]["Created_UserName"].ToString() : string.Empty);
row.GetCell(6).CellStyle = style;
//承包商报价
row.CreateCell(7).SetCellValue((double)ccpSess.Sum(p => p.Contractor_Quotation));
row.GetCell(7).CellStyle = ccpSess.Sum(p => p.Contractor_Quotation) >= 0 ? qstyle : qstyle1;
//CTE/D审价
row.CreateCell(8).SetCellValue((double)ccpSess.Sum(p => p.Incl_Tax));
row.GetCell(8).CellStyle = ccpSess.Sum(p => p.Incl_Tax) >= 0 ? qstyle : qstyle1;
//高核减率扣款
row.CreateCell(9).SetCellValue((double)ccpSess.Sum(p => p.Deduction_DeductionRate));
row.GetCell(9).CellStyle = ccpSess.Sum(p => p.Deduction_DeductionRate) >= 0 ? qstyle : qstyle1;
//延迟扣款
row.CreateCell(10).SetCellValue((double)ccpSess.Sum(p => p.DelayedDeduction));
row.GetCell(10).CellStyle = ccpSess.Sum(p => p.DelayedDeduction) >= 0 ? qstyle : qstyle1;
row.CreateCell(11).SetCellValue(dt.Rows[i]["PaymentAmount"] != null ? dt.Rows[i]["PaymentAmount"].ToString() : string.Empty);
row.GetCell(11).CellStyle = rstyle;
rowIndex++;
}
}
#endregion
book.Write(ms);
byte[] strmByte = ms.ToArray();
ms.Dispose();
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; fileName=" + fileName + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", strmByte.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.BinaryWrite(strmByte);
// 停止页面的执行
Response.End();
}
#endregion
#region
/// <summary>
/// 菜单按钮权限
/// </summary>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.UserId, BLL.Const.CPTViewListMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnDelete.Hidden = false;
}
else
{
this.btnDelete.Hidden = true;
}
}
}
#endregion
}
}