private void Manager_Load(object sender, EventArgs e) { pnlManagerDropdown.Visible = false; if (Login.Role != "Admin") { BtnAddUser.Enabled = false; } this.BtnUpdate.BackColor = ColorTranslator.FromHtml("#0099cc"); this.btnExportData.BackColor = ColorTranslator.FromHtml("#0099cc"); using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var getAllSchools = dbEntities.SchoolTables.ToList(); dgvSchools.Rows.Clear(); int i = 0; foreach (SchoolTable item in getAllSchools) { dgvSchools.Rows.Add(); dgvSchools.Rows[i].Cells[0].Value = item.Proprietor; dgvSchools.Rows[i].Cells[1].Value = item.SchoolName; dgvSchools.Rows[i].Cells[2].Value = item.Phone; dgvSchools.Rows[i].Cells[3].Value = item.Address; dgvSchools.Rows[i].Cells[4].Value = item.Id; i++; } } }
private void dgvSchools_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dgvSchools.Columns[e.ColumnIndex].Index == 2) { DialogResult dr = MessageBox.Show(@"Are sou sure you want to delete user?", "Warning", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var user = dgvSchools.Rows[e.RowIndex].Cells[0].Value.ToString(); var checkAll = dbEntities.UserTables; var checkusername = dbEntities.UserTables.SingleOrDefault(x => x.Username.Contains(user)); if (checkusername == null) { MessageBox.Show(@"Could not fetch user"); return; } checkAll.Remove(checkusername); dbEntities.SaveChanges(); MessageBox.Show(@"User Removed"); } return; } } TxtUsername.Text = dgvSchools.Rows[e.RowIndex].Cells[0].Value.ToString(); TxtPhone.Text = dgvSchools.Rows[e.RowIndex].Cells[1].Value.ToString(); }
private void btnExportData_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TxtUsername.Text)) { MessageBox.Show(@"Username is empty"); return; } if (string.IsNullOrEmpty(TxtPhone.Text)) { MessageBox.Show(@"Phone number is empty"); return; } if (string.IsNullOrEmpty(txtOldPassword.Text)) { MessageBox.Show(@"Old password is empty"); return; } if (string.IsNullOrEmpty(txtNewPassword.Text)) { MessageBox.Show(@"New password is empty"); return; } using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var checkusername = dbEntities.UserTables.SingleOrDefault(x => x.Username.Contains(TxtUsername.Text) && x.password.Contains(txtOldPassword.Text)); if (checkusername == null) { MessageBox.Show(@"Old Password Is Incorrect"); return; } checkusername.password = txtOldPassword.Text; checkusername.phone = TxtPhone.Text; dbEntities.SaveChanges(); var getallUsers = dbEntities.UserTables.ToList(); dgvSchools.Rows.Clear(); int i = 0; foreach (UserTable item in getallUsers) { dgvSchools.Rows.Add(); dgvSchools.Rows[i].Cells[0].Value = item.Username; dgvSchools.Rows[i].Cells[1].Value = item.phone; i++; } } }
private void AddUser_Load(object sender, EventArgs e) { pnlAddUserDropdown.Visible = false; this.btnExportData.BackColor = ColorTranslator.FromHtml("#0099cc"); using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var getallUsers = dbEntities.UserTables.ToList(); int i = 0; foreach (UserTable item in getallUsers) { dgvSchools.Rows.Add(); dgvSchools.Rows[i].Cells[0].Value = item.Username; dgvSchools.Rows[i].Cells[1].Value = item.phone; i++; } } }
private void BtnSubmit_Click(object sender, EventArgs e) { using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var getLogin = dbEntities.UserTables.SingleOrDefault(x => x.Username.Contains(TxtLogin.Text) && x.password.Contains(txtPassword.Text)); if (getLogin == null) { MessageBox.Show(@"Wrong Username or password entered"); return; } Role = getLogin.role; Username = getLogin.Username; var fn = new Manager(); fn.Show(); this.Hide(); } }
private void EditUser_Load(object sender, EventArgs e) { if (Login.Role != "Admin") { BtnAddUser.Enabled = false; dgvSchools.Visible = false; } using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var getAllUsers = dbEntities.UserTables.ToList(); dgvSchools.Rows.Clear(); int i = 0; DataGridViewButtonColumn btn = new DataGridViewButtonColumn(); dgvSchools.Columns.Add(btn); btn.HeaderText = "Action"; btn.Text = "Delete User"; btn.Name = "btn"; btn.UseColumnTextForButtonValue = true; foreach (UserTable item in getAllUsers) { if (Login.Username == item.Username) { TxtPhone.Text = item.phone; TxtUsername.Text = item.Username; txtHidden.Text = item.Id.ToString(); } dgvSchools.Rows.Add(); dgvSchools.Rows[i].Cells[0].Value = item.Username; dgvSchools.Rows[i].Cells[1].Value = item.phone; dgvSchools.Rows[i].Cells[2].Value = new Button(); i++; } } pnlAddUserDropdown.Visible = false; this.btnExportData.BackColor = ColorTranslator.FromHtml("#0099cc"); }
private void txtSearchDirectory_TextChanged(object sender, EventArgs e) { using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var getSearchedQuery = (string.IsNullOrEmpty(txtSearchDirectory.Text)) ? dbEntities.SchoolTables.ToList() : dbEntities.SchoolTables.Where(x => x.SchoolName.Contains(txtSearchDirectory.Text)).ToList(); if (getSearchedQuery.Count() != 0) { dgvSchools.Rows.Clear(); int i = 0; foreach (SchoolTable item in getSearchedQuery) { dgvSchools.Rows.Add(); dgvSchools.Rows[i].Cells[0].Value = item.Proprietor; dgvSchools.Rows[i].Cells[1].Value = item.SchoolName; dgvSchools.Rows[i].Cells[2].Value = item.Phone; dgvSchools.Rows[i].Cells[3].Value = item.Address; dgvSchools.Rows[i].Cells[4].Value = item.Id; i++; } } } }
private void btnExportData_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TxtUsername.Text)) { MessageBox.Show(@"Username is empty"); return; } if (string.IsNullOrEmpty(TxtPhone.Text)) { MessageBox.Show(@"Phone number is empty"); return; } if (string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show(@"password is empty"); return; } if (string.IsNullOrEmpty(txtRetypePassword.Text)) { MessageBox.Show(@"retype-password is empty"); return; } if (string.IsNullOrEmpty(CMBRole.SelectedItem.ToString())) { MessageBox.Show(@"User role is empty"); return; } if (txtRetypePassword.Text != txtPassword.Text) { MessageBox.Show(@"Password and retype password does not match"); return; } using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var checkusername = dbEntities.UserTables.Where(x => x.Username.Contains(TxtUsername.Text)); if (checkusername.Count() != 0) { MessageBox.Show(@"Username already exist"); return; } var insertUser = new UserTable() { password = txtPassword.Text, phone = TxtPhone.Text, Username = TxtUsername.Text, role = CMBRole.SelectedItem.ToString(), }; dbEntities.UserTables.Add(insertUser); dbEntities.SaveChanges(); var getallUsers = dbEntities.UserTables.ToList(); dgvSchools.Rows.Clear(); int i = 0; foreach (UserTable item in getallUsers) { dgvSchools.Rows.Add(); dgvSchools.Rows[i].Cells[0].Value = item.Username; dgvSchools.Rows[i].Cells[1].Value = item.phone; i++; } txtPassword.Text = ""; txtRetypePassword.Text = ""; TxtPhone.Text = ""; TxtUsername.Text = ""; CMBRole.Text = ""; } }
private void BtnUpdate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtPhone.Text)) { MessageBox.Show(@"School's Phone number is empty"); return; } if (string.IsNullOrEmpty(txtSchoolName.Text)) { MessageBox.Show(@"School's Name is empty"); return; } if (string.IsNullOrEmpty(TxtAddress.Text)) { MessageBox.Show(@"School's Address is empty"); return; } if (string.IsNullOrEmpty(TxtProperietor.Text)) { MessageBox.Show(@"School's proprietor is empty"); return; } using (AmanyeDbEntities dbEntities = new AmanyeDbEntities()) { var checkSchool = dbEntities.SchoolTables.Where(x => x.SchoolName.Contains(txtSchoolName.Text)); if (string.IsNullOrEmpty(check)) { if (checkSchool.Count() != 0) { MessageBox.Show(@"School already exists"); return; } var insertSchool = new SchoolTable() { Address = TxtAddress.Text, Phone = txtPhone.Text, Proprietor = TxtProperietor.Text, SchoolName = txtSchoolName.Text }; dbEntities.SchoolTables.Add(insertSchool); dbEntities.SaveChanges(); } else { var getASchool = dbEntities.SchoolTables.SingleOrDefault(x => x.Id.ToString() == txtHiddenForSchoolUpdate.Text); getASchool.Address = TxtAddress.Text; getASchool.Phone = txtPhone.Text; getASchool.Proprietor = TxtProperietor.Text; getASchool.SchoolName = txtSchoolName.Text; dbEntities.SaveChanges(); } txtSchoolName.Text = null; txtPhone.Text = null; TxtProperietor.Text = null; TxtAddress.Text = null; check = ""; var getAllSchools = dbEntities.SchoolTables.ToList(); dgvSchools.Rows.Clear(); int i = 0; foreach (SchoolTable item in getAllSchools) { dgvSchools.Rows.Add(); dgvSchools.Rows[i].Cells[0].Value = item.Proprietor; dgvSchools.Rows[i].Cells[1].Value = item.SchoolName; dgvSchools.Rows[i].Cells[2].Value = item.Phone; dgvSchools.Rows[i].Cells[3].Value = item.Address; dgvSchools.Rows[i].Cells[4].Value = item.Id; i++; } } }