/// <summary> /// Event handler for add button click of adding new animal . /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void add_button_Click(object sender, EventArgs e) { try { Add_GPS animalGPSAllocation = new Add_GPS(); DialogResult dialogresult = animalGPSAllocation.ShowDialog(); if (dialogresult == DialogResult.OK) { string animalName = animalGPSAllocation.animalName; int categoryId = animalGPSAllocation.categoryId; string gpsDeviceId = animalGPSAllocation.GPSDeviceId; this.animalDetails.Rows.Add(animalName, gpsDeviceId); this.gps_dataGridView.Refresh(); Models.Animal animalDetails = GetAnimalDetails(animalName, categoryId, gpsDeviceId); AnimalDelegate.AddNewAnimal(animalDetails); dataGrid(); animalGPSAllocation.Dispose(); PopUp popUpBox = new PopUp(Constants.SUCCESSFULL_GPS_ALLOCATION_MESSAGE); popUpBox.ShowDialog(); } } catch (Exception ex) { log.Error(string.Format("Error in allocating the animal with GPS Device {0}", ex.Message)); dataGrid(); PopUp popUp = new PopUp(Constants.ERROR_GPS_ALLOCATION_MESSAGE); popUp.ShowDialog(); } }
/// <summary> /// Event handler for the generate button click. /// It generates charts based on total number of animals per category. /// </summary> /// <param name="sender">Sender Object</param> /// <param name="e">Event argument</param> private void generate_button_Click(object sender, EventArgs e) { reportChart.Series[Constants.COUNT].Points.Clear(); reportChart.Titles.Clear(); if (toDate > DateTime.Now) { PopUp popUP = new PopUp(Constants.TO_DATE_VALIDATION_MESSAGE); popUP.ShowDialog(); } else if (fromDate > toDate && fromDate > DateTime.Now) { PopUp popUP = new PopUp(Constants.FROM_DATE_VALIDATION_MESSAGE); popUP.ShowDialog(); } else { string startDate = fromDate.ToString(Constants.DATE_PICKER_FOMAT); string endDate = toDate.ToString(Constants.DATE_PICKER_FOMAT); List <Models.AnimalCategoryCount> animals = AnimalDelegate.GetAnimalsCountPerCategory(startDate, endDate); int i = 0; foreach (Models.AnimalCategoryCount animal in animals) { reportChart.Series[Constants.COUNT].Points.AddXY(animal.categoryName, animal.totalAnimals); Color color = ColorTranslator.FromHtml(animal.colorIndication); reportChart.Series[Constants.COUNT].Points[i].Color = color; i++; } reportChart.Titles.Add(Constants.COUNT_OF_ALL_THE_ANIMALS_PER_CATEGORY); } }
/// <summary> /// Collects categroy details and saves as a datatable. /// </summary> /// <returns>Returns category data as datatable</returns> private DataTable getAllAnimalList() { animalDetails = new DataTable(); try { this.allAnimalsLocated = AnimalDelegate.GetAllAnimalsAllocated(); animalDetails.Columns.Add("Category Name", typeof(string)); animalDetails.Columns.Add("Animal Name", typeof(string)); animalDetails.Columns.Add("GPS Device Id", typeof(string)); foreach (Models.Animal animal in allAnimalsLocated) { animalDetails.Rows.Add(animal.categoryName, animal.animalName, animal.gpsDeviceId); } return(animalDetails); } catch (Exception ex) { log.Error(string.Format("Error in getting the Reposiory details from server {0}", ex.Message)); return(animalDetails); } }
/// <summary> /// Event handler for delete button click. /// </summary> /// <param name="sender">Sender Object</param> /// <param name="e">Event argument</param> private void delete_button_Click(object sender, EventArgs e) { try { selectedRow = this.gps_dataGridView.CurrentRow.Index; Models.Animal animalToBeDeleted = allAnimalsLocated[selectedRow]; Models.Animal deletedItem = AnimalDelegate.DeleteAnimal(animalToBeDeleted.animalId); if (deletedItem != null) { this.gps_dataGridView.Rows.RemoveAt(selectedRow); this.gps_dataGridView.Refresh(); dataGrid(); } PopUp popUpBox = new PopUp(Constants.SUCCESSFUL_ANIMAL_DELETING_MESSAGE); popUpBox.ShowDialog(); } catch (Exception ex) { PopUp popUpBox = new PopUp(Constants.ERROR_ANIMAL_DELETING_MESSAGE); popUpBox.ShowDialog(); log.Error(string.Format("Error in delete animal from server {0}", ex.Message)); this.SuspendLayout(); } }