private async void My_List_ItemTapped(object sender, ItemTappedEventArgs e) { var ayudante = e.Item as Modelos.Articulo; Modelos.Articulo detalles = ayudante; await DisplayAlert("Nombre: " + detalles.Producto, "\nIdentificador:" + detalles.Id + "\nCantidad: " + detalles.Cantidad + "\nPrecio: " + detalles.Precio, "OK"); }
private async void Button_Clicked(System.Object sender, System.EventArgs e) { MySqlConnection con = new MySqlConnection(PaginaPrincipal.conexion); if (App.listaCarrito != null) { string factura = ""; double total = 0; factura += "\n\nFecha:\t\t" + DateTime.Now.AddHours(-5).ToString("dd-MM-yyyy hh:mm:ss tt") + "\n"; factura += "\nProductos"; try { if (con.State == ConnectionState.Closed) { con.Open(); foreach (Modelos.ArticuloCarrito a in App.listaCarrito) { Modelos.Articulo articulo = await App.SQLiteDb.GetItemAsync(a.Producto); articulo.Cantidad = articulo.Cantidad - a.Cantidad; factura += "\n\n\t\t\t" + a.Producto + " (" + a.Cantidad + " x $" + articulo.Precio + ")" + "\t\t\t\t$" + a.Cantidad * articulo.Precio; total += a.Cantidad * articulo.Precio; articulo.VecesVendidas = articulo.VecesVendidas + a.Cantidad; string sql = "UPDATE articulos SET Producto='" + Convert.ToString(articulo.Producto) + "',Cantidad='" + Convert.ToInt32(articulo.Cantidad) + "', Popularidad='" + Convert.ToInt32(articulo.VecesVendidas) + "' WHERE Producto = '" + articulo.Producto + "'"; using (MySqlCommand cmd = new MySqlCommand(sql, con)) { MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { } await App.SQLiteDb.SaveItemAsync(articulo); con.Close(); con = new MySqlConnection(PaginaPrincipal.conexion); con.Open(); } } } }catch (MySqlException ex) { await DisplayAlert("Paso esto: ", Convert.ToString(ex) + "Fallo en conexion Intentelo mas tarde", "OK"); } finally { con.Close(); } factura += "\n\nTOTAL:\t\t$" + total; App.listaCarrito.Clear(); await Navigation.PushAsync(new Factura(factura)); } }
public async void update_local_db() { string id; try { if (con.State == ConnectionState.Closed) { string sql = "SELECT Id,Producto,Cantidad,Precio,Costo,Categoria_General,SubCategoria1,SubCategoria2,SubCategoria3,Popularidad FROM articulos"; using (MySqlCommand cmd = new MySqlCommand(sql, con)) { con.Open(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { id = reader["Id"].ToString(); producto = reader.GetString("Producto"); cantidad = reader.GetInt32("Cantidad"); precio = reader.GetInt32("Precio"); costo = reader.GetInt32("Costo"); categoria_general = reader.GetString("Categoria_General"); subcat1 = reader.GetString("SubCategoria1"); subcat2 = reader.GetString("SubCategoria2"); subcat3 = reader.GetString("SubCategoria3"); if (reader["Popularidad"] != DBNull.Value) { veces_vendidas = reader.GetInt32("Popularidad"); } else { veces_vendidas = 0; } var articulo = await App.SQLiteDb.GetItemAsync(producto); if (articulo == null) { articulo = new Modelos.Articulo() { Id = id, Producto = producto, Costo = costo, Precio = precio, Cantidad = cantidad, MasterCategory = categoria_general, Category1 = subcat1, Category2 = subcat2, Category3 = subcat3, VecesVendidas = veces_vendidas }; await App.SQLiteDb.SaveItemAsync(articulo); } else { articulo.Producto = (string.Equals("0", producto + "0")) ? articulo.Producto : producto; articulo.Cantidad = (string.Equals("0", cantidad + "0")) ? articulo.Cantidad : cantidad; articulo.Category1 = (string.Equals("0", subcat1 + "0")) ? articulo.Category1 : subcat1; articulo.Category2 = (string.Equals("0", subcat2 + "0")) ? articulo.Category2 : subcat2; articulo.Category3 = (string.Equals("0", subcat3 + "0")) ? articulo.Category3 : subcat3; articulo.MasterCategory = (string.Equals("0", categoria_general + "0")) ? articulo.MasterCategory : categoria_general; articulo.Precio = (string.Equals("0", precio + "0")) ? articulo.Precio : precio; articulo.Costo = (string.Equals("0", costo + "0")) ? articulo.Costo : costo; articulo.VecesVendidas = (string.Equals("0", veces_vendidas + "0")) ? articulo.VecesVendidas : veces_vendidas; await App.SQLiteDb.SaveItemAsync(articulo); } } reader.Close(); } } } catch (MySqlException ex) { await DisplayAlert("Paso esto: ", Convert.ToString(ex), "test"); } finally { con.Close(); } }