Programming     Travel Logs     Life Is Good     Surfing Online     About Me
The Internet has massively broadened the possible space of careers. Most people haven’t figured this out yet.
-Naval Ravikant
2018-05-03 20:45:31

Copy this link when reproducing:
http://www.casperlee.com/en/y/blog/51

The "Export Document" function is also not hard to be implemented, so I'll just post source code here without explaining too much.

/Images/20161213/01.jpg

/Images/20161213/02.jpg

/Images/20161213/03.jpg

/Images/20161213/04.jpg

/Images/20161213/05.jpg

/Images/20161213/06.jpg

/Images/20161213/07.jpg

/Images/20161213/08.jpg

/Images/20161213/09.jpg

1. Open the file "MainForm.cs" in the main project. Double click on the "Export" button to add an OnClick event handler, and put the following code in.

        private void btnExport_Click(object sender, EventArgs e)
{
if (lvResult.SelectedItems.Count == 0)
{
return;
}

FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog(this) != DialogResult.OK)
{
return;
}

string folderName = fbd.SelectedPath;

foreach (ListViewItem item in lvResult.SelectedItems)
{
ResourceEx rx = (ResourceEx)item.Tag;
string fileName = Path.Combine(folderName, rx.Name);
ResourceBll.Instance.ExportResource(rx, fileName);
}

MessageBox.Show(this, "Done!");
}

2. Open the file "ResourceBll.cs" in the Bll project and add the following function.

        public void ExportResource(ResourceEx aResouce, string aFileName)
{
if (aResouce.Encrypted)
{
aResouce.Decrypt(CEnvironment.CurrentPassword);
}

if (handler == null)
{
CreateHandler(false);
}

handler.ExportResource(aResouce, aFileName);
}

3. Open the file "ResourceHandler.cs" in the Bll project and add the following function.

        public void ExportResource(ResourceEx aResouce, string aFileName)
{
CFileHandler.Instance.FileHandleEvent += Resource_FileExportEvent;
try
{
CFileHandler.Instance.DecryptFile(
aResouce.FileName,
aFileName,
CEnvironment.CurrentPassword);
}
finally
{
CFileHandler.Instance.FileHandleEvent -= Resource_FileExportEvent;
}
}

4. Finished.