首先界面加载时查出所需dataSet
_person_cache = baseProxy.GetPersonCache(_cmstId);
public DataSet GetStorageCache(int dep_id)
{
DataSet ds = new DataSet();
DataTable dt1 = MyBaseDAL.SelectResvoirCache(dep_id).Tables[0].Copy();
dt1.TableName = "Table1";
DataTable dt2 = MyBaseDAL.SelectDepositCache(dep_id).Tables[0].Copy();
dt2.TableName = "Table2";
ds.Tables.Add(dt1);
ds.Tables.Add(dt2);
return ds;
}
string _directory = "Config";
string _fileStorage = "dbstorage.xml";
string _filePerson = "dbperson.xml";
string _fileCustomer = "dbcustomer.xml";
DataSet dbstorage = new DataSet();
DataSet dbperson = new DataSet();
DataSet dbcustomer = new DataSet();
界面初始化时加载和保存缓存信息
SaveConfigDataSet(_storage_cache, this._directory,this._fileStorage);
LoadConfigSet(_fileStorage,dbstorage);
SaveConfigDataSet(_person_cache, this._directory, this._filePerson);
LoadConfigSet(_filePerson,dbperson);
SaveConfigDataSet(_customer_cache,this._directory,this._fileCustomer);
LoadConfigSet(_fileCustomer,dbcustomer);
//保存基础信息
public static void SaveConfigDataSet(DataSet ds,string directory,string file)
{
string strdir = Application.StartupPath + "/" + directory;
string strfile = strdir + "/" + file;
if(!Directory.Exists(strdir))
{
Directory.CreateDirectory(strdir);
}
if(!File.Exists(strfile))
{
FileStream fs = File.Create(strfile);
fs.Close();
}
ds.WriteXml(strfile);
}
public void LoadConfigSet(string file,DataSet ds)
{
string config_path = Application.StartupPath + "/" + this._directory + "/" + file;
if(!File.Exists(config_path))
{
CMSTMsgBox.MsgBox.ShowDialog("...获取缓存信息信息失败");
}
else
{
try
{
ds.ReadXml(config_path);
}
catch
{
}
}
}
网友评论