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;
|
|
}
|
|
}
|
|
}
|