|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Newtonsoft.Json.Linq; |
| 4 | +using Sabre.Trams.AppServer.Client; |
| 5 | +class TramsAPIDemo |
| 6 | +{ |
| 7 | + static async Task RunAsync() |
| 8 | + { |
| 9 | + |
| 10 | + const string URL = "http://localhost:8085/"; |
| 11 | + const string alias = "Automate_CBB_117_C"; |
| 12 | + const string username = "SYSDBA"; |
| 13 | + const string password = "masterkey"; |
| 14 | + |
| 15 | + //const string URL = "http://ltxw1359.sgdcelab.sabre.com/tramsappserverbeta/tramsappserverwebisapi.dll/"; |
| 16 | + //const string alias = "automate_cbb_117"; |
| 17 | + //const string username = "SYSDBA"; |
| 18 | + //const string password = "masterkey"; |
| 19 | + |
| 20 | + const string TBO_Access_Key = ""; |
| 21 | + |
| 22 | + Console.WriteLine("Connecting to server..."); |
| 23 | + Session session = new Session(new System.Uri(URL)); |
| 24 | + |
| 25 | + Console.WriteLine("Logging in..."); |
| 26 | + WebResponse loginResponse = await session.Login(new System.Net.NetworkCredential(username, password, alias), 1, TBO_Access_Key).ConfigureAwait(false); |
| 27 | + loginResponse.Check(); |
| 28 | + Console.WriteLine(FormattableString.Invariant($"Login Successful, Username = {username}, Alias = {alias}, Session ID = {session.SessionID}")); |
| 29 | + |
| 30 | + Console.WriteLine("Running Invoice Search... "); |
| 31 | + InvoiceSearch invoiceSearch = new InvoiceSearch(session); |
| 32 | + await invoiceSearch.Search( |
| 33 | + new JObject |
| 34 | + { |
| 35 | + { InvoiceSearch.Param_IssueDateFrom, new JValue(new DateTime(2000, 1, 1)) }, |
| 36 | + { InvoiceSearch.Param_IssueDateTo, new JValue(new DateTime(2003, 12, 31)) }, |
| 37 | + { InvoiceSearch.Param_InvoiceType, |
| 38 | + new JArray( |
| 39 | + Invoice.Literal_InvoiceType_Sale, |
| 40 | + Invoice.Literal_InvoiceType_Refund |
| 41 | + ) |
| 42 | + }, |
| 43 | + { |
| 44 | + BaseSearchDataset.Param_IncludeCols, |
| 45 | + new JArray( |
| 46 | + InvoiceSearch.Col_Invoice_InvoiceNo, |
| 47 | + InvoiceSearch.Col_Invoice_IssueDate, |
| 48 | + InvoiceSearch.Col_Invoice_InvoiceNumber, |
| 49 | + InvoiceSearch.Col_Invoice_Remarks |
| 50 | + ) |
| 51 | + } |
| 52 | + } |
| 53 | + ).ConfigureAwait(false); |
| 54 | + Console.WriteLine("Invoice Search Dataset Result Count: " + invoiceSearch.ResultTable.Rows.Count); |
| 55 | + |
| 56 | + Invoice invoice = new Invoice(session); |
| 57 | + |
| 58 | + for (int i = 0; i < invoiceSearch.ResultTable.Rows.Count; i++) |
| 59 | + { |
| 60 | + //await invoice.Load((long)invoiceSearch.ResultTable.Rows[i][InvoiceSearch.Col_Invoice_InvoiceNo]); |
| 61 | + Console.WriteLine((long)invoiceSearch.ResultTable.Rows[i][InvoiceSearch.Col_Invoice_InvoiceNo]); |
| 62 | + } |
| 63 | + |
| 64 | + Console.WriteLine("Create New Profile... "); |
| 65 | + Profile profile = new Profile(session); |
| 66 | + |
| 67 | + await profile.Prepare().ConfigureAwait(false); |
| 68 | + profile.ProfileRow[Profile.Field_Profile_ProfileType_LinkCode] = Profile.Literal_ProfileType_Leisure; |
| 69 | + profile.ProfileRow[Profile.Field_Profile_Name] = "Palley/Dan"; |
| 70 | + profile.AddRow(profile.ProfileRow); |
| 71 | + |
| 72 | + profile.PassengerRow[Profile.Field_Passenger_FirstName] = "Dan"; |
| 73 | + profile.PassengerRow[Profile.Field_Passenger_LastName] = "Palley"; |
| 74 | + profile.PassengerRow[Profile.Field_ProfilePassenger_IsPrimary] = "Y"; |
| 75 | + profile.PassengerRow = profile.AddRow(profile.PassengerRow); |
| 76 | + |
| 77 | + profile.PassengerRow[Profile.Field_Passenger_FirstName] = "Tyson"; |
| 78 | + profile.PassengerRow[Profile.Field_Passenger_LastName] = "Palley"; |
| 79 | + profile.AddRow(profile.PassengerRow); |
| 80 | + |
| 81 | + Console.WriteLine("Saving Profile... "); |
| 82 | + await profile.Save().ConfigureAwait(false); |
| 83 | + |
| 84 | + Console.WriteLine("Create New Invoice... "); |
| 85 | + //Invoice invoice = new Invoice(session); |
| 86 | + |
| 87 | + await invoice.Prepare().ConfigureAwait(false); |
| 88 | + |
| 89 | + // set the desired column values for the new invoice datarow |
| 90 | + invoice.InvoiceRow[Invoice.Field_Invoice_InvoiceNumber] = await invoice.GetNextInvoiceNumber(Invoice.Literal_InvoiceType_Sale, 0).ConfigureAwait(false); |
| 91 | + invoice.InvoiceRow[Invoice.Field_Invoice_InvoiceType_LinkCode] = Invoice.Literal_InvoiceType_Sale; |
| 92 | + invoice.InvoiceRow[Invoice.Field_Invoice_IssueDate] = DateTime.Today; |
| 93 | + invoice.InvoiceRow[Invoice.Field_Invoice_Client_LinkNo] = 4; |
| 94 | + invoice.InvoiceRow[Invoice.Field_Invoice_Branch_LinkNo] = 0; |
| 95 | + invoice.InvoiceRow[Invoice.Field_Invoice_RecordLocator] = "ABCDEF"; |
| 96 | + |
| 97 | + // add the new invoice datarow to the invoice table |
| 98 | + invoice.AddRow(invoice.InvoiceRow); |
| 99 | + |
| 100 | + // set the desired column values for the new booking datarow |
| 101 | + invoice.BookingRow[Invoice.Field_Booking_SubmitTo_LinkCode] = Invoice.Literal_SubmitTo_Supplier; |
| 102 | + invoice.BookingRow[Invoice.Field_Booking_Vendor_LinkNo] = 2; |
| 103 | + invoice.BookingRow[Invoice.Field_Booking_ConfirmNo] = "ABC123"; |
| 104 | + |
| 105 | + // add the new booking datarow to the booking table and return a new row |
| 106 | + invoice.BookingRow = invoice.AddRow(invoice.BookingRow); |
| 107 | + |
| 108 | + // set the desired column values for the new booking datarow |
| 109 | + invoice.BookingRow[Invoice.Field_Booking_SubmitTo_LinkCode] = Invoice.Literal_SubmitTo_Supplier; |
| 110 | + invoice.BookingRow[Invoice.Field_Booking_Vendor_LinkNo] = 3; |
| 111 | + invoice.BookingRow[Invoice.Field_Booking_ConfirmNo] = "DEF456"; |
| 112 | + |
| 113 | + // add the new booking datarow to the booking table |
| 114 | + invoice.AddRow(invoice.BookingRow); |
| 115 | + |
| 116 | + // set the desired column values for the new segment datarow |
| 117 | + invoice.SegmentRow[Invoice.Field_Segment_IndexNo] = 1; |
| 118 | + |
| 119 | + // add the new segment datarow to the segment table |
| 120 | + invoice.AddRow(invoice.SegmentRow); |
| 121 | + |
| 122 | + Console.WriteLine("Saving invoice... "); |
| 123 | + await invoice.Save().ConfigureAwait(false); |
| 124 | + |
| 125 | + Console.WriteLine("Create New ResCard... "); |
| 126 | + ResCard resCard = new ResCard(session); |
| 127 | + |
| 128 | + await resCard.Prepare().ConfigureAwait(false); |
| 129 | + |
| 130 | + resCard.ResCardRow[ResCard.Field_ResCard_CreateDate] = DateTime.Today; |
| 131 | + resCard.ResCardRow[ResCard.Field_ResCard_Profile_Linkno] = 4; |
| 132 | + resCard.AddRow(resCard.ResCardRow); |
| 133 | + |
| 134 | + resCard.ReservationRow[ResCard.Field_Reservation_Vendor_LinkNo] = 66; |
| 135 | + resCard.ReservationRow[ResCard.Field_Reservation_TravelCategory_LinkNo] = 1; |
| 136 | + resCard.AddRow(resCard.ReservationRow); |
| 137 | + |
| 138 | + Console.WriteLine("Saving ResCard... "); |
| 139 | + await resCard.Save().ConfigureAwait(false); |
| 140 | + |
| 141 | + Console.WriteLine("Running Activity Search... "); |
| 142 | + ActivitySearch activitySearch = new ActivitySearch(session); |
| 143 | + await activitySearch.Search( |
| 144 | + new JObject |
| 145 | + { |
| 146 | + { |
| 147 | + BaseSearchDataset.Param_IncludeCols, |
| 148 | + new JArray( |
| 149 | + ActivitySearch.Col_ActivityNo |
| 150 | + ) |
| 151 | + } |
| 152 | + } |
| 153 | + ).ConfigureAwait(false); |
| 154 | + Console.WriteLine("Activity Search Dataset Result Count: " + activitySearch.ResultTable.Rows.Count); |
| 155 | + |
| 156 | + Activity activity = new Activity(session); |
| 157 | + |
| 158 | + for (int i = 0; i < activitySearch.ResultTable.Rows.Count; i++) |
| 159 | + { |
| 160 | + //await activity.Load((long)activitySearch.ResultTable.Rows[i][ActivitySearch.Col_ActivityNo]).ConfigureAwait(false); |
| 161 | + Console.WriteLine((long)activitySearch.ResultTable.Rows[i][ActivitySearch.Col_ActivityNo]); |
| 162 | + } |
| 163 | + |
| 164 | + Console.WriteLine("Logging Out"); |
| 165 | + await session.Logout().ConfigureAwait(false); |
| 166 | + } |
| 167 | + static void Main() |
| 168 | + { |
| 169 | + RunAsync().Wait(); |
| 170 | + } |
| 171 | +} |
0 commit comments