private void RecordsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var viewModel = DataContext as RecordManagerViewModel;

            if (viewModel.ViewMethod.Id == 1)
            {
                // It's in a monthly view.
                // Can't show detail panel.
                viewModel.ID             = -1;
                AnalyzerPanel.Visibility = Visibility.Collapsed;
                return;
            }

            var SelectedItem = RecordsListBox.SelectedItem as RecordViewModel;

            if (SelectedItem != null)
            {
                AnalyzerPanel.Visibility = Visibility.Visible;
                SaveButton.Visibility    = Visibility.Collapsed;

                viewModel.Record = SelectedItem;

                viewModel.ID           = SelectedItem.Id;
                viewModel.PH           = SelectedItem.PH;
                viewModel.DO           = SelectedItem.DO;
                viewModel.BOD5         = SelectedItem.BOD5;
                viewModel.COD          = SelectedItem.COD;
                viewModel.NH4N         = SelectedItem.NH4N;
                viewModel.NO2N         = SelectedItem.NO2N;
                viewModel.NO3N         = SelectedItem.NO3N;
                viewModel.SS           = SelectedItem.SS;
                viewModel.CL           = SelectedItem.CL;
                viewModel.CB           = SelectedItem.CB;
                viewModel.OverallIndex = SelectedItem.Overall;
                viewModel.Level        = SelectedItem.Level;
                viewModel.Date         = DateTime.Parse(SelectedItem.DateTime);

                Reservoir selectedReservoir = null;
                for (int i = 0; i < viewModel.Reservoirs.Count; i++)
                {
                    if (viewModel.Reservoirs[i].Id == SelectedItem.ReservoirId)
                    {
                        selectedReservoir = viewModel.Reservoirs[i];
                        break;
                    }
                }
                viewModel.Reservoir = selectedReservoir;

                OxygenDOViewModel selectedTemperatureRange = null;
                for (int i = 0; i < viewModel.TemperatureRange.Count; i++)
                {
                    if (viewModel.TemperatureRange[i].Temperature == SelectedItem.Temperature)
                    {
                        selectedTemperatureRange = viewModel.TemperatureRange[i];
                        break;
                    }
                }
                viewModel.Temperature = selectedTemperatureRange;
                viewModel.Explanation = Utility.GetExplanationsForLevels()[int.Parse(SelectedItem.Level)];
            }
            else
            {
                viewModel.ID             = -1;
                AnalyzerPanel.Visibility = Visibility.Collapsed;
            }
        }
        private async void Analyze_OnClick(object sender, RoutedEventArgs e)
        {
            var viewModel = DataContext as RecordManagerViewModel;

            if (analyzing == true)
            {
                // It's analyzing another data.
                // Please wait.
                viewModel.ShowMessageCommand.Execute("Please wait...");
                return;
            }

            Reservoir selectedReservoir = viewModel.Reservoir;

            if (selectedReservoir == null)
            {
                viewModel.ShowMessageCommand.Execute("Please choose a reservoir");
                return;
            }

            OxygenDOViewModel selectedTemperature = viewModel.Temperature;

            if (selectedTemperature == null)
            {
                viewModel.ShowMessageCommand.Execute("Please choose a temperature range");
                return;
            }

            if (TextPH.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for PH");
                return;
            }
            double PH = double.Parse(TextPH.Text);

            if (TextDO.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for DO");
                return;
            }
            double DO = double.Parse(TextDO.Text);

            if (TextBOD5.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for BOD5");
                return;
            }
            double BOD5 = double.Parse(TextBOD5.Text);

            if (TextCOD.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for COD");
                return;
            }
            double COD = double.Parse(TextCOD.Text);

            if (TextNH4N.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for NH4-N");
                return;
            }
            double NH4N = double.Parse(TextNH4N.Text);

            if (TextNO2N.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for NO2-N");
                return;
            }
            double NO2N = double.Parse(TextNO2N.Text);

            if (TextNO3N.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for NO3-N");
                return;
            }
            double NO3N = double.Parse(TextNO3N.Text);

            if (TextSS.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for SS");
                return;
            }
            double SS = double.Parse(TextSS.Text);

            if (TextCL.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for CL");
                return;
            }
            double CL = double.Parse(TextCL.Text);

            if (TextCB.Text == "")
            {
                viewModel.ShowMessageCommand.Execute("Please input a value for CB");
                return;
            }
            double CB = double.Parse(TextCB.Text);

            // All validations passed
            analyzed  = false;
            analyzing = true;
            await Task.Run(() => this.AnalyzeData(selectedTemperature.Temperature, PH, DO, BOD5, COD, NH4N, NO2N, NO3N, SS, CL, CB));

            analyzing = false;

            viewModel.OverallIndex = OverallIndex.ToString("F5");
            viewModel.Level        = Level.ToString("D");
            viewModel.Explanation  = Utility.GetExplanationsForLevels()[Level];
            analyzed = true;

            viewModel.PH   = TextPH.Text;
            viewModel.DO   = TextDO.Text;
            viewModel.BOD5 = TextBOD5.Text;
            viewModel.COD  = TextCOD.Text;
            viewModel.NH4N = TextNH4N.Text;
            viewModel.NO2N = TextNO2N.Text;
            viewModel.NO3N = TextNO3N.Text;
            viewModel.SS   = TextSS.Text;
            viewModel.CL   = TextCL.Text;
            viewModel.CB   = TextCB.Text;

            SaveButton.Visibility = Visibility.Visible;
        }