private void BackButton_Click(object sender, EventArgs e) { Hide(); var RAM = new RestAdminMainMenu(AdminId, RestaurantId); RAM.ShowDialog(); }
private void BackButton_Click(object sender, EventArgs e) { if (sysAdmin) { Hide(); var SAAM = new SysAdminAdminsMenu(AdminId); SAAM.ShowDialog(); } else { Hide(); var RAM = new RestAdminMainMenu(AdminId, RestaurantId); RAM.ShowDialog(); } }
private void BackButton_Click(object sender, EventArgs e) { if (sysAdmin) { if (newRestaurant) { Hide(); var SRM = new SysAdminRestaurantsMenu(AdminId); SRM.ShowDialog(); } else { Hide(); var SVR = new SysViewRestaraunt(AdminId, RestaurantId); SVR.ShowDialog(); } } else { Hide(); var RM = new RestAdminMainMenu(AdminId, RestaurantId); RM.ShowDialog(); } }
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; } }
private void SaveChangesButton_Click(object sender, EventArgs e) { var AdminInUse = StaticAccessor.DB.GetUser(0, RestaurantOwnerUsername); var CurrentRestaurant = StaticAccessor.DB.GetRestaurant(RestaurantId); if (AdminInUse.RestaurantId != 0 && AdminInUse.RestaurantId != CurrentRestaurant.Id) { CorrectOwnerFormat = false; OwnerUsernameLabel.Text = "Owner Username: Error: Admin already in use."; } else { CorrectOwnerFormat = true; } if (CorrectNameFormat && CorrectAddressFormat && CorrectOwnerFormat && CorrectPhoneNumberFormat && CorrectEmailFormat && CorrectOpeningHoursFormat && CorrectClosingHoursFormat && CorrectDaysOpenFormat && CorrectTypeFormat && CorrectDeliveryChargeFormat && CorrectOwnerUsernameFormat) { var previousOwner = StaticAccessor.DB.GetUser(StaticAccessor.DB.GetRestaurant(RestaurantId).OwnerId); var ownerId = StaticAccessor.DB.GetUser(0, RestaurantOwnerUsername).Id; var restaurant = new Restaurant.Restaurant(RestaurantId, RestaurantName, RestaurantAddress, ownerId, RestaurantPhoneNumber, RestaurantEmail, RestaurantOpeningHours, RestaurantClosingHours, RestaurantDaysOpen, RestaurantType, double.Parse(RestaurantDeliveryCharge), false); if (newRestaurant) { StaticAccessor.DB.InsertRestaurant(restaurant); } else { StaticAccessor.DB.UpdateRestaurant(restaurant); } var newRestaurantId = StaticAccessor.DB.GetRestaurant(0, RestaurantName).Id; var restaurantAdmin = StaticAccessor.DB.GetUser(ownerId); restaurantAdmin.RestaurantId = newRestaurantId; StaticAccessor.DB.UpdateUser(restaurantAdmin); if (previousOwner.Username != null && !previousOwner.Username.Equals(RestaurantOwnerUsername)) { previousOwner.RestaurantId = 0; StaticAccessor.DB.UpdateUser(previousOwner); } if (sysAdmin) { Hide(); var SVR = new SysViewRestaraunt(AdminId, RestaurantId); SVR.ShowDialog(); } else { Hide(); var RM = new RestAdminMainMenu(AdminId, RestaurantId); RM.ShowDialog(); } } else { ErrorMessageLabel.Text = "Error Message: Please Fix Any Issues with the Restaurant's details"; ErrorMessageLabel.Visible = true; } }