// 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"); } }
// Redirect to the home page or initialise page before it is presented to the User protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { // Redirect User if they do not have permission to view this page Security.RedirectIfNoQueryString(); int?batchId = BatteryService.GetBatchId(); int?userId = BatchService.GetUserId(batchId); Security.RedirectIfUserIdMismatch(userId); Security.RedirectIfIsGuest(); // Populate the page with entity data PopulatePage(); // Display Success/Error message on page if appropriate DisplayMessage(); } }