예제 #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!");
             }
         }
     }
 }
예제 #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);
            }
        }
예제 #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.");
         }
     }
 }
예제 #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);
                }
            }
        }
예제 #5
0
 public AdminForm()
 {
     InitializeComponent();
     isAdmin = WebHandeler.isUserAdmin(ProgramMain.currentUser);
     btnDeleteUser.Enabled = isAdmin;
     btnCreateUser.Enabled = isAdmin;
 }
예제 #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");
            }
        }
예제 #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);
        }
예제 #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);
         }
     }
 }
예제 #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();
        }
예제 #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.");
                }
            }
        }
예제 #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");
                }
            }
        }
예제 #12
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     WebHandeler.deleteAnimal(animal.id);
     this.Close();
 }