Ejemplo n.º 1
0
        protected void CmdGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                Conexion conn = new Conexion();
                conn.IniciarConexion();
                string imagen = null;
                string abierto = "";

                if (subir_img.PostedFile.ContentLength > 0)
                {
                    string dir = Server.MapPath(@"~/images/cursos");
                    imagen = new SubirArchivos().SubirImagen(dir, subir_img.PostedFile);
                }
                else
                    if (img_bdd != null)
                        imagen = img_bdd;

                if(checkabierto.Checked)
                    abierto = "1";
                else
                    abierto = "0";

                string sql = "UPDATE cursos SET id_curso='"
                    + txtrcod.Text + "', nombre='" + txtnombre.Text
                    + "', estado='" + dropestado.Text + "', imagen_curso='"
                    + imagen + "',abierto=" + abierto + " WHERE id_curso ='" + curso_id + "'" ;

                bool ok = conn.Get_Consulta_booleana(sql);
                if (ok)
                {
                    lblmensaje.InnerHtml = "Curso se ha editado con exito ";
                    lblmensaje.InnerHtml += " ";
                    lblmensaje.InnerHtml += "<a href='" + Session["Previa"].ToString() + "'>Regresar al curso</a>";
                }
                else
                    lblmensaje.InnerHtml = "Opps Hubo un error, Favor intentar denuevo ";

                lblmensaje.Visible = true;
                conn.CerrarConexion();

            }
            catch { }
        }
Ejemplo n.º 2
0
        protected void CmdGuardar_Click(object sender, EventArgs e)
        {
            Conexion conn = new Conexion();
            lblmensaje.Visible = true;
            try
            {
                if (checkacepto.Checked == false)
                {
                    lblmensaje.InnerText = "Acepta los terminos y condiciones de uso";
                    return;
                }
                string codigo = txtrcod.Text;
                string nombre = txtnombre.Text;
                if (codigo == "")
                {
                    if (checkcod.Checked == true)
                    {
                        string asignar_cod = null;
                        if (nombre.Length >= 4)
                            asignar_cod = nombre.Substring(0, 4)
                                + new Random(DateTime.Now.Millisecond).Next(0, 9).ToString()
                                + new Random(DateTime.Now.Millisecond).Next(0, 9).ToString()
                                + new Random(DateTime.Now.Millisecond).Next(0, 9).ToString();
                        else if (nombre.Length < 4)
                            asignar_cod = nombre
                                + new Random(DateTime.Now.Millisecond).Next(0, 9).ToString()
                                + new Random(DateTime.Now.Millisecond).Next(0, 9).ToString()
                                + new Random(DateTime.Now.Millisecond).Next(0, 9).ToString()
                                + new Random(DateTime.Now.Millisecond).Next(0, 9).ToString();
                        codigo = asignar_cod;
                    }
                    else
                    {

                       lblmensaje.InnerText = "Asigna un codigo del curso impartido o coloca autogenerar";
                       return;
                    }
                }

                conn.IniciarConexion();
                int abierto_cerrado = 0;

                if (checkabierto.Checked == true)
                    abierto_cerrado = 1;
                else
                    abierto_cerrado = 0;

                HttpPostedFile ImgFile = subir_img.PostedFile;
                string imagen_curso = null;
                if (ImgFile.ContentLength != 0)
                {
                    SubirArchivos archivar = new SubirArchivos();
                    string mapeo = Server.MapPath(@"~/images/cursos");
                    imagen_curso = archivar.SubirImagen(mapeo, ImgFile);
                }

                string id_periodo = null;
                id_periodo = Encriptador.Encriptar_Md5(codigo);

                string sql = "INSERT INTO cursos (id_curso , nombre , estado , imagen_curso , id_docente , id_periodos , fecha_inicio , abierto) VALUES ('"
                    + codigo + "','" + nombre + "',1" + ",'"
                    + imagen_curso + "','" + id_usuario + "','"
                    + id_periodo + "','"
                    + Seguridad.FormatoFecha(DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), DateTime.Now.Day.ToString())
                    + "'," + abierto_cerrado + ")";

                bool consulta = conn.Get_Consulta_booleana(sql);

                if (consulta)
                    lblmensaje.InnerHtml = "Curso creado con exito ";
                else
                    lblmensaje.InnerHtml = "No se pudo crear el curso ,el servidor esta ocupado";

                conn.CerrarConexion();
            }

            catch (Exception ex)
            {
                try
                {
                    lblmensaje.InnerText = "HUBO UN ERROR INESPERADO , INTENTAR MAS TARDE ESTA PETICION";
                    Log.Set_Log_Error(ex.Message, "add curso", id_usuario);
                    conn.CerrarConexion();
                }
                catch { }
            }
        }