Invoice using iTextSharp(转载),Support .NET1.1 & .NET2.0

简介:
None.gif using  System;
None.gif
using  System.Web;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.IO;
None.gif
using  System.Data;
None.gif
using  iTextSharp.text;
None.gif
using  iTextSharp.text.pdf;
None.gif
None.gif
namespace  snabbasvar.util
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for Invoices.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class MyInvoices
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public MyInvoices()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// TODO: Add constructor logic here
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
public static void CreateInvoice(
InBlock.gif            
int projectid)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataView project
=BusProjects.ListById(projectid);
InBlock.gif            
InBlock.gif            
int regiontype=Convert.ToInt32(project[0]["regiontype"]);
InBlock.gif            
int minage=Convert.ToInt32(project[0]["minage"]);
InBlock.gif            
int maxage=Convert.ToInt32(project[0]["maxage"]);
InBlock.gif            
int nrquestions=Convert.ToInt32(project[0]["maxquota"]);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
string[] regionSpecifics=Convert.ToString(project[0]["regionspecifics"]).Split(new char[]dot.gif{';'});
InBlock.gif            
string invoicedate=BusProjects.GetInvoicedate(
InBlock.gif                Convert.ToString(project[
0]["startdate"]),
InBlock.gif                Convert.ToBoolean(project[
0]["fastdelivery"]));
InBlock.gif            
string projectname=Convert.ToString(project[0]["BusprojectName"]);
InBlock.gif            
int userid=Convert.ToInt32(project[0]["user_id"]);
InBlock.gif
InBlock.gif            
bool usingage=Convert.ToBoolean(minage>0 || maxage>0);
InBlock.gif            
bool usingsex=Convert.ToBoolean(Convert.ToInt32(project[0]["sex"])!=-1);
InBlock.gif            
bool isSnabbLeverans=Convert.ToBoolean(project[0]["fastdelivery"]);
InBlock.gif            
InBlock.gif            DataView user
=Accounts.GetUserById(userid);
InBlock.gif            
string companyname=Convert.ToString(user[0]["companyname"]);
InBlock.gif            
string username=Convert.ToString(user[0]["ContactName"]);
InBlock.gif            
string companyaddress=Convert.ToString(user[0]["address"]);
InBlock.gif            
string postalcode=Convert.ToString(user[0]["postalcode"]);
InBlock.gif            
string postalort=Convert.ToString(user[0]["city"]);
InBlock.gif            
string country=Convert.ToString(user[0]["countryname"]);
InBlock.gif            
bool appliedKampanj=Globals.IsKampan && Accounts.User_IsNewOfSnabbasvar(userid,projectid);
InBlock.gif
InBlock.gif            Document document
=new Document(PageSize.A4,36,72,108,180);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string filename="../invoices/"+Convert.ToString(projectid*100)+Convert.ToString(projectid)+".pdf";
InBlock.gif                
string file=HttpContext.Current.Server.MapPath(filename);
InBlock.gif                PdfWriter writer
=PdfWriter.GetInstance(document,new FileStream(file,FileMode.Create));
InBlock.gif                document.Open();
InBlock.gif                
InBlock.gif                AddLogo(document);
InBlock.gif                
InBlock.gif                AddRightHeader(document,writer);
InBlock.gif                
InBlock.gif                AddCustomerAddress(document,
InBlock.gif                    writer,
InBlock.gif                    companyname,
InBlock.gif                    username,
InBlock.gif                    companyaddress,
InBlock.gif                    postalcode,
InBlock.gif                    postalort,
InBlock.gif                    country);
InBlock.gif                
InBlock.gif                AddReference(document,
InBlock.gif                    writer,
InBlock.gif                    userid,
InBlock.gif                    projectid,
InBlock.gif                    username,
InBlock.gif                    invoicedate);
InBlock.gif
InBlock.gif                AddSpecification(document,
InBlock.gif                    writer,
InBlock.gif                    projectname,
InBlock.gif                    nrquestions,
InBlock.gif                    regiontype,
InBlock.gif                    regionSpecifics,
InBlock.gif                    usingage,
InBlock.gif                    usingsex,
InBlock.gif                    isSnabbLeverans,
InBlock.gif                    appliedKampanj);
InBlock.gif
InBlock.gif                AddFooter(document,writer);
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception ee)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                HttpContext.Current.Response.Write(ee.StackTrace);
ExpandedSubBlockEnd.gif            }

