private void btnAgregar_Click(object sender, RoutedEventArgs e) { if (Regex.IsMatch(txbCategoria.Text, @"^[a-zA-Z\s]+$")) { BITland db = new BITland(); Categoria emp = new Categoria(); emp.Cate = txbCategoria.Text; db.Categorias.Add(emp); db.SaveChanges(); MessageBox.Show("Se agrego correctamente"); } else { MessageBox.Show("Solo caracteres en Categoria"); } }
private void btnAgregar_Click(object sender, RoutedEventArgs e) { if ((Regex.IsMatch(txbTienda.Text, @"^[a-zA-Z\s]+$")) && (Regex.IsMatch(txbNombre.Text, @"^[a-zA-Z\s]+$")) && (Regex.IsMatch(txbDireccion.Text, @"^[a-zA-Z\s\d+]+$"))) { BITland db = new BITland(); Cliente emp = new Cliente(); emp.Nombre = txbNombre.Text; emp.Tienda = txbTienda.Text; emp.Direccion = txbDireccion.Text; db.Clientes.Add(emp); db.SaveChanges(); MessageBox.Show("Se agrego correctamente"); } else { MessageBox.Show("Solo caracteres en Tienda, Nombre y Direccion"); } }
private void btnAgregar_Click(object sender, RoutedEventArgs e) { //guarda nuevo registro //Instanciar base de datos if ((Regex.IsMatch(txbTipo.Text, @"^[a-zA-Z\s]+$"))) { BITland db = new BITland(); TipoProducto emp = new TipoProducto(); emp.Tipo = txbTipo.Text; db.Tipos.Add(emp); db.SaveChanges(); MessageBox.Show("Se agrego Correctamente"); } else { MessageBox.Show("Solo caracteres en Tipo de producto"); } }
private void btnActualizar_Click(object sender, RoutedEventArgs e) { if ((Regex.IsMatch(txbIdTipo.Text, @"^\d+$")) && (Regex.IsMatch(txbTipo.Text, @"^[a-zA-Z\s]+$"))) { //actualiza BITland db = new BITland(); int id = int.Parse(txbIdTipo.Text); var em = db.Tipos.SingleOrDefault(x => x.idTipo == id); { em.Tipo = txbTipo.Text; db.SaveChanges(); MessageBox.Show("Se actualizo correctamente"); } } else { MessageBox.Show("Solo Numeros en Id Tipo y/o caracteres en Tipo de producto"); } }
private void btnEliminar_Click(object sender, RoutedEventArgs e) { if (Regex.IsMatch(txbIdTipo.Text, @"^\d+$"))//se esta verificando que se agregue { //elimina registro BITland db = new BITland(); int id = int.Parse(txbIdTipo.Text); var em = db.Tipos.SingleOrDefault(x => x.idTipo == id); if (em != null) { db.Tipos.Remove(em); db.SaveChanges(); MessageBox.Show("Se elimino correctamente"); } } else { MessageBox.Show("Solo Numeros en Id Tipo de producto"); } }
private void btnActualizar_Click(object sender, RoutedEventArgs e) { if ((Regex.IsMatch(txbIdTienda.Text, @"^\d+$")) && (Regex.IsMatch(txbTienda.Text, @"^[a-zA-Z\s]+$")) && (Regex.IsMatch(txbNombre.Text, @"^[ a-zA-Z\s]+$")) && (Regex.IsMatch(txbDireccion.Text, @"^[a-zA-Z\s\d]+$"))) { //actualiza BITland db = new BITland(); int id = int.Parse(txbIdTienda.Text); var em = db.Clientes.SingleOrDefault(x => x.idCliente == id); if (em != null) { em.Nombre = txbNombre.Text; em.Direccion = txbDireccion.Text; em.Tienda = txbTienda.Text; db.SaveChanges(); MessageBox.Show("Se actualizo correctamente"); } } else { MessageBox.Show("Solo Numeros en Id Tienda y/o caracteres en Nombre, Direccion y Tienda"); } }
private void btnActualizar_Click(object sender, RoutedEventArgs e) { if ((Regex.IsMatch(txbIdCategoria.Text, @"^\d+$")) && (Regex.IsMatch(txbCategoria.Text, @"^[a-zA-Z\s]+$"))) { //actualiza BITland db = new BITland(); int id = int.Parse(txbIdCategoria.Text); var em = db.Categorias.SingleOrDefault(x => x.idCategoria == id); // var em = from x in db.Empleados // where x.id == id // select x; if (em != null) { em.Cate = txbCategoria.Text; em.idCategoria = int.Parse(txbIdCategoria.Text); db.SaveChanges(); MessageBox.Show("Se actualizo correctamente"); } } else { MessageBox.Show("Solo Numeros en Id Categoria y/o caracteres en Categoria"); } }
private void btnAgregar_Click(object sender, RoutedEventArgs e) { //guarda nuevo registro //Instanciar base de datos if ((Regex.IsMatch(txbPersonaje.Text, @"^[a-zA-Z\s]+$")) && (Regex.IsMatch(txbPrecio.Text, @"^\d+$")) && (Regex.IsMatch(txbCantidad.Text, @"^\d+$")) && (cbxCategoria.SelectedIndex > -1)&&(cbxTipo.SelectedIndex > -1)) { BITland db = new BITland(); Producto emp = new Producto(); emp.Personaje = txbPersonaje.Text; emp.Cantidad = int.Parse(txbCantidad.Text); emp.Precio = int.Parse(txbPrecio.Text); emp.CategoriaidCategoria = (int)cbxCategoria.SelectedValue; emp.TipoProductoidTipo = (int)cbxTipo.SelectedValue; db.Productos.Add(emp); db.SaveChanges(); MessageBox.Show("Se agrego correctamente"); } else { MessageBox.Show("Solo caracteres en Personaje y/o numeros en Precio y Cantidad"); } }
private void btnActualizar_Click(object sender, RoutedEventArgs e) { if ((Regex.IsMatch(txbPersonaje.Text, @"^[ a-zA-Z\s]+$")) && (Regex.IsMatch(txbPrecio.Text, @"^\d+$")) && (Regex.IsMatch(txbCantidad.Text, @"^\d+$"))&&(Regex.IsMatch(txbIdProducto.Text, @"^\d+$"))) { //actualiza BITland db = new BITland(); int id = int.Parse(txbIdProducto.Text); var em = db.Productos.SingleOrDefault(x => x.idProducto == id); if (em != null) { em.Personaje = txbPersonaje.Text; em.Cantidad = int.Parse(txbCantidad.Text); em.Precio = int.Parse(txbPrecio.Text); em.CategoriaidCategoria = (int)cbxCategoria.SelectedValue; em.TipoProductoidTipo = (int)cbxTipo.SelectedValue; db.SaveChanges(); MessageBox.Show("Se actualizo correctamente"); } } else { MessageBox.Show("Solo caracteres en Personaje y/o numeros en Id Producto, Precio y Cantidad"); } }
private void btnMostrar_Click(object sender, RoutedEventArgs e) { //despliega todos los datos de la base de datos BITland db = new BITland(); var reg = from s in db.Categorias select s; dgCategoria.ItemsSource = reg.ToList(); }
private void btnComprar_Click(object sender, RoutedEventArgs e) { //we make sure there is at least one item in the cart and a sales person has been selected if (ShoppingCart.Count > 0 && cbxTienda.SelectedIndex > -1) { //auto dispose after no longer in scope using (BITland db = new BITland()) { //All database transactions are considered 1 unit of work using (var dbTransaction = db.Database.BeginTransaction()) { try { //we create the invoice object Factura inv = new Factura(); inv.Fecha = DateTime.Now; //assign sales person by querying the database using the Combobox selection inv.Tienda = db.Clientes.SingleOrDefault(s => s.idCliente == (int)cbxTienda.SelectedValue); //for each product in the shopping cart we query the database foreach (var prod in ShoppingCart) { //get product record with id Producto p = db.Productos.SingleOrDefault(i => i.idProducto == prod.idProducto); //reduce inventory int RemainingItems = p.Cantidad - prod.Cantidad >= 0 ? (p.Cantidad - prod.Cantidad) : p.Cantidad; if (p.Cantidad == RemainingItems) { MessageBox.Show( string.Format( "No disponible para venta #{0} No hay existencia, Desea Continuar?", p.idProducto), "No hay existencia", MessageBoxButton.OK, MessageBoxImage.Asterisk); //end transaction dbTransaction.Rollback(); //exit procedure return; } else { //If Qty is ok we sell the product p.Cantidad = RemainingItems; inv.ListaVenta.Add(p); } } //we add the generated invoice to the Invoice Entity (Table) db.Facturas.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 MessageBox.Show(string.Format("Compra #{0} guardada", inv.idFactura), "Listo", MessageBoxButton.OK, MessageBoxImage.Information); } catch { //if an error is produced, we rollback everything dbTransaction.Rollback(); //We notify the user of the error MessageBox.Show("Error en la compra, no disponible para realizar compra", "Error fatal", MessageBoxButton.OK, MessageBoxImage.Error); } } } } else { MessageBox.Show("Por favor seleccione producto y Tienda", "Error en los datos", MessageBoxButton.OK, MessageBoxImage.Stop); } }
private void Window_Loaded_1(object sender, RoutedEventArgs e) { BITland db = new BITland(); cbxTienda.ItemsSource = db.Clientes.ToList(); cbxTienda.DisplayMemberPath = "Tienda"; cbxTienda.SelectedValuePath = "idCliente"; cbxTienda.SelectedIndex = 0; }
private void Button_Click_1(object sender, RoutedEventArgs e) { //If a product code is not empty we search the database if (Regex.IsMatch(txbCodigoPro.Text, @"^\d+$")) { BITland db = new BITland(); //parse the product code as int from the TextBox int id = int.Parse(txbCodigoPro.Text); //We query the database for the product Producto p = db.Productos.SingleOrDefault(x => x.idProducto == id); if (p != null) //if product was found { //store in a temp variable (if user clicks on add we will need this for the Array) tmpProduct = p; //We display the product information on a label lblTotalProducto.Content = string.Format("ID: {0}, Personaje: {1}, Precio: {2}, EnStock: {3}", p.idProducto, p.Personaje, p.Precio, p.Cantidad); } else { //if product was not found we display a user notification window MessageBox.Show("Producto no encontrado", "Error en el Id Producto", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } else { MessageBox.Show("Solo numeros en codigo del producto"); } }
private void Window_Loaded_1(object sender, RoutedEventArgs e) { BITland db = new BITland(); cbxCategoria.ItemsSource = db.Categorias.ToList(); cbxCategoria.DisplayMemberPath = "Cate"; cbxCategoria.SelectedValuePath = "idCategoria"; cbxCategoria.SelectedIndex = 0; BITland db1 = new BITland(); cbxTipo.ItemsSource = db1.Tipos.ToList(); cbxTipo.DisplayMemberPath = "Tipo"; cbxTipo.SelectedValuePath = "idTipo"; cbxTipo.SelectedIndex = 0; }
private void Button_Click_1(object sender, RoutedEventArgs e) { //despliega todos los datos de la base de datos BITland db = new BITland(); var reg = from s in db.Productos select s; gbProdu.ItemsSource = reg.ToList(); }