Exemple #1
0
        private void FillQueryTab()
        {
            if (this.dpQuery.Children.Count == 0 && _pdfViewerWindow.lstPdfMetaFileData != null)
            {
                var uberToc = new List <Tuple <PdfMetaData, TOCEntry> >();
                foreach (var pdfMetaDataItem in _pdfViewerWindow.lstPdfMetaFileData)
                {
                    foreach (var tentry in pdfMetaDataItem.lstTocEntries)
                    {
                        uberToc.Add(Tuple.Create(pdfMetaDataItem, tentry));
                    }
                }
                var q = from tup in uberToc
                        let itm = tup.Item2
                                  let FileInfo = new FileInfo(tup.Item1.GetFullPathFileFromPageNo(itm.PageNo))
                                                 orderby itm.SongName
                                                 select new
                {
                    itm.SongName,
                    itm.Composer,
                    CompositionDate = itm.Date,
                    Page            = itm.PageNo,
                    Fav             = tup.Item1.IsFavorite(itm.PageNo) ? "Fav" : string.Empty,
                    BookName        = tup.Item1.GetFullPathFileFromVolno(volNo: 0, MakeRelative: true),
                    itm.Notes,
                    Acquisition = FileInfo.LastWriteTime,
                    Access      = FileInfo.LastAccessTime,
                    Created     = FileInfo.CreationTime,
                    _Tup        = tup
                };

                var br = new BrowsePanel(q,
                                         colWidths: new[] { 300, 100, 100, 40, 40, 500 });
                br.BrowseList.SelectionChanged += (o, e) =>
                {
                    e.Handled = true; // prevent bubbling SelectionChanged up to tabcontrol
                };
                br.BrowseList.MouseDoubleClick += (o, e) =>
                {
                    if (br.BrowseList.SelectedIndex >= 0)
                    {
                        BtnOk_Click(o, e);
                    }
                };
                br.BrowseList.KeyUp += (o, e) =>
                {
                    //                    BtnOk_Click(o, e);
                };
                this.dpQuery.Children.Add(br);
            }
        }
        readonly string _baseTypeName = string.Empty; // includes "_"
        public BrowseList(IEnumerable query, BrowsePanel browPanel)
        {
            this._colWidths  = browPanel._colWidths;
            this.Margin      = new System.Windows.Thickness(8);
            this.ItemsSource = query;
            var gridvw = new GridView();

            this.View = gridvw;
            var ienum = query.GetType().GetInterface(typeof(IEnumerable <>).FullName);

            var members = ienum.GetGenericArguments()[0].GetMembers().Where(m => m.MemberType == System.Reflection.MemberTypes.Property);

            foreach (var mbr in members)
            {
                //if (mbr.DeclaringType == typeof(EntityObject)) // if using Entity framework, filter out EntityKey, etc.
                //{
                //    continue;
                //}
                var dataType = mbr as System.Reflection.PropertyInfo;
                var colType  = dataType.PropertyType.Name;
                if (mbr.Name.StartsWith("_"))
                {
                    _baseType     = dataType.PropertyType;
                    _baseTypeName = mbr.Name;
                    continue;
                }
                GridViewColumn gridcol = null;

                if (mbr.Name.StartsWith("_x"))                           // == "Request" || mbr.Name == "Reply" || mbr.Name == "xmlData")
                {
                    var methodName = string.Format("get_{0}", mbr.Name); // like "get_Request" or "get_Response"
                    var enumerator = query.GetEnumerator();
                    var fLoopDone  = false;
                    while (!fLoopDone)
                    {
                        if (enumerator.MoveNext())
                        {
                            var currentRecord  = enumerator.Current;
                            var currentRecType = currentRecord.GetType();
                            var msgObj         = currentRecType.InvokeMember(methodName, BindingFlags.InvokeMethod, null, currentRecord, null);
                            if (msgObj != null)
                            {
                                var msgObjType      = msgObj.GetType();
                                var msgObjTypeProps = msgObjType.GetProperties();
                                foreach (var prop in msgObjTypeProps)
                                {
                                    AddAColumn(prop.Name, prop.Name, mbr.Name);
                                }
                                fLoopDone = true;
                            }
                        }
                        else
                        {
                            fLoopDone = true;
                        }
                    }
                }
                else
                {
                    switch (colType)
                    {
                    case "XmlReader":
                    {
                        gridcol = new GridViewColumn();
                        var colheader = new GridViewColumnHeader()
                        {
                            Content = mbr.Name
                        };
                        gridcol.Header   = colheader;
                        colheader.Click += new RoutedEventHandler(Colheader_Click);
                        gridvw.Columns.Add(gridcol);
                    }
                    break;

                    default:
                    {
                        AddAColumn(ColumnName: mbr.Name, bindingName: mbr.Name, bindingObjectName: null);
                    }
                    break;
                    }
                }
            }
            // now create a style for the items
            var style = new Style(typeof(ListViewItem));

            style.Setters.Add(new Setter(ForegroundProperty, Brushes.Blue));

            //            style.Setters.Add(new Setter(HorizontalContentAlignmentProperty, HorizontalAlignment.Stretch));

            var trig = new Trigger()
            {
                Property = IsSelectedProperty,// if Selected, use a different color
                Value    = true
            };

            trig.Setters.Add(new Setter(ForegroundProperty, Brushes.Red));
            trig.Setters.Add(new Setter(BackgroundProperty, Brushes.Cyan));
            style.Triggers.Add(trig);

            this.ItemContainerStyle = style;
            this.ContextMenu        = new ContextMenu();
            this.ContextMenu.AddMenuItem(On_CtxMenu, "_Copy", "Copy selected items to clipboard");
            this.ContextMenu.AddMenuItem(On_CtxMenu, "Export to E_xcel", "Create a temp file of selected items in CSV format. In Excel, select all data, Data->TextToColumns to invoke Wizard if needed");
            this.ContextMenu.AddMenuItem(On_CtxMenu, "Export to _Notepad", "Create a temp file of selected items in TXT format");
        }