Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Hide();
            var SVR = new SysViewRestaraunt(AdminId, RestaurantId);

            SVR.ShowDialog();
        }
        private void ListOfRestaurants_SelectedIndexChanged(object sender, EventArgs e)
        {
            RestaurantName = ListOfRestaurants.SelectedItems[0].Text;
            RestaurantId   = int.Parse(ListOfRestaurants.SelectedItems[0].SubItems[1].Text);
            Hide();
            var SVR = new SysViewRestaraunt(UserId, RestaurantId);

            SVR.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)
        {
            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;
            }
        }