C# 基础信息缓存到本地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);
     //保存基础信息
        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
                {
                   
                }
            }


        }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容