Exemplo n.º 1
0
		void CreatePDFFile( IEnumerable<ScannedImageViewModel> items, string filename )
		{
			try
			{
				// Save document
				var Document = new PdfDocument( PaperType.A4, false, UnitOfMeasure.cm, filename );

				// add to pdf file all images from collection
				foreach ( ScannedImageViewModel scan in items )
				{
					var page = new PdfPage( Document, PaperType.A4, scan.Image.Landscape );
					var contents = new PdfContents( page );
					var image = new PdfImage( Document, scan.Image.Source, 0, PdfQuality );
					contents.DrawFullPageImage( image, scan.Image.Landscape );
				}
				Document.CreateFile();
			}
			catch ( IOException )
			{
				// localization dictionary
				var dictionary = Application.Current.Resources.MergedDictionaries[ 0 ];
				Notify = new Notify( (string) dictionary[ "er_CantCreateFile" ], Notify.Type.Warning );
			}
			catch ( Exception ex )
			{
				Notify = new Notify( ex.Message, Notify.Type.Warning );
			}
		}
Exemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// PdfContents constructor for page contents
        /// </summary>
        /// <param name="Page">Page parent</param>
        ////////////////////////////////////////////////////////////////////
        public PdfContents(
			PdfPage		Page
			)
            : base(Page.Document, ObjectType.Stream)
        {
            // set page contents flag
            PageContents = true;

            // add contents to page's list of contents
            Page.AddContents(this);

            // exit
            return;
        }
Exemplo n.º 3
0
        // start a new page
        private void CreateNewPage()
        {
            // terminate activity on current page
            if(RowNumber > 0)
            {
            // draw border and grid on current page
            DrawBorders();

            // call user event handler for end of table on each page
            if(TableEndEvent != null) TableEndEvent(this, _RowTopPosition);
            }

            // create a new page
            Page = new PdfPage(Document);
            Contents = new PdfContents(Page);

            // reset border lines
            BorderRowTopPos = _TableArea.Top;
            BorderYPos.Clear();
            BorderYPos.Add(BorderRowTopPos);

            _RowTopPosition = BorderRowTopPos;
            _RowTopPosition -= Borders.TopBorder.HalfWidth;

            // calculate header height
            if(RowNumber > 0 && DisplayHeader && HeaderOnEachPage) HeaderHeight = CalculateRowHeight(_Header);
            return;
        }
Exemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw web link with one line of text
        /// </summary>
        /// <param name="Page">Current page</param>
        /// <param name="Font">Font</param>
        /// <param name="FontSize">Font size</param>
        /// <param name="TextAbsPosX">Text absolute position X</param>
        /// <param name="TextAbsPosY">Text absolute position Y</param>
        /// <param name="Text">Text</param>
        /// <param name="WebLink">Web link</param>
        /// <returns>Text width</returns>
        /// <remarks>
        ///	The position arguments are in relation to the
        ///	bottom left corner of the paper.
        ///	Text will be drawn left justified, underlined and in dark blue.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public Double DrawWebLink(
			PdfPage		Page,
			PdfFont		Font,
			Double		FontSize,		// in points
			Double		TextAbsPosX,
			Double		TextAbsPosY,
			String		Text,
			String		WebLink
			)
        {
            return(DrawWebLink(Page, Font, FontSize, TextAbsPosX, TextAbsPosY, TextJustify.Left, DrawStyle.Underline, Color.DarkBlue, Text, WebLink));
        }
Exemplo n.º 5
0
        ////////////////////////////////////////////////////////////////////
        // Draw text within text box center or right justified
        ////////////////////////////////////////////////////////////////////
        private Double DrawText(
			Double			PosX,
			Double			PosY,
			Double			Width,
			TextBoxJustify	Justify,
			TextBoxLine		Line,
			PdfPage			Page
			)
        {
            Double LineWidth = 0;
            foreach(TextBoxSeg Seg in Line.SegArray) LineWidth += Seg.SegWidth;

            Double SegPosX = PosX;
            if(Justify == TextBoxJustify.Right) SegPosX += Width - LineWidth;
            else SegPosX += 0.5 * (Width - LineWidth);
            foreach(TextBoxSeg Seg in Line.SegArray)
            {
            Double SegWidth = DrawText(Seg.Font, Seg.FontSize, SegPosX, PosY, TextJustify.Left, Seg.DrawStyle, Seg.FontColor, Seg.Text);
            if(Seg.WebLink != null)
                {
                if(Page == null) throw new ApplicationException("TextBox with WebLink. You must call DrawText with PdfPage");
                Page.AddWebLink(SegPosX, PosY - Seg.Font.DescentPlusLeading(Seg.FontSize), SegPosX + SegWidth, PosY + Seg.Font.AscentPlusLeading(Seg.FontSize), Seg.WebLink);
                }

            SegPosX += SegWidth;
            }

            return(SegPosX - PosX);
        }
        public void vuelveAHacerElCheque(bool conImagen)
        {
            string path = Properties.Settings.Default.letra+ ":" + (object)Path.DirectorySeparatorChar + "cheques";
            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(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            String fileImage = path + (object)Path.DirectorySeparatorChar + "cheque" + tipoDeBancoGlobal+".jpg";

            Document = new PdfDocument(PaperType.sobreprima, false, UnitOfMeasure.Point, FileName);
            DefineFontResources();
            DefineTilingPatternResource();
            PdfPage Page = new PdfPage(Document);
            PdfContents Contents = new PdfContents(Page);

            Contents.SaveGraphicsState();
            Contents.Translate(0.1, 0.1);

            const Double FontSize = 9.0;

            if(conImagen)
            {
                PdfImage Image = new PdfImage(Document, fileImage, 72.0, 50);
                Contents.SaveGraphicsState();
                int top = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "topCheque" + tipoDeBancoGlobal));
                int left = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "leftCheque" + tipoDeBancoGlobal));
                int ancho = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "anchoCheque" + tipoDeBancoGlobal));
                int largo = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "largoCheque" + tipoDeBancoGlobal));
                Contents.DrawImage(Image, left, top, ancho, largo);
                Contents.RestoreGraphicsState();
            }

            int fechaX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "fechaX" + tipoDeBancoGlobal));
            int fechaY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "fechaY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(fechaX, fechaY));
            Contents.DrawText(ArialNormal, FontSize, fechaX, fechaY, fecha);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            int nombreX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "nombreX" + tipoDeBancoGlobal));
            int nombreY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "nombreY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(nombreX, nombreY));
            Contents.DrawText(ArialNormal, FontSize, nombreX, nombreY, nombre);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            int cantidadX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "cantidadX" + tipoDeBancoGlobal));
            int cantidadY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "cantidadY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(cantidadX, cantidadY));
            Contents.DrawText(ArialNormal, FontSize, cantidadX, cantidadY, total);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            int letraX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "letraX" + tipoDeBancoGlobal));
            int letraY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "letraY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(letraX, letraY));
            Contents.DrawText(ArialNormal, FontSize, letraX, letraY, numeroAletras);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            Contents.RestoreGraphicsState();
            Document.CreateFile();

            String url = "file:" + (object)Path.DirectorySeparatorChar + (object)Path.DirectorySeparatorChar +FileName;
            // this.webBrowser1.Navigate(new Uri(url));
            this.webView1.ZoomFactor = 1.0;
            this.webView1.Url = url;
            Properties.Settings.Default.Save();
        }
Exemplo n.º 7
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw TextBox
        /// </summary>
        /// <param name="PosX">Position X</param>
        /// <param name="PosYTop">Position Y (by reference)</param>
        /// <param name="PosYBottom">Position Y bottom</param>
        /// <param name="LineNo">Start at line number</param>
        /// <param name="TextBox">TextBox</param>
        /// <param name="Page">Page if TextBox contains web link segment</param>
        /// <returns>Next line number</returns>
        /// <remarks>
        /// Before calling this method you must add text to a TextBox object.
        /// <para>
        /// Set the PosX and PosYTop to the left top corner of the text area.
        /// Note PosYTop is by reference. This variable will be updated to
        /// the next vertical line position after the method was executed.
        /// </para>
        /// <para>
        /// Set the PosYBottom to the bottom of your page. The method will
        /// not print below this value.
        /// </para>
        /// <para>
        /// Set the LineNo to the first line to be printed. Initially 
        /// this will be zero. After the method returns, PosYTop is set 
        /// to next print line on the page and LineNo is set to next line 
        /// within the box.
        /// </para>
        /// <para>
        /// If LineNo is equals to TextBox.LineCount the box was fully printed. 
        /// </para>
        /// <para>
        /// If LineNo is less than TextBox.LineCount box printing was not
        /// done. Start a new PdfPage and associated PdfContents. Set 
        /// PosYTop to desired start position. Set LineNo to the value
        /// returned by this method, and call the method again.
        /// </para>
        /// <para>
        /// If your TextBox contains WebLink segment you must supply
        /// Page argument and position X and Y must be relative to
        /// page bottom left corner.
        /// </para>
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public Int32 DrawText(
			Double			PosX,
			ref Double		PosYTop,
			Double			PosYBottom,
			Int32			LineNo,
			TextBox			TextBox,
			PdfPage			Page = null
			)
        {
            return(DrawText(PosX, ref PosYTop, PosYBottom, LineNo, 0.0, 0.0, TextBoxJustify.Left, TextBox, Page));
        }
Exemplo n.º 8
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add child bookmark
        /// </summary>
        /// <param name="Title">Bookmark title.</param>
        /// <param name="Page">Page</param>
        /// <param name="YPos">Vertical position.</param>
        /// <param name="Paint">Bookmark color.</param>
        /// <param name="TextStyle">Bookmark text style.</param>
        /// <param name="OpenEntries">Open child bookmarks attached to this one.</param>
        /// <returns>Bookmark object</returns>
        /// <remarks>
        /// Add bookmark as a child to this bookmark.
        /// This method creates a new child bookmark item attached
        /// to this parent
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfBookmark AddBookmark(
			String		Title,			// bookmark title
			PdfPage		Page,			// bookmark page
			Double		YPos,			// bookmark vertical position relative to bottom left corner of the page
			Color		Paint,			// bookmark color
			TextStyle	TextStyle,		// bookmark text style: normal, bold, italic, bold-italic
			Boolean		OpenEntries		// true is display children. false hide children
			)
        {
            return(AddBookmark(Title, Page, 0.0, YPos, 0.0, Paint, TextStyle, OpenEntries));
        }
