private void FillDataGrid() { listUsers = Firebird.ReturnListUsers(); dataGridView1.AllowUserToAddRows = false; dataGridView1.AllowUserToResizeRows = false; DataTable dataTable = new DataTable(); dataTable.Columns.Add("Usuário", typeof(string)); dataTable.Columns.Add("Salvar", typeof(bool)); dataTable.Columns.Add("Delet.", typeof(bool)); dataTable.Columns.Add("Alterar", typeof(bool)); for (int i = 0; i < listUsers.Count; i++) { string s = listUsers[i].UserName; if (listUsers[i].IsAdmin == 1) { s += " (admin)"; } dataTable.Rows.Add(s, listUsers[i].CanAdd, listUsers[i].CanDelete, listUsers[i].CanAlter); } dataGridView1.DataSource = dataTable; for (int i = 0; i < 4; i++) { DataGridViewColumn column = dataGridView1.Columns[i]; column.Width = 50; if (i == 0) { column.Width = 200; } } dataGridView1.Columns[0].ReadOnly = true; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; }
private void btLogin_Click(object sender, EventArgs e) { if (btLogin.Text == "Login") { var user = Firebird.ReturnUser(txtUser.Text, txtPassword.Text); if (user.UserName == null) { var lista = Firebird.ReturnListUsers(); bool UserExists = false; foreach (var item in lista) { if (item.UserName == txtUser.Text) { UserExists = true; break; } } string s = string.Empty; if (!UserExists) { s = "Usuário não encontrado"; } else { s = "Senha incorreta"; } MessageBox.Show(s, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } CurrentUser = user; cbCanAdd.Checked = user.CanAdd == 1; cbCanAlter.Checked = user.CanAlter == 1; cbCanDelete.Checked = user.CanDelete == 1; txtUser.Enabled = false; txtPassword.Enabled = false; btLogin.Text = "Desconectar"; lbUser.Text = user.UserName; if (CurrentUser.IsAdmin == 1) { label1.Text = "Admin: "; } else { label1.Text = "Usuário: "; } Firebird.SaveLastUser(CurrentUser); return; } if (btLogin.Text == "Desconectar") { CurrentUser = null; txtUser.Enabled = true; txtPassword.Enabled = true; txtUser.Text = string.Empty; txtPassword.Text = string.Empty; btLogin.Text = "Login"; lbUser.Text = "--"; } }