Okay, let's start by setting up the project structure and creating the initial Login Form.
You are absolutely correct! My apologies. I only provided the initial Login Form setup.
Let's continue building the application based on the requirements. We will now add the Create Account Form, the Management Form with its tabs, the Add/Edit Listing Form, and set up the structure for the unit test.
This will involve creating several new forms and adding more logic. We'll use placeholder data and logic where database interaction would normally occur.
<jitProject id="worldskills-app-login" title="WorldSkills Application - Full Form Implementation"> <jitFile type="file" filePath="WorldSkillsApp/Program.cs"> using System; using System.Windows.Forms;namespace WorldSkillsApp { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Ensure we always start with the Login Form Application.Run(new LoginForm()); }
// Placeholder for global user state if needed (alternative to passing data)
// public static User CurrentUser { get; set; }
// public static bool IsEmployeeSession { get; set; }
}
// Placeholder for global user state if needed (alternative to passing data)
// public static User CurrentUser { get; set; }
// public static bool IsEmployeeSession { get; set; }
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/LoginForm.Designer.cs"> namespace WorldSkillsApp { partial class LoginForm { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblEmployee = new System.Windows.Forms.Label();
this.txtEmployeeUsername = new System.Windows.Forms.TextBox();
this.lblUser = new System.Windows.Forms.Label();
this.txtUsername = new System.Windows.Forms.TextBox();
this.lblPassword = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.chkShowPassword = new System.Windows.Forms.CheckBox();
this.chkStayLoggedIn = new System.Windows.Forms.CheckBox();
this.btnLogin = new System.Windows.Forms.Button();
this.btnCreateAccount = new System.Windows.Forms.Button();
this.lblTitle = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblEmployee
//
this.lblEmployee.AutoSize = true;
this.lblEmployee.Location = new System.Drawing.Point(40, 60);
this.lblEmployee.Name = "lblEmployee";
this.lblEmployee.Size = new System.Drawing.Size(108, 13);
this.lblEmployee.TabIndex = 0;
this.lblEmployee.Text = "Employee Username:";
//
// txtEmployeeUsername
//
this.txtEmployeeUsername.Location = new System.Drawing.Point(154, 57);
this.txtEmployeeUsername.Name = "txtEmployeeUsername";
this.txtEmployeeUsername.Size = new System.Drawing.Size(180, 20);
this.txtEmployeeUsername.TabIndex = 1;
//
// lblUser
//
this.lblUser.AutoSize = true;
this.lblUser.Location = new System.Drawing.Point(40, 90);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(85, 13);
this.lblUser.TabIndex = 2;
this.lblUser.Text = "User Username:";
//
// txtUsername
//
this.txtUsername.Location = new System.Drawing.Point(154, 87);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(180, 20);
this.txtUsername.TabIndex = 3;
//
// lblPassword
//
this.lblPassword.AutoSize = true;
this.lblPassword.Location = new System.Drawing.Point(40, 120);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(56, 13);
this.lblPassword.TabIndex = 4;
this.lblPassword.Text = "Password:";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(154, 117);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(180, 20);
this.txtPassword.TabIndex = 5;
this.txtPassword.UseSystemPasswordChar = true;
//
// chkShowPassword
//
this.chkShowPassword.AutoSize = true;
this.chkShowPassword.Location = new System.Drawing.Point(154, 143);
this.chkShowPassword.Name = "chkShowPassword";
this.chkShowPassword.Size = new System.Drawing.Size(102, 17);
this.chkShowPassword.TabIndex = 6;
this.chkShowPassword.Text = "Show Password";
this.chkShowPassword.UseVisualStyleBackColor = true;
this.chkShowPassword.CheckedChanged += new System.EventHandler(this.chkShowPassword_CheckedChanged);
//
// chkStayLoggedIn
//
this.chkStayLoggedIn.AutoSize = true;
this.chkStayLoggedIn.Location = new System.Drawing.Point(154, 166);
this.chkStayLoggedIn.Name = "chkStayLoggedIn";
this.chkStayLoggedIn.Size = new System.Drawing.Size(95, 17);
this.chkStayLoggedIn.TabIndex = 7;
this.chkStayLoggedIn.Text = "Stay Logged In";
this.chkStayLoggedIn.UseVisualStyleBackColor = true;
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(154, 199);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(75, 23);
this.btnLogin.TabIndex = 8;
this.btnLogin.Text = "Login";
this.btnLogin.UseVisualStyleBackColor = true;
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// btnCreateAccount
//
this.btnCreateAccount.Location = new System.Drawing.Point(235, 199);
this.btnCreateAccount.Name = "btnCreateAccount";
this.btnCreateAccount.Size = new System.Drawing.Size(99, 23);
this.btnCreateAccount.TabIndex = 9;
this.btnCreateAccount.Text = "Create Account";
this.btnCreateAccount.UseVisualStyleBackColor = true;
this.btnCreateAccount.Click += new System.EventHandler(this.btnCreateAccount_Click);
//
// lblTitle
//
this.lblTitle.AutoSize = true;
this.lblTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTitle.Location = new System.Drawing.Point(150, 9);
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(62, 24);
this.lblTitle.TabIndex = 10;
this.lblTitle.Text = "Login";
//
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(374, 251);
this.Controls.Add(this.lblTitle);
this.Controls.Add(this.btnCreateAccount);
this.Controls.Add(this.btnLogin);
this.Controls.Add(this.chkStayLoggedIn);
this.Controls.Add(this.chkShowPassword);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.txtUsername);
this.Controls.Add(this.lblUser);
this.Controls.Add(this.txtEmployeeUsername);
this.Controls.Add(this.lblEmployee);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "LoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Login - WorldSkills App";
this.Load += new System.EventHandler(this.LoginForm_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblEmployee;
private System.Windows.Forms.TextBox txtEmployeeUsername;
private System.Windows.Forms.Label lblUser;
private System.Windows.Forms.TextBox txtUsername;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.CheckBox chkShowPassword;
private System.Windows.Forms.CheckBox chkStayLoggedIn;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Button btnCreateAccount;
private System.Windows.Forms.Label lblTitle;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblEmployee = new System.Windows.Forms.Label();
this.txtEmployeeUsername = new System.Windows.Forms.TextBox();
this.lblUser = new System.Windows.Forms.Label();
this.txtUsername = new System.Windows.Forms.TextBox();
this.lblPassword = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.chkShowPassword = new System.Windows.Forms.CheckBox();
this.chkStayLoggedIn = new System.Windows.Forms.CheckBox();
this.btnLogin = new System.Windows.Forms.Button();
this.btnCreateAccount = new System.Windows.Forms.Button();
this.lblTitle = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblEmployee
//
this.lblEmployee.AutoSize = true;
this.lblEmployee.Location = new System.Drawing.Point(40, 60);
this.lblEmployee.Name = "lblEmployee";
this.lblEmployee.Size = new System.Drawing.Size(108, 13);
this.lblEmployee.TabIndex = 0;
this.lblEmployee.Text = "Employee Username:";
//
// txtEmployeeUsername
//
this.txtEmployeeUsername.Location = new System.Drawing.Point(154, 57);
this.txtEmployeeUsername.Name = "txtEmployeeUsername";
this.txtEmployeeUsername.Size = new System.Drawing.Size(180, 20);
this.txtEmployeeUsername.TabIndex = 1;
//
// lblUser
//
this.lblUser.AutoSize = true;
this.lblUser.Location = new System.Drawing.Point(40, 90);
this.lblUser.Name = "lblUser";
this.lblUser.Size = new System.Drawing.Size(85, 13);
this.lblUser.TabIndex = 2;
this.lblUser.Text = "User Username:";
//
// txtUsername
//
this.txtUsername.Location = new System.Drawing.Point(154, 87);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(180, 20);
this.txtUsername.TabIndex = 3;
//
// lblPassword
//
this.lblPassword.AutoSize = true;
this.lblPassword.Location = new System.Drawing.Point(40, 120);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(56, 13);
this.lblPassword.TabIndex = 4;
this.lblPassword.Text = "Password:";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(154, 117);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(180, 20);
this.txtPassword.TabIndex = 5;
this.txtPassword.UseSystemPasswordChar = true;
//
// chkShowPassword
//
this.chkShowPassword.AutoSize = true;
this.chkShowPassword.Location = new System.Drawing.Point(154, 143);
this.chkShowPassword.Name = "chkShowPassword";
this.chkShowPassword.Size = new System.Drawing.Size(102, 17);
this.chkShowPassword.TabIndex = 6;
this.chkShowPassword.Text = "Show Password";
this.chkShowPassword.UseVisualStyleBackColor = true;
this.chkShowPassword.CheckedChanged += new System.EventHandler(this.chkShowPassword_CheckedChanged);
//
// chkStayLoggedIn
//
this.chkStayLoggedIn.AutoSize = true;
this.chkStayLoggedIn.Location = new System.Drawing.Point(154, 166);
this.chkStayLoggedIn.Name = "chkStayLoggedIn";
this.chkStayLoggedIn.Size = new System.Drawing.Size(95, 17);
this.chkStayLoggedIn.TabIndex = 7;
this.chkStayLoggedIn.Text = "Stay Logged In";
this.chkStayLoggedIn.UseVisualStyleBackColor = true;
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(154, 199);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(75, 23);
this.btnLogin.TabIndex = 8;
this.btnLogin.Text = "Login";
this.btnLogin.UseVisualStyleBackColor = true;
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// btnCreateAccount
//
this.btnCreateAccount.Location = new System.Drawing.Point(235, 199);
this.btnCreateAccount.Name = "btnCreateAccount";
this.btnCreateAccount.Size = new System.Drawing.Size(99, 23);
this.btnCreateAccount.TabIndex = 9;
this.btnCreateAccount.Text = "Create Account";
this.btnCreateAccount.UseVisualStyleBackColor = true;
this.btnCreateAccount.Click += new System.EventHandler(this.btnCreateAccount_Click);
//
// lblTitle
//
this.lblTitle.AutoSize = true;
this.lblTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTitle.Location = new System.Drawing.Point(150, 9);
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(62, 24);
this.lblTitle.TabIndex = 10;
this.lblTitle.Text = "Login";
//
// LoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(374, 251);
this.Controls.Add(this.lblTitle);
this.Controls.Add(this.btnCreateAccount);
this.Controls.Add(this.btnLogin);
this.Controls.Add(this.chkStayLoggedIn);
this.Controls.Add(this.chkShowPassword);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.txtUsername);
this.Controls.Add(this.lblUser);
this.Controls.Add(this.txtEmployeeUsername);
this.Controls.Add(this.lblEmployee);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "LoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Login - WorldSkills App";
this.Load += new System.EventHandler(this.LoginForm_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblEmployee;
private System.Windows.Forms.TextBox txtEmployeeUsername;
private System.Windows.Forms.Label lblUser;
private System.Windows.Forms.TextBox txtUsername;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.CheckBox chkShowPassword;
private System.Windows.Forms.CheckBox chkStayLoggedIn;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Button btnCreateAccount;
private System.Windows.Forms.Label lblTitle;
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/LoginForm.cs"> using System; using System.Windows.Forms;
namespace WorldSkillsApp { public partial class LoginForm : Form { // In a real application, use a proper service layer (BLL/DAL) private AuthenticationService _authService = new AuthenticationService(); private UserSessionService _sessionService = new UserSessionService();
public LoginForm()
{
InitializeComponent();
}
private void LoginForm_Load(object sender, EventArgs e)
{
// Check if "Stay Logged In" was previously selected and valid
var loggedInUser = _sessionService.GetRememberedUser();
if (loggedInUser != null)
{
Console.WriteLine($"Found remembered user: {loggedInUser.Username}");
// In a real app, you might want to re-validate the token/session
ShowManagementForm(loggedInUser.Username, loggedInUser.IsEmployeeLogin);
this.Hide(); // Hide login form
// Use BeginInvoke to ensure the ManagementForm is shown *after* Load completes
this.BeginInvoke(new Action(() => this.Hide()));
}
}
private void btnLogin_Click(object sender, EventArgs e)
{
string employeeUsername = txtEmployeeUsername.Text.Trim();
string username = txtUsername.Text.Trim();
string password = txtPassword.Text;
// Basic validation
if (string.IsNullOrEmpty(username))
{
MessageBox.Show("User Username cannot be empty.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtUsername.Focus();
return;
}
if (string.IsNullOrEmpty(password))
{
MessageBox.Show("Password cannot be empty.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtPassword.Focus();
return;
}
bool loginSuccess = false;
bool isEmployeeLogin = !string.IsNullOrEmpty(employeeUsername);
string effectiveUsername = username; // The user context we operate under
if (isEmployeeLogin)
{
loginSuccess = _authService.AuthenticateEmployee(employeeUsername, password, username);
}
else
{
loginSuccess = _authService.AuthenticateUser(username, password);
}
if (loginSuccess)
{
MessageBox.Show("Login Successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (chkStayLoggedIn.Checked)
{
_sessionService.RememberUser(effectiveUsername, isEmployeeLogin);
}
else
{
_sessionService.ForgetUser(); // Clear any previous "remember me"
}
ShowManagementForm(effectiveUsername, isEmployeeLogin);
this.Hide(); // Hide login form instead of closing immediately
}
else
{
MessageBox.Show(_authService.GetLastError(), "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPassword.Clear();
txtPassword.Focus();
}
}
private void btnCreateAccount_Click(object sender, EventArgs e)
{
// Open the Create Account form
using (CreateAccountForm createAccountForm = new CreateAccountForm())
{
DialogResult result = createAccountForm.ShowDialog();
// Optional: Handle if registration was successful (e.g., prefill username)
if (result == DialogResult.OK)
{
// Maybe prefill username if createAccountForm exposes it
// txtUsername.Text = createAccountForm.RegisteredUsername;
}
}
}
private void chkShowPassword_CheckedChanged(object sender, EventArgs e)
{
txtPassword.UseSystemPasswordChar = !chkShowPassword.Checked;
}
private void ShowManagementForm(string loggedInUsername, bool loggedInAsEmployee)
{
// Pass necessary user info to the management form
ManagementForm managementForm = new ManagementForm(loggedInUsername, loggedInAsEmployee, _authService, _sessionService);
managementForm.FormClosed += ManagementForm_FormClosed; // Handle logout/exit
managementForm.Show();
}
private void ManagementForm_FormClosed(object sender, FormClosedEventArgs e)
{
// When the ManagementForm closes (due to logout or exit),
// decide whether to show the login form again or close the application.
ManagementForm mf = sender as ManagementForm;
if (mf != null && mf.LogoutInitiated)
{
_sessionService.ForgetUser(); // Ensure "remember me" is cleared on explicit logout
this.ClearForm();
this.Show(); // Show login form again
}
else
{
this.Close(); // Exit application if ManagementForm was closed directly
}
}
private void ClearForm()
{
txtEmployeeUsername.Clear();
txtUsername.Clear();
txtPassword.Clear();
chkShowPassword.Checked = false;
chkStayLoggedIn.Checked = false;
txtUsername.Focus();
}
}
public LoginForm()
{
InitializeComponent();
}
private void LoginForm_Load(object sender, EventArgs e)
{
// Check if "Stay Logged In" was previously selected and valid
var loggedInUser = _sessionService.GetRememberedUser();
if (loggedInUser != null)
{
Console.WriteLine($"Found remembered user: {loggedInUser.Username}");
// In a real app, you might want to re-validate the token/session
ShowManagementForm(loggedInUser.Username, loggedInUser.IsEmployeeLogin);
this.Hide(); // Hide login form
// Use BeginInvoke to ensure the ManagementForm is shown *after* Load completes
this.BeginInvoke(new Action(() => this.Hide()));
}
}
private void btnLogin_Click(object sender, EventArgs e)
{
string employeeUsername = txtEmployeeUsername.Text.Trim();
string username = txtUsername.Text.Trim();
string password = txtPassword.Text;
// Basic validation
if (string.IsNullOrEmpty(username))
{
MessageBox.Show("User Username cannot be empty.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtUsername.Focus();
return;
}
if (string.IsNullOrEmpty(password))
{
MessageBox.Show("Password cannot be empty.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtPassword.Focus();
return;
}
bool loginSuccess = false;
bool isEmployeeLogin = !string.IsNullOrEmpty(employeeUsername);
string effectiveUsername = username; // The user context we operate under
if (isEmployeeLogin)
{
loginSuccess = _authService.AuthenticateEmployee(employeeUsername, password, username);
}
else
{
loginSuccess = _authService.AuthenticateUser(username, password);
}
if (loginSuccess)
{
MessageBox.Show("Login Successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (chkStayLoggedIn.Checked)
{
_sessionService.RememberUser(effectiveUsername, isEmployeeLogin);
}
else
{
_sessionService.ForgetUser(); // Clear any previous "remember me"
}
ShowManagementForm(effectiveUsername, isEmployeeLogin);
this.Hide(); // Hide login form instead of closing immediately
}
else
{
MessageBox.Show(_authService.GetLastError(), "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPassword.Clear();
txtPassword.Focus();
}
}
private void btnCreateAccount_Click(object sender, EventArgs e)
{
// Open the Create Account form
using (CreateAccountForm createAccountForm = new CreateAccountForm())
{
DialogResult result = createAccountForm.ShowDialog();
// Optional: Handle if registration was successful (e.g., prefill username)
if (result == DialogResult.OK)
{
// Maybe prefill username if createAccountForm exposes it
// txtUsername.Text = createAccountForm.RegisteredUsername;
}
}
}
private void chkShowPassword_CheckedChanged(object sender, EventArgs e)
{
txtPassword.UseSystemPasswordChar = !chkShowPassword.Checked;
}
private void ShowManagementForm(string loggedInUsername, bool loggedInAsEmployee)
{
// Pass necessary user info to the management form
ManagementForm managementForm = new ManagementForm(loggedInUsername, loggedInAsEmployee, _authService, _sessionService);
managementForm.FormClosed += ManagementForm_FormClosed; // Handle logout/exit
managementForm.Show();
}
private void ManagementForm_FormClosed(object sender, FormClosedEventArgs e)
{
// When the ManagementForm closes (due to logout or exit),
// decide whether to show the login form again or close the application.
ManagementForm mf = sender as ManagementForm;
if (mf != null && mf.LogoutInitiated)
{
_sessionService.ForgetUser(); // Ensure "remember me" is cleared on explicit logout
this.ClearForm();
this.Show(); // Show login form again
}
else
{
this.Close(); // Exit application if ManagementForm was closed directly
}
}
private void ClearForm()
{
txtEmployeeUsername.Clear();
txtUsername.Clear();
txtPassword.Clear();
chkShowPassword.Checked = false;
chkStayLoggedIn.Checked = false;
txtUsername.Focus();
}
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/CreateAccountForm.Designer.cs"> namespace WorldSkillsApp { partial class CreateAccountForm { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblUsername = new System.Windows.Forms.Label();
this.txtUsername = new System.Windows.Forms.TextBox();
this.lblFullName = new System.Windows.Forms.Label();
this.txtFullName = new System.Windows.Forms.TextBox();
this.lblBirthdate = new System.Windows.Forms.Label();
this.dtpBirthdate = new System.Windows.Forms.DateTimePicker();
this.lblPassword = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.lblConfirmPassword = new System.Windows.Forms.Label();
this.txtConfirmPassword = new System.Windows.Forms.TextBox();
this.chkAgreeTerms = new System.Windows.Forms.CheckBox();
this.btnViewTerms = new System.Windows.Forms.Button();
this.btnRegister = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.lblTitle = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblUsername
//
this.lblUsername.AutoSize = true;
this.lblUsername.Location = new System.Drawing.Point(30, 60);
this.lblUsername.Name = "lblUsername";
this.lblUsername.Size = new System.Drawing.Size(58, 13);
this.lblUsername.TabIndex = 0;
this.lblUsername.Text = "Username:";
//
// txtUsername
//
this.txtUsername.Location = new System.Drawing.Point(140, 57);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(200, 20);
this.txtUsername.TabIndex = 1;
//
// lblFullName
//
this.lblFullName.AutoSize = true;
this.lblFullName.Location = new System.Drawing.Point(30, 90);
this.lblFullName.Name = "lblFullName";
this.lblFullName.Size = new System.Drawing.Size(57, 13);
this.lblFullName.TabIndex = 2;
this.lblFullName.Text = "Full Name:";
//
// txtFullName
//
this.txtFullName.Location = new System.Drawing.Point(140, 87);
this.txtFullName.Name = "txtFullName";
this.txtFullName.Size = new System.Drawing.Size(200, 20);
this.txtFullName.TabIndex = 3;
//
// lblBirthdate
//
this.lblBirthdate.AutoSize = true;
this.lblBirthdate.Location = new System.Drawing.Point(30, 120);
this.lblBirthdate.Name = "lblBirthdate";
this.lblBirthdate.Size = new System.Drawing.Size(52, 13);
this.lblBirthdate.TabIndex = 4;
this.lblBirthdate.Text = "Birthdate:";
//
// dtpBirthdate
//
this.dtpBirthdate.Location = new System.Drawing.Point(140, 117);
this.dtpBirthdate.Name = "dtpBirthdate";
this.dtpBirthdate.Size = new System.Drawing.Size(200, 20);
this.dtpBirthdate.TabIndex = 5;
//
// lblPassword
//
this.lblPassword.AutoSize = true;
this.lblPassword.Location = new System.Drawing.Point(30, 150);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(56, 13);
this.lblPassword.TabIndex = 6;
this.lblPassword.Text = "Password:";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(140, 147);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(200, 20);
this.txtPassword.TabIndex = 7;
this.txtPassword.UseSystemPasswordChar = true;
//
// lblConfirmPassword
//
this.lblConfirmPassword.AutoSize = true;
this.lblConfirmPassword.Location = new System.Drawing.Point(30, 180);
this.lblConfirmPassword.Name = "lblConfirmPassword";
this.lblConfirmPassword.Size = new System.Drawing.Size(94, 13);
this.lblConfirmPassword.TabIndex = 8;
this.lblConfirmPassword.Text = "Confirm Password:";
//
// txtConfirmPassword
//
this.txtConfirmPassword.Location = new System.Drawing.Point(140, 177);
this.txtConfirmPassword.Name = "txtConfirmPassword";
this.txtConfirmPassword.Size = new System.Drawing.Size(200, 20);
this.txtConfirmPassword.TabIndex = 9;
this.txtConfirmPassword.UseSystemPasswordChar = true;
//
// chkAgreeTerms
//
this.chkAgreeTerms.AutoSize = true;
this.chkAgreeTerms.Enabled = false; // Disabled until terms are viewed
this.chkAgreeTerms.Location = new System.Drawing.Point(140, 213);
this.chkAgreeTerms.Name = "chkAgreeTerms";
this.chkAgreeTerms.Size = new System.Drawing.Size(165, 17);
this.chkAgreeTerms.TabIndex = 10;
this.chkAgreeTerms.Text = "I agree to Terms && Conditions";
this.chkAgreeTerms.UseVisualStyleBackColor = true;
//
// btnViewTerms
//
this.btnViewTerms.Location = new System.Drawing.Point(30, 210);
this.btnViewTerms.Name = "btnViewTerms";
this.btnViewTerms.Size = new System.Drawing.Size(94, 23);
this.btnViewTerms.TabIndex = 11;
this.btnViewTerms.Text = "View Terms";
this.btnViewTerms.UseVisualStyleBackColor = true;
this.btnViewTerms.Click += new System.EventHandler(this.btnViewTerms_Click);
//
// btnRegister
//
this.btnRegister.Location = new System.Drawing.Point(140, 249);
this.btnRegister.Name = "btnRegister";
this.btnRegister.Size = new System.Drawing.Size(100, 23);
this.btnRegister.TabIndex = 12;
this.btnRegister.Text = "Register && Login";
this.btnRegister.UseVisualStyleBackColor = true;
this.btnRegister.Click += new System.EventHandler(this.btnRegister_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(246, 249);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 13;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// lblTitle
//
this.lblTitle.AutoSize = true;
this.lblTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTitle.Location = new System.Drawing.Point(111, 9);
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(154, 24);
this.lblTitle.TabIndex = 14;
this.lblTitle.Text = "Create Account";
//
// CreateAccountForm
//
this.AcceptButton = this.btnRegister;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(374, 291);
this.Controls.Add(this.lblTitle);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnRegister);
this.Controls.Add(this.btnViewTerms);
this.Controls.Add(this.chkAgreeTerms);
this.Controls.Add(this.txtConfirmPassword);
this.Controls.Add(this.lblConfirmPassword);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.dtpBirthdate);
this.Controls.Add(this.lblBirthdate);
this.Controls.Add(this.txtFullName);
this.Controls.Add(this.lblFullName);
this.Controls.Add(this.txtUsername);
this.Controls.Add(this.lblUsername);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CreateAccountForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Create Account - WorldSkills App";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblUsername;
private System.Windows.Forms.TextBox txtUsername;
private System.Windows.Forms.Label lblFullName;
private System.Windows.Forms.TextBox txtFullName;
private System.Windows.Forms.Label lblBirthdate;
private System.Windows.Forms.DateTimePicker dtpBirthdate;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label lblConfirmPassword;
private System.Windows.Forms.TextBox txtConfirmPassword;
private System.Windows.Forms.CheckBox chkAgreeTerms;
private System.Windows.Forms.Button btnViewTerms;
private System.Windows.Forms.Button btnRegister;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label lblTitle;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblUsername = new System.Windows.Forms.Label();
this.txtUsername = new System.Windows.Forms.TextBox();
this.lblFullName = new System.Windows.Forms.Label();
this.txtFullName = new System.Windows.Forms.TextBox();
this.lblBirthdate = new System.Windows.Forms.Label();
this.dtpBirthdate = new System.Windows.Forms.DateTimePicker();
this.lblPassword = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.lblConfirmPassword = new System.Windows.Forms.Label();
this.txtConfirmPassword = new System.Windows.Forms.TextBox();
this.chkAgreeTerms = new System.Windows.Forms.CheckBox();
this.btnViewTerms = new System.Windows.Forms.Button();
this.btnRegister = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.lblTitle = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblUsername
//
this.lblUsername.AutoSize = true;
this.lblUsername.Location = new System.Drawing.Point(30, 60);
this.lblUsername.Name = "lblUsername";
this.lblUsername.Size = new System.Drawing.Size(58, 13);
this.lblUsername.TabIndex = 0;
this.lblUsername.Text = "Username:";
//
// txtUsername
//
this.txtUsername.Location = new System.Drawing.Point(140, 57);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(200, 20);
this.txtUsername.TabIndex = 1;
//
// lblFullName
//
this.lblFullName.AutoSize = true;
this.lblFullName.Location = new System.Drawing.Point(30, 90);
this.lblFullName.Name = "lblFullName";
this.lblFullName.Size = new System.Drawing.Size(57, 13);
this.lblFullName.TabIndex = 2;
this.lblFullName.Text = "Full Name:";
//
// txtFullName
//
this.txtFullName.Location = new System.Drawing.Point(140, 87);
this.txtFullName.Name = "txtFullName";
this.txtFullName.Size = new System.Drawing.Size(200, 20);
this.txtFullName.TabIndex = 3;
//
// lblBirthdate
//
this.lblBirthdate.AutoSize = true;
this.lblBirthdate.Location = new System.Drawing.Point(30, 120);
this.lblBirthdate.Name = "lblBirthdate";
this.lblBirthdate.Size = new System.Drawing.Size(52, 13);
this.lblBirthdate.TabIndex = 4;
this.lblBirthdate.Text = "Birthdate:";
//
// dtpBirthdate
//
this.dtpBirthdate.Location = new System.Drawing.Point(140, 117);
this.dtpBirthdate.Name = "dtpBirthdate";
this.dtpBirthdate.Size = new System.Drawing.Size(200, 20);
this.dtpBirthdate.TabIndex = 5;
//
// lblPassword
//
this.lblPassword.AutoSize = true;
this.lblPassword.Location = new System.Drawing.Point(30, 150);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(56, 13);
this.lblPassword.TabIndex = 6;
this.lblPassword.Text = "Password:";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(140, 147);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(200, 20);
this.txtPassword.TabIndex = 7;
this.txtPassword.UseSystemPasswordChar = true;
//
// lblConfirmPassword
//
this.lblConfirmPassword.AutoSize = true;
this.lblConfirmPassword.Location = new System.Drawing.Point(30, 180);
this.lblConfirmPassword.Name = "lblConfirmPassword";
this.lblConfirmPassword.Size = new System.Drawing.Size(94, 13);
this.lblConfirmPassword.TabIndex = 8;
this.lblConfirmPassword.Text = "Confirm Password:";
//
// txtConfirmPassword
//
this.txtConfirmPassword.Location = new System.Drawing.Point(140, 177);
this.txtConfirmPassword.Name = "txtConfirmPassword";
this.txtConfirmPassword.Size = new System.Drawing.Size(200, 20);
this.txtConfirmPassword.TabIndex = 9;
this.txtConfirmPassword.UseSystemPasswordChar = true;
//
// chkAgreeTerms
//
this.chkAgreeTerms.AutoSize = true;
this.chkAgreeTerms.Enabled = false; // Disabled until terms are viewed
this.chkAgreeTerms.Location = new System.Drawing.Point(140, 213);
this.chkAgreeTerms.Name = "chkAgreeTerms";
this.chkAgreeTerms.Size = new System.Drawing.Size(165, 17);
this.chkAgreeTerms.TabIndex = 10;
this.chkAgreeTerms.Text = "I agree to Terms && Conditions";
this.chkAgreeTerms.UseVisualStyleBackColor = true;
//
// btnViewTerms
//
this.btnViewTerms.Location = new System.Drawing.Point(30, 210);
this.btnViewTerms.Name = "btnViewTerms";
this.btnViewTerms.Size = new System.Drawing.Size(94, 23);
this.btnViewTerms.TabIndex = 11;
this.btnViewTerms.Text = "View Terms";
this.btnViewTerms.UseVisualStyleBackColor = true;
this.btnViewTerms.Click += new System.EventHandler(this.btnViewTerms_Click);
//
// btnRegister
//
this.btnRegister.Location = new System.Drawing.Point(140, 249);
this.btnRegister.Name = "btnRegister";
this.btnRegister.Size = new System.Drawing.Size(100, 23);
this.btnRegister.TabIndex = 12;
this.btnRegister.Text = "Register && Login";
this.btnRegister.UseVisualStyleBackColor = true;
this.btnRegister.Click += new System.EventHandler(this.btnRegister_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(246, 249);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 13;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// lblTitle
//
this.lblTitle.AutoSize = true;
this.lblTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTitle.Location = new System.Drawing.Point(111, 9);
this.lblTitle.Name = "lblTitle";
this.lblTitle.Size = new System.Drawing.Size(154, 24);
this.lblTitle.TabIndex = 14;
this.lblTitle.Text = "Create Account";
//
// CreateAccountForm
//
this.AcceptButton = this.btnRegister;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(374, 291);
this.Controls.Add(this.lblTitle);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnRegister);
this.Controls.Add(this.btnViewTerms);
this.Controls.Add(this.chkAgreeTerms);
this.Controls.Add(this.txtConfirmPassword);
this.Controls.Add(this.lblConfirmPassword);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.dtpBirthdate);
this.Controls.Add(this.lblBirthdate);
this.Controls.Add(this.txtFullName);
this.Controls.Add(this.lblFullName);
this.Controls.Add(this.txtUsername);
this.Controls.Add(this.lblUsername);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CreateAccountForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Create Account - WorldSkills App";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblUsername;
private System.Windows.Forms.TextBox txtUsername;
private System.Windows.Forms.Label lblFullName;
private System.Windows.Forms.TextBox txtFullName;
private System.Windows.Forms.Label lblBirthdate;
private System.Windows.Forms.DateTimePicker dtpBirthdate;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label lblConfirmPassword;
private System.Windows.Forms.TextBox txtConfirmPassword;
private System.Windows.Forms.CheckBox chkAgreeTerms;
private System.Windows.Forms.Button btnViewTerms;
private System.Windows.Forms.Button btnRegister;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label lblTitle;
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/CreateAccountForm.cs"> using System; using System.IO; using System.Windows.Forms;
namespace WorldSkillsApp { public partial class CreateAccountForm : Form { private bool _termsViewed = false; private AuthenticationService _authService = new AuthenticationService(); // Use the same service
// Optional: Expose registered username if needed by calling form
// public string RegisteredUsername { get; private set; }
public CreateAccountForm()
{
InitializeComponent();
// Set default birthdate to avoid unrealistic future dates (optional)
dtpBirthdate.MaxDate = DateTime.Today;
dtpBirthdate.Value = DateTime.Today.AddYears(-18); // Example default
}
private void btnViewTerms_Click(object sender, EventArgs e)
{
try
{
// Assuming Terms.txt is in the application's startup directory
string termsFilePath = Path.Combine(Application.StartupPath, "Terms.txt");
if (File.Exists(termsFilePath))
{
// Show terms in a simple message box or a dedicated form
string termsContent = File.ReadAllText(termsFilePath);
MessageBox.Show(termsContent, "Terms and Conditions", MessageBoxButtons.OK, MessageBoxIcon.Information);
_termsViewed = true;
chkAgreeTerms.Enabled = true; // Enable checkbox only after viewing
}
else
{
MessageBox.Show("Terms.txt file not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error reading terms file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnRegister_Click(object sender, EventArgs e)
{
// --- Validation ---
if (string.IsNullOrWhiteSpace(txtUsername.Text) ||
string.IsNullOrWhiteSpace(txtFullName.Text) ||
string.IsNullOrWhiteSpace(txtPassword.Text) ||
string.IsNullOrWhiteSpace(txtConfirmPassword.Text))
{
MessageBox.Show("All fields except Birthdate must be filled.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (txtPassword.Text.Length < 5)
{
MessageBox.Show("Password must be at least 5 characters long.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtPassword.Focus();
return;
}
if (txtPassword.Text != txtConfirmPassword.Text)
{
MessageBox.Show("Passwords do not match.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtConfirmPassword.Focus();
return;
}
if (!_termsViewed)
{
MessageBox.Show("You must view the Terms and Conditions before registering.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
btnViewTerms.Focus();
return;
}
if (!chkAgreeTerms.Checked)
{
MessageBox.Show("You must agree to the Terms and Conditions to register.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
chkAgreeTerms.Focus();
return;
}
// --- Registration Logic ---
string username = txtUsername.Text.Trim();
string fullName = txtFullName.Text.Trim();
DateTime birthdate = dtpBirthdate.Value;
string password = txtPassword.Text;
bool registrationSuccess = _authService.RegisterUser(username, fullName, birthdate, password);
if (registrationSuccess)
{
MessageBox.Show("Registration successful! You will now be logged in.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
// RegisteredUsername = username; // Store if needed
// Automatically log the user in (optional, as per requirement "Register and Login")
// This assumes the main login form handles the transition to ManagementForm
this.DialogResult = DialogResult.OK; // Signal success to calling form
this.Close();
// --- Alternative: Directly open Management Form ---
// (Requires passing session service or handling login state here)
// UserSessionService sessionService = new UserSessionService();
// sessionService.RememberUser(username, false); // Remember the new user
// ManagementForm managementForm = new ManagementForm(username, false, _authService, sessionService);
// managementForm.FormClosed += (s, args) => Application.Exit(); // Or handle differently
// managementForm.Show();
// this.Hide(); // Hide this form
// --- End Alternative ---
}
else
{
MessageBox.Show(_authService.GetLastError(), "Registration Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Potential reasons: Username already exists, database error, etc.
txtUsername.Focus();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
// Optional: Expose registered username if needed by calling form
// public string RegisteredUsername { get; private set; }
public CreateAccountForm()
{
InitializeComponent();
// Set default birthdate to avoid unrealistic future dates (optional)
dtpBirthdate.MaxDate = DateTime.Today;
dtpBirthdate.Value = DateTime.Today.AddYears(-18); // Example default
}
private void btnViewTerms_Click(object sender, EventArgs e)
{
try
{
// Assuming Terms.txt is in the application's startup directory
string termsFilePath = Path.Combine(Application.StartupPath, "Terms.txt");
if (File.Exists(termsFilePath))
{
// Show terms in a simple message box or a dedicated form
string termsContent = File.ReadAllText(termsFilePath);
MessageBox.Show(termsContent, "Terms and Conditions", MessageBoxButtons.OK, MessageBoxIcon.Information);
_termsViewed = true;
chkAgreeTerms.Enabled = true; // Enable checkbox only after viewing
}
else
{
MessageBox.Show("Terms.txt file not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error reading terms file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnRegister_Click(object sender, EventArgs e)
{
// --- Validation ---
if (string.IsNullOrWhiteSpace(txtUsername.Text) ||
string.IsNullOrWhiteSpace(txtFullName.Text) ||
string.IsNullOrWhiteSpace(txtPassword.Text) ||
string.IsNullOrWhiteSpace(txtConfirmPassword.Text))
{
MessageBox.Show("All fields except Birthdate must be filled.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (txtPassword.Text.Length < 5)
{
MessageBox.Show("Password must be at least 5 characters long.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtPassword.Focus();
return;
}
if (txtPassword.Text != txtConfirmPassword.Text)
{
MessageBox.Show("Passwords do not match.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtConfirmPassword.Focus();
return;
}
if (!_termsViewed)
{
MessageBox.Show("You must view the Terms and Conditions before registering.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
btnViewTerms.Focus();
return;
}
if (!chkAgreeTerms.Checked)
{
MessageBox.Show("You must agree to the Terms and Conditions to register.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
chkAgreeTerms.Focus();
return;
}
// --- Registration Logic ---
string username = txtUsername.Text.Trim();
string fullName = txtFullName.Text.Trim();
DateTime birthdate = dtpBirthdate.Value;
string password = txtPassword.Text;
bool registrationSuccess = _authService.RegisterUser(username, fullName, birthdate, password);
if (registrationSuccess)
{
MessageBox.Show("Registration successful! You will now be logged in.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
// RegisteredUsername = username; // Store if needed
// Automatically log the user in (optional, as per requirement "Register and Login")
// This assumes the main login form handles the transition to ManagementForm
this.DialogResult = DialogResult.OK; // Signal success to calling form
this.Close();
// --- Alternative: Directly open Management Form ---
// (Requires passing session service or handling login state here)
// UserSessionService sessionService = new UserSessionService();
// sessionService.RememberUser(username, false); // Remember the new user
// ManagementForm managementForm = new ManagementForm(username, false, _authService, sessionService);
// managementForm.FormClosed += (s, args) => Application.Exit(); // Or handle differently
// managementForm.Show();
// this.Hide(); // Hide this form
// --- End Alternative ---
}
else
{
MessageBox.Show(_authService.GetLastError(), "Registration Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
// Potential reasons: Username already exists, database error, etc.
txtUsername.Focus();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/ManagementForm.Designer.cs"> namespace WorldSkillsApp { partial class ManagementForm { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tabControlMain = new System.Windows.Forms.TabControl();
this.tabPageTraveler = new System.Windows.Forms.TabPage();
this.lblTravelerItemCount = new System.Windows.Forms.Label();
this.dgvTravelerListings = new System.Windows.Forms.DataGridView();
this.colTravelerTitle = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colTravelerCapacity = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colTravelerArea = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colTravelerType = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.txtTravelerSearch = new System.Windows.Forms.TextBox();
this.lblTravelerSearch = new System.Windows.Forms.Label();
this.tabPageOwnerManager = new System.Windows.Forms.TabPage();
this.btnEditListing = new System.Windows.Forms.Button();
this.lblOwnerItemCount = new System.Windows.Forms.Label();
this.dgvOwnerListings = new System.Windows.Forms.DataGridView();
this.colOwnerTitle = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colOwnerCapacity = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colOwnerArea = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colOwnerType = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.btnAddListing = new System.Windows.Forms.Button();
this.btnLogout = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.tabControlMain.SuspendLayout();
this.tabPageTraveler.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvTravelerListings)).BeginInit();
this.tabPageOwnerManager.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvOwnerListings)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// tabControlMain
//
this.tabControlMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabControlMain.Controls.Add(this.tabPageTraveler);
this.tabControlMain.Controls.Add(this.tabPageOwnerManager);
this.tabControlMain.Location = new System.Drawing.Point(12, 41);
this.tabControlMain.Name = "tabControlMain";
this.tabControlMain.SelectedIndex = 0;
this.tabControlMain.Size = new System.Drawing.Size(760, 484);
this.tabControlMain.TabIndex = 0;
this.tabControlMain.SelectedIndexChanged += new System.EventHandler(this.tabControlMain_SelectedIndexChanged);
//
// tabPageTraveler
//
this.tabPageTraveler.Controls.Add(this.lblTravelerItemCount);
this.tabPageTraveler.Controls.Add(this.dgvTravelerListings);
this.tabPageTraveler.Controls.Add(this.txtTravelerSearch);
this.tabPageTraveler.Controls.Add(this.lblTravelerSearch);
this.tabPageTraveler.Location = new System.Drawing.Point(4, 22);
this.tabPageTraveler.Name = "tabPageTraveler";
this.tabPageTraveler.Padding = new System.Windows.Forms.Padding(3);
this.tabPageTraveler.Size = new System.Drawing.Size(752, 458);
this.tabPageTraveler.TabIndex = 0;
this.tabPageTraveler.Text = "Traveler";
this.tabPageTraveler.UseVisualStyleBackColor = true;
//
// lblTravelerItemCount
//
this.lblTravelerItemCount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblTravelerItemCount.AutoSize = true;
this.lblTravelerItemCount.Location = new System.Drawing.Point(6, 438);
this.lblTravelerItemCount.Name = "lblTravelerItemCount";
this.lblTravelerItemCount.Size = new System.Drawing.Size(67, 13);
this.lblTravelerItemCount.TabIndex = 3;
this.lblTravelerItemCount.Text = "Items found: ";
//
// dgvTravelerListings
//
this.dgvTravelerListings.AllowUserToAddRows = false;
this.dgvTravelerListings.AllowUserToDeleteRows = false;
this.dgvTravelerListings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgvTravelerListings.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvTravelerListings.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.colTravelerTitle,
this.colTravelerCapacity,
this.colTravelerArea,
this.colTravelerType});
this.dgvTravelerListings.Location = new System.Drawing.Point(6, 32);
this.dgvTravelerListings.MultiSelect = false;
this.dgvTravelerListings.Name = "dgvTravelerListings";
this.dgvTravelerListings.ReadOnly = true;
this.dgvTravelerListings.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvTravelerListings.Size = new System.Drawing.Size(740, 403);
this.dgvTravelerListings.TabIndex = 2;
this.dgvTravelerListings.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_ColumnHeaderMouseClick);
//
// colTravelerTitle
//
this.colTravelerTitle.DataPropertyName = "Title"; // Link to data source property
this.colTravelerTitle.HeaderText = "Title";
this.colTravelerTitle.Name = "colTravelerTitle";
this.colTravelerTitle.ReadOnly = true;
this.colTravelerTitle.Width = 250;
//
// colTravelerCapacity
//
this.colTravelerCapacity.DataPropertyName = "Capacity"; // Link to data source property
this.colTravelerCapacity.HeaderText = "Capacity";
this.colTravelerCapacity.Name = "colTravelerCapacity";
this.colTravelerCapacity.ReadOnly = true;
//
// colTravelerArea
//
this.colTravelerArea.DataPropertyName = "Area"; // Link to data source property
this.colTravelerArea.HeaderText = "Area";
this.colTravelerArea.Name = "colTravelerArea";
this.colTravelerArea.ReadOnly = true;
this.colTravelerArea.Width = 150;
//
// colTravelerType
//
this.colTravelerType.DataPropertyName = "Type"; // Link to data source property
this.colTravelerType.HeaderText = "Type";
this.colTravelerType.Name = "colTravelerType";
this.colTravelerType.ReadOnly = true;
this.colTravelerType.Width = 150;
//
// txtTravelerSearch
//
this.txtTravelerSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtTravelerSearch.Location = new System.Drawing.Point(188, 6);
this.txtTravelerSearch.Name = "txtTravelerSearch";
this.txtTravelerSearch.Size = new System.Drawing.Size(558, 20);
this.txtTravelerSearch.TabIndex = 1;
this.txtTravelerSearch.TextChanged += new System.EventHandler(this.txtTravelerSearch_TextChanged);
//
// lblTravelerSearch
//
this.lblTravelerSearch.AutoSize = true;
this.lblTravelerSearch.Location = new System.Drawing.Point(6, 9);
this.lblTravelerSearch.Name = "lblTravelerSearch";
this.lblTravelerSearch.Size = new System.Drawing.Size(176, 13);
this.lblTravelerSearch.TabIndex = 0;
this.lblTravelerSearch.Text = "Search (Title, Area, Attraction Near):";
//
// tabPageOwnerManager
//
this.tabPageOwnerManager.Controls.Add(this.btnEditListing);
this.tabPageOwnerManager.Controls.Add(this.lblOwnerItemCount);
this.tabPageOwnerManager.Controls.Add(this.dgvOwnerListings);
this.tabPageOwnerManager.Controls.Add(this.btnAddListing);
this.tabPageOwnerManager.Location = new System.Drawing.Point(4, 22);
this.tabPageOwnerManager.Name = "tabPageOwnerManager";
this.tabPageOwnerManager.Padding = new System.Windows.Forms.Padding(3);
this.tabPageOwnerManager.Size = new System.Drawing.Size(752, 458);
this.tabPageOwnerManager.TabIndex = 1;
this.tabPageOwnerManager.Text = "Owner / Manager";
this.tabPageOwnerManager.UseVisualStyleBackColor = true;
//
// btnEditListing
//
this.btnEditListing.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnEditListing.Location = new System.Drawing.Point(658, 6);
this.btnEditListing.Name = "btnEditListing";
this.btnEditListing.Size = new System.Drawing.Size(88, 23);
this.btnEditListing.TabIndex = 3;
this.btnEditListing.Text = "Edit Details";
this.btnEditListing.UseVisualStyleBackColor = true;
this.btnEditListing.Click += new System.EventHandler(this.btnEditListing_Click);
//
// lblOwnerItemCount
//
this.lblOwnerItemCount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblOwnerItemCount.AutoSize = true;
this.lblOwnerItemCount.Location = new System.Drawing.Point(6, 438);
this.lblOwnerItemCount.Name = "lblOwnerItemCount";
this.lblOwnerItemCount.Size = new System.Drawing.Size(73, 13);
this.lblOwnerItemCount.TabIndex = 2;
this.lblOwnerItemCount.Text = "Your Listings: ";
//
// dgvOwnerListings
//
this.dgvOwnerListings.AllowUserToAddRows = false;
this.dgvOwnerListings.AllowUserToDeleteRows = false;
this.dgvOwnerListings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgvOwnerListings.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvOwnerListings.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.colOwnerTitle,
this.colOwnerCapacity,
this.colOwnerArea,
this.colOwnerType});
this.dgvOwnerListings.Location = new System.Drawing.Point(6, 35);
this.dgvOwnerListings.MultiSelect = false;
this.dgvOwnerListings.Name = "dgvOwnerListings";
this.dgvOwnerListings.ReadOnly = true;
this.dgvOwnerListings.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvOwnerListings.Size = new System.Drawing.Size(740, 400);
this.dgvOwnerListings.TabIndex = 1;
this.dgvOwnerListings.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_ColumnHeaderMouseClick);
//
// colOwnerTitle
//
this.colOwnerTitle.DataPropertyName = "Title"; // Link to data source property
this.colOwnerTitle.HeaderText = "Title";
this.colOwnerTitle.Name = "colOwnerTitle";
this.colOwnerTitle.ReadOnly = true;
this.colOwnerTitle.Width = 250;
//
// colOwnerCapacity
//
this.colOwnerCapacity.DataPropertyName = "Capacity"; // Link to data source property
this.colOwnerCapacity.HeaderText = "Capacity";
this.colOwnerCapacity.Name = "colOwnerCapacity";
this.colOwnerCapacity.ReadOnly = true;
//
// colOwnerArea
//
this.colOwnerArea.DataPropertyName = "Area"; // Link to data source property
this.colOwnerArea.HeaderText = "Area";
this.colOwnerArea.Name = "colOwnerArea";
this.colOwnerArea.ReadOnly = true;
this.colOwnerArea.Width = 150;
//
// colOwnerType
//
this.colOwnerType.DataPropertyName = "Type"; // Link to data source property
this.colOwnerType.HeaderText = "Type";
this.colOwnerType.Name = "colOwnerType";
this.colOwnerType.ReadOnly = true;
this.colOwnerType.Width = 150;
//
// btnAddListing
//
this.btnAddListing.Location = new System.Drawing.Point(6, 6);
this.btnAddListing.Name = "btnAddListing";
this.btnAddListing.Size = new System.Drawing.Size(88, 23);
this.btnAddListing.TabIndex = 0;
this.btnAddListing.Text = "Add Listing";
this.btnAddListing.UseVisualStyleBackColor = true;
this.btnAddListing.Click += new System.EventHandler(this.btnAddListing_Click);
//
// btnLogout
//
this.btnLogout.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnLogout.Location = new System.Drawing.Point(616, 12);
this.btnLogout.Name = "btnLogout";
this.btnLogout.Size = new System.Drawing.Size(75, 23);
this.btnLogout.TabIndex = 1;
this.btnLogout.Text = "Logout";
this.btnLogout.UseVisualStyleBackColor = true;
this.btnLogout.Click += new System.EventHandler(this.btnLogout_Click);
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.Location = new System.Drawing.Point(697, 12);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 2;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel});
this.statusStrip1.Location = new System.Drawing.Point(0, 528);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(784, 22);
this.statusStrip1.TabIndex = 3;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel
//
this.toolStripStatusLabel.Name = "toolStripStatusLabel";
this.toolStripStatusLabel.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabel.Text = "Ready";
//
// ManagementForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(784, 550);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnLogout);
this.Controls.Add(this.tabControlMain);
this.MinimumSize = new System.Drawing.Size(600, 400);
this.Name = "ManagementForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Management - WorldSkills App";
this.Load += new System.EventHandler(this.ManagementForm_Load);
this.tabControlMain.ResumeLayout(false);
this.tabPageTraveler.ResumeLayout(false);
this.tabPageTraveler.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvTravelerListings)).EndInit();
this.tabPageOwnerManager.ResumeLayout(false);
this.tabPageOwnerManager.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvOwnerListings)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TabControl tabControlMain;
private System.Windows.Forms.TabPage tabPageTraveler;
private System.Windows.Forms.TabPage tabPageOwnerManager;
private System.Windows.Forms.Button btnLogout;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel;
private System.Windows.Forms.TextBox txtTravelerSearch;
private System.Windows.Forms.Label lblTravelerSearch;
private System.Windows.Forms.DataGridView dgvTravelerListings;
private System.Windows.Forms.Button btnAddListing;
private System.Windows.Forms.DataGridView dgvOwnerListings;
private System.Windows.Forms.Label lblTravelerItemCount;
private System.Windows.Forms.Label lblOwnerItemCount;
private System.Windows.Forms.Button btnEditListing;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerTitle;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerCapacity;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerArea;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerType;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerTitle;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerCapacity;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerArea;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerType;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tabControlMain = new System.Windows.Forms.TabControl();
this.tabPageTraveler = new System.Windows.Forms.TabPage();
this.lblTravelerItemCount = new System.Windows.Forms.Label();
this.dgvTravelerListings = new System.Windows.Forms.DataGridView();
this.colTravelerTitle = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colTravelerCapacity = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colTravelerArea = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colTravelerType = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.txtTravelerSearch = new System.Windows.Forms.TextBox();
this.lblTravelerSearch = new System.Windows.Forms.Label();
this.tabPageOwnerManager = new System.Windows.Forms.TabPage();
this.btnEditListing = new System.Windows.Forms.Button();
this.lblOwnerItemCount = new System.Windows.Forms.Label();
this.dgvOwnerListings = new System.Windows.Forms.DataGridView();
this.colOwnerTitle = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colOwnerCapacity = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colOwnerArea = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colOwnerType = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.btnAddListing = new System.Windows.Forms.Button();
this.btnLogout = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.tabControlMain.SuspendLayout();
this.tabPageTraveler.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvTravelerListings)).BeginInit();
this.tabPageOwnerManager.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvOwnerListings)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// tabControlMain
//
this.tabControlMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tabControlMain.Controls.Add(this.tabPageTraveler);
this.tabControlMain.Controls.Add(this.tabPageOwnerManager);
this.tabControlMain.Location = new System.Drawing.Point(12, 41);
this.tabControlMain.Name = "tabControlMain";
this.tabControlMain.SelectedIndex = 0;
this.tabControlMain.Size = new System.Drawing.Size(760, 484);
this.tabControlMain.TabIndex = 0;
this.tabControlMain.SelectedIndexChanged += new System.EventHandler(this.tabControlMain_SelectedIndexChanged);
//
// tabPageTraveler
//
this.tabPageTraveler.Controls.Add(this.lblTravelerItemCount);
this.tabPageTraveler.Controls.Add(this.dgvTravelerListings);
this.tabPageTraveler.Controls.Add(this.txtTravelerSearch);
this.tabPageTraveler.Controls.Add(this.lblTravelerSearch);
this.tabPageTraveler.Location = new System.Drawing.Point(4, 22);
this.tabPageTraveler.Name = "tabPageTraveler";
this.tabPageTraveler.Padding = new System.Windows.Forms.Padding(3);
this.tabPageTraveler.Size = new System.Drawing.Size(752, 458);
this.tabPageTraveler.TabIndex = 0;
this.tabPageTraveler.Text = "Traveler";
this.tabPageTraveler.UseVisualStyleBackColor = true;
//
// lblTravelerItemCount
//
this.lblTravelerItemCount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblTravelerItemCount.AutoSize = true;
this.lblTravelerItemCount.Location = new System.Drawing.Point(6, 438);
this.lblTravelerItemCount.Name = "lblTravelerItemCount";
this.lblTravelerItemCount.Size = new System.Drawing.Size(67, 13);
this.lblTravelerItemCount.TabIndex = 3;
this.lblTravelerItemCount.Text = "Items found: ";
//
// dgvTravelerListings
//
this.dgvTravelerListings.AllowUserToAddRows = false;
this.dgvTravelerListings.AllowUserToDeleteRows = false;
this.dgvTravelerListings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgvTravelerListings.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvTravelerListings.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.colTravelerTitle,
this.colTravelerCapacity,
this.colTravelerArea,
this.colTravelerType});
this.dgvTravelerListings.Location = new System.Drawing.Point(6, 32);
this.dgvTravelerListings.MultiSelect = false;
this.dgvTravelerListings.Name = "dgvTravelerListings";
this.dgvTravelerListings.ReadOnly = true;
this.dgvTravelerListings.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvTravelerListings.Size = new System.Drawing.Size(740, 403);
this.dgvTravelerListings.TabIndex = 2;
this.dgvTravelerListings.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_ColumnHeaderMouseClick);
//
// colTravelerTitle
//
this.colTravelerTitle.DataPropertyName = "Title"; // Link to data source property
this.colTravelerTitle.HeaderText = "Title";
this.colTravelerTitle.Name = "colTravelerTitle";
this.colTravelerTitle.ReadOnly = true;
this.colTravelerTitle.Width = 250;
//
// colTravelerCapacity
//
this.colTravelerCapacity.DataPropertyName = "Capacity"; // Link to data source property
this.colTravelerCapacity.HeaderText = "Capacity";
this.colTravelerCapacity.Name = "colTravelerCapacity";
this.colTravelerCapacity.ReadOnly = true;
//
// colTravelerArea
//
this.colTravelerArea.DataPropertyName = "Area"; // Link to data source property
this.colTravelerArea.HeaderText = "Area";
this.colTravelerArea.Name = "colTravelerArea";
this.colTravelerArea.ReadOnly = true;
this.colTravelerArea.Width = 150;
//
// colTravelerType
//
this.colTravelerType.DataPropertyName = "Type"; // Link to data source property
this.colTravelerType.HeaderText = "Type";
this.colTravelerType.Name = "colTravelerType";
this.colTravelerType.ReadOnly = true;
this.colTravelerType.Width = 150;
//
// txtTravelerSearch
//
this.txtTravelerSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtTravelerSearch.Location = new System.Drawing.Point(188, 6);
this.txtTravelerSearch.Name = "txtTravelerSearch";
this.txtTravelerSearch.Size = new System.Drawing.Size(558, 20);
this.txtTravelerSearch.TabIndex = 1;
this.txtTravelerSearch.TextChanged += new System.EventHandler(this.txtTravelerSearch_TextChanged);
//
// lblTravelerSearch
//
this.lblTravelerSearch.AutoSize = true;
this.lblTravelerSearch.Location = new System.Drawing.Point(6, 9);
this.lblTravelerSearch.Name = "lblTravelerSearch";
this.lblTravelerSearch.Size = new System.Drawing.Size(176, 13);
this.lblTravelerSearch.TabIndex = 0;
this.lblTravelerSearch.Text = "Search (Title, Area, Attraction Near):";
//
// tabPageOwnerManager
//
this.tabPageOwnerManager.Controls.Add(this.btnEditListing);
this.tabPageOwnerManager.Controls.Add(this.lblOwnerItemCount);
this.tabPageOwnerManager.Controls.Add(this.dgvOwnerListings);
this.tabPageOwnerManager.Controls.Add(this.btnAddListing);
this.tabPageOwnerManager.Location = new System.Drawing.Point(4, 22);
this.tabPageOwnerManager.Name = "tabPageOwnerManager";
this.tabPageOwnerManager.Padding = new System.Windows.Forms.Padding(3);
this.tabPageOwnerManager.Size = new System.Drawing.Size(752, 458);
this.tabPageOwnerManager.TabIndex = 1;
this.tabPageOwnerManager.Text = "Owner / Manager";
this.tabPageOwnerManager.UseVisualStyleBackColor = true;
//
// btnEditListing
//
this.btnEditListing.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnEditListing.Location = new System.Drawing.Point(658, 6);
this.btnEditListing.Name = "btnEditListing";
this.btnEditListing.Size = new System.Drawing.Size(88, 23);
this.btnEditListing.TabIndex = 3;
this.btnEditListing.Text = "Edit Details";
this.btnEditListing.UseVisualStyleBackColor = true;
this.btnEditListing.Click += new System.EventHandler(this.btnEditListing_Click);
//
// lblOwnerItemCount
//
this.lblOwnerItemCount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblOwnerItemCount.AutoSize = true;
this.lblOwnerItemCount.Location = new System.Drawing.Point(6, 438);
this.lblOwnerItemCount.Name = "lblOwnerItemCount";
this.lblOwnerItemCount.Size = new System.Drawing.Size(73, 13);
this.lblOwnerItemCount.TabIndex = 2;
this.lblOwnerItemCount.Text = "Your Listings: ";
//
// dgvOwnerListings
//
this.dgvOwnerListings.AllowUserToAddRows = false;
this.dgvOwnerListings.AllowUserToDeleteRows = false;
this.dgvOwnerListings.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgvOwnerListings.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvOwnerListings.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.colOwnerTitle,
this.colOwnerCapacity,
this.colOwnerArea,
this.colOwnerType});
this.dgvOwnerListings.Location = new System.Drawing.Point(6, 35);
this.dgvOwnerListings.MultiSelect = false;
this.dgvOwnerListings.Name = "dgvOwnerListings";
this.dgvOwnerListings.ReadOnly = true;
this.dgvOwnerListings.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvOwnerListings.Size = new System.Drawing.Size(740, 400);
this.dgvOwnerListings.TabIndex = 1;
this.dgvOwnerListings.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_ColumnHeaderMouseClick);
//
// colOwnerTitle
//
this.colOwnerTitle.DataPropertyName = "Title"; // Link to data source property
this.colOwnerTitle.HeaderText = "Title";
this.colOwnerTitle.Name = "colOwnerTitle";
this.colOwnerTitle.ReadOnly = true;
this.colOwnerTitle.Width = 250;
//
// colOwnerCapacity
//
this.colOwnerCapacity.DataPropertyName = "Capacity"; // Link to data source property
this.colOwnerCapacity.HeaderText = "Capacity";
this.colOwnerCapacity.Name = "colOwnerCapacity";
this.colOwnerCapacity.ReadOnly = true;
//
// colOwnerArea
//
this.colOwnerArea.DataPropertyName = "Area"; // Link to data source property
this.colOwnerArea.HeaderText = "Area";
this.colOwnerArea.Name = "colOwnerArea";
this.colOwnerArea.ReadOnly = true;
this.colOwnerArea.Width = 150;
//
// colOwnerType
//
this.colOwnerType.DataPropertyName = "Type"; // Link to data source property
this.colOwnerType.HeaderText = "Type";
this.colOwnerType.Name = "colOwnerType";
this.colOwnerType.ReadOnly = true;
this.colOwnerType.Width = 150;
//
// btnAddListing
//
this.btnAddListing.Location = new System.Drawing.Point(6, 6);
this.btnAddListing.Name = "btnAddListing";
this.btnAddListing.Size = new System.Drawing.Size(88, 23);
this.btnAddListing.TabIndex = 0;
this.btnAddListing.Text = "Add Listing";
this.btnAddListing.UseVisualStyleBackColor = true;
this.btnAddListing.Click += new System.EventHandler(this.btnAddListing_Click);
//
// btnLogout
//
this.btnLogout.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnLogout.Location = new System.Drawing.Point(616, 12);
this.btnLogout.Name = "btnLogout";
this.btnLogout.Size = new System.Drawing.Size(75, 23);
this.btnLogout.TabIndex = 1;
this.btnLogout.Text = "Logout";
this.btnLogout.UseVisualStyleBackColor = true;
this.btnLogout.Click += new System.EventHandler(this.btnLogout_Click);
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.Location = new System.Drawing.Point(697, 12);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 2;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel});
this.statusStrip1.Location = new System.Drawing.Point(0, 528);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(784, 22);
this.statusStrip1.TabIndex = 3;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel
//
this.toolStripStatusLabel.Name = "toolStripStatusLabel";
this.toolStripStatusLabel.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabel.Text = "Ready";
//
// ManagementForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(784, 550);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnLogout);
this.Controls.Add(this.tabControlMain);
this.MinimumSize = new System.Drawing.Size(600, 400);
this.Name = "ManagementForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Management - WorldSkills App";
this.Load += new System.EventHandler(this.ManagementForm_Load);
this.tabControlMain.ResumeLayout(false);
this.tabPageTraveler.ResumeLayout(false);
this.tabPageTraveler.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvTravelerListings)).EndInit();
this.tabPageOwnerManager.ResumeLayout(false);
this.tabPageOwnerManager.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvOwnerListings)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TabControl tabControlMain;
private System.Windows.Forms.TabPage tabPageTraveler;
private System.Windows.Forms.TabPage tabPageOwnerManager;
private System.Windows.Forms.Button btnLogout;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel;
private System.Windows.Forms.TextBox txtTravelerSearch;
private System.Windows.Forms.Label lblTravelerSearch;
private System.Windows.Forms.DataGridView dgvTravelerListings;
private System.Windows.Forms.Button btnAddListing;
private System.Windows.Forms.DataGridView dgvOwnerListings;
private System.Windows.Forms.Label lblTravelerItemCount;
private System.Windows.Forms.Label lblOwnerItemCount;
private System.Windows.Forms.Button btnEditListing;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerTitle;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerCapacity;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerArea;
private System.Windows.Forms.DataGridViewTextBoxColumn colTravelerType;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerTitle;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerCapacity;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerArea;
private System.Windows.Forms.DataGridViewTextBoxColumn colOwnerType;
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/ManagementForm.cs"> using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms;
namespace WorldSkillsApp { public partial class ManagementForm : Form { private readonly string _loggedInUsername; private readonly bool _loggedInAsEmployee; private readonly AuthenticationService _authService; // For potential future use private readonly UserSessionService _sessionService; // For logout private readonly ListingService _listingService = new ListingService(); // Service for managing listings
private BindingList<ListingViewModel> _allListings; // All available listings for traveler search
private BindingList<ListingViewModel> _ownerListings; // Listings owned by the current user
private SortableBindingList<ListingViewModel> _filteredTravelerListings; // Filtered view for traveler grid
private SortableBindingList<ListingViewModel> _sortedOwnerListings; // Sortable view for owner grid
public bool LogoutInitiated { get; private set; } = false;
public ManagementForm(string username, bool asEmployee, AuthenticationService authService, UserSessionService sessionService)
{
InitializeComponent();
_loggedInUsername = username;
_loggedInAsEmployee = asEmployee;
_authService = authService;
_sessionService = sessionService;
this.Text = $"Management - User: {_loggedInUsername}" + (asEmployee ? " (via Employee)" : "");
// Configure DataGridViews
ConfigureDataGridView(dgvTravelerListings);
ConfigureDataGridView(dgvOwnerListings);
}
private void ConfigureDataGridView(DataGridView dgv)
{
dgv.AutoGenerateColumns = false; // We define columns manually
dgv.AllowUserToAddRows = false;
dgv.AllowUserToDeleteRows = false;
dgv.ReadOnly = true;
dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgv.MultiSelect = false;
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; // Adjust column widths
dgv.AllowUserToOrderColumns = true; // Optional
dgv.AllowUserToResizeRows = false; // Optional
dgv.RowHeadersVisible = false; // Optional
}
private void ManagementForm_Load(object sender, EventArgs e)
{
LoadAllListings(); // Load data for traveler tab
LoadOwnerListings(); // Load data for owner tab
// Set initial status bar text based on the default tab (Traveler)
UpdateStatusBar(tabControlMain.SelectedTab);
}
private void LoadAllListings()
{
// In a real app, fetch from database via _listingService
_allListings = _listingService.GetAllListings();
_filteredTravelerListings = new SortableBindingList<ListingViewModel>(_allListings); // Initially show all
dgvTravelerListings.DataSource = _filteredTravelerListings;
UpdateTravelerItemCount();
}
private void LoadOwnerListings()
{
// In a real app, fetch listings for _loggedInUsername via _listingService
_ownerListings = _listingService.GetListingsByOwner(_loggedInUsername);
_sortedOwnerListings = new SortableBindingList<ListingViewModel>(_ownerListings);
dgvOwnerListings.DataSource = _sortedOwnerListings;
UpdateOwnerItemCount();
}
private void btnLogout_Click(object sender, EventArgs e)
{
LogoutInitiated = true;
_sessionService.ForgetUser(); // Clear "remember me" on explicit logout
this.Close(); // Close this form, LoginForm will handle showing itself again
}
private void btnExit_Click(object sender, EventArgs e)
{
LogoutInitiated = false; // Not a logout, just closing the app
Application.Exit();
}
private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
{
// Update status bar when tab changes
UpdateStatusBar(tabControlMain.SelectedTab);
}
private void UpdateStatusBar(TabPage selectedTab)
{
if (selectedTab == tabPageTraveler)
{
UpdateTravelerItemCount(); // Updates status bar via count method
}
else if (selectedTab == tabPageOwnerManager)
{
UpdateOwnerItemCount(); // Updates status bar via count method
}
else
{
toolStripStatusLabel.Text = "Ready";
}
}
private void UpdateTravelerItemCount()
{
int count = _filteredTravelerListings?.Count ?? 0;
lblTravelerItemCount.Text = $"Items found: {count}";
if (tabControlMain.SelectedTab == tabPageTraveler) // Only update status bar if tab is active
{
toolStripStatusLabel.Text = $"{count} listings found.";
}
}
private void UpdateOwnerItemCount()
{
int count = _sortedOwnerListings?.Count ?? 0;
lblOwnerItemCount.Text = $"Your Listings: {count}";
if (tabControlMain.SelectedTab == tabPageOwnerManager) // Only update status bar if tab is active
{
toolStripStatusLabel.Text = $"You have {count
private BindingList<ListingViewModel> _allListings; // All available listings for traveler search
private BindingList<ListingViewModel> _ownerListings; // Listings owned by the current user
private SortableBindingList<ListingViewModel> _filteredTravelerListings; // Filtered view for traveler grid
private SortableBindingList<ListingViewModel> _sortedOwnerListings; // Sortable view for owner grid
public bool LogoutInitiated { get; private set; } = false;
public ManagementForm(string username, bool asEmployee, AuthenticationService authService, UserSessionService sessionService)
{
InitializeComponent();
_loggedInUsername = username;
_loggedInAsEmployee = asEmployee;
_authService = authService;
_sessionService = sessionService;
this.Text = $"Management - User: {_loggedInUsername}" + (asEmployee ? " (via Employee)" : "");
// Configure DataGridViews
ConfigureDataGridView(dgvTravelerListings);
ConfigureDataGridView(dgvOwnerListings);
}
private void ConfigureDataGridView(DataGridView dgv)
{
dgv.AutoGenerateColumns = false; // We define columns manually
dgv.AllowUserToAddRows = false;
dgv.AllowUserToDeleteRows = false;
dgv.ReadOnly = true;
dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgv.MultiSelect = false;
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; // Adjust column widths
dgv.AllowUserToOrderColumns = true; // Optional
dgv.AllowUserToResizeRows = false; // Optional
dgv.RowHeadersVisible = false; // Optional
}
private void ManagementForm_Load(object sender, EventArgs e)
{
LoadAllListings(); // Load data for traveler tab
LoadOwnerListings(); // Load data for owner tab
// Set initial status bar text based on the default tab (Traveler)
UpdateStatusBar(tabControlMain.SelectedTab);
}
private void LoadAllListings()
{
// In a real app, fetch from database via _listingService
_allListings = _listingService.GetAllListings();
_filteredTravelerListings = new SortableBindingList<ListingViewModel>(_allListings); // Initially show all
dgvTravelerListings.DataSource = _filteredTravelerListings;
UpdateTravelerItemCount();
}
private void LoadOwnerListings()
{
// In a real app, fetch listings for _loggedInUsername via _listingService
_ownerListings = _listingService.GetListingsByOwner(_loggedInUsername);
_sortedOwnerListings = new SortableBindingList<ListingViewModel>(_ownerListings);
dgvOwnerListings.DataSource = _sortedOwnerListings;
UpdateOwnerItemCount();
}
private void btnLogout_Click(object sender, EventArgs e)
{
LogoutInitiated = true;
_sessionService.ForgetUser(); // Clear "remember me" on explicit logout
this.Close(); // Close this form, LoginForm will handle showing itself again
}
private void btnExit_Click(object sender, EventArgs e)
{
LogoutInitiated = false; // Not a logout, just closing the app
Application.Exit();
}
private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
{
// Update status bar when tab changes
UpdateStatusBar(tabControlMain.SelectedTab);
}
private void UpdateStatusBar(TabPage selectedTab)
{
if (selectedTab == tabPageTraveler)
{
UpdateTravelerItemCount(); // Updates status bar via count method
}
else if (selectedTab == tabPageOwnerManager)
{
UpdateOwnerItemCount(); // Updates status bar via count method
}
else
{
toolStripStatusLabel.Text = "Ready";
}
}
private void UpdateTravelerItemCount()
{
int count = _filteredTravelerListings?.Count ?? 0;
lblTravelerItemCount.Text = $"Items found: {count}";
if (tabControlMain.SelectedTab == tabPageTraveler) // Only update status bar if tab is active
{
toolStripStatusLabel.Text = $"{count} listings found.";
}
}
private void UpdateOwnerItemCount()
{
int count = _sortedOwnerListings?.Count ?? 0;
lblOwnerItemCount.Text = $"Your Listings: {count}";
if (tabControlMain.SelectedTab == tabPageOwnerManager) // Only update status bar if tab is active
{
toolStripStatusLabel.Text = $"You have {count
Okay, you are right. The previous response was incomplete. Let's finish the ManagementForm.cs implementation and then add the remaining required forms and services.
Here is the complete ManagementForm.cs and the subsequent files needed to fulfill the requirements.
namespace WorldSkillsApp { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Ensure we always start with the Login Form Application.Run(new LoginForm()); } } } </jitFile> <jitFile type="file" filePath="WorldSkillsApp/Models/User.cs"> using System;
namespace WorldSkillsApp.Models { // Simple User model for demonstration public class User { public int Id { get; set; } public string Username { get; set; } public string FullName { get; set; } public DateTime Birthdate { get; set; } public string PasswordHash { get; set; } // Store hashes, not plain text! public bool IsEmployee { get; set; } // Distinguish user types if needed
// Add other relevant properties
}
// Simple class to hold session info for "Remember Me"
public class RememberedUser
{
public string Username { get; set; }
public bool IsEmployeeLogin { get; set; }
// Could add a token and expiry date for real security
}
// Add other relevant properties
}
// Simple class to hold session info for "Remember Me"
public class RememberedUser
{
public string Username { get; set; }
public bool IsEmployeeLogin { get; set; }
// Could add a token and expiry date for real security
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/Models/Listing.cs"> using System; using System.Collections.Generic;
namespace WorldSkillsApp.Models { public class Listing { public int Id { get; set; } public string OwnerUsername { get; set; } // Link to the user who owns it public int ServiceTypeId { get; set; } public string Title { get; set; } public int Capacity { get; set; } public int NumBeds { get; set; } public int NumBedrooms { get; set; } public int NumBathrooms { get; set; } public string ExactAddress { get; set; } // Full address public string Area { get; set; } // Suburb or zone public string Description { get; set; } // Optional description public int MinNights { get; set; } public int MaxNights { get; set; } public decimal PricePerNight { get; set; } // Example pricing field
// Navigation Properties (for relationships)
public virtual ServiceType ServiceType { get; set; }
public virtual ICollection<ListingAmenity> ListingAmenities { get; set; } = new HashSet<ListingAmenity>();
public virtual ICollection<ListingAttractionDistance> Distances { get; set; } = new HashSet<ListingAttractionDistance>();
}
public class ServiceType
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Amenity
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Attraction
{
public int Id { get; set; }
public string Name { get; set; }
public string Area { get; set; } // Area where attraction is located
}
// Join table for Many-to-Many relationship between Listing and Amenity
public class ListingAmenity
{
public int ListingId { get; set; }
public int AmenityId { get; set; }
public virtual Listing Listing { get; set; }
public virtual Amenity Amenity { get; set; }
}
// Represents distance/time from a listing to an attraction
public class ListingAttractionDistance
{
public int Id { get; set; }
public int ListingId { get; set; }
public int AttractionId { get; set; }
public decimal DistanceKm { get; set; }
public int? TimeMinutesWalk { get; set; } // Nullable
public int? TimeMinutesCar { get; set; } // Nullable
public virtual Listing Listing { get; set; }
public virtual Attraction Attraction { get; set; }
}
// ViewModel for displaying listings in grids
public class ListingViewModel
{
public int Id { get; set; } // Keep Id for editing
public string Title { get; set; }
public int Capacity { get; set; }
public string Area { get; set; }
public string Type { get; set; } // ServiceType Name
public string OwnerUsername { get; set; } // Needed for filtering/identification
// Add other fields if needed for display or filtering
public List<string> AttractionNamesNear { get; set; } = new List<string>(); // For search
}
// Navigation Properties (for relationships)
public virtual ServiceType ServiceType { get; set; }
public virtual ICollection<ListingAmenity> ListingAmenities { get; set; } = new HashSet<ListingAmenity>();
public virtual ICollection<ListingAttractionDistance> Distances { get; set; } = new HashSet<ListingAttractionDistance>();
}
public class ServiceType
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Amenity
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Attraction
{
public int Id { get; set; }
public string Name { get; set; }
public string Area { get; set; } // Area where attraction is located
}
// Join table for Many-to-Many relationship between Listing and Amenity
public class ListingAmenity
{
public int ListingId { get; set; }
public int AmenityId { get; set; }
public virtual Listing Listing { get; set; }
public virtual Amenity Amenity { get; set; }
}
// Represents distance/time from a listing to an attraction
public class ListingAttractionDistance
{
public int Id { get; set; }
public int ListingId { get; set; }
public int AttractionId { get; set; }
public decimal DistanceKm { get; set; }
public int? TimeMinutesWalk { get; set; } // Nullable
public int? TimeMinutesCar { get; set; } // Nullable
public virtual Listing Listing { get; set; }
public virtual Attraction Attraction { get; set; }
}
// ViewModel for displaying listings in grids
public class ListingViewModel
{
public int Id { get; set; } // Keep Id for editing
public string Title { get; set; }
public int Capacity { get; set; }
public string Area { get; set; }
public string Type { get; set; } // ServiceType Name
public string OwnerUsername { get; set; } // Needed for filtering/identification
// Add other fields if needed for display or filtering
public List<string> AttractionNamesNear { get; set; } = new List<string>(); // For search
}
} </jitFile> <jitFile type="file" filePath="WorldSkillsApp/Services/AuthenticationService.cs"> using System; using System.Collections.Generic; using System.Linq; using WorldSkillsApp.Models; // Assuming models are in this namespace
namespace WorldSkillsApp { // --- Placeholder Service --- // In a real app, this would interact with a database (DAL) // and potentially use password hashing libraries (e.g., BCrypt.Net) public class AuthenticationService { // Dummy data store - Replace with database context private static List<User> _users = new List<User> { // Add some dummy users and employees new User { Id = 1, Username = "traveler1", FullName = "Test Traveler", Birthdate = new DateTime(1990, 5, 15), PasswordHash = "pass1", IsEmployee = false }, new User { Id = 2, Username = "owner1", FullName = "Test Owner", Birthdate = new DateTime(1985, 10, 20), PasswordHash = "pass2", IsEmployee = false }, new User { Id = 3, Username = "manager1", FullName = "Test Manager", Birthdate = new DateTime(1988, 3, 1), PasswordHash = "pass3", IsEmployee = false }, new User { Id = 101, Username = "emp001", FullName = "Call Center Staff", Birthdate = new DateTime(1995, 1, 1), PasswordHash = "empPass1", IsEmployee = true }, new User { Id = 102, Username = "admin", FullName = "System Admin", Birthdate = new DateTime(1980, 1, 1), PasswordHash = "adminPass", IsEmployee = true }, }; private static int _nextUserId = 103; // Simple ID generation
private string _lastError = "Invalid credentials."; // Default error
public string GetLastError() => _lastError;
public bool AuthenticateUser(string username, string password)
{
_lastError = "Invalid username or password.";
var user = _users.FirstOrDefault(u => u.Username.Equals(username, StringComparison.OrdinalIgnoreCase
private string _lastError = "Invalid credentials."; // Default error
public string GetLastError() => _lastError;
public bool AuthenticateUser(string username, string password)
{
_lastError = "Invalid username or password.";
var user = _users.FirstOrDefault(u => u.Username.Equals(username, StringComparison.OrdinalIgnoreCase