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(); }
private void DrawPicturePai( PdfDocument Document, PdfContents Contents ) { // define local image resources PdfImage Image1 = new PdfImage(Document, "D:\\visual studio 2012\\TestPDFFileWriter\\TestPDFFileWriter\\logo.png"); // image size will be limited to 1.4" by 1.4" SizeD ImageSize = Image1.ImageSize(1.4, 1.4); // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the picture Contents.Translate(3.36, 5.7); // clipping path // Contents.DrawOval(-ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height, PaintOp.ClipPathEor); // draw image Contents.DrawImage(Image1, -ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw example of a text box //////////////////////////////////////////////////////////////////// private void DrawTextBox( PdfContents Contents ) { // save graphics state Contents.SaveGraphicsState(); // translate origin to PosX=1.1" and PosY=1.1" this is the bottom left corner of the text box example Contents.Translate(1.1, 1.1); // Contents.TranslateScaleRotate(7.4, 1.1, 1.0, Math.PI / 2); // Define constants // Box width 3.25" // Box height is 3.65" // Normal font size is 9.0 points. const Double Width = 3.15; const Double Height = 3.65; const Double FontSize = 9.0; // Create text box object width 3.25" // First line indent of 0.25" TextBox Box = new TextBox(Width, 0.25); // add text to the text box Box.AddText(ArialNormal, FontSize, "This area is an example of displaying text that is too long to fit within a fixed width " + "area. The text is displayed justified to right edge. You define a text box with the required " + "width and first line indent. You add text to this box. The box will divide the text into " + "lines. Each line is made of segments of text. For each segment, you define font, font " + "size, drawing style and color. After loading all the text, the program will draw the formatted text.\n"); Box.AddText(TimesNormal, FontSize + 1.0, "Example of multiple fonts: Times New Roman, "); Box.AddText(Comic, FontSize, "Comic Sans MS, "); Box.AddText(ArialNormal, FontSize, "Example of regular, "); Box.AddText(ArialBold, FontSize, "bold, "); Box.AddText(ArialItalic, FontSize, "italic, "); Box.AddText(ArialBoldItalic, FontSize, "bold plus italic. "); Box.AddText(ArialNormal, FontSize - 2.0, "Arial size 7, "); Box.AddText(ArialNormal, FontSize - 1.0, "size 8, "); Box.AddText(ArialNormal, FontSize, "size 9, "); Box.AddText(ArialNormal, FontSize + 1.0, "size 10. "); Box.AddText(ArialNormal, FontSize, DrawStyle.Underline, "Underline, "); Box.AddText(ArialNormal, FontSize, DrawStyle.Strikeout, "Strikeout. "); Box.AddText(ArialNormal, FontSize, "Subscript H"); Box.AddText(ArialNormal, FontSize, DrawStyle.Subscript, "2"); Box.AddText(ArialNormal, FontSize, "O. Superscript A"); Box.AddText(ArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(ArialNormal, FontSize, "+B"); Box.AddText(ArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(ArialNormal, FontSize, "=C"); Box.AddText(ArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(ArialNormal, FontSize, "\n"); Box.AddText(Comic, FontSize, Color.Red, "Lets add some color, "); Box.AddText(Comic, FontSize, Color.Green, "green, "); Box.AddText(Comic, FontSize, Color.Blue, "blue, "); Box.AddText(Comic, FontSize, Color.Orange, "orange, "); Box.AddText(Comic, FontSize, DrawStyle.Underline, Color.Purple, "and purple.\n"); // Draw the text box // Text left edge is at zero (note: origin was translated to 1.1") // The top text base line is at Height less first line ascent. // Text drawing is limited to vertical coordinate of zero. // First line to be drawn is line zero. // After each line add extra 0.015". // After each paragraph add extra 0.05" // Stretch all lines to make smooth right edge at box width of 3.15" // After all lines are drawn, PosY will be set to the next text line after the box's last paragraph Double PosY = Height; Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, true, Box); // Create text box object width 3.25" // No first line indent Box = new TextBox(Width); // Add text as before. // No extra line spacing. // No right edge adjustment Box.AddText(ArialNormal, FontSize, "In the examples above this area the text box was set for first line indent of " + "0.25 inches. This paragraph has zero first line indent and no right justify."); Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.01, 0.05, false, Box); // Create text box object width 2.75 // First line hanging indent of 0.5" Box = new TextBox(Width - 0.5, -0.5); // Add text Box.AddText(ArialNormal, FontSize, "This paragraph is set to first line hanging indent of 0.5 inches. " + "The left margin of this paragraph is 0.5 inches."); // Draw the text // left edge at 0.5" Contents.DrawText(0.5, ref PosY, 0.0, 0, 0.01, 0.05, false, Box); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw Happy Face //////////////////////////////////////////////////////////////////// private void DrawHappyFace( PdfContents Contents ) { // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the happy face Contents.Translate(4.25, 7.5); // change nonstroking (fill) color to yellow Contents.SetColorNonStroking(Color.Yellow); // draw happy face yellow oval Contents.DrawOval(-1.5, -1.0, 3.0, 2.0, PaintOp.Fill); // set line width to 0.2" this is the black circle around the eye Contents.SetLineWidth(0.2); // eye color is white with black outline circle Contents.SetColorNonStroking(Color.White); Contents.SetColorStroking(Color.Black); // draw eyes Contents.DrawOval(-0.75, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke); Contents.DrawOval(0.25, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke); // mouth color is black Contents.SetColorNonStroking(Color.Black); // draw mouth by creating a path made of one line and one Bezier curve Contents.MoveTo(-0.6, -0.4); Contents.LineTo(0.6, -0.4); Contents.DrawBezier(0.0, -0.8, 0, -0.8, -0.6, -0.4); // fill the path with black color Contents.SetPaintOp(PaintOp.Fill); // restore graphics sate Contents.RestoreGraphicsState(); return; }
private void DrawFormPai( PdfContents Contents ) { // Order form simulation // Define constants to make the code readable // Define constants const Double Width = 3.05; const Double Height = 7.65; const Double Margin = 0.04; const Double FontSize = 9.0; Double LineSpacing = ArialNormal.LineSpacing(FontSize); Double Descent = ArialNormal.Descent(FontSize); Double ColWidth1 = ArialNormal.TextWidth(FontSize, "9999.99") + 2 * Margin; Double ColWidth2 = ArialNormal.TextWidth(FontSize, "Qty") + 2 * Margin; Double Col4LinePosX = Width - ColWidth1; Double Col3LinePosX = Col4LinePosX - ColWidth2; Double Col2LinePosX = Col3LinePosX - ColWidth1; /////Text of header of table Double Col1TextPosX = Margin; Double Col2TextPosX = Col3LinePosX - Margin; Double Col3TextPosX = Col4LinePosX - Margin; Double Col4TextPosX = Width - Margin; // save graphics state Contents.SaveGraphicsState(); // form line width 0.01" Contents.SetLineWidth(0.01); // Initial vertical position for contents Double PosY1 = Height - LineSpacing - 2 * Margin; // bottom of the contents area of the form Double PosY2 = 2 * Margin + 3 * LineSpacing; // shift origin, bottom left of the form to X=4.35" and Y=1.1" /// Set Position of all contents ****** Contents.Translate(1, 5); // draw outline rectangle Contents.DrawRectangle(0.0, 0.0, 6.25, 6.25, PaintOp.CloseStroke); // draw two horizontal lines. under table heading and above total Contents.DrawLine(0, 6, 6.25, 6); Contents.DrawLine(1, 0, 1, 6); Contents.DrawLine(2, 0, 2, 6); // Contents.DrawLine(0, PosY2, Width, PosY2); // draw three vertical lines separating the column Contents.DrawLine(Col2LinePosX, Height, Col2LinePosX, PosY2); Contents.DrawLine(Col3LinePosX, Height, Col3LinePosX, PosY2); Contents.DrawLine(Col4LinePosX, Height, Col4LinePosX, 0); // draw table heading Double PosY = PosY1 + Margin + Descent; Contents.DrawText(ArialNormal, FontSize, Col1TextPosX, PosY, "Description"); Contents.DrawText(ArialNormal, FontSize, Col2TextPosX, PosY, TextJustify.Right, "Price"); Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Qty"); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, "Total"); // reset order total Double Total = 0; // define text box for book title and author TextBox Box = new TextBox(Col2LinePosX - 2 * Margin); // initial vertical position PosY = PosY1 - Margin; // loop for all items in the order // Order class is a atabase simulation for this example foreach (Order Book in Order.OrderList) { // clear the text box Box.Clear(); // add book title and authors to the box Box.AddText(ArialNormal, FontSize, Book.Title); Box.AddText(ArialNormal, FontSize, ". By: "); Box.AddText(ArialNormal, FontSize, Book.Authors); // draw the title and authors. // on exit, PosY will be for next line Contents.DrawText(Col1TextPosX, ref PosY, PosY2, 0, Box); // move PosY up to allow drawing cost on the same line as the last text line of the box PosY += Descent; // draw price quantity and item's total Contents.DrawText(ArialNormal, FontSize, Col2TextPosX, PosY, TextJustify.Right, Book.Price.ToString("#.00")); Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, Book.Qty.ToString()); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Book.Total.ToString("#.00")); // update PosY for next item PosY -= Descent + 0.5 * LineSpacing; // accumulate total Total += Book.Total; } // draw total before tax PosY = PosY2 - Margin - ArialNormal.Ascent(FontSize); Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Total before tax"); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Total.ToString("#.00")); // draw tax (Ontario Canada HST) PosY -= LineSpacing; Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Tax (13%)"); Double Tax = Math.Round(0.13 * Total, 2, MidpointRounding.AwayFromZero); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Tax.ToString("#.00")); // draw final total PosY -= LineSpacing; Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Total payable"); Total += Tax; Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Total.ToString("#.00")); // restore graphics state Contents.RestoreGraphicsState(); return; }
private void mandarButton_Click(object sender, EventArgs e) { this.Cursor = System.Windows.Forms.Cursors.WaitCursor; String connString = "Database=" + Properties.Settings.Default.databaseFiscal + ";Data Source=" + Properties.Settings.Default.datasource + ";Integrated Security=False;User ID='" + Properties.Settings.Default.user + "';Password='******';connect timeout = 10"; try { using (SqlConnection connection = new SqlConnection(connString)) { connection.Open(); String queryXML = ""; if(Login.unidadDeNegocioGlobal.Equals("FOP")) { queryXML = "SELECT b.ADDR_LINE_1,b.ADDR_LINE_2,b.ADDR_LINE_3,b.ADDR_LINE_4,b.ADDR_LINE_5 , a.AMOUNT, a.TRANS_DATETIME,a.DESCRIPTN,a.JRNAL_SRCE, a.ANAL_T0,a.ACCNT_CODE,c.DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_" + Properties.Settings.Default.sunLibro + "_SALFLDG] a INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ADDR] b on a.ANAL_T2 = b.ADDR_CODE INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[FOP_ACNT] c on c.ACNT_CODE = a.ACCNT_CODE WHERE a.JRNAL_NO = " + diarioText.Text + " AND a.ANAL_T9 = '" + iglesiaText.Text + "'"; } else { queryXML = "SELECT b.ADDR_LINE_1,b.ADDR_LINE_2,b.ADDR_LINE_3,b.ADDR_LINE_4,b.ADDR_LINE_5 , a.AMOUNT, a.TRANS_DATETIME,a.DESCRIPTN,a.JRNAL_SRCE, a.ANAL_T0,a.ACCNT_CODE,c.DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_" + Properties.Settings.Default.sunLibro + "_SALFLDG] a INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ADDR] b on a.ANAL_T2 = b.ADDR_CODE INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ACNT] c on c.ACNT_CODE = a.ACCNT_CODE WHERE a.JRNAL_NO = " + diarioText.Text + " AND a.ANAL_T5 = '" + iglesiaText.Text + "'"; } using (SqlCommand cmdCheck = new SqlCommand(queryXML, connection)) { String saveANAL=""; String saveFecha = ""; SqlDataReader reader = cmdCheck.ExecuteReader(); if (reader.HasRows) { bool first = true; String FileName = "C:" + (object)Path.DirectorySeparatorChar + "recibos" + (object)Path.DirectorySeparatorChar + iglesiaText.Text + "_" + diarioText.Text + ".pdf"; string path = "C:" + (object)Path.DirectorySeparatorChar + "recibos"; if (!Directory.Exists(path)) Directory.CreateDirectory(path); if (File.Exists(FileName)) { try { File.Delete(FileName); } catch (IOException ex2) { System.Windows.Forms.MessageBox.Show(ex2.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName); DefineFontResources(); DefineTilingPatternResource(); PdfPage Page = new PdfPage(Document); PdfContents Contents = new PdfContents(Page); Contents.SaveGraphicsState(); String fileImage = "C:" + (object)Path.DirectorySeparatorChar + "recibos" + (object)Path.DirectorySeparatorChar + "logo.jpg"; PdfImageControl ImageControl = new PdfImageControl(); ImageControl.Resolution = 300.0; PdfImage Image = new PdfImage(Document, fileImage, ImageControl); //new PdfImage(Document, fileImage, 72.0, 50); Contents.SaveGraphicsState(); double top = 9.9; double left = 0.4; int ancho = 1; int largo = 1; Contents.DrawImage(Image, left, top, ancho, largo); Contents.DrawImage(Image, left, top-6.2, ancho, largo); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); const Double Width = 8.15; const Double Height = 10.65; PdfFileWriter.TextBox Box = new PdfFileWriter.TextBox(Width, 0.0); PdfFileWriter.TextBox Datos = new PdfFileWriter.TextBox(Width, 0.0); PdfFileWriter.TextBox derecha = new PdfFileWriter.TextBox(Width, 0.0); PdfFileWriter.TextBox fechaBox = new PdfFileWriter.TextBox(Width, 0.0); PdfFileWriter.TextBox graciasBox = new PdfFileWriter.TextBox(Width, 0.0); PdfFileWriter.TextBox copiaBox = new PdfFileWriter.TextBox(Width, 0.0); //double dif = 2.5; // Contents.SaveGraphicsState(); //Contents.RestoreGraphicsState(); Contents.Translate(0.0, 0.0); PdfTable Table = new PdfTable(Page, Contents, ArialNormal, 9.0); PdfTable TableCopy = new PdfTable(Page, Contents, ArialNormal, 9.0); Table.TableArea = new PdfRectangle(0.5, 1,8.0,7.7); TableCopy.TableArea = new PdfRectangle(0.5, 1, 8.0, 1.75); Double MarginHor = 0.04; double aver = ArialNormal.TextWidth(9.0, "9999.99") + 2.0 * MarginHor; double aver2 = ArialNormal.TextWidth(9.0, "Qty") + 2.0 * MarginHor; aver += 0.2; Table.SetColumnWidth(new Double[] { aver2,aver , aver, aver2 }); Table.Borders.SetAllBorders(0.0); Table.Header[0].Style = Table.HeaderStyle; Table.Header[0].Style.Alignment = ContentAlignment.MiddleCenter; Table.Header[1].Style = Table.HeaderStyle; Table.Header[1].Style.Alignment = ContentAlignment.MiddleCenter; Table.Header[2].Style = Table.HeaderStyle; Table.Header[2].Style.Alignment = ContentAlignment.MiddleCenter; Table.Header[3].Style = Table.HeaderStyle; Table.Header[3].Style.Alignment = ContentAlignment.MiddleCenter; Table.Header[0].Value = "Cuenta"; Table.Header[1].Value = "Descripción"; Table.Header[2].Value = "Concepto"; Table.Header[3].Value = "Total"; TableCopy.SetColumnWidth(new Double[] { aver2, aver, aver, aver2 }); TableCopy.Borders.SetAllBorders(0.0); TableCopy.Header[0].Style = Table.HeaderStyle; TableCopy.Header[0].Style.Alignment = ContentAlignment.MiddleCenter; TableCopy.Header[1].Style = Table.HeaderStyle; TableCopy.Header[1].Style.Alignment = ContentAlignment.MiddleCenter; TableCopy.Header[2].Style = Table.HeaderStyle; TableCopy.Header[2].Style.Alignment = ContentAlignment.MiddleCenter; TableCopy.Header[3].Style = Table.HeaderStyle; TableCopy.Header[3].Style.Alignment = ContentAlignment.MiddleCenter; TableCopy.Header[0].Value = "Cuenta"; TableCopy.Header[1].Value = "Descripción"; TableCopy.Header[2].Value = "Concepto"; TableCopy.Header[3].Value = "Total"; StringBuilder cad = new StringBuilder(""); StringBuilder primeros = new StringBuilder(""); StringBuilder letrasGrandes = new StringBuilder(""); StringBuilder fechaCad = new StringBuilder(""); StringBuilder tabla = new StringBuilder(""); double total=0; int contadorTabla = 0; while (reader.Read()) { String ADDR_LINE_1 = reader.GetString(0).Trim(); String ADDR_LINE_2 = reader.GetString(1).Trim(); String ADDR_LINE_3 = reader.GetString(2).Trim(); String ADDR_LINE_4 = reader.GetString(3).Trim(); String ADDR_LINE_5 = reader.GetString(4).Trim(); String amount = Convert.ToString(reader.GetDecimal(5)); String fecha = Convert.ToString(reader.GetDateTime(6)).Substring(0, 10); String DESCR = reader.GetString(7).Trim(); if(DESCR.Length>32) { DESCR = DESCR.Substring(0, 32); } String JRNAL_SRCE = reader.GetString(8).Trim(); String ANAL_T0 = reader.GetString(9).Trim(); saveANAL=ANAL_T0; String ACNT_CODE = reader.GetString(10).Trim(); String descrCuenta = reader.GetString(11).Trim(); if (descrCuenta.Length > 36) { descrCuenta = descrCuenta.Substring(0, 36); } total+=Convert.ToDouble(amount); if(first) { first = false; primeros.Append( ADDR_LINE_1 + "\n" + ADDR_LINE_2 + "\n" + ADDR_LINE_3 + "\n" + ADDR_LINE_4 + "\n" + ADDR_LINE_5 + "\n\n"); fechaCad.Append(" Fecha de recepción:\n" + fecha); letrasGrandes.Append(" Recibido de " + DESCR + "\n"); saveFecha = fecha; } Table.Cell[0].Value = ACNT_CODE; Table.Cell[1].Value = descrCuenta; Table.Cell[2].Value = DESCR; Table.Cell[3].Value = "$"+String.Format("{0:n}", Convert.ToDouble(amount)); Table.DrawRow(); TableCopy.Cell[0].Value = ACNT_CODE; TableCopy.Cell[1].Value = descrCuenta; TableCopy.Cell[2].Value = DESCR; TableCopy.Cell[3].Value = "$" + String.Format("{0:n}", Convert.ToDouble(amount)); TableCopy.DrawRow(); contadorTabla++; // tabla.Append("\n"+DESCR+" "+ACNT_CODE+" "+JRNAL_SRCE+" "+ String.Format("{0:n}", Convert.ToDouble(amount))); }//while Table.Close(); TableCopy.Close(); Contents.SaveGraphicsState(); Contents.RestoreGraphicsState(); letrasGrandes.Append(" ***** " + Conversiones.NumeroALetras(total.ToString()) + " *****\n"); cad.Append(" Número de recibo original: " + saveANAL + "\n Diario: " + diarioText.Text + "\n" + " Monto recibido\n ***** "+String.Format("{0:n}", Convert.ToDouble(total))+" *****\n\n"); //cad.Append(); try{ Box.AddText(ArialNormal, 14.0, primeros.ToString() ); Datos.AddText(ArialNormal, 14.0, letrasGrandes.ToString() ); copiaBox.AddText(ArialBold, 50.0, " COPY"); graciasBox.AddText(ArialItalic, 30.0, " Gracias\n"); fechaBox.AddText(ArialNormal, 10.0, fechaCad.ToString()); derecha.AddText(ArialNormal, 12.0, cad.ToString()); Double PosY = 8.5; Double PosYDatos = 9.0; Double auxY = Height; Double auxFecha = Height-0.5; double dif = 6.0; Double auxYCopia = Height-dif; Double auxFechaCopia = Height - 0.5-dif; Double PosYCopia = 8.5-dif; Double copiaCopia = 8.5 - dif; Double PosYDatosCopia = 9.0-dif; Contents.Translate(0.0, 10.0); // Contents.Translate(0.0, -9.9);//-9.9 Contents.Translate(0.0, -9.9); Contents.DrawText(0.0, ref auxY, 9.0, 0, 0.0, 0.0, TextBoxJustify.Center, Box); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); //la copia Contents.DrawText(0.0, ref auxYCopia, 1.0, 0, 0.0, 0.0, TextBoxJustify.Center, Box); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); // Contents.Translate(0.0, -9.9); Contents.DrawText(0, ref PosYDatos, 8.5, 0, 0.00, 0.00, TextBoxJustify.Left, Datos); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Contents.DrawText(0, ref PosYDatosCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, Datos); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); // Contents.Translate(0.0, -9.9); Contents.DrawText(0, ref PosY, 7.0, 0, 0.00, 0.00, TextBoxJustify.Right, derecha); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Contents.DrawText(0, ref PosYDatos, 7.0, 0, 0.00, 0.00, TextBoxJustify.Left, graciasBox); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Contents.DrawText(0, ref PosYCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Right, derecha); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Contents.DrawText(0, ref PosYDatosCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, graciasBox); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Contents.DrawText(0, ref copiaCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, copiaBox); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); //Contents.Translate(0.0, -9.9); Contents.DrawText(0, ref auxFecha, 9.5, 0, 0.00, 0.00, TextBoxJustify.Right, fechaBox); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Contents.DrawText(0, ref auxFechaCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Right, fechaBox); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Document.CreateFile(); try { MailMessage mail2 = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail2.From = new MailAddress(Properties.Settings.Default.correoEmisor); mail2.To.Add(correoLabel.Text); mail2.CC.Add(Properties.Settings.Default.correoReceptor); DateTime now = DateTime.Now; int year = now.Year; int month = now.Month; int day = now.Day; String mes = month.ToString(); if (month < 10) { mes = "0" + month; } String dia = day.ToString(); if (day < 10) { dia = "0" + day; } if(Login.unidadDeNegocioGlobal.Equals("FOP")) { mail2.Subject = "Recibo del dia: " + saveFecha + " del diario "+diarioText.Text+" de FORPOUMN " + iglesiaText.Text ; mail2.Body = "Hola " + nombreLabel.Text + ", por este medio le envio el recibo de FOPROUMN correspondiente al diario "+diarioText.Text+". Dios lo bendiga. "; } else { mail2.Subject = "Recibo de caja del dia: " + saveFecha + " de la iglesia " + iglesiaText.Text; mail2.Body = "Hola " + nombreLabel.Text + ", por este medio le envio el recibo de caja de la iglesia " + iglesiaText.Text; } Attachment pdf = new Attachment(FileName); mail2.Attachments.Add(pdf); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential(Properties.Settings.Default.correoEmisor, Properties.Settings.Default.passEmisor); SmtpServer.EnableSsl = true; SmtpServer.Send(mail2); this.Cursor = System.Windows.Forms.Cursors.Arrow; System.Windows.Forms.MessageBox.Show("Ya se mando el correo", "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex3) { System.Windows.Forms.MessageBox.Show(ex3.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }//try catch(Exception ex1) { System.Windows.Forms.MessageBox.Show(ex1.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } } catch(Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } this.Cursor = System.Windows.Forms.Cursors.Arrow; }
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(); }
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()); } }