示例#1
0
文件: Form1.cs 项目: tuananh1998/test
        private void button1_Click(object sender, EventArgs e)
        {
            frmdn f = new frmdn();

            f.Show();
            this.Hide();
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string a = textBox2.Text;
                string b = textBox3.Text;
                if (textBox2.Text.Trim() == "")
                {
                    MessageBox.Show("Bạn chưa nhập mật khẩu!", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    textBox2.Focus();
                }
                else
                {
                    if (textBox3.Text.Trim() == "")
                    {
                        MessageBox.Show("Bạn chưa nhập lại mật khẩu!", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        textBox3.Focus();
                    }
                    else
                    {
                        if (a == b)
                        {
                            if (textBox1.Text.Trim() == "")
                            {
                                MessageBox.Show("Bạn chưa nhập tên người dùng!", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                textBox1.Focus();
                            }

                            if (textBox1.Text.Trim() != "" && textBox2.Text.Trim() != "")
                            {
                                SqlConnection ketnoi = new SqlConnection(truyxuat.con);
                                ketnoi.Open();
                                string     st  = "select count(*) from nguoidung where tk='" + textBox1.Text + "'";
                                int        i   = 0;
                                SqlCommand cmd = new SqlCommand(st, ketnoi);
                                i = (int)cmd.ExecuteScalar();
                                if (i != 0)
                                {
                                    MessageBox.Show("Tài khoản đã được đăng ký. Vui lòng sử dụng tên khác!", "Đăng Ký", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    textBox1.Focus();
                                    textBox1.Text = "";
                                    textBox2.Text = "";
                                    textBox3.Text = "";
                                }


                                else
                                {
                                    string     s  = "insert into nguoidung values('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "')";
                                    SqlCommand cm = new SqlCommand(s, ketnoi);
                                    cm.ExecuteNonQuery();

                                    if (MessageBox.Show("Đăng Ký thành công. Bạn muốn đăng nhập không?", "Đăng Ký", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                    {
                                        frmdn f = new frmdn();
                                        f.Show();
                                        this.Hide();
                                    }
                                    else
                                    {
                                        this.Hide();
                                    }
                                }
                                // this.Hide();
                            }
                        }

                        else
                        {
                            MessageBox.Show("Mật khẩu bạn nhập lại không khớp! Bạn vui lòng kiểm tra lại!", "Đăng nhập", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            textBox2.Clear();
                            textBox3.Clear();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Thao Tác không thực hiện được. Vui lòng kiểm tra lại!", "Đăng Nhập", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }