예제 #1
0
    public void insert_info()
    {
        string fname, lname, mclass, year, usern, pass, cpass;

        Console.WriteLine("Student Sign Up Selected \n");
        Console.WriteLine("Please type the following informations :\n");

        Console.WriteLine("First Name: "); fname       = Console.ReadLine();
        Console.WriteLine("Last Name: "); lname        = Console.ReadLine();
        Console.WriteLine("Class: "); mclass           = Console.ReadLine();
        Console.WriteLine("Year: "); year              = Console.ReadLine();
        Console.WriteLine("Username: "******"Password: "******"Confirm Password: "******"" || lname == "" || mclass == "" || year == "" || usern == "" || pass == "" || cpass == "")
        {
            Console.WriteLine("Please fill mandatory fields");

            re_insert_data_student mdata = new re_insert_data_student();

            mdata.insert_info();
        }
        else if (pass != cpass)
        {
            Console.WriteLine("Wrong password!");

            re_insert_data_student mdata = new re_insert_data_student();
            mdata.insert_info();
        }
        else
        {
            string commandText = "INSERT INTO Student (" +
                                 "[First Name]," +
                                 "[Last Name]," +
                                 "Class," +
                                 "Year," +
                                 "Username," +
                                 "Password," +
                                 "[Confirm Password])" +
                                 " VALUES (" +
                                 "@fname," +
                                 "@lname," +
                                 "@mclass," +
                                 "@year," +
                                 "@usern," +
                                 "@pass," +
                                 "@cpass);";


            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(commandText, connection);

                command.Parameters.AddWithValue("@fname", fname);
                command.Parameters.AddWithValue("@lname", lname);
                command.Parameters.AddWithValue("@mclass", mclass);
                command.Parameters.AddWithValue("@year", year);
                command.Parameters.AddWithValue("@usern", usern);
                command.Parameters.AddWithValue("@pass", pass);
                command.Parameters.AddWithValue("@cpass", cpass);

                try
                {
                    connection.Open();
                    Int32 rowsAffected = command.ExecuteNonQuery();
                    Console.WriteLine("RowsAffected: {0}", rowsAffected);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine("Registration is sucessfull!");
        }
    }
예제 #2
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;
        }
    }