private void BtnGo_Click(object sender, EventArgs e)
        {
            try
            {
                this.Enabled       = false;
                this.UseWaitCursor = true;
                Cursor.Current     = Cursors.WaitCursor;

                if (string.IsNullOrWhiteSpace(txtAccountNumber.Text) ||
                    string.IsNullOrWhiteSpace(txtAWBNumber.Text))
                {
                    MessageBox.Show(@"Missing data.");
                    return;
                }

                txtAccountNumber.Text = txtAccountNumber.Text.Trim();
                txtAWBNumber.Text     = txtAWBNumber.Text.Trim();

                GloWS glows = new GloWS(Common.username, Common.password, (Common.IsProduction ? Common.restProductionBaseUrl : Common.restTestingBaseUrl));

                EPodResponse ePod = glows.GetEPod(txtAWBNumber.Text
                                                  , txtAccountNumber.Text
                                                  // ReSharper disable once PossibleInvalidCastException
                                                  , (Enums.EPodType)cmbPODType.SelectedItem);

                _lastJsonRequest  = glows.LastJSONRequest;
                _lastJsonResponse = glows.LastJSONResponse;

                if (null != ePod)
                {
                    string tempFilename = System.IO.Path.GetTempFileName();
                    System.IO.File.WriteAllBytes(tempFilename, ePod.EPod.Image);

                    System.Diagnostics.Process.Start(tempFilename);
                }
            }
            catch (GloWSValidationException gvx)
            {
                txtResult.Text = GloWSValidationException.PrintResults(gvx.ExtractValidationResults(), 0);
            }
            catch (Exception ex)
            {
                txtResult.Text = ex.Message;
            }
            finally
            {
                this.Enabled       = true;
                this.UseWaitCursor = false;
                Cursor.Current     = Cursors.Default;
            }
        }
Esempio n. 2
0
        private void BtnTrack_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtTrackingNumber.Text))
            {
                MessageBox.Show("Please enter a tracking number.");
                return;
            }

            // We rely on AWB numbers being exactly 10 digits, trim the field.
            txtTrackingNumber.Text = txtTrackingNumber.Text.Trim();

