private void PlaceOrderButton_Click(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { int quantity = int.Parse(quantityTextBox.Text); decimal unitPrice = decimal.Parse(unitPriceTextBox.Text); Order order = new Order { CustomerID = Manager.customer.CustomerID, Date = dateDateTimePicker.Value, EmployeeID = Manager.employee.EmployeeID, Product = productTextBox.Text, Quantity = quantity, UnitPrice = unitPrice, TotalPrice = quantity * unitPrice, }; var totalPrice = unitPrice * quantity; dbContext.Orders.Add(order); dbContext.SaveChanges(); orderIDTextBox.Text = order.OrderID.ToString(); totalPriceTextBox.Text = totalPrice.ToString(); MessageBox.Show(string.Format("Order {0} successfully registered!", orderIDTextBox.Text), "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void DeleteOrderButton_Click(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { var orderId = int.Parse(OrderIdTextBox.Text); var order = from o in dbContext.Orders where o.OrderID == orderId select o; dbContext.Orders.Remove(order.First()); dbContext.SaveChanges(); MessageBox.Show(string.Format("Order {0} successfully deleted!", OrderIdTextBox.Text), "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Information); OrdersDataGrid.DataSource = null; OrdersDataGrid.Rows.Clear(); } }
private void RegisterButton_Click(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { dbContext.Employees.Add( new Employee { UserName = UserNameTextBox.Text, Password = PasswordTextBox.Text } ); dbContext.SaveChanges(); MessageBox.Show(string.Format("User {0} successfully registered!", UserNameTextBox.Text), "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void CreateAccountButton_Click(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { Customer cust = new Customer { Name = nameTextBox.Text, ShipAddress = shipAddressTextBox.Text, ShipCity = shipCityTextBox.Text, ShipCountry = shipCountryTextBox.Text }; dbContext.Customers.Add(cust); dbContext.SaveChanges(); customerIDTextBox.Text = cust.CustomerID.ToString(); MessageBox.Show(string.Format("Customer {0} successfully registered!", nameTextBox.Text), "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Information); } }