private void FindOrderButton_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 new { o.OrderID, o.Date, o.Product, o.UnitPrice, o.Quantity, o.TotalPrice, o.Customer.Name, o.Employee.UserName }; if (!order.Any()) { MessageBox.Show(string.Format("Order {0} not found in the databse!", orderId), "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { OrdersDataGrid.DataSource = order.ToList(); MessageBox.Show(string.Format("Order {0} successfully found in the databse!", orderId), "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
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 BrowseAllButton_Click(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { var orders = from o in dbContext.Orders orderby o.OrderID select new { o.OrderID, o.Date, o.Product, o.UnitPrice, o.Quantity, o.TotalPrice, o.Customer.Name, o.Employee.UserName }; if (orders.Any()) { OrdersDataGrid.DataSource = orders.ToList(); } else { MessageBox.Show("No orders found in the databse!", "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void QuestionsComboBox_SelectedIndexChanged(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { ComboBox cb = sender as ComboBox; ResultsDataGridView.DataSource = null; ResultsDataGridView.Rows.Clear(); if (cb.SelectedIndex == 0) { var users = from emp in dbContext.Employees join ord in dbContext.Orders on emp.EmployeeID equals ord.EmployeeID where ord.Date >= DateTime.Today select new { emp.EmployeeID, emp.UserName, ord.OrderID, ord.Date, ord.Product, ord.Quantity, ord.UnitPrice, ord.TotalPrice, ord.Customer.Name }; ResultsDataGridView.DataSource = users.ToList(); } else { var users = from emp in dbContext.Employees join ord in dbContext.Orders on emp.EmployeeID equals ord.EmployeeID join acc in dbContext.Customers on ord.CustomerID equals acc.CustomerID where acc.ShipCountry == "Canada" select new { emp.EmployeeID, emp.UserName, ord.OrderID, ord.Date, ord.Product, ord.Quantity, ord.UnitPrice, ord.TotalPrice, ord.Customer.Name, ord.Customer.ShipCountry }; ResultsDataGridView.DataSource = users.ToList(); } } }
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); } }
private void customerIDTextBox_Leave(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { var customerId = int.Parse(customerIDTextBox.Text); var customer = from cust in dbContext.Customers where cust.CustomerID == customerId select cust; if (!customer.Any()) { MessageBox.Show(string.Format("Customer {0} does not exist in the databse!", customerIDTextBox.Text), "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Manager.customer = customer.First(); nameTextBox.Text = Manager.customer.Name; } } }
private void LoginButton_Click(object sender, EventArgs e) { using (SalesEntities dbContext = new SalesEntities()) { var login = from emp in dbContext.Employees where emp.UserName == UserNameTextBox.Text && emp.Password == PasswordTextBox.Text select emp; if (!login.Any()) { MessageBox.Show("User Name or Password invalid!", "Sales Application", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // SHOW THE WELCOME WINDOW Hide(); Manager.employee = login.First(); Manager.welcomeForm = new WelcomeForm(); Manager.welcomeForm.ShowDialog(); } } }