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.
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.