private void BtnGo_Click(object sender, EventArgs e) { try { this.Enabled = false; this.Cursor = Cursors.WaitCursor; this.UseWaitCursor = true; MyDHLAPI api = new MyDHLAPI(Common.CurrentCredentials["Username"] , Common.CurrentCredentials["Password"] , Common.CurrentRestBaseUrl); RateQueryRequest rqr = new RateQueryRequest(); RateRequest rr = new RateRequest { /*** Request Header ***/ Request = new Request() { ServiceHeader = new ServiceHeader() { ShippingSystemPlatform = "MyDHL API Test App", ShippingSystemPlatformVersion = Application.ProductVersion, Plugin = "MyDHL API C# Library", PluginVersion = api.GetVersion() } } }; RequestedShipment rs = new RequestedShipment { DropOffType = (cmbRequestCourier.SelectedIndex == 0 ? Enums.DropOffType.RequestCourier : Enums.DropOffType.RegularPickup) , DeclaredValue = ntxtDeclaredValue.Value , DeclaredValueCurrencyCode = txtDeclaredCurrency.Text.Trim() , NextBusinessDay = Enums.YesNo.Yes , ShipTimestamp = DateTime.Now , UnitOfMeasurement = (cmbUOM.SelectedIndex == 0 ? Enums.UnitOfMeasurement.SI : Enums.UnitOfMeasurement.SU) , PaymentInfo = (Enums.TermsOfTrade)cmbTermsOfTrade.SelectedItem , RequestValueAddedServices = (cbxShowAllServices.Checked ? Enums.YesNo.Yes : Enums.YesNo.No) , Content = (cmbDutiable.SelectedIndex == 0 ? Enums.ShipmentType.Documents : Enums.ShipmentType.NonDocuments) }; MyDHLAPI_REST_Library.Objects.RateQuery.Ship s = new MyDHLAPI_REST_Library.Objects.RateQuery.Ship(); MyDHLAPI_REST_Library.Objects.RateQuery.Address sa = new MyDHLAPI_REST_Library.Objects.RateQuery.Address { City = txtShipperCity.Text.Trim() , PostalCode = txtShipperPostalCode.Text.Trim() , USSateCode = txtShipperUSState.Text.Trim() , CountryCode = txtShipperCountry.Text.Trim() }; s.Shipper = sa; MyDHLAPI_REST_Library.Objects.RateQuery.Address ra = new MyDHLAPI_REST_Library.Objects.RateQuery.Address { City = txtConsigneeCity.Text.Trim() , PostalCode = txtConsigneePostalCode.Text.Trim() , USSateCode = txtConsigneeUSState.Text.Trim() , CountryCode = txtConsigneeCountry.Text.Trim() }; s.Recipient = ra; rs.Ship = s; // 961187381 Billing b = new Billing { ShipperAccountNumber = txtAccountShipper.Text.Trim() , BillingAccountNumber = txtAccountBilling.Text.Trim() , ShippingPaymentType = (rbtnPayShipper.Checked ? Enums.PaymentTypes.Shipper : Enums.PaymentTypes.Receiver) }; rs.Billing = b; Packages p = new Packages(); List <RequestedPackages> rps = new List <RequestedPackages> { new RequestedPackages { PieceNumber = 1 , Weight = new Weight { Value = ntxtWeight.Value } , Dimensions = new Dimensions { Height = ntxtHeight.Value , Width = ntxtWidth.Value , Length = ntxtLength.Value } } }; p.RequestedPackages = rps; rs.Packages = p; if ((Enums.TermsOfTrade)cmbTermsOfTrade.SelectedItem == Enums.TermsOfTrade.DDP) { SpecialServices sss = new SpecialServices { Service = new List <SpecialService>() }; sss.Service.Add(new SpecialService("DD")); rs.SpecialServices = sss; } rs.GetDetailedRateBreakdown = Enums.YesNo.Yes; rr.RequestedShipment = rs; rqr.RateRequest = rr; RateQueryResponse result = null; try { result = api.RateQuery(rqr); } catch (Exception ex) { MessageBox.Show($"{ex.Message}", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); _lastJsonRequest = api.LastRateQueryJSONRequest; _lastJsonResponse = api.LastRateQueryJSONResponse; return; } _lastJsonRequest = api.LastRateQueryJSONRequest; _lastJsonResponse = api.LastRateQueryJSONResponse; tvResult.Nodes.Clear(); if (null == result.Services) { if (null != result.RateResponse.Provider) { if (1 == result.RateResponse.Provider.Count) { Provider provider = result.RateResponse.Provider.First(); if (provider.Notification.Any()) { foreach (Notification notificaiton in provider.Notification) { tvResult.Nodes.Add(notificaiton.Code, notificaiton.Message); } } } } else { // We got no results back tvResult.Nodes.Add("NONE", "--NONE--"); } } else { TreeNode servicesOkToShow = new TreeNode("Show on website"); TreeNode servicesNeedingAgreement = new TreeNode("Pre-agreement required"); foreach (Service service in result.Services) { TreeNode tn = new TreeNode($"{service.ProductCode}: {service.TotalNet.Currency} {service.TotalNet.Amount:#,##0.00}"); tn.Nodes.Add($"Transit time: {service.TotalTransitDays} day(s)"); if (null != service.Charges) { foreach (Charge charge in service.Charges.Charge) { TreeNode ctn = null; if (string.IsNullOrEmpty(charge.ChargeCode)) { ctn = new TreeNode($"{charge.ChargeType}"); } else { ctn = new TreeNode($"({charge.ChargeCode}) {charge.ChargeType}"); } if (!string.IsNullOrEmpty(service.Charges.Currency) && null != charge.ChargeAmount) { TreeNode cctn = new TreeNode($"{service.Charges.Currency} {charge.ChargeAmount:#,##0.00}"); ctn.Nodes.Add(cctn); } tn.Nodes.Add(ctn); } } tn.ExpandAll(); if (service.CustomerAgreementInd == Enums.YesNo.No) { servicesOkToShow.Nodes.Add(tn); } else { servicesNeedingAgreement.Nodes.Add(tn); } } servicesOkToShow.ExpandAll(); servicesNeedingAgreement.ExpandAll(); tvResult.Nodes.Add(servicesOkToShow); tvResult.Nodes.Add(servicesNeedingAgreement); } tvResult.Nodes[0].EnsureVisible(); } finally { this.Enabled = true; this.Cursor = Cursors.Default; this.UseWaitCursor = false; } }
private void BtnGo_Click(object sender, EventArgs e) { MyDHLAPI api = new MyDHLAPI(Common.CurrentCredentials["Username"] , Common.CurrentCredentials["Password"] , Common.CurrentRestBaseUrl); try { this.Enabled = false; this.UseWaitCursor = true; Cursor.Current = Cursors.WaitCursor; if (string.IsNullOrWhiteSpace(txtPickupCountry.Text) || string.IsNullOrWhiteSpace(txtRequestorName.Text)) { MessageBox.Show(@"Missing data."); return; } txtPickupCountry.Text = txtPickupCountry.Text.Trim(); txtRequestorName.Text = txtRequestorName.Text.Trim(); txtPickupRequestNumber.Text = txtPickupRequestNumber.Text.Trim(); DeletePickupRequest req = new DeletePickupRequest { DeleteRequest = new DeleteRequest { Request = new Request() { ServiceHeader = new ServiceHeader() { ShippingSystemPlatform = "MyDHL API Test App", ShippingSystemPlatformVersion = Application.ProductVersion, Plugin = "MyDHL API C# Library", PluginVersion = api.GetVersion() } }, PickupDate = dtpPickupDate.Value, PickupCountry = txtPickupCountry.Text, RequestorName = txtRequestorName.Text, PickupRequestNumber = txtPickupRequestNumber.Text, Reason = (Enums.DeletePickupRequestReason)cmbReason.SelectedValue } }; DeletePickupResponse resp = api.RequestDeletePickupAsync(req).Result; if (null != resp) { txtResult.Text = Notification.GetAllNotifications(resp.Notifications, Environment.NewLine); } } catch (MyDHLAPIValidationException gvx) { txtResult.Text = MyDHLAPIValidationException.PrintResults(gvx.ExtractValidationResults(), 0); } catch (Exception ex) { txtResult.Text = ex.Message; } finally { this.Enabled = true; this.UseWaitCursor = false; Cursor.Current = Cursors.Default; _lastJsonRequest = api.LastDeletePickupJSONRequest; _lastJsonResponse = api.LastDeletePickupJSONResponse; } }