Пример #1
0
        private async void ConfirmPay_Click(object sender, RoutedEventArgs e)
        {
            OrderInfo orderList = new OrderInfo();
            string id = DateTime.Now.ToString("yyyyMMddHHmmss");
            string name = customerNameText.Text;
            string mobile = mobileText.Text;
            string totalPrice;
            string address = addressText.Text;
            double price = 0;
            foreach (var item in selectedGoods)
            {
                double singlePrice = Convert.ToDouble(item.Value.price.Substring(item.Value.price.IndexOf('¥') + 1));
                price += (singlePrice * item.Value.count);
            }
            totalPrice = Convert.ToString(price);
            Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile storageFile = await storageFolder.GetFileAsync("Goods.xml");
            XmlDocument doc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(storageFile);
            IXmlNode root = null;
            foreach (var item in doc.ChildNodes)
            {
                if (item.NodeName.Equals("orders"))
                {
                    root = item;
                    break;
                }
            }
            if (null == root)
            {
                return;
            }
            try
            {
                XmlElement orderEle = doc.CreateElement("order");
                XmlElement ele = doc.CreateElement("id");
                ele.InnerText = id;
                orderEle.AppendChild(ele);
                ele = doc.CreateElement("name");
                ele.InnerText = name;
                orderEle.AppendChild(ele);
                ele = doc.CreateElement("mobile");
                ele.InnerText = mobile;
                orderEle.AppendChild(ele);
                ele = doc.CreateElement("totalPrice");
                ele.InnerText = totalPrice;
                orderEle.AppendChild(ele);
                ele = doc.CreateElement("address");
                ele.InnerText = address;
                orderEle.AppendChild(ele);
                ele = doc.CreateElement("payed");
                ele.InnerText = "true";
                orderEle.AppendChild(ele);
                ele = doc.CreateElement("completed");
                ele.InnerText = "false";
                orderEle.AppendChild(ele);
                ele = doc.CreateElement("goods");
                foreach (var item in selectedGoods)
                {
                    XmlElement eleInner = doc.CreateElement("item");
                    XmlElement eleInnerChild = doc.CreateElement("img");
                    eleInnerChild.InnerText = item.Value.imgUri;
                    eleInner.AppendChild(eleInnerChild);
                    eleInnerChild = doc.CreateElement("count");
                    eleInnerChild.InnerText = Convert.ToString(item.Value.count);
                    eleInner.AppendChild(eleInnerChild);
                    eleInnerChild = doc.CreateElement("price");
                    eleInnerChild.InnerText = item.Value.price;
                    eleInner.AppendChild(eleInnerChild);
                    eleInnerChild = doc.CreateElement("productName");
                    eleInnerChild.InnerText = item.Value.name;
                    eleInner.AppendChild(eleInnerChild);
                    eleInnerChild = doc.CreateElement("imageName");
                    eleInnerChild.InnerText = item.Value.imageName;
                    eleInner.AppendChild(eleInnerChild);
                    ele.AppendChild(eleInner);
                }
                orderEle.AppendChild(ele);
                root.AppendChild(orderEle);
                await doc.SaveToFileAsync(storageFile);
                foreach (var item in selectedGoods)
                {
                    GoodsInfo info = item.Value;
                    foreach (var goods in goodsList)
                    {
                        if (goods.imgUri.Equals(info.imgUri) && goods.name.Equals(info.name))
                        {
                            goodsList.Remove(goods);
                            break;
                        }
                    }
                }
                bool success = await WriteShorppingcart();
                MainPage._CurrentHandle.Navigate(typeof(Orders));
            }
            catch (Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(ex.Message);
#endif
            }
        }
Пример #2
0
        private async Task<bool> GetOrderInfo()
        {
            notPayOrders.Clear();
            payedOrders.Clear();
            completedOrders.Clear();
            List<IXmlNode> orderNodes = new List<IXmlNode>();
            //Windows.Storage.StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Data");
            Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile storageFile = await storageFolder.GetFileAsync("Goods.xml");
            XmlDocument doc   = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(storageFile);
            IXmlNode root = null;
            //遍历订单
            foreach(var item in doc.ChildNodes)
            {
                var name = item.NodeName;
               if(name.Equals("orders"))
                {
                    root = item;
                    break;
                }
            }
            if(null == root)
            {
                return false;
            }
            foreach(var item in root.ChildNodes)
            {              
                var name = item.NodeName;
                if(name.Equals("order"))
                {
                    orderNodes.Add(item);         
                }            
            }
            
            foreach(var item in orderNodes)
            {
                string customer = item.SelectSingleNode("name").InnerText;
                string mobile = item.SelectSingleNode("mobile").InnerText;
                string id = item.SelectSingleNode("id").InnerText;
                string price = item.SelectSingleNode("totalPrice").InnerText;
                string payed = item.SelectSingleNode("payed").InnerText;
                string completed = item.SelectSingleNode("completed").InnerText;
                string address = item.SelectSingleNode("address").InnerText;
                IXmlNode goodsNode = item.SelectSingleNode("goods");
                List<GoodsInfo> goodsList = new List<GoodsInfo>();
                foreach(var goods in goodsNode.ChildNodes)
                {
                    if(goods.NodeName.Equals("item"))
                    {
                        string img = goods.SelectSingleNode("img").InnerText;
                        string singlePrice = goods.SelectSingleNode("price").InnerText;
                        string name = goods.SelectSingleNode("productName").InnerText;
                        string count = goods.SelectSingleNode("count").InnerText;
                        string imagename = goods.SelectSingleNode("imageName").InnerText;                       
                        GoodsInfo info = new GoodsInfo();
                        StorageFile file = await StorageFile.GetFileFromPathAsync(img);
                        using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                        {
                            BitmapImage image = new BitmapImage();
                            image.SetSource(fileStream);
                            info.img = image;
                        }
                        info.name = name;
                        info.price = singlePrice;
                        info.count = Convert.ToInt32(count);
                        info.imageName = imagename;
                        goodsList.Add(info);
                    }
                }
                OrderInfo orderInfo = new OrderInfo();
                orderInfo.address = address;
                orderInfo.id = id;
                orderInfo.price = price;
                orderInfo.goodsList = goodsList;
                orderInfo.mobile = mobile;
                orderInfo.payed = payed;
                orderInfo.completed = completed;
                orderInfo.customerName = customer;
                if(!payed.Equals("true"))
                {
                    notPayOrders.Add(orderInfo);
                }
                else if (payed.Equals("true") && completed.Equals("false"))
                {
                    payedOrders.Add(orderInfo);
                }
                else
                {
                    completedOrders.Add(orderInfo);
                }
            }

            return true;
        }