Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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++;
                }
            }
        }
Ejemplo n.º 3
0
        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           = "";
            }
        }
Ejemplo n.º 4
0
        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++;
                }
            }
        }