Ejemplo n.º 1
0
        public DeliveryInfo GetLogisticsTcatSod(string delivery_code)
        {
            DeliveryInfo deliver = new DeliveryInfo();

            string sql = string.Format("SELECT  status_id,delivery_status_time  FROM logistics_tcat_sod WHERE delivery_number={0};", delivery_code);
            DataTable table = _accessMySql.getDataTable(sql);
            if (table.Rows.Count > 0)
            {
                DateTime date;
                if (DateTime.TryParse(table.Rows[0]["delivery_status_time"].ToString(), out date))
                {
                    deliver.CreateTime = date;
                }
                if (table.Rows[0]["status_id"].ToString() == "00003")
                {
                    deliver.Status = "順利送達";
                }
            }
            return deliver;
        }  
Ejemplo n.º 2
0
        /// <summary>
        /// 根據物流單號獲取物流狀態
        /// </summary>
        /// <param name="delivery_code">物流單號</param>
        /// <returns>DeliveryInfo對象</returns>
        static DeliveryInfo GetWebContent(string delivery_code)
        {
            string strResult = "";
            DeliveryInfo model = new DeliveryInfo();
            model.delivery_code = delivery_code;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + delivery_code);
            request.Timeout = 30000;//设置连接超时时间 
            request.Headers.Set("Pragma", "no-cache");
            request.ContentType = "text/xml; charset=gb2312";
            request.Method = "GET";
            request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
            request.ContentType = "application/x-www-form-urlencoded";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream streamReceive = response.GetResponseStream();
            StreamReader streamReader = new StreamReader(streamReceive, Encoding.UTF8);
            strResult = streamReader.ReadToEnd();

            #region 抓取狀態
            string strCheckStatus = "<font color='red'>";
            int indexStatus = strResult.IndexOf(strCheckStatus);
            if (indexStatus != -1)
            {
                string status = strResult.Substring(indexStatus + strCheckStatus.Length, 4);
                if (status.Contains("<"))
                {
                    model.Status = status.Substring(0, 3);
                }
                else
                {
                    model.Status = status;
                }
            }
            #endregion

            #region 抓取創建時間
            string strCheckTime = "<div align='center'>            <span class='bl12'>";
            int indexCreateTime = strResult.IndexOf(strCheckTime);

            if (indexCreateTime != -1)
            {
                string date = strResult.Substring(indexCreateTime + strCheckTime.Length, 10);
                string time = strResult.Substring(indexCreateTime + strCheckTime.Length + 15, 5);
                DateTime dt = Convert.ToDateTime(date + " " + time);
                model.CreateTime = dt;
            }
            #endregion

            #region 抓取營業所
            string strCheckName = "<span class='bl12'><a class='text4' href='Foothold_Detail.aspx";
            int indexName = strResult.IndexOf(strCheckName);

            if (indexName != -1)
            {
                string name = strResult.Substring(indexName + strCheckName.Length + 9, 20);
                int indexSign = name.IndexOf('<');
                if (indexSign != -1)
                {
                    model.DeliveryName = name.Substring(0, indexSign);
                }
                else
                {
                    model.DeliveryName = name;
                }
            }
            #endregion

            return model;
        }