Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (ProgressBarForm bar = new ProgressBarForm(SaveData))
            {
                bar.ShowDialog(this);
            }
            My_Database    my_data = new My_Database();
            SqlDataAdapter sda     = new SqlDataAdapter();
            DataTable      table   = new DataTable();
            SqlCommand     command = new SqlCommand("SELECT * FROM Login WHERE Username = @User AND Password = @Pass", my_data.Getcon);

            command.Parameters.Add("@User", SqlDbType.VarChar).Value = Username_tb.Text;
            command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = Password_tb.Text;
            sda.SelectCommand = command;
            sda.Fill(table);
            if (table.Rows.Count > 0)
            {
                MessageBox.Show("Ok, Login Successful");
                Function_Login fl = new Function_Login();
                this.Hide();
                fl.Show();
            }
            else
            {
                MessageBox.Show("Invalid Username or Password, Please create new account!", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Function_Login fl = new Function_Login();
                //fl.Show();
            }
            for (int i = 0; i < 100; i++)
            {
                progressBar1.Increment(i);
            }
        }
Пример #2
0
        private void button2add_Click(object sender, EventArgs e)
        {
            Student  student   = new Student();
            int      Id        = Convert.ToInt32(ID_student.Text);
            string   firstname = this.firstname.Text;
            string   lastname  = this.lastname.Text;
            DateTime birthday  = datetime.Value;
            string   phone     = this.address1.Text;
            string   address   = this.phone.Text;
            string   gender    = "Female";

            if (malebutton.Checked)
            {
                gender = "Male";
            }
            MemoryStream pic       = new MemoryStream();
            int          born_year = datetime.Value.Year;
            int          this_year = DateTime.Now.Year;

            if (this_year - born_year < 10 || this_year - born_year > 100)
            {
                MessageBox.Show("The student age must be 10 to 100 year", "Invalid Birthday", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (verif())
            {
                picture.Image.Save(pic, picture.Image.RawFormat);
                if (student.AddStudent(Id, firstname, lastname, birthday, gender, phone, address, pic))
                {
                    MessageBox.Show("New student added", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Hide();
                    Function_Login fl = new Function_Login();
                    fl.Show();
                }
                else
                {
                    MessageBox.Show("Error", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Empty fields", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }