本想把系统逻辑图贴出来,贴个图可真难,最终还是没贴出来 :(
我就先贴出来一些代码了,在后面讲解逻辑与思路
下面这个是我们程序的配置文件中的内容:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="EnumerSetting"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<appSettings>
<!-- config the file type
config rule:
AssemblyName[TypeName]
example:
<add key=".mytype" value = "MyAssembly[MyType]"/>
-->
<!-- csharp code enumer -->
<add key=".cs" value="CSharpEnumer[Enumer2006.CSharp.CSharpEnmer]"/>
<!-- c/c++ -->
<add key=".h" value="CSharpEnumer[Enumer2006.CSharp.CSharpEnmer]"/>
<add key=".cpp" value="CSharpEnumer[Enumer2006.CSharp.CSharpEnmer]"/>
<add key=".c" value="CSharpEnumer[Enumer2006.CSharp.CSharpEnmer]"/>
<!-- javascript -->
<!-- java -->
<!-- asp/asp.net -->
<!-- html/xml -->
<!-- delphi -->
</appSettings>
<EnumerSetting>
</EnumerSetting>
</configuration>
下面是主程序代码:
using System;
using System.Windows.Forms;
using System.Threading;

namespace Enumer2006
{
/// <summary>
/// EnmerStart
/// </summary>
public class EnmerStart
{
[STAThread]
static void Main()
{
// ThreadException
Application.ThreadException += new
ThreadExceptionEventHandler(Application_ThreadException);

// UnhandledException
Thread.GetDomain().UnhandledException += new
UnhandledExceptionEventHandler(Application_UnhandledException);

//ApplicationをRun
Application.Run(new Form1());
return;
}

//************************************************************************
/// <summary>
///
/// </summary>
//************************************************************************
public static void ShowErrorMessage(Exception ex)
{
MessageBox.Show(null, ex.Message + " " + ex.StackTrace, "error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
// append by linzc
}
...
}
}
下面是程序主窗体Form中的代码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using EnumerConfig.Config;
using EnumerConfig.Factories;
using EnumerUtility.CommonStruct;
using EnumerOutput;
using EnumerUtility.Excepiton;

namespace Enumer2006
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnAddFolder;
private System.Windows.Forms.Button btnAddFiles;
private System.Windows.Forms.Button btnAccount;
private System.Windows.Forms.Label lblOutInfo;
private System.Windows.Forms.ListBox lstFiles;
/// <summary>
///
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button btnClear;

ArrayList mSrcFileInfo = new ArrayList();

public Form1()
{
//
// Windows
//
InitializeComponent();
}

/// <summary>
///
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

Windows

private void btnAccount_Click(object sender, System.EventArgs e)
{
ArrayList fileInfos = GetFileInfos();
EnumerProxy.Exectue(fileInfos);

// show info
try
{
this.Enabled = false;
System.Diagnostics.Process pro = new System.Diagnostics.Process();
pro.StartInfo = new System.Diagnostics.ProcessStartInfo(
"EXCEL.EXE",EnumerProxy.GetOutputFileName());
pro.Start();
this.Enabled = true;
}
catch
{
this.Enabled = true;
throw new EnumerExcelNotFoundException();
}
}

private void btnAddFolder_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
System.Windows.Forms.FolderBrowserDialog folderDlg =
new FolderBrowserDialog();
if (folderDlg.ShowDialog() == DialogResult.OK)
{
GetFileFromFolder(folderDlg.SelectedPath);
}
this.Enabled = true;
}

private void btnAddFiles_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
System.Windows.Forms.OpenFileDialog fileDlg = new OpenFileDialog();
fileDlg.RestoreDirectory = true;
fileDlg.Multiselect = true;

if (fileDlg.ShowDialog() == DialogResult.OK)
{
string [] files = fileDlg.FileNames;
for (int i = 0; i < files.Length ; ++i)
{
SourceFileInfo fileInfo = new SourceFileInfo();
fileInfo.filePath = files[i];
int lastDotIndex = files[i].LastIndexOf(".");
fileInfo.fileExandName = ((lastDotIndex==-1)?
string.Empty:
files[i].Substring(lastDotIndex));

mSrcFileInfo.Add(fileInfo);

// add to the list
this.lstFiles.Items.Add(files[i]);
}
}
this.Enabled = true;
}

void GetFileFromFolder(string bootDir)
{
// get files.
string [] files = System.IO.Directory.GetFiles(bootDir);
for (int i = 0; i < files.Length ; ++i)
{
SourceFileInfo fileInfo = new SourceFileInfo();
fileInfo.filePath = files[i];
int lastDotIndex = files[i].LastIndexOf(".");
fileInfo.fileExandName = ((lastDotIndex==-1)?
string.Empty:
files[i].Substring(lastDotIndex));

mSrcFileInfo.Add(fileInfo);

// add to the list
this.lstFiles.Items.Add(files[i]);
}
// get child folder
string [] dirs = System.IO.Directory.GetDirectories(bootDir);
for (int i = 0 ; i < dirs.Length ; ++i)
{
GetFileFromFolder(dirs[i]);
}
}

ArrayList GetFileInfos()
{
SourceFileInfo [] fileInfos = new SourceFileInfo[0];
return this.mSrcFileInfo;
}

private void btnClear_Click(object sender, System.EventArgs e)
{
this.mSrcFileInfo.Clear();
this.lstFiles.Items.Clear();
// delete output file.
try
{
EnumerProxy.Clear();
}
catch(EnumerOutFileUseingException ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
我就先贴出来一些代码了,在后面讲解逻辑与思路
下面这个是我们程序的配置文件中的内容:








































下面是主程序代码:





















































































































































































































