You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using FireBirdUtil.SqlUtils;
using WeighBusiness.BO.CreateTables;
namespace WeighBusiness.Utils
{
public class BackupUtil
{
/// <summary>
/// 创建备份数据库
/// </summary>
/// <returns>失败则返回失败信息。</returns>
public static string CreateDataBaseAndTable()
{
try
{
string errorMessage;
var success = CreateDataBaseIfNotExist(out errorMessage);
if (!success)
{
return "备份数据库创建失败" + Environment.NewLine + errorMessage;
}
success = CreateTableIfNotExist(out errorMessage);
if (!success)
return "备份数据表创建失败" + Environment.NewLine + errorMessage;
}
catch (Exception ex)
{
return "在创建备份数据库时碰到错误:" + ex.Message;
}
return string.Empty;
}
static bool CreateDataBaseIfNotExist(out string errorMessage)
{
errorMessage = string.Empty;
try
{
var folder = new FileInfo(TableNames._backup).Directory.FullName;
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
SQLExecuteUtil.CreateDataBaseIfNotExist(TableNames._backup);
return true;
}
catch (Exception ex)
{
errorMessage = ex.ToString();
return false;
}
}
static bool CreateTableIfNotExist(out string errorMessage)
{
if (!new CreateProductCatalog(TableNames._backup,TableNames.).Create(out errorMessage))
return false;
if (!new CreateSelectedProductCatalogGoods(TableNames._backup, TableNames.).Create(out errorMessage))
return false;
return true;
}
}
}