#pragma warning disable IDE0017 // Simplify object initialization
            try
            {
                this.Enabled = false;

                GloWS glows = new GloWS(Common.username, Common.password, (Common.IsProduction ? Common.restProductionBaseUrl : Common.restTestingBaseUrl));
                KnownTrackingResponse resp = null;

                try
                {
                    //if (10 == txtTrackingNumber.Text.Length)
                    //{
                    //    reqData.TrackingRequest.AWBNumber = new[] { txtTrackingNumber.Text.Trim() };
                    //}
                    //else
                    //{
                    //    reqData.TrackingRequest.LPNumber = new[] { txtTrackingNumber.Text.Trim() };
                    //}

                    resp = glows.KnownAWBTracking(new List <string>()
                    {
                        txtTrackingNumber.Text, "1234567891"
                    }
                                                  , Enums.LevelOfDetails.AllCheckpoints
                                                  , Enums.PiecesEnabled.Both
                                                  , Enums.EstimatedDeliveryDateEnabled.Yes);

                    _gloWsRequest  = glows.LastJSONRequest;
                    _gloWsResponse = glows.LastJSONResponse;
                }
                catch (GloWSValidationException ex)
                {
                    string msg = "Validation Failed:";
                    foreach (ValidationResult validationResult in ex.Data["ValidationResults"] as List <ValidationResult> )
                    {
                        msg += $"{Environment.NewLine}   {validationResult.ErrorMessage}";
                    }
                    MessageBox.Show(msg, "Validation Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Get the most recent AWB Info (this is a common issue due to AWB reuse)
                AWBInfoItem shipment = resp.ActualResponse.AWBInfo.Aggregate((a1, a2) => a1.ArrayOfAWBInfoItem.ShipmentInfo.ShipmentDate > a2.ArrayOfAWBInfoItem.ShipmentInfo.ShipmentDate ? a1 : a2).ArrayOfAWBInfoItem;

                if (shipment.Status.ActionStatus.ToLower() != "success")
                {
                    MessageBox.Show("There was an error in tracking.");
                    return;
                }

                //if (string.IsNullOrWhiteSpace(shipment.AWBNumber)
                //    || "No Shipments Found" == shipment.Status.ActionStatus)
                //{
                //    MessageBox.Show("No shipment found with that AWB number");
                //    return;
                //}

                SetTextboxText(ref txtShipper, shipment.ShipmentInfo.ShipperName);
                SetTextboxText(ref txtConsignee, shipment.ShipmentInfo.ConsigneeName);
                SetTextboxText(ref txtShipmentDate, shipment.ShipmentInfo.ShipmentDate);
                SetTextboxText(ref txtNumberOfPieces, shipment.ShipmentInfo.Pieces);
                SetTextboxText(ref txtShipmentWeight, shipment.ShipmentInfo.Weight, true);
                //if (null != shipment.ShipmentInfo.ShipperReference)
                //{
                //    SetTextboxText(ref txtShipmentReference, shipment.ShipmentInfo.ShipperReference.ReferenceID);
                //}

                List <string> lastCheckpoints = new List <string>();
                foreach (PieceInfoItem piece in shipment.PieceInfo)
                {
                    if (null == piece.PieceEvents)
                    {
                        continue;
                    }
                    if (piece.PieceEvents.Any())
                    {
                        var lastCheckpoint = piece.PieceEvents.Aggregate((p1, p2) => p1.Date > p2.Date ? p1 : p2).ServiceEvent.EventCode;
                        lastCheckpoints.Add(lastCheckpoint);
                    }
                    else
                    {
                        lastCheckpoints.Add("NONE");
                    }
                }

                SetTextboxText(ref txtShipmentLastCheckpoint, string.Join(" | ", lastCheckpoints));

                // Set up our tracking data list for display
                List <TrackingEventData> eventData = new List <TrackingEventData>();

                if (null != shipment.ShipmentInfo.ShipmentEvent)
                {
                    List <TrackingEventData> shipmentEvents = new List <TrackingEventData>();
                    foreach (EventItem shipmentEvent in shipment.ShipmentInfo.ShipmentEvents)
                    {
                        shipmentEvents.Add(new TrackingEventData(shipment.AWBNumber, shipmentEvent));
                    }
                    shipmentEvents.Sort((x, y) => x.Date.CompareTo(y.Date));
                    eventData.AddRange(shipmentEvents);
                }

                if (null != shipment.Pieces.PieceInfo)
                {
                    List <TrackingEventData> pieceEvents;
                    foreach (PieceInfoItem piece in shipment.PieceInfo)
                    {
                        if (null != piece.PieceEvents)
                        {
                            pieceEvents = new List <TrackingEventData>();
                            foreach (EventItem pieceEvent in piece.PieceEvents)
                            {
                                pieceEvents.Add(new TrackingEventData(piece.PieceDetails.LicensePlate, pieceEvent));
                            }
                            pieceEvents.Sort((x, y) => x.Date.CompareTo(y.Date));
                            eventData.AddRange(pieceEvents);
                        }
                    }
                }

                dgvTrackingData.DataSource = eventData;

                dgvTrackingData.RowHeadersVisible        = false;
                dgvTrackingData.AllowUserToOrderColumns  = true;
                dgvTrackingData.AllowUserToResizeColumns = true;
                dgvTrackingData.AllowUserToResizeRows    = false;

                // Set the column order(s)
                dgvTrackingData.Columns["Date"].DisplayIndex            = 0;
                dgvTrackingData.Columns["TrackingNumber"].DisplayIndex  = 1;
                dgvTrackingData.Columns["Code"].DisplayIndex            = 2;
                dgvTrackingData.Columns["Description"].DisplayIndex     = 3;
                dgvTrackingData.Columns["ServiceAreaCode"].DisplayIndex = 4;
                dgvTrackingData.Columns["ServiceAreaName"].DisplayIndex = 5;

                // Set the column headers(s)
                dgvTrackingData.Columns["TrackingNumber"].HeaderText  = "AWB / LPN";
                dgvTrackingData.Columns["ServiceAreaCode"].HeaderText = "S.A.";
                dgvTrackingData.Columns["ServiceAreaName"].HeaderText = "S.A. Name";

                foreach (DataGridViewColumn col in dgvTrackingData.Columns)
                {
                    col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }

                dgvTrackingData.Refresh();
                dgvTrackingData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            }
            finally
            {
                this.Enabled = true;
            }
        }
Esempio n. 3
0
        private void BtnGo_Click(object sender, EventArgs e)
        {
            try
            {
                this.Enabled       = false;
                this.Cursor        = Cursors.WaitCursor;
                this.UseWaitCursor = true;

                GloWS glows = new GloWS(Common.username, Common.password, (Common.IsProduction ? Common.restProductionBaseUrl : Common.restTestingBaseUrl));

                RateQueryRequest  rqr = new RateQueryRequest();
                RateRequest       rr  = new RateRequest();
                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)
                };
                GloWS_REST_Library.Objects.RateQuery.Ship s = new GloWS_REST_Library.Objects.RateQuery.Ship();
                Address sa = new Address
                {
                    City          = txtShipperCity.Text.Trim()
                    , PostalCode  = txtShipperPostalCode.Text.Trim()
                    , USSateCode  = txtShipperUSState.Text.Trim()
                    , CountryCode = txtShipperCountry.Text.Trim()
                };
                s.Shipper = sa;
                Address ra = new 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;
                }

                rr.RequestedShipment = rs;
                rqr.RateRequest      = rr;

                RateQueryResponse result = glows.RateQuery(rqr);

                _lastJsonRequest  = glows.LastJSONRequest;
                _lastJsonResponse = glows.LastJSONResponse;

                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
                {
                    foreach (Service service in result.Services)
                    {
                        TreeNode tn = new TreeNode($"{service.ProductCode}: {service.TotalNet.Currency} {service.TotalNet.Amount:#,##0.00}");
                        if (null != service.Charges)
                        {
                            foreach (Charge charge in service.Charges.Charge)
                            {
                                TreeNode ctn =
                                    new TreeNode(
                                        $"{charge.ChargeType}");
                                TreeNode cctn =
                                    new TreeNode($"{service.Charges.Currency} {charge.ChargeAmount:#,##0.00}");
                                ctn.Nodes.Add(cctn);
                                tn.Nodes.Add(ctn);
                            }
                        }

                        tn.ExpandAll();
                        tvResult.Nodes.Add(tn);
                    }
                }

                tvResult.Nodes[0].EnsureVisible();
            }
            finally
            {
                this.Enabled       = true;
                this.Cursor        = Cursors.Default;
                this.UseWaitCursor = false;
            }
        }