コード例 #1
0
        private void tbViewAnimals_Click(object sender, EventArgs e)
        {
            //todo make sure the animals are loaded
            AnimalsPanel.Show();
            // everytime we show the list we update the status
            db.updateStatus();
            //this is the method for showing All the animals
            ds = db.getAllAnimals();
            dataGridView1.DataSource            = ds.Tables[0];
            dataGridView1.Columns[1].Width      = 80;
            dataGridView1.Columns[1].HeaderText = "Species";
            dataGridView1.Columns[2].Width      = 80;
            dataGridView1.Columns[2].HeaderText = "Status";
            dataGridView1.AutoSizeColumnsMode   = DataGridViewAutoSizeColumnsMode.Fill;

            //this is for fixing bugs
            //if (dataGridView1.Columns[3].Index == 0 && dataGridView1.Columns[4].Index == 0)
            if (dataGridView1.ColumnCount < 4)
            {
                DataGridViewButtonColumn claimButton = new DataGridViewButtonColumn();
                claimButton.HeaderText = "Claim";
                claimButton.Text       = "Claim";
                claimButton.UseColumnTextForButtonValue = true;
                claimButton.Width = 50;
                dataGridView1.Columns.Add(claimButton);


                DataGridViewButtonColumn adoptButton = new DataGridViewButtonColumn();
                adoptButton.HeaderText = "Adopt";
                adoptButton.Text       = "Adopt";
                adoptButton.UseColumnTextForButtonValue = true;
                adoptButton.Width = 50;
                dataGridView1.Columns.Add(adoptButton);

                DataGridViewButtonColumn detailsButton = new DataGridViewButtonColumn();
                detailsButton.HeaderText = "Details";
                detailsButton.Text       = "Details";
                detailsButton.UseColumnTextForButtonValue = true;
                detailsButton.Width = 50;
                dataGridView1.Columns.Add(detailsButton);
            }
        }
コード例 #2
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];
        }