private void btnAddC_Click(object sender, RoutedEventArgs e) { if (rbCust.IsChecked == true) { try { Customers customer = new Customers(); customer.cust_id = cust_idTextBox.Text; customer.cust_name = cust_nameTextBox.Text; customer.cust_city = cust_cityTextBox.Text; customer.cust_state = cust_stateTextBox.Text; customer.cust_zip = cust_zipTextBox.Text; customer.cust_country = cust_countryTextBox.Text; customer.cust_contact = cust_contactTextBox.Text; customer.cust_email = cust_emailTextBox.Text; context.Customers.Add(customer); context.SaveChanges(); dgrProd.ItemsSource = context.Customers.ToList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (rbOrd.IsChecked == true) { try { Orders orders = new Orders(); orders.order_num = int.Parse(order_numTextBox.Text); orders.order_date = DateTime.Parse(order_dateDatePicker.Text); orders.cust_id = cust_idTextBox1.Text; context.Orders.Add(orders); context.SaveChanges(); dgrProd.ItemsSource = context.Orders.ToList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (rbOrdIt.IsChecked == true) { try { OrderItems orderItems = new OrderItems(); orderItems.order_num = int.Parse(order_numTextBox1.Text); orderItems.order_item = int.Parse(order_itemTextBox.Text); orderItems.prod_id = prod_idTextBox.Text; orderItems.quantity = int.Parse(quantityTextBox.Text); orderItems.item_price = decimal.Parse(item_priceTextBox.Text); context.OrderItems.Add(orderItems); context.SaveChanges(); dgrProd.ItemsSource = context.OrderItems.ToList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnDeletec_Click(object sender, RoutedEventArgs e) { if (rbCust.IsChecked == true) { try { if (dgrProd.SelectedItems.Count > 0) { for (int i = 0; i < dgrProd.SelectedItems.Count; i++) { Customers cust = dgrProd.SelectedItems[i] as Customers; if (cust != null) { context.Customers.Remove(cust); context.SaveChanges(); } } dgrProd.ItemsSource = context.Customers.ToList(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (rbOrd.IsChecked == true) { try { if (dgrProd.SelectedItems.Count > 0) { for (int i = 0; i < dgrProd.SelectedItems.Count; i++) { Orders ord = dgrProd.SelectedItems[i] as Orders; if (ord != null) { context.Orders.Remove(ord); context.SaveChanges(); } } dgrProd.ItemsSource = context.Orders.ToList(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (rbOrdIt.IsChecked == true) { try { if (dgrProd.SelectedItems.Count > 0) { for (int i = 0; i < dgrProd.SelectedItems.Count; i++) { OrderItems items = dgrProd.SelectedItems[i] as OrderItems; if (items != null) { context.OrderItems.Remove(items); context.SaveChanges(); } } dgrProd.ItemsSource = context.OrderItems.ToList(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnSearchc_Click(object sender, RoutedEventArgs e) { if (rbCust.IsChecked == true) { if (cust_idTextBox.Text != "") { var query = from product in context.Customers where product.cust_id == cust_idTextBox.Text select new { product.cust_id, product.cust_name, CategoryName = product.cust_address, product.cust_contact, product.cust_country }; dgrProd.ItemsSource = query.ToList(); } } if (rbOrd.IsChecked == true) { Orders orders = new Orders(); orders.order_num = int.Parse(order_numTextBox.Text); if (order_numTextBox.Text != "") { var query = from product in context.Orders where product.order_num == orders.order_num select new { product.order_num, product.order_date, product.cust_id }; dgrProd.ItemsSource = query.ToList(); } } if (rbOrdIt.IsChecked == true) { OrderItems items = new OrderItems(); items.order_num = int.Parse(order_numTextBox1.Text); if (order_numTextBox1.Text != "") { var query = from product in context.OrderItems where product.order_num == items.order_num select new { product.order_num, product.order_item, product.quantity, product.item_price, product.prod_id }; dgrProd.ItemsSource = query.ToList(); } } }