Exemplo n.º 9
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add child bookmark
        /// </summary>
        /// <param name="Title">Bookmark title.</param>
        /// <param name="Page">Page</param>
        /// <param name="XPos">Horizontal position</param>
        /// <param name="YPos">Vertical position.</param>
        /// <param name="Zoom">Zoom factor (1.0 is 100%. 0.0 is no change from existing zoom).</param>
        /// <param name="OpenEntries">Open child bookmarks attached to this one.</param>
        /// <returns>Bookmark object</returns>
        /// <remarks>
        /// Add bookmark as a child to this bookmark.
        /// This method creates a new child bookmark item attached
        /// to this parent
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfBookmark AddBookmark(
			String		Title,			// bookmark title
			PdfPage		Page,			// bookmark page
			Double		XPos,			// bookmark horizontal position relative to bottom left corner of the page
			Double		YPos,			// bookmark vertical position relative to bottom left corner of the page
			Double		Zoom,			// Zoom factor. 1.0 is 100%. 0.0 is no change from existing zoom.
			Boolean		OpenEntries		// true is display children. false hide children
			)
        {
            return(AddBookmark(Title, Page, XPos, YPos, Zoom, Color.Empty, TextStyle.Normal, OpenEntries));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            String FileName = "testmac2.pdf";
            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();

            const Double Width = 8.15;
            const Double Height = 10.65;
            //const Double FontSize = 12.0;
            PdfFileWriter.TextBox Box = new PdfFileWriter.TextBox(Width, 0.25);
            StringBuilder lineas = new StringBuilder("hola 2");

            Box.AddText(ArialNormal, 14.0,
                                  lineas.ToString() + "\n");
            Double PosY = Height;
            Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box);
            Contents.RestoreGraphicsState();

            Document.CreateFile();

            System.Windows.Forms.MessageBox.Show("al parecer, todo bien tambien", "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
Exemplo n.º 11
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add child bookmark
        /// </summary>
        /// <param name="Title">Bookmark title.</param>
        /// <param name="Page">Page</param>
        /// <param name="YPos">Vertical position.</param>
        /// <param name="OpenEntries">Open child bookmarks attached to this one.</param>
        /// <returns>Bookmark object</returns>
        /// <remarks>
        /// Add bookmark as a child to this bookmark.
        /// This method creates a new child bookmark item attached
        /// to this parent
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfBookmark AddBookmark(
			String		Title,			// bookmark title
			PdfPage		Page,			// bookmark page
			Double		YPos,			// bookmark vertical position relative to bottom left corner of the page
			Boolean		OpenEntries		// true is display children. false hide children
			)
        {
            return(AddBookmark(Title, Page, 0.0, YPos, 0.0, Color.Empty, TextStyle.Normal, OpenEntries));
        }
        private void generarButton_Click(object sender, EventArgs e)
        {
            Item itm = (Item)periodosCombo.SelectedItem;
            int periodo = Convert.ToInt32(itm.Name);
            String cuenta = cuentaText.Text.Trim();

            String connString = "Database=" + Properties.Settings.Default.sunDatabase + ";Data Source=" + Properties.Settings.Default.datasource + ";Integrated Security=False;MultipleActiveResultSets=true;User ID='" + Properties.Settings.Default.user + "';Password='******';connect timeout = 60";
            String queryPeriodos = "SELECT JRNAL_NO, JRNAL_LINE, AMOUNT, PERIOD, JRNAL_SRCE, TRANS_DATETIME, ALLOCATION, D_C, JRNAL_TYPE, ANAL_T0, ANAL_T1, ANAL_T2, ANAL_T3, ANAL_T4, ANAL_T5, ANAL_T6, ANAL_T7, ANAL_T8, ANAL_T9 FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_" + Properties.Settings.Default.sunLibro + "_SALFLDG] WHERE ACCNT_CODE = '"+cuenta+"' AND PERIOD <= "+periodo+" order by PERIOD asc, JRNAL_NO asc, JRNAL_LINE desc";
            try
            {
                using (SqlConnection connection = new SqlConnection(connString))
                {
                    connection.Open();
                    SqlCommand cmdCheck = new SqlCommand(queryPeriodos, connection);
                    SqlDataReader reader = cmdCheck.ExecuteReader();
                    if (reader.HasRows)
                    {
                        String FileName = cuentaText.Text + "_" + periodo + ".pdf";
                        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 Page0 = new PdfPage(Document);
                        PdfContents Contents0 = new PdfContents(Page0);

                        PdfPage Page1 = null;
                        PdfContents Contents1 = null;
                        PdfPage Page2 = null;
                        PdfContents Contents2 = null;
                        PdfPage Page3 = null;
                        PdfContents Contents3 = null;
                        PdfPage Page4 = null;
                        PdfContents Contents4 = null;
                        PdfPage Page5 = null;
                        PdfContents Contents5 = null;
                        PdfPage Page6 = null;
                        PdfContents Contents6 = null;
                        PdfPage Page7 = null;
                        PdfContents Contents7 = null;
                        PdfPage Page8 = null;
                        PdfContents Contents8 = null;
                        PdfPage Page9 = null;
                        PdfContents Contents9 = null;
                        PdfPage Page10 = null;
                        PdfContents Contents10 = null;
                        PdfPage Page11 = null;
                        PdfContents Contents11 = null;
                        PdfPage Page12 = null;
                        PdfContents Contents12 = null;
                        PdfPage Page13 = null;
                        PdfContents Contents13 = null;
                        PdfPage Page14 = null;
                        PdfContents Contents14 = null;
                        PdfPage Page15 = null;
                        PdfPage Page16 = null;
                        PdfPage Page17 = null;
                        PdfPage Page18 = null;
                        PdfPage Page19 = null;
                        PdfPage Page20 = null;
                        PdfPage Page21 = null;
                       /* PdfPage Page22 = null;
                        PdfPage Page23 = null;
                        PdfPage Page24 = null;
                        PdfPage Page25 = null;
                        PdfPage Page26 = null;
                        PdfPage Page27 = null;
                        PdfPage Page28 = null;
                        PdfPage Page29 = null;
                        PdfPage Page30 = null;
                        PdfPage Page31 = null;
                        PdfPage Page32 = null;
                        PdfPage Page33 = null;
                        PdfPage Page34 = null;
                        PdfPage Page35 = null;
                        PdfPage Page36 = null;
                        PdfPage Page37 = null;
                        PdfPage Page38 = null;
                        PdfPage Page39 = null;
                        PdfPage Page40 = null;
                        PdfPage Page41 = null;
                        */
                        PdfContents Contents15 = null;
                        PdfContents Contents16 = null;
                        PdfContents Contents17 = null;
                        PdfContents Contents18 = null;
                        PdfContents Contents19 = null;
                        PdfContents Contents20 = null;
                        PdfContents Contents21 = null;
                       /* PdfContents Contents22 = null;
                        PdfContents Contents23 = null;
                        PdfContents Contents24 = null;
                        PdfContents Contents25 = null;
                        PdfContents Contents26 = null;
                        PdfContents Contents27 = null;
                        PdfContents Contents28 = null;
                        PdfContents Contents29 = null;
                        PdfContents Contents30 = null;
                        PdfContents Contents31 = null;
                        PdfContents Contents32 = null;
                        PdfContents Contents33 = null;
                        PdfContents Contents34 = null;
                        PdfContents Contents35 = null;
                        PdfContents Contents36 = null;
                        PdfContents Contents37 = null;
                        PdfContents Contents38 = null;
                        PdfContents Contents39 = null;
                        PdfContents Contents40 = null;
                        PdfContents Contents41 = null;
                       */

                        Contents0.SaveGraphicsState();

                        const Double Width = 8.15;
                        const Double Height = 10.65;
                        //const Double FontSize = 12.0;
                        PdfFileWriter.TextBox Box0 = new PdfFileWriter.TextBox(Width, 0.25);
                        StringBuilder lineas = new StringBuilder("");

                        PdfFileWriter.TextBox Box1 = null;
                        PdfFileWriter.TextBox Box2 = null;
                        PdfFileWriter.TextBox Box3 = null;
                        PdfFileWriter.TextBox Box4 = null;
                        PdfFileWriter.TextBox Box5 = null;
                        PdfFileWriter.TextBox Box6 = null;
                        PdfFileWriter.TextBox Box7 = null;
                        PdfFileWriter.TextBox Box8 = null;
                        PdfFileWriter.TextBox Box9 = null;
                        PdfFileWriter.TextBox Box10 = null;
                        PdfFileWriter.TextBox Box11 = null;
                        PdfFileWriter.TextBox Box12 = null;
                        PdfFileWriter.TextBox Box13 = null;
                        PdfFileWriter.TextBox Box14 = null;
                        PdfFileWriter.TextBox Box15 = null;
                        PdfFileWriter.TextBox Box16 = null;
                        PdfFileWriter.TextBox Box17 = null;
                        PdfFileWriter.TextBox Box18 = null;
                        PdfFileWriter.TextBox Box19 = null;
                        PdfFileWriter.TextBox Box20 = null;
                        PdfFileWriter.TextBox Box21 = null;
                       /* PdfFileWriter.TextBox Box22 = null;
                        PdfFileWriter.TextBox Box23 = null;
                        PdfFileWriter.TextBox Box24 = null;
                        PdfFileWriter.TextBox Box25 = null;
                        PdfFileWriter.TextBox Box26 = null;
                        PdfFileWriter.TextBox Box27 = null;
                        PdfFileWriter.TextBox Box28 = null;
                        PdfFileWriter.TextBox Box29 = null;
                        PdfFileWriter.TextBox Box30 = null;
                        PdfFileWriter.TextBox Box31 = null;
                        PdfFileWriter.TextBox Box32 = null;
                        PdfFileWriter.TextBox Box33 = null;
                        PdfFileWriter.TextBox Box34 = null;
                        PdfFileWriter.TextBox Box35 = null;
                        PdfFileWriter.TextBox Box36 = null;
                        PdfFileWriter.TextBox Box37 = null;
                        PdfFileWriter.TextBox Box38 = null;
                        PdfFileWriter.TextBox Box39 = null;
                        PdfFileWriter.TextBox Box40 = null;
                        PdfFileWriter.TextBox Box41 = null;
                        */

                        double total = 0;
                        int cuantosPorPagina = 30;
                        int cuantosVamos = 0;
                        int numeroDePagina = 0;
                        while (reader.Read())
                        {
                            String JRNAL_NO = Convert.ToString(reader.GetInt32(0)).Trim();
                            String JRNAL_LINE = Convert.ToString(reader.GetInt32(1)).Trim();
                            String TRANS_DATETIME = reader.GetDateTime(5).ToString().Substring(0, 10);

                            String PERIOD = Convert.ToString(reader.GetInt32(3));

                            String JRNAL_SRCE = reader.GetString(4).Trim();

                            String ALLOCATION = reader.GetString(6).Trim();

                            String D_C = reader.GetString(7).Trim();
                            String AMOUNT_SUNPLUS = Convert.ToString( Math.Abs(Convert.ToDouble(reader.GetDecimal(2))) ).Trim();
                            if(D_C.Equals("D"))//debito
                            {
                                total += Math.Abs(Convert.ToDouble(reader.GetDecimal(2)));
                            }
                            else//creditos
                            {
                                total -= Math.Abs(Convert.ToDouble(reader.GetDecimal(2)));
                            }
                            String ANAL_T0 = reader.GetString(9).Trim();
                            String ANAL_T1 = reader.GetString(10).Trim();
                            String ANAL_T2 = reader.GetString(11).Trim();
                            String ANAL_T3 = reader.GetString(12).Trim();
                            String ANAL_T4 = reader.GetString(13).Trim();
                            String ANAL_T5 = reader.GetString(14).Trim();
                            String ANAL_T6 = reader.GetString(15).Trim();
                            String ANAL_T7 = reader.GetString(16).Trim();
                            String ANAL_T8 = reader.GetString(17).Trim();
                            String ANAL_T9 = reader.GetString(18).Trim();
                            if (cuantosVamos<cuantosPorPagina)
                            {
                                cuantosVamos++;
                            }
                            else
                            {
                                Double PosY = Height;
                                numeroDePagina++;
                               // Document.Add

                                switch(numeroDePagina)
                                {
                                    case 1:
                                        Box0.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents0.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box0);
                                        Contents0.SaveGraphicsState();
                                        Contents0.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page1 = new PdfPage(Document);
                                        Contents1 = new PdfContents(Page1);
                                        Box1 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 2:
                                        Box1.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents1.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box1);
                                        Contents1.SaveGraphicsState();
                                        Contents1.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page2 = new PdfPage(Document);
                                        Contents2 = new PdfContents(Page2);
                                        Box2 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 3:
                                        Box2.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents2.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box2);
                                        Contents2.SaveGraphicsState();
                                        Contents2.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page3 = new PdfPage(Document);
                                        Contents3 = new PdfContents(Page3);
                                        Box3 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 4:
                                        Box3.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents3.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box3);
                                        Contents3.SaveGraphicsState();
                                        Contents3.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page4 = new PdfPage(Document);
                                        Contents4 = new PdfContents(Page4);
                                        Box4 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 5:
                                        Box4.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents4.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box4);
                                        Contents4.SaveGraphicsState();
                                        Contents4.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page5 = new PdfPage(Document);
                                        Contents5 = new PdfContents(Page5);
                                        Box5 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 6:
                                        Box5.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents5.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box5);
                                        Contents5.SaveGraphicsState();
                                        Contents5.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page6 = new PdfPage(Document);
                                        Contents6 = new PdfContents(Page6);
                                        Box6 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 7:
                                        Box6.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents6.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box6);
                                        Contents6.SaveGraphicsState();
                                        Contents6.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page7 = new PdfPage(Document);
                                        Contents7 = new PdfContents(Page7);
                                        Box7 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 8:
                                        Box7.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents7.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box7);
                                        Contents7.SaveGraphicsState();
                                        Contents7.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page8 = new PdfPage(Document);
                                        Contents8 = new PdfContents(Page8);
                                        Box8 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 9:
                                        Box8.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents8.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box8);
                                        Contents8.SaveGraphicsState();
                                        Contents8.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page9 = new PdfPage(Document);
                                        Contents9 = new PdfContents(Page9);
                                        Box9 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 10:
                                        Box9.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents9.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box9);
                                        Contents9.SaveGraphicsState();
                                        Contents9.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page10 = new PdfPage(Document);
                                        Contents10 = new PdfContents(Page10);
                                        Box10 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 11:
                                        Box10.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents10.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box10);
                                        Contents10.SaveGraphicsState();
                                        Contents10.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page11 = new PdfPage(Document);
                                        Contents11 = new PdfContents(Page11);
                                        Box11 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 12:
                                        Box11.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents11.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box11);
                                        Contents11.SaveGraphicsState();
                                        Contents11.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page12 = new PdfPage(Document);
                                        Contents12 = new PdfContents(Page12);
                                        Box12 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 13:
                                        Box12.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents12.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box12);
                                        Contents12.SaveGraphicsState();
                                        Contents12.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page13 = new PdfPage(Document);
                                        Contents13 = new PdfContents(Page13);
                                        Box13 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 14:
                                        Box13.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents13.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box13);
                                        Contents13.SaveGraphicsState();
                                        Contents13.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page14 = new PdfPage(Document);
                                        Contents14 = new PdfContents(Page14);
                                        Box14 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 15:
                                        Box14.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents14.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box14);
                                        Contents14.SaveGraphicsState();
                                        Contents14.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page15 = new PdfPage(Document);
                                        Contents15 = new PdfContents(Page15);
                                        Box15 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 16:
                                        Box15.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents15.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box15);
                                        Contents15.SaveGraphicsState();
                                        Contents15.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page16 = new PdfPage(Document);
                                        Contents16 = new PdfContents(Page16);
                                        Box16 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 17:
                                        Box16.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents16.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box16);
                                        Contents16.SaveGraphicsState();
                                        Contents16.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page17 = new PdfPage(Document);
                                        Contents17 = new PdfContents(Page17);
                                        Box17 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 18:
                                        Box17.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents17.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box17);
                                        Contents17.SaveGraphicsState();
                                        Contents17.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page18 = new PdfPage(Document);
                                        Contents18 = new PdfContents(Page18);
                                        Box18 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 19:
                                        Box18.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents18.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box18);
                                        Contents18.SaveGraphicsState();
                                        Contents18.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page19 = new PdfPage(Document);
                                        Contents19 = new PdfContents(Page19);
                                        Box19 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 20:
                                        Box19.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents19.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box19);
                                        Contents19.SaveGraphicsState();
                                        Contents19.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page20 = new PdfPage(Document);
                                        Contents20 = new PdfContents(Page20);
                                        Box20 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;
                                    case 21:
                                        Box20.AddText(ArialNormal, 14.0,
                                        lineas.ToString() + "\n");
                                        Contents20.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box20);
                                        Contents20.SaveGraphicsState();
                                        Contents20.RestoreGraphicsState();
                                        lineas = new StringBuilder("");
                                        cuantosVamos = 0;
                                        Page21 = new PdfPage(Document);
                                        Contents21 = new PdfContents(Page21);
                                        Box21 = new PdfFileWriter.TextBox(Width, 0.25);
                                    break;

                                }

                            }
                            lineas.Append("" + PERIOD + "-" + JRNAL_NO + "-" + JRNAL_LINE + "-" + TRANS_DATETIME + " $" + AMOUNT_SUNPLUS + " - " + JRNAL_SRCE + "\n");
                        }

                        Document.CreateFile();
                        System.Diagnostics.Process.Start(FileName);

                        System.Windows.Forms.MessageBox.Show("al parecer, todo bien", "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates new instantce of PdfDocument
        /// </summary>
        /// <param name="width">Width of the page</param>
        /// <param name="height">HeightOf the page</param>
        /// <param name="overrideCzechLetters">If true - czech letters are overriden to english.</param>
        /// <returns>PdfDocument object</returns>
        public PdfDocument CreateDocument(double width, double height, bool overrideCzechLetters=false)
        {
            _overrideCzechLetters = overrideCzechLetters;
            Height = height;
            Width = width;
            _PDF = new PdfDocument(width, height, UnitOfMeasure.mm);

            _page = new PdfPage(_PDF, PaperType.A4, false);

            _font = new PdfFont(_PDF, "Arial", FontStyle.Regular, true);

            Contents = new PdfContents(_page);

            return _PDF;
        }
        private void GeneratePdfHeader()
        {
            Log.Write(LogLevel.Info, string.Format("Wpisywanie podstawowych informacji o sieci"));
            mTimesNormal = new PdfFont(mDocument, "Times New Roman", FontStyle.Regular);
            mTimesBold = new PdfFont(mDocument, "Times New Roman", FontStyle.Bold);

            var page = new PdfPage(mDocument);
            var contents = new PdfContents(page);

            contents.DrawText(mTimesNormal, 22.0, 10, 26, TextJustify.Center, "Raport");
            contents.DrawText(mTimesNormal, 18.0, 10, 25, TextJustify.Center, "z zaprojektowanej bezprzewodowej sieci sensorowej");
            DrawGeneralNetworkInfo(contents);

            contents.CommitToPdfFile(false);
        }
        public void ReportNodeTechnology()
        {
            var page = new PdfPage(mDocument);
            var contents = new PdfContents(page);

            var constraints = mNodeNetwork.Constraints;

            contents.DrawText(mTimesNormal, 14.0, 10, 26, TextJustify.Center, "Informacje o ograniczeniach narzucanych przez wybrany typ węzła");
            contents.DrawText(mTimesNormal, 12.0, 1.5, 24, TextJustify.Left, string.Format("Ograniczenia częstotliwości: {0}-{1} {2}", constraints.FrequencyConstraint.Min, constraints.FrequencyConstraint.Max, constraints.FrequencyConstraint.Metric));
            contents.DrawText(mTimesNormal, 12.0, 1.5, 23.5, TextJustify.Left, string.Format("Ograniczenia mocy sygnału nadawanego: {0}-{1} dBm", constraints.SignalStrengthConstraint.Min, constraints.SignalStrengthConstraint.Max));
            contents.DrawText(mTimesNormal, 12.0, 1.5, 23, TextJustify.Left, string.Format("Ograniczenia czułości: ({0})-({1}) dBm", constraints.SensitivityConstraint.Min, constraints.SensitivityConstraint.Max));
            contents.DrawText(mTimesNormal, 12.0, 1.5, 22.5, TextJustify.Left, string.Format("Ograniczenia zysku: {0}-{1} dBi", constraints.GainConstraint.Min, constraints.GainConstraint.Max));
            contents.DrawText(mTimesNormal, 12.0, 1.5, 22, TextJustify.Left, string.Format("Ograniczenia prądu pobieranego podczas uśpienia: {0}-{1} uA", constraints.SleepCurrentConstraint.Min, constraints.SleepCurrentConstraint.Max));
            contents.DrawText(mTimesNormal, 12.0, 1.5, 21.5, TextJustify.Left, string.Format("Ograniczenia prądu pobieranego podczas nadawania: {0}-{1} mA", constraints.TxCurrentConstraint.Min, constraints.TxCurrentConstraint.Max));
            contents.DrawText(mTimesNormal, 12.0, 1.5, 21, TextJustify.Left, string.Format("Ograniczenia prądu pobieranego podczas odbioru: {0}-{1} mA", constraints.RxCurrentConstraint.Min, constraints.RxCurrentConstraint.Max));

            contents.CommitToPdfFile(false);
        }
Exemplo n.º 16
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add child bookmark
        /// </summary>
        /// <param name="Title">Bookmark title.</param>
        /// <param name="Page">Page</param>
        /// <param name="XPos">Horizontal position</param>
        /// <param name="YPos">Vertical position.</param>
        /// <param name="Zoom">Zoom factor (1.0 is 100%. 0.0 is no change from existing zoom).</param>
        /// <param name="Paint">Bookmark color.</param>
        /// <param name="TextStyle">Bookmark text style.</param>
        /// <param name="OpenEntries">Open child bookmarks attached to this one.</param>
        /// <returns>Bookmark object</returns>
        /// <remarks>
        /// Add bookmark as a child to this bookmark.
        /// This method creates a new child bookmark item attached
        /// to this parent
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfBookmark AddBookmark(
			String		Title,			// bookmark title
			PdfPage		Page,			// bookmark page
			Double		XPos,			// bookmark horizontal position relative to bottom left corner of the page
			Double		YPos,			// bookmark vertical position relative to bottom left corner of the page
			Double		Zoom,			// Zoom factor. 1.0 is 100%. 0.0 is no change from existing zoom.
			Color		Paint,			// bookmark color
			TextStyle	TextStyle,		// bookmark text style: normal, bold, italic, bold-italic
			Boolean		OpenEntries		// true is display children. false hide children
			)
        {
            // create new bookmark
            PdfBookmark Bookmark = new PdfBookmark(Document, OpenEntries);

            // attach to parent
            Bookmark.Parent = this;

            // this bookmark is first child
            if(FirstChild == null)
            {
            FirstChild = Bookmark;
            LastChild = Bookmark;
            }

            // this bookmark is not first child
            else
            {
            LastChild.NextSibling = Bookmark;
            Bookmark.PrevSibling = LastChild;
            LastChild = Bookmark;
            }

            // the parent of this bookmark displays all children
            if(this.OpenEntries)
            {
            // update count
            Count++;
            for(PdfBookmark TestParent = Parent; TestParent != null && TestParent.OpenEntries; TestParent = TestParent.Parent) TestParent.Count++;
            }
            // the parent of this bookmark does not display all children
            else
            {
            Count--;
            }

            // build dictionary
            Bookmark.Dictionary.AddPdfString("/Title", Title);
            Bookmark.Dictionary.AddIndirectReference("/Parent", this);
            Bookmark.Dictionary.AddFormat("/Dest", "[{0} 0 R /XYZ {1} {2} {3}]", Page.ObjectNumber, ToPt(XPos), ToPt(YPos), (Single) Zoom);
            if(Paint != Color.Empty)
            Bookmark.Dictionary.AddFormat("/C", "[{0} {1} {2}]",  Round((Double) Paint.R / 255.0), Round((Double) Paint.G / 255.0), Round((Double) Paint.B / 255.0));
            if(TextStyle != TextStyle.Normal)
            Bookmark.Dictionary.AddInteger("/F", (Int32) TextStyle);
            return(Bookmark);
        }
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add pages to PDF document
        /// </summary>
        /// <remarks>
        /// The PrintDoc.Print method will call BeginPrint method,
        /// next it will call multiple times PrintPage method and finally
        /// it will call EndPrint method. 
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void AddPagesToPdfDocument()
        {
            // print the document by calling BeginPrint, PrintPage multiple times and finally EndPrint
            Print();

            // get printing results in the form of array of images one per page
            // image format is Metafile
            PreviewPageInfo[] PageInfo = ((PreviewPrintController) PrintController).GetPreviewPageInfo();

            // page size in user units
            Double PageWidth = Document.PageSize.Width / Document.ScaleFactor;
            Double PageHeight = Document.PageSize.Height / Document.ScaleFactor;

            // define empty image source rectangle
            Rectangle SourceRect = new Rectangle();

            // add pages to pdf document
            for(Int32 ImageIndex = 0; ImageIndex < PageInfo.Length; ImageIndex++)
            {
            // add page to document
            PdfPage Page = new PdfPage(Document);

            // add contents to the page
            PdfContents Contents = new PdfContents(Page);

            // page image
            Image PageImage = PageInfo[ImageIndex].Image;

            // no crop
            if(CropRect.IsEmpty)
                {
                // convert metafile image to PdfImage
                PdfImage Image = new PdfImage(Contents.Document, PageImage, Resolution);

                // draw the image
                Contents.DrawImage(Image, 0.0, 0.0, PageWidth, PageHeight);
                }

            // crop
            else
                {
                Int32 ImageWidth = PageImage.Width;
                Int32 ImageHeight = PageImage.Height;
                SourceRect.X = (Int32) (ImageWidth * CropRect.X / PageWidth + 0.5);
                SourceRect.Y = (Int32) (ImageHeight * CropRect.Y / PageHeight + 0.5);
                SourceRect.Width = (Int32) (ImageWidth * CropRect.Width / PageWidth + 0.5);
                SourceRect.Height = (Int32) (ImageHeight * CropRect.Height / PageHeight + 0.5);

                // convert metafile image to PdfImage
                PdfImage PdfPageImage = new PdfImage(Contents.Document, PageImage, SourceRect, Resolution);

                // draw the image
                Contents.DrawImage(PdfPageImage, CropRect.X, PageHeight - CropRect.Y - CropRect.Height, CropRect.Width, CropRect.Height);
                }
            }
            return;
        }
Exemplo n.º 18
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add child bookmark
        /// </summary>
        /// <param name="Title">Bookmark title.</param>
        /// <param name="Page">Page</param>
        /// <param name="XPos">Horizontal position</param>
        /// <param name="YPos">Vertical position.</param>
        /// <param name="Zoom">Zoom factor (1.0 is 100%. 0.0 is no change from existing zoom).</param>
        /// <param name="Paint">Bookmark color.</param>
        /// <param name="TextStyle">Bookmark text style.</param>
        /// <param name="OpenEntries">Open child bookmarks attached to this one.</param>
        /// <returns>Bookmark object</returns>
        /// <remarks>
        /// Add bookmark as a child to this bookmark.
        /// This method creates a new child bookmark item attached
        /// to this parent
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public PdfBookmark AddBookmark
        (
            string Title,                                       // bookmark title
            PdfPage Page,                                       // bookmark page
            double XPos,                                        // bookmark horizontal position relative to bottom left corner of the page
            double YPos,                                        // bookmark vertical position relative to bottom left corner of the page
            double Zoom,                                        // Zoom factor. 1.0 is 100%. 0.0 is no change from existing zoom.
            Color Paint,                                        // bookmark color
            TextStyle TextStyle,                                // bookmark text style: normal, bold, italic, bold-italic
            bool OpenEntries                                    // true is display children. false hide children
        )
        {
            // create new bookmark
            PdfBookmark Bookmark = new PdfBookmark(Document, OpenEntries);

            // attach to parent
            Bookmark.Parent = this;

            // this bookmark is first child
            if (FirstChild == null)
            {
                FirstChild = Bookmark;
                LastChild  = Bookmark;
            }

            // this bookmark is not first child
            else
            {
                LastChild.NextSibling = Bookmark;
                Bookmark.PrevSibling  = LastChild;
                LastChild             = Bookmark;
            }

            // the parent of this bookmark displays all children
            if (this.OpenEntries)
            {
                // update count
                Count++;
                for (PdfBookmark TestParent = Parent; TestParent != null && TestParent.OpenEntries; TestParent = TestParent.Parent)
                {
                    TestParent.Count++;
                }
            }
            // the parent of this bookmark does not display all children
            else
            {
                Count--;
            }

            // build dictionary
            Bookmark.Dictionary.AddPdfString("/Title", Title);
            Bookmark.Dictionary.AddIndirectReference("/Parent", this);
            Bookmark.Dictionary.AddFormat("/Dest", "[{0} 0 R /XYZ {1} {2} {3}]", Page.ObjectNumber, ToPt(XPos), ToPt(YPos), Round(Zoom));
            if (Paint != Color.Empty)
            {
                Bookmark.Dictionary.AddFormat("/C", "[{0} {1} {2}]", Round((double)Paint.R / 255.0), Round((double)Paint.G / 255.0), Round((double)Paint.B / 255.0));
            }
            if (TextStyle != TextStyle.Normal)
            {
                Bookmark.Dictionary.AddInteger("/F", (int)TextStyle);
            }
            return(Bookmark);
        }
        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;
        }
