private void btDangNhap_Click(object sender, EventArgs e) { string sql = "select username,isLoggedIn from users where username='******' and password='******'"; SQLConnection connection = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123")); SqlDataReader reader = connection.Query(sql); if (reader.HasRows && reader.Read() && reader.GetInt32(1) == 0) { //create new connection to update login status SQLConnection conn = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123")); string sqlcmd = "update users set isLoggedIn=1 where username='******'"; conn.AddRemoveAlter(sqlcmd); conn.Close(); // MessageBox.Show("Đăng nhập thành công"); txtboxUsername.Text = txtboxID.Text; txtboxID.Text = ""; txtboxPassword.Text = ""; txtboxRivalIP.Enabled = true; btCreateRoom.Enabled = true; btEnterRoom.Enabled = true; Const.username = txtboxUsername.Text; Const.serverIP = txtboxDatabaseIP.Text; } else if (reader.HasRows && reader.GetInt32(1) == 1) { MessageBox.Show("Tài khoản đang được đăng nhập ở nơi khác !!!"); } else { MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu !!!"); } connection.Close(); }
bool IsValidUsername(string username) { //Chuan bi cau lenh query viet bang SQL String sqlQuery = "select * from users where username='******'"; SQLConnection connection = new SQLConnection(SQLConnection.GetDatabasePath(txtboxDatabaseIP.Text + ",6969", "doan", "admin", "cuong123")); SqlDataReader reader = connection.Query(sqlQuery); if (reader.HasRows) { connection.Close(); return(false); } connection.Close(); return(true); }
private void LoadDataToTable(string databaseIP) { //Chuan bi cau lenh query viet bang SQL String sqlQuery = "select username,won_matchs from users order by won_matchs desc"; SQLConnection connection = new SQLConnection(SQLConnection.GetDatabasePath(databaseIP + ",6969", "doan", "admin", "cuong123")); SqlDataReader reader = connection.Query(sqlQuery); //Su dung reader de doc tung dong du lieu //va thuc hien thao tac xu ly mong muon voi du lieu doc len while (reader.HasRows)//con dong du lieu thi doc tiep { if (reader.Read() == false) { return; //doc ko duoc thi return } //xu ly khi da doc du lieu len dataGridView1.Rows.Add(reader.GetString(0), reader.GetInt32(1)); } connection.Close(); }