Ejemplo n.º 1
0
        public void CrearPdf()
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                if (tdbgCotizacion.RowCount == 0)
                {
                    Cursor = Cursors.Default;
                    return;
                }

                if (CbProveedor.SelectedValue == null)
                {
                    MessageBox.Show("Seleccione el Proveedor.", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Cursor = Cursors.Default;
                    return;
                }
                dtCotizacion.AcceptChanges();

                DataView dvProveedor = new DataView(dtProveedor);
                dvProveedor.RowFilter = "IDProveedor='" + CbProveedor.SelectedValue + "'";
                string EmailProveedor = Convert.ToString(dvProveedor[0][2]);
                string NomProveedor   = Convert.ToString(dvProveedor[0][1]);
                //create pdf document
                this.PdfCotizacion.Clear();
                this.PdfCotizacion.DocumentInfo.Title = "COTIZACIÓN";

                //calculate page rect (discounting margins)
                RectangleF rcPage = GetPageRect();
                RectangleF rc     = rcPage;

                Image     img = Properties.Resources.HalleyLogo;
                Rectangle RC  = new Rectangle(30, 12, 160, 44);
                PdfCotizacion.DrawImage(img, RC);
                PdfCotizacion.DrawRectangle(Pens.White, RC);

                // add title
                Font titleFont   = new Font("Tahoma", 20, FontStyle.Regular);
                Font detalleFont = new Font("Tahoma", 15, FontStyle.Regular);

                rc = RenderParagraph(PdfCotizacion.DocumentInfo.Title, titleFont, rcPage, rc, false, 3);
                RenderParagraph("Proveedor : " + NomProveedor, detalleFont, rcPage, rc, false, 3);
                rc = RenderParagraph("Comprador : " + AppSettings.ApeNom_Login, detalleFont, rcPage, rc, false, 2);


                rc = RenderTable(rc, rcPage, dtCotizacion, "ProductoID", "Descripcion", "UM", "CantidadSolicitada");

                // second pass to number pages
                AddFooters();

                //enviar correo
                string NomArchivo = AppSettings.EmpresaID + "COTIZACION.pdf";
                string fileName   = "\\\\192.168.1.21\\cotizacion\\" + NomArchivo;
                this.PdfCotizacion.Save(fileName);
                string ruta = "D:\\COTIZACION\\" + NomArchivo;

                string Asunto  = "COTIZACIÓN " + AppSettings.NomEmpresa;
                string Mensaje = "Deseo que me cotizé los siguientes productos.\nAdjuntado en el pdf.\n\nREMITIR A: " + AppSettings.UserEmail;
                new CL_Helper().SendMail(Asunto, Mensaje, EmailProveedor, AppSettings.UserEmail, ruta);
                MessageBox.Show("Se envió la cotización correctamente.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dtCotizacion.Rows.Clear();
                this.tdbgCotizacion.SetDataBinding(dtCotizacion, "", true);

                Get_Requerimientos(AppSettings.EmpresaID);
                //Process.Start(fileName);

                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                MessageBox.Show(ex.Message, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }