Esempio n. 1
0
 private void btnChangeInfo_Click(object sender, EventArgs e)
 {
     if (txtPassword.Text.Equals(""))
     {
         MessageBox.Show("Password must not be blank");
     }
     else
     {
         if (dgvUserList.SelectedRows.Count == 0)
         {
             MessageBox.Show("Select a user to edit");
         }
         else
         {
             //Grid is layed out as id-email-username
             int  id = (int)dgvUserList.SelectedRows[0].Cells[0].Value;
             User u  = ProgramMain.currentUser;
             u.email    = txtEmail.Text;
             u.password = txtPassword.Text;
             u.username = txtUsername.Text;
             u.id       = id;
             if (WebHandeler.updateUser(u) == 1)
             {
                 MessageBox.Show("Update successful!");
             }
         }
     }
 }
Esempio n. 2
0
        public void updateGrid()
        {
            dgvUserList.Rows.Clear();
            if (isAdmin)
            {
                Tuple <List <User>, int> response = WebHandeler.getAllUsers(ProgramMain.currentUser.shelter_id);
                if (response.Item2 == 1)
                {
                    List <User> users = response.Item1;

                    foreach (User u in users)
                    {
                        dgvUserList.Rows.Add(u.id, u.email, u.username);
                    }
                }
                else if (response.Item2 == -1)
                {
                    MessageBox.Show("Error getting users");
                }
                else if (response.Item2 == -2)
                {
                    MessageBox.Show("Could not connect to server");
                }
            }
            else
            {
                User u = ProgramMain.currentUser;
                dgvUserList.Rows.Add(u.id, u.email, u.username);
            }
        }
Esempio n. 3
0
 private void btnCreateUser_Click(object sender, EventArgs e)
 {
     if (areFieldsBlank())
     {
         MessageBox.Show("Username, Password, and Email must not be blank");
     }
     else
     {
         User u = new User();
         u.email      = txtEmail.Text;
         u.password   = txtPassword.Text;
         u.username   = txtUsername.Text;
         u.shelter_id = ProgramMain.currentUser.shelter_id;
         //  MessageBox.Show("User: "******"    Current User:"******"User creation successful");
             updateGrid();
         }
         else
         {
             MessageBox.Show("User creation failed.");
         }
     }
 }
Esempio n. 4
0
        private void btnDeleteUser_Click(object sender, EventArgs e)
        {
            if (dgvUserList.SelectedRows.Count == 0)
            {
                MessageBox.Show("Select a user to delete");
            }
            else
            {
                //Grid is layed out as id-email-username
                int id = (int)dgvUserList.SelectedRows[0].Cells[0].Value;
                if (id == ProgramMain.currentUser.id)
                {
                    MessageBox.Show("Cannot delete current user");
                    return;
                }
                string username = (string)dgvUserList.SelectedRows[0].Cells[2].Value;

                DialogResult result = MessageBox.Show("Do you want to delete user " + username, "Confirmation", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    WebHandeler.deleteUsers(id);
                    btnRefresh_Click(sender, e);
                }
            }
        }
Esempio n. 5
0
 public AdminForm()
 {
     InitializeComponent();
     isAdmin = WebHandeler.isUserAdmin(ProgramMain.currentUser);
     btnDeleteUser.Enabled = isAdmin;
     btnCreateUser.Enabled = isAdmin;
 }
Esempio n. 6
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Tuple <User, int> response = WebHandeler.verifyUser(txtUsername.Text, txtPassword.Text);

            //checks if the user successfully logged in
            if (response.Item2 == -1)
            {
                MessageBox.Show("Incorrect Login");
            }
            else if (response.Item2 == -2)
            {
                MessageBox.Show("Could not connect to server");
            }
            //allows user to enter the application on successful login
            else if (response.Item2 == 1)
            {
                ProgramMain.currentUser = response.Item1;
                this.Hide();
                AnimalListForm switchTo = new AnimalListForm();
                switchTo.ShowDialog();
                this.Close();
            }
            else
            {
                MessageBox.Show("An unidentified error has occured");
            }
        }
Esempio n. 7
0
        //redirects to AddEditForm
        private void btnEdit_Click(object sender, EventArgs e)
        {
            using (AddEditForm editForm = new AddEditForm(animal))
            {
                editForm.ShowDialog();
            }

            animal = WebHandeler.getAnimal(animal.id).Item1;
            AnimalForm_Load(sender, e);
        }
Esempio n. 8
0
 //redirects to picture upload
 private void pnlProfilePic_Click(object sender, EventArgs e)
 {
     using (UploadImageForm uploadForm = new UploadImageForm(false))
     {
         if (uploadForm.ShowDialog() == DialogResult.OK)
         {
             string fname = uploadForm.filename;
             WebHandeler.addPicture(fname, animal.id);
         }
     }
 }
Esempio n. 9
0
        /*
         *  When any cell containing an animal is selected
         */
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            Tuple <Animal, int> selectedAnimal = WebHandeler.getAnimal((int)dgvAnimalList.Rows[e.RowIndex].Cells[0].Value);

            if (selectedAnimal == null)
            {
                return;
            }
            AnimalDetailForm detailForm = new AnimalDetailForm(selectedAnimal.Item1);

            detailForm.ShowDialog();
        }
Esempio n. 10
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            animal.name        = txtName.Text;
            animal.age         = dtpBirthday.Value.Date;
            animal.breed       = txtBreed.Text;
            animal.animal_type = txtAnimalType.Text;
            int temp;

            if (int.TryParse(txtWeight.Text, out temp))
            {
                animal.weight = temp;
            }
            else
            {
                if (temp != 0)
                {
                    MessageBox.Show("Weight must be a whole number");
                }
            }
            animal.size  = cboSize.Text;
            animal.notes = txtNotes.Text;
            if (newAnimal)
            {
                animal.shelter_id = ProgramMain.currentUser.shelter_id;
                if (WebHandeler.addPet(animal) == 1)
                {
                    MessageBox.Show("Pet Added!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("There was a problem adding the pet.");
                }
            }
            else
            {
                if (WebHandeler.updatePet(animal) == 1)
                {
                    MessageBox.Show("Pet updated!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("There was a problem updating this animal.");
                }
            }
        }
Esempio n. 11
0
        private void AnimalListForm_Load(object sender, EventArgs e)
        {
            dgvAnimalList.Rows.Clear();
            User curUser = ProgramMain.currentUser;
            Tuple <List <Animal>, int> result = WebHandeler.getAllAnimals(curUser.shelter_id);
            List <Animal> animalList          = result.Item1;

            foreach (Animal animal in animalList)
            {
                //checks if the picture is set
                if (WebHandeler.getPicture(animal.id).Item2 != -1)
                {
                    dgvAnimalList.Rows.Add(animal.id, animal.name, WebHandeler.getPicture(animal.id).Item1);
                }
                else
                {
                    MessageBox.Show("Error showing picture");
                }
            }
        }
Esempio n. 12
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     WebHandeler.deleteAnimal(animal.id);
     this.Close();
 }