Example #1
0
        private void si_Click(object sender, EventArgs e)
        {
            preconcepto = preconceptoT.Text;
            nombre = nombreT.Text;
            fecha = fechaT.Text;
            total = totalT.Text;
            numeroAletras = numeroALetrasT.Text;

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

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

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

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

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

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

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

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

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

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

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

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

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

                        }
                    }

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

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

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

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

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

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

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

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

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

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

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

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

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

                form.folio = numeroDeCheque;
                form.numeroDiario = numeroDiario;
                form.FileName = FileName;
                form.FileNameToPDF = FileNameToPDF;
                form.vuelveAHacerElCheque(true);
                form.ShowDialog();
        }
Example #2
0
 private void cambiarEspaciosDeChequeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     previewCheque formP = new previewCheque();
     formP.Show();
 }