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.

Sys_DataBaseBackupSetController.cs 5.5 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using Learun.Util;
  2. using System.Data;
  3. using Learun.Application.TwoDevelopment.LR_Desktop;
  4. using System.Web.Mvc;
  5. using System.Collections.Generic;
  6. using System;
  7. using Hangfire;
  8. namespace Learun.Application.Web.Areas.LR_Desktop.Controllers
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  12. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2019-06-26 15:35
  15. /// 描 述:数据库备份设置
  16. /// </summary>
  17. public class Sys_DataBaseBackupSetController : MvcControllerBase
  18. {
  19. private Sys_DataBaseBackupSetIBLL sys_DataBaseBackupSetIBLL = new Sys_DataBaseBackupSetBLL();
  20. #region 视图功能
  21. /// <summary>
  22. /// 主页面
  23. /// <summary>
  24. /// <returns></returns>
  25. [HttpGet]
  26. public ActionResult Index()
  27. {
  28. return View();
  29. }
  30. /// <summary>
  31. /// 表单页
  32. /// <summary>
  33. /// <returns></returns>
  34. [HttpGet]
  35. public ActionResult Form()
  36. {
  37. return View();
  38. }
  39. #endregion
  40. #region 获取数据
  41. /// <summary>
  42. /// 获取页面显示列表数据
  43. /// <summary>
  44. /// <param name="queryJson">查询参数</param>
  45. /// <returns></returns>
  46. [HttpGet]
  47. [AjaxOnly]
  48. public ActionResult GetPageList(string pagination, string queryJson)
  49. {
  50. Pagination paginationobj = pagination.ToObject<Pagination>();
  51. var data = sys_DataBaseBackupSetIBLL.GetPageList(paginationobj, queryJson);
  52. var jsonData = new
  53. {
  54. rows = data,
  55. total = paginationobj.total,
  56. page = paginationobj.page,
  57. records = paginationobj.records
  58. };
  59. return Success(jsonData);
  60. }
  61. /// <summary>
  62. /// 获取表单数据
  63. /// <summary>
  64. /// <returns></returns>
  65. [HttpGet]
  66. [AjaxOnly]
  67. public ActionResult GetFormData(string keyValue)
  68. {
  69. var Sys_DataBaseBackupSetData = sys_DataBaseBackupSetIBLL.GetSys_DataBaseBackupSetEntity(keyValue);
  70. var jsonData = new
  71. {
  72. Sys_DataBaseBackupSet = Sys_DataBaseBackupSetData,
  73. };
  74. return Success(jsonData);
  75. }
  76. #endregion
  77. #region 提交数据
  78. /// <summary>
  79. /// 删除实体数据
  80. /// <param name="keyValue">主键</param>
  81. /// <summary>
  82. /// <returns></returns>
  83. [HttpPost]
  84. [AjaxOnly]
  85. public ActionResult DeleteForm(string keyValue)
  86. {
  87. try
  88. {
  89. RecurringJob.RemoveIfExists(keyValue);
  90. sys_DataBaseBackupSetIBLL.DeleteEntity(keyValue);
  91. return Success("删除成功!");
  92. }
  93. catch (Exception e)
  94. {
  95. return Success("删除成功!");
  96. }
  97. }
  98. /// <summary>
  99. /// 保存实体数据(新增、修改)
  100. /// <param name="keyValue">主键</param>
  101. /// <summary>
  102. /// <returns></returns>
  103. [HttpPost]
  104. [ValidateAntiForgeryToken]
  105. [AjaxOnly]
  106. public ActionResult SaveForm(string keyValue, string strEntity)
  107. {
  108. try
  109. {
  110. var loginUserInfo = LoginUserInfo.Get();
  111. Sys_DataBaseBackupSetEntity entity = strEntity.ToObject<Sys_DataBaseBackupSetEntity>();
  112. entity.CreateUserId = loginUserInfo.userId;
  113. entity.CreateUserName = loginUserInfo.realName;
  114. entity.CreateTime = DateTime.Now;
  115. if (sys_DataBaseBackupSetIBLL.GetRecordCount() <= 1)
  116. {
  117. sys_DataBaseBackupSetIBLL.SaveEntity(keyValue, entity);
  118. RecurringJob.RemoveIfExists(entity.Id);
  119. if (entity.EnabledMark == 1)
  120. {
  121. if (entity.BackupType == 0)
  122. {
  123. RecurringJob.AddOrUpdate(entity.Id,
  124. () => sys_DataBaseBackupSetIBLL.AutoBackUp(),
  125. Cron.Daily(Convert.ToInt32(entity.Time.Split(':')[0]), Convert.ToInt32(entity.Time.Split(':')[1])), TimeZoneInfo.Local);
  126. }
  127. if (entity.BackupType == 1)
  128. {
  129. Enum.TryParse(entity.Week.ToString(), out DayOfWeek dayOfWeek);
  130. RecurringJob.AddOrUpdate(entity.Id,
  131. () => sys_DataBaseBackupSetIBLL.AutoBackUp(),
  132. Cron.Weekly(dayOfWeek, Convert.ToInt32(entity.Time.Split(':')[0]), Convert.ToInt32(entity.Time.Split(':')[1])),TimeZoneInfo.Local);
  133. }
  134. }
  135. return Success("保存成功!");
  136. }
  137. else
  138. {
  139. return Fail("已设置备份方式,只能设置一种备份方式!");
  140. }
  141. }
  142. catch (Exception e)
  143. {
  144. return Success("保存成功!");
  145. }
  146. }
  147. #endregion
  148. #region 扩展数据
  149. /// <summary>
  150. /// 获取周
  151. /// </summary>
  152. [HttpGet]
  153. [AjaxOnly]
  154. public ActionResult GetWeek()
  155. {
  156. var data = WebHelper.GenerateWeek();
  157. return Success(data);
  158. }
  159. #endregion
  160. }
  161. }