示例#1
0
 private void DbFileWatch_FileChanged(string filePath)
 {
     if (!DB.IsApplicationUpdate)
     {
         Dictionary <string, DirectoryMeta> dirs = DB.GetFoldersData();
         foreach (var item in RootFolders)
         {
             this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)(() =>
             {
                 StoreBanner banner = ((fileTree.Items.CurrentItem as TreeViewItem).Tag as DirectoryMeta).StoreBanner;
                 if (HasSearched && banner.BANNER_CODE != DBServices.NoBanner.BANNER_CODE)
                 {
                     ObservableCollection <TreeViewItem> itemsFound = new ObservableCollection <TreeViewItem>();
                     foreach (var dir in DB.SearchFoldersByTag(banner))
                     {
                         itemsFound.Add(CreateTreeViewItem(dir.Value.GetDirectoryInfo()));
                     }
                     fileTree.ItemsSource = itemsFound;
                     HasSearched = true;
                 }
                 else
                 {
                     RootFolders[item.Key] = TreeTraverse(item.Value, dirs);
                 }
             }));
         }
     }
     else
     {
         DB.IsApplicationUpdate = false;
     }
 }
示例#2
0
 public Dictionary <string, DirectoryMeta> SearchFoldersByTag(StoreBanner banner)
 {
     using (var db = new LiteDatabase(Settings.Default.ConnectionString))
     {
         Folders = db.GetCollection <DirectoryMeta>("projdirs").Include <StoreBanner>(x => x.StoreBanner).Query().Where(x => x.StoreBanner.BANNER_CODE == banner.BANNER_CODE).ToList().ToDictionary(folder => folder.DirectoryPath);
         db.Commit();
     }
     return(Folders);
 }
示例#3
0
 public void AddBanner(StoreBanner storeBanner)
 {
     IsApplicationUpdate = true;
     using (var db = new LiteDatabase(Settings.Default.ConnectionString))
     {
         var collection = db.GetCollection <StoreBanner>("storebanners");
         if (!collection.Exists(x => x.BANNER_CODE == storeBanner.BANNER_CODE || x.BANNER_NAME == storeBanner.BANNER_NAME))
         {
             collection.Insert(storeBanner);
         }
         db.Commit();
         Banners = collection.FindAll().ToDictionary(banner => banner.BANNER_CODE);
     }
 }
示例#4
0
 public StoreBanner CheckAndInsertUpdateData(StoreBanner data)
 {
     IsApplicationUpdate = true;
     //ConfigurationManager.ConnectionStrings["LiteDB"].ConnectionString
     using (var db = new LiteDatabase(Settings.Default.ConnectionString))
     {
         var collection = db.GetCollection <StoreBanner>("storebanners");
         if (!collection.Exists(x => x.BANNER_CODE == data.BANNER_CODE || x.BANNER_NAME == data.BANNER_NAME))
         {
             collection.Insert(data);
         }
         else if (!collection.Exists(x => x.BANNER_CODE == data.BANNER_CODE && x.BANNER_NAME == data.BANNER_NAME && x.CLIENT == data.CLIENT))
         {
             collection.Update(data);
         }
         db.Commit();
         Banners = collection.FindAll().ToDictionary(banner => banner.BANNER_CODE);
     }
     return(Banners[data.BANNER_CODE]);
 }
示例#5
0
 private void TagChip_Click(object sender, RoutedEventArgs e)
 {
     this.Dispatcher.Invoke(() =>
     {
         StoreBanner banner = (sender is Chip) ? (sender as Chip).Tag as StoreBanner : sender as StoreBanner;
         if (banner.BANNER_CODE == DBServices.NoBanner.BANNER_CODE)
         {
             InitRootFolders();
             HasSearched = false;
         }
         else
         {
             ObservableCollection <TreeViewItem> itemsFound = new ObservableCollection <TreeViewItem>();
             foreach (var dir in DB.SearchFoldersByTag(banner))
             {
                 itemsFound.Add(CreateTreeViewItem(dir.Value.GetDirectoryInfo()));
             }
             fileTree.ItemsSource = itemsFound;
             HasSearched          = true;
         }
         fileTree.Items.Refresh();
         fileTree.UpdateLayout();
     });
 }
