美文网首页
C# 基础信息缓存到本地XML

C# 基础信息缓存到本地XML

作者: a9b854aded01 | 来源:发表于2017-11-23 17:13 被阅读0次

首先界面加载时查出所需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
                {
                   
                }
            }


        }

相关文章

网友评论

      本文标题:C# 基础信息缓存到本地XML

      本文链接:https://www.haomeiwen.com/subject/yqazvxtx.html