void wcDhlOrders_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { PromptForm prompt = e.UserState as PromptForm; string xml = Encoding.UTF8.GetString(e.Result); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xml); XmlNodeList nodeDhlOrders = xmldoc.SelectNodes(".//order"); if (null == nodeDhlOrders || nodeDhlOrders.Count <= 0) { return; } foreach (XmlNode nodeDhlOrder in nodeDhlOrders) { string orderId = nodeDhlOrder.Attributes.GetNamedItem("order_id").Value; string buyer = nodeDhlOrder.Attributes.GetNamedItem("buyer").Value; string shipmentNumber = nodeDhlOrder.Attributes.GetNamedItem("shipment_number").Value; string payingTime = nodeDhlOrder.Attributes.GetNamedItem("paying_time").Value; string pdfTime = nodeDhlOrder.Attributes.GetNamedItem("pdf_time").Value; string pickupTime = nodeDhlOrder.Attributes.GetNamedItem("pickup_time").Value; string resendTime = nodeDhlOrder.Attributes.GetNamedItem("resend_time").Value; DhlOrder o = new DhlOrder(orderId, buyer, shipmentNumber); DateTime dt = DateTime.MinValue; if (DateTime.TryParse(payingTime, out dt)) { o.PayingTime = dt; } if (DateTime.TryParse(pdfTime, out dt)) { o.PdfTime = dt; } if (DateTime.TryParse(pickupTime, out dt)) { o.PickedupTime = dt; } if (DateTime.TryParse(resendTime, out dt)) { o.ResendTime = dt; } DhlOrder.DhlOrders.Add(o); } prompt.Messages[prompt.Messages.Count - 1].Content = string.Format("成功下载{0}个订单的DHL数据.", DhlOrder.DhlOrders.Count); prompt.RefreshDisplay(); prompt.OKEnabled = true; }
private void btnLoad_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; // Get folder for google downloads. string documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string user = Directory.GetParent(documents).FullName; string downloads = Path.Combine(user, "downloads"); OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Taobao exported file (*.csv)|*.csv|Parsed orders file (*.xml)|*.xml"; ofd.FilterIndex = 0; ofd.Multiselect = false; ofd.ShowReadOnly = false; if (Directory.Exists(downloads)) { ofd.InitialDirectory = downloads; } if (DialogResult.OK == ofd.ShowDialog(this)) { if (Path.GetExtension(ofd.FileName).ToLower().Equals(".xml")) { _orders = Order.LoadXmlFile(ofd.FileName, false); } else if (Path.GetExtension(ofd.FileName).ToLower().Equals(".csv")) { _orders = AnalyseCsv(ofd.FileName); } } if (null == _orders) { return; } int total = 0; foreach (Order o in _orders) { if (!o.ShipmentCompany.Equals("其他")) { continue; } if (!o.ShipmentNumber.StartsWith("297808") && !o.ShipmentNumber.StartsWith("960")) { continue; } DhlOrder dhlorder = DhlOrder.GetItem(o.OrderId); if (null != dhlorder && dhlorder.Pickedup) { continue; } total++; } lblInfo.Text = string.Format("{0}/{1}", 0 + 1, total); foreach (Order o in _orders) { if (!o.ShipmentCompany.Equals("其他")) { continue; } if (!o.ShipmentNumber.StartsWith("297808") && !o.ShipmentNumber.StartsWith("960")) { continue; } DhlOrder dhlorder = DhlOrder.GetItem(o.OrderId); if (null != dhlorder && dhlorder.Pickedup) { continue; } OrderListViewItem lvi = new OrderListViewItem(lvwOrders.Items.Count + 1, o, lvwOrders); lvwOrders.Items.Add(lvi); } Cursor.Current = Cursors.Default; }