private void SignUpButton_Click_1(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=OLA\SQLSERVER;Initial Catalog=ApplicantTrackingSystem;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False");

            con.Open();

            bool Reg, UsedUsername;

            if (!string.IsNullOrEmpty(MailBox.Text) && !(MailBox.Text == "E-mail") &&
                !string.IsNullOrEmpty(UsernameBox.Text) && !(UsernameBox.Text == "Username") &&
                !string.IsNullOrEmpty(PasswordBox.Text) && !(PasswordBox.Text == "Password") &&
                !(CareerLevelBox.Text == "Career Level") && !string.IsNullOrEmpty(CareerLevelBox.Text) &&
                !(EducationalLevelBox.Text == "Educational Level") && !string.IsNullOrEmpty(EducationalLevelBox.Text) &&
                !(YearsOfExperience.Text == "Years of Experience") && !string.IsNullOrEmpty(YearsOfExperience.Text) &&
                !(FirstName.Text == "First Name") && !string.IsNullOrEmpty(FirstName.Text) &&
                !(LastName.Text == "Last Name") && !string.IsNullOrEmpty(LastName.Text) &&
                !(CountryBox.Text == "Country") && !string.IsNullOrEmpty(CountryBox.Text) &&
                !(CityBox.Text == "City") && !string.IsNullOrEmpty(CityBox.Text) &&
                !(AreaBox.Text == "Area") && !string.IsNullOrEmpty(AreaBox.Text) &&
                !(MobileBox.Text == "Mobile Number") && !string.IsNullOrEmpty(MobileBox.Text)
                )
            {
                SqlCommand    cmd = new SqlCommand("select Username, Mail from [Candidate]", con);
                SqlDataReader rdr = cmd.ExecuteReader();
                Reg          = false;
                UsedUsername = false;

                while (rdr.Read())
                {
                    string Mail = (string)rdr["Mail"];
                    if (Mail != MailBox.Text)
                    {
                        Reg = false;
                    }
                    else
                    {
                        Reg = true;
                        MessageBox.Show("You already have an account! You can log in.");
                        Form form = new UserLogin();
                        form.Show();
                        this.Hide();

                        break;
                    }

                    string UserName = (string)rdr["Username"];
                    if (UserName == UsernameBox.Text)
                    {
                        UsedUsername = true;
                        MessageBox.Show("This Usename already used, Please write another one.");
                        UsernameBox.Clear();
                        break;
                    }
                }

                rdr.Close();
                if (!Reg && !UsedUsername)
                {
                    string     CandidateInsertCommand = "INSERT INTO [Candidate](Username,Mail , Password)VALUES  (@Username,@Mail , @Password)";
                    SqlCommand CandidateInsert        = new SqlCommand(CandidateInsertCommand, con);


                    CandidateInsert.Parameters.AddWithValue("@Mail", MailBox.Text);
                    CandidateInsert.Parameters.AddWithValue("@Username", UsernameBox.Text);
                    CandidateInsert.Parameters.AddWithValue("@Password", PasswordBox.Text);
                    CandidateInsert.ExecuteNonQuery();

                    string     PersonalInfoInsertCommand = "INSERT INTO [PersonalInformation](Username,FirstName,LastName,Birthdate,Country,City,Area,MobileNumber) VALUES (@Username,@FirstName,@LastName,@Birthdate,@Country,@City,@Area,@MobileNumber)";
                    SqlCommand PersonalInfoInsert        = new SqlCommand(PersonalInfoInsertCommand, con);
                    //Username,FirstName,LastName,Birthdate,Country,City,Area,MobileNumber

                    PersonalInfoInsert.Parameters.AddWithValue("@Username", UsernameBox.Text);
                    PersonalInfoInsert.Parameters.AddWithValue("@FirstName", FirstName.Text);
                    PersonalInfoInsert.Parameters.AddWithValue("@LastName", LastName.Text);
                    PersonalInfoInsert.Parameters.AddWithValue("@Birthdate", Birthdate.Value.Date.ToString("yyyyMMdd"));
                    PersonalInfoInsert.Parameters.AddWithValue("@Country", CountryBox.Text);
                    PersonalInfoInsert.Parameters.AddWithValue("@City", CityBox.Text);
                    PersonalInfoInsert.Parameters.AddWithValue("@Area", AreaBox.Text);
                    PersonalInfoInsert.Parameters.AddWithValue("@MobileNumber", MobileBox.Text);

                    PersonalInfoInsert.ExecuteNonQuery();



                    string     CareerInsertCommand = "INSERT INTO [CareerInterests](Username,EducationLevel,CareerLevel,ExperienceYears) VALUES (@Username,@EducationLevel,@CareerLevel,@ExperienceYears)";
                    SqlCommand CareerInsert        = new SqlCommand(CareerInsertCommand, con);
                    //EducationalLevel,CareerLevel,ExperienceYears
                    CareerInsert.Parameters.AddWithValue("@Username", UsernameBox.Text);
                    CareerInsert.Parameters.AddWithValue("@EducationLevel", EducationalLevelBox.Text);
                    CareerInsert.Parameters.AddWithValue("@CareerLevel", CareerLevelBox.Text);
                    CareerInsert.Parameters.AddWithValue("@ExperienceYears", Convert.ToInt64(YearsOfExperience.Text));


                    CareerInsert.ExecuteNonQuery();


                    MessageBox.Show("Registration Completed, Now you have an account and you can log in.");
                    Form form = new UserLogin();
                    form.Show();
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show("Please Fill the Empty Boxes");
            }
            con.Close();
        }
Ejemplo n.º 2
0
        private void SignUpButton_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=OLA\SQLSERVER;Initial Catalog=ApplicantTrackingSystem;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False");

            con.Open();

            bool Reg, UsedUsername;

            if (!string.IsNullOrEmpty(MailBox.Text) && !string.IsNullOrEmpty(CompanyBox.Text) &&
                !string.IsNullOrEmpty(PasswordBox.Text) && !(MailBox.Text == "E-mail") &&
                !(CompanyBox.Text == "Username") && !(PasswordBox.Text == "Password"))
            {
                SqlCommand    cmd = new SqlCommand("select Username, Mail from [Account]", con);
                SqlDataReader rdr = cmd.ExecuteReader();
                Reg          = false;
                UsedUsername = false;

                while (rdr.Read())
                {
                    string Mail = (string)rdr["Mail"];
                    if (Mail != MailBox.Text)
                    {
                        Reg = false;
                    }
                    else
                    {
                        Reg = true;
                        MessageBox.Show("You already have an account! You can log in.");
                        Form form = new UserLogin();
                        form.Show();
                        this.Hide();

                        break;
                    }

                    string UserName = (string)rdr["Username"];
                    if (UserName == CompanyBox.Text)
                    {
                        UsedUsername = true;
                        MessageBox.Show("This Company already Exist");
                        CompanyBox.Clear();
                        break;
                    }
                }

                rdr.Close();
                if (!Reg && !UsedUsername)
                {
                    string     AccountInsertCommand = "INSERT INTO [Account]VALUES  (@Mail, @Username, @Password,@Type)";
                    SqlCommand AccountInsert        = new SqlCommand(AccountInsertCommand, con);


                    AccountInsert.Parameters.AddWithValue("@Mail", MailBox.Text);
                    AccountInsert.Parameters.AddWithValue("@Username", CompanyBox.Text);
                    AccountInsert.Parameters.AddWithValue("@Password", Convert.ToInt64(PasswordBox.Text));
                    AccountInsert.Parameters.AddWithValue("@Type", 1);
                    AccountInsert.ExecuteNonQuery();

                    MessageBox.Show("Registration Completed, Now you have an account and you can log in.");
                }
            }
            else
            {
                MessageBox.Show("Please Fill the Empty Boxes");
            }
            con.Close();
        }