//////////////////////////////////////////////////////////////////// // Draw Cell Initialization //////////////////////////////////////////////////////////////////// internal void DrawCellInitialization() { // calculate left and right client space ClientLeft = FrameLeft + Style.Margin.Left; ClientRight = FrameLeft + FrameWidth - Style.Margin.Right; // initialize cell height to top and bottom margins CellHeight = Style.Margin.Top + Style.Margin.Bottom; // we have something to draw if (Value != null) { // assume cell type to be text Type = CellType.Text; // get object type Type ValueType = Value.GetType(); // value is string if (ValueType == typeof(string)) { // multi line text if (Style.MultiLineText) { // convert string to TextBox TextBox = new TextBox(ClientRight - ClientLeft, Style.TextBoxFirstLineIndent, Style.TextBoxLineBreakFactor); TextBox.AddText(Style.Font, Style.FontSize, Style.ForegroundColor, (string)Value); // textbox initialization TextBoxInitialization(); } // single line text else { // save value as string FormattedText = (string)Value; // add line spacing CellHeight += Style.FontLineSpacing; } } // value is text box else if (ValueType == typeof(TextBox)) { // set TextBox TextBox = (TextBox)Value; // test width if (TextBox.BoxWidth - (ClientRight - ClientLeft) > Parent.Epsilon) { throw new ApplicationException("PdfTableCell: TextBox width is greater than column width"); } // textbox initialization TextBoxInitialization(); } // value is PdfImage else if (ValueType == typeof(PdfImage)) { // set image Image = (PdfImage)Value; // calculate client width double Width = ClientWidth; // calculate image width and height if (ImageWidth == 0.0) { if (ImageHeight == 0.0) { ImageWidth = Width; ImageHeight = ImageWidth * (double)Image.HeightPix / (double)Image.WidthPix; } else { ImageWidth = ImageHeight * (double)Image.WidthPix / (double)Image.HeightPix; } } else if (ImageHeight == 0.0) { ImageHeight = ImageWidth * (double)Image.HeightPix / (double)Image.WidthPix; } // image width is too wide if (ImageWidth > Width) { ImageHeight = Width * ImageHeight / ImageWidth; ImageWidth = Width; } // adjust cell's height CellHeight += ImageHeight; // set type to image Type = CellType.Image; } // value is a derived class of barcode else if (ValueType.BaseType == typeof(Barcode)) { // set barcode Barcode = (Barcode)Value; // test barcode height if (Style.BarcodeHeight <= 0.0) { throw new ApplicationException("PdfTableStyle: BarcodeHeight must be defined."); } // calculate total barcode height BarcodeBox = Barcode.GetBarcodeBox(Style.BarcodeBarWidth, Style.BarcodeHeight, Style.Font, Style.FontSize); // adjust cell's height CellHeight += BarcodeBox.TotalHeight; // set type to barcode Type = CellType.Barcode; } // value is basic mostly numeric object else { string Format = Style.Format; NumberFormatInfo NumberFormat = Style.NumberFormatInfo; if (ValueType == typeof(int)) { FormattedText = ((int)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(float)) { FormattedText = ((float)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(double)) { FormattedText = ((double)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(bool)) { FormattedText = ((bool)Value).ToString(); } else if (ValueType == typeof(char)) { FormattedText = ((char)Value).ToString(); } else if (ValueType == typeof(byte)) { FormattedText = ((byte)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(sbyte)) { FormattedText = ((sbyte)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(short)) { FormattedText = ((short)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(ushort)) { FormattedText = ((ushort)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(uint)) { FormattedText = ((uint)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(long)) { FormattedText = ((long)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(ulong)) { FormattedText = ((ulong)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(decimal)) { FormattedText = ((decimal)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(DBNull)) { FormattedText = string.Empty; } else { throw new ApplicationException("PdfTableCell: Unknown object type"); } // add line spacing CellHeight += Style.FontLineSpacing; } } // value is null and textbox continuation is required else if (Type == CellType.TextBox && TextBoxLineNo != 0) { CellHeight += TextBox.BoxHeightExtra(ref TextBoxLineNo, out int LineEnd, Parent._RowTopPosition - Parent.TableBottomLimit - (Style.Margin.Top + Style.Margin.Bottom), Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace); TextBoxCellHeight = CellHeight; } else { // reset cell type Type = CellType.Empty; } // test for minimum height requirement if (CellHeight < Style.MinHeight) { CellHeight = Style.MinHeight; } // cell minimum height for all types but textbox if (Type != CellType.TextBox) { TextBoxCellHeight = CellHeight; } // return result return; }
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 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; }
//////////////////////////////////////////////////////////////////// // 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; }
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; }
//////////////////////////////////////////////////////////////////// // Draw Cell Initialization //////////////////////////////////////////////////////////////////// internal Double DrawCellInitialization() { // calculate left and right client space ClientLeft = FrameLeft + Style.Margin.Left; ClientRight = FrameLeft + FrameWidth - Style.Margin.Right; // initialize cell height to top and bottom margins Double CellHeight = Style.Margin.Top + Style.Margin.Bottom; // reset cell type Type = CellType.Empty; // we have something to draw if(Value != null) { // assume cell type to be text Type = CellType.Text; // get object type Type ValueType = Value.GetType(); // value is string if(ValueType == typeof(String)) { // multi line text if(Style.MultiLineText) { // convert string to TextBox TextBox = new TextBox(ClientRight - ClientLeft, Style.TextBoxFirstLineIndent, Style.TextBoxLineBreakFactor); TextBox.AddText(Style.Font, Style.FontSize, (String) Value); TextBox.Terminate(); TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace); CellHeight += TextBoxHeight; Type = CellType.TextBox; } // single line text else { // save value as string FormattedText = (String) Value; // add line spacing CellHeight += Style.FontLineSpacing; } } // value is text box else if(ValueType == typeof(TextBox)) { // set TextBox TextBox = (TextBox) Value; // test width if(TextBox.BoxWidth - (ClientRight - ClientLeft) > Parent.Epsilon) throw new ApplicationException("PdfTableCell: TextBox width is greater than column width"); // terminate TextBox TextBox.Terminate(); // calculate TextBox height and add to cell height TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace); CellHeight += TextBoxHeight; // set type to text box Type = CellType.TextBox; } // value is PdfImage else if(ValueType == typeof(PdfImage)) { // set image Image = (PdfImage) Value; // calculate client width Double Width = ClientWidth; // calculate image width and height if(ImageWidth == 0.0) { if(ImageHeight == 0.0) { ImageWidth = Width; ImageHeight = ImageWidth * (Double) Image.HeightPix / (Double) Image.WidthPix; } else { ImageWidth = ImageHeight * (Double) Image.WidthPix / (Double) Image.HeightPix; } } else if(ImageHeight == 0.0) { ImageHeight = ImageWidth * (Double) Image.HeightPix / (Double) Image.WidthPix; } // image width is too wide if(ImageWidth > Width) { ImageHeight = Width * ImageHeight / ImageWidth; ImageWidth = Width; } // adjust cell's height CellHeight += ImageHeight; // set type to image Type = CellType.Image; } // value is PdfQRCode else if(ValueType == typeof(PdfQRCode)) { // set QR Code QRCode = (PdfQRCode) Value; // calculate client width Double Width = ClientWidth; // calculate QR Code width if(QRCodeWidth == 0.0 || QRCodeWidth > Width) QRCodeWidth = Width; // adjust cell's height CellHeight += QRCodeWidth; // set type to QR Code Type = CellType.QRCode; } // value is a derived class of barcode else if(ValueType.BaseType == typeof(Barcode)) { // set barcode Barcode = (Barcode) Value; // test barcode height if(Style.BarcodeHeight <= 0.0) throw new ApplicationException("PdfTableStyle: BarcodeHeight must be defined."); // calculate total barcode height BarcodeBox = Barcode.GetBarcodeBox(Style.BarcodeBarWidth, Style.BarcodeHeight, Style.Font, Style.FontSize); // adjust cell's height CellHeight += BarcodeBox.TotalHeight; // set type to barcode Type = CellType.Barcode; } // value is basic mostly numeric object else { String Format = Style.Format; NumberFormatInfo NumberFormat = Style.NumberFormatInfo; if(ValueType == typeof(Int32)) FormattedText = ((Int32) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(Single)) FormattedText = ((Single) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(Double)) FormattedText = ((Double) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(Boolean)) FormattedText = ((Boolean) Value).ToString(); else if(ValueType == typeof(Char)) FormattedText = ((Char) Value).ToString(); else if(ValueType == typeof(Byte)) FormattedText = ((Byte) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(SByte)) FormattedText = ((SByte) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(Int16)) FormattedText = ((Int16) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(UInt16)) FormattedText = ((UInt16) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(UInt32)) FormattedText = ((UInt32) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(Int64)) FormattedText = ((Int64) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(UInt64)) FormattedText = ((UInt64) Value).ToString(Format, NumberFormat); else if(ValueType == typeof(Decimal)) FormattedText = ((Decimal) Value).ToString(Format, NumberFormat); else throw new ApplicationException("PdfTableCell: Unknown object type"); // add line spacing CellHeight += Style.FontLineSpacing; } } // test for minimum height requirement if(CellHeight < Style.MinHeight) CellHeight = Style.MinHeight; // return result return(CellHeight); }
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); }
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); } }
//////////////////////////////////////////////////////////////////// // Draw Cell Initialization //////////////////////////////////////////////////////////////////// internal Double DrawCellInitialization() { // calculate left and right client space ClientLeft = FrameLeft + Style.Margin.Left; ClientRight = FrameLeft + FrameWidth - Style.Margin.Right; // initialize cell height to top and bottom margins Double CellHeight = Style.Margin.Top + Style.Margin.Bottom; // reset cell type Type = CellType.Empty; // we have something to draw if (Value != null) { // assume cell type to be text Type = CellType.Text; // get object type Type ValueType = Value.GetType(); // value is string if (ValueType == typeof(String)) { // multi line text if (Style.MultiLineText) { // convert string to TextBox TextBox = new TextBox(ClientRight - ClientLeft, Style.TextBoxFirstLineIndent, Style.TextBoxLineBreakFactor); TextBox.AddText(Style.Font, Style.FontSize, (String)Value); TextBox.Terminate(); TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace); CellHeight += TextBoxHeight; Type = CellType.TextBox; } // single line text else { // save value as string FormattedText = (String)Value; // add line spacing CellHeight += Style.FontLineSpacing; } } // value is text box else if (ValueType == typeof(TextBox)) { // set TextBox TextBox = (TextBox)Value; // test width if (TextBox.BoxWidth - (ClientRight - ClientLeft) > Parent.Epsilon) { throw new ApplicationException("PdfTableCell: TextBox width is greater than column width"); } // terminate TextBox TextBox.Terminate(); // calculate TextBox height and add to cell height TextBoxHeight = TextBox.BoxHeightExtra(Style.TextBoxLineExtraSpace, Style.TextBoxParagraphExtraSpace); CellHeight += TextBoxHeight; // set type to text box Type = CellType.TextBox; } // value is PdfImage else if (ValueType == typeof(PdfImage)) { // set image Image = (PdfImage)Value; // calculate client width Double Width = ClientWidth; // calculate image width and height if (ImageWidth == 0.0) { if (ImageHeight == 0.0) { ImageWidth = Width; ImageHeight = ImageWidth * (Double)Image.HeightPix / (Double)Image.WidthPix; } else { ImageWidth = ImageHeight * (Double)Image.WidthPix / (Double)Image.HeightPix; } } else if (ImageHeight == 0.0) { ImageHeight = ImageWidth * (Double)Image.HeightPix / (Double)Image.WidthPix; } // image width is too wide if (ImageWidth > Width) { ImageHeight = Width * ImageHeight / ImageWidth; ImageWidth = Width; } // adjust cell's height CellHeight += ImageHeight; // set type to image Type = CellType.Image; } // value is PdfQRCode else if (ValueType == typeof(PdfQRCode)) { // set QR Code QRCode = (PdfQRCode)Value; // calculate client width Double Width = ClientWidth; // calculate QR Code width if (QRCodeWidth == 0.0 || QRCodeWidth > Width) { QRCodeWidth = Width; } // adjust cell's height CellHeight += QRCodeWidth; // set type to QR Code Type = CellType.QRCode; } // value is a derived class of barcode else if (ValueType.BaseType == typeof(Barcode)) { // set barcode Barcode = (Barcode)Value; // test barcode height if (Style.BarcodeHeight <= 0.0) { throw new ApplicationException("PdfTableStyle: BarcodeHeight must be defined."); } // calculate total barcode height BarcodeBox = Barcode.GetBarcodeBox(Style.BarcodeBarWidth, Style.BarcodeHeight, Style.Font, Style.FontSize); // adjust cell's height CellHeight += BarcodeBox.TotalHeight; // set type to barcode Type = CellType.Barcode; } // value is basic mostly numeric object else { String Format = Style.Format; NumberFormatInfo NumberFormat = Style.NumberFormatInfo; if (ValueType == typeof(Int32)) { FormattedText = ((Int32)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(Single)) { FormattedText = ((Single)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(Double)) { FormattedText = ((Double)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(Boolean)) { FormattedText = ((Boolean)Value).ToString(); } else if (ValueType == typeof(Char)) { FormattedText = ((Char)Value).ToString(); } else if (ValueType == typeof(Byte)) { FormattedText = ((Byte)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(SByte)) { FormattedText = ((SByte)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(Int16)) { FormattedText = ((Int16)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(UInt16)) { FormattedText = ((UInt16)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(UInt32)) { FormattedText = ((UInt32)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(Int64)) { FormattedText = ((Int64)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(UInt64)) { FormattedText = ((UInt64)Value).ToString(Format, NumberFormat); } else if (ValueType == typeof(Decimal)) { FormattedText = ((Decimal)Value).ToString(Format, NumberFormat); } else { throw new ApplicationException("PdfTableCell: Unknown object type"); } // add line spacing CellHeight += Style.FontLineSpacing; } } // test for minimum height requirement if (CellHeight < Style.MinHeight) { CellHeight = Style.MinHeight; } // return result return(CellHeight); }