You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.6 KiB
C#
118 lines
3.6 KiB
C#
using Server.Factory;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using Utils;
|
|
using VM;
|
|
|
|
namespace Web
|
|
{
|
|
public class DataInit
|
|
{
|
|
|
|
/// <summary>
|
|
/// 初始化课时安排
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
public static int AddMessageClassSchedule(int userId)
|
|
{
|
|
int result = SvrFactory.Instance.TrainingSvr.AddMessageClassSchedule(userId);
|
|
return result;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化银行存蓄数据
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <returns></returns>
|
|
public static int AddBankDeposits(int userId)
|
|
{
|
|
int result = SvrFactory.Instance.TrainingSvr.AddBankDeposits(userId);
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 创建备份文件
|
|
/// </summary>
|
|
public static void CreateDataBak()
|
|
{
|
|
|
|
string fileUrl = System.Threading.Thread.GetDomain().BaseDirectory + AppSettingsHelper.GetStringByKey("DataBackUp", "/DataBackUpFiles") + "\\";
|
|
SvrFactory.Instance.TrainingSvr.DataBaseBackup(fileUrl);
|
|
DateTime t1 = DateTime.Now;
|
|
DateTime t2 = DateTime.Now.AddDays(-7);
|
|
var da = Convert.ToInt32(DateTime.Now.DayOfWeek);
|
|
if (da == 0)
|
|
{
|
|
da = 7;
|
|
}
|
|
var te = DateTime.Now.AddDays(-da);
|
|
DataBackOperateVM model = SvrFactory.Instance.TrainingSvr.GetDataBackOperate();
|
|
|
|
|
|
|
|
if (model == null)
|
|
{
|
|
DataBackOperate(fileUrl);
|
|
}
|
|
//星期一重启,星期天要更新
|
|
else //model.CreateTime < t2
|
|
{
|
|
//时间差
|
|
if (model.CreateTime.ToString("yyyy-MM-dd") != te.ToString("yyyy-MM-dd") || t1.DayOfWeek == 0)
|
|
{
|
|
DataBackOperate(fileUrl);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private static void DataBackOperate(string fileUrl)
|
|
{
|
|
SvrFactory.Instance.TrainingSvr.DataBaseBackup(fileUrl);
|
|
DateTime t1 = DateTime.Now;
|
|
string[] DataNameList = { "FPBT_Training_V1.1[" + t1.ToString("yyyy-MM-dd") + "].bak",
|
|
"FPBT_Structure_V1.1[" + t1.ToString("yyyy-MM-dd") + "].bak",
|
|
"FPBT_Resource_V1.1["+ t1.ToString("yyyy-MM-dd") + "].bak",
|
|
"FPBT_Exam_V1.1["+t1.ToString("yyyy-MM-dd") + "].bak",
|
|
"Description.txt"
|
|
};
|
|
foreach (var file in Directory.GetFiles(fileUrl))
|
|
{
|
|
var filename = Path.GetFileName(file);
|
|
if (!DataNameList.Contains(filename))
|
|
{
|
|
File.Delete(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
///// <summary>
|
|
///// 删除备份文件
|
|
///// </summary>
|
|
//public static void DelFolderBakFile()
|
|
//{
|
|
// string ext = ".bak";
|
|
// string s = System.Threading.Thread.GetDomain().BaseDirectory;
|
|
// var DataPath = s + AppSettingsHelper.GetStringByKey("DataBackUp", "/DataBackUpFiles") + "\\";
|
|
|
|
// foreach (var file in Directory.GetFiles(DataPath))
|
|
// {
|
|
// if (Path.GetExtension(file) == ext)
|
|
// {
|
|
// File.Delete(file);
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
}
|
|
} |