Пример #1
0
        protected void btn_guardarCambios_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                funcionesJuegos fJue = new funcionesJuegos();
                ClaseJuego      jue  = new ClaseJuego();
                Descuento       desc = new Descuento();

                string   aux     = Request.Form["ip_listboxCodigos"].ToString();
                string[] codigos = aux.Split('-');

                lbl_stockActual.Text = (codigos.Length - 1).ToString();

                jue.GenerarCod();
                jue.nombre      = txb_nombre.Text;
                jue.empresa     = txb_empresa.Text;
                jue.tipo        = txb_tipo.Value;
                jue.precio      = Convert.ToDecimal(txb_Precio.Value.Replace(".", ","));
                jue.stock       = Convert.ToInt32(lbl_stockActual.Text);
                jue.consola     = rbl_listaConsolas.SelectedItem.Text;
                jue.descripcion = txb_descripcion.Text;
                jue.requisitos  = txb_requisitos.Text;

                desc.GenerarCod();
                desc.codJuego    = jue.codJuego;
                desc.porcentaje  = Convert.ToInt32(txb_Porcentaje.Value);
                desc.fechaInicio = Convert.ToDateTime(txb_FechaInicio.Value);
                desc.fechaFin    = Convert.ToDateTime(txb_FechaFin.Value);
                desc.estado      = chx_Disponibilidad.Checked;

                fJue.AgregarJuego(jue);
                fJue.AgregarDescuento(desc);

                foreach (string codigo in codigos)
                {
                    if (codigo != string.Empty)
                    {
                        fJue.AgregarCodActivacion(codigo, jue.codJuego);
                    }
                }

                guardarImagenes();

                if (Session["Imagenes"] != null)
                {
                    string[] rutasAux = (string[])Session["Imagenes"];
                    bool     primero  = true;
                    for (int i = 0; i < rutasAux.Length; i++)
                    {
                        if (rutasAux[i] != string.Empty)
                        {
                            fJue.AgregarImagen(GenerarCodImagen(), jue.codJuego, rutasAux[i], primero);
                            primero = false;
                        }
                    }
                }

                limpiarPagina();
            }
        }
        public int ActualizarJuego(ClaseJuego jue)
        {
            SqlCommand comando = new SqlCommand();

            ArmarParametrosAgregarJuego(ref comando, jue);
            return(ds.EjecutarProcedimientoAlmacenado(comando, "spActualizarJuego"));
        }
        protected void actualizarCodigoActivacion(ClaseJuego jue)
        {
            if (Session["CodigosActivacion"] != null)
            {
                DataTable codActivacion = (DataTable)Session["CodigosActivacion"];

                funcionesJuegos fJue = new funcionesJuegos();

                foreach (DataRow row in codActivacion.Rows)
                {
                    if (!(bool)row[3])
                    {
                        fJue.AgregarCodActivacion(row[0].ToString(), row[1].ToString());
                    }
                }
            }

            if (Session["CodigosEliminar"] != null)
            {
                DataTable       codEliminar = (DataTable)Session["CodigosEliminar"];
                FuncionesCompra fCompra     = new FuncionesCompra();

                foreach (DataRow row in codEliminar.Rows)
                {
                    fCompra.darBajaCodActivacion(row[0].ToString(), jue.codJuego);
                }
            }
        }
        protected void agregarDescuento(ClaseJuego jue)
        {
            Descuento       desc = new Descuento();
            funcionesJuegos fJue = new funcionesJuegos();

            if (Session["Descuento"] != null)
            {
                DataTable tabla = (DataTable)Session["Descuento"];

                foreach (DataRow row in tabla.Rows)
                {
                    desc.codDescuento = row[0].ToString();
                    desc.codJuego     = row[1].ToString();
                    desc.porcentaje   = (int)row[2];
                    desc.fechaInicio  = (DateTime)row[3];
                    desc.fechaFin     = (DateTime)row[4];
                    desc.estado       = (bool)row[5];

                    fJue.AgregarDescuento(desc);
                }
            }
            else
            {
                desc.GenerarCod();
                desc.codJuego    = jue.codJuego;
                desc.porcentaje  = 0;
                desc.fechaInicio = DateTime.Now;
                desc.fechaFin    = DateTime.Now;
                desc.estado      = false;

                fJue.AgregarDescuento(desc);
            }
        }
 protected void agregarCodigoActivacion(ClaseJuego jue)
 {
     if (jue.stock > 0)
     {
         funcionesJuegos fJue  = new funcionesJuegos();
         DataTable       tabla = (DataTable)Session["CodigosActivacion"];
         foreach (DataRow row in tabla.Rows)
         {
             fJue.AgregarCodActivacion(row[0].ToString(), row[1].ToString());
         }
     }
 }
        protected void eliminarFisicamenteImagen(ClaseJuego jue)
        {
            funcionesJuegos fJue  = new funcionesJuegos();
            DataTable       tabla = (DataTable)Session["ImagenesAelminiar"];

            foreach (DataRow row in tabla.Rows)
            {
                fJue.EliminarImagenBD(row[0].ToString(), jue.codJuego);

                string rutaImagen = AppDomain.CurrentDomain.BaseDirectory + row[1].ToString().Remove(0, 2).Replace('/', '\\');
                File.Delete(rutaImagen);
            }
        }
        protected void cargarClaseJuego(ClaseJuego jue)
        {
            AccesoDatos ds    = new AccesoDatos();
            DataTable   tabla = new DataTable();

            string codJuego = Request.QueryString["cod"];

            tabla = ds.ObtenerTabla("Juego", "SELECT precio, stock FROM juegos WHERE codJuego = '" + codJuego + "'");

            jue.codJuego = codJuego;
            jue.precio   = (decimal)tabla.Rows[0][0];
            jue.stock    = (int)tabla.Rows[0][1];
        }
        protected void cargarClaseJuego(ClaseJuego jue)
        {
            DataTable tabla = (DataTable)Session["Juego"];

            jue.codJuego    = tabla.Rows[0][0].ToString();
            jue.nombre      = tabla.Rows[0][1].ToString();
            jue.empresa     = tabla.Rows[0][2].ToString();
            jue.tipo        = tabla.Rows[0][3].ToString();
            jue.precio      = (decimal)tabla.Rows[0][4];
            jue.stock       = (int)tabla.Rows[0][5];
            jue.consola     = tabla.Rows[0][6].ToString();
            jue.descripcion = tabla.Rows[0][7].ToString();
            jue.requisitos  = tabla.Rows[0][8].ToString();
        }
        public void AgregarFila(DataTable tabla, ClaseJuego jue)
        {
            DataRow dr = tabla.NewRow();

            dr["codJuego"]    = jue.codJuego;
            dr["nombre"]      = jue.nombre;
            dr["empresa"]     = jue.empresa;
            dr["tipo"]        = jue.tipo;
            dr["precio"]      = jue.precio;
            dr["stock"]       = jue.stock;
            dr["consola"]     = jue.consola;
            dr["descripcion"] = jue.descripcion;
            dr["Requisitos"]  = jue.requisitos;
            tabla.Rows.Add(dr);
        }
        protected void btn_FinalizarModificar_Click(object sender, EventArgs e)
        {
            if (sesionesCreadas())
            {
                if (Page.IsValid)
                {
                    if (lbl_portada.Text != "0")
                    {
                        funcionesJuegos fJue = new funcionesJuegos();
                        ClaseJuego      jue  = new ClaseJuego();

                        cargarClaseJuego(jue);
                        fJue.ActualizarJuego(jue);
                        actualizarCodigoActivacion(jue);
                        if (Session["Descuento"] != null)
                        {
                            actulizarDescuento();
                        }

                        if (Session["ImagenesAelminiar"] != null)
                        {
                            eliminarFisicamenteImagen(jue);
                        }

                        agregarImagenAbasededatos();
                        agregarFisicamenteLaImagen();

                        Session["CodigosEliminar"]   = null;
                        Session["Juego"]             = null;
                        Session["Stock"]             = null;
                        Session["CodigosActivacion"] = null;
                        Session["Descuento"]         = null;
                        Session["Imagenes"]          = null;
                        Session["CantImagenes"]      = null;
                        Session["ImagenesAelminiar"] = null;
                        Page.ClientScript.RegisterStartupScript(GetType(), "scripts", "<script>alert('Juego modificado correctamente')</script>");
                        Response.Redirect("Home.aspx");
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "scripts", "<script>alert('Seleccione una imagen de portada')</script>");
                    }
                }
            }
        }
        private void ArmarParametrosAgregarJuego(ref SqlCommand Comando, ClaseJuego jue)
        {
            Comando.Parameters.Add("@CODJUEGO", SqlDbType.NVarChar, 10);
            Comando.Parameters.Add("@NOMBRE", SqlDbType.NVarChar, 100);
            Comando.Parameters.Add("@EMPRESA", SqlDbType.NVarChar, 50);
            Comando.Parameters.Add("@TIPO", SqlDbType.NVarChar, 15);
            Comando.Parameters.Add("@PRECIO", SqlDbType.SmallMoney);
            Comando.Parameters.Add("@STOCK", SqlDbType.Int);
            Comando.Parameters.Add("@CONSOLA", SqlDbType.NVarChar, 15);
            Comando.Parameters.Add("@DESCRIPCION", SqlDbType.NVarChar, 2000);
            Comando.Parameters.Add("@REQUISITOS", SqlDbType.NVarChar, 1000);


            Comando.Parameters["@CODJUEGO"].Value    = jue.codJuego;
            Comando.Parameters["@NOMBRE"].Value      = jue.nombre;
            Comando.Parameters["@EMPRESA"].Value     = jue.empresa;
            Comando.Parameters["@TIPO"].Value        = jue.tipo;
            Comando.Parameters["@PRECIO"].Value      = jue.precio;
            Comando.Parameters["@STOCK"].Value       = jue.stock;
            Comando.Parameters["@CONSOLA"].Value     = jue.consola;
            Comando.Parameters["@DESCRIPCION"].Value = jue.descripcion;
            Comando.Parameters["@REQUISITOS"].Value  = jue.requisitos;
        }