private void Button_Click_1(object sender, RoutedEventArgs e) { //ver todo bdPrincipal bd = new bdPrincipal(); var registros = from s in bd.producto select s; dbgrid.ItemsSource = registros.ToList(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (Regex.IsMatch(txtnom.Text, "^[a-zA-Z]+$") && (Regex.IsMatch(txtCi.Text, "^[a-zA-Z]+$") && (Regex.IsMatch(txtTel.Text, @"^\d+$")))) { bdPrincipal bd = new bdPrincipal(); ProyectoFinal.MiBD.Proveedor pro = new ProyectoFinal.MiBD.Proveedor(); pro.NombrePro = txtnom.Text; pro.Ciudad = txtCi.Text; pro.Telefono = int.Parse(txtTel.Text); bd.proveedores.Add(pro); bd.SaveChanges(); MessageBox.Show("Datos guardados exitosamente"); }else { MessageBox.Show("datos no validos"); } }
private void Button_Click_3(object sender, RoutedEventArgs e) { //Borrar if (Regex.IsMatch(txtid.Text, @"\d+$")) { bdPrincipal db = new bdPrincipal(); int id = int.Parse(txtid.Text); var com = db.producto .SingleOrDefault(x => x.idPro == id); if (com != null) { db.producto.Remove(com); db.SaveChanges(); MessageBox.Show("dato eliminado satisfactoriamente "); } } else { MessageBox.Show("solo capture numeros "); } txtid.Clear(); }
private void Button_Click_2(object sender, RoutedEventArgs e) { //Actualiza if (Regex.IsMatch(txtid.Text, @"^\d+$")) { bdPrincipal db = new bdPrincipal(); int id = int.Parse(txtid.Text); var prod = db.compra .SingleOrDefault(x => x.idCom == id); if (prod != null) { db.compra.Add(prod); db.SaveChanges(); } } else { MessageBox.Show("Solo numeros en id"); } }
private void Buscar_Click(object sender, EventArgs e) { //buscar if (Regex.IsMatch(textBox1.Text.Trim(), @"^\d+$")) { bdPrincipal db = new bdPrincipal(); //parse the product code as int from the TextBox int idProd = int.Parse(textBox1.Text); //We query the database for the product MiBD.Productos p = db.producto.SingleOrDefault(x => x.idPro == idProd); if (p != null) //if product was found { //store in a temp variable (if user clicks on add we will need this for the Array) product = p; //We display the product information on a label label2.Text = string.Format("ID: {0}, Name: {1}, Price: {2}", p.idPro, p.NombreProdu, p.Categoria, p.Cantidad); } else { //if product was not found we display a user notification window // MessageBox.Show("Product not found. (Only numbers allowed)", "Product code error", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (Regex.IsMatch(txtno.Text, "^[a-zA-Z]+$") && (Regex.IsMatch(txtCa.Text, "^[a-zA-Z]+$") && (Regex.IsMatch(txtCan.Text, @"^\d+$")))) { bdPrincipal bd = new bdPrincipal(); ProyectoFinal.MiBD.Productos prod = new ProyectoFinal.MiBD.Productos(); prod.NombreProdu = txtno.Text; prod.Categoria = txtCa.Text; prod.Cantidad = int.Parse(txtCan.Text); bd.producto.Add(prod); bd.SaveChanges(); MessageBox.Show("Datos almacenados correctamente"); } else { MessageBox.Show("datos no validos"); } Compras vb = new Compras(); vb.Show(); this.Close(); }
private void button3_Click(object sender, EventArgs e) { //guardar //we make sure there is at least one item in the cart and a sales person has been selected if (ShoppingCart.Count > 0 && comboBox1.SelectedIndex > -1){ //auto dispose after no longer in scope using(bdPrincipal db = new bdPrincipal()){ //All database transactions are considered 1 unit of work using (var dbTransaction = db.Database.BeginTransaction()) { try { //we create the invoice object invoice inv = new invoice(); inv.SaleDate = DateTime.Now; //assign sales person by querying the database using the Combobox selection //comboBox1.SelectedIndex = 0; inv.id = db.Registro.SingleOrDefault(s => s.id == (int)comboBox1.SelectedValue); //for each product in the shopping cart we query the database foreach (var prod in ShoppingCart) { //get product record with id MiBD.Productos p = db.producto.SingleOrDefault(i => i.idPro == prod.idPro); //reduce inventory int RemainingItems = p.Qty - prod.Qty >= 0 ? (p.Qty - prod.Qty) : p.Qty; if (p.Qty == RemainingItems) { System.Windows.MessageBox.Show( string.Format( "Unable to sell Product #{0} not enough inventory, Do want to continue?", p.idPro), "Not Enough Inventory", MessageBoxButton.OK, MessageBoxImage.Asterisk); //end transaction dbTransaction.Rollback(); //exit procedure return; } else { //If Qty is ok we sell the product p.Qty = RemainingItems; inv.SaleList.Add(p); } } //we add the generated invoice to the Invoice Entity (Table) db.invoices.Add(inv); //Save Changed to the database db.SaveChanges(); // Make the changes permanent dbTransaction.Commit(); //We restore the form with defaults CleanUp(); //Show confirmation message to the user System.Windows.MessageBox.Show(string.Format("Transaction #{0} Saved", inv.invoiceId), "Success", MessageBoxButton.OK, MessageBoxImage.Information); } catch { //if an error is produced, we rollback everything dbTransaction.Rollback(); //We notify the user of the error System.Windows.MessageBox.Show("Transaction Error, unable to generate invoice", "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } else { System.Windows.MessageBox.Show("Please select at least one product and a Sales Person", "Data Error", MessageBoxButton.OK, MessageBoxImage.Stop); } }
private void Button_Click_4(object sender, RoutedEventArgs e) { //buscarid if (Regex.IsMatch(txtid.Text, @"\d+$")) { bdPrincipal bd = new bdPrincipal(); int id = int.Parse(txtid.Text); var registros = from s in bd.producto where s.idPro == id select new { s.idPro, s.NombreProdu, s.Categoria, s.Cantidad, }; dbgrid.ItemsSource = registros.ToList(); } else { MessageBox.Show("Ingresa solo numeros en id"); } }
private void Button_Click_5(object sender, RoutedEventArgs e) { //modificar if (Regex.IsMatch(txtnew.Text, "^[a-zA-Z]+$") && (Regex.IsMatch(txtcate.Text, "^[a-zA-Z]+$") && (Regex.IsMatch(txtcan.Text, @"^\d+$") && (Regex.IsMatch(txtid.Text, @"^\d+$"))))){ bdPrincipal db = new bdPrincipal(); int idPro = int.Parse(txtid.Text); var registro = db.producto .SingleOrDefault(x => x.idPro == idPro); if (registro != null) { registro.NombreProdu = txtnew.Text; registro.Categoria = txtcate.Text; registro.Cantidad = int.Parse(txtcan.Text); db.SaveChanges(); } MessageBox.Show("Modificar a sido exitoso"); txtnew.Clear(); txtcate.Clear(); txtcan.Clear(); } }