// Creates a new Route Session public static long NewRoutingSession(DailyRoutingSession dailyRoutingSession) { try { // Call the Web Services SaveResult[] saveResults = RoutingServiceClient.Save( SessionHeader, RegionContext, new AggregateRootEntity[] { dailyRoutingSession }, new SaveOptions { InclusionMode = PropertyInclusionMode.All }); if (saveResults[0].Error != null) // Error creating the New Route Session { throw new Exception(saveResults[0].Error.Code.ErrorCode_Status); } return(saveResults[0].EntityKey); // New Route Session created } catch (Exception Ex) { throw new Exception(Ex.Message); } }
// Creates a new route session private void button8_Click(object sender, EventArgs e) { if (Region_EntityKey > 0) { // Capture the next day date to be use as default name DateTime now = DateTime.Now; if (now.DayOfWeek == System.DayOfWeek.Friday) { now = now.AddDays(3); // Next week } else { now = now.AddDays(1); // Next day } now.AddDays(1); // Next day string r = String.Format("{0:0000}", now.Year) + "-" + String.Format("{0:00}", now.Month) + "-" + String.Format("{0:00}", (now.Day)); // Visual Basic Interop - No Input Call in C# r = Interaction.InputBox("Inform or confirm the new route session date:", "New Route Session", r, -1, -1); if (r.Trim().Length > 0) // OK Button { // Converts the result string into a system date time DateTime d = Convert.ToDateTime(r); // Create the Dauly Rouse Session object DailyRoutingSession newRouteSession = new DailyRoutingSession(); // Load the Route Session information into the object newRouteSession.Action = ActionType.Add; newRouteSession.CreatedBy = ConfigurationManager.AppSettings["Login"]; newRouteSession.Description = "Created by RNA WebSerives Tool on " + d.ToShortDateString(); newRouteSession.NumberOfTimeUnits = 1; newRouteSession.RegionEntityKey = Region_EntityKey; newRouteSession.SessionMode_Mode = Enum.GetName(typeof(SessionMode), SessionMode.Operational); newRouteSession.StartDate = r; newRouteSession.TimeUnit_TimeUnitType = Enum.GetName(typeof(TimeUnit), TimeUnit.Day); try { // Create the new Route Session long entity_key = 0; entity_key = RNA.WebServices.NewRoutingSession(newRouteSession); // Check if the Route Session was created. if (entity_key > 0) { getRouteSessions(); // Update Route Sessions data MessageBox.Show("New Route Session " + r + " created. Entity Key " + entity_key.ToString()); } } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error"); } } } else { MessageBox.Show("Select one Region first.", "Warning"); } }