コード例 #1
0
        public DataTable userList()
        {
            MY_DB          db      = new MY_DB();
            DataTable      tb      = new DataTable();
            SqlCommand     cmd     = new SqlCommand("SELECT user_id, fname, lname, birthdate, gender, phone, address, picture, selected_courses FROM listUser", db.getConnection);
            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = cmd;
            adapter.Fill(tb);
            return(tb);
        }
コード例 #2
0
ファイル: Login.cs プロジェクト: concuachetngac/winform
 private void loginButton_Click(object sender, EventArgs e)
 {
     if (userRadio.Checked)
     {
         MY_DB          db      = new MY_DB();
         SqlDataAdapter adapter = new SqlDataAdapter();
         DataTable      table   = new DataTable();
         SqlCommand     command = new SqlCommand("SELECT * FROM [account] WHERE username = @User AND password = @Pass", db.getConnection);
         command.Parameters.Add("@User", SqlDbType.NVarChar).Value = textBoxUser.Text;
         command.Parameters.Add("@Pass", SqlDbType.NVarChar).Value = textBoxPass.Text;
         adapter.SelectCommand = command;
         adapter.Fill(table);
         if (table.Rows.Count > 0)
         {
             MessageBox.Show("Ok, next time will be go to Main Menu of App");
             MainMenu menu = new MainMenu();
             menu.Show();
         }
         else
         {
             MessageBox.Show("Invalid Username or Password", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         if (textBoxUser.Text == string.Empty)
         {
             textBoxUser.Focus();
             errorProvider1.SetError(textBoxUser, "Please input username !!!");
         }
         if (textBoxPass.Text == string.Empty)
         {
             textBoxPass.Focus();
             errorProvider1.SetError(textBoxPass, "Please input password !!!");
         }
     }
     else
     {
         MY_DB          db      = new MY_DB();
         SqlDataAdapter adapter = new SqlDataAdapter();
         DataTable      table   = new DataTable();
         SqlCommand     command = new SqlCommand("SELECT * FROM [customer] WHERE username = @user AND password = @pass", db.getConnection);
         command.Parameters.Add("@user", SqlDbType.NVarChar).Value = textBoxUser.Text;
         command.Parameters.Add("pass", SqlDbType.NVarChar).Value  = textBoxPass.Text;
         adapter.SelectCommand = command;
         adapter.Fill(table);
         if (table.Rows.Count > 0)
         {
             MessageBox.Show("Ok, next time will be go to Main Menu of App");
             CustomerMainInterface customer = new CustomerMainInterface();
             Global.setCustomerID(Convert.ToInt32(table.Rows[0][0]));
             customer.Show();
         }
         else
         {
             MessageBox.Show("Invalid Username or Password", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         if (textBoxUser.Text == string.Empty)
         {
             textBoxUser.Focus();
             errorProvider1.SetError(textBoxUser, "Please input username !!!");
         }
         if (textBoxPass.Text == string.Empty)
         {
             textBoxPass.Focus();
             errorProvider1.SetError(textBoxPass, "Please input password !!!");
         }
     }
 }