コード例 #1
0
ファイル: BillCategories.xaml.cs プロジェクト: rajnx/winapps
        public async void LoadBills(ObservableCollection<Bill> bills)
        {
            try
            {
                string categoriesXML = @"Assets\BillCategories.xml";

                StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                StorageFile file = await InstallationFolder.GetFileAsync(categoriesXML);

                XmlDocument billCategoriesXML = await XmlDocument.LoadFromFileAsync(file);

                XmlNodeList xmlList = billCategoriesXML.SelectNodes("/Categories/Bill");

                foreach (XmlElement element in xmlList)
                {
                    string title = element.GetAttribute("Title");
                    string subtitle = element.GetAttribute("SubTitle");
                    string imagePath = element.GetAttribute("ImagePath");
                    string portalUrl = element.GetAttribute("PortalUrl");
                    string type = element.GetAttribute("Type");
                    string isPaid = element.SelectSingleNode("IsPaid").InnerText;
                    string dueDate = element.SelectSingleNode("DueDate").InnerText;

                    Bill bill = new Bill(title, subtitle, imagePath, portalUrl, (BillType)Convert.ToInt16(type), isPaid == "1", Convert.ToDateTime(dueDate));
                    bills.Add(bill);
                }
            }
            catch (Exception e)
            {
                string error = e.Message;
            }
        }
コード例 #2
0
ファイル: HomePage.xaml.cs プロジェクト: rajnx/winapps
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            try
            {
                StorageFile localFile = await ApplicationData.Current.LocalFolder.GetFileAsync("usersettings.xml");
                string localData = await FileIO.ReadTextAsync(localFile);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(localData);

                XmlNodeList nodeList = xmlDoc.SelectNodes("Categories/Bill");

                foreach (IXmlNode node in nodeList)
                {
                    string type = node.Attributes[0].NodeValue.ToString();
                    string title = node.Attributes[1].NodeValue.ToString();
                    string subtitle = node.Attributes[2].NodeValue.ToString();
                    string imagePath = node.Attributes[3].NodeValue.ToString();
                    string portalUrl = node.Attributes[4].NodeValue.ToString();

                    string dueDate = node.FirstChild.InnerText;
                    string isPaid = node.LastChild.InnerText;

                    Bill bill = new Bill(title, subtitle, imagePath, portalUrl, BillType.CreditCard, isPaid == "1", Convert.ToDateTime(dueDate));
                    this.Bill.Add(bill);
                }

                this.DataContext = this.Bill;

            }
            catch (FileNotFoundException)
            {
                this.Frame.Navigate(typeof(BillCategories));
            }
        }