InBlock.gif            document.Close();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static void AddLogo(Document document)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string
InBlock.gif                _logo
=HttpContext.Current.Server.MapPath("../invoices/"+Globals.CI.Name+"_snabbasvar_logga.gif");
InBlock.gif            iTextSharp.text.Image
InBlock.gif                logo
=iTextSharp.text.Image.GetInstance(_logo);
InBlock.gif            logo.SetAbsolutePosition(
360,750);
InBlock.gif            document.Add(logo);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static void AddReference(
InBlock.gif            Document document,
InBlock.gif            PdfWriter writer,
InBlock.gif            
int userid,
InBlock.gif            
int projectid,
InBlock.gif            
string username,
InBlock.gif            
string invoicedate)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
InBlock.gif            
InBlock.gif            iTextSharp.text.pdf.PdfPTable re
=new iTextSharp.text.pdf.PdfPTable(1);
ExpandedSubBlockStart.gifContractedSubBlock.gif            re.SetTotalWidth(
new float[]dot.gif{530});
InBlock.gif            re.LockedWidth
=true;
InBlock.gif            re.HorizontalAlignment
=0;
InBlock.gif            re.DefaultCell.BorderColor
=iTextSharp.text.Color.BLACK;
InBlock.gif
InBlock.gif            
InBlock.gif            iTextSharp.text.pdf.PdfPTable reference
=new iTextSharp.text.pdf.PdfPTable(4);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
float[] columnDefinitionSize=dot.gif{130F,120F,120F,160F};
InBlock.gif            reference.SetTotalWidth(columnDefinitionSize);
InBlock.gif            reference.LockedWidth
=true;
InBlock.gif            reference.HorizontalAlignment
=0;
InBlock.gif            reference.DefaultCell.BorderColor
=iTextSharp.text.Color.WHITE;
InBlock.gif
InBlock.gif            reference.AddCell(
new Phrase(Globals.RM.GetString("Faktura_InvoiceNumber",Globals.CI),BoldFont));
InBlock.gif            reference.AddCell(
new Phrase(Convert.ToString(projectid),NormalFont));
InBlock.gif            reference.AddCell(
new Phrase(Globals.RM.GetString("Faktura_PrintDate",Globals.CI),BoldFont));
InBlock.gif            reference.AddCell(
new Phrase(DateTime.Now.ToShortDateString(),NormalFont));
InBlock.gif
InBlock.gif
InBlock.gif            reference.AddCell(
new Phrase(Globals.RM.GetString("Faktura_CustomerNo",Globals.CI),BoldFont));
InBlock.gif            reference.AddCell(
new Phrase(Convert.ToString(userid),NormalFont));
InBlock.gif            reference.AddCell(
new Phrase(Globals.RM.GetString("Faktura_PayDueDate",Globals.CI),BoldFont));
InBlock.gif            reference.AddCell(
new Phrase(Convert.ToDateTime(invoicedate).AddDays(-1).ToShortDateString(),NormalFont));
InBlock.gif
InBlock.gif            reference.AddCell(
new Phrase(Globals.RM.GetString("Faktura_YourRef",Globals.CI),BoldFont));
InBlock.gif            reference.AddCell(
new Phrase(username,NormalFont));
InBlock.gif            reference.AddCell(
new Phrase(Globals.RM.GetString("Faktura_OurRef",Globals.CI),BoldFont));
InBlock.gif            reference.AddCell(
new Phrase("Bo Mattsson,"+Globals.RM.GetString("Invoice_SupportMail",Globals.CI),NormalFont));
InBlock.gif
InBlock.gif            re.AddCell(reference);
InBlock.gif            re.WriteSelectedRows(
0,-1,0,-1,30,620,writer.DirectContent);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static iTextSharp.text.Image Line
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string _image=HttpContext.Current.Server.MapPath("../invoices/line.gif");
InBlock.gif                iTextSharp.text.Image image
=iTextSharp.text.Image.GetInstance(_image);
InBlock.gif                
return image;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static  void AddFooter(Document document,PdfWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            iTextSharp.text.pdf.PdfPTable footer
=new iTextSharp.text.pdf.PdfPTable(1);
ExpandedSubBlockStart.gifContractedSubBlock.gif            footer.SetTotalWidth(
new float[]dot.gif{500});
InBlock.gif            footer.HorizontalAlignment
=0;
InBlock.gif            footer.LockedWidth
=true;
InBlock.gif            footer.DefaultCell.BorderColor
=iTextSharp.text.Color.WHITE;
InBlock.gif            footer.AddCell(Line);
InBlock.gif            footer.WriteSelectedRows(
0,-1,0,-1,30,241,writer.DirectContent);
InBlock.gif            
//float[] columnDefinitionSize={160F,160F,100F,120F};
InBlock.gif
            footer=new iTextSharp.text.pdf.PdfPTable(1);
ExpandedSubBlockStart.gifContractedSubBlock.gif            footer.SetTotalWidth(
new float[]dot.gif{230F});
InBlock.gif            footer.HorizontalAlignment
=0;
InBlock.gif            footer.LockedWidth
=true;
InBlock.gif            footer.DefaultCell.BorderColor
=iTextSharp.text.Color.WHITE;
InBlock.gif
InBlock.gif            footer.AddCell(
new Phrase(Globals.RM.GetString("Faktura_PleaseToPay",Globals.CI),NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("Cint AB",NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("Bank: Östgotabanken",NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("Bankkonto: 1334 1408 940",NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("Bankgiro: 5528-6520",NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("SWIFT: DABASESX",NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("IBAN: SE23 1200 0000 0133 4140 8940",NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("Momsregistreringsnummer:SE556559876901",NormalFont));
InBlock.gif            footer.AddCell(
new Phrase("Företaget innnehar F-skattesedel",NormalFont));
InBlock.gif            footer.WriteSelectedRows(
0,-1,0,-1,30,240,writer.DirectContent);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private static void AddProductItemRow(
InBlock.gif            iTextSharp.text.pdf.PdfPTable table,
InBlock.gif            
string description,
InBlock.gif            
int nrquestions,
InBlock.gif            
int aprice,
InBlock.gif            
int amount)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            table.AddCell(
new Phrase(description,NormalFont));
InBlock.gif            table.AddCell(
new Phrase(Convert.ToString(nrquestions),NormalFont));
InBlock.gif            table.AddCell(
new Phrase(Convert.ToString(aprice),NormalFont));
InBlock.gif            table.AddCell(
new Phrase(Convert.ToString(amount),NormalFont));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static void AddSpecification(
InBlock.gif            Document document,
InBlock.gif            PdfWriter writer,
InBlock.gif            
string projectname,
InBlock.gif            
int nrquestions,
InBlock.gif            
int regiontype,
InBlock.gif            
string[] regionSpecifics,
InBlock.gif            
bool usingage,
InBlock.gif            
bool usingsex,
InBlock.gif            
bool isSnabbLeverans,
InBlock.gif            
bool appliedKampanj)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            iTextSharp.text.pdf.PdfPTable specification
=new iTextSharp.text.pdf.PdfPTable(4);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
float[] columnDefinitionSize=dot.gif{200F,80F,120F,100F};
InBlock.gif            specification.SetTotalWidth(columnDefinitionSize);
InBlock.gif            specification.HorizontalAlignment
=0;
InBlock.gif            specification.LockedWidth
=true;
InBlock.gif            specification.DefaultCell.BorderColor
=iTextSharp.text.Color.WHITE;
InBlock.gif
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Description",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Unit",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_UnitPrice",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Amount",Globals.CI),BoldFont));
InBlock.gif
InBlock.gif            specification.DefaultCell.Colspan
=4;
InBlock.gif            specification.AddCell(Line);
InBlock.gif
InBlock.gif            specification.DefaultCell.Colspan
=1;
InBlock.gif
InBlock.gif            
int aprice=0;
InBlock.gif            
double totalprice=0;
InBlock.gif
InBlock.gif            
string par=string.Empty;
InBlock.gif            
string countryId=string.Empty;
InBlock.gif            
string type=string.Empty;
InBlock.gif
InBlock.gif            
switch(regiontype)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
case (int)RegionType.AllTheCountry:
InBlock.gif                
case (int)RegionType.CountryPart:
InBlock.gif                
case (int)RegionType.Province:
InBlock.gif                    aprice
=Prices.GetBaseprice(nrquestions,regiontype);
InBlock.gif                    AddProductItemRow(specification,
InBlock.gif                        appliedKampanj
?projectname+"(*)":projectname,
InBlock.gif                        nrquestions,
InBlock.gif                        aprice,
InBlock.gif                        (appliedKampanj
?(nrquestions-1):nrquestions)*aprice);
InBlock.gif                    totalprice
=(appliedKampanj?nrquestions-1:nrquestions)*aprice;
InBlock.gif                    
break;
InBlock.gif                
case (int)RegionType.Capitals:
InBlock.gif                
case (int)RegionType.Metros:
InBlock.gif                
case (int)RegionType.Oresundsregion:
InBlock.gif                    
for(int i=0;i<regionSpecifics.Length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        aprice
=Prices.GetBaseprice(nrquestions,regiontype);
InBlock.gif                        par
=regionSpecifics[i];
InBlock.gif                        countryId
=par.Substring(0,par.IndexOf(","));
InBlock.gif                        AddProductItemRow(specification,
InBlock.gif                            appliedKampanj
?projectname+" ("+Regions.GetCountrynames(countryId,",")+" *)":projectname+" ("+Regions.GetCountrynames(countryId,",")+")",
InBlock.gif                            nrquestions,
InBlock.gif                            aprice,
InBlock.gif                            (appliedKampanj
?nrquestions-1:nrquestions)*aprice);
InBlock.gif                        totalprice
+=(appliedKampanj?nrquestions-1:nrquestions)*aprice;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
break;
InBlock.gif                
case (int)RegionType.SpecificRegions:
InBlock.gif                    
for(int j=0;j<regionSpecifics.Length;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        par
=regionSpecifics[j];
InBlock.gif                        countryId
=par.Substring(0,par.IndexOf(","));
InBlock.gif                        
InBlock.gif                        type
=par.Substring(par.IndexOf(",")+1);
InBlock.gif                        aprice
=Prices.GetBaseprice(nrquestions,Convert.ToInt32(type));
InBlock.gif                        AddProductItemRow(specification,
InBlock.gif                            appliedKampanj
?projectname+" ("+Regions.GetCountrynames(countryId,",")+" *)":projectname+" ("+Regions.GetCountrynames(countryId,",")+" *)",
InBlock.gif                            nrquestions,
InBlock.gif                            aprice,
InBlock.gif                            aprice
*(appliedKampanj?nrquestions-1:nrquestions));
InBlock.gif                        totalprice
+=aprice*(appliedKampanj?nrquestions-1:nrquestions);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
double _totalprice=totalprice;
InBlock.gif            
if(usingsex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _totalprice
=_totalprice+totalprice/2;
InBlock.gif                specification.AddCell(
new Phrase(Globals.RM.GetString("Invoice_SexExtra",Globals.CI),NormalFont));
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
new Phrase(Convert.ToString(totalprice/2)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI)+"(50%)",NormalFont));
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(usingage)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _totalprice
=_totalprice+totalprice/2;
InBlock.gif                specification.AddCell(
new Phrase(Globals.RM.GetString("Invoice_AgeExtra",Globals.CI),NormalFont));
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
new Phrase(Convert.ToString(totalprice/2)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI)+"(50%)",NormalFont));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(isSnabbLeverans)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _totalprice
=_totalprice+totalprice;
InBlock.gif                specification.AddCell(
new Phrase(Globals.RM.GetString("Invoice_FastDelivery",Globals.CI),NormalFont));
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
new Phrase(Convert.ToString(totalprice)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI)+"(100%)",NormalFont));
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Sum",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Convert.ToString(_totalprice)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI),NormalFont));
InBlock.gif
InBlock.gif            
InBlock.gif            specification.DefaultCell.Colspan
=4;
InBlock.gif            
//specification.DefaultCell.FixedHeight=10;
InBlock.gif
            specification.AddCell("");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
new Phrase("* Vid kampanj är en fråga gratis.",NormalFont));
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(Line);
InBlock.gif
InBlock.gif            
InBlock.gif            specification.DefaultCell.Colspan
=1;
InBlock.gif            
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Tax",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Convert.ToString(_totalprice/4)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI),NormalFont));
InBlock.gif
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_TotalToPay",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Convert.ToString(_totalprice*1.25)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI),NormalFont));
InBlock.gif
InBlock.gif            
InBlock.gif            specification.WriteSelectedRows(
0,-1,0,-1,30,500,writer.DirectContent);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static void AddSpecification(
InBlock.gif            Document document,
InBlock.gif            PdfWriter writer,
InBlock.gif            
string projectname,
InBlock.gif            
int nrquestions,
InBlock.gif            
int regiontype,
InBlock.gif            
string[] regionSpecifics,
InBlock.gif            
bool usingage,
InBlock.gif            
bool usingsex,
InBlock.gif            
bool isSnabbLeverans)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            iTextSharp.text.pdf.PdfPTable specification
=new iTextSharp.text.pdf.PdfPTable(4);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
float[] columnDefinitionSize=dot.gif{200F,80F,120F,100F};
InBlock.gif            specification.SetTotalWidth(columnDefinitionSize);
InBlock.gif            specification.HorizontalAlignment
=0;
InBlock.gif            specification.LockedWidth
=true;
InBlock.gif            specification.DefaultCell.BorderColor
=iTextSharp.text.Color.WHITE;
InBlock.gif
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Description",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Unit",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_UnitPrice",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Amount",Globals.CI),BoldFont));
InBlock.gif
InBlock.gif            specification.DefaultCell.Colspan
=4;
InBlock.gif            specification.AddCell(Line);
InBlock.gif
InBlock.gif            specification.DefaultCell.Colspan
=1;
InBlock.gif
InBlock.gif            
int aprice=0;
InBlock.gif            
double totalprice=0;
InBlock.gif
InBlock.gif            
string par=string.Empty;
InBlock.gif            
string countryId=string.Empty;
InBlock.gif            
string type=string.Empty;
InBlock.gif
InBlock.gif            
switch(regiontype)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
case (int)RegionType.AllTheCountry:
InBlock.gif                
case (int)RegionType.CountryPart:
InBlock.gif                
case (int)RegionType.Province:
InBlock.gif                    aprice
=Prices.GetBaseprice(nrquestions,regiontype);
InBlock.gif                    AddProductItemRow(specification,
InBlock.gif                        projectname,
InBlock.gif                        nrquestions,
InBlock.gif                        aprice,
InBlock.gif                        nrquestions
*aprice);
InBlock.gif                    totalprice
=nrquestions*aprice;
InBlock.gif                    
break;
InBlock.gif                
case (int)RegionType.Capitals:
InBlock.gif                
case (int)RegionType.Metros:
InBlock.gif                
case (int)RegionType.Oresundsregion:
InBlock.gif                    
for(int i=0;i<regionSpecifics.Length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        aprice
=Prices.GetBaseprice(nrquestions,regiontype);
InBlock.gif                        par
=regionSpecifics[i];
InBlock.gif                        countryId
=par.Substring(0,par.IndexOf(","));
InBlock.gif                        AddProductItemRow(specification,
InBlock.gif                            projectname
+" ("+Regions.GetCountrynames(countryId,"")+")",
InBlock.gif                            nrquestions,
InBlock.gif                            aprice,
InBlock.gif                            nrquestions
*aprice);
InBlock.gif                        totalprice
+=nrquestions*aprice;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
break;
InBlock.gif                
case (int)RegionType.SpecificRegions:
InBlock.gif                    
for(int j=0;j<regionSpecifics.Length;j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        par
=regionSpecifics[j];
InBlock.gif                        countryId
=par.Substring(0,par.IndexOf(","));
InBlock.gif                        
InBlock.gif                        type
=par.Substring(par.IndexOf(",")+1);
InBlock.gif                        aprice
=Prices.GetBaseprice(nrquestions,Convert.ToInt32(type));
InBlock.gif                        AddProductItemRow(specification,
InBlock.gif                            projectname
+" ("+Regions.GetCountrynames(countryId,"")+")",
InBlock.gif                            nrquestions,
InBlock.gif                            aprice,
InBlock.gif                            aprice
*nrquestions);
InBlock.gif                        totalprice
+=aprice*nrquestions;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
double _totalprice=totalprice;
InBlock.gif            
if(usingsex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _totalprice
=_totalprice+totalprice/2;
InBlock.gif                specification.AddCell(
new Phrase(Globals.RM.GetString("Invoice_SexExtra",Globals.CI),NormalFont));
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
new Phrase(Convert.ToString(totalprice/2)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI)+"(50%)",NormalFont));
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(usingage)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _totalprice
=_totalprice+totalprice/2;
InBlock.gif                specification.AddCell(
new Phrase(Globals.RM.GetString("Invoice_AgeExtra",Globals.CI),NormalFont));
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
new Phrase(Convert.ToString(totalprice/2)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI)+"(50%)",NormalFont));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(isSnabbLeverans)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _totalprice
=_totalprice+totalprice;
InBlock.gif                specification.AddCell(
new Phrase(Globals.RM.GetString("Invoice_FastDelivery",Globals.CI),NormalFont));
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
"");
InBlock.gif                specification.AddCell(
new Phrase(Convert.ToString(totalprice)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI)+"(100%)",NormalFont));
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Sum",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Convert.ToString(_totalprice)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI),NormalFont));
InBlock.gif
InBlock.gif            
InBlock.gif            specification.DefaultCell.Colspan
=4;
InBlock.gif            
//specification.DefaultCell.FixedHeight=10;
InBlock.gif
            specification.AddCell("");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(Line);
