/// <summary>
        /// March 12 - Made as test for updation
        /// </summary>
        public void Update()
        {
            try
            {
                medicalRecordHandler = new AnimalMedicalRecordsHandler();
                List <AnimalMedicalRecord> updatedList = dataGrid.Items.OfType <AnimalMedicalRecord>().ToList();

                foreach (AnimalMedicalRecord record in updatedList)
                {
                    medicalRecordHandler.Update(record);
                }
            }
            catch (Exception exp)
            {
                MessageBoxResult result = MessageBox.Show(exp.Message,
                                                          "Do you want to correct it or Restore to the original content?",
                                                          MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    return;
                }
                else
                {
                    Refresh();
                }


                return;
            }
        }
예제 #2
0
        public void Save()
        {
            medicalHandler = new AnimalMedicalRecordsHandler();

            AnimalMedicalRecord medicalRecord = new AnimalMedicalRecord();

            #region Validation for valid Milking data

            //Check if all text boxes are empty

            IEnumerable <TextBox>  textBoxcollection  = EntryGrid.Children.OfType <TextBox>();
            IEnumerable <ComboBox> comboBoxcollection = EntryGrid.Children.OfType <ComboBox>();

            foreach (TextBox box in textBoxcollection)
            {
                if (box.Name == "textBoxComments")
                {
                    //ignore
                }

                else
                {
                    if (string.IsNullOrWhiteSpace(box.Text))
                    {
                        MessageBox.Show("Kindly Fill all the boxes.");
                        return;
                    }
                }
            }

            foreach (ComboBox box in comboBoxcollection)
            {
                if (box.SelectedIndex == -1)
                {
                    MessageBox.Show("Kindly Select the animal");
                    return;
                }
            }


            #endregion

            try
            {
                //Inserting values in Object

                medicalRecord.EntryDate = DateTime.Now;

                Cattle illCattle = new Cattle();

                illCattle.ID    = ((Cattle)tagNoComboBox.SelectedItem).ID;
                illCattle.TagNo = ((Cattle)tagNoComboBox.SelectedItem).TagNo;

                medicalRecord.IllAnimal = illCattle;

                medicalRecord.Diagnosis = textBoxDiagnosis.Text;
                medicalRecord.Prognosis = textBoxPrognosis.Text;
                medicalRecord.Treatment = textBoxTreatment.Text;

                medicalHandler.Insert(medicalRecord);
            }

            catch (ArgumentException exc)
            {
                MessageBox.Show(exc.Message, "Error!");
                return;
            }

            //Clear all the TextBoxes

            foreach (TextBox box in textBoxcollection)
            {
                box.Text = "";
            }

            foreach (ComboBox box in comboBoxcollection)
            {
                box.SelectedIndex = -1;
            }

            //Commented on March - 12 Talha

            //MessageBox.Show("Successfully Saved!");

            //Window mainwin = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);

            //mainwin.Activate();
        }
 /// <summary>
 /// Added on March 18
 /// </summary>
 /// <param name="col">Column Name</param>
 /// <param name="param">Column Value</param>
 public void ShowFilteredList(string col, string param)
 {
     medicalRecordHandler = new AnimalMedicalRecordsHandler();
     dataGrid.ItemsSource = medicalRecordHandler.GetAnimalMedicalRecords(col, param);
 }
        public void Refresh()
        {
            medicalRecordHandler = new AnimalMedicalRecordsHandler();

            dataGrid.ItemsSource = medicalRecordHandler.GetAnimalMedicalRecords();
        }