Esempio n. 1
0
        private void DrawLogImage()
        {
            // define local image resources
            // resolution 96 pixels per inch, image quality 100%
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution   = 96.0;
            ImageControl.ImageQuality = 100;

            CreateLogoFile();

            PdfImage Image1 = new PdfImage(Document, "temps/" + pk.Logo.Filename, ImageControl);

            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the picture
            Contents.Translate(0, 10);

            // adjust image size an preserve aspect ratio
            PdfRectangle NewSize = Image1.ImageSizePosition(3, 1.1, ContentAlignment.MiddleCenter);

            // clipping path
            Contents.DrawOval(NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height, PaintOp.Fill);

            // draw image
            Contents.DrawImage(Image1, NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Esempio n. 2
0
        ////////////////////////////////////////////////////////////////////
        // Draw image and clip it
        ////////////////////////////////////////////////////////////////////

        private void DrawImage()
        {
            // define local image resources
            // resolution 96 pixels per inch, image quality 50%
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution   = 96.0;
            ImageControl.ImageQuality = 50;
//		ImageControl.SaveAs = SaveImageAs.GrayImage;
//		ImageControl.ReverseBW = true;
            PdfImage Image1 = new PdfImage(Document, "TestImage.jpg", ImageControl);

            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the picture
            Contents.Translate(2.6, 5.0);

            // adjust image size an preserve aspect ratio
            PdfRectangle NewSize = Image1.ImageSizePosition(1.75, 1.5, ContentAlignment.MiddleCenter);

            // clipping path
            Contents.DrawOval(NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height, PaintOp.ClipPathEor);

            // draw image
            Contents.DrawImage(Image1, NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Esempio n. 3
0
        ////////////////////////////////////////////////////////////////////
        // Draw image and clip it
        ////////////////////////////////////////////////////////////////////

        private void DrawImage(float originx, float originy)
        {
            // define local image resources
            // resolution 96 pixels per inch, image quality 50%
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution   = 300;
            ImageControl.ImageQuality = 80;
            ;
//		ImageControl.SaveAs = SaveImageAs.GrayImage;
//		ImageControl.ReverseBW = true;
            PdfImage Image1 = new PdfImage(Document, @"C:\Users\Sriram\Downloads\10-05-2017_17-59-05_Report\20170510063212x3.jpg", ImageControl);

            //TestImage.jpg
            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the picture
            //Contents.Translate(2.6, 5.0);
            Contents.Translate(originx, originy);

            // adjust image size an preserve aspect ratio
            PdfRectangle NewSize = Image1.ImageSizePosition(300, 200, ContentAlignment.MiddleCenter);

            // clipping path
            //Contents.DrawOval(NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height, PaintOp.ClipPathEor);

            // draw image
            Contents.DrawImage(Image1, NewSize.Left, NewSize.Bottom, NewSize.Width, NewSize.Height);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Draw image and clip it
        ////////////////////////////////////////////////////////////////////

        private static void DrawTitle()
        {
            // define local image resources as 200ppi and 100% quality
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution   = 200;
            ImageControl.ImageQuality = 100;
            // Get image from embedded local resource
            Image    BocTitle   = Properties.Resources.BocTitleBitmap;
            PdfImage titleImage = new PdfImage(document, BocTitle, ImageControl);

            // save graphics state
            Contents.SaveGraphicsState();

            // set coordinate
            Contents.Translate(1.3, 26.8);

            // set image size
            PdfRectangle size = titleImage.ImageSizePosition(18.39, 1.85, ContentAlignment.MiddleCenter);

            // clipping path
            Contents.DrawRectangle(size.Left, size.Bottom, size.Width, size.Height, PaintOp.ClipPathEor);

            // draw image
            Contents.DrawImage(titleImage, size.Left, size.Bottom, size.Width, size.Height);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Esempio n. 5
0
        ////////////////////////////////////////////////////////////////////
        // Create print example
        ////////////////////////////////////////////////////////////////////

        public void Test
        (
            Boolean Debug,
            String FileName
        )
        {
            // Step 1: Create empty document
            // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches
            // Return value: PdfDocument main class
            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);

            // Debug property
            // By default it is set to false. Use it for debugging only.
            // If this flag is set, PDF objects will not be compressed, font and images will be replaced
            // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader.
            Document.Debug = Debug;

            // create default font for printing
            DefaultFont = new Font("Arial", 10.0F, FontStyle.Regular);

            // start page number
            PageNo = 1;

            // create PrintPdfDocument
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution = 300.0;
            ImageControl.SaveAs     = SaveImageAs.BWImage;
            PdfPrintDocument Print = new PdfPrintDocument(Document, ImageControl);

            // the method that will print one page at a time to PrintDocument
            Print.PrintPage += PrintPage;

            // set margins
            Print.SetMargins(1.0, 1.0, 1.0, 1.0);

            // crop the page image result to reduce PDF file size
            Print.PageCropRect = new RectangleF(0.95F, 0.95F, 6.6F, 9.1F);

            // initiate the printing process (calling the PrintPage method)
            // after the document is printed, add each page an an image to PDF file.
            Print.AddPagesToPdfDocument();

            // dispose of the PrintDocument object
            Print.Dispose();

            // create the PDF file
            Document.CreateFile();

            // start default PDF reader and display the file
            Process Proc = new Process();

            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Esempio n. 6
0
        private void DrawStrip()
        {
            // define local image resources
            // resolution 96 pixels per inch, image quality 50%
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.Resolution   = 96.0;
            ImageControl.ImageQuality = 100;
            //		ImageControl.SaveAs = SaveImageAs.GrayImage;
            //		ImageControl.ReverseBW = true;
            CreateStripFile();
            PdfImage Image1 = new PdfImage(Document, "temps/strip.png", ImageControl);

            // save graphics state
            Contents.SaveGraphicsState();
            Contents.DrawImage(Image1, 0, 7.8, 8.5, 2.3);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Esempio n. 7
0
        ////////////////////////////////////////////////////////////////////
        // Write object to PDF file
        ////////////////////////////////////////////////////////////////////

        internal void ConstructorHelper
        (
            string DataString,
            string[] SegDataString,
            ErrorCorrection ErrorCorrection,
            int QuietZone = 4
        )
        {
            // create QR Code object
            var Encoder = new QREncoder();

            if (DataString != null)
            {
                Encoder.EncodeQRCode(DataString, ErrorCorrection, QuietZone);
            }
            else
            {
                Encoder.EncodeQRCode(SegDataString, ErrorCorrection, QuietZone);
            }

            // output matrix
            // NOTE: Black=true, White=flase
            BWImage = Encoder.OutputMatrix;

            // image width and height in pixels
            MatrixDimension = Encoder.MatrixDimension;
            WidthPix        = MatrixDimension + 2 * QuietZone;
            HeightPix       = WidthPix;

            // image control for QR code
            ImageControl = new PdfImageControl
            {
                ReverseBW = true,
                SaveAs    = SaveImageAs.BWImage
            };

            // write stream object
            WriteObjectToPdfFile();
        }
Esempio n. 8
0
        ////////////////////////////////////////////////////////////////////
        // Draw chart
        ////////////////////////////////////////////////////////////////////

        private void DrawChart()
        {
            // save graphics state
            Contents.SaveGraphicsState();

            // create chart
            Chart PieChart = PdfChart.CreateChart(Document, 1.8, 1.5, 300.0);

            // create PdfChart object with Chart object
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.SaveAs = SaveImageAs.IndexedImage;
            PdfChart PiePdfChart = new PdfChart(Document, PieChart, ImageControl);

            // make sure we have good quality image
            PieChart.AntiAliasing = AntiAliasingStyles.None;     //.All;

            // set colors
            PieChart.BackColor = Color.FromArgb(220, 220, 255);
            PieChart.Palette   = ChartColorPalette.BrightPastel;

            // default font
            Font DefaultFont = PiePdfChart.CreateFont("Verdana", FontStyle.Regular, 0.05, FontSizeUnit.UserUnit);
            Font TitleFont   = PiePdfChart.CreateFont("Verdana", FontStyle.Bold, 0.07, FontSizeUnit.UserUnit);

            // title (font size is 0.25 inches)
            Title Title1 = new Title("Pie Chart Example", Docking.Top, TitleFont, Color.Purple);

            PieChart.Titles.Add(Title1);

            // legend
            Legend Legend1 = new Legend();

            PieChart.Legends.Add(Legend1);
            Legend1.BackColor = Color.FromArgb(230, 230, 255);
            Legend1.Docking   = Docking.Bottom;
            Legend1.Font      = DefaultFont;

            // chart area
            ChartArea ChartArea1 = new ChartArea();

            PieChart.ChartAreas.Add(ChartArea1);

            // chart area background color
            ChartArea1.BackColor = Color.FromArgb(255, 200, 255);

            // series 1
            Series Series1 = new Series();

            PieChart.Series.Add(Series1);
            Series1.ChartType           = SeriesChartType.Pie;
            Series1.Font                = DefaultFont;
            Series1.IsValueShownAsLabel = true;
            Series1.LabelFormat         = "{0} %";

            // series values
            Series1.Points.Add(22.0);
            Series1.Points[0].LegendText = "Apple";
            Series1.Points.Add(27.0);
            Series1.Points[1].LegendText = "Banana";
            Series1.Points.Add(33.0);
            Series1.Points[2].LegendText = "Orange";
            Series1.Points.Add(18.0);
            Series1.Points[3].LegendText = "Grape";

            Contents.DrawChart(PiePdfChart, 5.6, 5.0);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Esempio n. 9
0
        ////////////////////////////////////////////////////////////////////
        // Draw 3D Pyramin Chart
        ////////////////////////////////////////////////////////////////////

        public void DrawPyramidChart()
        {
            // create Chart object
            Chart PyramidChart = PdfChart.CreateChart(Document, 6.5, 4.0, 300.0);

            // create PdfChart object
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.SaveAs = SaveImageAs.IndexedImage;
            PdfChart PyramidPdfChart = new PdfChart(Document, PyramidChart, ImageControl);

            // make sure we have good quality image
            PyramidChart.AntiAliasing = AntiAliasingStyles.None;     // .All;

            // set colors
            PyramidChart.BackColor = Color.FromArgb(220, 220, 255);
            PyramidChart.Palette   = ChartColorPalette.BrightPastel;

            // title (font size is 0.25 inches)
            Font  TitleFont1 = PyramidPdfChart.CreateFont("Verdana", FontStyle.Bold, 0.25, FontSizeUnit.UserUnit);
            Title Title1     = new Title("Pyramid 3D Chart Example", Docking.Top, TitleFont1, Color.Purple);

            PyramidChart.Titles.Add(Title1);

            // title (font size is 0.25 inches)
            Font  TitleFont2 = PyramidPdfChart.CreateFont("Verdana", FontStyle.Bold, 0.15, FontSizeUnit.UserUnit);
            Title Title2     = new Title("Percent Fruit Sales", Docking.Top, TitleFont2, Color.Purple);

            PyramidChart.Titles.Add(Title2);

            // default font
            Font DefaultFont = PyramidPdfChart.CreateFont("Verdana", FontStyle.Regular, 0.12, FontSizeUnit.UserUnit);

            // legend
            Legend Legend1 = new Legend();

            PyramidChart.Legends.Add(Legend1);
            Legend1.BackColor = Color.FromArgb(230, 230, 255);
            Legend1.Docking   = Docking.Bottom;
            Legend1.Font      = DefaultFont;

            // chart area
            ChartArea ChartArea1 = new ChartArea();

            PyramidChart.ChartAreas.Add(ChartArea1);

            // 3d style
            ChartArea1.Area3DStyle.Enable3D = true;

            // chart area background color
            ChartArea1.BackColor = Color.FromArgb(255, 200, 255);

            // series 1
            Series Series1 = new Series();

            PyramidChart.Series.Add(Series1);
            Series1.ChartType                 = SeriesChartType.Pyramid;
            Series1.Font                      = DefaultFont;
            Series1.IsValueShownAsLabel       = true;
            Series1.LabelFormat               = "{0} %";
            Series1["Pyramid3DDrawingStyle"]  = "SquareBase";
            Series1["Pyramid3DRotationAngle"] = "8";
            Series1["PyramidPointGap"]        = "1";

            // series values
            Series1.Points.Add(20.0);
            Series1.Points[0].LegendText = "Apple";
            Series1.Points.Add(25.0);
            Series1.Points[1].LegendText = "Banana";
            Series1.Points.Add(10.0);
            Series1.Points[2].LegendText = "Pear";
            Series1.Points.Add(30.0);
            Series1.Points[3].LegendText = "Orange";
            Series1.Points.Add(15.0);
            Series1.Points[4].LegendText = "Grape";

            // draw chart into page contents
            Contents.DrawChart(PyramidPdfChart, 1.0, 1.0);
            return;
        }
Esempio n. 10
0
        ////////////////////////////////////////////////////////////////////
        // Draw Candle Stick Chart
        ////////////////////////////////////////////////////////////////////

        public void DrawStockChart()
        {
            // create Chart object
            Chart StockChart = PdfChart.CreateChart(Document, 6.5, 4.0, 300.0);

            // create PdfChart object
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.SaveAs = SaveImageAs.IndexedImage;
            PdfChart StockPdfChart = new PdfChart(Document, StockChart, ImageControl);

            // make sure we have good quality image
            StockChart.AntiAliasing = AntiAliasingStyles.None;     //.All;

            // set colors
            StockChart.BackColor = Color.FromArgb(220, 220, 255);
            StockChart.Palette   = ChartColorPalette.BrightPastel;

            // title (font size is 0.25 inches)
            Font  TitleFont1 = StockPdfChart.CreateFont("Verdana", FontStyle.Bold, 0.2, FontSizeUnit.UserUnit);
            Title Title1     = new Title("SP500 Daily Stock Price Chart Example", Docking.Top, TitleFont1, Color.Purple);

            StockChart.Titles.Add(Title1);

            // default font
            Font DefaultFont = StockPdfChart.CreateFont("Verdana", FontStyle.Regular, 0.12, FontSizeUnit.UserUnit);

            // chart area
            ChartArea ChartArea1 = new ChartArea();

            StockChart.ChartAreas.Add(ChartArea1);

            // chart area background color
            ChartArea1.BackColor = Color.FromArgb(255, 200, 255);

            // set font for axis
            Font TickMarkFont = StockPdfChart.CreateFont("Arial", FontStyle.Regular, 0.1, FontSizeUnit.Inch);

            ChartArea1.AxisX.LabelStyle.Font   = TickMarkFont;
            ChartArea1.AxisY.LabelStyle.Font   = TickMarkFont;
            ChartArea1.AxisY.LabelStyle.Format = "#,##0.00";

            // open stock daily price
            // takem from Yahoo Financial
            StreamReader Reader = new StreamReader("SP500.csv");

            // ignore header
            Reader.ReadLine();

            // data list
            List <DataPoint> DataArray = new List <DataPoint>();

            Double Max = Double.MinValue;
            Double Min = Double.MaxValue;

            // read all daily prices
            for (;;)
            {
                String TextLine = Reader.ReadLine();
                if (TextLine == null)
                {
                    break;
                }

                String[] Fld = TextLine.Split(new Char[] { ',' });

                String Date  = Fld[0];
                Double Open  = Double.Parse(Fld[1], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, NFI.PeriodDecSep);
                Double High  = Double.Parse(Fld[2], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, NFI.PeriodDecSep);
                Double Low   = Double.Parse(Fld[3], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, NFI.PeriodDecSep);
                Double Close = Double.Parse(Fld[4], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, NFI.PeriodDecSep);

                DataPoint Data = new DataPoint();
                Data.SetValueXY(Date, High, Low, Open, Close);
                DataArray.Add(Data);

                if (High > Max)
                {
                    Max = High;
                }
                if (Low < Min)
                {
                    Min = Low;
                }
            }

            // series 1
            Series Series1 = new Series();

            StockChart.Series.Add(Series1);
            Series1.ChartType = SeriesChartType.Candlestick;

            // setting bar colors
            Series1["PriceUpColor"]   = "White";
            Series1["PriceDownColor"] = "Black";
            Series1.Color             = Color.Black;

            // load data
            // note Yahoo provides in reversed order first line is most recent data
            DataArray.Reverse();
            foreach (DataPoint Data in DataArray)
            {
                Series1.Points.Add(Data);
            }

            // set min and max values for y axis
            ChartArea1.AxisY.Minimum = Math.Floor(Min);
            ChartArea1.AxisY.Maximum = Math.Ceiling(Max);

            // draw chart into page contents
            Contents.DrawChart(StockPdfChart, 1.0, 6.0);
            return;
        }
Esempio n. 11
0
        ////////////////////////////////////////////////////////////////////
        // Draw Column Chart
        ////////////////////////////////////////////////////////////////////

        public void DrawColumnChart()
        {
            // create chart
            Chart ColChart = new Chart();

            // image resolution pixels per user units
            Double ImageResolution = ColChart.RenderingDpiY * Document.ScaleFactor / 72.0;

            // image size in pixels
            // the equivalent of 6.5 by 4 inches in user units
            ColChart.Width  = (Int32)(6.5 * ImageResolution + 0.5);
            ColChart.Height = (Int32)(4.0 * ImageResolution + 0.5);

            // make sure we have good quality image
            ColChart.AntiAliasing = AntiAliasingStyles.None;     //.All;

            // set colors
            ColChart.BackColor = Color.FromArgb(220, 220, 255);
            ColChart.Palette   = ChartColorPalette.Excel;

            // title (font size is 0.25 inches)
            Font  TitleFont = new Font("Verdana", (Single)(0.25 * ImageResolution), FontStyle.Bold, GraphicsUnit.Pixel);
            Title Title1    = new Title("Column Chart Example", Docking.Top, TitleFont, Color.Purple);

            ColChart.Titles.Add(Title1);

            // legend
            Font   LegendFont = new Font("Times New Roman", (Single)(0.125 * ImageResolution), FontStyle.Bold, GraphicsUnit.Pixel);
            Legend Legend1    = new Legend();

            ColChart.Legends.Add(Legend1);
            Legend1.BackColor = Color.FromArgb(230, 230, 255);
            Legend1.Docking   = Docking.Bottom;
            Legend1.Font      = LegendFont;

            // chart area
            ChartArea ChartArea1 = new ChartArea();

            ColChart.ChartAreas.Add(ChartArea1);

            // set font for axis
            Font TickMarkFont = new Font("Arial", (Single)(0.1 * ImageResolution), FontStyle.Regular, GraphicsUnit.Pixel);

            ChartArea1.AxisX.LabelStyle.Font = TickMarkFont;
            ChartArea1.AxisY.LabelStyle.Font = TickMarkFont;

            // Y axis labels
            ChartArea1.AxisY.Title     = "Y Axis Description";
            ChartArea1.AxisY.TitleFont = LegendFont;

            // chart area back color
            ChartArea1.BackColor = Color.FromArgb(255, 220, 255);

            // series 1
            Series Series1 = new Series();

            ColChart.Series.Add(Series1);
            Series1.ChartType           = SeriesChartType.Column;
            Series1.LegendText          = "Series One";
            Series1.IsValueShownAsLabel = true;
            Series1.Font = TickMarkFont;
            Series1.Points.AddXY("2010", 3.0);
            Series1.Points.AddXY("2011", 4.5);
            Series1.Points.AddXY("2012", 7.0);
            Series1.Points.AddXY("2013", 5.0);
            Series1.Points.AddXY("2014", 9.0);

            // series 2
            Series Series2 = new Series();

            ColChart.Series.Add(Series2);
            Series2.ChartType           = SeriesChartType.Column;
            Series2.LegendText          = "Series Two";
            Series2.IsValueShownAsLabel = true;
            Series2.Font = TickMarkFont;
            Series2.Points.AddXY("2010", 12.0);
            Series2.Points.AddXY("2011", 13.5);
            Series2.Points.AddXY("2012", 16.0);
            Series2.Points.AddXY("2013", 14.0);
            Series2.Points.AddXY("2014", 18.0);

            // draw chart into page contents
            PdfImageControl ImageControl = new PdfImageControl();

            ImageControl.SaveAs = SaveImageAs.IndexedImage;
            PdfChart ColumnChart = new PdfChart(Document, ColChart, ImageControl);

            Contents.DrawChart(ColumnChart, 1.0, 1.0);
            return;
        }
        private void mandarButton_Click(object sender, EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

              String connString = "Database=" + Properties.Settings.Default.databaseFiscal + ";Data Source=" + Properties.Settings.Default.datasource + ";Integrated Security=False;User ID='" + Properties.Settings.Default.user + "';Password='******';connect timeout = 10";
              try
              {

                  using (SqlConnection connection = new SqlConnection(connString))
                  {
                      connection.Open();
                      String queryXML = "";
                      if(Login.unidadDeNegocioGlobal.Equals("FOP"))
                      {
                          queryXML = "SELECT b.ADDR_LINE_1,b.ADDR_LINE_2,b.ADDR_LINE_3,b.ADDR_LINE_4,b.ADDR_LINE_5  , a.AMOUNT, a.TRANS_DATETIME,a.DESCRIPTN,a.JRNAL_SRCE, a.ANAL_T0,a.ACCNT_CODE,c.DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_" + Properties.Settings.Default.sunLibro + "_SALFLDG] a INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ADDR] b on a.ANAL_T2 = b.ADDR_CODE INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[FOP_ACNT] c on c.ACNT_CODE = a.ACCNT_CODE WHERE a.JRNAL_NO = " + diarioText.Text + " AND a.ANAL_T9 = '" + iglesiaText.Text + "'";
                      }
                      else
                      {
                          queryXML = "SELECT b.ADDR_LINE_1,b.ADDR_LINE_2,b.ADDR_LINE_3,b.ADDR_LINE_4,b.ADDR_LINE_5  , a.AMOUNT, a.TRANS_DATETIME,a.DESCRIPTN,a.JRNAL_SRCE, a.ANAL_T0,a.ACCNT_CODE,c.DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_" + Properties.Settings.Default.sunLibro + "_SALFLDG] a INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ADDR] b on a.ANAL_T2 = b.ADDR_CODE INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ACNT] c on c.ACNT_CODE = a.ACCNT_CODE WHERE a.JRNAL_NO = " + diarioText.Text + " AND a.ANAL_T5 = '" + iglesiaText.Text + "'";
                      }
                      using (SqlCommand cmdCheck = new SqlCommand(queryXML, connection))
                      {
                          String saveANAL="";
                          String saveFecha = "";

                          SqlDataReader reader = cmdCheck.ExecuteReader();
                          if (reader.HasRows)
                          {
                              bool first = true;
                              String FileName = "C:" + (object)Path.DirectorySeparatorChar + "recibos" + (object)Path.DirectorySeparatorChar + iglesiaText.Text + "_" + diarioText.Text + ".pdf";
                              string path = "C:" + (object)Path.DirectorySeparatorChar + "recibos";
                              if (!Directory.Exists(path))
                                  Directory.CreateDirectory(path);
                              if (File.Exists(FileName))
                              {
                                  try
                                  {
                                      File.Delete(FileName);
                                  }
                                  catch (IOException ex2)
                                  {
                                      System.Windows.Forms.MessageBox.Show(ex2.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                  }
                              }

                              Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);
                              DefineFontResources();
                              DefineTilingPatternResource();
                              PdfPage Page = new PdfPage(Document);
                              PdfContents Contents = new PdfContents(Page);
                              Contents.SaveGraphicsState();

                              String fileImage = "C:" + (object)Path.DirectorySeparatorChar + "recibos" + (object)Path.DirectorySeparatorChar + "logo.jpg";
                              PdfImageControl ImageControl = new PdfImageControl();
                              ImageControl.Resolution = 300.0;
                              PdfImage Image = new PdfImage(Document, fileImage, ImageControl); //new PdfImage(Document, fileImage, 72.0, 50);
                              Contents.SaveGraphicsState();
                              double top = 9.9;
                              double left = 0.4;
                              int ancho = 1;
                              int largo = 1;
                             Contents.DrawImage(Image, left, top, ancho, largo);
                             Contents.DrawImage(Image, left, top-6.2, ancho, largo);

                              Contents.RestoreGraphicsState();
                              Contents.SaveGraphicsState();

                              const Double Width = 8.15;
                              const Double Height = 10.65;
                              PdfFileWriter.TextBox Box = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox Datos = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox derecha = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox fechaBox = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox graciasBox = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox copiaBox = new PdfFileWriter.TextBox(Width, 0.0);

                              //double dif = 2.5;
                             // Contents.SaveGraphicsState();
                              //Contents.RestoreGraphicsState();
                              Contents.Translate(0.0, 0.0);
                              PdfTable Table = new PdfTable(Page, Contents, ArialNormal, 9.0);
                              PdfTable TableCopy = new PdfTable(Page, Contents, ArialNormal, 9.0);

                              Table.TableArea = new PdfRectangle(0.5, 1,8.0,7.7);
                              TableCopy.TableArea = new PdfRectangle(0.5, 1, 8.0, 1.75);

                              Double MarginHor = 0.04;
                              double aver = ArialNormal.TextWidth(9.0, "9999.99") + 2.0 * MarginHor;
                              double aver2 = ArialNormal.TextWidth(9.0, "Qty") + 2.0 * MarginHor;
                              aver += 0.2;
                              Table.SetColumnWidth(new Double[] { aver2,aver , aver, aver2 });
                              Table.Borders.SetAllBorders(0.0);

                              Table.Header[0].Style = Table.HeaderStyle;
                              Table.Header[0].Style.Alignment = ContentAlignment.MiddleCenter;
                              Table.Header[1].Style = Table.HeaderStyle;
                              Table.Header[1].Style.Alignment = ContentAlignment.MiddleCenter;
                              Table.Header[2].Style = Table.HeaderStyle;
                              Table.Header[2].Style.Alignment = ContentAlignment.MiddleCenter;
                              Table.Header[3].Style = Table.HeaderStyle;
                              Table.Header[3].Style.Alignment = ContentAlignment.MiddleCenter;

                              Table.Header[0].Value = "Cuenta";
                              Table.Header[1].Value = "Descripción";
                              Table.Header[2].Value = "Concepto";
                              Table.Header[3].Value = "Total";

                              TableCopy.SetColumnWidth(new Double[] { aver2, aver, aver, aver2 });
                              TableCopy.Borders.SetAllBorders(0.0);

                              TableCopy.Header[0].Style = Table.HeaderStyle;
                              TableCopy.Header[0].Style.Alignment = ContentAlignment.MiddleCenter;
                              TableCopy.Header[1].Style = Table.HeaderStyle;
                              TableCopy.Header[1].Style.Alignment = ContentAlignment.MiddleCenter;
                              TableCopy.Header[2].Style = Table.HeaderStyle;
                              TableCopy.Header[2].Style.Alignment = ContentAlignment.MiddleCenter;
                              TableCopy.Header[3].Style = Table.HeaderStyle;
                              TableCopy.Header[3].Style.Alignment = ContentAlignment.MiddleCenter;

                              TableCopy.Header[0].Value = "Cuenta";
                              TableCopy.Header[1].Value = "Descripción";
                              TableCopy.Header[2].Value = "Concepto";
                              TableCopy.Header[3].Value = "Total";

                              StringBuilder cad = new StringBuilder("");
                              StringBuilder primeros = new StringBuilder("");
                              StringBuilder letrasGrandes = new StringBuilder("");
                              StringBuilder fechaCad = new StringBuilder("");

                              StringBuilder tabla = new StringBuilder("");
                              double total=0;
                              int contadorTabla = 0;
                              while (reader.Read())
                              {
                                  String ADDR_LINE_1 = reader.GetString(0).Trim();
                                  String ADDR_LINE_2 = reader.GetString(1).Trim();
                                  String ADDR_LINE_3 = reader.GetString(2).Trim();
                                  String ADDR_LINE_4 = reader.GetString(3).Trim();
                                  String ADDR_LINE_5 = reader.GetString(4).Trim();
                                  String amount = Convert.ToString(reader.GetDecimal(5));
                                  String fecha = Convert.ToString(reader.GetDateTime(6)).Substring(0, 10);

                                  String DESCR = reader.GetString(7).Trim();
                                  if(DESCR.Length>32)
                                  {
                                      DESCR = DESCR.Substring(0, 32);
                                  }
                                  String JRNAL_SRCE = reader.GetString(8).Trim();
                                  String ANAL_T0 = reader.GetString(9).Trim();
                                  saveANAL=ANAL_T0;
                                  String ACNT_CODE = reader.GetString(10).Trim();
                                  String descrCuenta = reader.GetString(11).Trim();
                                  if (descrCuenta.Length > 36)
                                  {
                                      descrCuenta = descrCuenta.Substring(0, 36);
                                  }
                                  total+=Convert.ToDouble(amount);
                                  if(first)
                                  {
                                      first = false;
                                      primeros.Append( ADDR_LINE_1 + "\n" +
                                         ADDR_LINE_2 + "\n" +
                                      ADDR_LINE_3 + "\n" +
                                      ADDR_LINE_4 + "\n" +
                                      ADDR_LINE_5 + "\n\n");
                                      fechaCad.Append(" Fecha de recepción:\n" + fecha);

                                      letrasGrandes.Append("      Recibido de " + DESCR + "\n");
                                      saveFecha = fecha;
                                  }
                                  Table.Cell[0].Value = ACNT_CODE;
                                  Table.Cell[1].Value = descrCuenta;
                                  Table.Cell[2].Value = DESCR;
                                   Table.Cell[3].Value = "$"+String.Format("{0:n}", Convert.ToDouble(amount));
                                  Table.DrawRow();
                                  TableCopy.Cell[0].Value = ACNT_CODE;
                                  TableCopy.Cell[1].Value = descrCuenta;
                                  TableCopy.Cell[2].Value = DESCR;
                                  TableCopy.Cell[3].Value = "$" + String.Format("{0:n}", Convert.ToDouble(amount));
                                  TableCopy.DrawRow();

                                  contadorTabla++;

                                //  tabla.Append("\n"+DESCR+"         "+ACNT_CODE+"        "+JRNAL_SRCE+"        "+  String.Format("{0:n}", Convert.ToDouble(amount)));
                              }//while
                              Table.Close();
                              TableCopy.Close();
                              Contents.SaveGraphicsState();
                              Contents.RestoreGraphicsState();

                              letrasGrandes.Append("      ***** " + Conversiones.NumeroALetras(total.ToString()) + " *****\n");

                              cad.Append(" Número de recibo original: " + saveANAL + "\n Diario: " + diarioText.Text + "\n" +
                                      " Monto recibido\n ***** "+String.Format("{0:n}", Convert.ToDouble(total))+" *****\n\n");
                              //cad.Append();
                              try{

                                  Box.AddText(ArialNormal, 14.0,
                                    primeros.ToString()  );
                                  Datos.AddText(ArialNormal, 14.0,
                                letrasGrandes.ToString() );
                                  copiaBox.AddText(ArialBold, 50.0,
                              "     COPY");
                                  graciasBox.AddText(ArialItalic, 30.0,
                              "                           Gracias\n");
                                  fechaBox.AddText(ArialNormal, 10.0,
                                 fechaCad.ToString());
                               derecha.AddText(ArialNormal, 12.0,
                                 cad.ToString());
                                  Double PosY = 8.5;
                                  Double PosYDatos = 9.0;
                                  Double auxY = Height;
                                  Double auxFecha = Height-0.5;
                                  double dif = 6.0;
                                  Double auxYCopia = Height-dif;
                                  Double auxFechaCopia = Height - 0.5-dif;
                                  Double PosYCopia = 8.5-dif;
                                  Double copiaCopia = 8.5 - dif;

                                  Double PosYDatosCopia = 9.0-dif;

                                  Contents.Translate(0.0, 10.0);

                                 // Contents.Translate(0.0, -9.9);//-9.9

                                 Contents.Translate(0.0, -9.9);

                                  Contents.DrawText(0.0, ref auxY, 9.0, 0, 0.0, 0.0, TextBoxJustify.Center, Box);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();
                                  //la copia
                                  Contents.DrawText(0.0, ref auxYCopia, 1.0, 0, 0.0, 0.0, TextBoxJustify.Center, Box);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();
                                 // Contents.Translate(0.0, -9.9);
                                  Contents.DrawText(0, ref PosYDatos, 8.5, 0, 0.00, 0.00, TextBoxJustify.Left, Datos);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYDatosCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, Datos);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                 // Contents.Translate(0.0, -9.9);
                                  Contents.DrawText(0, ref PosY, 7.0, 0, 0.00, 0.00, TextBoxJustify.Right, derecha);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYDatos, 7.0, 0, 0.00, 0.00, TextBoxJustify.Left, graciasBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Right, derecha);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYDatosCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, graciasBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref copiaCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, copiaBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  //Contents.Translate(0.0, -9.9);
                                  Contents.DrawText(0, ref auxFecha, 9.5, 0, 0.00, 0.00, TextBoxJustify.Right, fechaBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref auxFechaCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Right, fechaBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                Document.CreateFile();

                                try
                                {
                                    MailMessage mail2 = new MailMessage();
                                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                                    mail2.From = new MailAddress(Properties.Settings.Default.correoEmisor);
                                    mail2.To.Add(correoLabel.Text);

                                    mail2.CC.Add(Properties.Settings.Default.correoReceptor);
                                    DateTime now = DateTime.Now;
                                    int year = now.Year;
                                    int month = now.Month;
                                    int day = now.Day;
                                    String mes = month.ToString();
                                    if (month < 10)
                                    {
                                        mes = "0" + month;
                                    }
                                    String dia = day.ToString();
                                    if (day < 10)
                                    {
                                        dia = "0" + day;
                                    }
                                    if(Login.unidadDeNegocioGlobal.Equals("FOP"))
                                    {
                                        mail2.Subject = "Recibo del dia: " + saveFecha + " del diario "+diarioText.Text+" de FORPOUMN " + iglesiaText.Text ;
                                        mail2.Body = "Hola " + nombreLabel.Text + ", por este medio le envio el recibo de FOPROUMN correspondiente al diario "+diarioText.Text+". Dios lo bendiga. ";
                                    }
                                    else
                                    {
                                        mail2.Subject = "Recibo de caja del dia: " + saveFecha + " de la iglesia " + iglesiaText.Text;
                                        mail2.Body = "Hola " + nombreLabel.Text + ", por este medio le envio el recibo de caja de la iglesia " + iglesiaText.Text;
                                    }
                                    Attachment pdf = new Attachment(FileName);
                                    mail2.Attachments.Add(pdf);
                                    SmtpServer.Port = 587;
                                    SmtpServer.Credentials = new System.Net.NetworkCredential(Properties.Settings.Default.correoEmisor, Properties.Settings.Default.passEmisor);
                                    SmtpServer.EnableSsl = true;
                                    SmtpServer.Send(mail2);
                                    this.Cursor = System.Windows.Forms.Cursors.Arrow;

                                    System.Windows.Forms.MessageBox.Show("Ya se mando el correo", "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                                }
                                catch (Exception ex3)
                                {
                                    System.Windows.Forms.MessageBox.Show(ex3.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }

                                   }//try
                              catch(Exception ex1)
                              {
                                          System.Windows.Forms.MessageBox.Show(ex1.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                              }
                          }
                      }
                  }
              }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
              this.Cursor = System.Windows.Forms.Cursors.Arrow;
        }