⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entrylistpanel.cs

📁 这是一款系统系统备份的软件
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using BackupSystem.DataLayer;

namespace BackupSystem.Controls
{
    public partial class EntryListPanel : UserControl
    {
        private DataLayer.EntryList elEntryList;

        internal DataLayer.EntryList EntryList
        {
            get { return elEntryList; }
        }

        public int SelectedCount
        {
            get {
                int count = 0;
                foreach (ListViewItem item in this.listView.Items)
                {
                    if (item.Checked == true)
                    {
                        count++;
                    }
                }
                return count;
            }
        }

        public Entry SelectedEntry
        {
            get
            {
                foreach (ListViewItem item in this.listView.Items)
                {
                    if (item.Checked == true)
                    {
                        return this.elEntryList.Search(item.SubItems[1].Text, item.SubItems[2].Text);
                    }
                }
                return null;
            }
        }

        public EntryListPanel()
        {
            InitializeComponent();
            this.elEntryList = new EntryList();
        }

        /// <summary>
        /// Load entries from given file.
        /// </summary>
        /// <param name="filename"></param>
        public void LoadEntryList(string filename)
        {
            this.elEntryList = DataLayer.EntryList.Load(filename);
            this.RefreshEntryList();
        }

        private void RefreshEntryList()
        {
            this.listView.Items.Clear();
            foreach (Entry entry in this.elEntryList.Entries)
            {
                ListViewItem item = new ListViewItem(entry.ID);
                item.SubItems.Add(entry.OriginalFolder);
                item.SubItems.Add(entry.TargetFolder);
                this.listView.Items.Add(item);
            }
        }

        public void Save(string filename)
        {
            this.elEntryList.Save(filename);
        }

        /// <summary>
        /// Add an entry to the list.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="originalFolder"></param>
        /// <param name="targetFolder"></param>
        public void AddEntry(string id, string originalFolder, string targetFolder)
        {
            //Add to the data list
            this.elEntryList.Add(id,originalFolder,targetFolder);
            //Add to the view
            this.RefreshEntryList();
        }

        /// <summary>
        /// Delete Selected Entries.
        /// </summary>
        public void DeleteEntry()
        {
            foreach (ListViewItem item in this.listView.Items)
            {
                if (item.Checked == true)
                {
                    this.elEntryList.Delete(item.SubItems[1].Text, item.SubItems[2].Text);
                }
            }
            this.RefreshEntryList();
        }

        public void ModifyEntry(string oldOriginal,string oldTarget,string newID,string newOriginal,string newTarget)
        {
            Entry e = this.elEntryList.Search(oldOriginal, oldTarget);
            if (e != null)
            {
                e.ID = newID;
                e.OriginalFolder = newOriginal;
                e.TargetFolder = newTarget;
                this.RefreshEntryList();
            }
        }


        public void SelectAll()
        {
            foreach (ListViewItem item in this.listView.Items)
            {
                item.Checked = true;
            }
        }

        public void DisSelectAll()
        {
            foreach (ListViewItem item in this.listView.Items)
            {
                item.Checked = false;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -