Beispiel #1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            goodsList.Clear();
            try
            {
                List<GoodsInfo> list = e.Parameter as List<GoodsInfo>;
                if (null != list)
                {
                    goodsList = list;
                }              
                Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                Windows.Storage.StorageFile shoppingCartStorageFile = await storageFolder.GetFileAsync("ShoppingCart.xml");                
                XmlDocument doc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(shoppingCartStorageFile);
                IXmlNode root = null;
                foreach (var item in doc.ChildNodes)
                {
                    if (item.NodeName.Equals("goods"))
                    {
                        root = item;
                        break;
                    }
                }
                if (null != root)
                {
                    foreach (var goods in root.ChildNodes)
                    {
                        if (goods.NodeName.Equals("item"))
                        {
                            string imgUrl = 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;
                            bool exist = false;
                            foreach (var item in goodsList)
                            {
                                if (item.name.Equals(name) && item.imgUri.Equals(imgUrl))
                                {
                                    item.count = item.count + Convert.ToInt32(count);
                                    exist = true;
                                    break;
                                }
                            }
                            if (!exist)
                            {
                                GoodsInfo info = new GoodsInfo();
                                StorageFile file = await StorageFile.GetFileFromPathAsync(imgUrl);
                                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;
                                info.imgUri = imgUrl;
                                goodsList.Add(info);
                            }

                        }
                    }
                }
                int index = 0;
                foreach (var item in goodsList)
                {
                    ShopCartPanel panel = new ShopCartPanel();
                    panel.Picture = item.brush;
                    panel.GoodsName = item.name;
                    panel.PictureName = item.imageName;
                    panel.GoodsCount = item.count;
                    panel.Price = item.price;
                    panel.Name = item.imgUri + item.name;
                    panel.PictureURL = item.imgUri;
                    CheckBox check = new CheckBox();
                    if(null != checkboxStyle)
                    {
                        check.SetValue(StyleProperty,checkboxStyle);
                    }
                    check.Checked += CheckBox_Checked;
                    check.Unchecked += CheckBox_Unchecked;
                    panel.Check = check;
                    Button btnAdd = new Button();
                    btnAdd.Click += Add_Click;
                    Button btnDecrease = new Button();
                    btnDecrease.Click += Decrease_Click;
                    panel.ButtonAdd = btnAdd;
                    panel.ButtonDecrease = btnDecrease;
                    panel.PictureWith = PicWidth;
                    if(index > 0 && goodsPanels.ContainsKey(index - 1))
                    {
                        panel.SetValue(RelativePanel.RightOfProperty, goodsPanels[index - 1].Name);                        
                    }
                    else
                    {
                        panel.SetValue(RelativePanel.AlignLeftWithPanelProperty, true);
                    }
                    panel.SetValue(RelativePanel.AlignTopWithPanelProperty, true);
                    goods.Children.Add(panel);
                    goodsPanels.Add(index++,panel);
                }
                ResetPicturePanelPositon();
            }
            catch(Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(ex.Message);
#endif
            }            
        }
Beispiel #2
0
 private void CheckBox_Checked(object sender, RoutedEventArgs e)
 {
     CheckBox check = sender as CheckBox;
     if (null == check)
     {
         return;
     }
     var panel = VisualTreeHelper.GetParent(check);
     if (null == panel)
     {
         return;
     }
     var grid = VisualTreeHelper.GetParent(panel);
     if(null == grid)
     {
         return;
     }
     var shopcartPanel = VisualTreeHelper.GetParent(grid);
     if(null != shopcartPanel && shopcartPanel.ToString().Equals(typeof(ShopCartPanel).ToString()))
     {
         ShopCartPanel itemPanel = shopcartPanel as ShopCartPanel;
         double totalPrice = itemPanel.GetItemTotalPrice();
         double oldPrice = Convert.ToDouble(this.price.Text);
         oldPrice += totalPrice;
         this.price.Text = Convert.ToString(oldPrice);
         GoodsInfo info = new GoodsInfo();
         info.name = itemPanel.GoodsName;
         info.price = itemPanel.Price;
         info.count = itemPanel.GoodsCount;
         info.imageName = itemPanel.PictureName;
         info.imgUri = itemPanel.PictureURL;
         selectedGoods.Add(itemPanel, info);
     }             
 }
Beispiel #3
0
 private void CheckBox_Checked(object sender, RoutedEventArgs e)
 {
     CheckBox check = sender as CheckBox;
     if(null == sender)
     {
         return;
     }
     var parent = VisualTreeHelper.GetParent(check);
     if(null == parent)
     {
         return;
     }
     var grid = VisualTreeHelper.GetParent(parent);
     if(null == grid)
     {
         return;
     }
     var panel = VisualTreeHelper.GetParent(grid);
     if (null != panel && panel.ToString().Equals(typeof(GoodsPanel).ToString()))
     {
         GoodsPanel goods = panel as GoodsPanel;
         GoodsInfo info = new GoodsInfo();
         info.img = source;
         info.imgUri = imgPath;
         info.count = 1;
         info.imageName = imageName;
         info.name = goods.GoodsName;
         info.price = goods.Price.Substring(goods.Price.IndexOf('¥')+1);
         selectedGoods.Add(check, info);
     }            
 }
Beispiel #4
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;
        }
Beispiel #5
0
        private async Task<bool> GetShopCartInfo()
        {     
            try
            {
                Windows.Storage.StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                Windows.Storage.StorageFile shoppingCartStorageFile = await storageFolder.GetFileAsync("ShoppingCart.xml");
                //string rootPath = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
                //rootPath = rootPath + @"\Data";
                //StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(rootPath);
                //Windows.Storage.StorageFile shoppingCartStorageFile = await folder.GetFileAsync("ShoppingCart.xml");
                XmlDocument doc = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(shoppingCartStorageFile);
                IXmlNode root = null;
                foreach (var item in doc.ChildNodes)
                {
                    if (item.NodeName.Equals("goods"))
                    {
                        root = item;
                        break;
                    }
                }
                int goodsCount = 0;
                if (null != root)
                {
                    foreach (var goods in root.ChildNodes)
                    {
                        if (goods.NodeName.Equals("item"))
                        {
                            string imgUrl = 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(imgUrl);
                            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;
                            info.imgUri = imgUrl;
                            goodsList.Add(info); goodsCount += Convert.ToInt32(count);
                        }
                    }
                }
                if (goodsCount > 0)
                {
                    shopcartGoodsNumber.Text = Convert.ToString(goodsCount);
                    shopcartGoodsNumber.Visibility = Visibility.Visible;
                    shopcartEllipse.Visibility = Visibility.Visible;
                }
                else
                {
                    shopcartGoodsNumber.Text = "0";
                    shopcartGoodsNumber.Visibility = Visibility.Collapsed;
                    shopcartEllipse.Visibility = Visibility.Collapsed;
                }
                return true;
            }   
            catch(Exception e)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(e.Message);                
#endif
                return false;
            }    
            
        }