Exemplo n.º 20
0
        private void WebView_DownloadCompleted(object sender, DownloadEventArgs e)
        {
            try
            {
                if (this.Cancelar)
                {
                    this.Cursor = System.Windows.Forms.Cursors.Arrow;
                    this.webControl1.Cursor = System.Windows.Forms.Cursors.Arrow;
                //    Mensaje.MostrarMensaje(Constantes.TipoMensaje.Detenido, "Descarga", "Proceso cancelado por el usuario");
                }
                else
                {
                    DownloadItem archivoXML = e.Item;

                    String full = archivoXML.FullPath;
                    if (new FileInfo(full).Length == 0)
                    {
                        // empty
                        System.Windows.Forms.Clipboard.SetText("archivo vacio");

                        this.cuantosNoSeInsertaron++;

                    }
                    else
                    {
                        String[] fullArray = full.Split('\\');
                        String nombreDelArchivo = fullArray.Last();

                        XmlDocument doc = new XmlDocument();
                        doc.Load(full);
                        XmlNodeList titles = doc.GetElementsByTagName("tfd:TimbreFiscalDigital");
                        XmlNode obj = titles.Item(0);

                        String noCertificadoSAT = "";
                        bool isNoCertificado = obj.Attributes["noCertificadoSAT"] != null;
                        if (isNoCertificado)
                        {
                            noCertificadoSAT = obj.Attributes["noCertificadoSAT"].InnerText;
                        }

                        String selloCFD = "";
                        bool isselloCFD = obj.Attributes["selloCFD"] != null;
                        if (isselloCFD)
                        {
                            selloCFD = obj.Attributes["selloCFD"].InnerText;
                        }

                        String selloSAT = "";
                        bool isselloSAT = obj.Attributes["selloSAT"] != null;
                        if (isselloSAT)
                        {
                            selloSAT = obj.Attributes["selloSAT"].InnerText;
                        }

                        String folio_fiscal = obj.Attributes["UUID"].InnerText;
                        folio_fiscal = folio_fiscal.ToUpper();

                        XmlNodeList titlesx = doc.GetElementsByTagName("cfdi:Receptor");
                        if (titlesx.Count == 0)
                        {
                            titlesx = doc.GetElementsByTagName("Receptor");
                        }

                        XmlNode objx = titlesx.Item(0);
                        String rfcReceptor = "";
                        String nombreReceptor = "";
                        bool isRFCrfcReceptor = objx.Attributes["rfc"] != null;
                        if (isRFCrfcReceptor)
                        {
                            rfcReceptor = objx.Attributes["rfc"].InnerText.Trim();
                        }
                        bool isRFCNombreReceptor = objx.Attributes["nombre"] != null;
                        if (isRFCNombreReceptor)
                        {
                            nombreReceptor = objx.Attributes["nombre"].InnerText;
                        }

                        XmlNodeList titles1 = doc.GetElementsByTagName("cfdi:Emisor");
                        if (titles1.Count == 0)
                        {
                            titles1 = doc.GetElementsByTagName("Emisor");
                        }

                        XmlNode obj1 = titles1.Item(0);
                        String rfc = "";
                        bool isRFC = obj1.Attributes["rfc"] != null;
                        if (isRFC)
                        {
                            rfc = obj1.Attributes["rfc"].InnerText.Trim();
                        }
                        //revisar que el RFC coincida , por lo menos uno de los 2
                        if (!rfc.Equals(Properties.Settings.Default.RFC))
                        {
                            if (!rfcReceptor.Equals(Properties.Settings.Default.RFC))
                            {
                                return;//naranjas
                            }
                        }

                        String razon = "";
                        bool isRazon = obj1.Attributes["nombre"] != null;
                        if (isRazon)
                        {
                            razon = obj1.Attributes["nombre"].InnerText;
                            razon = razon.Replace('\'', ' ');
                        }

                        XmlNodeList titles2 = doc.GetElementsByTagName("cfdi:Comprobante");
                        if (titles2.Count == 0)
                        {
                            titles2 = doc.GetElementsByTagName("Comprobante");
                        }

                        XmlNode obj2 = titles2.Item(0);

                        XmlNodeList titlesY = doc.GetElementsByTagName("cfdi:DomicilioFiscal");
                        if (titlesY.Count == 0)
                        {
                            titlesY = doc.GetElementsByTagName("DomicilioFiscal");
                        }
                        String calle = "";
                        String noExterior = "";
                        String colonia = "";
                        String municipio = "";
                        String estado = "";

                        if (titlesY.Count > 0)
                        {
                            XmlNode objY = titlesY.Item(0);
                            bool isCalle = objY.Attributes["calle"] != null;
                            if (isCalle)
                            {
                                calle = objY.Attributes["calle"].InnerText;
                            }

                            bool isnoExterior = objY.Attributes["noExterior"] != null;
                            if (isnoExterior)
                            {
                                noExterior = objY.Attributes["noExterior"].InnerText;
                            }

                            bool iscolonia = objY.Attributes["colonia"] != null;
                            if (iscolonia)
                            {
                                colonia = objY.Attributes["colonia"].InnerText;
                            }

                            bool ismunicipio = objY.Attributes["municipio"] != null;
                            if (ismunicipio)
                            {
                                municipio = objY.Attributes["municipio"].InnerText;
                            }

                            bool isestado = objY.Attributes["estado"] != null;
                            if (isestado)
                            {
                                estado = objY.Attributes["estado"].InnerText;
                            }
                        }

                        XmlNodeList titles4 = doc.GetElementsByTagName("cfdi:Impuestos");
                        if (titles4.Count == 0)
                        {
                            titles4 = doc.GetElementsByTagName("Impuestos");
                        }

                        XmlNode obj4 = titles4.Item(0);

                        String iva = "0";
                        bool isIva = obj4.Attributes["totalImpuestosTrasladados"] != null;
                        if (isIva)
                        {
                            iva = obj4.Attributes["totalImpuestosTrasladados"].InnerText;
                        }
                        else
                        {
                            XmlNodeList traslados = doc.GetElementsByTagName("cfdi:Traslado");
                            if (traslados.Count == 0)
                            {
                                traslados = doc.GetElementsByTagName("Traslado");
                            }
                            int i;
                            for (i = 0; i < traslados.Count; i++)
                            {
                                XmlNode objn = traslados.Item(i);
                                String cantidad = "0";
                                bool isCantidad = objn.Attributes["importe"] != null;
                                if (isCantidad)
                                {
                                    cantidad = objn.Attributes["importe"].InnerText;
                                }
                                iva = Convert.ToString(float.Parse(iva) + float.Parse(cantidad));
                            }
                        }

                        String subTotal = "";
                        bool isSubTotal = obj2.Attributes["subTotal"] != null;
                        if (isSubTotal)
                        {
                            subTotal = obj2.Attributes["subTotal"].InnerText;
                        }

                        String tipoDeComprobante = "INGRESO";
                        bool istipoDeComprobante = obj2.Attributes["tipoDeComprobante"] != null;
                        if (istipoDeComprobante)
                        {
                            tipoDeComprobante = obj2.Attributes["tipoDeComprobante"].InnerText.Trim().ToUpper();
                        }

                        String total = "";
                        bool isTotal = obj2.Attributes["total"] != null;
                        if (isTotal)
                        {
                            total = obj2.Attributes["total"].InnerText;
                        }

                        bool isFecha = obj2.Attributes["fecha"] != null;
                        String fecha = "";
                        if (isFecha)
                        {
                            fecha = obj2.Attributes["fecha"].InnerText;
                        }
                        bool isFolio = obj2.Attributes["folio"] != null;
                        String folio = "";
                        if (isFolio)
                        {
                            folio = obj2.Attributes["folio"].InnerText;
                        }
                        if (estoyEnCancelados)
                        {
                            String query1 = "UPDATE [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] set STATUS = '0' WHERE folioFiscal = '" + folio_fiscal + "'";
                            totalDeCancelados++;
                            try
                            {
                                using (SqlConnection connection = new SqlConnection(connString))
                                {
                                    connection.Open();
                                    SqlCommand cmd = new SqlCommand(query1, connection);
                                    cmd.ExecuteNonQuery();

                                    String queryCheck1 = "SELECT BUNIT, JRNAL_NO, JRNAL_LINE, CONCEPTO, FUNCION, PROJECT, descripcionLI, AMOUNT, Consecutivo, FOLIO_FISCAL FROM [" + Properties.Settings.Default.Database + "].[dbo].[FISCAL_xml] WHERE folioFiscal = '" + folio_fiscal + "'";
                                    SqlCommand cmdCheck = new SqlCommand(queryCheck1, connection);
                                    SqlDataReader reader = cmdCheck.ExecuteReader();

                                    if (reader.HasRows)
                                    {
                                        String BUNIT = "";
                                        String JRNAL_NO = "";
                                        String JRNAL_LINE = "";
                                        String CONCEPTO = "";
                                        String FUNCION = "";
                                        String PROJECT = "";
                                        String descripcionLI = "";
                                        String AMOUNT = "";
                                        String Consecutivo = "";
                                        String FOLIO_FISCAL = "";
                                        mensajeParaElCorreo.Append(this.Enters + "Los cancelados estan ligados a los siguientes movimientos: ");
                                        while (reader.Read())
                                        {
                                            BUNIT = reader.GetString(0).Trim();
                                            JRNAL_NO = Convert.ToString(reader.GetInt32(1));
                                            JRNAL_LINE = Convert.ToString(reader.GetInt32(2));
                                            CONCEPTO = reader.GetString(3).Trim();
                                            FUNCION = reader.GetString(4).Trim();
                                            PROJECT = reader.GetString(5).Trim();
                                            descripcionLI = reader.GetString(6).Trim();
                                            AMOUNT = Convert.ToString(reader.GetDecimal(7));
                                            Consecutivo = reader.GetString(8).Trim();
                                            FOLIO_FISCAL = reader.GetString(9).Trim();

                                            mensajeParaElCorreo.Append(this.Enters + BUNIT + " " + JRNAL_NO + " " + JRNAL_LINE + " " + CONCEPTO + " " + FUNCION + " " + PROJECT + " " + descripcionLI + " " + AMOUNT + " " + FOLIO_FISCAL + " " + Consecutivo);

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

                        }
                        else
                        {

                            String query = "";
                            int STATUS = -1;
                            if (this.AnoSel.IndexOf("Emitidos") != -1)
                            {
                                if (tipoDeComprobante.Equals("INGRESO"))
                                {
                                    STATUS = 2;
                                    query = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] (folioFiscal,nombreArchivoXML,ruta,rfc,razonSocial,total,folio,fechaExpedicion,nombreArchivoPDF,STATUS,ocultaEnLigar,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + nombreDelArchivo + "', '" + carpeta.Text + (object)Path.DirectorySeparatorChar + this.AnoSel + (object)Path.DirectorySeparatorChar + this.MesSel + (object)Path.DirectorySeparatorChar + diaActual + "', '" + rfcReceptor + "', '" + nombreReceptor + "', " + total + ", '" + folio + "' , '" + fecha + "', '" + folio_fiscal + ".pdf','2',0,'" + Properties.Settings.Default.RFC + "')";
                                }
                                else
                                {
                                    STATUS = 1;
                                    query = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] (folioFiscal,nombreArchivoXML,ruta,rfc,razonSocial,total,folio,fechaExpedicion,nombreArchivoPDF,STATUS,ocultaEnLigar,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + nombreDelArchivo + "', '" + carpeta.Text + (object)Path.DirectorySeparatorChar + this.AnoSel + (object)Path.DirectorySeparatorChar + this.MesSel + (object)Path.DirectorySeparatorChar + diaActual + "', '" + rfcReceptor + "', '" + nombreReceptor + "', " + total + ", '" + folio + "' , '" + fecha + "', '" + folio_fiscal + ".pdf','1',0,'" + Properties.Settings.Default.RFC + "')";
                                }
                                insertaProveedor(rfcReceptor, nombreReceptor);
                                sincroniza(fecha, rfcReceptor, nombreReceptor, STATUS, total, folio, folio_fiscal, Properties.Settings.Default.RFC, "");
                            }
                            else
                            {
                                if (tipoDeComprobante.Equals("INGRESO"))
                                {
                                    STATUS = 1;
                                    query = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] (folioFiscal,nombreArchivoXML,ruta,rfc,razonSocial,total,folio,fechaExpedicion,nombreArchivoPDF,STATUS,ocultaEnLigar,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + nombreDelArchivo + "', '" + carpeta.Text + (object)Path.DirectorySeparatorChar + this.AnoSel + (object)Path.DirectorySeparatorChar + this.MesSel + (object)Path.DirectorySeparatorChar + diaActual + "', '" + rfc + "', '" + razon + "', " + total + ", '" + folio + "' , '" + fecha + "', '" + folio_fiscal + ".pdf','1',0,'" + Properties.Settings.Default.RFC + "')";
                                }
                                else
                                {
                                    STATUS = 2;
                                    query = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] (folioFiscal,nombreArchivoXML,ruta,rfc,razonSocial,total,folio,fechaExpedicion,nombreArchivoPDF,STATUS,ocultaEnLigar,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + nombreDelArchivo + "', '" + carpeta.Text + (object)Path.DirectorySeparatorChar + this.AnoSel + (object)Path.DirectorySeparatorChar + this.MesSel + (object)Path.DirectorySeparatorChar + diaActual + "', '" + rfc + "', '" + razon + "', " + total + ", '" + folio + "' , '" + fecha + "', '" + folio_fiscal + ".pdf','2',0,'" + Properties.Settings.Default.RFC + "')";
                                }
                                //query = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] (folioFiscal,nombreArchivoXML,ruta,rfc,razonSocial,total,folio,fechaExpedicion,nombreArchivoPDF,STATUS,ocultaEnLigar) VALUES ('" + folio_fiscal + "', '" + nombreDelArchivo + "', '" + carpeta.Text + (object)Path.DirectorySeparatorChar + this.AnoSel + (object)Path.DirectorySeparatorChar + this.MesSel + (object)Path.DirectorySeparatorChar + diaActual + "', '" + rfc + "', '" + razon + "', " + total + ", '" + folio + "' , '" + fecha + "', '" + folio_fiscal + ".pdf','1',0)";
                                insertaProveedor(rfc, razon);
                                sincroniza(fecha, rfc,  razon,  STATUS,  total,  folio,  folio_fiscal, Properties.Settings.Default.RFC, "");
                            }
                            String queryCheck = "SELECT * FROM [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] WHERE folioFiscal = '" + folio_fiscal + "'";

                            try
                            {
                                using (SqlConnection connection = new SqlConnection(connString))
                                {
                                    connection.Open();
                                    SqlCommand cmdCheck = new SqlCommand(queryCheck, connection);
                                    SqlDataReader reader = cmdCheck.ExecuteReader();
                                    if (!reader.Read())
                                    {
                                        reader.Close();
                                        connection.Close();
                                        connection.Open();
                                        SqlCommand cmd = new SqlCommand(query, connection);
                                        cmd.ExecuteNonQuery();
                                        PdfContents Contents = null;
                                        PdfPage Page = null;
                                        const Double Width = 5.15;
                                        const Double Height = 10.65;
                                        const Double FontSize = 9.0;
                                        PdfFileWriter.TextBox Box = null;
                                        if (cadaCuantasHorasGlobal == 0 || 1 == 1)//no estoy en modo de horas
                                        {
                                            String FileName = carpeta.Text + (object)Path.DirectorySeparatorChar + this.AnoSel + (object)Path.DirectorySeparatorChar + this.MesSel + (object)Path.DirectorySeparatorChar + diaActual.ToString() + (object)Path.DirectorySeparatorChar + folio_fiscal + ".pdf";
                                            Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);
                                            DefineFontResources();
                                            DefineTilingPatternResource();
                                            Page = new PdfPage(Document);
                                            Contents = new PdfContents(Page);
                                            Contents.SaveGraphicsState();
                                            Contents.Translate(0.1, 0.1);
                                            Box = new PdfFileWriter.TextBox(Width, 0.25);
                                        }
                                        XmlNodeList conceptos = doc.GetElementsByTagName("cfdi:Concepto");
                                        if (conceptos.Count == 0)
                                        {
                                            conceptos = doc.GetElementsByTagName("Concepto");
                                        }

                                        int i;
                                        String conceptosString = "";
                                        for (i = 0; i < conceptos.Count; i++)
                                        {
                                            XmlNode objy = conceptos.Item(i);
                                            String cantidadc = "";
                                            bool isCantidadc = objy.Attributes["cantidad"] != null;
                                            if (isCantidadc)
                                            {
                                                cantidadc = objy.Attributes["cantidad"].InnerText;
                                            }
                                            String unidadc = "";
                                            bool isUnidadc = objy.Attributes["unidad"] != null;
                                            if (isUnidadc)
                                            {
                                                unidadc = objy.Attributes["unidad"].InnerText;
                                            }
                                            String descripcionc = "";
                                            bool isdescripcionc = objy.Attributes["descripcion"] != null;
                                            if (isdescripcionc)
                                            {
                                                descripcionc = objy.Attributes["descripcion"].InnerText;
                                            }
                                            String importec = "";
                                            bool isimportec = objy.Attributes["importe"] != null;
                                            if (isimportec)
                                            {
                                                importec = objy.Attributes["importe"].InnerText;
                                            }
                                            conceptosString = conceptosString + "\n" + cantidadc + " " + descripcionc + " $" + importec;
                                        }
                                        String impuestosString = "";
                                        double totalDeRetenciones = 0;
                                        XmlNodeList retencionesLocales = doc.GetElementsByTagName("implocal:RetencionesLocales");
                                        if (retencionesLocales.Count == 0)
                                        {
                                            retencionesLocales = doc.GetElementsByTagName("RetencionesLocales");
                                        }
                                        for (i = 0; i < retencionesLocales.Count; i++)
                                        {
                                            XmlNode objn = retencionesLocales.Item(i);
                                            String cantidad = "0";
                                            String impuesto = "";
                                            float tasa = 0;
                                            bool isCantidad = objn.Attributes["Importe"] != null;
                                            if (isCantidad)
                                            {
                                                totalDeRetenciones += Convert.ToDouble(objn.Attributes["Importe"].InnerText);
                                                cantidad = objn.Attributes["Importe"].InnerText;
                                                impuesto = objn.Attributes["ImpLocRetenido"].InnerText;
                                                tasa = float.Parse(objn.Attributes["TasadeRetencion"].InnerText);
                                                float importe = float.Parse(cantidad);
                                                String queryCheckImpuesto = "SELECT * FROM [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] WHERE folioFiscal = '" + folio_fiscal + "' and impuesto = '" + impuesto + "' and tasa = " + tasa + " and importe = " + importe;
                                                SqlCommand cmdCheckImpuesto = new SqlCommand(queryCheckImpuesto, connection);
                                                SqlDataReader readerImpuesto = cmdCheckImpuesto.ExecuteReader();
                                                impuestosString = impuestosString + "\nImpuesto: " + impuesto + "\nTasa: " + tasa + "\nImporte: " + importe;
                                                if (!readerImpuesto.HasRows)
                                                {
                                                    readerImpuesto.Close();
                                                    String queryImpuesto = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] (folioFiscal,impuesto,tasa,importe,tipo,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + impuesto + "', " + tasa + ", " + importe + ",2,'" + Properties.Settings.Default.RFC + "')";
                                                    SqlCommand cmdImpuesto = new SqlCommand(queryImpuesto, connection);
                                                    cmdImpuesto.ExecuteNonQuery();
                                                }
                                                else
                                                {
                                                    readerImpuesto.Close();
                                                }
                                            }
                                            iva = Convert.ToString(float.Parse(iva) + float.Parse(cantidad));
                                        }

                                        XmlNodeList retenciones = doc.GetElementsByTagName("cfdi:Retencion");
                                        if (retenciones.Count == 0)
                                        {
                                            retenciones = doc.GetElementsByTagName("Retencion");
                                        }

                                        for (i = 0; i < retenciones.Count; i++)
                                        {
                                            XmlNode objn = retenciones.Item(i);
                                            String cantidad = "0";
                                            String impuesto = "";
                                            float tasa = 0;
                                            bool isCantidad = objn.Attributes["importe"] != null;
                                            if (isCantidad)
                                            {
                                                totalDeRetenciones += Convert.ToDouble(objn.Attributes["importe"].InnerText);
                                                cantidad = objn.Attributes["importe"].InnerText;
                                                impuesto = objn.Attributes["impuesto"].InnerText;
                                                tasa = 0;
                                                float importe = float.Parse(cantidad);
                                                String queryCheckImpuesto = "SELECT * FROM [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] WHERE folioFiscal = '" + folio_fiscal + "' and impuesto = '" + impuesto + "' and tasa = " + tasa + " and importe = " + importe;
                                                SqlCommand cmdCheckImpuesto = new SqlCommand(queryCheckImpuesto, connection);
                                                SqlDataReader readerImpuesto = cmdCheckImpuesto.ExecuteReader();
                                                impuestosString = impuestosString + "\nImpuesto: " + impuesto + "\nImporte: " + importe;
                                                if (!readerImpuesto.HasRows)
                                                {
                                                    readerImpuesto.Close();
                                                    String queryImpuesto = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] (folioFiscal,impuesto,tasa,importe,tipo,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + impuesto + "', " + tasa + ", " + importe + ",2,'" + Properties.Settings.Default.RFC + "')";
                                                    SqlCommand cmdImpuesto = new SqlCommand(queryImpuesto, connection);
                                                    cmdImpuesto.ExecuteNonQuery();
                                                }
                                                else
                                                {
                                                    readerImpuesto.Close();
                                                }
                                            }
                                            iva = Convert.ToString(float.Parse(iva) + float.Parse(cantidad));
                                        }

                                        if (totalDeRetenciones > 0.0)
                                        {
                                            double nuevoTotal = Math.Round(totalDeRetenciones + Convert.ToDouble(total), 2);
                                            String query2 = "UPDATE [" + Properties.Settings.Default.Database + "].[dbo].[facturacion_XML] set total = " + nuevoTotal + "  WHERE folioFiscal = '" + folio_fiscal + "'";
                                            try
                                            {
                                                using (SqlCommand cmdx = new SqlCommand(query2, connection))
                                                {
                                                    cmd.ExecuteNonQuery();
                                                }
                                            }
                                            catch (Exception ex3)
                                            {
                                                ex3.ToString();
                                            }
                                        }

                                        XmlNodeList trasladosLocales = doc.GetElementsByTagName("implocal:TrasladosLocales");
                                        if (trasladosLocales.Count == 0)
                                        {
                                            trasladosLocales = doc.GetElementsByTagName("TrasladosLocales");
                                        }
                                        for (i = 0; i < trasladosLocales.Count; i++)
                                        {
                                            XmlNode objn = trasladosLocales.Item(i);
                                            String cantidad = "0";
                                            String impuesto = "";
                                            float tasa = 0;
                                            bool isCantidad = objn.Attributes["Importe"] != null;
                                            if (isCantidad)
                                            {
                                                cantidad = objn.Attributes["Importe"].InnerText;
                                                impuesto = objn.Attributes["ImpLocTrasladado"].InnerText;
                                                tasa = float.Parse(objn.Attributes["TasadeTraslado"].InnerText);
                                                float importe = float.Parse(cantidad);
                                                String queryCheckImpuesto = "SELECT * FROM [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] WHERE folioFiscal = '" + folio_fiscal + "' and impuesto = '" + impuesto + "' and tasa = " + tasa + " and importe = " + importe;
                                                SqlCommand cmdCheckImpuesto = new SqlCommand(queryCheckImpuesto, connection);
                                                SqlDataReader readerImpuesto = cmdCheckImpuesto.ExecuteReader();
                                                impuestosString = impuestosString + "\nImpuesto: " + impuesto + "\nTasa: " + tasa + "\nImporte: " + importe;
                                                if (!readerImpuesto.HasRows)
                                                {
                                                    readerImpuesto.Close();
                                                    String queryImpuesto = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] (folioFiscal,impuesto,tasa,importe,tipo,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + impuesto + "', " + tasa + ", " + importe + ",1,'" + Properties.Settings.Default.RFC + "')";
                                                    SqlCommand cmdImpuesto = new SqlCommand(queryImpuesto, connection);
                                                    cmdImpuesto.ExecuteNonQuery();
                                                }
                                                else
                                                {
                                                    readerImpuesto.Close();
                                                }
                                            }
                                            iva = Convert.ToString(float.Parse(iva) + float.Parse(cantidad));
                                        }

                                        XmlNodeList traslados = doc.GetElementsByTagName("cfdi:Traslado");
                                        if (traslados.Count == 0)
                                        {
                                            traslados = doc.GetElementsByTagName("Traslado");
                                        }
                                        for (i = 0; i < traslados.Count; i++)
                                        {
                                            XmlNode objn = traslados.Item(i);
                                            String cantidad = "0";
                                            String impuesto = "";
                                            float tasa = 0;
                                            bool isCantidad = objn.Attributes["importe"] != null;
                                            if (isCantidad)
                                            {
                                                cantidad = objn.Attributes["importe"].InnerText;
                                                impuesto = objn.Attributes["impuesto"].InnerText;
                                                tasa = float.Parse(objn.Attributes["tasa"].InnerText);
                                                float importe = float.Parse(cantidad);
                                                String queryCheckImpuesto = "SELECT * FROM [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] WHERE folioFiscal = '" + folio_fiscal + "' and impuesto = '" + impuesto + "' and tasa = " + tasa + " and importe = " + importe;
                                                SqlCommand cmdCheckImpuesto = new SqlCommand(queryCheckImpuesto, connection);
                                                SqlDataReader readerImpuesto = cmdCheckImpuesto.ExecuteReader();
                                                impuestosString = impuestosString + "\nImpuesto: " + impuesto + "\nTasa: " + tasa + "\nImporte: " + importe;
                                                if (!readerImpuesto.HasRows)
                                                {
                                                    readerImpuesto.Close();
                                                    String queryImpuesto = "INSERT INTO [" + Properties.Settings.Default.Database + "].[dbo].[impuestos] (folioFiscal,impuesto,tasa,importe,tipo,rfcRaiz) VALUES ('" + folio_fiscal + "', '" + impuesto + "', " + tasa + ", " + importe + ",1,'" + Properties.Settings.Default.RFC + "')";
                                                    SqlCommand cmdImpuesto = new SqlCommand(queryImpuesto, connection);
                                                    cmdImpuesto.ExecuteNonQuery();
                                                }
                                                else
                                                {
                                                    readerImpuesto.Close();
                                                }
                                            }
                                            iva = Convert.ToString(float.Parse(iva) + float.Parse(cantidad));
                                        }
                                        if (cadaCuantasHorasGlobal == 0 || 1 == 1)//no estoy en modo de horas
                                        {
                                            Box.AddText(ArialNormal, FontSize,
                                           "Cliente: " + nombreReceptor + "\n" +
                                           "RFC: " + rfcReceptor + "\n" +
                                           "Emisor: " + razon + "\n" +
                                           "RFC: " + rfc + "\n" +
                                           "Domicilio Fiscal: " + calle + " " + noExterior + " " + colonia + " " + municipio + " " + estado + "\n" +
                                           "Folio: " + folio + "\nFolio Fiscal: " + folio_fiscal + "\nTotal: $" + total + "\nFecha de Expedicion: " + fecha + conceptosString + impuestosString + "\nNo de Serie del Certificado del SAT: " + noCertificadoSAT + "\nSello digital del CFDI:\n" + selloCFD + "\n\nSello del SAT:\n" + selloSAT + "\n\n\nEste documento es una representación impresa de un CFDI");
                                            Box.AddText(ArialNormal, FontSize, "\n");
                                            Double PosY = Height;
                                            Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box);
                                            Contents.RestoreGraphicsState();
                                            Contents.SaveGraphicsState();
                                            String DataString = "?re=" + rfc + "&rr=" + rfcReceptor + "&tt=" + total + "&id=" + folio_fiscal;
                                            PdfQRCode QRCode = new PdfQRCode(Document, DataString, ErrorCorrection.M);
                                            Contents.DrawQRCode(QRCode, 6.0, 6.8, 1.2);
                                            Contents.RestoreGraphicsState();
                                            Document.CreateFile();
                                        }
                                        totalDeDescargados++;
                                    }
                                    else
                                    {
                                        this.cuantosYaExistian++;
                                        totalDeYaExistian++;
                                    }

                                }
                            }
                            catch (Exception ex1)
                            {
                                ex1.ToString();
                                System.Windows.Forms.Clipboard.SetText(query);

                                this.cuantosNoSeInsertaron++;
                                //   System.Windows.Forms.MessageBox.Show("Error Message", ex1.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }//else if estoyEnCancelados
                    }//else de empty

                    ++this.posicion;
                    if (this.posicion < this.ligas.Count)
                    {
                        if (!this.Cancelar)
                        {
                            this.Descargados.Add(e.Item);
                            this.proceso.Text = string.Format("Descargando {0} de {1}, Ya existian: {2}, Con errores: {3} ", (object)(this.posicion + 1), (object)this.ligas.Count.ToString() , (object)this.cuantosYaExistian, (object)this.cuantosNoSeInsertaron);
                            this.Descarga();
                        }
                        else
                        {
                            this.Cursor = System.Windows.Forms.Cursors.Arrow;
                            this.webControl1.Cursor = System.Windows.Forms.Cursors.Arrow;
                 //           Mensaje.MostrarMensaje(Constantes.TipoMensaje.Detenido, "Descarga", "Proceso cancelado por el usuario");
                        }
                    }
                    else
                    {

                        //                  enQueHoraVoyGlobal
                        //                    cadaCuantasHorasGlobal

                        int horaQueSigue = enQueHoraVoyGlobal + cadaCuantasHorasGlobal;
                        if(horaQueSigue<24 && cadaCuantasHorasGlobal!=0)//sigue con las horas
                        {
                            enQueHoraVoyGlobal = enQueHoraVoyGlobal + cadaCuantasHorasGlobal;
                            if(estoyEnEmitidos)
                            {
                                tmrDecimoCuarto.Start();
                            }
                            else
                            {
                                tmrQuintoPrimo.Start();
                            }
                        }
                        else
                        {//cambia el dia
                            enQueHoraVoyGlobal = 0;
                            //cambia un dia
                            if (modoGlobal == 2 && estoyEnEmitidos)
                            {
                                DateTime now = DateTime.Now;
                                int year = now.Year - anoAnterior;
                                int month = now.Month;
                                if (modoGlobal == 2)//ultrapesado
                                {
                                    month = mesActual + 1;
                                }

                                int diaFinal = 28;
                                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                                {
                                    diaFinal = 31;
                                }
                                else
                                {
                                    if (month == 4 || month == 6 || month == 9 || month == 11)
                                    {
                                        diaFinal = 30;
                                    }
                                    else
                                    {
                                        if (year % 4 == 0)//ano bisiesto
                                        {
                                            diaFinal = 29;
                                        }
                                    }
                                }

                                if (diaActual < diaFinal)
                                {
                                    diaActual++;
                                    tmrDecimoCuarto.Start();
                                    return;
                                }
                                else
                                {
                                    diaActual = 1;
                                    if (mesActual < 11)
                                    {
                                        mesActual++;
                                        tmrDecimoCuarto.Start();
                                        return;
                                    }
                                    else
                                    {
                                        tmrDecimoSexto.Start();
                                        return;
                                    }
                                }

                            }
                            if (modoGlobal == 1)
                            {
                                if (estoyEnEmitidos)
                                {
                                    mandaCorreo();
                                }
                                else
                                {
                                    empiezaConLosEmitidos();
                                }
                            }
                            else
                            {
                                this.proceso.Text = string.Format("Descargando {0} de {1}, Ya existian: {2}, Con errores: {3}", (object)this.posicion, (object)this.ligas.Count.ToString(), (object)this.cuantosYaExistian, (object)this.cuantosNoSeInsertaron);
                                this.Descargados.Add(e.Item);
                                this.Cursor = System.Windows.Forms.Cursors.Arrow;
                                this.webControl1.Cursor = System.Windows.Forms.Cursors.Arrow;
                                this.proceso.Text = string.Format("Descarga Finalizada {0} de {1}, Ya existian: {2}, Con errores: {3}", (object)this.posicion, (object)this.ligas.Count.ToString(), (object)this.cuantosYaExistian, (object)this.cuantosNoSeInsertaron);
                                if (estoyEnCancelados)
                                {
                                    //ya termine
                                    mensajeParaElCorreo.Append(totalDeCancelados);
                                    return;
                                }
                                if (!estoyEnCancelados && estoyEnEmitidos)
                                {
                                    //agregar para debuguear emitidos
                                    mensajeParaElCorreo.Append(Enters + Enters + "Facturas Emitidas totales: " + (object)this.ligas.Count.ToString() + " Ya existian: " + (object)this.cuantosYaExistian);
                                    tmrDecimoSexto.Start();
                                    return;
                                }
                                DateTime now = DateTime.Now;
                                int year = now.Year - anoAnterior;
                                int month = now.Month;
                                if (modoGlobal == 2)//ultrapesado
                                {
                                    month = mesActual + 1;
                                }

                                int diaFinal = 28;
                                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                                {
                                    diaFinal = 31;
                                }
                                else
                                {
                                    if (month == 4 || month == 6 || month == 9 || month == 11)
                                    {
                                        diaFinal = 30;
                                    }
                                    else
                                    {
                                        if (year % 4 == 0)//ano bisiesto
                                        {
                                            diaFinal = 29;
                                        }
                                    }
                                }

                                if (diaActual < diaFinal)
                                {
                                    diaActual++;
                                    if (estoyEnElMesAnterior)
                                    {
                                        tmrDecimo.Start();
                                    }
                                    else
                                    {
                                        if(cadaCuantasHorasGlobal==0)//sin horas
                                        {
                                            tmrQuinto.Start();
                                        }
                                        else
                                        {
                                            tmrQuintoPrimo.Start();
                                        }

                                    }
                                }
                                else
                                {
                                    if (estoyEnElMesAnterior)
                                    {
                                        estoyEnElMesAnterior = false;
                                        diaActual = 1;
                                        empiezaConLosCancelados();
                                    }
                                    else
                                    {
                                        if (modoGlobal == 2)//ultrapesado
                                        {
                                            if (mesActual < 11)
                                            {
                                                mesActual++;
                                                diaActual = 1;
                                                tmrDecimo.Start();
                                            }
                                            else
                                            {
                                                estoyEnElMesAnterior = false;
                                                diaActual = 1;
                                                mesActual = 0;
                                                empiezaConLosCancelados();
                                            }
                                        }
                                        else//modo pesado
                                        {
                                            empiezaConElMesAnterior();
                                        }
                                    }
                                }
                            }
                        }//if cambia un dia
                    }
                }
            }
            catch (Exception ex)
            {
               System.Windows.Forms.MessageBox.Show( ex.ToString(), "Error Title2", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

               //  Logs.Escribir("Error en download complete : " + ex.ToString());
            }
        }
Exemplo n.º 21
0
        ////////////////////////////////////////////////////////////////////
        // Draw Text for TextBox with web link
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw TextBox
        /// </summary>
        /// <param name="PosX">Position X</param>
        /// <param name="PosYTop">Position Y (by reference)</param>
        /// <param name="PosYBottom">Position Y bottom</param>
        /// <param name="LineNo">Start at line number</param>
        /// <param name="LineExtraSpace">Extra line spacing</param>
        /// <param name="ParagraphExtraSpace">Extra paragraph spacing</param>
        /// <param name="Justify">TextBox justify enumeration</param>
        /// <param name="TextBox">TextBox</param>
        /// <param name="Page">Page if TextBox contains web link segment</param>
        /// <returns>Next line number</returns>
        /// <remarks>
        /// Before calling this method you must add text to a TextBox object.
        /// <para>
        /// Set the PosX and PosYTop to the left top corner of the text area.
        /// Note PosYTop is by reference. This variable will be updated to
        /// the next vertical line position after the method was executed.
        /// </para>
        /// <para>
        /// Set the PosYBottom to the bottom of your page. The method will
        /// not print below this value.
        /// </para>
        /// <para>
        /// Set the LineNo to the first line to be printed. Initially 
        /// this will be zero. After the method returns, PosYTop is set 
        /// to next print line on the page and LineNo is set to next line 
        /// within the box.
        /// </para>
        /// <para>
        /// If LineNo is equals to TextBox.LineCount the box was fully printed. 
        /// </para>
        /// <para>
        /// If LineNo is less than TextBox.LineCount box printing was not
        /// done. Start a new PdfPage and associated PdfContents. Set 
        /// PosYTop to desired start position. Set LineNo to the value
        /// returned by this method, and call the method again.
        /// </para>
        /// <para>
        /// If your TextBox contains WebLink segment you must supply
        /// Page argument and position X and Y must be relative to
        /// page bottom left corner.
        /// </para>
        /// <para>
        /// TextBoxJustify controls horizontal justification. FitToWidth
        /// will display a straight right edge.
        /// </para>
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public Int32 DrawText(
			Double			PosX,
			ref Double		PosYTop,
			Double			PosYBottom,
			Int32			LineNo,
			Double			LineExtraSpace,
			Double			ParagraphExtraSpace,
			TextBoxJustify	Justify,
			TextBox			TextBox,
			PdfPage			Page = null
			)
        {
            TextBox.Terminate();
            for(; LineNo < TextBox.LineCount; LineNo++)
            {
            // short cut
            TextBoxLine Line = TextBox[LineNo];

            // break out of the loop if printing below bottom line
            if(PosYTop - Line.LineHeight < PosYBottom) break;

            // adjust PosY to font base line
            PosYTop -= Line.Ascent;

            // text horizontal position
            Double X = PosX;
            Double W = TextBox.BoxWidth;

            // if we have first line indent, adjust text x position for first line of a paragraph
            if(TextBox.FirstLineIndent != 0 && (LineNo == 0 || TextBox[LineNo - 1].EndOfParagraph))
                {
                X += TextBox.FirstLineIndent;
                W -= TextBox.FirstLineIndent;
                }

            // draw text to fit box width
            if(Justify == TextBoxJustify.FitToWidth && !Line.EndOfParagraph)
                {
                DrawText(X, PosYTop, W, Line, Page);
                }

            // draw text center or right justified
            else if(Justify == TextBoxJustify.Center || Justify == TextBoxJustify.Right)
                {
                DrawText(X, PosYTop, W, Justify, Line, Page);
                }

            // draw text normal
            else
                {
                DrawText(X, PosYTop, Line, Page);
                }

            // advance position y to next line
            PosYTop -= Line.Descent + LineExtraSpace;
            if(Line.EndOfParagraph) PosYTop -= ParagraphExtraSpace;
            }
            return(LineNo);
        }
Exemplo n.º 22
0
        /// <summary>
        /// PDF screen annotation constructor
        /// </summary>
        /// <param name="Page">Associated page</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="DisplayMedia">Display media class</param>
        public PdfAnnotation(
			PdfPage				Page,
			PdfRectangle		AnnotRect,
			PdfDisplayMedia		DisplayMedia
			)
            : base(Page.Document)
        {
            // annotation subtype
            Dictionary.Add("/Subtype", "/Screen");

            // action reference dictionary
            Dictionary.AddIndirectReference("/A", DisplayMedia);
            this.DisplayMedia = DisplayMedia;

            // add page reference
            Dictionary.AddIndirectReference("/P", Page);

            // add annotation reference
            DisplayMedia.Dictionary.AddIndirectReference("/AN", this);

            // constructor helper method
            ContructorHelper(Page, AnnotRect);

            // exit
            return;
        }
Exemplo n.º 23
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw web link with one line of text
        /// </summary>
        /// <param name="Page">Current page</param>
        /// <param name="Font">Font</param>
        /// <param name="FontSize">Font size</param>
        /// <param name="TextAbsPosX">Text absolute position X</param>
        /// <param name="TextAbsPosY">Text absolute position Y</param>
        /// <param name="Justify">Text justify enumeration.</param>
        /// <param name="DrawStyle">Draw style enumeration</param>
        /// <param name="TextColor">Color</param>
        /// <param name="Text">Text</param>
        /// <param name="WebLink">Web link</param>
        /// <returns>Text width</returns>
        /// <remarks>
        ///	The position arguments are in relation to the
        ///	bottom left corner of the paper.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public Double DrawWebLink(
			PdfPage		Page,
			PdfFont		Font,
			Double		FontSize,		// in points
			Double		TextAbsPosX,
			Double		TextAbsPosY,
			TextJustify	Justify,
			DrawStyle	DrawStyle,
			Color		TextColor,
			String		Text,
			String		WebLink
			)
        {
            Double Width = DrawText(Font, FontSize, TextAbsPosX, TextAbsPosY, Justify, DrawStyle, TextColor, Text);
            if(Width == 0.0) return(0.0);

            // adjust position
            switch(Justify)
            {
            // right
            case TextJustify.Right:
                TextAbsPosX -= Width;
                break;

            // center
            case TextJustify.Center:
                TextAbsPosX -= 0.5 * Width;
                break;
            }

            Page.AddWebLink(TextAbsPosX, TextAbsPosY - Font.DescentPlusLeading(FontSize), TextAbsPosX + Width, TextAbsPosY + Font.AscentPlusLeading(FontSize), WebLink);
            return(Width);
        }
Exemplo n.º 24
0
        /// <summary>
        /// File attachement
        /// </summary>
        /// <param name="Page">Associated page</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="EmbeddedFile">Embedded file name</param>
        /// <param name="Icon">Icon</param>
        /// <remarks>
        /// <para>
        /// PDF specifications File Attachment Annotation page 637 table 8.35
        /// </para>
        /// </remarks>
        public PdfAnnotation(
			PdfPage				Page,
			PdfRectangle		AnnotRect,
			PdfEmbeddedFile		EmbeddedFile,
			FileAttachIcon		Icon = FileAttachIcon.PushPin
			)
            : base(Page.Document)
        {
            // annotation subtype
            Dictionary.Add("/Subtype", "/FileAttachment");

            // add page reference
            Dictionary.AddIndirectReference("/FS", EmbeddedFile);

            // icon
            Dictionary.AddName("/Name", Icon.ToString());

            // constructor helper method
            ContructorHelper(Page, AnnotRect);

            // exit
            return;
        }
Exemplo n.º 25
0
        ////////////////////////////////////////////////////////////////////
        // Draw text justify to width within text box
        ////////////////////////////////////////////////////////////////////
        private Double DrawText(
			Double		PosX,
			Double		PosY,
			Double		Width,
			TextBoxLine	Line,
			PdfPage		Page
			)
        {
            Double WordSpacing;
            Double CharSpacing;
            if(!TextFitToWidth(Width, out WordSpacing, out CharSpacing, Line)) return(DrawText(PosX, PosY, Line, Page));
            SaveGraphicsState();
            SetWordSpacing(WordSpacing);
            SetCharacterSpacing(CharSpacing);

            Double SegPosX = PosX;
            foreach(TextBoxSeg Seg in Line.SegArray)
            {
            Double SegWidth = DrawText(Seg.Font, Seg.FontSize, SegPosX, PosY, TextJustify.Left, Seg.DrawStyle, Seg.FontColor, Seg.Text) + Seg.SpaceCount * WordSpacing + Seg.Text.Length * CharSpacing;
            if(Seg.WebLink != null)
                {
                if(Page == null) throw new ApplicationException("TextBox with WebLink. You must call DrawText with PdfPage");
                Page.AddWebLink(SegPosX, PosY - Seg.Font.DescentPlusLeading(Seg.FontSize), SegPosX + SegWidth, PosY + Seg.Font.AscentPlusLeading(Seg.FontSize), Seg.WebLink);
                }
            SegPosX += SegWidth;
            }
            RestoreGraphicsState();
            return(SegPosX - PosX);
        }
Exemplo n.º 26
0
        private void ContructorHelper(
			PdfPage				Page,
			PdfRectangle		AnnotRect
			)
        {
            // save rectangle
            this.AnnotRect = AnnotRect;

            // area rectangle on the page
            Dictionary.AddRectangle("/Rect", AnnotRect);

            // annotation flags. value of 4 = Bit position 3 print
            Dictionary.Add("/F", "4");

            // add annotation object to page dictionary
            PdfKeyValue KeyValue = Page.Dictionary.GetValue("/Annots");
            if(KeyValue == null)
            {
            Page.Dictionary.AddFormat("/Annots", "[{0} 0 R]", ObjectNumber);
            }

            else
            {
            Page.Dictionary.Add("/Annots", ((String) KeyValue.Value).Replace("]", String.Format(" {0} 0 R]", ObjectNumber)));
            }

            // border style dictionary. If /BS with /W 0 is not specified, the annotation will have a thin border
            Dictionary.Add("/BS", "<</W 0>>");

            // exit
            return;
        }
Exemplo n.º 27
0
        /// <summary>
        /// PdfTable constructor.
        /// </summary>
        /// <param name="Page">Current PdfPage.</param>
        /// <param name="Contents">Current PdfContents.</param>
        /// <param name="Font">Table's default font.</param>
        /// <param name="FontSize">Table's default font size.</param>
        public PdfTable(
			PdfPage		Page,
			PdfContents	Contents,
			PdfFont		Font = null,
			Double		FontSize = 9.0
			)
        {
            // save arguments
            this.Document = Page.Document;
            this.Page = Page;
            this.Contents = Contents;

            // See if at least one font is defined. Make it the default font for the table
            if(Font == null) foreach(PdfObject Obj in Document.ObjectArray) if(Obj.GetType() == typeof(PdfFont))
            {
            Font = (PdfFont) Obj;
            break;
            }

            // initialize default cell style
            DefaultCellStyle = new PdfTableStyle();
            DefaultCellStyle.Font = Font;
            DefaultCellStyle.FontSize = FontSize;
            DefaultCellStyle.Margin.Left = DefaultCellStyle.Margin.Right = 3.0 / Document.ScaleFactor;
            DefaultCellStyle.Margin.Bottom = DefaultCellStyle.Margin.Top = 1.0 / Document.ScaleFactor;

            // initialize default header style
            DefaultHeaderStyle = CellStyle;
            DefaultHeaderStyle.BackgroundColor = Color.LightGray;

            // default table area
            TableArea = new PdfRectangle(72.0 / Document.ScaleFactor, 72.0 / Document.ScaleFactor,
            (Document.PageSize.Width - 72.0) / Document.ScaleFactor, (Document.PageSize.Height - 72.0) / Document.ScaleFactor);

            // set header on each page as the default
            HeaderOnEachPage = true;

            // create table border control
            Borders = new PdfTableBorder(this);

            // very small amount 1/300 of an inch
            // used to guard against rounding errors
            Epsilon = 1.0 / (300.0 * Document.ScaleFactor);
            return;
        }
Exemplo n.º 28
0
        /// <summary>
        /// PDF link annotation constructor
        /// </summary>
        /// <param name="Page">Associated page</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="WebLink">Weblink</param>
        public PdfAnnotation(
			PdfPage				Page,
			PdfRectangle		AnnotRect,
			PdfWebLink			WebLink
			)
            : base(Page.Document)
        {
            // annotation subtype
            Dictionary.Add("/Subtype", "/Link");

            // action reference dictionary
            Dictionary.AddIndirectReference("/A", WebLink);

            // constructor helper method
            ContructorHelper(Page, AnnotRect);

            // exit
            return;
        }
Exemplo n.º 29
0
        ////////////////////////////////////////////////////////////////////
        // Create article's example test PDF document
        ////////////////////////////////////////////////////////////////////
        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
            PdfDocument Document = new PdfDocument(8.25, 11.75, UnitOfMeasure.Inch);

            // 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;

            // Step 2: create resources
            // define font resources
            DefineFontResources(Document);

            // define tiling pattern resources
            DefineTilingPatternResource(Document);

            // Step 3: Add new page
            PdfPage Page = new PdfPage(Document);

            // Step 4:Add contents to page
            PdfContents Contents = new PdfContents(Page);

            // Step 5: add graphices and text contents to the contents object
            //DrawFrameAndBackgroundWaterMark(Contents);
            //DrawTwoLinesOfHeading(Contents);
            //DrawHappyFace(Contents);
            //DrawBrickPattern(Document, Contents);
            DrawLogo(Document, Contents);
            //DrawHeart(Contents);
            //DrawStar(Contents);
            //DrawTextBox(Contents);
            DrawBookOrderForm(Contents);

            // Step 6: create pdf file
            // argument: PDF file name
            Document.CreateFile(FileName);

            // start default PDF reader and display the file
            Process Proc = new Process();
            Proc.StartInfo = new ProcessStartInfo(FileName);
            Proc.Start();

            // exit
            return;
        }
Exemplo n.º 30
0
        /// <summary>
        /// PdfAnnotation constructor
        /// </summary>
        /// <param name="AnnotPage">Page object</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="AnnotAction">Annotation action</param>
        internal PdfAnnotation
        (
            PdfPage AnnotPage,
            PdfRectangle AnnotRect,
            AnnotAction AnnotAction
        ) : base(AnnotPage.Document)
        {
            // save arguments
            this.AnnotPage   = AnnotPage;
            this.AnnotRect   = AnnotRect;
            this.AnnotAction = AnnotAction;

            // annotation subtype
            Dictionary.Add("/Subtype", AnnotAction.Subtype);

            // area rectangle on the page
            Dictionary.AddRectangle("/Rect", AnnotRect);

            // annotation flags. value of 4 = Bit position 3 print
            Dictionary.Add("/F", "4");

            // border style dictionary. If /BS with /W 0 is not specified, the annotation will have a thin border
            Dictionary.Add("/BS", "<</W 0>>");

            // web link
            if (AnnotAction.GetType() == typeof(AnnotWebLink))
            {
                Dictionary.AddIndirectReference("/A", PdfWebLink.AddWebLink(Document, ((AnnotWebLink)AnnotAction).WebLinkStr));
            }

            // jump to destination
            else if (AnnotAction.GetType() == typeof(AnnotLinkAction))
            {
                if (Document.LinkAnnotArray == null)
                {
                    Document.LinkAnnotArray = new List <PdfAnnotation>();
                }
                Document.LinkAnnotArray.Add(this);
            }

            // display video or play sound
            else if (AnnotAction.GetType() == typeof(AnnotDisplayMedia))
            {
                PdfDisplayMedia DisplayMedia = ((AnnotDisplayMedia)AnnotAction).DisplayMedia;

                // action reference dictionary
                Dictionary.AddIndirectReference("/A", DisplayMedia);

                // add page reference
                Dictionary.AddIndirectReference("/P", AnnotPage);

                // add annotation reference
                DisplayMedia.Dictionary.AddIndirectReference("/AN", this);
            }

            // file attachment
            else if (AnnotAction.GetType() == typeof(AnnotFileAttachment))
            {
                // add file attachment reference
                AnnotFileAttachment File = (AnnotFileAttachment)AnnotAction;
                Dictionary.AddIndirectReference("/FS", File.EmbeddedFile);

                if (File.Icon != FileAttachIcon.NoIcon)
                {
                    // icon
                    Dictionary.AddName("/Name", File.Icon.ToString());
                }
                else
                {
                    // no icon
                    PdfXObject XObject = new PdfXObject(Document, AnnotRect.Right, AnnotRect.Top);
                    Dictionary.AddFormat("/AP", "<</N {0} 0 R>>", XObject.ObjectNumber);
                }
            }

            // sticky notes
            else if (AnnotAction.GetType() == typeof(AnnotStickyNote))
            {
                // short cut
                AnnotStickyNote StickyNote = (AnnotStickyNote)AnnotAction;

                // icon
                Dictionary.AddName("/Name", StickyNote.Icon.ToString());

                // action reference dictionary
                Dictionary.AddPdfString("/Contents", StickyNote.Note);
            }

            // add annotation object to page dictionary
            PdfKeyValue KeyValue = AnnotPage.Dictionary.GetValue("/Annots");

            if (KeyValue == null)
            {
                AnnotPage.Dictionary.AddFormat("/Annots", "[{0} 0 R]", ObjectNumber);
            }

            else
            {
                AnnotPage.Dictionary.Add("/Annots", ((string)KeyValue.Value).Replace("]", string.Format(" {0} 0 R]", ObjectNumber)));
            }

            // exit
            return;
        }
Exemplo n.º 31
0
        private void si_Click(object sender, EventArgs e)
        {
            preconcepto = preconceptoT.Text;
            nombre = nombreT.Text;
            fecha = fechaT.Text;
            total = totalT.Text;
            numeroAletras = numeroALetrasT.Text;

            string path = Properties.Settings.Default.letra+":" + (object)Path.DirectorySeparatorChar + "cheques";
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            String numeroDeCheque = "";
            if(anal.Length>11)
            {
                numeroDeCheque = anal.Substring(5, 7);
            }
            String FileName = path + (object)Path.DirectorySeparatorChar + numeroDiario + "_" + numeroDeCheque + ".pdf";
            String FileNameToPDF = path + (object)Path.DirectorySeparatorChar + numeroDiario + "_" + numeroDeCheque + "-Orden_de_cheque.pdf";
            if (File.Exists(FileName))
            {
                try
                {
                    File.Delete(FileName);
                }
                catch (IOException ex2)
                {
                    System.Windows.Forms.MessageBox.Show(ex2.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            if (File.Exists(FileNameToPDF))
            {
                try
                {
                    File.Delete(FileNameToPDF);
                }
                catch (IOException ex2)
                {
                     System.Windows.Forms.MessageBox.Show(ex2.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            Document = new PdfDocument(PaperType.sobreprima, false, UnitOfMeasure.Point, FileName);

            DocumentToPDF = new PdfDocument(PaperType.A4, false, UnitOfMeasure.Point, FileNameToPDF);

            DefineFontResources();
            DefineTilingPatternResource();
            PdfPage Page = new PdfPage(Document);
            PdfContents Contents = new PdfContents(Page);

            PdfPage PageToPDF = new PdfPage(DocumentToPDF);
            PdfContents ContentsToPDF = new PdfContents(PageToPDF);

            Contents.SaveGraphicsState();
            Contents.Translate(0.1, 0.1);

            ContentsToPDF.SaveGraphicsState();
            ContentsToPDF.Translate(0.1, 0.1);

            const Double Width = 632;
            const Double Height = 288;
            const Double FontSize = 9.0;

            const Double WidthToPDF = 632;//1200;
            const Double HeightToPDF = 850;// 288;//2138;
            const Double FontSizeToPDF = 12.0;

               string[] arrayCuentas = new string[100] ;
            string[] arrayDescr = new string[100] ;
            string[] arrayCantidad = new string[100];

            int con=0;
            try
            {
                using (SqlConnection connection = new SqlConnection(connStringSun))
                {
                    connection.Open();
                    foreach (Dictionary<string, object> dic in listaFinalconDebitos)
                    {
                        if (dic.ContainsKey("nombre"))
                        {
                            String analPrima = Convert.ToString(dic["anal"]).Trim();
                            String totalPrima = Convert.ToString(dic["total"]);
                            totalPrima = totalPrima.Replace("-", "");

                            String ACCNT_CODEPrima = Convert.ToString(dic["ACCNT_CODE"]).Trim();
                            if(analPrima.Equals(anal))
                            {
                                String paraVer = ACCNT_CODEPrima.Trim();

                                String queryDiario = "SELECT DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Properties.Settings.Default.sunUnidadDeNegocio + "_ACNT] WHERE ACNT_CODE = '" + paraVer + "'";
                                SqlCommand cmdCheck = new SqlCommand(queryDiario, connection);
                                SqlDataReader reader = cmdCheck.ExecuteReader();
                                if (reader.HasRows)
                                {
                                    while (reader.Read())
                                    {
                                        arrayCuentas[con] = paraVer;
                                        arrayCantidad[con] = totalPrima;
                                        arrayDescr[con] = reader.GetString(0);
                                        con++;
                                    }
                                }
                            }

                        }
                    }

                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString(), "Cheques", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            String descr_acntC = "";

            try
            {
                using (SqlConnection connection = new SqlConnection(connStringSun))
                {
                    connection.Open();
                    String paraVer2 = Convert.ToString(ACCNT_CODE).Trim();
                    String queryDiario = "SELECT DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Properties.Settings.Default.sunUnidadDeNegocio + "_ACNT] WHERE ACNT_CODE = '" + paraVer2 + "'";
                    SqlCommand cmdCheck = new SqlCommand(queryDiario, connection);
                    SqlDataReader reader = cmdCheck.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            descr_acntC = reader.GetString(0);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString(), "Cheques", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            String space = "                                                          ";
            PdfFileWriter.TextBox BoxToPDF = new PdfFileWriter.TextBox(WidthToPDF, 0.25);
            int l;
            StringBuilder debitos = new StringBuilder("");
            StringBuilder otrosDebitos = new StringBuilder("");

            int hastai = con;
            int max = 15;
            PdfContents ContentsToPDF1 = null;
            if(con>max)
            {
                hastai = max;
                PdfPage PageToPDF1 = new PdfPage(DocumentToPDF);
                ContentsToPDF1 = new PdfContents(PageToPDF1);

                ContentsToPDF1.SaveGraphicsState();
                ContentsToPDF1.Translate(0.1, 750);
                for (l = max; l < con; l++)
                {
                    otrosDebitos.Append("\n         Debito: $" + arrayCantidad[l] + " - " + arrayCuentas[l] + " - " + arrayDescr[l]);
                }

            }
            for(l=0;l<hastai;l++)
            {
                debitos.Append("\n         Debito: $" + arrayCantidad[l] +" - " +arrayCuentas[l] + " - " + arrayDescr[l]);
            }

            String aver = "\n\n\n\n\n" +
            space +
            Properties.Settings.Default.campo +
            "\n" + space +
            Properties.Settings.Default.calle + "\n" + space +
            "       " + Properties.Settings.Default.colonia + "                                        Fecha: " + fecha + "\n" + space +
            Properties.Settings.Default.ciudad+"                     Reference: " + anal + "\n" +
            "\n\n" +
            "\n\n" +
            "        Pagarse a: " + nombre +
            "\n" +
            "        Concepto: " + preconcepto + "\n" +
            "        Cantidad: " + total + "\n"+
            "        Bueno por: " + numeroAletras + "\n\n" +"\n\n\n\n\n\n" +
            "      ______________________                        ____________________               ____________________\n" +
            "           Processed by: " + JRNAL_SRCE + "                                         Approved by                                    Received by " +
            "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
            "         Crédito: $" +total+" - "+ ACCNT_CODE + " - " + descr_acntC.Trim() +debitos.ToString();
            BoxToPDF.AddText(ArialNormalToPDF, FontSizeToPDF,aver);
            Double PosYToPDF = HeightToPDF;

            StringBuilder espacios = new StringBuilder("");
            int j = 0;
            for (j = 0; j < Convert.ToInt32(Properties.Settings.Default.sunEspacios1); j++)
            {
                espacios.Append(" ");
            }
            StringBuilder entersPrimeros = new StringBuilder("");
            for (j = 0; j < Convert.ToInt32(Properties.Settings.Default.entersPrimeros1); j++)
            {
                entersPrimeros.Append("\n");
            }
            StringBuilder espaciosDeFecha = new StringBuilder("");
            for (j = 0; j < Convert.ToInt32(Properties.Settings.Default.espaciosDeFecha1); j++)
            {
                espaciosDeFecha.Append(" ");
            }
            StringBuilder entersEntreFechaYNombre = new StringBuilder("");
            for (j = 0; j < Convert.ToInt32(Properties.Settings.Default.entersEntreFechaYNombre1); j++)
            {
                entersEntreFechaYNombre.Append("\n");
            }
            StringBuilder entersEntreNombreYLetras = new StringBuilder("");
            for (j = 0; j < Convert.ToInt32(Properties.Settings.Default.entersEntreNombreYLetras1); j++)
            {
                entersEntreNombreYLetras.Append("\n");
            }
            StringBuilder espaciosEntreNombreYTotal = new StringBuilder("");
            for (j = 0; j < Convert.ToInt32(Properties.Settings.Default.espaciosEntreNombreYTotal1); j++)
            {
                espaciosEntreNombreYTotal.Append(" ");
            }

            PdfFileWriter.TextBox Box = new PdfFileWriter.TextBox(Width, 0.25);
            Box.AddText(ArialNormal, FontSize,
             entersPrimeros.ToString() +
            espaciosDeFecha.ToString() +
             fecha +
             entersEntreFechaYNombre.ToString() +
               espacios.ToString() +//64
             nombre + espaciosEntreNombreYTotal.ToString() + total +
             entersEntreNombreYLetras.ToString() +
            espacios.ToString() +
             numeroAletras);

            BoxToPDF.AddText(ArialNormalToPDF, FontSizeToPDF, "\n");
            ContentsToPDF.DrawText(0.0, ref PosYToPDF, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, BoxToPDF);
            ContentsToPDF.RestoreGraphicsState();
            ContentsToPDF.SaveGraphicsState();
            ContentsToPDF.RestoreGraphicsState();

            if (con > max)
            {
                PdfFileWriter.TextBox BoxToPDF1 = new PdfFileWriter.TextBox(WidthToPDF, 0.25);
                BoxToPDF1.AddText(ArialNormalToPDF, FontSizeToPDF, otrosDebitos.ToString());
                ContentsToPDF1.DrawText(0.0, ref PosYToPDF, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, BoxToPDF1);
                ContentsToPDF1.RestoreGraphicsState();
                ContentsToPDF1.SaveGraphicsState();
                ContentsToPDF1.RestoreGraphicsState();
            }
            DocumentToPDF.CreateFile();

            Box.AddText(ArialNormal, FontSize, "\n");
            Double PosY = Height;
            Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();
            Contents.RestoreGraphicsState();
            Document.CreateFile();

            previewCheque form = new previewCheque(tipoDeBancoGlobal);
                form.nombre = nombre;
                form.total = total;
                form.concepto = preconcepto;
                form.numeroAletras = numeroAletras;
                form.fecha = fecha;
                form.dia = dia;
                form.ano = ano;
                form.mes = mes;
                form.origen = JRNAL_SRCE;

                form.folio = numeroDeCheque;
                form.numeroDiario = numeroDiario;
                form.FileName = FileName;
                form.FileNameToPDF = FileNameToPDF;
                form.vuelveAHacerElCheque(true);
                form.ShowDialog();
        }
        public void ReportNodesPositioning()
        {
            var nodes = mNodeRepository.GetItems(n => n.IsInNetwork).ToList();

            if (nodes.Any())
            {
                for (var i = 0; i < nodes.Count(); i++)
                {
                    var page = new PdfPage(mDocument);
                    var contents = new PdfContents(page);

                    if(i == 0) contents.DrawText(mTimesNormal, 14.0, 10, 26, TextJustify.Center, "Informacje o położeniu węzłów oraz stacji bazowej na planie budynku");

                    contents.DrawText(mTimesNormal, 12.0, 1.5, 24, TextJustify.Left, string.Format("Nazwa: {0}, Pozycja: [{1}, {2}]",
                                      nodes[i].Name, nodes[i].Position.X, nodes[i].Position.Y));

                    var neighbours = nodes[i].Neighbours;

                    contents.DrawText(mTimesNormal, 12.0, 1.5, 23, TextJustify.Left, "Węzły widoczne:");
                    for (int j = 0; j < neighbours.Count; j++)
                    {
                        contents.DrawText(mTimesNormal, 12.0, 1.5, 23 - (j+1)*0.5, TextJustify.Left, string.Format("- Nazwa: {0}, Guid: {1}, Pozycja: [{2}, {3}]", neighbours[j].Name, neighbours[j].Guid, neighbours[j].Position.X, neighbours[j].Position.Y));
                    }

                    int nextline = 23 - neighbours.Count / 2 - 1;

                    var connections = nodes[i].Connections.Where(n => n.SecondNode != nodes[i].Guid).ToList();

                    contents.DrawText(mTimesNormal, 12.0, 1.5, nextline, TextJustify.Left, "Połączenia z węzłami lub stacją bazową:");
                    for (int j = 0; j < connections.Count; j++)
                    {
                        contents.DrawText(mTimesNormal, 12.0, 1.5, nextline - 0.5*(j+1), TextJustify.Left, string.Format("Element: {0}, Dystans: {1} m",
                                         (connections[j].SecondNode == Guid.Empty ? "Stacja bazowa" : connections[j].SecondNode.ToString()), connections[j].Distance.ToString("F")));
                    }

                    contents.CommitToPdfFile(false);
                }

                var newpage = new PdfPage(mDocument);
                var newcontents = new PdfContents(newpage);

                newcontents.DrawText(mTimesNormal, 12.0, 1.5, 24, TextJustify.Left, string.Format("Stacja bazowa, Pozycja [{0}, {1}]", mNodeNetwork.Sink.Position.X, mNodeNetwork.Sink.Position.Y));
                newcontents.DrawText(mTimesNormal, 12.0, 1.5, 23, TextJustify.Left, string.Format("Połączenia z węzłami:"));

                for (int i = 0; i < mNodeNetwork.Sink.NodeLinks.Count; i++)
                {
                    newcontents.DrawText(mTimesNormal, 12.0, 1.5, 22.5 - (i+1)*0.5 , TextJustify.Left, string.Format("- Element: {0}, Dystans: {1} m",
                                         mNodeNetwork.Sink.NodeLinks[i].FirstNode, mNodeNetwork.Sink.NodeLinks[i].Distance.ToString("F")));
                }

                newcontents.CommitToPdfFile(false);
            }
        }