示例#1
0
        public async Task loadLog()
        {
            StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("logdata.xml");
            Debug.WriteLine("Attempting to read file  " + file.Path + " into xdocument");
            XDocument doc = XDocument.Load(file.Path);
            var ps = (
                    from actions in doc.Root.Elements("Action").Elements("Person")
                    select actions
                );

            IEnumerable<XElement> nactions = (
                  from actionsa in doc.Root.Elements("Action")
                 // where (string)actions.Attribute("type") == "Sign In"
                  from person in actionsa.Elements("Person")
                  from dates in person.Elements("Date")
                  orderby (Convert.ToDateTime(person.Element("Date").Value)) descending
                  select actionsa
              );

            foreach (XElement action in nactions)
            {
                LogRecordTile tile = new LogRecordTile();
                tile.txtName.Text = action.Element("Person").Element("First-Name").Value + " " + action.Element("Person").Element("Last-Name").Value;
                tile.txtCompany.Text = action.Element("Person").Element("Company-Represented").Value;
                tile.txtHost.Text = action.Element("Person").Element("Boeing-Host-Name").Value;
                tile.txtAction.Text = action.Attribute("type").Value;
                var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
                var formatterTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shorttime");
                DateTime dateToFormat = Convert.ToDateTime(action.Element("Person").Element("Time-In").Value.ToString());
                var thedate = formatter.Format(dateToFormat);
                var thetime = formatterTime.Format(dateToFormat);
                tile.txtDate.Text = thedate + " " + thetime; 
                theGrid.Items.Add(tile);
            }
        }
示例#2
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {

            DateTimeOffset sd = startDate.Date;
            DateTimeOffset ed = endDate.Date;
            string searchStr = txtSearchString.Text;

            Debug.WriteLine("Applying Filter...");
         

            StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("logdata.xml");
            Debug.WriteLine("Attempting to read file  " + file.Path + " into xdocument");
            XDocument doc = XDocument.Load(file.Path);
            var ps = (
                    from nodes in doc.Root.Elements("Action").Elements("Person")
                    select nodes
                );

            IEnumerable<XElement> actions = (
                  from nodes in doc.Root.Elements("Action")
                  from person in nodes.Elements("Person")
                  from dates in person.Elements("Date")
                  where (Convert.ToDateTime(person.Element("Time-In").Value) < ed.ToUniversalTime())
                  where (Convert.ToDateTime(person.Element("Time-In").Value) > sd.ToUniversalTime())
                  orderby (Convert.ToDateTime(person.Element("Date").Value)) descending
                  select nodes
              );

            Debug.WriteLine("found " + actions.Count() + "matching records.");

            theGrid.Items.Clear();

            foreach (XElement action in actions)
            {

                if (txtSearchString.Text != "" || txtCompany.Text != "" || txtHost.Text != "")
                {
                    if (txtSearchString.Text != "")
                    {
                        string filter = action.Element("Person").Element("First-Name").Value + " " + action.Element("Person").Element("Last-Name").Value;
                        if (filter.ToUpper().Contains(txtSearchString.Text.ToUpper()))
                        {
                            LogRecordTile tile = new LogRecordTile();
                            tile.txtAction.Text = action.Attribute("type").Value;
                            tile.txtName.Text = action.Element("Person").Element("First-Name").Value + " " + action.Element("Person").Element("Last-Name").Value;
                            tile.txtCompany.Text = action.Element("Person").Element("Company-Represented").Value;
                            tile.txtHost.Text = action.Element("Person").Element("Boeing-Host-Name").Value;
                            var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
                            var formatterTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shorttime");
                            DateTime dateToFormat = Convert.ToDateTime(action.Element("Person").Element("Time-In").Value.ToString());
                            var thedate = formatter.Format(dateToFormat);
                            var thetime = formatterTime.Format(dateToFormat);
                            tile.txtDate.Text = thedate + " " + thetime;
                            theGrid.Items.Add(tile);
                        }
                    }

                    if(txtCompany.Text != ""){
                        string filter = action.Element("Person").Element("Company-Represented").Value;
                        if (filter.ToUpper().Contains(txtCompany.Text.ToUpper()))
                        {
                            LogRecordTile tile = new LogRecordTile();
                            tile.txtAction.Text = action.Attribute("type").Value;
                            tile.txtName.Text = action.Element("Person").Element("First-Name").Value + " " + action.Element("Person").Element("Last-Name").Value;
                            tile.txtCompany.Text = action.Element("Person").Element("Company-Represented").Value;
                            tile.txtHost.Text = action.Element("Person").Element("Boeing-Host-Name").Value;
                            var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
                            var formatterTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shorttime");
                            DateTime dateToFormat = Convert.ToDateTime(action.Element("Person").Element("Time-In").Value.ToString());
                            var thedate = formatter.Format(dateToFormat);
                            var thetime = formatterTime.Format(dateToFormat);
                            tile.txtDate.Text = thedate + " " + thetime;
                            theGrid.Items.Add(tile);
                        }
                    }

                    if (txtHost.Text != "")
                    {
                        string filter = action.Element("Person").Element("Boeing-Host-Name").Value;
                        if (filter.ToUpper().Contains(txtHost.Text.ToUpper()))
                        {
                            LogRecordTile tile = new LogRecordTile();
                            tile.txtAction.Text = action.Attribute("type").Value;
                            tile.txtName.Text = action.Element("Person").Element("First-Name").Value + " " + action.Element("Person").Element("Last-Name").Value;
                            tile.txtCompany.Text = action.Element("Person").Element("Company-Represented").Value;
                            tile.txtHost.Text = action.Element("Person").Element("Boeing-Host-Name").Value;
                            var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
                            var formatterTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shorttime");
                            DateTime dateToFormat = Convert.ToDateTime(action.Element("Person").Element("Time-In").Value.ToString());
                            var thedate = formatter.Format(dateToFormat);
                            var thetime = formatterTime.Format(dateToFormat);
                            tile.txtDate.Text = thedate + " " + thetime;
                            theGrid.Items.Add(tile);
                        }
                    }

                }
                else
                {
                    LogRecordTile tile = new LogRecordTile();
                    tile.txtAction.Text = action.Attribute("type").Value;
                    tile.txtName.Text = action.Element("Person").Element("First-Name").Value + " " + action.Element("Person").Element("Last-Name").Value;
                    tile.txtCompany.Text = action.Element("Person").Element("Company-Represented").Value;
                    tile.txtHost.Text = action.Element("Person").Element("Boeing-Host-Name").Value;
                    var formatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
                    var formatterTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shorttime");
                    DateTime dateToFormat = Convert.ToDateTime(action.Element("Person").Element("Time-In").Value.ToString());
                    var thedate = formatter.Format(dateToFormat);
                    var thetime = formatterTime.Format(dateToFormat);
                    tile.txtDate.Text = thedate + " " + thetime;
                    theGrid.Items.Add(tile);

                }

            }

        }