private void btnDeleteDetails_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Are you sure want to Delete this animal", "Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { db.DeleteAnimal(animal); HomePanel.Show(); AnmDetailsPanel.Hide(); MessageBox.Show("Animal successfully deleted"); } else { AnmDetailsPanel.Show(); } }
private void btnUpdateDetails_Click(object sender, EventArgs e) { try { animal.setDateBrought(Convert.ToString(dtpDateBroughtDetails.Value)); animal.setDescription(tbDescriptionDetails.Text); animal.setLocationFound(tbLocationFoundDetails.Text); if (tbOwnersIdDetails.Text != string.Empty) { int po_id = Convert.ToInt32(tbOwnersIdDetails.Text); try { po = db.getOwnerById(po_id); } catch (Exception err) { MessageBox.Show("Can't find previous owner: " + err.ToString()); } } else { po = null; } animal.setOwner(po); if (animal.GetType() == typeof(Dog)) { Dog dog = (Dog)animal; dog.setLastWalked(dtpLastWalkedDetails.Value); } else if (animal.GetType() == typeof(Cat)) { Cat cat = (Cat)animal; cat.setExtra(tbExtraDetails.Text); } db.updateAnimal(animal); MessageBox.Show("Animal successfully updated"); AnmDetailsPanel.Hide(); HomePanel.Show(); } catch (Exception er) { MessageBox.Show(er.ToString()); } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { Int32 selectedCellCount = dataGridView1.GetCellCount(DataGridViewElementStates.Selected); if (selectedCellCount > 0) { if (dataGridView1.AreAllCellsSelected(true)) { MessageBox.Show("All cells are selected", "Selected Cells"); } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < selectedCellCount; i++) { //an attributes to know which part we selecting string condition = dataGridView1.SelectedCells[i].Value .ToString(); //this is an attribute for getting the value of rfid string rfidselected = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); //We need to create an attribute for identifying what species is our animal string species = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); //Now time for creating the Adopt and Claim function in Database MessageBox.Show(rfidselected + " , " + species); if (species == "cat") { animal = db.getCatByRFID(rfidselected); } else if (species == "dog") { animal = db.getDogByRFID(rfidselected); } if (condition == "Claim") { // if the animal is in the shelter since less than 20 days and have a PO if (animal.calculateDays() < 20 && animal.getPoId() != 0) { // TODO put the informations of animal in the good variables (textbox) // TODO the same with owner (use animal.getPo() to retrieve the owner) AnimalsPanel.Hide(); ClaimPanel.Show(); //Animal tbRfidClaim.Text = animal.getRfid(); tbSpeciesClaim.Text = species; dtpClaim.Value = animal.getDateBrought(); tbLocationClaim.Text = animal.getLocationFound(); tbPoClaim.Text = Convert.ToString(animal.getPoId()); tbFee.Text = Convert.ToString(db.calculateClaimFee(animal)); tbTotalDays.Text = Convert.ToString(animal.calculateDays()); po = db.getOwnerById(animal.getPoId()); //Owner tbOwnerIdClaim.Text = Convert.ToString(po.getOwnerId()); tbLNameClaim.Text = po.getLastName(); tbFNameClaim.Text = po.getFirstName(); tbAddressClaim.Text = po.getAddress(); tbPhoneClaim.Text = Convert.ToString(po.getPhoneOwner()); dtpDobClaim.Value = Convert.ToDateTime(po.getDob()); if (species == "cat") { Cat cat = db.getCatByRFID(rfidselected); tbExtraClaim.Text = cat.getExtra(); } else if (species == "dog") { Dog dog = db.getDogByRFID(rfidselected); tbExtraClaim.Text = dog.getLastWalked(); } } else { MessageBox.Show("Can't claim this animal"); } } else if (condition == "Adopt") { if (species == "cat") { Cat cat = db.getCatByRFID(rfidselected); tbExtraAdopt.Text = cat.getExtra(); } tbDateBroughtAdopt.Text = Convert.ToString(animal.getDateBrought()); tbRfidAdopt.Text = animal.getRfid(); tbSpeciesAdopt.Text = species; tbDescriptionAdopt.Text = animal.getDescription(); tbLocationFoundAdopt.Text = animal.getLocationFound(); tbFeeAdopt.Text = Convert.ToString(db.calculateAdoptFee(animal)); AnimalsPanel.Hide(); AdoptPanel.Show(); //This method will continue to Adopt and showing the overview of animal } else if (condition == "Details") { AnimalsPanel.Hide(); AnmDetailsPanel.Show(); dtpDateBroughtDetails.Text = Convert.ToString(animal.getDateBrought()); tbRfidDetails.Text = animal.getRfid(); cbSpeciesDetails.Text = species; tbStatusDetails.Text = animal.getStatusAsString(); tbDescriptionDetails.Text = animal.getDescription(); tbLocationFoundDetails.Text = animal.getLocationFound(); tbOwnersIdDetails.Text = Convert.ToString(animal.getPoId()); if (species == "cat") { Cat cat = db.getCatByRFID(rfidselected); tbExtraDetails.Text = cat.getExtra(); } else if (species == "dog") { Dog dog = db.getDogByRFID(rfidselected); dtpLastWalkedDetails.Text = dog.getLastWalked(); } } condition = ""; rfidselected = ""; species = ""; } } } selectedCellCount = 0; dataGridView1.ClearSelection(); dataGridView1.CurrentCell = dataGridView1[0, 0]; }