//写备份文件 private bool WriteFile(string[] dStr, string[] mStr, string[] bStr) { //判断文件夹是否存在 DirectoryInfo dir = new DirectoryInfo(@"D:\\DataBaseBack"); if(!dir.Exists) dir.Create(); FileOperation fp = new FileOperation(); //日报数据 if (dStr != null) { if (!fp.WriteFile("D:\\DataBaseBack\\dStrMsg.dat", dStr)) return false; } //月报数据 if (mStr != null) { if (!fp.WriteFile("D:\\DataBaseBack\\mStrMsg.dat", mStr)) return false; } //流水数据 if (bStr != null) { if (!fp.WriteFile("D:\\DataBaseBack\\bStrMsg.dat", bStr)) return false; } return true; }
//读备份文件 并且恢复 需要改进 对于有几十万条记录 分步执行 private bool ReadFile(MySqlConnection con) { //判断文件夹是否存在 DirectoryInfo dir = new DirectoryInfo(@"D:\\DataBaseBack"); if (dir.Exists) { FileOperation fp = new FileOperation(); //恢复日汇总表 List<string> dList = new List<string>(); //读入数据失败 if(!fp.ReadFile("D:\\DataBaseBack\\dStrMsg.dat",ref dList)) return false; //恢复数据库失败 if(!ReDataBase(dList, null, null, con)) return false; dList.Clear(); //恢复月汇总表 List<string> mList = new List<string>(); if(!fp.ReadFile("D:\\DataBaseBack\\mStrMsg.dat",ref mList)) return false; if(!ReDataBase(null, mList, null, con)) return false; mList.Clear(); //恢复流水 List<string> bList = new List<string>(); if(!fp.ReadFile("D:\\DataBaseBack\\bStrMsg.dat",ref bList)) return false; if(!ReDataBase(null, null, bList, con)) return false; bList.Clear(); } return true; }