private void ShowResult(TrackingInfo info)
 {
     StringBuilder builder = new StringBuilder();
     builder.Append("<h2>Result </h2><div>");
     builder.Append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">");
     builder.Append("<tr><td>");
     builder.Append("Tracking Number");
     builder.Append("</td><td>");
     builder.Append(info.TrackingNumber);
     builder.Append("</td></tr>");
     builder.Append("<tr><td>");
     builder.Append("Summary");
     builder.Append("</td><td>");
     builder.Append(info.Summary);
     builder.Append("</td></tr>");
     builder.Append("<tr><td>");
     builder.Append("Details");
     builder.Append("</td><td><div>");
     int i = 0;
     foreach (var detail in info.Details)
     {
         builder.Append("<p>" + detail + "</p>");
         i++;
     }
     if (info.Details.Count == 0)
     {
         builder.Append("<p>N/A</p>");
     }
     builder.Append("</div></td></tr>");
     builder.Append("</table></div>");
     dvTrackResponse.InnerHtml = builder.ToString();
 }
예제 #2
0
 public static TrackingInfo FromXml(string xml)
 {
     int idx1 = 0;
     int idx2 = 0;
     var t = new TrackingInfo();
     if(xml.Contains("<TrackSummary>"))
     {
         idx1 = xml.IndexOf("<TrackSummary>") + 14;
         idx2 = xml.IndexOf("</TrackSummary>");
         t._summary = xml.Substring(idx1, idx2 - idx1);
     }
     int lastidx = 0;
     while (xml.IndexOf("<TrackDetail>", lastidx) > -1)
     {
         idx1 = xml.IndexOf("<TrackDetail>", lastidx) + 13;
         idx2 = xml.IndexOf("</TrackDetail>", lastidx + 13);
         t.Details.Add(xml.Substring(idx1, idx2 - idx1));
         lastidx = idx2;
     }
     return t;
 }
예제 #3
0
        public static TrackingInfo FromXml(string xml)
        {
            int idx1 = 0;
            int idx2 = 0;
            var t    = new TrackingInfo();

            if (xml.Contains("<TrackSummary>"))
            {
                idx1       = xml.IndexOf("<TrackSummary>") + 14;
                idx2       = xml.IndexOf("</TrackSummary>");
                t._summary = xml.Substring(idx1, idx2 - idx1);
            }
            int lastidx = 0;

            while (xml.IndexOf("<TrackDetail>", lastidx) > -1)
            {
                idx1 = xml.IndexOf("<TrackDetail>", lastidx) + 13;
                idx2 = xml.IndexOf("</TrackDetail>", lastidx + 13);
                t.Details.Add(xml.Substring(idx1, idx2 - idx1));
                lastidx = idx2;
            }
            return(t);
        }
예제 #4
0
        private TrackingInfo ParseTrackingResponse(XmlDocument tinfo)
        {
            try
            {
                TrackingInfo trackdetail = new TrackingInfo();
                var elem = tinfo.DocumentElement;

                if (tinfo.DocumentElement != null)
                {
                    if (elem.Name.ToLower().Trim() != "error")
                    {
                        XmlNodeList list = tinfo.DocumentElement.SelectNodes("TrackInfo");
                        if (list != null)
                            foreach (XmlNode node in list)
                            {
                                if (node.FirstChild.Name.ToLower() == "error")
                                {
                                    string error = node.FirstChild.InnerXml;
                                    trackdetail.IsFailed = true;
                                    trackdetail.Error = error;
                                    break;
                                }
                                else
                                {
                                    trackdetail.TrackingNumber =
                                        node.Attributes["ID"].Value;
                                    trackdetail.Summary = node.SelectSingleNode("TrackSummary").InnerXml;
                                    XmlNodeList detailslist = node.SelectNodes("TrackDetail");

                                    if (detailslist.Count > 0)
                                    {
                                        foreach (XmlNode detail in detailslist)
                                        {
                                            trackdetail.Details.Add(detail.InnerXml);
                                        }
                                    }
                                    return trackdetail;
                                }
                            }
                    }
                    else
                    {
                        string error = elem.InnerXml;
                        trackdetail.IsFailed = true;
                        trackdetail.Error = error;
                    }
                }
                return trackdetail;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }