private void GridFoodItem_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { FoodItem selectedItem = (FoodItem)GridFoodItem.SelectedItem; if (selectedItem != null) { // create data context ofosDataContext dc = new ofosDataContext(); // get selected id int selectedIndex = ((FoodItem)GridFoodItem.SelectedItem).Id; // fill the ingredients grid GridIngredients.ItemsSource = dc.GetIngredients(selectedIndex); // Enabling New button btnNew.IsEnabled = true; } else { // Disabling New button btnNew.IsEnabled = false; } } catch { } }
private void BtnDelete_Click(object sender, RoutedEventArgs e) { try { // Getting selected row GetIngredientsResult selectedItem = (GetIngredientsResult)GridIngredients.SelectedItem; if (selectedItem != null) { if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { ofosDataContext dc = new ofosDataContext(); // Delete the row dc.FoodIngredientDelete(selectedItem.Id); // Refresh the grid after Delete // get selected id int selectedIndex = ((FoodItem)GridFoodItem.SelectedItem).Id; // fill the ingredients grid GridIngredients.ItemsSource = dc.GetIngredients(selectedIndex); } } } catch { } }
//function to view menu items from databse for cake --> Sania Jain public void CookieSelected(object sender, RoutedEventArgs e) { ofosDataContext dc = new ofosDataContext(); CheckBox chkBox = (CheckBox)sender; if (chkBox.IsChecked == true) { cookieListBox.IsEnabled = true; selectedCategory.Add(chkBox); var Cookies = new List <ItemPriceClass>(); ISingleResult <FoodItem_FetchResult> Cookieresults = dc.FoodItem_Fetch(chkBox.Content.ToString()); foreach (FoodItem_FetchResult res in Cookieresults) { Console.WriteLine(res); Cookies.Add(new ItemPriceClass { ItemName = res.FoodItemName, ItemPrice = (decimal)res.FoodItemPrice }); cookieListBox.ItemsSource = Cookies; } } else { selectedCategory.Remove(chkBox); cookieListBox.IsEnabled = false; } enableCart(); }
private void btnSubmit_Click(object sender, RoutedEventArgs e) // By MOHSEN { try { if (!_isEditMode) // INSERT COMMAND { // Executing INSERT stored procedure -- By Mohsen ofosDataContext dc = new ofosDataContext(); dc.FoodItemInsert(txtName.Text, txtImage.Text, Convert.ToDecimal(txtPrice.Text), Convert.ToInt32(txtAvailability.Text), ComboCategory.SelectedValue.ToString()); MessageBox.Show("Record inserted successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } else // UPDATE COMMAND { // Executing UPDATE stored procedure -- By Mohsen ofosDataContext dc = new ofosDataContext(); dc.FoodItemUpdate(Convert.ToInt32(txtId.Text), txtName.Text, txtImage.Text, Convert.ToDecimal(txtPrice.Text), Convert.ToInt32(txtAvailability.Text), ComboCategory.SelectedValue.ToString()); MessageBox.Show("Record Updated successfully!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } } catch { MessageBox.Show("Please check your entries and try again!", "Validation problem", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void BtnEdit_Click(object sender, RoutedEventArgs e) { try { // Getting selected row GetIngredientsResult selectedItem = (GetIngredientsResult)GridIngredients.SelectedItem; if (selectedItem != null) { FoodIngredientsCU fi = new FoodIngredientsCU((GetIngredientsResult)GridIngredients.SelectedItem, ((FoodItem)GridFoodItem.SelectedItem).FoodItemName); // Open Update Form fi.ShowDialog(); // Refresh the grid // create data context ofosDataContext dc = new ofosDataContext(); // get selected id int selectedIndex = ((FoodItem)GridFoodItem.SelectedItem).Id; // fill the ingredients grid GridIngredients.ItemsSource = dc.GetIngredients(selectedIndex); } } catch { } }
//function to view menu items from databse for coffee --> Sania Jain public void coffeeSelected(object sender, RoutedEventArgs e) { ofosDataContext dc = new ofosDataContext(); CheckBox chkBox = (CheckBox)sender; if (chkBox.IsChecked == true) { coffeeListBox.IsEnabled = true; var Coffee = new List <ItemPriceClass>(); ISingleResult <FoodItem_FetchResult> Coffeeresults = dc.FoodItem_Fetch(chkBox.Content.ToString()); foreach (FoodItem_FetchResult res in Coffeeresults) { Console.WriteLine(res); Coffee.Add(new ItemPriceClass { ItemName = res.FoodItemName, ItemPrice = (decimal)res.FoodItemPrice }); } coffeeListBox.ItemsSource = Coffee; } else { coffeeListBox.IsEnabled = false; OrderListView.Items.Clear(); } }
//function to handle staff login (Admin and Kitchen) --> Sania Jain private void staffLogin_Click(object sender, RoutedEventArgs e) { ofosDataContext dc = new ofosDataContext(); ISingleResult <StaffLogin_CheckResult> tab = dc.StaffLogin_Check(UserNameTextBox.Text, passwordTextBox.Text); Console.WriteLine(tab); foreach (StaffLogin_CheckResult val in tab) { if (val.Type != null) { if (val.Type == "Admin") { //redirect to Admin code flow Admin.FoodItemForm fi = new Admin.FoodItemForm(); fi.ShowDialog(); } else if (val.Type == "Kitchen") { KitchenStaff.Kitchen ki = new KitchenStaff.Kitchen(); ki.ReloadButton.Visibility = Visibility.Hidden; ki.ShowDialog(); //redirect to Kitchen code flow } } } }
//function to manage cart button and add items to cart --> Sania Jain public void ManageCart(object sender, RoutedEventArgs e) { ofosDataContext dc = new ofosDataContext(); bool error = false; totalCost = 0; List <string> itm = new List <string>(); //check if the order object is having values then populate the cart if (ord.Count != 0) { OrderListView.Items.Clear(); foreach (Order o in ord) { //fetch item availability values from db before checkout ISingleResult <FoodItemAvailable_CheckResult> itemAvailableRes = dc.FoodItemAvailable_Check(o.ItemName.ToString()); foreach (FoodItemAvailable_CheckResult res in itemAvailableRes) { Console.WriteLine(res); if (!error) { //check if quantity added by user is not available, prompt to modify order if (res.FoodItemAvailable < o.ItemQuantity) { errorLabel.Content = "Added quantity of " + o.ItemName + " is not available."; error = true; if (itm.Count > 0) { itm.Clear(); } break; } else { //if everything is available, populate the cart errorLabel.Content = ""; error = false; itm.Add(o.ItemName + "---" + o.ItemPrice + "---" + o.ItemQuantity); //calculating the total cost of the order totalCost += Decimal.Multiply(o.ItemPrice, o.ItemQuantity); } } } } foreach (string s in itm) { //displaying order items in the cart box OrderListView.Items.Add(s); } checkout.IsEnabled = true; clearCart.IsEnabled = true; } //if nothing is selected, ask user to pick food items first else { errorLabel.Content = "Please add atleast one food item to cart for checkout."; } }
public FoodIngredients() { InitializeComponent(); ofosDataContext dc = new ofosDataContext(); GridFoodItem.ItemsSource = dc.FoodItems; }
public FoodItemForm() { // Initializing and showing data in grid - By Mohsen InitializeComponent(); ofosDataContext dc = new ofosDataContext(); FoodItemGrid.ItemsSource = dc.FoodItems; }
//function to display order placed --> Sania Jain public OrderDisplay(string orderId) { InitializeComponent(); orderIdLabel.Content = "Your order has been placed! Order Id is: " + orderId; ofosDataContext dc = new ofosDataContext(); OrderDisplayGrid.ItemsSource = dc.Orders; }
//to reload the data grid private void LoadData() { // Loading data grid view -- BY MOHSEN ofosDataContext dc = new ofosDataContext(); FoodItemGrid.ItemsSource = dc.FoodItems; /*DataGridTextColumn textColumn = new DataGridTextColumn(); * textColumn.Header = "Food Name"; * textColumn.Binding = new Binding("FoodItemName"); * FoodItemGrid.Columns.Add(textColumn);*/ }
private void btnNew_Click(object sender, RoutedEventArgs e) { // Create a new Insert form and show it as modal - By Mohsen FoodItemCU insertform = new FoodItemCU(); if (insertform.ShowDialog() == true) // Refresh the grid after insertion { ofosDataContext dc = new ofosDataContext(); FoodItemGrid.ItemsSource = dc.FoodItems; } LoadData(); //insertform.ShowDialog(); }
//function to handle customer login --> Sania Jain private void AddCustomer_click(object sender, RoutedEventArgs e) { //Data maping object to our database ofosDataContext clContext = new ofosDataContext(); //check if the customer name and phone exists in db int?Id = null; //calling the stored procedure to insert customer information and generate a customer if clContext.Customer_Insert(textbox1.Text, textBox2.Text, ref Id); //MessageBox.Show("Your customer id is: " + ((int)Id).ToString()); Menu menuWindow = new Menu(Id.ToString()); menuWindow.ShowDialog(); }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { try { // Executing UPDATE stored procedure ofosDataContext dc = new ofosDataContext(); int id = txtId.Text != "" && Convert.ToInt32(txtId.Text) > 0 ? Convert.ToInt32(txtId.Text) : -1; dc.FoodIngredientsInsertUpdate(id, Convert.ToInt32(txtFoodItemId.Text), txtIngredient.Text, Convert.ToDouble(txtAmount.Text), ComboUnit.SelectedValue.ToString()); MessageBox.Show("Operation successfull!", "Success", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } catch { MessageBox.Show("Please check your entries and try again!", "Validation problem", MessageBoxButton.OK, MessageBoxImage.Error); } }
// Returns the Tax ----- BY GEET private double getTax() { // creating an instance of data context ofosDataContext dc = new ofosDataContext(); // run the GetTax stored procedure and store the result in a list List <GetTaxResult> tr = dc.GetTax("Ontario").ToList <GetTaxResult>(); // Check if there is only 1 row of data, return the tax, otherwise return 0 if (tr.Count == 1) { return((double)tr[0].Tax); } else { return(0); } }
//function to manage cart button and add items to cart --> Sania Jain public void ManageCart(object sender, RoutedEventArgs e) { ofosDataContext dc = new ofosDataContext(); bool error = false; totalCost = 0; List <string> itm = new List <string>(); foreach (Order o in ord) { //fetch availability values from db before checkout ISingleResult <FoodItemAvailable_CheckResult> itemAvailableRes = dc.FoodItemAvailable_Check(o.ItemName.ToString()); foreach (FoodItemAvailable_CheckResult res in itemAvailableRes) { Console.WriteLine(res); if (!error) { if (res.FoodItemAvailable < o.ItemQuantity) { errorLabel.Content = "Added quantity of " + o.ItemName + " is not available."; error = true; if (itm.Count > 0) { itm.Clear(); } break; } else { errorLabel.Content = ""; itm.Add(o.ItemName + "---" + o.ItemPrice + "---" + o.ItemQuantity); //totalCost += decimal.Parse(o.ItemPrice * o.ItemQuantity); totalCost += Decimal.Multiply(o.ItemPrice, o.ItemQuantity); } } } } foreach (string s in itm) { OrderListView.Items.Add(s); } checkout.IsEnabled = true; }
//function to compute the total on checkout --> Sania Jain public void checkoutClick(object sender, RoutedEventArgs e) { String ordr = ""; ofosDataContext dc = new ofosDataContext(); foreach (Order o in ord) { int updatedQty = 0; //update foodItem table with availability ISingleResult <FoodItemAvailable_CheckResult> available = dc.FoodItemAvailable_Check(o.ItemName); foreach (FoodItemAvailable_CheckResult res in available) { //calculate the updated availability int availableQty = (int)res.FoodItemAvailable; updatedQty = availableQty - o.ItemQuantity; } //calling the stored procedure to update the food item availability dc.FoodItemAvailability_Update(o.ItemName, updatedQty); //creating order string for order table string orderStr = o.ItemName + "-" + o.ItemQuantity + " "; ordr += orderStr; } int? orderId = null; string Status = "placed"; //calling stored procedure to insert the order in the order table and get order id dc.Order_Insert(CustomerId, ordr, totalCost, Status, ref orderId); //display the order id //MessageBox.Show("Orderid: " + orderId); // Showing Receipt -- BY Geet ShowReceipt receipt = new ShowReceipt(ord, (int)orderId); receipt.ShowDialog(); this.Close(); OrderDisplay orderWindow = new OrderDisplay(orderId.ToString()); orderWindow.ShowDialog(); }
private void BtnInventory_Click(object sender, RoutedEventArgs e) { // Creating an instance of data context ofosDataContext dc = new ofosDataContext(); // an instance of categorized food to generate a summary CategorizedFood categorize = new CategorizedFood(); // Adding each item to category summary (it keeps distinct values and total only) foreach (FoodItem item in dc.FoodItems) { categorize.Add(new FoodCategory() { CategoryName = item.FoodItemCategory, Amount = (int)item.FoodItemAvailable }); } FoodItemSummary fis = new FoodItemSummary(categorize); fis.ShowDialog(); }
private void BtnDelete_Click(object sender, RoutedEventArgs e) { try { // Getting selected row FoodItem selectedItem = (FoodItem)FoodItemGrid.SelectedItem; if (selectedItem != null) { if (MessageBox.Show("Are you sure?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { ofosDataContext dc = new ofosDataContext(); // Delete the row dc.FoodItemDelete(selectedItem.Id); LoadData(); } } } catch { } }
private void btnNew_Click(object sender, RoutedEventArgs e) { // Getting selected row FoodItem selectedItem = (FoodItem)GridFoodItem.SelectedItem; if (selectedItem != null) { // Open Insert Form new FoodIngredientsCU(((FoodItem)GridFoodItem.SelectedItem).Id, ((FoodItem)GridFoodItem.SelectedItem).FoodItemName).ShowDialog(); // Refresh the grid // create data context ofosDataContext dc = new ofosDataContext(); // get selected id int selectedIndex = ((FoodItem)GridFoodItem.SelectedItem).Id; // fill the ingredients grid GridIngredients.ItemsSource = dc.GetIngredients(selectedIndex); } }
private void BtnEdit_Click(object sender, RoutedEventArgs e) { try { // Getting selected row FoodItem selectedItem = (FoodItem)FoodItemGrid.SelectedItem; if (selectedItem != null) { // Create a new Insert form and show it as modal - By Mohsen FoodItemCU updateform = new FoodItemCU(selectedItem.Id, selectedItem.FoodItemName, selectedItem.FoodItemImage, selectedItem.FoodItemPrice, selectedItem.FoodItemAvailable, selectedItem.FoodItemCategory); if (updateform.ShowDialog() == true) // Refresh the grid after insertion { ofosDataContext dc = new ofosDataContext(); FoodItemGrid.ItemsSource = dc.FoodItems; } LoadData(); //insertform.ShowDialog(); } } catch { } }
//function to handle staff login (Admin and Kitchen) --> Sania Jain private void staffLogin_Click(object sender, RoutedEventArgs e) { ofosDataContext dc = new ofosDataContext(); //fetching all values from staffLogin table ISingleResult <StaffLogin_CheckResult> tab = dc.StaffLogin_Check(UserNameTextBox.Text, passwordTextBox.Password); Console.WriteLine(tab); var lst = tab.ToList(); //check if the db has no record of staff show error of incorrect credentials. if (lst.Count == 0) { staffLoginError.Content = "Incorrect Credentials"; } else { staffLoginError.Content = ""; foreach (var val in lst) { //check the type of staff - Kitchen or Admin if (val.Type != null) { if (val.Type == "Admin") { //redirect to Admin code flow Admin.FoodItemForm fi = new Admin.FoodItemForm(); fi.ShowDialog(); } else if (val.Type == "Kitchen") { //redirect to Kitchen code flow KitchenStaff.Kitchen ki = new KitchenStaff.Kitchen(); ki.ReloadButton.Visibility = Visibility.Hidden; ki.ShowDialog(); } } } } }
//function to handle customer login --> Sania Jain private void AddCustomer_click(object sender, RoutedEventArgs e) { //check if phone number and name entered is not empty. If so, show error. if (phoneTextbox.Text == "" || unameTextbox.Text == "") { errorLabel.Content = "Please fill in all the fields before login."; } else { //Data maping object to our database ofosDataContext clContext = new ofosDataContext(); //check if the customer name and phone exists in db then return the customer id //if its a new customer then insert and return the customer id //this is checked by stored procedure Customer_Insert int?Id = null; //calling the stored procedure to insert customer information and generate a customer id clContext.Customer_Insert(unameTextbox.Text, phoneTextbox.Text, ref Id); //MessageBox.Show("Your customer id is: " + Id.ToString()); Menu menuWindow = new Menu(Id.ToString()); menuWindow.ShowDialog(); } }
//function to view menu items from databse for coffee --> Sania Jain public void coffeeSelected(object sender, RoutedEventArgs e) { ofosDataContext dc = new ofosDataContext(); CheckBox chkBox = (CheckBox)sender; if (chkBox.IsChecked == true) { //enabling the coffeList element coffeeListBox.IsEnabled = true; selectedCategory.Add(chkBox); var Coffee = new List <ItemPriceClass>(); //fetching coffee options from FoodItems table using storedProcedure FoodItem_Fetch ISingleResult <FoodItem_FetchResult> Coffeeresults = dc.FoodItem_Fetch(chkBox.Content.ToString()); //add each coffee item values in ItemPrice list foreach (FoodItem_FetchResult res in Coffeeresults) { Console.WriteLine(res); Coffee.Add(new ItemPriceClass { ItemName = res.FoodItemName, ItemPrice = (decimal)res.FoodItemPrice }); } //populate the listBox view with fetched coffee items coffeeListBox.ItemsSource = Coffee; } else { //remove all coffee items from order and disable the listView selectedCategory.Remove(chkBox); coffeeListBox.IsEnabled = false; OrderListView.Items.Clear(); } //calling function to enable the addtocart button enableCart(); }
private void LoadData() { dc = new ofosDataContext(); KitchenGrid.ItemsSource = dc.Orders; }
public LoginForm() { InitializeComponent(); dc = new ofosDataContext(); }