Exemple #1
0
        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];
        }