private void UserOrderHistory_Load(object sender, EventArgs e) { var orders = StaticAccessor.DB.GetOrders(UserId); foreach (var order in orders) { var row = new ListViewItem("" + order.Id); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + StaticAccessor.DB.GetRestaurant(order.RestaurantId).Name)); for (var i = 0; i < 8; i++) { if (i < order.FoodItems.Count) { row.SubItems.Add(new ListViewItem.ListViewSubItem(row, StaticAccessor.DB.GetFoodItem(order.FoodItems[i].Id, true).Name)); } else { row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "")); } } var cost = StaticAccessor.DoubleToMoneyString(order.Cost); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + cost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + order.Address)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + (order.Cancelled ? "Yes" : "No"))); UserOrders.Items.Add(row); } }
private void UserCheckout_Load(object sender, EventArgs e) { var membership = StaticAccessor.DB.GetUser(UserId).Membership; if (membership == 0) { YourOrder.Columns.RemoveAt(2); YourOrder.Columns[0].Width += 200; } foreach (var Food in Order.FoodItems) { var row = new ListViewItem(Food.Name); var cost = StaticAccessor.DoubleToMoneyString(Food.Cost); var discountedCost = StaticAccessor.DoubleToMoneyString(Food.Cost - Food.Discounts[membership]); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, cost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, discountedCost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + Food.Id)); YourOrder.Items.Add(row); } var deliveryCharge = StaticAccessor.DB.GetRestaurant(RestaurantId).Delivery; OrderPriceLabel.Text = @"Price: " + StaticAccessor.DoubleToMoneyString(Order.Cost - deliveryCharge); DeliveryChargeLabel.Text = @"Delivery: " + StaticAccessor.DoubleToMoneyString(deliveryCharge); PriceLabel.Text = @"Total: " + StaticAccessor.DoubleToMoneyString(Order.Cost); ErrorMessageLabel.Visible = false; }
private void EditRestaurantMenu_Load(object sender, EventArgs e) { RestaurantNameTextbox.Text = RestaurantName; RestaurantAddressTextbox.Text = RestaurantAddress; RestaurantOwnerUsernameTextbox.Text = RestaurantOwnerUsername; RestaurantOwnerTextbox.Text = RestaurantOwner; RestaurantPhoneNumberTextbox.Text = RestaurantPhoneNumber; RestaurantEmailTextbox.Text = RestaurantEmail; RestaurantDeliveryChargeTextbox.Text = RestaurantDeliveryCharge; RestaurantTypeTextbox.Text = RestaurantType; RestaurantOpeningHoursTextbox.Text = RestaurantOpeningHours; RestaurantClosingHoursTextbox.Text = RestaurantClosingHours; RestaurantDaysOpenTextbox.Text = RestaurantDaysOpen; RestaurantDeliveryChargeTextbox.Text = StaticAccessor.DoubleToMoneyString(Convert.ToDouble(RestaurantDeliveryCharge)); if (sysAdmin) { Text = "SysAdmin Menu: Edit Restaurant"; } else { DeleteRestaurantButton.Enabled = false; DeleteRestaurantButton.Visible = false; Text = "Admin Menu: Edit Restaurant"; } }
private void LoginButton_Click(object sender, EventArgs e) { //Hash password input so the raw password isn't stored in the database var hashPassword = StaticAccessor.HashString(Password); var User = StaticAccessor.DB.GetUser(0, Username); //Check User exists in db and compare hashed passwords if (User.Username == null || !User.Password.Equals(hashPassword)) { UserFound = false; } else { UserFound = true; } if (UserFound) { Interceptor interceptor = new ConcreteLoginInterceptor(); var dispatcher = new Dispatcher(); dispatcher.RegisterInterceptor(interceptor); if (User.SystemAdmin) { Hide(); var SAA = new SysAdminAuthentication(User.Id); SAA.ShowDialog(); } else { if (User.RestaurantAdmin && User.RestaurantId == 0) { MessageBox.Show("Login Failed"); ErrorMessageLabel.Text = "Error Message: Admin not assigned to a restaurant"; ErrorMessageLabel.Visible = true; PasswordTextbox.Text = ""; } else { dispatcher.DispatchLoginInterceptor(interceptor, this); Hide(); User.login(); } } } else { MessageBox.Show("Login Failed"); ErrorMessageLabel.Text = "Error Message: Incorrect Username or Password"; ErrorMessageLabel.Visible = true; PasswordTextbox.Text = ""; } }
private void UndoButton_Click(object sender, EventArgs e) { if (YourOrder.Items.Count > 0) { YourOrder.Items.RemoveAt(YourOrder.Items.Count - 1); try { Order.SetMemento(Mementos[Mementos.Count - 2]); } catch { Order.SetMemento(new Memento(Order.Id, Order.UserId, Order.Cancelled, new List <FoodItem>())); } Mementos.RemoveAt(Mementos.Count - 1); TotalCostLabel.Text = "" + StaticAccessor.DoubleToMoneyString(Order.Cost); } }
private void RestaurantMenu_SelectedIndexChanged(object sender, EventArgs e) { if (YourOrder.Items.Count < 8 && RestaurantMenu.SelectedItems.Count > 0) { var selectedRow = RestaurantMenu.SelectedItems[0]; YourOrder.Items.Add((ListViewItem)selectedRow.Clone()); selectedRow.Selected = false; //order.Cost += Convert.ToDouble(selectedRow.SubItems[1].Text); Order.Add(StaticAccessor.DB.GetFoodItem(Convert.ToInt32(selectedRow.SubItems[3].Text))); Mementos.Add(Order.CreateMemento()); TotalCostLabel.Text = "" + StaticAccessor.DoubleToMoneyString(Order.Cost); if (YourOrder.Items.Count >= 8) { MessageBox.Show(@"You've reached the item limit."); } } }
private void Form3_Load(object sender, EventArgs e) { var items = StaticAccessor.DB.GetFoodItems(); foreach (var item in items) { if (item.RestaurantId == RestaurantId) { var row = new ListViewItem("" + item.Id); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + StaticAccessor.DB.GetFoodItem(item.Id).Name)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + StaticAccessor.DoubleToMoneyString(item.Cost))); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + (item.Deleted ? "Yes" : "No"))); listView.Items.Add(row); } } }
private void RestAdminManageOrders_Load(object sender, EventArgs e) { var orders = StaticAccessor.DB.GetOrders(0, RestaurantId); foreach (var order in orders) { if (order.RestaurantId == RestaurantId) { var row = new ListViewItem("" + order.Id); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + StaticAccessor.DB.GetUser(order.UserId).Username)); var cost = StaticAccessor.DoubleToMoneyString(order.Cost); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + cost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + order.Address)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + (order.Cancelled ? "Yes" : "No"))); CurrentOrders.Items.Add(row); } } }
private void UserOrderMenu_Load(object sender, EventArgs e) { Order.UserId = UserId; Order.RestaurantId = RestaurantId; var membership = StaticAccessor.DB.GetUser(UserId).Membership; if (membership == 0) { RestaurantMenu.Columns.RemoveAt(2); RestaurantMenu.Columns[0].Width += 170; YourOrder.Columns.RemoveAt(2); YourOrder.Columns[0].Width += 170; } var FoodItems = StaticAccessor.DB.GetFoodItems(RestaurantId); foreach (var Food in FoodItems) { var row = new ListViewItem(Food.Name); var cost = StaticAccessor.DoubleToMoneyString(Food.Cost); var discountedCost = StaticAccessor.DoubleToMoneyString(Food.Cost - Food.Discounts[membership]); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, cost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, discountedCost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + Food.Id)); RestaurantMenu.Items.Add(row); } foreach (var Food in Order.FoodItems) { var row = new ListViewItem(Food.Name); var cost = StaticAccessor.DoubleToMoneyString(Food.Cost); var discountedCost = StaticAccessor.DoubleToMoneyString(Food.Cost - Food.Discounts[membership]); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, cost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, discountedCost)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + Food.Id)); YourOrder.Items.Add(row); } var delivery = StaticAccessor.DB.GetRestaurant(RestaurantId).Delivery; TotalCostLabel.Text = "" + StaticAccessor.DoubleToMoneyString(Order.Cost - delivery); }
private void RestAdminViewMenu_Load(object sender, EventArgs e) { PriceTextbox.Text = Price; var FoodItems = StaticAccessor.DB.GetFoodItems(RestaurantId); foreach (var Food in FoodItems) { var row = new ListViewItem("" + Food.Id); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + Food.Name)); row.SubItems.Add( new ListViewItem.ListViewSubItem(row, "" + StaticAccessor.DoubleToMoneyString(Food.Cost))); var bronze = StaticAccessor.DoubleToMoneyString(Math.Round(Food.Discounts[1], 2)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + bronze)); var silver = StaticAccessor.DoubleToMoneyString(Math.Round(Food.Discounts[2], 2)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + silver)); var gold = StaticAccessor.DoubleToMoneyString(Math.Round(Food.Discounts[3], 2)); row.SubItems.Add(new ListViewItem.ListViewSubItem(row, "" + gold)); RestaurantMenuList.Items.Add(row); } }
private void SaveChangesButton_Click(object sender, EventArgs e) { if (CorrectEmailFormat && CorrectNameFormat && CorrectUsernameFormat && CorrectPasswordFormat /* && CorrectRestaurantFormat*/) { //Hash password input so the raw password isn't stored in the database var hashPassword = StaticAccessor.HashString(Password); if (newAccount) { var user = new UserFactory().GetUser(0, Username, hashPassword, FirstName, LastName, Email, Membership, "User"); StaticAccessor.DB.InsertUser(user); MessageBox.Show(@"Account Created"); Hide(); new LoginMenuV2(); } else { var user = StaticAccessor.DB.GetUser(UserId); user.FirstName = FirstName; user.LastName = LastName; user.Username = Username; user.Password = hashPassword; user.Email = Email; user.Membership = Membership; StaticAccessor.DB.UpdateUser(user); MessageBox.Show(@"Changes Saved"); Hide(); var UMM = new UserMainMenu(UserId); UMM.ShowDialog(); } } else { ErrorMessageLabel.Text = "Error Message: Please Fix Any Issues with your details"; ErrorMessageLabel.Visible = true; } }
private void UserPlaceOrderMenu_Load(object sender, EventArgs e) { var order = StaticAccessor.DB.GetOrder(OrderId); var restaurant = StaticAccessor.DB.GetRestaurant(order.RestaurantId); TotalCost = order.Cost + restaurant.Delivery; //getOrderid and Cost OrderIdLabel.Text = @"Order ID: " + OrderId; TotalCostLabel.Text = @"Total Cost: " + StaticAccessor.DoubleToMoneyString(TotalCost); currentTime = DateTime.Now.ToString("h:mm"); TimeLabel.Text = @"Time: " + currentTime; var num = new Random(); var mins = num.Next(40, 100); var hours = 0; if (mins > 60) { hours = mins / 60; mins = mins - 60; } EDTime = hours + " Hours, " + mins + " Minutes"; EDTLabel.Text = @"Estimated Delivery Time: " + EDTime; }
private void SaveChangesButton_Click(object sender, EventArgs e) { if (CorrectEmailFormat && CorrectNameFormat && CorrectUsernameFormat && CorrectPasswordFormat /* && CorrectRestaurantFormat*/) { var UsernameExists = false; var EmailExists = false; //Boolean RestaurantExists = false; var Admin = StaticAccessor.DB.GetUser(0, AdminUsername); var Admin2 = StaticAccessor.DB.GetUser(0, "", AdminEmail); //Restaurant.Restaurant Rest = DatabaseHandler.GetRestaurant(AdminRestaurant); if (newAdmin) { if (Admin.Username == null) { } else { UsernameExists = true; ErrorMessage = "Error: Username Already Exists."; } if (Admin2.Username == null) { } else { EmailExists = true; ErrorMessage = "Error: Email Already Exists."; } } if (!UsernameExists && !EmailExists) { //check if admin already exists var RestaurantAdminExists = StaticAccessor.DB.GetUser(0, "", "", 0, AdminRestaurant); //AbstractUser IsCurrentAdmin = DatabaseHandler.CheckIfAdmin(AdminUsername); var CurrentAdmin = StaticAccessor.DB.GetUser(0, AdminUsername); //Hash password input so the raw password isn't stored in the database string hashPassword; if (sysAdmin && !newAdmin) { hashPassword = StaticAccessor.DB.GetUser(CurrentAdmin.Id).Password; } else { hashPassword = StaticAccessor.HashString(AdminPassword); } if (RestaurantAdminExists.Username == null) { if (newAdmin) { var restaurantId = StaticAccessor.DB.GetRestaurant(0, AdminRestaurant).Id; var user = new UserFactory().GetUser(CurrentAdmin.Id, AdminUsername, hashPassword, AdminFirstName, AdminLastName, AdminEmail, 0, "RestAdmin", restaurantId, true); StaticAccessor.DB.InsertUser(user); MessageBox.Show("New Admin Created"); Hide(); var SAAM = new SysAdminAdminsMenu(AdminId); SAAM.ShowDialog(); } } else { if (CurrentAdmin.RestaurantAdmin) //admin of that restaurant { var restaurantId = StaticAccessor.DB.GetRestaurant(0, AdminRestaurant).Id; var user = new UserFactory().GetUser(CurrentAdmin.Id, AdminUsername, hashPassword, AdminFirstName, AdminLastName, AdminEmail, 0, "RestAdmin", restaurantId, true); StaticAccessor.DB.UpdateUser(user); MessageBox.Show("Admin Details Updated"); if (sysAdmin) { Hide(); var SAAM = new SysAdminAdminsMenu(AdminId); SAAM.ShowDialog(); } else { Hide(); var RAM = new RestAdminMainMenu(AdminId, RestaurantId); RAM.ShowDialog(); } MessageBox.Show("Admin Details Updated"); if (sysAdmin) { Hide(); var SAAM = new SysAdminAdminsMenu(AdminId); SAAM.ShowDialog(); } else { Hide(); var RAM = new RestAdminMainMenu(AdminId, RestaurantId); RAM.ShowDialog(); } } else { UsernameExists = true; MessageBox.Show("Error: An Admin Already exists for that restaurant"); } } } else { ErrorMessageLabel.Visible = true; ErrorMessageLabel.Text = "Error Message: " + ErrorMessage; } } else { ErrorMessageLabel.Text = "Error Message: Please Fix Any Issues with the Admin's details"; ErrorMessageLabel.Visible = true; } }