Esempio n. 1
0
        /// <summary>
        ///     GFS系统
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="lstData"></param>
        private static void SetGridFileToListView(List <BsonDocument> dataList, ListView lstData)
        {
            lstData.Clear();
            if (!GuiConfig.IsUseDefaultLanguage)
            {
                lstData.Columns.Add(GuiConfig.GetText(TextType.GfsFilename));
                lstData.Columns.Add(GuiConfig.GetText(TextType.GfsLength));
                lstData.Columns.Add(
                    GuiConfig.GetText(TextType.GfsChunkSize));
                lstData.Columns.Add(
                    GuiConfig.GetText(TextType.GfsUploadDate));
                lstData.Columns.Add(GuiConfig.GetText(TextType.GfsMd5));
                //!MONO
                lstData.Columns.Add("ContentType");
            }
            else
            {
                lstData.Columns.Add("filename");
                lstData.Columns.Add("length");
                lstData.Columns.Add("chunkSize");
                lstData.Columns.Add("uploadDate");
                lstData.Columns.Add("MD5");
                //!MONO
                lstData.Columns.Add("ContentType");
            }
            lstData.SmallImageList = GetSystemIcon.IconImagelist;
            lstData.LargeImageList = GetSystemIcon.IconImagelist;
            lstData.TileSize       = new Size(200, 100);

            foreach (var docFile in dataList)
            {
                var filename = docFile.GetValue("filename").ToString();
                var lstItem  = new ListViewItem();
                lstItem.ImageIndex  = GetSystemIcon.GetIconIndexByFileName(filename, false);
                lstItem.Text        = filename;
                lstItem.ToolTipText = filename;
                lstItem.SubItems.Add(MongoHelper.GetBsonSize(docFile.GetValue("length")));
                lstItem.SubItems.Add(MongoHelper.GetBsonSize(docFile.GetValue("chunkSize")));
                lstItem.SubItems.Add(ConvertToString(docFile.GetValue("uploadDate")));
                lstItem.SubItems.Add(ConvertToString(docFile.GetValue("md5")));
                //!MONO
                lstItem.SubItems.Add(GetSystemIcon.GetContentType(filename));
                lstData.Items.Add(lstItem);
            }
            //自动调节列宽
            UIAssistant.ListViewColumnResize(lstData);
            // 用新的排序方法对ListView排序
            var lvwGfsColumnSorter = new LvwColumnSorter();

            lstData.ListViewItemSorter = lvwGfsColumnSorter;
            lstData.ColumnClick       += (sender, e) =>
            {
                switch (e.Column)
                {
                case 1:
                case 2:
                    lvwGfsColumnSorter.CompareMethod = LvwColumnSorter.SortMethod.SizeCompare;
                    break;

                default:
                    lvwGfsColumnSorter.CompareMethod = LvwColumnSorter.SortMethod.StringCompare;
                    break;
                }
                // 检查点击的列是不是现在的排序列.
                if (e.Column == lvwGfsColumnSorter.SortColumn)
                {
                    // 重新设置此列的排序方法.
                    lvwGfsColumnSorter.Order = lvwGfsColumnSorter.Order == SortOrder.Ascending
                        ? SortOrder.Descending
                        : SortOrder.Ascending;
                }
                else
                {
                    // 设置排序列,默认为正向排序
                    lvwGfsColumnSorter.SortColumn = e.Column;
                    lvwGfsColumnSorter.Order      = SortOrder.Ascending;
                }
                lstData.Sort();
            };
        }