C# 基礎(chǔ)信息緩存到本地XML

首先界面加載時查出所需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);
     //保存基礎(chǔ)信息
        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
                {
                   
                }
            }


        }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容