public bool UpdateCompensation() { //Update bool result = false; try { //Updated routes DriverCompDataset driverRoutes = (DriverCompDataset)this.mCompensation.GetChanges(DataRowState.Modified); if (driverRoutes != null && driverRoutes.DriverRouteTable.Rows.Count > 0) { //Update all modified driver compensations foreach (DriverCompDataset.DriverRouteTableRow driverRoute in driverRoutes.DriverRouteTable.Rows) { try { driverRoute.LastUpdated = DateTime.Now; driverRoute.UserID = Environment.UserName; result = FinanceGateway.UpdateDriverRoute(driverRoute); if (result) { driverRoute.AcceptChanges(); } else { driverRoute.RejectChanges(); } } catch (Exception) { driverRoute.RejectChanges(); System.Windows.Forms.MessageBox.Show("Failed to update route (" + driverRoute.RouteDate.ToShortDateString() + ", " + driverRoute.Operator, "Route Update", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } } //Deleted routes- need to re-assess fees and bonus driverRoutes = (DriverCompDataset)this.mCompensation.GetChanges(DataRowState.Deleted); if (driverRoutes != null && driverRoutes.DriverRouteTable.Rows.Count > 0) { //Delete all deleted driverRoutes DriverCompDataset.DriverRouteTableRow driverRoute = null; for (int i = driverRoutes.DriverRouteTable.Rows.Count - 1; i >= 0; i--) { try { driverRoute = (DriverCompDataset.DriverRouteTableRow)driverRoutes.DriverRouteTable.Rows[i]; driverRoute.RejectChanges(); if (!driverRoute.IsImportedNull()) { result = FinanceGateway.DeleteDriverRoute(driverRoute.ID); } else { result = true; } if (result) { driverRoute.Delete(); driverRoute.AcceptChanges(); } } catch (Exception) { System.Windows.Forms.MessageBox.Show("Failed to update route (" + driverRoute.RouteDate.ToShortDateString() + ", " + driverRoute.Operator, "Route Update", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } } this.mCompensation.AcceptChanges(); ImportRoutes(); } catch (Exception ex) { this.mCompensation.RejectChanges(); throw new ApplicationException(ex.Message, ex); } return(result); }