Пример #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     listView1.Items.Clear();
     //数据验证
     if (!string.IsNullOrWhiteSpace(tbx_Dh.Text.Trim()) && !string.IsNullOrWhiteSpace(tbx_Phone.Text.Trim()))
     {
         KdApiSearchDemo demo = new KdApiSearchDemo();
         //获取控件值
         string dh     = tbx_Dh.Text.Trim();
         string phone  = tbx_Phone.Text.Trim();
         string bsCode = comboBox1.SelectedValue.ToString();
         //接受返回值
         string result = demo.getOrderTracesByJson(dh, phone, bsCode);
         List <LogisticsModel> logisticsList = new List <LogisticsModel>();
         if (!string.IsNullOrWhiteSpace(result))
         {
             //Json转化实体类
             LogisticsInfoResultModel logisticsModelList = JsonNewtonsoft.FromJSON <LogisticsInfoResultModel>(result);
             if (logisticsModelList != null && logisticsModelList.Traces != null && logisticsModelList.Traces.Count() > 0)
             {
                 //接收快递信息列表,按最新时间倒序排列
                 logisticsList = logisticsModelList.Traces.OrderByDescending(x => x.AcceptTime).ToList();
             }
         }
         if (logisticsList != null && logisticsList.Count() > 0)
         {
             listView1.BeginUpdate();   //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
             int i = 0;
             foreach (var trace in logisticsList)
             {
                 //绑定数据
                 ListViewItem lvi = new ListViewItem();
                 //lvi.Text第一列
                 lvi.Text = trace.AcceptTime.ToString();
                 //第二列,第三列、第四列以此类推,与第一列不同
                 lvi.SubItems.Add(trace.AcceptStation);
                 //设置最新一条记录的样式区别于其他记录
                 if (i == 0)
                 {
                     lvi.Font = new Font("仿宋", 12, FontStyle.Bold);
                     //设置字体颜色
                     lvi.ForeColor = Color.Blue;
                 }
                 listView1.Items.Add(lvi);
                 i++;
             }
             listView1.EndUpdate();
         }
         else
         {
             MessageBox.Show("未获取到快递信息", "提示");
         }
     }
     else
     {
         MessageBox.Show("快递单号与收件人手机号不能为空", "提示");
     }
 }
Пример #2
0
        public static void Seacher()
        {
            string dh    = "";
            string phone = "";

            while (string.IsNullOrWhiteSpace(dh) || string.IsNullOrWhiteSpace(phone))
            {
                Console.WriteLine("请输入快递单号");
                dh = Console.ReadLine();
                Console.WriteLine("请输入手机号后四位");
                phone = Console.ReadLine();
            }
            if (!string.IsNullOrWhiteSpace(dh) && !string.IsNullOrWhiteSpace(phone))
            {
                KdApiSearchDemo demo = new KdApiSearchDemo();
                //string result = demo.getOrderTracesByJson(dh, phone);YT4305684277871
                string result = demo.getOrderTracesByJson(dh, phone, "SF");//.orderTracesSubByJson(dh);
                Console.WriteLine(result);
                Console.ReadLine();
            }
        }