Example #1
0
        protected void TrackBtn_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("Track!");
            ImageDisplay.Visible    = false;
            MapDisplayPanel.Visible = true;
            ErrorMessage.Visible    = false;
            statusList.Clear();

            TrackResult tr = ParcelController.Track(TrackingNumber.Text);

            if (tr != null)
            {
                List <TrackRecord> records = tr.Records;

                ParcelStatusRepeater.Visible = (tr.Status != 0 && tr.Status != 1);
                ShowMoreBtn.Visible          = (tr.Status != 0 && tr.Status != 1);
                MapPanel.Visible             = (tr.Status != 0 && tr.Status != 1);

                ParcelStatus.Text = tr.Status.ToString();

                if (tr.Status != 0 && tr.Status != 1)
                {
                    for (int i = 0; i < records.Count; i++)
                    {
                        ParcelStatus parcelStatus;
                        if (i == 0)
                        {
                            string status = string.Empty;
                            if (tr.Status == 2 || tr.Status == 3 || tr.Status == 5)
                            {
                                switch (tr.Status)
                                {
                                case 2:
                                    status             = "Pending in " + records[i].Departure;
                                    DepBranch.Text     = records[i].DeparturePoint;
                                    DepBranchName.Text = records[i].Departure + " Branch";
                                    ArrBranch.Text     = "";
                                    ArrBranchName.Text = "";
                                    break;

                                case 3:
                                    status             = "Pending transit from " + records[i].Departure + " to " + records[i].Arrival;
                                    DepBranch.Text     = records[i].DeparturePoint;
                                    DepBranchName.Text = records[i].Departure + " Branch";
                                    ArrBranch.Text     = records[i].ArrivalPoint;
                                    ArrBranchName.Text = records[i].Arrival + " Branch";
                                    break;

                                case 5:
                                    status             = "Pending delivery from " + records[i].Departure + " to receiver address";
                                    DepBranch.Text     = records[i].DeparturePoint;
                                    DepBranchName.Text = records[i].Departure + " Branch";
                                    ArrBranch.Text     = "";
                                    ArrBranchName.Text = "";
                                    break;
                                }
                                parcelStatus = new ParcelStatus("...", "...", status);
                            }
                            else if (tr.Status == 4)
                            {
                                parcelStatus = new ParcelStatus(
                                    records[i].DepartureDateTime?.ToShortDateString(),
                                    records[i].DepartureDateTime?.ToShortTimeString(),
                                    "Transiting from " + records[i].Departure + " to " + records[i].Arrival);
                                DepBranch.Text     = records[i].DeparturePoint;
                                DepBranchName.Text = records[i].Departure + " Branch";
                                ArrBranch.Text     = records[i].ArrivalPoint;
                                ArrBranchName.Text = records[i].Arrival + " Branch";
                            }
                            else if (tr.Status == 6)
                            {
                                status             = "Delivering from " + records[i].Departure + " to receiver address";
                                DepBranch.Text     = records[i].DeparturePoint;
                                DepBranchName.Text = records[i].Departure + " Branch";
                                ArrBranch.Text     = "";
                                ArrBranchName.Text = "";
                                parcelStatus       = new ParcelStatus(
                                    records[i].DepartureDateTime?.ToShortDateString(),
                                    records[i].DepartureDateTime?.ToShortTimeString(),
                                    status);
                            }
                            else    // 7
                            {
                                status             = "Delivered to receiver address";
                                DepBranch.Text     = "";
                                DepBranchName.Text = "";
                                ArrBranch.Text     = "";
                                ArrBranchName.Text = "";
                                parcelStatus       = new ParcelStatus(
                                    records[i].ArrivalDateTime?.ToShortDateString(),
                                    records[i].ArrivalDateTime?.ToShortTimeString(),
                                    status);
                                ImageDisplay.ImageUrl   = "Images/delivered.png";
                                ImageDisplay.Visible    = true;
                                MapDisplayPanel.Visible = false;
                            }
                        }
                        else        // previous transit
                        {
                            parcelStatus = new ParcelStatus(
                                records[i].ArrivalDateTime?.ToShortDateString(),
                                records[i].ArrivalDateTime?.ToShortTimeString(),
                                "Transited from " + records[i].Departure + " to " + records[i].Arrival);
                        }
                        statusList.Add(parcelStatus);
                    }
                }
                else
                {
                    ImageDisplay.ImageUrl   = "Images/pending.png";
                    ImageDisplay.Visible    = true;
                    MapDisplayPanel.Visible = false;
                    ErrorMessage.ForeColor  = System.Drawing.Color.Red;
                    ErrorMessage.Text       = "Parcel is pending";
                    ErrorMessage.Visible    = true;
                }
            }
            else
            {
                ImageDisplay.ImageUrl        = "Images/not-found.png";
                ImageDisplay.Visible         = true;
                MapDisplayPanel.Visible      = false;
                ParcelStatusRepeater.Visible = false;
                ShowMoreBtn.Visible          = false;
                MapPanel.Visible             = false;
                ErrorMessage.ForeColor       = System.Drawing.Color.Red;
                ErrorMessage.Text            = "Parcel not found";
                ErrorMessage.Visible         = true;
            }

            List <ParcelStatus> resultList = new List <ParcelStatus>();
            int count = (statusList.Count < limit ? statusList.Count : limit);

            for (int i = 0; i < count; i++)
            {
                resultList.Add(statusList[i]);
            }

            ShowMoreBtn.Visible = (statusList.Count > limit);

            ParcelStatusRepeater.DataSource = resultList;
            ParcelStatusRepeater.DataBind();
        }