using Learun.Util;
using System.Data;
using Learun.Application.TwoDevelopment.LR_Desktop;
using System.Web.Mvc;
using System.Collections.Generic;
using System;
using Hangfire;
namespace Learun.Application.Web.Areas.LR_Desktop.Controllers
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2019-06-26 15:35
/// 描 述:数据库备份设置
///
public class Sys_DataBaseBackupSetController : MvcControllerBase
{
private Sys_DataBaseBackupSetIBLL sys_DataBaseBackupSetIBLL = new Sys_DataBaseBackupSetBLL();
#region 视图功能
///
/// 主页面
///
///
[HttpGet]
public ActionResult Index()
{
return View();
}
///
/// 表单页
///
///
[HttpGet]
public ActionResult Form()
{
return View();
}
#endregion
#region 获取数据
///
/// 获取页面显示列表数据
///
/// 查询参数
///
[HttpGet]
[AjaxOnly]
public ActionResult GetPageList(string pagination, string queryJson)
{
Pagination paginationobj = pagination.ToObject();
var data = sys_DataBaseBackupSetIBLL.GetPageList(paginationobj, queryJson);
var jsonData = new
{
rows = data,
total = paginationobj.total,
page = paginationobj.page,
records = paginationobj.records
};
return Success(jsonData);
}
///
/// 获取表单数据
///
///
[HttpGet]
[AjaxOnly]
public ActionResult GetFormData(string keyValue)
{
var Sys_DataBaseBackupSetData = sys_DataBaseBackupSetIBLL.GetSys_DataBaseBackupSetEntity(keyValue);
var jsonData = new
{
Sys_DataBaseBackupSet = Sys_DataBaseBackupSetData,
};
return Success(jsonData);
}
#endregion
#region 提交数据
///
/// 删除实体数据
/// 主键
///
///
[HttpPost]
[AjaxOnly]
public ActionResult DeleteForm(string keyValue)
{
try
{
RecurringJob.RemoveIfExists(keyValue);
sys_DataBaseBackupSetIBLL.DeleteEntity(keyValue);
return Success("删除成功!");
}
catch (Exception e)
{
return Success("删除成功!");
}
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
[HttpPost]
[ValidateAntiForgeryToken]
[AjaxOnly]
public ActionResult SaveForm(string keyValue, string strEntity)
{
try
{
var loginUserInfo = LoginUserInfo.Get();
Sys_DataBaseBackupSetEntity entity = strEntity.ToObject();
entity.CreateUserId = loginUserInfo.userId;
entity.CreateUserName = loginUserInfo.realName;
entity.CreateTime = DateTime.Now;
if (sys_DataBaseBackupSetIBLL.GetRecordCount() <= 1)
{
sys_DataBaseBackupSetIBLL.SaveEntity(keyValue, entity);
RecurringJob.RemoveIfExists(entity.Id);
if (entity.EnabledMark == 1)
{
if (entity.BackupType == 0)
{
RecurringJob.AddOrUpdate(entity.Id,
() => sys_DataBaseBackupSetIBLL.AutoBackUp(),
Cron.Daily(Convert.ToInt32(entity.Time.Split(':')[0]), Convert.ToInt32(entity.Time.Split(':')[1])), TimeZoneInfo.Local);
}
if (entity.BackupType == 1)
{
Enum.TryParse(entity.Week.ToString(), out DayOfWeek dayOfWeek);
RecurringJob.AddOrUpdate(entity.Id,
() => sys_DataBaseBackupSetIBLL.AutoBackUp(),
Cron.Weekly(dayOfWeek, Convert.ToInt32(entity.Time.Split(':')[0]), Convert.ToInt32(entity.Time.Split(':')[1])),TimeZoneInfo.Local);
}
}
return Success("保存成功!");
}
else
{
return Fail("已设置备份方式,只能设置一种备份方式!");
}
}
catch (Exception e)
{
return Success("保存成功!");
}
}
#endregion
#region 扩展数据
///
/// 获取周
///
[HttpGet]
[AjaxOnly]
public ActionResult GetWeek()
{
var data = WebHelper.GenerateWeek();
return Success(data);
}
#endregion
}
}