Beispiel #1
0
        private void RightMenuItemClick(object sender, EventArgs e)
        {
            if (sender is ToolStripItem)
            {
                ToolStripItem toolStripItem = (ToolStripItem)sender;
                var           items         = listView1.SelectedItems;
                foreach (var item in items)
                {
                    ListViewItem    li                  = (ListViewItem)item;
                    bool            isDirec             = false;
                    DirectoryInfo   selectDirectoryInfo = null;
                    FileInfo        selectFileInfo      = null;
                    DirectoryInfo   di                  = new DirectoryInfo(CurSelectNode.FullPath);
                    DirectoryInfo[] dis                 = di.GetDirectories();
                    foreach (var directory in dis)
                    {
                        if (directory.Name == li.Text)
                        {
                            isDirec             = true;
                            selectDirectoryInfo = directory;
                            break;
                        }
                    }
                    if (!isDirec)
                    {
                        FileInfo[] fis = di.GetFiles();
                        foreach (var fileInfo in fis)
                        {
                            if (fileInfo.Name == li.Text)
                            {
                                selectFileInfo = fileInfo;
                                break;
                            }
                        }
                    }
                    switch (toolStripItem.Text)
                    {
                    case "属性":
                        if (isDirec)
                        {
                            MessageBox.Show("详细属性:\n" +
                                            "名称:" + selectDirectoryInfo.Name + "\n" +
                                            "类型:文件夹\n" +
                                            "位置:" + selectDirectoryInfo.FullName + "\n" +
                                            "大小:" + Util.FormatSize(Util.GetDirectoryLength(selectDirectoryInfo.FullName)) + "\n" +
                                            "创建时间:" + selectDirectoryInfo.CreationTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后修改时间:" + selectDirectoryInfo.LastWriteTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后访问时间:" + selectDirectoryInfo.LastAccessTime.ToString("yyyy年MM月dd日,HH:MM:ss"),
                                            selectDirectoryInfo.Name + "属性",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("详细属性:\n" +
                                            "名称:" + selectFileInfo.Name + "\n" +
                                            "类型:" + selectFileInfo.Extension.Replace(".", "").ToUpper() + "文件(" + selectFileInfo.Extension + ")" + "\n" +
                                            "位置:" + selectFileInfo.FullName + "\n" +
                                            "大小:" + Util.FormatSize(Util.GetDirectoryLength(selectFileInfo.FullName)) + "\n" +
                                            "创建时间:" + selectFileInfo.CreationTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后修改时间:" + selectFileInfo.LastWriteTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后访问时间:" + selectFileInfo.LastAccessTime.ToString("yyyy年MM月dd日,HH:MM:ss"),
                                            selectFileInfo.Name + "属性",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        break;

                    case "删除":
                        if (isDirec)
                        {
                            DialogResult dr = MessageBox.Show("确定是否删除文件夹" + selectDirectoryInfo.Name + "?", "文件夹删除",
                                                              MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                            if (dr == DialogResult.OK)
                            {
                                try
                                {
                                    selectDirectoryInfo.Delete();
                                }
                                catch (Exception ee)
                                {
                                    MessageBox.Show(ee.Message, "删除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            DialogResult dr = MessageBox.Show("确定是否删除文件" + selectFileInfo.Name + "?", "文件删除",
                                                              MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                            if (dr == DialogResult.OK)
                            {
                                try
                                {
                                    selectFileInfo.Delete();
                                }
                                catch (Exception ee)
                                {
                                    MessageBox.Show(ee.Message, "删除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                finally
                                {
                                    RefreshViewList(CurSelectNode.TreeNode);
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        private void AddListItemThread(object fullpath)
        {
            progressForm.Visible = true;
            progressForm.SetPosition(Left, Width, Top, Height);
            LogLabel.Text = "加载中...";
            string path = (string)fullpath;

            listView1.Items.Clear();
            try
            {
                ListViewData.Instance.ClearListItemInfo();
                DirectoryInfo   di       = new DirectoryInfo(path);
                DirectoryInfo[] dis      = di.GetDirectories();
                FileInfo[]      fis      = di.GetFiles();
                int             allfiles = dis.Length + fis.Length;
                int             index    = 0;
                foreach (var directoryInfo in dis)
                {
                    string text = string.Format("正在加载{2}  已完成{0}/{1}", index, allfiles, directoryInfo.Name);
                    LogLabel.Text = text;
                    progressForm.ShowText(text);
                    progressForm.ShowProgress(allfiles, index);
                    ListItemInfo listItemInfo = new ListItemInfo {
                        Name = directoryInfo.Name, CrtTm = directoryInfo.CreationTime, ModTm = directoryInfo.LastWriteTime, Type = "文件夹", Size = Util.GetDirectoryLength(directoryInfo.FullName)
                    };
                    AddViewItem(listItemInfo, false);
                    ListViewData.Instance.SetListItemInfo(listItemInfo, InfoType.DIRECTORY);
                    index++;
                    Thread.Sleep(10);
                }
                foreach (var fileInfo in fis)
                {
                    string text = string.Format("正在加载{2}  已完成{0}/{1}", index, allfiles, fileInfo.Name);
                    LogLabel.Text = text;
                    LogLabel.Text = text;
                    progressForm.ShowText(text);
                    progressForm.ShowProgress(allfiles, index);
                    ListItemInfo listItemInfo = new ListItemInfo {
                        Name = fileInfo.Name, CrtTm = fileInfo.CreationTime, ModTm = fileInfo.LastWriteTime, Type = fileInfo.Extension.Replace(".", "").ToUpper() + "文件", Size = Util.FileSize(fileInfo.FullName)
                    };
                    AddViewItem(listItemInfo);
                    ListViewData.Instance.SetListItemInfo(listItemInfo, InfoType.File);
                    index++;
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            LogLabel.Text        = "加载完成";
            progressForm.Visible = false;
        }