示例#1
0
        // login button
        private void ButtonLogin_Click(object sender, EventArgs e)
        {
            string username = TextUser.Text;
            string password = Textpassword.Text;
            string user1    = "Admin1";
            string user2    = "Admin2";

            if (username == string.Empty || password == string.Empty)
            {
                MessageBox.Show("Your information must be filled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (password.Length <= 6)
            {
                MessageBox.Show("Password must be more than 6 words", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ((string.Compare(username, user1, false) == 0 && password.Length > 6) || (string.Compare(username, user2, false) == 0 && password.Length > 6))
            {
                MessageBox.Show("Login success", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
                FormNhanVien nhanVien = new FormNhanVien();
                nhanVien.Show();
            }
            else if (string.Compare(username, user1, false) != 0 || string.Compare(username, user2, false) == 0)
            {
                MessageBox.Show("Information not match", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        // click button action
        // nút signup
        private void button1_Click(object sender, EventArgs e)
        {
            // tên tài khoản
            string name = txtAccountName.Text;
            // địa chỉ email
            string email = txtEmail.Text;
            // số đt
            string phonenumber = txtPhone.Text;
            // password
            string password = txtPassword.Text;
            // nhập lại password
            string confirm = txtConfirm.Text;

            // kiểm tra dữ liệu không được phép trống
            if (name == string.Empty || email == string.Empty || phonenumber == string.Empty || password == string.Empty || confirm == string.Empty)
            {
                MessageBox.Show("You must not leave any information blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            // kiểm tra độ dài password
            else if (password.Length <= 6)
            {
                MessageBox.Show("Password must be more than 6 words", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            // kiểm tra bằng cách so sánh chuỗi có phân biệt hoa thường
            else if (string.Compare(password, confirm, false) != 0)
            {
                MessageBox.Show("Password and confirm aren't match", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            // kiểm tra toàn bộ nếu đúng thì đăng ký thành công ngược lại thì thanh thụ
            else if (password.Length > 6 && string.Compare(password, confirm, false) == 0)
            {
                MessageBox.Show("Sign up success press 'ok' to continue", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Hide();
                FormNhanVien formNhanVien = new FormNhanVien();
                formNhanVien.Show();
            }
        }