private void btnBackup_Click(object sender, RoutedEventArgs e)
        {
            backupTask = new Task(() =>
            {
                try
                {
                    //创建temp 目录
                    CreateDir(AppPath.TempDirPath);
                    //1、读取选择的项目的测试数据,包括人员信息和测试数据
                    List<TB_TestManager> checkedTestManager = testManagerList.FindAll(x => x.IsChecked == true);
                    Converter<TB_TestManager, int> testManagerIDConverter = new Converter<TB_TestManager, int>((TB_TestManager manager) =>
                    {
                        return manager.ID;
                    });
                    int[] checkedTestManagerIDs = checkedTestManager.ConvertAll<int>(testManagerIDConverter).ToArray();
                    string testManagerIDs = string.Join(",", checkedTestManagerIDs);
                    List<TB_AthleteInfo> athList = (new BLL.TB_AthleteInfo()).GetModelList(string.Format("ath_testid in ({0})", testManagerIDs));
                    Converter<TB_AthleteInfo, int> athIDConverter = new Converter<TB_AthleteInfo, int>((TB_AthleteInfo ath) =>
                    {
                        return ath.ID;
                    });
                    string athIDs = string.Join(",", athList.ConvertAll<int>(athIDConverter).ToArray());
                    List<TB_TestInfo> testInfoList = (new BLL.TB_TestInfo()).GetModelList(string.Format("ath_id in ({0})", athIDs));
                    //2、复制空数据库文件,复制数据xml文件
                    File.Copy(AppPath.DataPath + AppPath.EmptyDBName, AppPath.TempDirPath + AppPath.DBName);
                    //3、往空数据库文件中写入数据
                    DBUtility.DbHelperOleDb.SetDBPath(AppPath.TempDirPath + AppPath.DBName);//------------------

                    //4、创建压缩窗口,设置DataFilePath属性,并启动,Invoke
                    this.Dispatcher.Invoke(new Action(() => {
                        CompressProgress compress = new CompressProgress();
                        compress.DataFilePath = AppPath.TempDirPath;
                        compress.OutputPath = backFileName;
                        if (compress.ShowDialog() == true)
                        {
                            //删除temp目录
                            DeleteTempDir();
                            MessageBoxTool.ShowConfirmMsgBox("备份成功!");
                            this.Close();
                        }
                    }));
                }
                catch (Exception ee)
                {
                    MessageBoxTool.ShowConfirmMsgBox(string.Format("备份出现错误!\r\n异常类型:{0}\r\n异常信息:{1}", ee.GetType().ToString(), ee.Message));
                }

            });
            backupTask.Start();
            btnBackup.IsEnabled = btnChangeFolder.IsEnabled = false;
            btnCancle.IsEnabled = true;
        }
Esempio n. 2
0
        private void btnBackup_Click(object sender, RoutedEventArgs e)
        {
            backupTask = new Task(() =>
            {
                try
                {
                    //创建temp 目录
                    CreateDir(AppPath.TempDirPath);
                    //1、读取选择的项目的测试数据,包括人员信息和测试数据
                    List <TB_TestManager> checkedTestManager = testManagerList.FindAll(x => x.IsChecked == true);
                    Converter <TB_TestManager, int> testManagerIDConverter = new Converter <TB_TestManager, int>((TB_TestManager manager) =>
                    {
                        return(manager.ID);
                    });
                    int[] checkedTestManagerIDs   = checkedTestManager.ConvertAll <int>(testManagerIDConverter).ToArray();
                    string testManagerIDs         = string.Join(",", checkedTestManagerIDs);
                    List <TB_AthleteInfo> athList = (new BLL.TB_AthleteInfo()).GetModelList(string.Format("ath_testid in ({0})", testManagerIDs));
                    Converter <TB_AthleteInfo, int> athIDConverter = new Converter <TB_AthleteInfo, int>((TB_AthleteInfo ath) =>
                    {
                        return(ath.ID);
                    });
                    string athIDs = string.Join(",", athList.ConvertAll <int>(athIDConverter).ToArray());
                    List <TB_TestInfo> testInfoList = (new BLL.TB_TestInfo()).GetModelList(string.Format("ath_id in ({0})", athIDs));
                    //2、复制空数据库文件,复制数据xml文件
                    File.Copy(AppPath.DataPath + AppPath.EmptyDBName, AppPath.TempDirPath + AppPath.DBName);
                    //3、往空数据库文件中写入数据
                    DBUtility.DbHelperOleDb.SetDBPath(AppPath.TempDirPath + AppPath.DBName);//------------------

                    //4、创建压缩窗口,设置DataFilePath属性,并启动,Invoke
                    this.Dispatcher.Invoke(new Action(() => {
                        CompressProgress compress = new CompressProgress();
                        compress.DataFilePath     = AppPath.TempDirPath;
                        compress.OutputPath       = backFileName;
                        if (compress.ShowDialog() == true)
                        {
                            //删除temp目录
                            DeleteTempDir();
                            MessageBoxTool.ShowConfirmMsgBox("备份成功!");
                            this.Close();
                        }
                    }));
                }
                catch (Exception ee)
                {
                    MessageBoxTool.ShowConfirmMsgBox(string.Format("备份出现错误!\r\n异常类型:{0}\r\n异常信息:{1}", ee.GetType().ToString(), ee.Message));
                }
            });
            backupTask.Start();
            btnBackup.IsEnabled = btnChangeFolder.IsEnabled = false;
            btnCancle.IsEnabled = true;
        }
Esempio n. 3
0
        //备份
        private void btnBackup_Click(object sender, RoutedEventArgs e)
        {
            if (txtBackupName.Text.Trim() == "")
            {
                MessageBoxTool.ShowConfirmMsgBox("备份名称不能为空,请重新输入!");
                return;
            }
            string fileName = txtBackupName.Text.Trim() + "-" + DateTime.Now.ToString("yyyyMMdd");

            SaveFileDialog ofd = new SaveFileDialog();
            ofd.Title = "请选择保存文件的路径";
            ofd.DefaultExt = "zip";
            ofd.FileName = fileName;
            ofd.OverwritePrompt = true;
            ofd.AddExtension = true;
            ofd.Filter = "等速肌力数据库备份文件(*.zip)|*.zip";
            if (ofd.ShowDialog()== true)
            {
                string path = ofd.FileName;
                try
                {
                    CompressProgress progressWindow = new CompressProgress();
                    progressWindow.OutputPath = path;
                    progressWindow.Owner = Application.Current.MainWindow;
                    progressWindow.ShowDialog();

                    Model.TB_BackupInfo backInfo = new Model.TB_BackupInfo();
                    backInfo.BackupDate = DateTime.Now.ToString("yyyy-MM-dd");
                    backInfo.BackupName = txtBackupName.Text.Trim();
                    backInfo.BackupPath = path;
                    backInfoBLL.Add(backInfo);
                    ReloadData();
                    txtBackupName.Text = "";

                    MessageBoxTool.ShowConfirmMsgBox("备份成功!");

                }
                catch (Exception ee)
                {
                    MessageBoxTool.ShowErrorMsgBox("备份出错,请稍候重试!\r\n" + ee.Message);

                }
            }
        }