.NET经验心得探讨社区  
请在这里用键盘敲打出属于你的地位!

public class ExPDF
{
           
    static string sqlStr = "select Member_Value from MDB_Archive_Member where Member_ID in (000000,000000) order by Member_ID ";
    int dtc;
    Document document = new Document();
    static BaseFont bfHei = BaseFont.CreateFont(@ConfigurationManager.AppSettings["windir"].Replace("system32","fonts")+@"\SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    static Font font = new Font(bfHei, 12);
    DataSet ds;
    DataTable dt;
    public ExPDF()
    {
    }
    public void MakePDF(string entityID,string fn)
    {
        ds = SqlHelper.ExecuteDataset(SqlHelper.ToEposConnString, CommandType.Text, sqlStr);
        SqlParameter spa = new SqlParameter("@VarEntityid", entityID);
        DataSet dst = SqlHelper.ExecuteDataset(SqlHelper.ToEposConnString, CommandType.StoredProcedure, "DSC_SP_ExportAuthedShop", spa);

        PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + "/" + System.Configuration.ConfigurationSettings.AppSettings["UploadFilePath"].ToString() + "/" + fn + ".pdf", FileMode.Create));
        document.Open();

        for (int ii = 0; ii < dst.Tables.Count; ii++)
        {
            dt = dst.Tables[ii];
            dtc = dt.Rows.Count;
            if (dtc > 0)
            {
                int P = int.Parse(System.Math.Floor((double)(dtc / 10)).ToString());
                int Pc = dtc % 10;
                if (P == 0)
                {
                    for (int i = 0; i < 1; i++)
                    {
                        PdfRot(i * 10, (i + 1) * 10);
                    }
                }
                if (Pc == 0 && P > 0)
                {
                    for (int i = 0; i < P; i++)
                    {
                        PdfRot(i * 10, (i + 1) * 10);
                        if (i + 1 < P)
                        {
                            document.NewPage();
                        }
                    }
                }
                if (Pc > 0 && P > 0)
                {
                    for (int i = 0; i < P + 1; i++)
                    {
                        PdfRot(i * 10, (i + 1) * 10);
                        if (i + 1 < P + 1)
                        {
                            document.NewPage();
                        }
                    }
                }
            }
            if (ii + 1 < dst.Tables.Count)
            {
                document.NewPage();
            }
        }
        document.Close();
    }
    public void PdfRot(int start,int end)
    {

        Image ln = Image.GetInstance(HttpContext.Current.Request.PhysicalApplicationPath + "/EXCEL/ln.jpg");
        ln.Alignment = Image.RIGHT_ALIGN;
        ln.ScalePercent(25);
        document.Add(ln);

        string text = @"“***”****合同(编号:" + (dt.Rows.Count>0?dt.Rows[0]["DEALER_NO"].ToString():"") + @")附件

    
                        “***”********表格
   
";
        string text_b = "  本店铺名单表格作为甲乙双方《“***”******》的附件,明确乙方开设的店铺的名称、地址,与《“***”******》具有相同的法律效力,有效期自" + dt.Rows[0][dt.Columns.Count - 1].ToString().Substring(0, 4) + "年" + dt.Rows[0][dt.Columns.Count - 1].ToString().Substring(4, 2) + "月" + dt.Rows[0][dt.Columns.Count - 1].ToString().Substring(6, 2) + "日" + "至" + DateTime.Today.AddYears(1).ToString("yyyy") + "年" + int.Parse(ds.Tables[0].Rows[1]["Member_Value"].ToString()).ToString("00月00日") + "止。(在《“***”******》的有效期限内)。";
        document.Add(new Paragraph(text, font));
        document.Add(new Paragraph(text_b, font));

        Table aTable = new Table(7, 2);
        aTable.Cellpadding = 2;
        aTable.WidthPercentage = 100;
        aTable.AddCell(new Paragraph("**ID", font));
        Cell c = new Cell(new Paragraph("**名称", font));
        c.Colspan = 3;
        aTable.AddCell(c);

        c = new Cell(new Paragraph("**地址", font));
        c.Colspan = 3;
        aTable.AddCell(c);

        for (int i = start; i < end;i++ )
        {
            if (i < dtc)
            {
                aTable.AddCell(new Paragraph(dt.Rows[i][0].ToString(), font));
                c = new Cell(new Paragraph(dt.Rows[i][2].ToString(), font));
                c.Colspan = 3;
                aTable.AddCell(c);
                c = new Cell(new Paragraph(dt.Rows[i][3].ToString(), font));
                c.Colspan = 3;
                aTable.AddCell(c);
                //aTable.AddCell(new Paragraph(dt.Rows[i][2].ToString(), font));
                //aTable.AddCell(new Paragraph(dt.Rows[i][3].ToString(), font));
            }
        }
        document.Add(aTable);

        string vtext = @"  我****乙方在以上****“***”产品。

 

 


                                                    ***有限公司

                                                            " + dt.Rows[0][dt.Columns.Count - 1].ToString().Substring(0, 4) + "年" + dt.Rows[0][dt.Columns.Count - 1].ToString().Substring(4, 2) + "月" + dt.Rows[0][dt.Columns.Count - 1].ToString().Substring(6, 2) + "日";
        document.Add(new Paragraph(vtext, font));
    }
}

posted on 2006-08-01 09:56  苦涩的咖啡  阅读(514)  评论(1编辑  收藏  举报