protected void btnActualizar_Click(object sender, EventArgs e) { MatrizEntidad matriz = new MatrizEntidad(); matriz.nombreArchivo = txtNombre.Text; matriz.cantidadPuntadas = int.Parse(txtCantidadPuntadas.Text); matriz.cantidadColores = int.Parse(txtCantidadColores.Text); matriz.precio = decimal.Parse(txtPrecio.Text); matriz.aplique = 0; if (cbxAplique.Checked == true) { matriz.aplique = 1; } matriz.fechaCreacion = DateTime.Parse(txtFechaCreacion.Text); matriz.tamaño = int.Parse(ddlTamaño.SelectedValue); MatrizGestor.ActualizarMatriz(matriz); cargarMatrices(); limpiarControles(); resetearGuardar(); txtNombre.Enabled = true; }
public static void ActualizarMatriz(MatrizEntidad matriz) { SqlConnection connection = new SqlConnection(); SqlCommand command = new SqlCommand(); try { connection.ConnectionString = cadenaConexion; connection.Open(); string sql = "UPDATE Matriz SET cantidadPuntadas=@CantidadPuntadas, cantidadColores=@CantidadColores, fechaCreacion=@FechaCreacion, aplique=@Aplique, precio=@Precio, idTamaño=@Tamaño WHERE nombreArchivo=@Nombre"; command.CommandText = sql; command.Connection = connection; command.Parameters.AddWithValue("@Nombre", matriz.nombreArchivo); command.Parameters.AddWithValue("@CantidadPuntadas", matriz.cantidadPuntadas); command.Parameters.AddWithValue("@CantidadColores", matriz.cantidadColores); command.Parameters.AddWithValue("@FechaCreacion", matriz.fechaCreacion); command.Parameters.AddWithValue("@Precio", matriz.precio); command.Parameters.AddWithValue("@Aplique", matriz.aplique); command.Parameters.AddWithValue("@Tamaño", matriz.tamaño); command.ExecuteNonQuery(); } catch(ApplicationException ex) { } catch(SqlException ex) { } finally { if(connection.State == ConnectionState.Open) { connection.Close(); } } }
public static MatrizEntidad Buscar(string nombre) { MatrizEntidad m = new MatrizEntidad(); SqlConnection connection = new SqlConnection(); SqlCommand command = new SqlCommand(); try { connection.ConnectionString = cadenaConexion; connection.Open(); string sql = "SELECT m.nombreArchivo AS 'nombreArchivo', m.cantidadPuntadas AS 'cantidadPuntadas', m.precio AS 'precio', m.cantidadColores AS 'cantidadColores', m.fechaCreacion AS 'fechaCreacion', m.aplique AS 'aplique', t.nombre AS 'tamaño'"; sql += "FROM Matriz AS m JOIN Tamaño AS t on (m.idTamaño = t.id)"; command.CommandText = sql; command.Connection = connection; SqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { m.apliqueBooleano = bool.Parse(dr["aplique"].ToString()); m.cantidadColores = int.Parse(dr["cantidadColores"].ToString()); m.cantidadPuntadas = int.Parse(dr["cantidadPuntadas"].ToString()); m.fechaCreacion = DateTime.Parse(dr["fechaCreacion"].ToString()); m.nombreArchivo = dr["nombreArchivo"].ToString(); m.precio = decimal.Parse(dr["precio"].ToString()); m.tamañoDescripcion = dr["tamaño"].ToString(); } } catch(SqlException ex) { } finally { if(connection.State == ConnectionState.Open) { connection.Close(); } } return m; }
protected void grdMatrices_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (Session["carritoPresupuesto"] == null) { Session["carritoPresupuesto"] = new List<MatrizEntidad>(); } List<MatrizEntidad> lista = (List<MatrizEntidad>)Session["carritoPresupuesto"]; int indice = e.RowIndex; GridViewRow fila = grdMatricesPresupuesto.Rows[indice]; MatrizEntidad m = new MatrizEntidad(); m.nombreArchivo = fila.Cells[1].Text; m.cantidadColores = int.Parse(fila.Cells[2].Text); m.cantidadPuntadas = int.Parse(fila.Cells[3].Text); m.precio = decimal.Parse(fila.Cells[4].Text); m.fechaCreacion = DateTime.Parse(fila.Cells[5].Text); m.apliqueBooleano = bool.Parse(fila.Cells[6].Text); m.tamaño = MatrizGestor.obtenerId(fila.Cells[7].Text); foreach (var matriz in lista) { if (m.nombreArchivo == matriz.nombreArchivo) { matriz.cantidad++; matriz.subTotal = matriz.precio * matriz.cantidad; cargarCarrito(); cargarTotal(); return; } } m.subTotal = m.precio; m.cantidad = 1; lista.Add(m); cargarCarrito(); cargarTotal(); btnGuardar.Visible = true; btnCancelar.Visible = true; }
protected void guardarMatriz() { MatrizEntidad matriz = new MatrizEntidad(); matriz.nombreArchivo = txtNombre.Text; matriz.cantidadPuntadas = int.Parse(txtCantidadPuntadas.Text); matriz.cantidadColores = int.Parse(txtCantidadColores.Text); matriz.precio = decimal.Parse(txtPrecio.Text); matriz.aplique = 0; if (cbxAplique.Checked == true) { matriz.aplique = 1; } matriz.fechaCreacion = DateTime.Parse(txtFechaCreacion.Text); matriz.tamaño = int.Parse(ddlTamaño.SelectedValue); MatrizGestor.Insertar(matriz); cargarMatrices(); limpiarControles(); resetearGuardar(); }
public static void Insertar(MatrizEntidad matriz) { SqlConnection connection = new SqlConnection(); SqlCommand command = new SqlCommand(); try { connection.ConnectionString = cadenaConexion; connection.Open(); string sql = "INSERT INTO Matriz (nombreArchivo, cantidadPuntadas, cantidadColores, aplique, fechaCreacion, precio, idTamaño)"; sql += " VALUES (@NombreArchivo, @CantidadPuntadas, @CantidadColores, @Aplique, @FechaCreacion, @Precio, @Tamaño)"; command.CommandText = sql; command.Connection = connection; command.Parameters.AddWithValue("@NombreArchivo", matriz.nombreArchivo); command.Parameters.AddWithValue("@CantidadPuntadas", matriz.cantidadPuntadas); command.Parameters.AddWithValue("@CantidadColores", matriz.cantidadColores); command.Parameters.AddWithValue("@Aplique", matriz.aplique); command.Parameters.AddWithValue("@FechaCreacion", matriz.fechaCreacion); command.Parameters.AddWithValue("@Precio", matriz.precio); command.Parameters.AddWithValue("@Tamaño", matriz.tamaño); command.ExecuteNonQuery(); } catch(SqlException ex) { } finally { if(connection.State == ConnectionState.Open) { connection.Close(); } } }