InBlock.gif
InBlock.gif            
InBlock.gif            specification.DefaultCell.Colspan
=1;
InBlock.gif            
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_Tax",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Convert.ToString(_totalprice/4)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI),NormalFont));
InBlock.gif
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
"");
InBlock.gif            specification.AddCell(
new Phrase(Globals.RM.GetString("Faktura_TotalToPay",Globals.CI),BoldFont));
InBlock.gif            specification.AddCell(
new Phrase(Convert.ToString(_totalprice*1.25)+" "+Globals.RM.GetString("Invoice_Currency",Globals.CI),NormalFont));
InBlock.gif            specification.WriteSelectedRows(
0,-1,0,-1,30,500,writer.DirectContent);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static void AddCustomerAddress(Document document,PdfWriter writer,
InBlock.gif            
string companyname,string username,string companyaddress,string postalcode,string postalort,string country)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            iTextSharp.text.pdf.PdfPTable address
=new iTextSharp.text.pdf.PdfPTable(1);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
float[] columnDefinitionSize=dot.gif{260F};
InBlock.gif            address.SetTotalWidth(columnDefinitionSize);
InBlock.gif            address.HorizontalAlignment
=0;
InBlock.gif            address.DefaultCell.BorderColor
=iTextSharp.text.Color.WHITE;
InBlock.gif            address.LockedWidth
=true;
InBlock.gif            address.AddCell(
new Phrase(companyname,NormalFont));
InBlock.gif            address.AddCell(
new Phrase("Att: "+username,NormalFont));
InBlock.gif            address.AddCell(
new Phrase(companyaddress,NormalFont));
InBlock.gif            address.AddCell(
new Phrase(postalcode+" "+postalort,NormalFont));
InBlock.gif            address.AddCell(
new Phrase(country,NormalFont));
InBlock.gif            address.AddCell(
"");
InBlock.gif            address.AddCell(
"");
InBlock.gif            address.AddCell(
new Phrase(DateTime.Now.ToShortDateString(),NormalFont));
InBlock.gif            address.WriteSelectedRows(
0,-1,0,-1,30,735,writer.DirectContent);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static void AddRightHeader(Document
InBlock.gif            document,PdfWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            iTextSharp.text.pdf.PdfPTable header
=new
InBlock.gif                iTextSharp.text.pdf.PdfPTable(
1);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
float[] columnDefinitionSize=dot.gif{200F};
InBlock.gif            
//float[] columnDefinitionSize = { 120F, 20F,120F };
InBlock.gif            
//float width=document.PageSize.Width;
InBlock.gif            
//float height=document.PageSize.Height;
InBlock.gif            
//header.HorizontalAlignment=0;
InBlock.gif
            header.DefaultCell.BorderColor=iTextSharp.text.Color.WHITE;
InBlock.gif            header.DefaultCell.HorizontalAlignment
=2;
InBlock.gif            header.SetTotalWidth(columnDefinitionSize);
InBlock.gif            header.LockedWidth
=true;
InBlock.gif            header.AddCell(
new Phrase("Cint AB",NormalFont));
InBlock.gif            header.AddCell(
new Phrase("Barnhusgatan 16",NormalFont));
InBlock.gif            header.AddCell(
new Phrase("SE 11123 STOCKHOLM",NormalFont));
InBlock.gif            header.AddCell(
new Phrase("SWEDEN",NormalFont));
InBlock.gif            header.AddCell(
"");
InBlock.gif            header.AddCell(
new Phrase("Tel: +46-8-545-282 60",NormalFont));
InBlock.gif            header.AddCell(
new Phrase("Fax: +46-8-545 282 70",NormalFont));
InBlock.gif            header.AddCell(
new Phrase(Globals.RM.GetString("Invoice_SupportMail",Globals.CI),NormalFont));
InBlock.gif            header.AddCell(
new Phrase(Globals.RM.GetString("Invoice_Snabbasvar",Globals.CI),NormalFont));
InBlock.gif            header.WriteSelectedRows(
0,-1,0,-1,360,750,writer.DirectContent);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static Font NormalFont
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return new Font(Font.TIMES_ROMAN,10);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
private static Font BoldFont
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
getdot.gif{return new Font(Font.TIMES_ROMAN,10,Font.BOLD);}
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
None.gif

copy from:http://www.cnblogs.com/hardrock/archive/2006/02/09/327886.html

分类: C#,iTextSharp(iText#),8.技术转载区

相关文章
|
Web App开发 前端开发 .NET
ASP.Net MVC——使用 ITextSharp 完美解决HTML转PDF(中文也可以)
前言: 最近在做老师交代的一个在线写实验报告的小项目中,有这么个需求:把学生提交的实验报告(HTML形式)直接转成PDF,方便下载和打印。 以前都是直接用rdlc报表实现的,可这次牵扯到图片,并且更为重要的一点是 PDF的格式得跟学生提交的HMTL页面一样。
2931 0