// Populate the page with entity data
        private void PopulatePage()
        {
            int batteryId = 0;

            try
            {
                // Get object from BatteryApi
                batteryId = Int32.Parse(Security.GetQueryString());
                BatteryDto battery = BatteryService.GetBattery(batteryId);

                BatteryReferenceTb.Text  = battery.Battery_Ref;
                CycleIndexTb.Text        = battery.Cycle_Index.ToString();
                ChargeCapacityTb.Text    = battery.Charge_Capacity.ToString();
                DischargeCapacityTb.Text = battery.Discharge_Capacity.ToString();
                ChargeEnergyTb.Text      = battery.Charge_Energy.ToString();
                DischargeEnergyTb.Text   = battery.Discharge_Energy.ToString();
                dvdtTb.Text = battery.dvdt.ToString();
                InternalResistanceTb.Text = battery.Internal_Resistance.ToString();
            }
            catch
            {
                // ERROR - User contained invalid data
                Response.Redirect("BatteryDetail?Id{" + batteryId + "}&message=DatabaseError");
            }
        }
        // Update Battery in the database
        protected void UpdateBtn_Click(object sender, EventArgs e)
        {
            // Create Battery Object
            int        batteryId = Int32.Parse(Security.GetQueryString());
            BatteryDto battery   = BatteryService.GetBattery(batteryId);

            battery.Battery_Ref        = BatteryReferenceTb.Text;
            battery.Cycle_Index        = Int32.Parse(CycleIndexTb.Text);
            battery.Charge_Capacity    = Double.Parse(ChargeCapacityTb.Text);
            battery.Discharge_Capacity = Double.Parse(DischargeCapacityTb.Text);
            battery.Charge_Energy      = Double.Parse(ChargeEnergyTb.Text);
            battery.Discharge_Energy   = Double.Parse(DischargeEnergyTb.Text);
            battery.dvdt = Double.Parse(dvdtTb.Text);
            battery.Internal_Resistance = Double.Parse(InternalResistanceTb.Text);
            battery.BatchId             = Int32.Parse(BatteryService.GetBatchId().ToString());
            battery.Lifetime            = null;

            // update in database
            if (BatteryService.UpdateBattery(battery))
            {
                Response.Redirect("Default.aspx?message=BatteryUpdateSuccess");
            }
            else
            {
                Response.Redirect("BatteryDetail.aspx?id=" + batteryId + "&message=UpdateError");
            }
        }
        // Predict the remaining lifetime for a Battery in the gridview
        protected void PredictLB_Command(object sender, CommandEventArgs e)
        {
            int batchId = Int32.Parse(Security.GetQueryString());

            // Get batteryId
            int batteryId = 0;

            try
            {
                batteryId = Int32.Parse(e.CommandArgument.ToString());
            }
            catch
            {
                Response.Redirect("BatchDetail.aspx?id=" + batchId + "&message=IdError");
            }

            // Get prediction
            double prediction = 0;

            try
            {
                prediction = Double.Parse(PredictService.Single(batteryId).ToString());
            }
            catch
            {
                Response.Redirect("BatchDetail.aspx?id=" + batchId + "&message=PredictionError");
            }

            // Update battery in database
            BatteryDto battery = BatteryService.GetBattery(batteryId);

            battery.Lifetime = prediction;

            if (BatteryService.UpdateBattery(battery))
            {
                Response.Redirect("BatchDetail.aspx?id=" + batchId + "&message=PredictionSuccess");
            }
            else
            {
                Response.Redirect("BatchDetail.aspx?id=" + batchId + "&message=UpdateError");
            }
        }