JIT
Database & Forms Development
Database creation: 1.Create a database “Session1” (MySQL or MS SQL). Import the provided SQL scripts without changing the structure. 2.Login form: Realize login form with fields for employee (optional) and user. Add functions “Show password”, “Stay logged in” and “Create” (go to the login form). 3.Account creation form: Registration form with mandatory fields, password verification (min. 5 symbols) and agreement with terms and conditions (Terms.txt file). After successful registration - proceed to the management form. 4.Management form: Main form with tabs "Traveler" and "Owner/Manager". Traveler: search for accommodation by name, neighborhood or proximity to attractions, display results in a table. Owner/Manager: manage listings (add, edit), display list of properties. 5.Form for adding/editing a listing: Two modes: adding and editing. Three tabs: "Details" (type, capacity, number of rooms, etc.). “Amenities” (select from a list). “Distance to attractions” (giving distance and time). Navigation: “Next”/‘Done’ when adding, “Close” when editing. 6.Unit Test: Write a test for the user registration method, deleting the test record after execution. Requirements: Use standard date format (YYYYY-MM-DD). Add checks, comments in code, scroll bars if necessary. Delete and Cancel buttons are red. Center forms, block background operations when form is active.

Okay, let's start by setting up the project structure, data models, and the initial Login Form.

We will use Windows Forms and Entity Framework Core with SQL Server.

1. Project Setup and Dependencies:

First, create a new Windows Forms App (.NET) project named Session1.WinForms.

Then, add the necessary NuGet packages:

  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.Design (for migrations, if needed later)

2. Data Models and DbContext:

We'll define basic models for User, Listing, Amenity, etc., and the DbContext.

Explanation:

  1. Models: Defined basic C# classes (User, Listing, Amenity, etc.) that represent the database tables. Added [Required], [MaxLength], and [ForeignKey] attributes for basic validation and relationships.
  2. AppDbContext: Created the Entity Framework Core DbContext (AppDbContext). It includes DbSet properties for each model and configures the database connection string (hardcoded for now) and model relationships (like the many-to-many ListingAmenity).
  3. PasswordHelper: Added a static class for basic password hashing (using SHA256). Note: For production, use a more robust library like BCrypt.Net.
  4. AuthService: Created a service class to handle user authentication logic, interacting with the AppDbContext.
  5. LoginForm.cs:
    • Created the main LoginForm class.
    • Added UI controls (Labels, TextBoxes, CheckBoxes, Buttons) using the designer-generated InitializeComponent method (included in the code).
    • Implemented event handlers:
      • showPasswordCheckBox_CheckedChanged: Toggles password visibility.
      • loginButton_Click: Calls AuthService to authenticate, handles success (opens ManagementForm placeholder) or failure (shows message box), and manages UI state during login. Uses async/await for non-blocking UI.
      • createAccountButton_Click: Opens the RegistrationForm placeholder modally.
      • cancelButton_Click: Closes the form.
    • Set StartPosition to CenterScreen.
    • Set CancelButton color to Red.
    • Added placeholder classes for RegistrationForm and ManagementForm so the code compiles.
  6. Program.cs: Modified the entry point to start the application with LoginForm.

Next Steps:

  1. Implement the RegistrationForm with its fields, validation, and user creation logic.
  2. Implement the ManagementForm with its tabs and basic functionality.
  3. Implement the ListingForm for adding/editing listings.
  4. Write the unit test for user registration.
  5. Refine error handling, UI details, and potentially replace direct DbContext instantiation with Dependency Injection.
  6. Ensure the database "Session1" is created and the schema matches the models (you might need to use EF Core Migrations: Add-Migration InitialCreate and Update-Database in the Package Manager Console).
Updated files
v1