MyConfig對象還有一個Save方法用於將系統配置信息保存到數據庫中,其處理過程為
public void Save()
{
using (System.Data.IDbCommand cmd = Util.DBConnection.CreateCommand())
{
cmd.CommandText = "Delete From SystemConfig";
cmd.ExecuteNonQuery();
cmd.CommandText = "Insert Into SystemConfig ( ConfigName , ConfigValue ) Values( ? , ? )" ;
System.Data.IDbDataParameter pName = cmd.CreateParameter();
cmd.Parameters.Add( pName );
System.Data.IDbDataParameter pValue = cmd.CreateParameter();
cmd.Parameters.Add( pValue );
pName.Value = "LogRenamed";
pValue.Value = bolLogRenamed.ToString();
cmd.ExecuteNonQuery();
pName.Value = "LogChanged";
pValue.Value = bolLogChanged.ToString();
cmd.ExecuteNonQuery();
pName.Value = "LogDeleted";
pValue.Value = bolLogDeleted.ToString();
cmd.ExecuteNonQuery();
pName.Value = "LogCreated";
pValue.Value = bolLogCreated.ToString();
cmd.ExecuteNonQuery();
for (int iCount = 0; iCount < myWatchedPaths.Length; iCount++)
{
string path = myWatchedPaths[ iCount ] ;
if( path == null || path.Trim().Length == 0 )
{
continue ;
}
pName.Value = "path" + iCount ;
pValue.Value = path ;
cmd.ExecuteNonQuery();
}
}
}
在這個方法中,首先刪除數據表SystemConfig中所有的記錄,然後將所有的 配置信息保存到數據表SystemConfig中。