Beispiel #1
0
    //static string connectionString = "SERVER = .\\SQLEXPRESS; DATABASE = MathAppDB; USER ID = zsolt; PASSWORD = 12345678; Trusted_Connection=True;";
    public void my_select()
    {
        string my_select, my_select2, my_select3;


        Console.WriteLine("\n\tMathApp\n");

        Console.WriteLine("Select between [1] - [2] - [3] \n");
        Console.WriteLine("[1] - Login \t [2] - Sign Up \t   [3] - Exit");

        my_select = Console.ReadLine();

        switch (my_select)
        {
        case "1":

            Console.WriteLine("Select between [A] and [B] \n");
            Console.WriteLine("[A] - Student Login \t [B] - Teacher Login");
            my_select2 = Console.ReadLine();

            switch (my_select2)
            {
            case "A":

                Console.WriteLine("Student Login Selected \n");

                show_login stud = new show_login();
                stud.student_login();

                break;

            case "B":

                Console.WriteLine("Teacher Login Selected \n");

                show_login teach = new show_login();
                teach.teacher_login();

                break;

            default:
                Console.WriteLine("Wrong character! \n");
                my_login_sign_up my_try = new my_login_sign_up();
                my_try.my_select();
                break;
            }

            break;

        case "2":

            Console.WriteLine("Select between [A] and [B] \n");
            Console.WriteLine("[A] - Student Sign Up \t [B] - Teacher Sign Up");
            my_select3 = Console.ReadLine();


            switch (my_select3)
            {
            case "A":

                re_insert_data_student mdata = new re_insert_data_student();

                mdata.insert_info();

                break;

            case "B":

                re_insert_data_teacher mdata1 = new re_insert_data_teacher();

                mdata1.insert_info();

                break;

            default:

                Console.WriteLine("Wrong character! \n");
                my_login_sign_up my_try2 = new my_login_sign_up();
                my_try2.my_select();
                break;
            }

            break;

        case "3":
            Environment.Exit(0);
            break;

        default:

            Console.WriteLine("Wrong number! \n");
            my_login_sign_up my_try3 = new my_login_sign_up();
            my_try3.my_select();
            break;
        }
    }
Beispiel #2
0
    public void student_login()
    {
        string uname, pass, cpass;
        bool   my_stud = false, my_pass = false, my_cpass = false;

        Console.WriteLine("Please enter the followings: \n");

        Console.WriteLine("Username: "******"Password: "******"Confirm Password: "******"SELECT * FROM Student WHERE ([Username] = @user)", connection);
        SqlCommand check_password         = new SqlCommand("SELECT * FROM Student WHERE ([Password] = @pass)", connection);
        SqlCommand check_confirm_password = new SqlCommand("SELECT * FROM Student  WHERE ([Confirm Password] = @cpass)", connection);

        check_User_Name.Parameters.AddWithValue("@user", uname);
        check_password.Parameters.AddWithValue("@pass", pass);
        check_confirm_password.Parameters.AddWithValue("@cpass", cpass);

        connection.Open();
        using (SqlDataReader reader_user = check_User_Name.ExecuteReader())
        {
            if (reader_user.HasRows)
            {
                //Console.WriteLine("User exist");
                my_stud = true;
            }
            else
            {
                Console.WriteLine("User doesnt exist");
                show_login stud = new show_login();
                stud.student_login();
            }
        }
        connection.Close();

        connection.Open();
        using (SqlDataReader reader_pass = check_password.ExecuteReader())
        {
            if (reader_pass.HasRows)
            {
                //Console.WriteLine("Password exist");
                my_pass = true;
            }
            else
            {
                Console.WriteLine("Wrong Password or doesnt exist");
                show_login stud = new show_login();
                stud.student_login();
            }
        }
        connection.Close();

        connection.Open();
        using (SqlDataReader reader_cpass = check_confirm_password.ExecuteReader())
        {
            if (reader_cpass.HasRows)
            {
                //Console.WriteLine("Confirm Password exist");
                my_cpass = true;
            }
            else
            {
                Console.WriteLine("Wrong Confirm Password or doesnt exist");
                show_login stud = new show_login();
                stud.student_login();
            }
        }
        connection.Close();

        if (my_stud || my_pass || my_cpass)
        {
            Console.WriteLine("\n");
            SqlCommand cmd = new SqlCommand("Select * From Student WHERE Password = @pass", connection);
            using (connection)
            {
                try
                {
                    connection.Open();

                    cmd.Parameters.AddWithValue("@pass", pass);

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                Console.WriteLine(reader.GetValue(i));
                            }
                            Console.WriteLine();
                        }
                    }

                    connection.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    Console.ReadKey();
                }
            }
        }
    }