/// <summary> /// 创建自动备份数据库计划 /// </summary> /// <param name="entity">实体参数</param> /// <param name="_Mode">执行方式</param> /// <param name="_StartTime">执行时间</param> public void CreateDbBackup(Base_BackupJob entity, string _Mode, string _StartTime) { IDatabase database = DataFactory.Database(); DbTransaction isOpenTrans = database.BeginTrans(); try { int IsOk = DataFactory.Database().Insert(entity, isOpenTrans); if (IsOk > 0) { //调用执行备份计划存储过程 List<DbParameter> parameter = new List<DbParameter>(); parameter.Add(DbFactory.CreateDbParameter("@ServerName", entity.ServerName)); parameter.Add(DbFactory.CreateDbParameter("@DbName", entity.DbName)); parameter.Add(DbFactory.CreateDbParameter("@JobName", entity.JobName)); parameter.Add(DbFactory.CreateDbParameter("@FilePath", entity.FilePath)); parameter.Add(DbFactory.CreateDbParameter("@DispatchType", _Mode)); parameter.Add(DbFactory.CreateDbParameter("@StartTime", _StartTime)); DataFactory.Database().ExecuteByProc("Proc_CreateBackJob", parameter.ToArray(), isOpenTrans); } DataFactory.Database().Commit(); } catch { database.Rollback(); database.Close(); throw; } }
/// <summary> /// 新增备份计划 /// </summary> /// <param name="entity"></param> /// <param name="_Mode"></param> /// <param name="_StartTime"></param> /// <returns></returns> public ActionResult AddDbBackup(Base_BackupJob entity, string _Mode, string _StartTime) { try { entity.FilePath = entity.FilePath; entity.Create(); base_databasebll.CreateDbBackup(entity, _Mode, _StartTime); return Content(new JsonMessage { Success = true, Code = "1", Message = "操作成功" }.ToString()); } catch (Exception ex) { return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString()); } }