public void DeleteProduct(Product product) { using (OracleConnection connection = new OracleConnection(connectionString)) { if (connection.State != ConnectionState.Open) connection.Open(); // delete record from table DeleteProduct(connection, product); } }
private void btnSave_Click(object sender, System.Windows.RoutedEventArgs e) { try { if (productBackup == null) { productBackup = data.NewProduct(product.Name, product.Price, product.TimeConsuming); product.Id = productBackup.Id; } else { data.UpdateProduct(product, productBackup); productBackup.Name = product.Name; productBackup.Price = product.Price; productBackup.TimeConsuming = product.TimeConsuming; productBackup.Active = product.Active; } } catch { } }
private void DeleteProduct(OracleConnection connection, Product product) { OracleCommand cmd = connection.CreateCommand(); cmd.CommandText = "delete from tis_vyrobek where vyrobek_id = :1"; cmd.Parameters.Add(GetNumber(":1", product.Id)); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); cmd.Dispose(); }
public void UpdateProduct(Product newProduct, Product oldProduct) { using (OracleConnection connection = new OracleConnection(connectionString)) { if (connection.State != ConnectionState.Open) connection.Open(); // update record in table UpdateProduct(connection, newProduct, oldProduct); } }
public Item NewItem(Order order, Product product, int count) { using (OracleConnection connection = new OracleConnection(connectionString)) { if (connection.State != ConnectionState.Open) connection.Open(); // insert record to table InsertItem(connection, order, product, count); } return new Item { OrderId = order.Id, Order = order, ProductId = product.Id, Product = product, Count = count }; }
private void UpdateProduct(OracleConnection connection, Product newProduct, Product oldProduct) { if (newProduct.Id != oldProduct.Id) // probably different products - wrong input return; OracleCommand cmd = connection.CreateCommand(); cmd.CommandText = "update tis_vyrobek set "; cmd.CommandType = CommandType.Text; int paramIdx = 1; paramIdx = AddUpdateField(cmd, "nazev", paramIdx, CheckForInjection(newProduct.Name), oldProduct.Name); paramIdx = AddUpdateField(cmd, "cena", paramIdx, newProduct.Price, oldProduct.Price); paramIdx = AddUpdateField(cmd, "narocnost", paramIdx, newProduct.TimeConsuming, oldProduct.TimeConsuming); paramIdx = AddUpdateField(cmd, "aktivni", paramIdx, newProduct.Active, oldProduct.Active); if (paramIdx > 1) { cmd.CommandText += " where vyrobek_id = :" + paramIdx.ToString(); cmd.Parameters.Add(GetNumber(":" + paramIdx.ToString(), newProduct.Id)); cmd.ExecuteNonQuery(); } cmd.Dispose(); }
private void InsertItem(OracleConnection connection, Order order, Product product, int count) { OracleCommand cmd = connection.CreateCommand(); cmd.CommandText = "insert into tis_polozka (zakazka_id,vyrobek_id,pocet) values(:1,:2,:3)"; cmd.Parameters.Add(GetNumber(":1", order.Id)); cmd.Parameters.Add(GetNumber(":2", product.Id)); cmd.Parameters.Add(GetNumber(":3", count)); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); cmd.Dispose(); }
private void EditProduct(Product editProduct) { product = new Product(); if (editProduct != null) { product.Id = editProduct.Id; product.Name = editProduct.Name; product.Price = editProduct.Price; product.TimeConsuming = editProduct.TimeConsuming; product.Active = editProduct.Active; } gridEdit.DataContext = product; }