protected void cargarJuego() { DataTable tabla = (DataTable)Session["Juego"]; string codJuego = tabla.Rows[0][0].ToString(); txb_Precio.Value = tabla.Rows[0][4].ToString().Replace(',', '.').Substring(0, tabla.Rows[0][4].ToString().Length - 2); lbl_stockActual.Text = tabla.Rows[0][5].ToString(); if (lbl_stockActual.Text != "0") { if (Session["Stock"] == null) { Session["Stock"] = (int)tabla.Rows[0][5]; } funcionesJuegos fJue = new funcionesJuegos(); AccesoDatos ds = new AccesoDatos(); tabla = ds.ObtenerTabla("Codigos", "SELECT CodActivacion FROM CodigosActivacion WHERE CodJuego = '" + codJuego + "' AND Disponibilidad = 1"); foreach (DataRow row in tabla.Rows) { lb_CodJuegos.Items.Add(row[0].ToString()); if (Session["CodigosActivacion"] == null) { Session["CodigosActivacion"] = fJue.crearTablaCodigos(); } fJue.AgregarFilaCodigos((DataTable)Session["CodigosActivacion"], row[0].ToString(), codJuego, true); } } }
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(); } }
protected void btn_siguiente_Click(object sender, EventArgs e) { if (Page.IsValid) { funcionesJuegos fJue = new funcionesJuegos(); if (Session["Juego"] == null) { Session["Juego"] = fJue.crearTabla(); } if (Session["Modificar"] == null) { jue.GenerarCod(); jue.precio = 0; jue.stock = 0; } jue.nombre = txb_nombre.Value.Replace('\'', '´'); jue.empresa = txb_empresa.Value; jue.tipo = txb_tipo.Value; jue.consola = rbl_listaConsolas.SelectedItem.ToString(); jue.descripcion = txb_descripcion.Value; jue.requisitos = txb_requisitos.Value; fJue.AgregarFila((DataTable)Session["Juego"], jue); Response.Redirect("AgregarJuego(Paso2).aspx"); } }
protected void btn_Agregar_Click(object sender, EventArgs e) { if (cv_codigo.IsValid) { if (Session["Stock"] == null) { Session["Stock"] = 0; } lb_CodJuegos.Items.Add(modificarCodigo()); Session["Stock"] = (int)Session["Stock"] + 1; lbl_stockActual.Text = Session["Stock"].ToString(); funcionesJuegos fJue = new funcionesJuegos(); DataTable tabla = (DataTable)Session["Juego"]; string codJuego = tabla.Rows[0][0].ToString(); if (Session["CodigosActivacion"] == null) { Session["CodigosActivacion"] = fJue.crearTablaCodigos(); } fJue.AgregarFilaCodigos((DataTable)Session["CodigosActivacion"], modificarCodigo(), codJuego, false); txb_codigo.Text = ""; } }
protected void btn_siguiente_Click(object sender, EventArgs e) { if (Page.IsValid) { funcionesJuegos fJue = new funcionesJuegos(); DataTable tabla = (DataTable)Session["Juego"]; if (Session["Descuento"] == null) { Session["Descuento"] = fJue.crearTablaDescuento(); } if (Session["Modificar"] == null) { desc.GenerarCod(); } else { cargarCodDescuento(desc); } desc.codJuego = tabla.Rows[0][0].ToString(); 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.AgregarFilaDescuento((DataTable)Session["Descuento"], desc); Response.Redirect("AgregarJuego(Paso4).aspx"); } }
protected void cargarDataTableImagenes() { funcionesJuegos fJue = new funcionesJuegos(); AccesoDatos ds = new AccesoDatos(); DataTable tabla = new DataTable(); tabla = (DataTable)Session["Juego"]; string codJuego = tabla.Rows[0][0].ToString(); tabla = ds.ObtenerTabla("Imagenes", "SELECT codImagen, rutaImagen, primeraImagen FROM Imagenes WHERE CodJuego = '" + codJuego + "'"); if (Session["Imagenes"] == null) { Session["Imagenes"] = fJue.crearTablaImagenes(); } byte[] bytesImagen = null; int i = 1; foreach (DataRow row in tabla.Rows) { string rutaImagen = AppDomain.CurrentDomain.BaseDirectory + row[1].ToString().Remove(0, 2).Replace('/', '\\'); bytesImagen = File.ReadAllBytes(rutaImagen); fJue.AgregarFilaImagenes((DataTable)Session["Imagenes"], row[0].ToString(), row[1].ToString(), (bool)row[2], bytesImagen); if ((bool)row[2]) { lbl_portada.Text = i.ToString(); } i++; } }
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 agregarImagenAbasededatos() { funcionesJuegos fJue = new funcionesJuegos(); DataTable tabla = (DataTable)Session["Imagenes"]; DataTable DT = (DataTable)Session["Juego"]; foreach (DataRow row in tabla.Rows) { if (Session["Modificar"] == null) { fJue.AgregarImagen(GenerarCodImagen(), DT.Rows[0][0].ToString(), row[1].ToString(), (bool)row[2]); } else { if (row[0].ToString() == "null") { fJue.AgregarImagen(GenerarCodImagen(), DT.Rows[0][0].ToString(), row[1].ToString(), (bool)row[2]); } else { if (!(bool)row[2]) { fJue.cambiarEstadoImagen(row[0].ToString(), DT.Rows[0][0].ToString(), "false"); } else { fJue.cambiarEstadoImagen(row[0].ToString(), DT.Rows[0][0].ToString(), "true"); } } } } }
protected void btn_eliminarTodo_Click(object sender, EventArgs e) { if (lb_CodJuegos.Items.Count > 0) { DataTable tabla = (DataTable)Session["CodigosActivacion"]; foreach (DataRow row in tabla.Rows) { if ((bool)row[3]) { funcionesJuegos fJue = new funcionesJuegos(); if (Session["CodigosEliminar"] == null) { Session["CodigosEliminar"] = fJue.crearTablaCodActivacionEliminar(); } fJue.AgregarFilaCodActivacionEliminar((DataTable)Session["CodigosEliminar"], row[0].ToString()); } } lb_CodJuegos.Items.Clear(); Session["Stock"] = null; lbl_stockActual.Text = "0"; Session["CodigosActivacion"] = null; } }
protected void cargarSessionImagenes(string rutaImagen, FileUpload file) { funcionesJuegos fJue = new funcionesJuegos(); if (Session["Imagenes"] == null) { Session["Imagenes"] = fJue.crearTablaImagenes(); } fJue.AgregarFilaImagenes((DataTable)Session["Imagenes"], "null", rutaImagen, false, file.FileBytes); }
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 btn_GuardarCambios_Click(object sender, EventArgs e) { if (Page.IsValid) { funcionesJuegos fJue = new funcionesJuegos(); ActualizarClaseUsuario(us); fJue.ActualizarUsuario(us); } else { panelDcuenta.Attributes.Add("display", "block"); panelDpersonales.Attributes.Add("display", "block"); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["c"] != null) { string codigoJuego = Request.QueryString["c"]; if (!Page.IsPostBack) { cargarImagenes(codigoJuego); cargarCarta(codigoJuego); funcionesJuegos fJue = new funcionesJuegos(); fJue.insertarVisualizacion(codigoJuego, fJue.generarCodVisualizacion(), DateTime.Now); } } }
protected void btn_Eliminar_Click(object sender, EventArgs e) { if (Session["Imagenes"] != null) { DataTable tabla = (DataTable)Session["Imagenes"]; if (txb_posicionSeleccionada.Value != "null") { int pos = Convert.ToInt32(txb_posicionSeleccionada.Value); if (tabla.Rows[pos][0].ToString() != "null") { funcionesJuegos fJue = new funcionesJuegos(); if (Session["ImagenesAelminiar"] == null) { Session["ImagenesAelminiar"] = fJue.crearTablaImagenesEliminar(); } fJue.AgregarFilaImagenesEliminar((DataTable)Session["ImagenesAelminiar"], tabla.Rows[pos][0].ToString(), tabla.Rows[pos][1].ToString()); } if (tabla.Rows.Count > 0) { if ((bool)tabla.Rows[pos][2] == true) { lbl_portada.Text = "0"; } tabla.Rows[pos].Delete(); Session["Imagenes"] = tabla; } else { lbl_portada.Text = "0"; Session["Imagenes"] = null; } Session["CantImagenes"] = (int)Session["CantImagenes"] - 1; txb_posicionSeleccionada.Value = "null"; AgregarImagen(); } } }
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>"); } } } }
protected void actulizarDescuento() { Descuento desc = new Descuento(); funcionesJuegos fJue = new funcionesJuegos(); 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.ActualizarDescuento(desc); } }
protected void btn_eliminar_Click(object sender, EventArgs e) { if (lb_CodJuegos.Items.Count > 0) { if (lb_CodJuegos.SelectedIndex >= 0) { if (Session["CodigosActivacion"] != null) { DataTable tabla = (DataTable)Session["CodigosActivacion"]; if ((bool)tabla.Rows[lb_CodJuegos.SelectedIndex][3]) { funcionesJuegos fJue = new funcionesJuegos(); if (Session["CodigosEliminar"] == null) { Session["CodigosEliminar"] = fJue.crearTablaCodActivacionEliminar(); } fJue.AgregarFilaCodActivacionEliminar((DataTable)Session["CodigosEliminar"], tabla.Rows[lb_CodJuegos.SelectedIndex][0].ToString()); } tabla.Rows[lb_CodJuegos.SelectedIndex].Delete(); if (tabla.Rows.Count <= 0) { Session["CodigosActivacion"] = null; } } string codigo = lb_CodJuegos.SelectedItem.ToString(); lb_CodJuegos.Items.RemoveAt(lb_CodJuegos.SelectedIndex); if ((int)Session["Stock"] > 0) { Session["Stock"] = (int)Session["Stock"] - 1; } lbl_stockActual.Text = Session["Stock"].ToString(); } } }