// Advance:執行把資料建置到Listview private void GenerateListviewItem(int page) { lvwAdvanceClassify.ItemsSource = null; lvwAdvanceClassify.Items.Clear(); cmbPager.ItemsSource = null; _dataPager.Clear(); dynamic files = GetAdvanceFileList(); int totalRecordNum = Enumerable.Count(files); _advCurrentPage = page; if (totalRecordNum <= _advPageSize) { _advTotalPage = 1; cmbPager.Visibility = System.Windows.Visibility.Hidden; } else { _advTotalPage = totalRecordNum % _advPageSize == 0 ? totalRecordNum / _advPageSize : totalRecordNum / _advPageSize + 1; if (_advTotalPage == 0) _advTotalPage = 1; for (int i = 1; i <= _advTotalPage; i++) { _dataPager.Add(i); } cmbPager.Visibility = System.Windows.Visibility.Visible; cmbPager.SelectedItem = page ; } cmbPager.ItemsSource = _dataPager; int skipNum = (_advCurrentPage - 1) * _advPageSize; files = GetAdvanceFileList(skipNum, _advPageSize); // For list mode datasource System.Collections.ObjectModel.ObservableCollection<FileInfo> fileCollection = new System.Collections.ObjectModel.ObservableCollection<FileInfo>(); ApiHelper api = new ApiHelper(); foreach (var file in files) { if (_isAdvanceTileView) { bool isImageFile = false; lvwAdvanceClassify.View = lvwAdvanceClassify.FindResource("TileView") as ViewBase; // Using store procedure to get full path. string path = DBHelper.GenerateFileFullPath(file.Id); if (api.CheckPath(path)) { BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; ExtensionHelper helper = new ExtensionHelper(); string iconPath = helper.GetIconPath( System.IO.Path.GetExtension(file.NickName)); if (iconPath != "img.ico") { bitmap.UriSource = new Uri(iconPath); } else { isImageFile = true; bitmap.UriSource = new Uri(String.Format(GlobalHelper.ApiThumb, path)); } bitmap.EndInit(); Image img = new Image(); if (!isImageFile) { img.Width = 60; img.Height = 60; } else { img.Width = 120; img.Height = 120; } img.Source = bitmap; string title = Convert.ToString(file.NickName); Tile tile = new Tile(); tile.FontFamily = new FontFamily("Microsoft JhengHei"); tile.Width = 120; tile.Height = 120; tile.Margin = new Thickness(5); tile.Content = img; tile.Tag = path; // Download Path tile.ToolTip = file.NickName; tile.Click += new RoutedEventHandler(tileAdvance_Click); tile.MouseDoubleClick += new MouseButtonEventHandler(tileAdvance_MouseDoubleClick); if (isImageFile) { tile.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); } else { tile.Title = title.Length > 12 ? String.Format("{0}…", title.Substring(0, 11)) : title; } lvwAdvanceClassify.Items.Add(tile); } } else { lvwAdvanceClassify.View = lvwAdvanceClassify.FindResource("AdvanceListView") as ViewBase; string path = DBHelper.GenerateFileFullPath(file.Id); if (api.CheckPath(path)) { fileCollection.Add(new FileInfo { FileName = file.Name, FilePath = DBHelper.GenerateFileFullPath(file.Id), FileId = file.Id }); } } } // 修改Listview Datasource if (!_isAdvanceTileView) { lvwAdvanceClassify.ItemsSource = fileCollection; } if (lvwAdvanceClassify.Items.Count == 0) { lbMessage.Visibility = System.Windows.Visibility.Visible; lbMessage.Content = "搜尋完成,無資料紀錄"; } else { lbMessage.Visibility = System.Windows.Visibility.Hidden; lbMessage.Content = ""; } }
/// <summary> /// Query:取得目錄內容 /// </summary> /// <param name="level">目錄階層</param> private void GetCatalog(int level) { lvwClassify.ItemsSource = null; lvwClassify.Items.Clear(); // display mode switch btn if (level == 6) { btnListView.Visibility = Visibility.Visible; btnTileView.Visibility = Visibility.Visible; } else { btnListView.Visibility = Visibility.Hidden; btnTileView.Visibility = Visibility.Hidden; } // 取得各階層資料 dynamic classify = null; switch (level) { case 1: classify = GetLv1Catalog(); break; case 2: classify = GetLv2Catalog(); break; case 3: classify = GetLv3Catalog(); break; case 4: classify = GetLv4Catalog(); break; case 5: classify = GetFileCatalog(); break; case 6: classify = GetFileList(); break; } ApiHelper api = new ApiHelper(); List<string> remoteFolderFullPathList = api.Dir(_ftpPath).ToList(); Dictionary<string, string> remoteFileList = new Dictionary<string, string>(); foreach (var item in remoteFolderFullPathList) { remoteFileList.Add(item.Substring(item.LastIndexOf('/') + 1), item); } System.Collections.ObjectModel.ObservableCollection<FileInfo> fileCollection = new System.Collections.ObjectModel.ObservableCollection<FileInfo>(); foreach (var classifyItem in classify) { if (remoteFileList.ContainsKey(classifyItem.Name)) { Dictionary<string, string> dicInfo = new Dictionary<string, string>(); dicInfo.Add("Id", classifyItem.Id.ToString()); dicInfo.Add("Name", classifyItem.Name); dicInfo.Add("NickName", classifyItem.NickName); if (_isTileView || level < 6) { bool isImageFile = false; lvwClassify.View = lvwClassify.FindResource("TileView") as ViewBase; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; if (level < 6) { bitmap.UriSource = new Uri(@"pack://application:,,,/WFTP;component/Icons/folder.ico"); } else { ExtensionHelper helper = new ExtensionHelper(); string iconPath = helper.GetIconPath( System.IO.Path.GetExtension(classifyItem.NickName)); if (iconPath != "img.ico") { bitmap.UriSource = new Uri(iconPath); } else { isImageFile = true; bitmap.UriSource = new Uri(String.Format(GlobalHelper.ApiThumb, remoteFileList[classifyItem.Name])); } } bitmap.EndInit(); Image img = new Image(); if (!isImageFile) { img.Width = 60; img.Height = 60; } else { img.Width = 120; img.Height = 120; } img.Source = bitmap; Tile tile = new Tile(); tile.FontFamily = new FontFamily("Microsoft JhengHei"); tile.Width = 120; tile.Height = 120; tile.Margin = new Thickness(5); tile.Content = img; if (level < 6) { if (level == 4) { tile.Count = classifyItem.Counts.ToString(); } else { tile.Count = Convert.ToString(api.GetCount(_ftpPath + dicInfo["Name"])); } } else { tile.Count = ""; } tile.Tag = dicInfo; ToolTip tip = new ToolTip(); tip.Content = dicInfo["NickName"]; tile.ToolTip = tip; tile.Click += new RoutedEventHandler(tile_Click); tile.MouseDoubleClick += new MouseButtonEventHandler(tile_MouseDoubleClick); if (tile.Count == "0") { tile.Background = new SolidColorBrush(Color.FromRgb(255, 93, 93)); } if (isImageFile) { tile.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); } else { tile.Title = dicInfo["NickName"].Length > 12 ? String.Format("{0}…", dicInfo["NickName"].Substring(0, 11)) : dicInfo["NickName"]; } lvwClassify.Items.Add(tile); } else { lvwClassify.View = lvwClassify.FindResource("ListView") as ViewBase; fileCollection.Add(new FileInfo { FileName = classifyItem.Name, FilePath = remoteFileList[classifyItem.Name], FileId = classifyItem.Id }); } } } if (!_isTileView && level == 6) { lvwClassify.ItemsSource = fileCollection; } }