private void button8_Click(object sender, EventArgs e) { try { double reading1 = Double.Parse(textBox24.Text); double reading2 = Double.Parse(textBox23.Text); double estimatedReading; DateTime date1 = DateTime.Parse(dateTimePicker1.Text); DateTime date2 = DateTime.Parse(dateTimePicker2.Text); DateTime dateEstimation = DateTime.Parse(dateTimePicker3.Text); Estimation estimare = new Estimation(reading1, reading2, date1, date2, dateEstimation); estimare.averageDayConsumption(); estimare.averageDayConsumptionAtReset(); estimare.dateReset(); if (estimare.averageDayConsumption() < 0) // if a meter reset exists and it resets at value 99999 { if (((estimare.dateReset() - dateEstimation).TotalDays) < ((dateEstimation - date1).TotalDays)) // estimate date after meter reset date { estimatedReading = 99999 - (estimare.dateReset() - dateEstimation).TotalDays * estimare.averageDayConsumptionAtReset(); if (estimatedReading > 99999) { label45.Text = (estimatedReading - 99999).ToString(); label46.Text = (estimare.averageDayConsumptionAtReset() * 365).ToString(); label47.Text = estimare.dateReset().ToShortDateString(); } else { label45.Text = String.Format("{0:0.00}", estimatedReading); label46.Text = String.Format("{0:0.00}", (estimare.averageDayConsumptionAtReset() * 365)); label47.Text = estimare.dateReset().ToShortDateString(); } } else if (((estimare.dateReset() - dateEstimation).TotalDays) > ((dateEstimation - date1).TotalDays)) // estimate date before meter reset { estimatedReading = 99999 - (estimare.dateReset() - dateEstimation).TotalDays * estimare.averageDayConsumptionAtReset(); if (estimatedReading > 99999) { label45.Text = String.Format("{0:0.00}", (estimatedReading - 99999)); label46.Text = String.Format("{0:0.00}", (estimare.averageDayConsumptionAtReset() * 365)); label47.Text = estimare.dateReset().ToShortDateString(); } else { label45.Text = String.Format("{0:0.00}", estimatedReading); label46.Text = String.Format("{0:0.00}", (estimare.averageDayConsumptionAtReset() * 365)); label47.Text = estimare.dateReset().ToShortDateString(); } } } else // when there is no meter reset { if (((dateEstimation - date2).TotalDays) < ((dateEstimation - date1).TotalDays)) { estimatedReading = reading2 + ((dateEstimation - date2).TotalDays) * estimare.averageDayConsumption(); label45.Text = String.Format("{0:0.00}", estimatedReading); label46.Text = String.Format("{0:0.00}", (estimare.averageDayConsumption() * 365)); } else if (((dateEstimation - date2).TotalDays) > ((dateEstimation - date1).TotalDays)) { estimatedReading = reading1 - ((date1 - dateEstimation).TotalDays) * estimare.averageDayConsumption(); label45.Text = String.Format("{0:0.00}", estimatedReading); label46.Text = String.Format("{0:0.00}", (estimare.averageDayConsumption() * 365)); } else if (((date2 - dateEstimation).TotalDays) < ((dateEstimation - date1).TotalDays)) { estimatedReading = reading2 - ((date2 - dateEstimation).TotalDays) * estimare.averageDayConsumption(); label45.Text = String.Format("{0:0.00}", estimatedReading); label46.Text = String.Format("{0:0.00}", (estimare.averageDayConsumption() * 365)); } else if (((date2 - dateEstimation).TotalDays) > ((dateEstimation - date1).TotalDays)) { estimatedReading = reading1 + ((dateEstimation - date1).TotalDays) * estimare.averageDayConsumption(); label45.Text = String.Format("{0:0.00}", estimatedReading); label46.Text = String.Format("{0:0.00}", (estimare.averageDayConsumption() * 365)); } } } catch (FormatException) { MessageBox.Show("You must enter numbers only! Please try again!"); } }