diff --git a/Code/DBProject/SignUp.aspx.cs b/Code/DBProject/SignUp.aspx.cs index 582293e..92a8c04 100644 --- a/Code/DBProject/SignUp.aspx.cs +++ b/Code/DBProject/SignUp.aspx.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; +using System; using System.Web.UI; -using System.Web.UI.WebControls; using DBProject.DAL; -using System.Data; - namespace DBProject { @@ -14,114 +8,91 @@ public partial class SignUp : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { - Session["idoriginal"] = ""; + if (!IsPostBack) + { + Session["idoriginal"] = ""; + } } - //-----------------------Function1--------------------------// + //----------------------- Login Function --------------------------// protected void loginV(object sender, EventArgs e) { - string email = loginEmail.Text; - string password = loginPassword.Text; + string email = loginEmail.Text.Trim(); + string password = loginPassword.Text.Trim(); - myDAL objmyDAl = new myDAL(); - - int status = 0; - int type = 0; - int id = 0; + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + ShowAlert("Please enter both Email and Password."); + return; + } - status = objmyDAl.validateLogin(email, password, ref type, ref id); + myDAL objmyDAL = new myDAL(); + int status = objmyDAL.validateLogin(email, password, ref int type, ref int id); if (status == 0) { Session["idoriginal"] = id; - if (type == 1) - { - Response.BufferOutput = true; - Response.Redirect("~/Patient/PatientHome.aspx"); - return; - } - - else if (type == 2) - { - Response.BufferOutput = true; - Response.Redirect("~/Doctor/DoctorHome.aspx"); - return; - } - - else if (type == 3) + switch (type) { - Response.BufferOutput = true; - Response.Redirect("~/Admin/AdminHome.aspx"); - return; + case 1: + Response.Redirect("~/Patient/PatientHome.aspx", false); + break; + case 2: + Response.Redirect("~/Doctor/DoctorHome.aspx", false); + break; + case 3: + Response.Redirect("~/Admin/AdminHome.aspx", false); + break; + default: + ShowAlert("Invalid user type."); + break; } } - - else if (status == 1) - { - Response.Write(""); - } - + ShowAlert("Email not found. Try again!"); else if (status == 2) - { - Response.Write(""); - } - - else if (status == -1) - { - Response.Write(""); - } + ShowAlert("Incorrect password. Try again!"); + else + ShowAlert("Unexpected error occurred. Please try again."); } - - - - //-----------------------Function2--------------------------// + //----------------------- Signup Function --------------------------// protected void signupV(object sender, EventArgs e) { - string Name = sName.Text; - string BirthDate = sBirthDate.Text; - string Email = sEmail.Text; - string Password = sPassword.Text; - string PhoneNo = Phone.Text; - string Addr = Address.Text; - - string gender = Request.Form["Gender"].ToString(); - - - - myDAL objmyDAl = new myDAL(); + string name = sName.Text.Trim(); + string birthDate = sBirthDate.Text.Trim(); + string email = sEmail.Text.Trim(); + string password = sPassword.Text.Trim(); + string phone = Phone.Text.Trim(); + string addr = Address.Text.Trim(); + string gender = Request.Form["Gender"]; + + if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + ShowAlert("Please fill in all required fields."); + return; + } + myDAL objmyDAL = new myDAL(); int id = 0; + int status = objmyDAL.validateUser(name, birthDate, email, password, phone, gender, addr, ref id); - int status = objmyDAl.validateUser(Name, BirthDate, Email, Password, PhoneNo, gender, Addr, ref id); - - - //status == 0 failure if (status == 0) - { - Response.Write(""); - } - + ShowAlert("Email already exists. Please choose a different one."); else if (status == 1) { Session["idoriginal"] = id; - - //Response.Write(""); - - Response.BufferOutput = true; - Response.Redirect("~/Patient/PatientHome.aspx"); + Response.Redirect("~/Patient/PatientHome.aspx", false); } - - else if (status == -1) - { - Response.Write(""); - } - + else + ShowAlert("Unexpected error occurred. Please try again."); } - //Enter new function here// + //----------------------- Utility Function --------------------------// + private void ShowAlert(string message) + { + ClientScript.RegisterStartupScript(this.GetType(), "alert", $"alert('{message}');", true); + } } - -} \ No newline at end of file +}