/// <summary>
        /// 删除备份记录
        /// </summary>
        /// <param name="_backrecord"></param>
        public bool DelBackRecord(UIModels.DataBaseBackInfo _backrecord)
        {
            bool bolSucced = false;

            if (recordlist == null)
            {
                GetDataBackRecords();
            }
            if (recordlist != null && recordlist.Count > 0)
            {
                foreach (UIModels.DataBaseBackInfo item in recordlist)
                {
                    if (item.SortNo == _backrecord.SortNo)
                    {
                        recordlist.Remove(item);
                        if (File.Exists(item.DataFilePath))
                        {
                            File.Delete(item.DataFilePath);
                        }
                        break;
                    }
                }

                int SortNo = 1;
                foreach (UIModels.DataBaseBackInfo item in recordlist)
                {
                    item.SortNo = SortNo;
                    SortNo++;
                }

                bolSucced = SaveRecords();//保存记录
            }

            return(bolSucced);
        }
        /// <summary>
        /// 获取数据库备份记录
        /// </summary>
        /// <returns></returns>
        public List <UIModels.DataBaseBackInfo> GetDataBackRecords()
        {
            if (recordlist == null)
            {
                if (System.IO.File.Exists("DataBaseBackLog.xml"))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load("DataBaseBackLog.xml");

                    //<Record No="1" FileName="aa" UpTime=""></Record>
                    XmlNodeList retrunDataList = doc.GetElementsByTagName("Record"); //取得节点名为Record的XmlNode集合
                    if (retrunDataList != null && retrunDataList.Count > 0)
                    {
                        recordlist = new List <UIModels.DataBaseBackInfo>();
                        UIModels.DataBaseBackInfo _backrecord = null;
                        foreach (XmlNode _node in retrunDataList)
                        {
                            _backrecord = new UIModels.DataBaseBackInfo();
                            _backrecord.BackDataFileName = _node.Attributes["FileName"].Value;
                            _backrecord.DataBackTime     = _node.Attributes["UpTime"].Value;
                            _backrecord.SortNo           = Convert.ToInt32(_node.Attributes["No"].Value);
                            _backrecord.DataFilePath     = _node.InnerText;

                            recordlist.Add(_backrecord);
                        }
                    }
                }
            }
            return(recordlist);
        }
 /// <summary>
 /// 还原数据库至本地的一个版本
 /// </summary>
 /// <param name="_backrecord">本地备份版本信息</param>
 public void RestoreByLocalVesion(UIModels.DataBaseBackInfo backrecordinfo)
 {
     _backrecord = backrecordinfo;
     System.Threading.Thread restoreToVesionthread = new System.Threading.Thread(new System.Threading.ThreadStart(RestoreThread));
     restoreToVesionthread.IsBackground = true;
     restoreToVesionthread.Start();
 }
        /// <summary>
        /// 添加新备份
        /// </summary>
        /// <param name="_backrecord"></param>
        /// <returns></returns>
        public bool AddBackRecord(UIModels.DataBaseBackInfo _backrecord)
        {
            bool bolsucced = false;

            if (recordlist == null)
            {
                GetDataBackRecords();
            }
            if (recordlist == null)
            {
                recordlist = new List <UIModels.DataBaseBackInfo> ();
            }
            recordlist.Add(_backrecord);

            //重新排序号
            int SortNo = 1;

            foreach (UIModels.DataBaseBackInfo item in recordlist)
            {
                item.SortNo = SortNo;
                SortNo++;
            }

            if (SaveRecords())
            {
                bolsucced = true;
            }

            return(bolsucced);
        }
        /// <summary>
        /// 创建备份版本现场执行操作
        /// </summary>
        private void CreatebackvesionThread()
        {
            bool   bolState        = false;
            string strErrorMsgInfo = "备份发生错误!";
            string DbFilePath      = KPS.DBUtility.DbHelperOleDb.getDBPath();

            if (File.Exists(DbFilePath))
            {
                try
                {
                    #region 执行备份操作
                    string strExePath       = System.Windows.Forms.Application.StartupPath;//当前程序目录
                    string strBackupDirPath = Path.Combine(strExePath, "DataBack");
                    if (!Directory.Exists(strBackupDirPath))
                    {
                        //文件夹不存在则创建
                        Directory.CreateDirectory(strBackupDirPath);
                    }

                    string   BackUpFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    FileInfo DataFile       = new FileInfo(DbFilePath);

                    //复制备份文件
                    string strfilecopytoPath = Path.Combine(strBackupDirPath, string.Format("{0}{1}", BackUpFileName, DataFile.Extension));
                    DataFile.CopyTo(strfilecopytoPath, true);

                    //本地添加备份日志
                    UIModels.DataBaseBackInfo newback = new UIModels.DataBaseBackInfo(strfilecopytoPath, BackUpFileName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), -1);
                    bolState = DataBackManager.Instance.AddBackRecord(newback);
                    if (!bolState)
                    {
                        strErrorMsgInfo = "本地记录备份日志错误!";
                    }
                    else
                    {
                        strErrorMsgInfo = "数据备份成功!";
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    strErrorMsgInfo = ex.Message;
                }
            }
            else
            {
                strErrorMsgInfo = "无法找到备份所需的数据库文件,请确定系统配置路径正确!";
            }
            if (BackEndEvent != null)
            {
                BackEndEvent(bolState, strErrorMsgInfo);
            }
        }
