Пример #1
0
        private void ButtonSignin_Click(object sender, EventArgs e)
        {
            MYDB lg = new MYDB();
            dbfromsqlDataContext db = new dbfromsqlDataContext(lg.Connection);
            var selectcus           = from i in db.GetTable <Customersdb>()
                                      where i.Cuser == textBoxUser.Text && i.Cpass == textBoxPass.Text
                                      select i;

            if (selectcus.Count() > 0)
            {
                KhachHangForm kh = new KhachHangForm(textBoxUser.Text);
                kh.Show();
            }
            else
            {
                db = new dbfromsqlDataContext(lg.Connection);
                var selectemp = from i in db.GetTable <Employeesdb>()
                                where i.Euser == textBoxUser.Text && i.Epass == textBoxPass.Text
                                select i;
                if (selectemp.Count() > 0)
                {
                    NhanVienForm nv = new NhanVienForm();
                    nv.Show();
                }
                else
                {
                    MessageBox.Show("invalid user");
                }
            }
        }
Пример #2
0
        private void ButtonSignin_Click(object sender, EventArgs e)
        {
            MYDB lg = new MYDB();

            lg.openconection();
            SqlDataAdapter adapter = new SqlDataAdapter();
            DataTable      table   = new DataTable();
            SqlCommand     command = new SqlCommand("SELECT * FROM Customersdb WHERE Cuser=@User and Cpass=@Pass", lg.Connection);

            command.Parameters.Add("@User", SqlDbType.VarChar).Value = textBoxUser.Text;
            command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = textBoxPass.Text;
            SqlDataReader reader = command.ExecuteReader();

            if ((reader.Read() == true))
            //if (command.ExecuteNonQuery() == 1)
            {
                KhachHangForm kh = new KhachHangForm(textBoxUser.Text);
                kh.Show();
            }
            else
            {
                lg.closeconection();
                lg.openconection();
                command = new SqlCommand("SELECT * FROM Employeesdb WHERE Euser=@User and Epass=@Pass", lg.Connection);
                command.Parameters.Add("@User", SqlDbType.VarChar).Value = textBoxUser.Text;
                command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = textBoxPass.Text;
                SqlDataReader reader1 = command.ExecuteReader();

                if (reader1.Read() == true)
                {
                    NhanVienForm nv = new NhanVienForm();
                    nv.Show();
                }
                else
                {
                    MessageBox.Show("invalid user");
                }
            }
        }