示例#6
0
 public StoreBannerHeader(StoreBanner storeBanner)
 {
     this._storeBanner = storeBanner;
 }
示例#7
0
        private TreeViewItem CreateTreeViewItem(FileSystemInfo fsinfo)
        {
            TreeViewItem item = new TreeViewItem();

            DirectoryMeta dirMeta = DB.GetInsertFolderData(fsinfo.FullName);
            StoreBanner   banner  = dirMeta.StoreBanner;

            //Build StackPanel as Header
            StackPanel stack = new StackPanel()
            {
                Orientation = Orientation.Horizontal
            };
            Label folderName = new Label()
            {
                Content = fsinfo.Name, VerticalContentAlignment = VerticalAlignment.Center
            };

            Chip chipBanner = new Chip()
            {
                Content    = banner.BANNER_NAME,
                Visibility = banner.BANNER_CODE != DBServices.NoBanner.BANNER_CODE ? Visibility.Visible : Visibility.Hidden
            };
            Chip chipClient = new Chip()
            {
                Content    = banner.CLIENT,
                Visibility = banner.BANNER_CODE != DBServices.NoBanner.BANNER_CODE ? Visibility.Visible : Visibility.Hidden
            };

            stack.Children.Add(folderName);
            stack.Children.Add(chipBanner);
            stack.Children.Add(chipClient);

            item.Header  = stack;
            item.ToolTip = fsinfo.FullName;
            item.Tag     = dirMeta;
            item.Items.Add(null);
            item.Expanded += Item_Expanded;
            //Build ContextMenu
            ContextMenu menu = new ContextMenu();
            Button      btnAddOrChangeBanner = new Button()
            {
                Content = "Select Banner", ContextMenu = menu
            };

            btnAddOrChangeBanner.Click += delegate(object sender, RoutedEventArgs e) { (sender as Button).ContextMenu.IsOpen = true; };
            stack.Children.Add(btnAddOrChangeBanner);
            this.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)(() =>
            {
                DB.GetStoreBanners().ToList()
                .ForEach(x =>
                {
                    MenuItem menuItem = new MenuItem()
                    {
                        Header = x.Value.BANNER_NAME, Tag = x.Value
                    };

                    //Update DB to change Banner
                    menuItem.Click += delegate(object sender, RoutedEventArgs e)
                    {
                        DirectoryMeta dir = dirMeta;
                        dirMeta.StoreBanner = x.Value;
                        DB.CheckAndInsertUpdateData(dir);
                        item = CreateTreeViewItem(dir.GetDirectoryInfo());
                        if (x.Value.BANNER_CODE != DBServices.NoBanner.BANNER_CODE)
                        {
                            chipBanner.Content = x.Value.BANNER_NAME;
                            chipClient.Content = x.Value.CLIENT;
                            chipBanner.Visibility = Visibility.Visible;
                            chipClient.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            chipBanner.Content = x.Value.BANNER_NAME;
                            chipClient.Content = x.Value.CLIENT;
                            chipBanner.Visibility = Visibility.Hidden;
                            chipClient.Visibility = Visibility.Hidden;
                        }
                        if (HasSearched)
                        {
                            ObservableCollection <TreeViewItem> itemsFound = new ObservableCollection <TreeViewItem>();
                            foreach (var directory in DB.SearchFoldersByTag(banner))
                            {
                                itemsFound.Add(CreateTreeViewItem(directory.Value.GetDirectoryInfo()));
                            }
                            fileTree.ItemsSource = itemsFound;
                            HasSearched = true;
                        }
                    };
                    menu.Items.Add(menuItem);
                });
            }));
            return(item);
        }