예제 #6
0
        /// <summary>
        /// 创建备份版本现场执行操作
        /// </summary>
        private void CreatebackvesionThread()
        {
            bool bolState = false;
            string strErrorMsgInfo = "备份发生错误!";
            string DbFilePath = KPS.DBUtility.DbHelperOleDb.getDBPath();
            if (File.Exists(DbFilePath))
            {
                try
                {
                    #region 执行备份操作
                    string strExePath = System.Windows.Forms.Application.StartupPath;//当前程序目录
                    string strBackupDirPath = Path.Combine(strExePath, "DataBack");
                    if (!Directory.Exists(strBackupDirPath))
                    {
                        //文件夹不存在则创建
                        Directory.CreateDirectory(strBackupDirPath);
                    }

                    string BackUpFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    FileInfo DataFile = new FileInfo(DbFilePath);

                    //复制备份文件
                    string strfilecopytoPath = Path.Combine(strBackupDirPath, string.Format("{0}{1}", BackUpFileName, DataFile.Extension));
                    DataFile.CopyTo(strfilecopytoPath, true);

                    //本地添加备份日志
                    UIModels.DataBaseBackInfo newback = new UIModels.DataBaseBackInfo(strfilecopytoPath, BackUpFileName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), -1);
                    bolState = DataBackManager.Instance.AddBackRecord(newback);
                    if (!bolState)
                    {
                        strErrorMsgInfo = "本地记录备份日志错误!";
                    }
                    else
                    {
                        strErrorMsgInfo = "数据备份成功!";
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    strErrorMsgInfo = ex.Message;
                }
            }
            else
            {
                strErrorMsgInfo = "无法找到备份所需的数据库文件,请确定系统配置路径正确!";
            }
            if (BackEndEvent != null)
            {
                BackEndEvent(bolState, strErrorMsgInfo);
            }
        }
예제 #7
0
 /// <summary>
 /// 还原数据库至本地的一个版本
 /// </summary>
 /// <param name="_backrecord">本地备份版本信息</param>
 public void RestoreByLocalVesion(UIModels.DataBaseBackInfo backrecordinfo)
 {
     _backrecord = backrecordinfo;
     System.Threading.Thread restoreToVesionthread = new System.Threading.Thread(new System.Threading.ThreadStart(RestoreThread));
     restoreToVesionthread.IsBackground = true;
     restoreToVesionthread.Start();
 }
예제 #8
0
        /// <summary>
        /// 获取数据库备份记录
        /// </summary>
        /// <returns></returns>
        public List<UIModels.DataBaseBackInfo> GetDataBackRecords()
        {
            if (recordlist== null)
            {
                if (System.IO.File.Exists("DataBaseBackLog.xml"))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load("DataBaseBackLog.xml");

                    //<Record No="1" FileName="aa" UpTime=""></Record>
                    XmlNodeList retrunDataList = doc.GetElementsByTagName("Record"); //取得节点名为Record的XmlNode集合
                    if (retrunDataList != null && retrunDataList.Count > 0)
                    {
                        recordlist = new List<UIModels.DataBaseBackInfo>();
                        UIModels.DataBaseBackInfo _backrecord = null;
                        foreach (XmlNode _node in retrunDataList)
                        {
                            _backrecord = new UIModels.DataBaseBackInfo();
                            _backrecord.BackDataFileName = _node.Attributes["FileName"].Value;
                            _backrecord.DataBackTime = _node.Attributes["UpTime"].Value;
                            _backrecord.SortNo = Convert.ToInt32(_node.Attributes["No"].Value);
                            _backrecord.DataFilePath = _node.InnerText;

                            recordlist.Add(_backrecord);
                        }
                    }
                }
            }
            return recordlist;
        }