static void Main(string[] args) { Console.WriteLine("Welcome to Student Management System"); mainprogram: Console.Clear(); Console.WriteLine("Select from the given options :"); Console.WriteLine("1.Teacher Registration 2.Teacher login 3.Student login"); int c = Convert.ToInt32(Console.ReadLine()); try { switch (c) { case 1: try { Console.WriteLine("Enter your Name"); string p_name = Console.ReadLine(); Console.WriteLine("Enter your Password"); string p_pass = TurnToStars(); if (p_pass.Length < 8) { throw new PassLengthNotValidException("Password should be more than 8 character"); } Console.WriteLine("Enter your City"); string p_city = Console.ReadLine(); Console.WriteLine("Enter your Email"); string p_email = Console.ReadLine(); Console.WriteLine("Enter your Contact Number"); string p_contact = Console.ReadLine(); teacher t1 = new teacher(p_name, p_pass, p_city, p_email, p_contact); t1.selfregistration(); } catch (PassLengthNotValidException e) { Console.WriteLine(e.Message); } break; case 2: Console.WriteLine("enter user Id and Password to login"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("enter password"); string pass = TurnToStars(); teacher t = new teacher(); int j = t.login(id, pass); if (j == 3) { Console.WriteLine("Logged in successfully!"); Console.WriteLine("Enter :"); Console.WriteLine("1.To Register new student 2.Update the existing Student 3.Update Your Details 4.Delete Student 5.Delete your ID"); int x = int.Parse(Console.ReadLine()); if (x == 1) { t.registration(); } else if (x == 2) { Console.WriteLine("Enter student ID to edit details"); int stid = int.Parse(Console.ReadLine()); t.UpdateStudent(stid); } else if (x == 3) { t.Update_teacher(id); } else if (x == 4) { Console.WriteLine("Enter Student ID to delete: "); int did = int.Parse(Console.ReadLine()); t.DeleteStudent(did); } else { t.DeleteTeacher(id); } } else { Console.WriteLine("Failed"); } break; case 3: Console.WriteLine("enter user Id and Password to login"); int sid = int.Parse(Console.ReadLine()); Console.WriteLine("enter password"); string spass = TurnToStars(); student o = new student(); int i = o.login(sid, spass); if (i == 1) { Console.WriteLine("Logged in successfully!"); } else { Console.WriteLine("Incorrect ID/Password!"); } break; } } catch (SqlException e) { Console.WriteLine(e.Message); } Console.WriteLine("Press Y to continue or any other key to exit"); char inp = char.Parse(Console.ReadLine()); if (inp == 'Y' || inp == 'y') { goto mainprogram; } }
// partial void selfregistration(); public void registration() { Console.WriteLine("Enter Student Name"); string p_name = Console.ReadLine(); try { Console.WriteLine("Enter Student Password"); string p_pass = Console.ReadLine(); if (p_pass.Length < 8) { throw new PassLengthNotValidException("Password should be more than 8 character"); } Console.WriteLine("Enter Student City"); string p_city = Console.ReadLine(); Console.WriteLine("Enter Student Email"); string p_email = Console.ReadLine(); Console.WriteLine("Enter Student Contact Number"); string p_contact = Console.ReadLine(); SqlCommand cmd1 = new SqlCommand("insert into student(p_name,p_pass,p_city,p_email,p_contact)values(@p_name,@p_pass,@p_city,@p_email,@p_contact)", con); cmd1.Parameters.AddWithValue("@p_name", p_name); cmd1.Parameters.AddWithValue("@p_pass", p_pass); cmd1.Parameters.AddWithValue("@p_city", p_city); cmd1.Parameters.AddWithValue("@p_email", p_email); cmd1.Parameters.AddWithValue("@p_contact", p_contact); con.Open(); Console.WriteLine("***"); int i = cmd1.ExecuteNonQuery(); Console.WriteLine("Student Registered Successfully!"); Console.WriteLine("New ID for registered user : "******"SELECT MAX(s_enroll) FROM Student", con); SqlDataReader dr1 = command.ExecuteReader(); using (dr1) { while (dr1.Read()) { Console.WriteLine("ID : " + dr1[0].ToString()); } } Console.WriteLine("Press 1 to login or any other key to exit."); int input = Convert.ToInt32(Console.ReadLine()); if (input == 1) { Console.WriteLine("enter user Id and Password to login"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("enter password"); string pass = Console.ReadLine(); teacher t = new teacher(); int j = t.login(id, pass); if (j == 3) { Console.WriteLine("Successfull Logged In"); t.selfregistration(); } else { Console.WriteLine("Failed"); } } } catch (PassLengthNotValidException e) { Console.WriteLine(e.Message); } catch (SqlException e) { Console.WriteLine(e.Message); } finally { con.Close(); } }