Пример #1
0
        private void CertificarButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("¿ Esta seguro que el estudiante " + dataGridView1.CurrentRow.Cells[4].Value.ToString() + " con la cedula " + dataGridView1.CurrentRow.Cells[3].Value.ToString() + " se Certificó ?", "ATENCION", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                try
                {
                    string NombreEstudiante    = dataGridView1.CurrentRow.Cells[4].Value.ToString();
                    string cedulaEstudiante    = dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    string DiplomadoEstudiante = dataGridView1.CurrentRow.Cells[5].Value.ToString();
                    string idDiploPagado       = dataGridView1.CurrentRow.Cells[0].Value.ToString();

                    Consultas.HacerConsulta("update Diplomado_pagado set Estado = 'Certificado' , FechaEstado='" + DateTime.Now.ToString("yyyy-MM-dd") + "' where IdDiploPagado = " + idDiploPagado + "");
                    Consultas.comando.ExecuteNonQuery();

                    int UltimoNumActa = Consultas.devolverUnEntero("select Max(NumConsecutivo) as n from LibroActa");
                    if (UltimoNumActa == 0)
                    {
                        UltimoNumActa = Consultas.devolverUnEntero("select UltimoRegistro as n from UltimoRegistro") + 1;
                    }
                    else
                    {
                        UltimoNumActa++;
                    }

                    string NumActa = "DI" + Convert.ToDateTime(Consultas.DevolverUnString("select FechaEstado as n from Diplomado_pagado where IdDiploPagado = '" + idDiploPagado + "'")).ToString("ddMMyyyy") + UltimoNumActa;

                    int ultimoIdActa = Consultas.InsertDevovliendoId("insert into LibroActa (IdPersonaRegistrada,IdDiplomado,FechaCreated,NumConsecutivo,NumActa) "
                                                                     + "values (" + dataGridView1.CurrentRow.Cells[2].Value.ToString() + "," + dataGridView1.CurrentRow.Cells[1].Value.ToString() + ",'" + DateTime.Now.ToString("yyyy-MM-dd") + "',1,'" + NumActa + "')");

                    Consultas.HacerConsulta("update LibroActa set NumConsecutivo = " + (UltimoNumActa) + " where IdLibroActa = " + ultimoIdActa);
                    Consultas.comando.ExecuteNonQuery();

                    Consultas.HacerConsulta("update Diplomado_pagado set IdLibroActa = " + ultimoIdActa + " where IdDiploPagado = " + idDiploPagado);
                    Consultas.comando.ExecuteNonQuery();

                    ReportParameter NombreCompleto = new ReportParameter("NombreCompleto", NombreEstudiante.ToUpper().Trim());
                    ReportParameter Cedula         = new ReportParameter("Cedula", cedulaEstudiante.ToString());
                    //ReportParameter NumeroActa = new ReportParameter("NumeroActa", " DI2018070180".ToUpper().Trim());
                    ReportParameter NumeroActa = new ReportParameter("NumeroActa", NumActa.ToUpper().Trim());
                    //ReportParameter Diplomado = new ReportParameter("Diplomado", " INCLUSION EDUCATIVA EN LOS AMBIENTES DE APRENDIZAJE ".ToUpper().Trim());
                    ReportParameter Diplomado = new ReportParameter("Diplomado", DiplomadoEstudiante.ToUpper().Trim());

                    string Mes   = MonthName(DateTime.Now.Month);
                    string dia   = DateTime.Now.ToString("dd");
                    string año   = DateTime.Now.ToString("yyyy");
                    string fecha = Mes + " " + dia + " del " + año;

                    ReportParameter Fecha = new ReportParameter("Fecha", fecha.Trim());
                    this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { NombreCompleto, Cedula, NumeroActa, Diplomado, Fecha });

                    this.reportViewer1.RefreshReport();

                    byte[] pdfContent = reportViewer1.LocalReport.Render("PDF");

                    string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Diplomas_Grupo_Colombiano";

                    if (!Directory.Exists(path))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(path);
                    }
                    // Generar el archivo PDF
                    string pdfPath = path + @"\" + cedulaEstudiante + "-" + NumActa + ".pdf";
                    System.IO.FileStream pdfFile = new System.IO.FileStream(pdfPath, System.IO.FileMode.Create);
                    pdfFile.Write(pdfContent, 0, pdfContent.Length);
                    pdfFile.Close();

                    CargarTabla();
                    notifyIcon1.Visible = true;
                    notifyIcon1.ShowBalloonTip(400);
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Пример #2
0
        public void actualizarBaseDatos(string archivo, Form1 f)
        {
            Cursor.Current = Cursors.WaitCursor;
            string          cadenaConexionExcel = "provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + archivo + "';Extended Properties=Excel 12.0;";
            OleDbConnection conexionExcel       = new OleDbConnection(cadenaConexionExcel);


            //Traigo el Maximo IdPag que existe en la BD
            int MaxIdPag = 0;

            try
            {
                MaxIdPag = Convert.ToInt32(Consultas.DevolverUnString("select max(IdPag) as n from Diplo_Cursos"));
            }
            catch (Exception) { MaxIdPag = 0; }

            //Hago la consulta
            string consulta = "select * from [H1$] where ID> " + MaxIdPag + " and TITLE like '%Diplomado%' or TITLE like '%Curso%' order by ID";


            //Abro la conexion para el excel
            conexionExcel.Open();
            OleDbDataReader lector       = null;
            OleDbCommand    comandoExcel = new OleDbCommand(consulta, conexionExcel);

            lector = comandoExcel.ExecuteReader();

            //Traigo a partir del Maximo idpag de la bd lo que hay en el excel
            string IdPersona = "";

            while (lector.Read())
            {
                int idPag = Convert.ToInt32(lector["ID"].ToString());
                IdPersona = Consultas.DevolverUnString("select IdPersonaRegistrada as n from Persona_Registrada where Identificacion = '" + lector["Número de Identificación:"].ToString() + "' and Estado is null");
                if (IdPersona == "")
                {
                    //Insertar la persona
                    string identificacion = lector["Número de Identificación:"].ToString();
                    string pNombre        = lector["Primer Nombre:"].ToString();
                    string sNombre        = lector["Segundo Nombre:"].ToString();
                    string pApellido      = lector["Primer Apellido:"].ToString();
                    string sApellido      = lector["Segundo Apellido:"].ToString();
                    string Genero         = lector["Genero:"].ToString();
                    string Pais           = lector["País de Residencia:"].ToString();
                    string Ciudad         = lector["Ciudad de Residencia:"].ToString();
                    string direccion      = lector["Dirección de Residencia:"].ToString();
                    string Telefono       = lector["Teléfono de Contacto:"].ToString();
                    string Correo         = lector["Email:"].ToString();
                    IdPersona = Consultas.InsertDevovliendoId("insert into Persona_Registrada (Identificacion,PNombre,SNombre,PApellido,SApellido,Genero,Pais,Ciudad,Direccion,Telefono,Correo) values ('" + identificacion + "','" + pNombre + "','" + sNombre + "','" + pApellido + "','" + sApellido + "','" + Genero + "','" + Pais + "','" + Ciudad + "','" + direccion + "','" + Telefono + "','" + Correo + "')").ToString();
                }
                //Sigue el proceso

                int diplomado = 0;
                int curso     = 0;
                try
                {
                    diplomado = Convert.ToInt32(lector["Nombre del Diplomado Virtual a realizar:"].ToString());
                }
                catch (Exception)
                {
                    curso = Convert.ToInt32(lector["Nombre del Curso a realizar:"].ToString());
                }


                //Se valida si el codigo de asesor es correcto
                int codAsesor = 0;
                try
                {
                    codAsesor = Convert.ToInt32(lector["Digite el Codigo del Asesor:"].ToString());
                }
                catch (Exception) { }

                //Consultas.HacerConsulta("insert into Diplo_Cursos (IdPag,IdPersonaRegistrada,IdDiplomado,CodAsesor, IdCursoG,Pagado, DateCreated) values (" + idPag + "," + IdPersona + "," + diplomado + "," + codAsesor + "," + curso + ",'false','" + DateTime.Now.ToString("yyyy-MM-dd") + "')");
                try
                {
                    if (diplomado != 0)
                    {
                        if (codAsesor != 0)
                        {
                            Consultas.HacerConsulta("insert into Diplo_Cursos (IdPag,IdPersonaRegistrada,IdDiplomado,CodAsesor,Pagado, DateCreated) values (" + idPag + "," + IdPersona + "," + diplomado + "," + codAsesor + ",'false','" + DateTime.Now.ToString("yyyy-MM-dd") + "')");
                        }
                        else
                        {
                            Consultas.HacerConsulta("insert into Diplo_Cursos (IdPag,IdPersonaRegistrada,IdDiplomado,Pagado, DateCreated) values (" + idPag + "," + IdPersona + "," + diplomado + ",'false','" + DateTime.Now.ToString("yyyy-MM-dd") + "')");
                        }
                    }
                    else
                    {
                        Consultas.HacerConsulta("insert into Diplo_Cursos (IdPag,IdPersonaRegistrada, IdCursoG,Pagado, DateCreated) values (" + idPag + "," + IdPersona + "," + curso + ",'false','" + DateTime.Now.ToString("yyyy-MM-dd") + "')");
                    }
                    Consultas.comando.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    MessageBox.Show("Algun diplomado o Curso no esta registrado en la Base de datos");
                }
            }
            conexionExcel.Close();
            f.notifyIcon1.Visible = true;
            f.notifyIcon1.ShowBalloonTip(400);
            Cursor.Current = Cursors.Default;
        }