打印PDF
using iTextSharp.text.pdf;
using iTextSharp.text;
//字体
private BaseFont bfHei = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//表格宽度
private float _tablewidth = 500f;
//将PDF通过浏览器下载到客户端
private void PDFToLocal(string PdfPath ,string docName)
{
base.Response.Clear();
byte[] data = File.ReadAllBytes(PdfPath + docName + ".pdf");
MemoryStream stream = new MemoryStream(data);
base.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}.pdf", docName));
base.Response.BinaryWrite(stream.ToArray());
stream.Close();
stream.Dispose();
File.Delete(PdfPath + docName + ".pdf");
base.Response.End();
}
///<summary>
///客户账单模板
/// PDFType 1:对账单 2:欠款单
/// </summary>
private void PDFCustomer(int PDFType)
{
#region PDF设置
string PdfPath = Server.MapPath("/Upload/Temp/");
string docType = "";
if (PDFType==1)
{
docType = "客户对账单";
}
else if (PDFType == 2)
{
docType = "客户欠款单";
}
string docName = string.Format("{0}{1:yyyyMMddHHmmssffff}", docType, DateTime.Now);
//设置中文字体
//BaseFont bfHei = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bfHei, 11);
iTextSharp.text.Font font2 = new iTextSharp.text.Font(bfHei, 10);
//设置居中
int aligncenter = iTextSharp.text.Rectangle.ALIGN_CENTER;
//设置纸张尺寸
int pagenum = int.Parse(this.ddlPaperSize.SelectedValue);
iTextSharp.text.Rectangle pagesize = PageSize.A4;
switch (pagenum)
{
case 0: pagesize = PageSize.A0; break;
case 1: pagesize = PageSize.A1; break;
case 2: pagesize = PageSize.A2; break;
case 3: pagesize = PageSize.A3; break;
case 4: pagesize = PageSize.A4; break;
case 5: pagesize = PageSize.A5; break;
}
iTextSharp.text.Document document = new iTextSharp.text.Document(pagesize);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(PdfPath + docName + ".pdf", FileMode.Create));
#endregion
#region 数据来源
//获取数据
StringBuilder builder = new StringBuilder();
//付款状态
if (PDFType == 2)
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" PaymentStatus = 0 ");
}
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" CreatedDate between '{0}' and '{1}' ", InjectionFilter.QuoteFilter(this.txtCreatedDateStart.Text.Trim()), InjectionFilter.QuoteFilter(this.txtCreatedDateEnd.Text.Trim()));
}
//值查看印刷订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" OrderType in ({0},{1}) ", (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Print, (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Template);
//已发货的订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" ShippingStatus>1 ");
DataSet dataSetSource = this.orderBll.GetListWithEmployee(-1, builder.ToString(), "CreatedDate desc");
DateTime orderStartTime = new DateTime();
DateTime orderEndTime = new DateTime();
int TimeCountFlag = 0;
//BuyerID去重、EmployeeID去重
HashSet<int> BuyerIDs = new HashSet<int>();
HashSet<int> EmployeeIDs = new HashSet<int>();
foreach (DataRow row0 in dataSetSource.Tables[0].Rows)
{
TimeCountFlag++;
if (TimeCountFlag == 1)
{
orderEndTime = row0.Field<DateTime>("CreatedDate");
}
if (TimeCountFlag == dataSetSource.Tables[0].Rows.Count)
{
orderStartTime = row0.Field<DateTime>("CreatedDate");
}
BuyerIDs.Add(row0.Field<int>("BuyerID"));
EmployeeIDs.Add(row0.Field<int>("UserID"));
}
string startTime = "";
string endTime = "";
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
startTime = this.txtCreatedDateEnd.Text.Trim();
endTime = this.txtCreatedDateStart.Text.Trim();
}
else
{
startTime = orderStartTime.ToString("yyyy-MM-dd hh:mm:ss");
endTime = orderEndTime.ToString("yyyy-MM-dd hh:mm:ss");
}
#endregion
//this.BindData();
//DataSet dataSetSource = this.gridView.DataSetSource;
HashSet<int> hs = new HashSet<int>();
hs = BuyerIDs;
if (hs.Count == 0)
{
MessageBox.ShowFailTip(this, "抱歉,暂无数据!");
return;
}
else
{
document.Open();
}
foreach (var hsNow in hs)
{
#region BuyerID
int countflag = 1;
StringBuilder sbBuyerID = new StringBuilder();
//按客户分页
sbBuyerID.AppendFormat(" and BuyerID={0} ", hsNow.ToString());
DataSet dataSetSource2 = this.orderBll.GetListWithEmployee(-1, builder.ToString() + sbBuyerID.ToString(), "CreatedDate desc");
//汇总数据
//总金额
decimal AllPageAmount = 0;
//总已付款
decimal AllPagePaid = 0;
//总欠款
decimal AllPageDebt = 0;
#region 打印数据
int rowCount = 1;
foreach (DataRow row2 in dataSetSource2.Tables[0].Rows)
{
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(11);//11列
table.TotalWidth = _tablewidth;
table.LockedWidth = false;
#region 表头
if (countflag == 1)
{
//按客户分页
//row["收货地址"]
string Address = row2.Field<String>("ShipRegion") + row2.Field<String>("ShipAddress");
//row["收货人"]
string ShipName = row2.Field<String>("ShipName");
//row["电话"]
string CellPhone = row2.Field<String>("ShipCellPhone");
//手机ShipTelPhone
string Phone = row2.Field<String>("ShipTelPhone");
//发货方式ShippingModeName
string ShipWay = row2.Field<String>("ShippingModeName");
//客户名称
V5print.Model.Members.Users user = userBll.GetModel(row2.Field<int>("BuyerId"));
string UserNickName = user.NickName;
//取出当前用户的所有的用信用支付且未支付的订单信息,包括本次下单的信息
string sql = string.Format(" BuyerID={0} and PaymentStatus=0 and PaymentGateway='credit'", user.UserID);
List<V5print.Model.Shop.Order.OrderInfo> orderList = orderBll.GetModelList(sql);
decimal debt = 0;//欠款金额
if (orderList.Count > 0)
{
foreach (V5print.Model.Shop.Order.OrderInfo order in orderList)
{
debt += order.Amount;
}
}
//row["欠款"] = Math.Round(debt, 2);
string AllDebt = Math.Round(debt, 2).ToString();
V5print.BLL.Members.UsersExp userexpbLL = new V5print.BLL.Members.UsersExp();
V5print.Model.Members.UsersExpModel userexp = userexpbLL.GetUsersExpModel(user.UserID);
decimal bal = 0;
if (userexp != null)
{
bal = Math.Round(decimal.Parse(userexp.Balance.ToString()), 2);
}
string balance = bal.ToString();
PdfPCell header1 = new PdfPCell(new Phrase("地址:" + Address, font));
PdfPCell header2 = new PdfPCell(new Phrase("联系人:" + ShipName, font));
PdfPCell header3 = new PdfPCell(new Phrase("电话:" + CellPhone, font));
PdfPCell header4 = new PdfPCell(new Phrase("手机:" + Phone, font));
PdfPCell header5 = new PdfPCell(new Phrase("发货方式:" + ShipWay, font));
PdfPCell header6 = new PdfPCell(new Phrase("客户名称:" + UserNickName, font));
//PdfPCell header7 = new PdfPCell(new Phrase("总欠款:" + AllDebt, font));
//Phrase h8phrase = new Phrase();
//if (this.cbShowBalance.Checked)
//{
// h8phrase = new Phrase("预存余额:" + balance, font);
//}
//PdfPCell header8 = new PdfPCell(h8phrase);
//设置每个单元格所占列数
header1.Colspan = 6;
header2.Colspan = 5;
header3.Colspan = 3;
header4.Colspan = 3;
header5.Colspan = 5;
header6.Colspan = 11;
//header7.Colspan = 6;
//header8.Colspan = 5;
//添加单元格到表格中
table.AddCell(header1);
table.AddCell(header2);
table.AddCell(header3);
table.AddCell(header4);
table.AddCell(header5);
table.AddCell(header6);
//table.AddCell(header7);
//table.AddCell(header8);
PdfPCell header9 = new PdfPCell(new Phrase("订单详情", font2));
header9.Colspan = 11;
header9.HorizontalAlignment = aligncenter;
table.AddCell(header9);
PdfPCell t1 = new PdfPCell(new Phrase("序号", font2));
PdfPCell t2 = new PdfPCell(new Phrase("订单号", font2));
Phrase t3Cell = new Phrase();
//if (this.cbIsDetail.Checked)
//{
// t3Cell = new Phrase("交易内容", font2);
//}
//else
//{
// t3Cell = new Phrase("客户名称", font2);
//}
t3Cell = new Phrase("交易内容", font2);
PdfPCell t3 = new PdfPCell(t3Cell);
PdfPCell t4 = new PdfPCell(new Phrase("产品类型", font2));
PdfPCell t5 = new PdfPCell(new Phrase("数量", font2));
PdfPCell t9 = new PdfPCell(new Phrase("款数", font2));
PdfPCell t6 = new PdfPCell(new Phrase("总金额", font2));
PdfPCell t7 = new PdfPCell(new Phrase("已付款", font2));
PdfPCell t8 = new PdfPCell(new Phrase("未付款", font2));
//设置每个单元格所占列数
t1.Colspan = 1;
t2.Colspan = 2;
t3.Colspan = 2;
t4.Colspan = 1;
t5.Colspan = 1;
t6.Colspan = 1;
t7.Colspan = 1;
t8.Colspan = 1;
t9.Colspan = 1;
//设置字体居中
t1.HorizontalAlignment = aligncenter;
t2.HorizontalAlignment = aligncenter;
t3.HorizontalAlignment = aligncenter;
t4.HorizontalAlignment = aligncenter;
t5.HorizontalAlignment = aligncenter;
t6.HorizontalAlignment = aligncenter;
t7.HorizontalAlignment = aligncenter;
t8.HorizontalAlignment = aligncenter;
t9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(t1);
table.AddCell(t2);
table.AddCell(t3);
table.AddCell(t4);
table.AddCell(t5);
table.AddCell(t9);
table.AddCell(t6);
table.AddCell(t7);
table.AddCell(t8);
}
#endregion
#region 表中数据
List<V5print.Model.Shop.Order.OrderItems> modelListByCache = this.orderItemManage.GetModelListByCache(" OrderId=" + row2.Field<long>("OrderId"));
if ((modelListByCache != null) && (modelListByCache.Count > 0))
{
int rownum = 1;
foreach (V5print.Model.Shop.Order.OrderItems info in modelListByCache)
{
//次序
//PdfPCell c1 = new PdfPCell(new Phrase(rowCount.ToString() + "-" + rownum.ToString(), font2));
PdfPCell c1 = new PdfPCell(new Phrase(rowCount.ToString(), font2));
rowCount++;
//订单号
PdfPCell c2 = new PdfPCell(new Phrase(row2.Field<string>("OrderCode"), font2));
Phrase c3Cell = new Phrase();
//交易内容
string AttributeNames = "";
if (info.TypeId == 14 || info.TypeId == 13)
{
AttributeNames = info.AttributeNames.Split(',')[0];
}
else if (info.TypeId == 12)
{
AttributeNames = "样本";
}
c3Cell = new Phrase(AttributeNames, font2);
PdfPCell c3 = new PdfPCell(c3Cell);
//产品类型
PdfPCell c4 = new PdfPCell(new Phrase(new V5print.BLL.Shop.Products.ProductType().GetModelByCache(info.TypeId).TypeName, font2));
//数量
PdfPCell c5 = new PdfPCell(new Phrase(info.Quantity.ToString() + info.Unit, font2));
//款数
string ModelCount = "1";
if (row2.Field<Int32>("ModelCount") != null)
{
ModelCount = row2.Field<Int32>("ModelCount").ToString();
}
PdfPCell c9 = new PdfPCell(new Phrase(ModelCount + "款", font2));
//总金额
PdfPCell c6 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
AllPageAmount += info.Amount;
//已付款和欠款
PdfPCell c7 = new PdfPCell();
PdfPCell c8 = new PdfPCell();
int PaymentStatus = int.Parse(row2.Field<Int16>("PaymentStatus").ToString());
if (PaymentStatus == (int)V5print.Model.Shop.Order.EnumHelper.PaymentStatus.Paid)
{
//已支付
c7 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
c8 = new PdfPCell(new Phrase("0", font2));
AllPagePaid += info.Amount;
}
else
{
c7 = new PdfPCell(new Phrase("0", font2));
c8 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
AllPageDebt += info.Amount;
}
//设置每个单元格所占列数
c1.Colspan = 1;
c2.Colspan = 2;
c3.Colspan = 2;
c4.Colspan = 1;
c5.Colspan = 1;
c6.Colspan = 1;
c7.Colspan = 1;
c8.Colspan = 1;
c9.Colspan = 1;
//居中
c1.HorizontalAlignment = aligncenter;
c2.HorizontalAlignment = aligncenter;
c3.HorizontalAlignment = aligncenter;
c4.HorizontalAlignment = aligncenter;
c5.HorizontalAlignment = aligncenter;
c6.HorizontalAlignment = aligncenter;
c7.HorizontalAlignment = aligncenter;
c8.HorizontalAlignment = aligncenter;
c9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(c1);
table.AddCell(c2);
table.AddCell(c3);
table.AddCell(c4);
table.AddCell(c5);
table.AddCell(c9);
table.AddCell(c6);
table.AddCell(c7);
table.AddCell(c8);
rownum++;
}
}
#endregion
#region 表头文字
if (countflag == 1)
{
Paragraph Title1 = new Paragraph(this.WebSiteSet.Company_Name, font);
Paragraph Title2 = new Paragraph("_______________________________", font);
string tel = "";
if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Tel400))
{
tel = this.WebSiteSet.Company_Tel400;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Telephone))
{
tel = this.WebSiteSet.Company_Telephone;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_MobilePhone))
{
tel = this.WebSiteSet.Company_MobilePhone;
}
Paragraph Title3 = new Paragraph("全国免费服务电话:" + tel, font);
Paragraph Title4 = new Paragraph("时间" + startTime + " ~ " + endTime, font);
//设置居中
Title1.Alignment = aligncenter;
Title2.Alignment = aligncenter;
Title3.Alignment = aligncenter;
Title4.Alignment = aligncenter;
//空一行
Paragraph nullp = new Paragraph(" ", font);
nullp.Leading = 10;
//将标题段加入PDF文档中
document.Add(Title1);
document.Add(Title2);
document.Add(Title3);
document.Add(Title4);
document.Add(nullp);
}
#endregion
document.Add(table);//table end
table = null;
countflag++;
}
#endregion
//汇总数据
iTextSharp.text.pdf.PdfPTable tableGather = new iTextSharp.text.pdf.PdfPTable(11);//11列
tableGather.TotalWidth = _tablewidth;
tableGather.LockedWidth = false;
PdfPCell gather1 = new PdfPCell(new Phrase("总计", font));
PdfPCell gather2 = new PdfPCell(new Phrase(AllPageAmount.ToString("0.00"), font));
PdfPCell gather3 = new PdfPCell(new Phrase(AllPagePaid.ToString("0.00"), font));
PdfPCell gather4 = new PdfPCell(new Phrase(AllPageDebt.ToString("0.00"), font));
gather1.Colspan = 8;
gather2.Colspan = 1;
gather3.Colspan = 1;
gather4.Colspan = 1;
gather1.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_RIGHT;
gather2.HorizontalAlignment = aligncenter;
gather3.HorizontalAlignment = aligncenter;
gather4.HorizontalAlignment = aligncenter;
tableGather.AddCell(gather1);
tableGather.AddCell(gather2);
tableGather.AddCell(gather3);
tableGather.AddCell(gather4);
document.Add(tableGather);
#endregion
document.NewPage();
}
if (hs.Count == 0)
{
MessageBox.ShowFailTip(this, "抱歉,暂无数据!");
return;
}
else
{
document.Close();
}
PDFToLocal(PdfPath ,docName);
}
//客户对账单
private void PrintPDFCustomerDetail()
{
this.PDFCustomer(1);
}
//客户欠款单
private void PrintPDFCustomerDebt()
{
this.PDFCustomer(2);
}
///<summary>
///业务员单据模板2(不含订单明细)
///PDFType 1:对账单 2:欠款单
///</summary>
private void PDFEmployee2_no(int PDFType)
{
#region PDF设置
string PdfPath = Server.MapPath("/Upload/Temp/");
string docType = "";
if (PDFType == 1)
{
docType = "业务员对账单二";
}
else if (PDFType == 2)
{
docType = "业务员欠款单";
}
string docName = string.Format("{0}{1:yyyyMMddHHmmssffff}", docType, DateTime.Now);
//设置中文字体
//BaseFont bfHei = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bfHei, 11);
iTextSharp.text.Font font2 = new iTextSharp.text.Font(bfHei, 10);
//设置居中
int aligncenter = iTextSharp.text.Rectangle.ALIGN_CENTER;
//设置纸张尺寸
int pagenum = int.Parse(this.ddlPaperSize.SelectedValue);
iTextSharp.text.Rectangle pagesize = PageSize.A4;
switch (pagenum)
{
case 0: pagesize = PageSize.A0; break;
case 1: pagesize = PageSize.A1; break;
case 2: pagesize = PageSize.A2; break;
case 3: pagesize = PageSize.A3; break;
case 4: pagesize = PageSize.A4; break;
case 5: pagesize = PageSize.A5; break;
}
iTextSharp.text.Document document = new iTextSharp.text.Document(pagesize);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(PdfPath + docName + ".pdf", FileMode.Create));
document.Open();
#endregion
#region 数据来源
//获取数据
StringBuilder builder = new StringBuilder();
//付款状态
if (PDFType == 2)
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" PaymentStatus = 0 ");
}
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" CreatedDate between '{0}' and '{1}' ", InjectionFilter.QuoteFilter(this.txtCreatedDateStart.Text.Trim()), InjectionFilter.QuoteFilter(this.txtCreatedDateEnd.Text.Trim()));
}
//值查看印刷订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" OrderType in ({0},{1}) ", (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Print, (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Template);
//已发货的订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" ShippingStatus>1 ");
DataSet dataSetSource = this.orderBll.GetListWithEmployee(-1, builder.ToString(), "CreatedDate desc");
DateTime orderStartTime = new DateTime();
DateTime orderEndTime = new DateTime();
int TimeCountFlag = 0;
//BuyerID去重、EmployeeID去重
HashSet<int> BuyerIDs = new HashSet<int>();
HashSet<int> EmployeeIDs = new HashSet<int>();
foreach (DataRow row0 in dataSetSource.Tables[0].Rows)
{
TimeCountFlag++;
if (TimeCountFlag == 1)
{
orderEndTime = row0.Field<DateTime>("CreatedDate");
}
if (TimeCountFlag == dataSetSource.Tables[0].Rows.Count)
{
orderStartTime = row0.Field<DateTime>("CreatedDate");
}
BuyerIDs.Add(row0.Field<int>("BuyerID"));
EmployeeIDs.Add(row0.Field<int>("UserID"));
}
string startTime = "";
string endTime = "";
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
startTime = this.txtCreatedDateEnd.Text.Trim();
endTime = this.txtCreatedDateStart.Text.Trim();
}
else
{
startTime = orderStartTime.ToString("yyyy-MM-dd hh:mm:ss");
endTime = orderEndTime.ToString("yyyy-MM-dd hh:mm:ss");
}
#endregion
HashSet<int> hs = new HashSet<int>();
//按业务员分页
hs = EmployeeIDs;
foreach (var hsNow in hs)
{
#region BuyerID
int countflag = 1;
StringBuilder sbBuyerID = new StringBuilder();
//按业务员分页
sbBuyerID.AppendFormat(" and p3.UserID={0} ", hsNow.ToString());
DataSet dataSetSource2 = this.orderBll.GetListWithEmployee(-1, builder.ToString() + sbBuyerID.ToString(), "CreatedDate desc");
#region 打印数据
int rowCount = 1;
foreach (DataRow row2 in dataSetSource2.Tables[0].Rows)
{
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(11);//11列
table.TotalWidth = _tablewidth;
table.LockedWidth = true;
if (countflag == 1)
{
//按业务员分页
PdfPCell header21 = new PdfPCell(new Phrase("业务员:" + row2.Field<String>("UserName"), font));
header21.Colspan = 11;
table.AddCell(header21);
PdfPCell header9 = new PdfPCell(new Phrase("订单详情", font2));
header9.Colspan = 11;
header9.HorizontalAlignment = aligncenter;
table.AddCell(header9);
PdfPCell t1 = new PdfPCell(new Phrase("序号", font2));
//PdfPCell t2 = new PdfPCell(new Phrase("订单号", font2));
PdfPCell t3 = new PdfPCell(new Phrase("客户名称", font2));
PdfPCell t4 = new PdfPCell(new Phrase("交易总额", font2));
PdfPCell t5 = new PdfPCell(new Phrase("订单总数", font2));
PdfPCell t6 = new PdfPCell(new Phrase("已收金额", font2));
PdfPCell t7 = new PdfPCell(new Phrase("欠款金额", font2));
PdfPCell t8 = new PdfPCell(new Phrase("预存余额", font2));
//设置每个单元格所占列数
t1.Colspan = 1;
//t2.Colspan = 2;
t3.Colspan = 5;
t4.Colspan = 1;
t5.Colspan = 1;
t6.Colspan = 1;
t7.Colspan = 1;
t8.Colspan = 1;
//设置字体居中
t1.HorizontalAlignment = aligncenter;
//t2.HorizontalAlignment = aligncenter;
t3.HorizontalAlignment = aligncenter;
t4.HorizontalAlignment = aligncenter;
t5.HorizontalAlignment = aligncenter;
t6.HorizontalAlignment = aligncenter;
t7.HorizontalAlignment = aligncenter;
t8.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(t1);
//table.AddCell(t2);
table.AddCell(t3);
table.AddCell(t4);
table.AddCell(t5);
table.AddCell(t6);
table.AddCell(t7);
table.AddCell(t8);
}
List<V5print.Model.Shop.Order.OrderItems> modelListByCache = this.orderItemManage.GetModelListByCache(" OrderId=" + row2.Field<long>("OrderId"));
if ((modelListByCache != null) && (modelListByCache.Count > 0))
{
int rownum = 1;
foreach (V5print.Model.Shop.Order.OrderItems info in modelListByCache)
{
//次序
//PdfPCell c1 = new PdfPCell(new Phrase(rowCount.ToString() + "-" + rownum.ToString(), font2));
PdfPCell c1 = new PdfPCell(new Phrase(rowCount.ToString(), font2));
rowCount++;
//订单号
//PdfPCell c2 = new PdfPCell(new Phrase(row2.Field<string>("OrderCode"), font2));
Phrase c3Cell = new Phrase();
//客户名称
V5print.Model.Members.Users c3user = userBll.GetModel(row2.Field<int>("BuyerId"));
string c3UserNickName = c3user.NickName;
c3Cell = new Phrase(c3UserNickName, font2);
PdfPCell c3 = new PdfPCell(c3Cell);
//string sql = string.Format(" BuyerID={0} and PaymentStatus=0 and PaymentGateway='credit'", c3user.UserID);
string sql = string.Format(" BuyerID={0} ", c3user.UserID);
List<V5print.Model.Shop.Order.OrderInfo> orderList = orderBll.GetModelList(sql);
//交易总额
decimal allAmount = 0;
//已收金额
decimal allPaid = 0;
if (orderList.Count > 0)
{
foreach (V5print.Model.Shop.Order.OrderInfo order in orderList)
{
allAmount += order.Amount;
//已收金额
if (order.PaymentStatus == (int)V5print.Model.Shop.Order.EnumHelper.PaymentStatus.Paid)
{
allPaid += order.Amount;
}
}
}
//欠款金额
decimal allDebt = allAmount - allPaid;
//预存余额
decimal allBalance = 0;
V5print.Model.Members.UsersExpModel userexp = userexpBll.GetUsersExpModel(c3user.UserID);
if (userexp != null)
{
allBalance = Math.Round(decimal.Parse(userexp.Balance.ToString()), 2);
}
//交易总额
PdfPCell c4 = new PdfPCell(new Phrase(allAmount.ToString("0.00"), font2));
//订单总数
PdfPCell c5 = new PdfPCell(new Phrase(orderList.Count.ToString(), font2));
//已收金额
PdfPCell c6 = new PdfPCell(new Phrase(allPaid.ToString("0.00"), font2));
//欠款金额
PdfPCell c7 = new PdfPCell(new Phrase(allDebt.ToString("0.00"), font2));
//预存余额
PdfPCell c8 = new PdfPCell(new Phrase(allBalance.ToString("0.00"), font2));
//设置每个单元格所占列数
c1.Colspan = 1;
//c2.Colspan = 2;
c3.Colspan = 5;
c4.Colspan = 1;
c5.Colspan = 1;
c6.Colspan = 1;
c7.Colspan = 1;
c8.Colspan = 1;
//居中
c1.HorizontalAlignment = aligncenter;
//c2.HorizontalAlignment = aligncenter;
c3.HorizontalAlignment = aligncenter;
c4.HorizontalAlignment = aligncenter;
c5.HorizontalAlignment = aligncenter;
c6.HorizontalAlignment = aligncenter;
c7.HorizontalAlignment = aligncenter;
c8.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(c1);
//table.AddCell(c2);
table.AddCell(c3);
table.AddCell(c4);
table.AddCell(c5);
table.AddCell(c6);
table.AddCell(c7);
table.AddCell(c8);
rownum++;
}
}
if (countflag == 1)
{
//添加表头文字this.WebSiteSet.Company_Name
//Paragraph Title1 = new Paragraph("厦门晨辉快印", font);
Paragraph Title1 = new Paragraph(this.WebSiteSet.Company_Name, font);
Paragraph Title2 = new Paragraph("_______________________________", font);
//this.WebSiteSet.Company_Tel400
//this.WebSiteSet.Company_Telephone
//this.WebSiteSet.Company_MobilePhone
string tel = "";
if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Tel400))
{
tel = this.WebSiteSet.Company_Tel400;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Telephone))
{
tel = this.WebSiteSet.Company_Telephone;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_MobilePhone))
{
tel = this.WebSiteSet.Company_MobilePhone;
}
Paragraph Title3 = new Paragraph("全国免费服务电话:" + tel, font);
Paragraph Title4 = new Paragraph("时间" + startTime + " ~ " + endTime, font);
//设置居中
Title1.Alignment = aligncenter;
Title2.Alignment = aligncenter;
Title3.Alignment = aligncenter;
Title4.Alignment = aligncenter;
//空一行
Paragraph nullp = new Paragraph(" ", font);
nullp.Leading = 10;
//将标题段加入PDF文档中
document.Add(Title1);
document.Add(Title2);
document.Add(Title3);
document.Add(Title4);
document.Add(nullp);
}
document.Add(table);//table end
table = null;
countflag++;
#endregion
}
#endregion
document.NewPage();
}
document.Close();
PDFToLocal(PdfPath, docName);
}
///<summary>
///业务员单据模板2(不含订单明细)
///PDFType 1:对账单 2:欠款单
///</summary>
private void PDFEmployee2(int PDFType)
{
#region PDF设置
string PdfPath = Server.MapPath("/Upload/Temp/");
string docType = "";
if (PDFType == 1)
{
docType = "业务员对账单二";
}
else if (PDFType == 2)
{
docType = "业务员欠款单";
}
string docName = string.Format("{0}{1:yyyyMMddHHmmssffff}", docType, DateTime.Now);
//设置中文字体
//BaseFont bfHei = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bfHei, 11);
iTextSharp.text.Font font2 = new iTextSharp.text.Font(bfHei, 10);
//设置居中
int aligncenter = iTextSharp.text.Rectangle.ALIGN_CENTER;
//设置纸张尺寸
int pagenum = int.Parse(this.ddlPaperSize.SelectedValue);
iTextSharp.text.Rectangle pagesize = PageSize.A4;
switch (pagenum)
{
case 0: pagesize = PageSize.A0; break;
case 1: pagesize = PageSize.A1; break;
case 2: pagesize = PageSize.A2; break;
case 3: pagesize = PageSize.A3; break;
case 4: pagesize = PageSize.A4; break;
case 5: pagesize = PageSize.A5; break;
}
iTextSharp.text.Document document = new iTextSharp.text.Document(pagesize);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(PdfPath + docName + ".pdf", FileMode.Create));
#endregion
#region 数据来源
//获取数据
StringBuilder builder = new StringBuilder();
//付款状态
if (PDFType == 2)
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" PaymentStatus = 0 ");
}
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" CreatedDate between '{0}' and '{1}' ", InjectionFilter.QuoteFilter(this.txtCreatedDateStart.Text.Trim()), InjectionFilter.QuoteFilter(this.txtCreatedDateEnd.Text.Trim()));
}
//值查看印刷订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" OrderType in ({0},{1}) ", (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Print, (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Template);
//已发货的订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" ShippingStatus>1 ");
DataSet dataSetSource = this.orderBll.GetListWithEmployee(-1, builder.ToString(), "CreatedDate desc");
DateTime orderStartTime = new DateTime();
DateTime orderEndTime = new DateTime();
int TimeCountFlag = 0;
//BuyerID去重、EmployeeID去重
HashSet<int> BuyerIDs = new HashSet<int>();
HashSet<int> EmployeeIDs = new HashSet<int>();
foreach (DataRow row0 in dataSetSource.Tables[0].Rows)
{
TimeCountFlag++;
if (TimeCountFlag == 1)
{
orderEndTime = row0.Field<DateTime>("CreatedDate");
}
if (TimeCountFlag == dataSetSource.Tables[0].Rows.Count)
{
orderStartTime = row0.Field<DateTime>("CreatedDate");
}
BuyerIDs.Add(row0.Field<int>("BuyerID"));
EmployeeIDs.Add(row0.Field<int>("UserID"));
}
string startTime = "";
string endTime = "";
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
startTime = this.txtCreatedDateEnd.Text.Trim();
endTime = this.txtCreatedDateStart.Text.Trim();
}
else
{
startTime = orderStartTime.ToString("yyyy-MM-dd hh:mm:ss");
endTime = orderEndTime.ToString("yyyy-MM-dd hh:mm:ss");
}
#endregion
HashSet<int> hs = new HashSet<int>();
//按业务员分页
hs = EmployeeIDs;
if (hs.Count == 0)
{
MessageBox.ShowFailTip(this, "抱歉,暂无数据!");
return;
}
else
{
document.Open();
}
foreach (var hsNow in hs)
{
#region EmployeeID
int countflag = 1;
StringBuilder sbBuyerID = new StringBuilder();
//按业务员分页
sbBuyerID.AppendFormat(" and p3.UserID={0} ", hsNow.ToString());
DataSet dataSetSource2 = this.orderBll.GetListWithEmployee(-1, builder.ToString() + sbBuyerID.ToString(), "CreatedDate desc");
//汇总数据
//交易总额
decimal AllPageAmount = 0;
//订单总数
int AllPageOrderCount = 0;
//已收金额
decimal AllPagePaid = 0;
//欠款金额
decimal AllPageDebt = 0;
//预存余额
decimal AllPageBalance = 0;
//该业务员的所有客户(去重)
HashSet<int> Buyergroup = new HashSet<int>();
foreach (DataRow row3 in dataSetSource2.Tables[0].Rows)
{
Buyergroup.Add(row3.Field<int>("BuyerID"));
}
#region 打印数据
int rowCount = 1;
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(11);//11列
table.TotalWidth = _tablewidth;
table.LockedWidth = false;
#region 表头
if (countflag == 1)
{
//按业务员分页
V5print.Model.Members.Users employNow = userBll.GetModel(hsNow);
string employeeName = "";
if (employNow != null)
{
employeeName = employNow.UserName;
}
PdfPCell header21 = new PdfPCell(new Phrase("业务员:" + employeeName, font));
header21.Colspan = 11;
table.AddCell(header21);
PdfPCell header9 = new PdfPCell(new Phrase("订单详情", font2));
header9.Colspan = 11;
header9.HorizontalAlignment = aligncenter;
table.AddCell(header9);
PdfPCell t1 = new PdfPCell(new Phrase("序号", font2));
//PdfPCell t2 = new PdfPCell(new Phrase("订单号", font2));
PdfPCell t3 = new PdfPCell(new Phrase("客户名称", font2));
PdfPCell t4 = new PdfPCell(new Phrase("交易总额", font2));
PdfPCell t5 = new PdfPCell(new Phrase("订单总数", font2));
PdfPCell t6 = new PdfPCell(new Phrase("已收金额", font2));
PdfPCell t7 = new PdfPCell(new Phrase("欠款金额", font2));
PdfPCell t8 = new PdfPCell(new Phrase("预存余额", font2));
//设置每个单元格所占列数
t1.Colspan = 1;
//t2.Colspan = 2;
t3.Colspan = 5;
t4.Colspan = 1;
t5.Colspan = 1;
t6.Colspan = 1;
t7.Colspan = 1;
t8.Colspan = 1;
//设置字体居中
t1.HorizontalAlignment = aligncenter;
//t2.HorizontalAlignment = aligncenter;
t3.HorizontalAlignment = aligncenter;
t4.HorizontalAlignment = aligncenter;
t5.HorizontalAlignment = aligncenter;
t6.HorizontalAlignment = aligncenter;
t7.HorizontalAlignment = aligncenter;
t8.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(t1);
//table.AddCell(t2);
table.AddCell(t3);
table.AddCell(t4);
table.AddCell(t5);
table.AddCell(t6);
table.AddCell(t7);
table.AddCell(t8);
}
#endregion
foreach (var BuyerIdNow in Buyergroup)
{
int rownum = 1;
PdfPCell c1 = new PdfPCell(new Phrase(rowCount.ToString(), font2));
rowCount++;
//订单号
//PdfPCell c2 = new PdfPCell(new Phrase(row2.Field<string>("OrderCode"), font2));
Phrase c3Cell = new Phrase();
//客户名称
V5print.Model.Members.Users c3user = userBll.GetModel(BuyerIdNow);
string c3UserNickName = c3user.NickName;
c3Cell = new Phrase(c3UserNickName, font2);
PdfPCell c3 = new PdfPCell(c3Cell);
//string sql = string.Format(" BuyerID={0} and PaymentStatus=0 and PaymentGateway='credit'", c3user.UserID);
string sql = string.Format(" and BuyerID={0} ", c3user.UserID);
List<V5print.Model.Shop.Order.OrderInfo> orderList = orderBll.GetModelList(builder.ToString() + sql);
//交易总额
decimal allAmount = 0;
//已收金额
decimal allPaid = 0;
if (orderList.Count > 0)
{
foreach (V5print.Model.Shop.Order.OrderInfo order in orderList)
{
allAmount += order.Amount;
//已收金额
if (order.PaymentStatus == (int)V5print.Model.Shop.Order.EnumHelper.PaymentStatus.Paid)
{
allPaid += order.Amount;
}
}
}
//欠款金额
decimal allDebt = allAmount - allPaid;
//预存余额
decimal allBalance = 0;
V5print.Model.Members.UsersExpModel userexp = userexpBll.GetUsersExpModel(c3user.UserID);
if (userexp != null)
{
allBalance = Math.Round(decimal.Parse(userexp.Balance.ToString()), 2);
}
//汇总数据
AllPageAmount += allAmount;
AllPageOrderCount += orderList.Count;
AllPagePaid += allPaid;
AllPageDebt += allDebt;
AllPageBalance += allBalance;
//交易总额
PdfPCell c4 = new PdfPCell(new Phrase(allAmount.ToString("0.00"), font2));
//订单总数
PdfPCell c5 = new PdfPCell(new Phrase(orderList.Count.ToString(), font2));
//已收金额
PdfPCell c6 = new PdfPCell(new Phrase(allPaid.ToString("0.00"), font2));
//欠款金额
PdfPCell c7 = new PdfPCell(new Phrase(allDebt.ToString("0.00"), font2));
//预存余额
PdfPCell c8 = new PdfPCell(new Phrase(allBalance.ToString("0.00"), font2));
//设置每个单元格所占列数
c1.Colspan = 1;
//c2.Colspan = 2;
c3.Colspan = 5;
c4.Colspan = 1;
c5.Colspan = 1;
c6.Colspan = 1;
c7.Colspan = 1;
c8.Colspan = 1;
//居中
c1.HorizontalAlignment = aligncenter;
//c2.HorizontalAlignment = aligncenter;
c3.HorizontalAlignment = aligncenter;
c4.HorizontalAlignment = aligncenter;
c5.HorizontalAlignment = aligncenter;
c6.HorizontalAlignment = aligncenter;
c7.HorizontalAlignment = aligncenter;
c8.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(c1);
//table.AddCell(c2);
table.AddCell(c3);
table.AddCell(c4);
table.AddCell(c5);
table.AddCell(c6);
table.AddCell(c7);
table.AddCell(c8);
rownum++;
}
#region 表头文字
if (countflag == 1)
{
Paragraph Title1 = new Paragraph(this.WebSiteSet.Company_Name, font);
Paragraph Title2 = new Paragraph("_______________________________", font);
string tel = "";
if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Tel400))
{
tel = this.WebSiteSet.Company_Tel400;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Telephone))
{
tel = this.WebSiteSet.Company_Telephone;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_MobilePhone))
{
tel = this.WebSiteSet.Company_MobilePhone;
}
Paragraph Title3 = new Paragraph("全国免费服务电话:" + tel, font);
Paragraph Title4 = new Paragraph("时间" + startTime + " ~ " + endTime, font);
//设置居中
Title1.Alignment = aligncenter;
Title2.Alignment = aligncenter;
Title3.Alignment = aligncenter;
Title4.Alignment = aligncenter;
//空一行
Paragraph nullp = new Paragraph(" ", font);
nullp.Leading = 10;
//将标题段加入PDF文档中
document.Add(Title1);
document.Add(Title2);
document.Add(Title3);
document.Add(Title4);
document.Add(nullp);
}
#endregion
document.Add(table);//table end
table = null;
countflag++;
#endregion
#endregion
//汇总数据
iTextSharp.text.pdf.PdfPTable tableGather = new iTextSharp.text.pdf.PdfPTable(11);//11列
tableGather.TotalWidth = _tablewidth;
tableGather.LockedWidth = false;
PdfPCell gather1 = new PdfPCell(new Phrase("总计", font));
PdfPCell gather2 = new PdfPCell(new Phrase(AllPageAmount.ToString("0.00"), font));
PdfPCell gather3 = new PdfPCell(new Phrase(AllPageOrderCount.ToString("0"), font));
PdfPCell gather4 = new PdfPCell(new Phrase(AllPagePaid.ToString("0.00"), font));
PdfPCell gather5 = new PdfPCell(new Phrase(AllPageDebt.ToString("0.00"), font));
PdfPCell gather6 = new PdfPCell(new Phrase(AllPageBalance.ToString("0.00"), font));
gather1.Colspan = 6;
gather2.Colspan = 1;
gather3.Colspan = 1;
gather4.Colspan = 1;
gather5.Colspan = 1;
gather6.Colspan = 1;
gather1.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_RIGHT;
gather2.HorizontalAlignment = aligncenter;
gather3.HorizontalAlignment = aligncenter;
gather4.HorizontalAlignment = aligncenter;
gather5.HorizontalAlignment = aligncenter;
gather6.HorizontalAlignment = aligncenter;
tableGather.AddCell(gather1);
tableGather.AddCell(gather2);
tableGather.AddCell(gather3);
tableGather.AddCell(gather4);
tableGather.AddCell(gather5);
tableGather.AddCell(gather6);
document.Add(tableGather);
document.NewPage();
}
if (hs.Count == 0)
{
MessageBox.ShowFailTip(this, "抱歉,暂无数据!");
return;
}
else
{
document.Close();
}
PDFToLocal(PdfPath, docName);
}
//业务员对账单二(不含订单明细)
private void PrintPDFEmployeeDetail2()
{
this.PDFEmployee2(1);
}
//业务员欠款单(不含订单明细)
//不含订单明细,含未付款,按业务员分页
private void PrintPDFEmployeeDebt()
{
this.PDFEmployee2(2);
}
//业务员对账单一
//含订单明细,含已付款、未付款、客户,按业务员分页
private void PrintPDFEmployeeDetail1()
{
#region pdf设置
string PdfPath = Server.MapPath("/Upload/Temp/");
string docName = string.Format("业务员对账单一{0:yyyyMMddHHmmssffff}", DateTime.Now);
//设置中文字体
//BaseFont bfHei = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bfHei, 11);
iTextSharp.text.Font font2 = new iTextSharp.text.Font(bfHei, 10);
//设置居中
int aligncenter = iTextSharp.text.Rectangle.ALIGN_CENTER;
//设置纸张尺寸
int pagenum = int.Parse(this.ddlPaperSize.SelectedValue);
iTextSharp.text.Rectangle pagesize = PageSize.A4;
switch (pagenum)
{
case 0: pagesize = PageSize.A0; break;
case 1: pagesize = PageSize.A1; break;
case 2: pagesize = PageSize.A2; break;
case 3: pagesize = PageSize.A3; break;
case 4: pagesize = PageSize.A4; break;
case 5: pagesize = PageSize.A5; break;
}
iTextSharp.text.Document document = new iTextSharp.text.Document(pagesize);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(PdfPath + docName + ".pdf", FileMode.Create));
#endregion
#region 数据来源
//获取数据
StringBuilder builder = new StringBuilder();
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" CreatedDate between '{0}' and '{1}' ", InjectionFilter.QuoteFilter(this.txtCreatedDateStart.Text.Trim()), InjectionFilter.QuoteFilter(this.txtCreatedDateEnd.Text.Trim()));
}
//值查看印刷订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" OrderType in ({0},{1}) ", (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Print, (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Template);
//已发货的订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" ShippingStatus>1 ");
DataSet dataSetSource = this.orderBll.GetListWithEmployee(-1, builder.ToString(), "CreatedDate desc");
DateTime orderStartTime = new DateTime();
DateTime orderEndTime = new DateTime();
int TimeCountFlag = 0;
//BuyerID去重、EmployeeID去重
HashSet<int> BuyerIDs = new HashSet<int>();
HashSet<int> EmployeeIDs = new HashSet<int>();
foreach (DataRow row0 in dataSetSource.Tables[0].Rows)
{
TimeCountFlag++;
if (TimeCountFlag == 1)
{
orderEndTime = row0.Field<DateTime>("CreatedDate");
}
if (TimeCountFlag == dataSetSource.Tables[0].Rows.Count)
{
orderStartTime = row0.Field<DateTime>("CreatedDate");
}
BuyerIDs.Add(row0.Field<int>("BuyerID"));
EmployeeIDs.Add(row0.Field<int>("UserID"));
}
string startTime = "";
string endTime = "";
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
startTime = this.txtCreatedDateEnd.Text.Trim();
endTime = this.txtCreatedDateStart.Text.Trim();
}
else
{
startTime = orderStartTime.ToString("yyyy-MM-dd hh:mm:ss");
endTime = orderEndTime.ToString("yyyy-MM-dd hh:mm:ss");
}
#endregion
//this.BindData();
//DataSet dataSetSource = this.gridView.DataSetSource;
HashSet<int> hs = new HashSet<int>();
//按业务员分页
hs = EmployeeIDs;
if (hs.Count == 0)
{
MessageBox.ShowFailTip(this, "抱歉,暂无数据!");
return;
}
else
{
document.Open();
}
foreach (var hsNow in hs)
{
#region EmployeeID
int countflag = 1;
StringBuilder sbEmployeeID = new StringBuilder();
//按业务员分页
sbEmployeeID.AppendFormat(" and p3.UserID={0} ", hsNow.ToString());
DataSet dataSetSource2 = this.orderBll.GetListWithEmployee(-1, builder.ToString() + sbEmployeeID.ToString(), "CreatedDate desc");
//汇总数据
//总金额
decimal AllPageAmount = 0;
//总已付款
decimal AllPagePaid = 0;
//总欠款
decimal AllPageDebt = 0;
HashSet<int> BuyerGroup = new HashSet<int>();
foreach (DataRow row1 in dataSetSource2.Tables[0].Rows)
{
BuyerGroup.Add(row1.Field<int>("BuyerID"));
}
foreach (var Buyer in BuyerGroup)
{
#region Buyer
StringBuilder sbBuyer = new StringBuilder();
sbBuyer.AppendFormat(" and BuyerID={0} ", Buyer.ToString());
DataSet dataSetSource3 = this.orderBll.GetListWithEmployee(-1, builder.ToString() + sbEmployeeID.ToString() + sbBuyer.ToString(), "CreatedDate desc");
#region 打印数据
int rowCount = 1;
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(11);//11列
table.TotalWidth = _tablewidth;
table.LockedWidth = false;
foreach (DataRow row2 in dataSetSource3.Tables[0].Rows)
{
#region 表头
if (countflag == 1)
{
PdfPCell header21 = new PdfPCell(new Phrase("业务员:" + row2.Field<String>("UserName"), font));
header21.Colspan = 11;
table.AddCell(header21);
PdfPCell header9 = new PdfPCell(new Phrase("订单详情", font2));
header9.Colspan = 11;
header9.HorizontalAlignment = aligncenter;
table.AddCell(header9);
PdfPCell t1 = new PdfPCell(new Phrase("客户", font2));
PdfPCell t2 = new PdfPCell(new Phrase("订单号", font2));
PdfPCell t3 = new PdfPCell(new Phrase("产品名称", font2));
PdfPCell t4 = new PdfPCell(new Phrase("产品类型", font2));
PdfPCell t5 = new PdfPCell(new Phrase("数量", font2));
PdfPCell t9 = new PdfPCell(new Phrase("款数", font2));
PdfPCell t6 = new PdfPCell(new Phrase("总金额", font2));
PdfPCell t7 = new PdfPCell(new Phrase("已付款", font2));
PdfPCell t8 = new PdfPCell(new Phrase("未付款", font2));
//设置每个单元格所占列数
t1.Colspan = 1;
t2.Colspan = 2;
t3.Colspan = 2;
t4.Colspan = 1;
t5.Colspan = 1;
t6.Colspan = 1;
t7.Colspan = 1;
t8.Colspan = 1;
t9.Colspan = 1;
//设置字体居中
t1.HorizontalAlignment = aligncenter;
t2.HorizontalAlignment = aligncenter;
t3.HorizontalAlignment = aligncenter;
t4.HorizontalAlignment = aligncenter;
t5.HorizontalAlignment = aligncenter;
t6.HorizontalAlignment = aligncenter;
t7.HorizontalAlignment = aligncenter;
t8.HorizontalAlignment = aligncenter;
t9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(t1);
table.AddCell(t2);
table.AddCell(t3);
table.AddCell(t4);
table.AddCell(t5);
table.AddCell(t9);
table.AddCell(t6);
table.AddCell(t7);
table.AddCell(t8);
}
#endregion
#region 表体数据
List<V5print.Model.Shop.Order.OrderItems> modelListByCache = this.orderItemManage.GetModelListByCache(" OrderId=" + row2.Field<long>("OrderId"));
if ((modelListByCache != null) && (modelListByCache.Count > 0))
{
int rownum = 1;
foreach (V5print.Model.Shop.Order.OrderItems info in modelListByCache)
{
if (rowCount == 1)
{
//客户名称
V5print.Model.Members.Users user = userBll.GetModel(row2.Field<int>("BuyerId"));
string UserNickName = user.NickName;
PdfPCell c1 = new PdfPCell(new Phrase(UserNickName, font2));
c1.Rowspan = dataSetSource3.Tables[0].Rows.Count;
c1.Colspan = 1;
c1.HorizontalAlignment = aligncenter;
c1.VerticalAlignment = aligncenter;
table.AddCell(c1);
rowCount++;
}
//订单号
PdfPCell c2 = new PdfPCell(new Phrase(row2.Field<string>("OrderCode"), font2));
Phrase c3Cell = new Phrase();
//交易内容
string AttributeNames = "";
if (info.TypeId == 14 || info.TypeId == 13)
{
AttributeNames = info.AttributeNames.Split(',')[0];
}
else if (info.TypeId == 12)
{
AttributeNames = "样本";
}
c3Cell = new Phrase(AttributeNames, font2);
PdfPCell c3 = new PdfPCell(c3Cell);
//产品类型
PdfPCell c4 = new PdfPCell(new Phrase(new V5print.BLL.Shop.Products.ProductType().GetModelByCache(info.TypeId).TypeName, font2));
//数量
PdfPCell c5 = new PdfPCell(new Phrase(info.Quantity.ToString() + info.Unit, font2));
//款数
string ModelCount = "1";
if (row2.Field<Int32>("ModelCount") != null)
{
ModelCount = row2.Field<Int32>("ModelCount").ToString();
}
PdfPCell c9 = new PdfPCell(new Phrase(ModelCount + "款", font2));
//总金额
PdfPCell c6 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
//已付款和欠款
PdfPCell c7 = new PdfPCell();
PdfPCell c8 = new PdfPCell();
int PaymentStatus = int.Parse(row2.Field<Int16>("PaymentStatus").ToString());
if (PaymentStatus == (int)V5print.Model.Shop.Order.EnumHelper.PaymentStatus.Paid)
{
//已支付
c7 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
c8 = new PdfPCell(new Phrase("0", font2));
AllPagePaid += info.Amount;
}
else
{
c7 = new PdfPCell(new Phrase("0", font2));
c8 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
AllPageDebt += info.Amount;
}
AllPageAmount += info.Amount;
//设置每个单元格所占列数
c2.Colspan = 2;
c3.Colspan = 2;
c4.Colspan = 1;
c5.Colspan = 1;
c6.Colspan = 1;
c7.Colspan = 1;
c8.Colspan = 1;
c9.Colspan = 1;
//居中
c2.HorizontalAlignment = aligncenter;
c3.HorizontalAlignment = aligncenter;
c4.HorizontalAlignment = aligncenter;
c5.HorizontalAlignment = aligncenter;
c6.HorizontalAlignment = aligncenter;
c7.HorizontalAlignment = aligncenter;
c8.HorizontalAlignment = aligncenter;
c9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(c2);
table.AddCell(c3);
table.AddCell(c4);
table.AddCell(c5);
table.AddCell(c9);
table.AddCell(c6);
table.AddCell(c7);
table.AddCell(c8);
rownum++;
}
}
#endregion
#region 表头文字
if (countflag == 1)
{
Paragraph Title1 = new Paragraph(this.WebSiteSet.Company_Name, font);
Paragraph Title2 = new Paragraph("_______________________________", font);
string tel = "";
if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Tel400))
{
tel = this.WebSiteSet.Company_Tel400;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Telephone))
{
tel = this.WebSiteSet.Company_Telephone;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_MobilePhone))
{
tel = this.WebSiteSet.Company_MobilePhone;
}
Paragraph Title3 = new Paragraph("全国免费服务电话:" + tel, font);
Paragraph Title4 = new Paragraph("时间" + startTime + " ~ " + endTime, font);
//设置居中
Title1.Alignment = aligncenter;
Title2.Alignment = aligncenter;
Title3.Alignment = aligncenter;
Title4.Alignment = aligncenter;
//空一行
Paragraph nullp = new Paragraph(" ", font);
nullp.Leading = 10;
//将标题段加入PDF文档中
document.Add(Title1);
document.Add(Title2);
document.Add(Title3);
document.Add(Title4);
document.Add(nullp);
}
#endregion
countflag++;
}
#endregion
#endregion
document.Add(table);//table end
table = null;
#region 打印数据废弃
//int rowCount = 1;
//foreach (DataRow row2 in dataSetSource2.Tables[0].Rows)
//{
// iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(11);//11列
// table.TotalWidth = 400f;
// table.LockedWidth = true;
// if (countflag == 1)
// {
// PdfPCell header21 = new PdfPCell(new Phrase("业务员:" + row2.Field<String>("UserName"), font));
// header21.Colspan = 11;
// table.AddCell(header21);
// PdfPCell header9 = new PdfPCell(new Phrase("订单详情", font2));
// header9.Colspan = 11;
// header9.HorizontalAlignment = aligncenter;
// table.AddCell(header9);
// PdfPCell t1 = new PdfPCell(new Phrase("客户", font2));
// PdfPCell t2 = new PdfPCell(new Phrase("订单号", font2));
// PdfPCell t3 = new PdfPCell(new Phrase("产品名称", font2));
// PdfPCell t4 = new PdfPCell(new Phrase("产品类型", font2));
// PdfPCell t5 = new PdfPCell(new Phrase("数量", font2));
// PdfPCell t6 = new PdfPCell(new Phrase("总金额", font2));
// PdfPCell t7 = new PdfPCell(new Phrase("已付款", font2));
// PdfPCell t8 = new PdfPCell(new Phrase("未付款", font2));
// //设置每个单元格所占列数
// t1.Colspan = 1;
// t2.Colspan = 2;
// t3.Colspan = 3;
// t4.Colspan = 1;
// t5.Colspan = 1;
// t6.Colspan = 1;
// t7.Colspan = 1;
// t8.Colspan = 1;
// //设置字体居中
// t1.HorizontalAlignment = aligncenter;
// t2.HorizontalAlignment = aligncenter;
// t3.HorizontalAlignment = aligncenter;
// t4.HorizontalAlignment = aligncenter;
// t5.HorizontalAlignment = aligncenter;
// t6.HorizontalAlignment = aligncenter;
// t7.HorizontalAlignment = aligncenter;
// t8.HorizontalAlignment = aligncenter;
// //添加单元格到表格中
// table.AddCell(t1);
// table.AddCell(t2);
// table.AddCell(t3);
// table.AddCell(t4);
// table.AddCell(t5);
// table.AddCell(t6);
// table.AddCell(t7);
// table.AddCell(t8);
// }
// List<V5print.Model.Shop.Order.OrderItems> modelListByCache = this.orderItemManage.GetModelListByCache(" OrderId=" + row2.Field<long>("OrderId"));
// if ((modelListByCache != null) && (modelListByCache.Count > 0))
// {
// int rownum = 1;
// foreach (V5print.Model.Shop.Order.OrderItems info in modelListByCache)
// {
// //客户名称
// V5print.Model.Members.Users user = userBll.GetModel(row2.Field<int>("BuyerId"));
// string UserNickName = user.NickName;
// PdfPCell c1 = new PdfPCell(new Phrase(UserNickName, font2));
// //List<V5print.Model.Shop.Order.OrderItems> CurUserOrders = this.orderItemManage.GetModelListByCache(" BuyerId=" + row2.Field<int>("BuyerId"));
// //c1.Rowspan = 3;
// //次序
// //PdfPCell c1 = new PdfPCell(new Phrase(rowCount.ToString() + "-" + rownum.ToString(), font2));
// //PdfPCell c1 = new PdfPCell(new Phrase(rowCount.ToString(), font2));
// rowCount++;
// //订单号
// PdfPCell c2 = new PdfPCell(new Phrase(row2.Field<string>("OrderCode"), font2));
// Phrase c3Cell = new Phrase();
// //交易内容
// string AttributeNames = "";
// if (info.TypeId == 14 || info.TypeId == 13)
// {
// AttributeNames = info.AttributeNames.Split(',')[0];
// }
// else if (info.TypeId == 12)
// {
// AttributeNames = "样本";
// }
// c3Cell = new Phrase(AttributeNames, font2);
// PdfPCell c3 = new PdfPCell(c3Cell);
// //产品类型
// PdfPCell c4 = new PdfPCell(new Phrase(new V5print.BLL.Shop.Products.ProductType().GetModelByCache(info.TypeId).TypeName, font2));
// //数量
// PdfPCell c5 = new PdfPCell(new Phrase(info.Quantity.ToString(), font2));
// //总金额
// PdfPCell c6 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
// //已付款和欠款
// PdfPCell c7 = new PdfPCell();
// PdfPCell c8 = new PdfPCell();
// int PaymentStatus = int.Parse(row2.Field<Int16>("PaymentStatus").ToString());
// if (PaymentStatus == (int)V5print.Model.Shop.Order.EnumHelper.PaymentStatus.Paid)
// {
// //已支付
// c7 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
// c8 = new PdfPCell(new Phrase("0", font2));
// }
// else
// {
// c7 = new PdfPCell(new Phrase("0", font2));
// c8 = new PdfPCell(new Phrase(info.Amount.ToString("F"), font2));
// }
// //设置每个单元格所占列数
// c1.Colspan = 1;
// c2.Colspan = 2;
// c3.Colspan = 3;
// c4.Colspan = 1;
// c5.Colspan = 1;
// c6.Colspan = 1;
// c7.Colspan = 1;
// c8.Colspan = 1;
// //居中
// c1.HorizontalAlignment = aligncenter;
// c2.HorizontalAlignment = aligncenter;
// c3.HorizontalAlignment = aligncenter;
// c4.HorizontalAlignment = aligncenter;
// c5.HorizontalAlignment = aligncenter;
// c6.HorizontalAlignment = aligncenter;
// c7.HorizontalAlignment = aligncenter;
// c8.HorizontalAlignment = aligncenter;
// //添加单元格到表格中
// table.AddCell(c1);
// table.AddCell(c2);
// table.AddCell(c3);
// table.AddCell(c4);
// table.AddCell(c5);
// table.AddCell(c6);
// table.AddCell(c7);
// table.AddCell(c8);
// rownum++;
// }
// }
// if (countflag == 1)
// {
// //添加表头文字
// Paragraph Title1 = new Paragraph("厦门晨辉快印", font);
// Paragraph Title2 = new Paragraph("_______________________________", font);
// Paragraph Title3 = new Paragraph("全国免费服务电话:40081234567", font);
// Paragraph Title4 = new Paragraph("时间2015-2016", font);
// //设置居中
// Title1.Alignment = aligncenter;
// Title2.Alignment = aligncenter;
// Title3.Alignment = aligncenter;
// Title4.Alignment = aligncenter;
// //空一行
// Paragraph nullp = new Paragraph(" ", font);
// nullp.Leading = 10;
// //将标题段加入PDF文档中
// document.Add(Title1);
// document.Add(Title2);
// document.Add(Title3);
// document.Add(Title4);
// document.Add(nullp);
// }
// document.Add(table);//table end
// table = null;
// countflag++;
#endregion
}
#endregion
//汇总数据
iTextSharp.text.pdf.PdfPTable tableGather = new iTextSharp.text.pdf.PdfPTable(11);//11列
tableGather.TotalWidth = _tablewidth;
tableGather.LockedWidth = false;
PdfPCell gather1 = new PdfPCell(new Phrase("总计", font));
PdfPCell gather2 = new PdfPCell(new Phrase(AllPageAmount.ToString("0.00"), font));
PdfPCell gather3 = new PdfPCell(new Phrase(AllPagePaid.ToString("0.00"), font));
PdfPCell gather4 = new PdfPCell(new Phrase(AllPageDebt.ToString("0.00"), font));
gather1.Colspan = 8;
gather2.Colspan = 1;
gather3.Colspan = 1;
gather4.Colspan = 1;
gather1.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_RIGHT;
gather2.HorizontalAlignment = aligncenter;
gather3.HorizontalAlignment = aligncenter;
gather4.HorizontalAlignment = aligncenter;
tableGather.AddCell(gather1);
tableGather.AddCell(gather2);
tableGather.AddCell(gather3);
tableGather.AddCell(gather4);
document.Add(tableGather);
document.NewPage();
}
if (hs.Count == 0)
{
MessageBox.ShowFailTip(this, "抱歉,暂无数据!");
return;
}
else
{
document.Close();
}
PDFToLocal(PdfPath, docName);
}
///<summary>
///老板单据模板一(含客户)
///PDFType 1:对账单 2:欠款单
///</summary>
private void PDFBoss1(int PDFType)
{
#region PDF设置
string PdfPath = Server.MapPath("/Upload/Temp/");
string docType = "";
if (PDFType == 1)
{
docType = "老板对账单一";
}
else if (PDFType == 2)
{
docType = "老板欠款单一";
}
string docName = string.Format("{0}{1:yyyyMMddHHmmssffff}", docType, DateTime.Now);
//设置中文字体
//BaseFont bfHei = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bfHei, 11);
iTextSharp.text.Font font2 = new iTextSharp.text.Font(bfHei, 10);
//设置居中
int aligncenter = iTextSharp.text.Rectangle.ALIGN_CENTER;
//设置纸张尺寸
int pagenum = int.Parse(this.ddlPaperSize.SelectedValue);
iTextSharp.text.Rectangle pagesize = PageSize.A4;
switch (pagenum)
{
case 0: pagesize = PageSize.A0; break;
case 1: pagesize = PageSize.A1; break;
case 2: pagesize = PageSize.A2; break;
case 3: pagesize = PageSize.A3; break;
case 4: pagesize = PageSize.A4; break;
case 5: pagesize = PageSize.A5; break;
}
iTextSharp.text.Document document = new iTextSharp.text.Document(pagesize);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(PdfPath + docName + ".pdf", FileMode.Create));
document.Open();
#endregion
#region 数据来源
//获取数据
StringBuilder builder = new StringBuilder();
//付款状态
if (PDFType == 2)
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" PaymentStatus = 0 ");
}
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" CreatedDate between '{0}' and '{1}' ", InjectionFilter.QuoteFilter(this.txtCreatedDateStart.Text.Trim()), InjectionFilter.QuoteFilter(this.txtCreatedDateEnd.Text.Trim()));
}
//值查看印刷订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" OrderType in ({0},{1}) ", (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Print, (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Template);
//已发货的订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" ShippingStatus>1 ");
DataSet dataSetSource = this.orderBll.GetListWithEmployee(-1, builder.ToString(), "CreatedDate desc");
DateTime orderStartTime = new DateTime();
DateTime orderEndTime = new DateTime();
int TimeCountFlag = 0;
//BuyerID去重、EmployeeID去重
HashSet<int> BuyerIDs = new HashSet<int>();
HashSet<int> EmployeeIDs = new HashSet<int>();
foreach (DataRow row0 in dataSetSource.Tables[0].Rows)
{
TimeCountFlag++;
if (TimeCountFlag == 1)
{
orderEndTime = row0.Field<DateTime>("CreatedDate");
}
if (TimeCountFlag == dataSetSource.Tables[0].Rows.Count)
{
orderStartTime = row0.Field<DateTime>("CreatedDate");
}
BuyerIDs.Add(row0.Field<int>("BuyerID"));
EmployeeIDs.Add(row0.Field<int>("UserID"));
}
string startTime = "";
string endTime = "";
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
startTime = this.txtCreatedDateEnd.Text.Trim();
endTime = this.txtCreatedDateStart.Text.Trim();
}
else
{
startTime = orderStartTime.ToString("yyyy-MM-dd hh:mm:ss");
endTime = orderEndTime.ToString("yyyy-MM-dd hh:mm:ss");
}
#endregion
//this.BindData();
//DataSet dataSetSource = this.gridView.DataSetSource;
HashSet<int> hs = new HashSet<int>();
//按业务员不分页
hs = EmployeeIDs;
int countflag = 1;
#region 表头文字
if (countflag == 1)
{
Paragraph Title1 = new Paragraph(this.WebSiteSet.Company_Name, font);
Paragraph Title2 = new Paragraph("_______________________________", font);
string tel = "";
if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Tel400))
{
tel = this.WebSiteSet.Company_Tel400;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Telephone))
{
tel = this.WebSiteSet.Company_Telephone;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_MobilePhone))
{
tel = this.WebSiteSet.Company_MobilePhone;
}
Paragraph Title3 = new Paragraph("全国免费服务电话:" + tel, font);
Paragraph Title4 = new Paragraph("时间" + startTime + " ~ " + endTime, font);
//设置居中
Title1.Alignment = aligncenter;
Title2.Alignment = aligncenter;
Title3.Alignment = aligncenter;
Title4.Alignment = aligncenter;
//空一行
Paragraph nullp = new Paragraph(" ", font);
nullp.Leading = 10;
//将标题段加入PDF文档中
document.Add(Title1);
document.Add(Title2);
document.Add(Title3);
document.Add(Title4);
document.Add(nullp);
}
#endregion
//汇总数据
//交易总额
decimal AllPageAmount = 0;
//订单总数
int AllPageOrderCount = 0;
//已收金额
decimal AllPagePaid = 0;
//欠款金额
decimal AllPageDebt = 0;
//成本金额
decimal AllPageCost = 0;
//利润金额
decimal AllPageProfit = 0;
foreach (var hsNow in hs)
{
#region EmployeeID
StringBuilder sbEmployeeID = new StringBuilder();
//按业务员分页
sbEmployeeID.AppendFormat(" and p3.UserID={0} ", hsNow.ToString());
DataSet dataSetSource2 = this.orderBll.GetListWithEmployee(-1, builder.ToString() + sbEmployeeID.ToString(), "CreatedDate desc");
//该业务员的所有客户(去重)
HashSet<int> Buyergroup = new HashSet<int>();
foreach (DataRow row3 in dataSetSource2.Tables[0].Rows)
{
Buyergroup.Add(row3.Field<int>("BuyerID"));
}
#region 打印数据
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(11);//11列
table.TotalWidth = _tablewidth;
table.LockedWidth = false;
int EndFlag = 0;
foreach (DataRow row2 in dataSetSource2.Tables[0].Rows)
{
#region 表头
if (countflag == 1)
{
PdfPCell t1 = new PdfPCell(new Phrase("序号", font2));
PdfPCell t2 = new PdfPCell(new Phrase("业务员", font2));
PdfPCell t3 = new PdfPCell(new Phrase("客户名称", font2));
PdfPCell t4 = new PdfPCell(new Phrase("交易总额", font2));
PdfPCell t5 = new PdfPCell(new Phrase("订单总数", font2));
PdfPCell t6 = new PdfPCell(new Phrase("已收金额", font2));
PdfPCell t7 = new PdfPCell(new Phrase("欠款金额", font2));
PdfPCell t8 = new PdfPCell(new Phrase("成本金额", font2));
PdfPCell t9 = new PdfPCell(new Phrase("利润金额", font2));
//设置每个单元格所占列数
t1.Colspan = 1;
t2.Colspan = 2;
t3.Colspan = 2;
t4.Colspan = 1;
t5.Colspan = 1;
t6.Colspan = 1;
t7.Colspan = 1;
t8.Colspan = 1;
t9.Colspan = 1;
//设置字体居中
t1.HorizontalAlignment = aligncenter;
t2.HorizontalAlignment = aligncenter;
t3.HorizontalAlignment = aligncenter;
t4.HorizontalAlignment = aligncenter;
t5.HorizontalAlignment = aligncenter;
t6.HorizontalAlignment = aligncenter;
t7.HorizontalAlignment = aligncenter;
t8.HorizontalAlignment = aligncenter;
t9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(t1);
table.AddCell(t2);
table.AddCell(t3);
table.AddCell(t4);
table.AddCell(t5);
table.AddCell(t6);
table.AddCell(t7);
table.AddCell(t8);
table.AddCell(t9);
}
#endregion
#region 表体数据
#region 不用管
List<V5print.Model.Shop.Order.OrderItems> modelListByCache = this.orderItemManage.GetModelListByCache(" OrderId=" + row2.Field<long>("OrderId"));
if ((modelListByCache != null) && (modelListByCache.Count > 0))
{
foreach (V5print.Model.Shop.Order.OrderItems info in modelListByCache)
{
#endregion
int BuyerCount = 1;
foreach (var BuyerIdNow in Buyergroup)
{
EndFlag++;
//编号
PdfPCell c1 = new PdfPCell(new Phrase(countflag.ToString(), font2));
c1.Colspan = 1;
c1.HorizontalAlignment = aligncenter;
table.AddCell(c1);
if (BuyerCount == 1)
{
//业务员
PdfPCell c2 = new PdfPCell(new Phrase(row2.Field<String>("UserName"), font2));
c2.Rowspan = Buyergroup.Count;
c2.Colspan = 2;
c2.HorizontalAlignment = aligncenter;
c2.VerticalAlignment = aligncenter;
table.AddCell(c2);
}
BuyerCount++;
V5print.Model.Members.Users user = userBll.GetModel(BuyerIdNow);
//客户名称
string UserNickName = user.NickName;
PdfPCell c3 = new PdfPCell(new Phrase(UserNickName, font2));
string sql = string.Format(" and BuyerID={0} ", BuyerIdNow);
List<V5print.Model.Shop.Order.OrderInfo> orderList = orderBll.GetModelList(builder.ToString() + sql);
//交易总额
decimal allAmount = 0;
//已收金额
decimal allPaid = 0;
//总成本
decimal allCost = 0;
//总利润
decimal allProfit = 0;
if (orderList.Count > 0)
{
foreach (V5print.Model.Shop.Order.OrderInfo order in orderList)
{
allAmount += order.Amount;
//已收金额
if (order.PaymentStatus == (int)V5print.Model.Shop.Order.EnumHelper.PaymentStatus.Paid)
{
allPaid += order.Amount;
}
allCost += (order.OrderCostPrice == null ? 0 : order.OrderCostPrice.Value);
}
}
allProfit = allAmount - allCost;
//欠款金额
decimal allDebt = allAmount - allPaid;
//预存余额
decimal allBalance = 0;
V5print.Model.Members.UsersExpModel userexp = userexpBll.GetUsersExpModel(BuyerIdNow);
if (userexp != null)
{
allBalance = Math.Round(decimal.Parse(userexp.Balance.ToString()), 2);
}
//交易总额
PdfPCell c4 = new PdfPCell(new Phrase(allAmount.ToString("0.00"), font2));
//订单总数
PdfPCell c5 = new PdfPCell(new Phrase(orderList.Count.ToString(), font2));
//已收金额
PdfPCell c6 = new PdfPCell(new Phrase(allPaid.ToString("0.00"), font2));
//欠款金额
PdfPCell c7 = new PdfPCell(new Phrase(allDebt.ToString("0.00"), font2));
//成本
PdfPCell c8 = new PdfPCell(new Phrase(allCost.ToString("0.00"), font2));
//利润金额
PdfPCell c9 = new PdfPCell(new Phrase(allProfit.ToString("0.00"), font2));
//汇总数据
AllPageAmount += allAmount;
AllPageOrderCount += orderList.Count;
AllPagePaid += allPaid;
AllPageDebt += allDebt;
AllPageCost += allCost;
AllPageProfit += allProfit;
//设置每个单元格所占列数
//c1.Colspan = 1;
//c2.Colspan = 2;
c3.Colspan = 2;
c4.Colspan = 1;
c5.Colspan = 1;
c6.Colspan = 1;
c7.Colspan = 1;
c8.Colspan = 1;
c9.Colspan = 1;
//居中
//c1.HorizontalAlignment = aligncenter;
//c2.HorizontalAlignment = aligncenter;
c3.HorizontalAlignment = aligncenter;
c4.HorizontalAlignment = aligncenter;
c5.HorizontalAlignment = aligncenter;
c6.HorizontalAlignment = aligncenter;
c7.HorizontalAlignment = aligncenter;
c8.HorizontalAlignment = aligncenter;
c9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
//table.AddCell(c1);
//table.AddCell(c2);
table.AddCell(c3);
table.AddCell(c4);
table.AddCell(c5);
table.AddCell(c6);
table.AddCell(c7);
table.AddCell(c8);
table.AddCell(c9);
countflag++;
}
#region 还是不用管
}
}
#endregion
if (EndFlag == Buyergroup.Count)
{
break;
}
#endregion
}
#endregion
document.Add(table);//table end
table = null;
#endregion
//document.NewPage();
}
//汇总数据
iTextSharp.text.pdf.PdfPTable tableGather = new iTextSharp.text.pdf.PdfPTable(11);//11列
tableGather.TotalWidth = _tablewidth;
tableGather.LockedWidth = false;
PdfPCell gather1 = new PdfPCell(new Phrase("总计", font));
PdfPCell gather2 = new PdfPCell(new Phrase(AllPageAmount.ToString("0.00"), font));
PdfPCell gather3 = new PdfPCell(new Phrase(AllPageOrderCount.ToString("0"), font));
PdfPCell gather4 = new PdfPCell(new Phrase(AllPagePaid.ToString("0.00"), font));
PdfPCell gather5 = new PdfPCell(new Phrase(AllPageDebt.ToString("0.00"), font));
PdfPCell gather6 = new PdfPCell(new Phrase(AllPageCost.ToString("0.00"), font));
PdfPCell gather7 = new PdfPCell(new Phrase(AllPageProfit.ToString("0.00"), font));
gather1.Colspan = 5;
gather2.Colspan = 1;
gather3.Colspan = 1;
gather4.Colspan = 1;
gather5.Colspan = 1;
gather6.Colspan = 1;
gather7.Colspan = 1;
gather1.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_RIGHT;
gather2.HorizontalAlignment = aligncenter;
gather3.HorizontalAlignment = aligncenter;
gather4.HorizontalAlignment = aligncenter;
gather5.HorizontalAlignment = aligncenter;
gather6.HorizontalAlignment = aligncenter;
gather7.HorizontalAlignment = aligncenter;
tableGather.AddCell(gather1);
tableGather.AddCell(gather2);
tableGather.AddCell(gather3);
tableGather.AddCell(gather4);
tableGather.AddCell(gather5);
tableGather.AddCell(gather6);
tableGather.AddCell(gather7);
document.Add(tableGather);
document.Close();
PDFToLocal(PdfPath, docName);
}
//老板对账单一(含客户)
private void PrintPDFBossDetail1()
{
this.PDFBoss1(1);
}
//老板欠款单一
private void PrintPDFBossDebt1()
{
this.PDFBoss1(2);
}
///<summary>
///老板单据模板二(含客户)
///PDFType 1:对账单 2:欠款单
///</summary>
private void PDFBoss2(int PDFType)
{
#region PDF设置
string PdfPath = Server.MapPath("/Upload/Temp/");
string docType = "";
if (PDFType == 1)
{
docType = "老板对账单二";
}
else if (PDFType == 2)
{
docType = "老板欠款单二";
}
string docName = string.Format("{0}{1:yyyyMMddHHmmssffff}", docType, DateTime.Now);
//设置中文字体
//BaseFont bfHei = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font font = new iTextSharp.text.Font(bfHei, 11);
iTextSharp.text.Font font2 = new iTextSharp.text.Font(bfHei, 10);
//设置居中
int aligncenter = iTextSharp.text.Rectangle.ALIGN_CENTER;
//设置纸张尺寸
int pagenum = int.Parse(this.ddlPaperSize.SelectedValue);
iTextSharp.text.Rectangle pagesize = PageSize.A4;
switch (pagenum)
{
case 0: pagesize = PageSize.A0; break;
case 1: pagesize = PageSize.A1; break;
case 2: pagesize = PageSize.A2; break;
case 3: pagesize = PageSize.A3; break;
case 4: pagesize = PageSize.A4; break;
case 5: pagesize = PageSize.A5; break;
}
iTextSharp.text.Document document = new iTextSharp.text.Document(pagesize);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(PdfPath + docName + ".pdf", FileMode.Create));
document.Open();
#endregion
#region 数据来源
//获取数据
StringBuilder builder = new StringBuilder();
//付款状态
if (PDFType == 2)
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" PaymentStatus = 0 ");
}
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" CreatedDate between '{0}' and '{1}' ", InjectionFilter.QuoteFilter(this.txtCreatedDateStart.Text.Trim()), InjectionFilter.QuoteFilter(this.txtCreatedDateEnd.Text.Trim()));
}
//值查看印刷订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.AppendFormat(" OrderType in ({0},{1}) ", (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Print, (int)V5print.Model.Shop.Order.EnumHelper.OrderItemType.Template);
//已发货的订单
if (builder.Length > 1)
{
builder.Append(" and ");
}
builder.Append(" ShippingStatus>1 ");
DataSet dataSetSource = this.orderBll.GetListWithEmployee(-1, builder.ToString(), "CreatedDate desc");
DateTime orderStartTime = new DateTime();
DateTime orderEndTime = new DateTime();
int TimeCountFlag = 0;
//BuyerID去重、EmployeeID去重
HashSet<int> BuyerIDs = new HashSet<int>();
HashSet<int> EmployeeIDs = new HashSet<int>();
foreach (DataRow row0 in dataSetSource.Tables[0].Rows)
{
TimeCountFlag++;
if (TimeCountFlag == 1)
{
orderEndTime = row0.Field<DateTime>("CreatedDate");
}
if (TimeCountFlag == dataSetSource.Tables[0].Rows.Count)
{
orderStartTime = row0.Field<DateTime>("CreatedDate");
}
BuyerIDs.Add(row0.Field<int>("BuyerID"));
EmployeeIDs.Add(row0.Field<int>("UserID"));
}
string startTime = "";
string endTime = "";
if (PageValidate.IsDateTime(this.txtCreatedDateEnd.Text.Trim()) && PageValidate.IsDateTime(this.txtCreatedDateStart.Text.Trim()))
{
startTime = this.txtCreatedDateEnd.Text.Trim();
endTime = this.txtCreatedDateStart.Text.Trim();
}
else
{
startTime = orderStartTime.ToString("yyyy-MM-dd hh:mm:ss");
endTime = orderEndTime.ToString("yyyy-MM-dd hh:mm:ss");
}
#endregion
//this.BindData();
//DataSet dataSetSource = this.gridView.DataSetSource;
HashSet<int> hs = new HashSet<int>();
//按业务员不分页
hs = EmployeeIDs;
int countflag = 1;
#region 表头文字
if (countflag == 1)
{
Paragraph Title1 = new Paragraph(this.WebSiteSet.Company_Name, font);
Paragraph Title2 = new Paragraph("_______________________________", font);
string tel = "";
if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Tel400))
{
tel = this.WebSiteSet.Company_Tel400;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_Telephone))
{
tel = this.WebSiteSet.Company_Telephone;
}
else if (!string.IsNullOrWhiteSpace(this.WebSiteSet.Company_MobilePhone))
{
tel = this.WebSiteSet.Company_MobilePhone;
}
Paragraph Title3 = new Paragraph("全国免费服务电话:" + tel, font);
Paragraph Title4 = new Paragraph("时间" + startTime + " ~ " + endTime, font);
//设置居中
Title1.Alignment = aligncenter;
Title2.Alignment = aligncenter;
Title3.Alignment = aligncenter;
Title4.Alignment = aligncenter;
//空一行
Paragraph nullp = new Paragraph(" ", font);
nullp.Leading = 10;
//将标题段加入PDF文档中
document.Add(Title1);
document.Add(Title2);
document.Add(Title3);
document.Add(Title4);
document.Add(nullp);
}
#endregion
//汇总数据
//客户数
int AllPageBuyerCount = 0;
//交易总额
decimal AllPageAmount = 0;
//订单总数
int AllPageOrderCount = 0;
//已收金额
decimal AllPagePaid = 0;
//欠款金额
decimal AllPageDebt = 0;
//成本金额
decimal AllPageCost = 0;
//利润金额
decimal AllPageProfit = 0;
foreach (var hsNow in hs)
{
#region EmployeeID
StringBuilder sbEmployeeID = new StringBuilder();
//按业务员分页
sbEmployeeID.AppendFormat(" and p3.UserID={0} ", hsNow.ToString());
DataSet dataSetSource2 = this.orderBll.GetListWithEmployee(-1, builder.ToString() + sbEmployeeID.ToString(), "CreatedDate desc");
//该业务员的所有客户(去重)
HashSet<int> Buyergroup = new HashSet<int>();
foreach (DataRow row3 in dataSetSource2.Tables[0].Rows)
{
Buyergroup.Add(row3.Field<int>("BuyerID"));
}
#region 打印数据
iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(11);//11列
table.TotalWidth = _tablewidth;
table.LockedWidth = false;
int EndFlag = 0;
foreach (DataRow row2 in dataSetSource2.Tables[0].Rows)
{
#region 表头
if (countflag == 1)
{
PdfPCell t1 = new PdfPCell(new Phrase("序号", font2));
PdfPCell t2 = new PdfPCell(new Phrase("业务员", font2));
PdfPCell t3 = new PdfPCell(new Phrase("客户数", font2));
PdfPCell t4 = new PdfPCell(new Phrase("交易总额", font2));
PdfPCell t5 = new PdfPCell(new Phrase("订单总数", font2));
PdfPCell t6 = new PdfPCell(new Phrase("已收金额", font2));
PdfPCell t7 = new PdfPCell(new Phrase("欠款金额", font2));
PdfPCell t8 = new PdfPCell(new Phrase("成本金额", font2));
PdfPCell t9 = new PdfPCell(new Phrase("利润金额", font2));
//设置每个单元格所占列数
t1.Colspan = 1;
t2.Colspan = 2;
t3.Colspan = 2;
t4.Colspan = 1;
t5.Colspan = 1;
t6.Colspan = 1;
t7.Colspan = 1;
t8.Colspan = 1;
t9.Colspan = 1;
//设置字体居中
t1.HorizontalAlignment = aligncenter;
t2.HorizontalAlignment = aligncenter;
t3.HorizontalAlignment = aligncenter;
t4.HorizontalAlignment = aligncenter;
t5.HorizontalAlignment = aligncenter;
t6.HorizontalAlignment = aligncenter;
t7.HorizontalAlignment = aligncenter;
t8.HorizontalAlignment = aligncenter;
t9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(t1);
table.AddCell(t2);
table.AddCell(t3);
table.AddCell(t4);
table.AddCell(t5);
table.AddCell(t6);
table.AddCell(t7);
table.AddCell(t8);
table.AddCell(t9);
}
#endregion
#region 表体数据
//编号
PdfPCell c1 = new PdfPCell(new Phrase(countflag.ToString(), font2));
//业务员
PdfPCell c2 = new PdfPCell(new Phrase(row2.Field<String>("UserName"), font2));
//客户数
PdfPCell c3 = new PdfPCell(new Phrase(Buyergroup.Count.ToString(), font2));
//交易总额
decimal EmployallAmount = 0;
//已收金额
decimal EmployallPaid = 0;
//总成本
decimal EmployallCost = 0;
//总利润
decimal EmployallProfit = 0;
int EmployallorderCount = 0;
#region 不用管
List<V5print.Model.Shop.Order.OrderItems> modelListByCache = this.orderItemManage.GetModelListByCache(" OrderId=" + row2.Field<long>("OrderId"));
if ((modelListByCache != null) && (modelListByCache.Count > 0))
{
foreach (V5print.Model.Shop.Order.OrderItems info in modelListByCache)
{
#endregion
#region 统计每个业务员下的用户总数的相关数据
int BuyerCount = 1;
foreach (var BuyerIdNow in Buyergroup)
{
EndFlag++;
BuyerCount++;
string sql = string.Format(" and BuyerID={0} ", BuyerIdNow);
List<V5print.Model.Shop.Order.OrderInfo> orderList = orderBll.GetModelList(builder.ToString() + sql);
//交易总额
decimal allAmount = 0;
//已收金额
decimal allPaid = 0;
//总成本
decimal allCost = 0;
//总利润
decimal allProfit = 0;
if (orderList.Count > 0)
{
foreach (V5print.Model.Shop.Order.OrderInfo order in orderList)
{
allAmount += order.Amount;
//已收金额
if (order.PaymentStatus == (int)V5print.Model.Shop.Order.EnumHelper.PaymentStatus.Paid)
{
allPaid += order.Amount;
}
allCost += (order.OrderCostPrice == null ? 0 : order.OrderCostPrice.Value);
}
}
allProfit = allAmount - allCost;
//欠款金额
decimal allDebt = allAmount - allPaid;
//订单总数
EmployallorderCount += orderList.Count;
//交易总额
EmployallAmount += allAmount;
//已收金额
EmployallPaid += allPaid;
//总成本
EmployallCost += allCost;
//总利润
EmployallProfit += allProfit;
countflag++;
}
#endregion
#region 还是不用管
}
}
#endregion
//欠款金额
decimal EmployallDebt = EmployallAmount - EmployallPaid;
//交易总额
PdfPCell c4 = new PdfPCell(new Phrase(EmployallAmount.ToString("0.00"), font2));
//订单总数
PdfPCell c5 = new PdfPCell(new Phrase(EmployallorderCount.ToString(), font2));
//已收金额
PdfPCell c6 = new PdfPCell(new Phrase(EmployallPaid.ToString("0.00"), font2));
//欠款金额
PdfPCell c7 = new PdfPCell(new Phrase(EmployallDebt.ToString("0.00"), font2));
//成本
PdfPCell c8 = new PdfPCell(new Phrase(EmployallCost.ToString("0.00"), font2));
//利润金额
PdfPCell c9 = new PdfPCell(new Phrase(EmployallProfit.ToString("0.00"), font2));
//汇总数据
AllPageBuyerCount += Buyergroup.Count;
AllPageAmount += EmployallAmount;
AllPageOrderCount += EmployallorderCount;
AllPagePaid += EmployallPaid;
AllPageDebt += EmployallDebt;
AllPageCost += EmployallCost;
AllPageProfit += EmployallProfit;
//设置每个单元格所占列数
c1.Colspan = 1;
c2.Colspan = 2;
c3.Colspan = 2;
c4.Colspan = 1;
c5.Colspan = 1;
c6.Colspan = 1;
c7.Colspan = 1;
c8.Colspan = 1;
c9.Colspan = 1;
//居中
c1.HorizontalAlignment = aligncenter;
c2.HorizontalAlignment = aligncenter;
c3.HorizontalAlignment = aligncenter;
c4.HorizontalAlignment = aligncenter;
c5.HorizontalAlignment = aligncenter;
c6.HorizontalAlignment = aligncenter;
c7.HorizontalAlignment = aligncenter;
c8.HorizontalAlignment = aligncenter;
c9.HorizontalAlignment = aligncenter;
//添加单元格到表格中
table.AddCell(c1);
table.AddCell(c2);
table.AddCell(c3);
table.AddCell(c4);
table.AddCell(c5);
table.AddCell(c6);
table.AddCell(c7);
table.AddCell(c8);
table.AddCell(c9);
if (EndFlag == Buyergroup.Count)
{
break;
}
#endregion
}
#endregion
document.Add(table);//table end
table = null;
#endregion
//document.NewPage();
}
//汇总数据
iTextSharp.text.pdf.PdfPTable tableGather = new iTextSharp.text.pdf.PdfPTable(11);//11列
tableGather.TotalWidth = _tablewidth;
tableGather.LockedWidth = false;
PdfPCell gather1 = new PdfPCell(new Phrase("总计", font));
PdfPCell gather1_2 = new PdfPCell(new Phrase(AllPageBuyerCount.ToString("0"), font));
PdfPCell gather2 = new PdfPCell(new Phrase(AllPageAmount.ToString("0.00"), font));
PdfPCell gather3 = new PdfPCell(new Phrase(AllPageOrderCount.ToString("0"), font));
PdfPCell gather4 = new PdfPCell(new Phrase(AllPagePaid.ToString("0.00"), font));
PdfPCell gather5 = new PdfPCell(new Phrase(AllPageDebt.ToString("0.00"), font));
PdfPCell gather6 = new PdfPCell(new Phrase(AllPageCost.ToString("0.00"), font));
PdfPCell gather7 = new PdfPCell(new Phrase(AllPageProfit.ToString("0.00"), font));
gather1.Colspan = 3;
gather1_2.Colspan = 2;
gather2.Colspan = 1;
gather3.Colspan = 1;
gather4.Colspan = 1;
gather5.Colspan = 1;
gather6.Colspan = 1;
gather7.Colspan = 1;
gather1.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_RIGHT;
gather1_2.HorizontalAlignment = aligncenter;
gather2.HorizontalAlignment = aligncenter;
gather3.HorizontalAlignment = aligncenter;
gather4.HorizontalAlignment = aligncenter;
gather5.HorizontalAlignment = aligncenter;
gather6.HorizontalAlignment = aligncenter;
gather7.HorizontalAlignment = aligncenter;
tableGather.AddCell(gather1);
tableGather.AddCell(gather1_2);
tableGather.AddCell(gather2);
tableGather.AddCell(gather3);
tableGather.AddCell(gather4);
tableGather.AddCell(gather5);
tableGather.AddCell(gather6);
tableGather.AddCell(gather7);
document.Add(tableGather);
document.Close();
PDFToLocal(PdfPath, docName);
}
//老板对账单二(含客户)
private void PrintPDFBossDetail2()
{
this.PDFBoss2(1);
}
//老板欠款单二(含客户)
private void PrintPDFBossDebt2()
{
this.PDFBoss2(2);
}