计划任务配置管理页面

发表于:2018-8-16 11:31

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:哥屋恩0528    来源:CSDN

  //计划配置页面
  public ActionResult PlanManager()
  {
  Session[MyConst.StartTime] = DateTime.Now.ToString();
  SysLogModel sysModel = new SysLogModel()
  {
  Action = "计划任务配置",
  Content = "浏览计划",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  List<PlanModel> model = new List<PlanModel>();
  model = SearchPlanData("", "", "");
  InitPlan("");
  return View(model);
  }
  //计划配置页的提交,这里是“查询”,其参数是POST方式传递过来的,参数名是控件(input\select等)的name属性
  [HttpPost]
  public ActionResult PlanManager(string startTime, string endTime, string PlanName)
  {
  SysLogModel sysModel = new SysLogModel()
  {
  Action = "计划任务配置",
  Content = "查询计划",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  List<PlanModel> model = new List<PlanModel>();
  model = SearchPlanData(startTime, endTime, PlanName);
  InitPlan("");
  return View(model);
  }
  [NonAction]
  private List<PlanModel> SearchPlanData(string startTime, string endTime, string PlanName)
  {
  SystemManager syMan = new SystemManager();
  if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime)) //有起止日期
  {
  ViewBag.startTime = startTime;
  ViewBag.endTime = Convert.ToDateTime(endTime).AddDays(1).ToShortDateString().Replace("/", "-");
  }
  else if (!string.IsNullOrEmpty(startTime) && string.IsNullOrEmpty(endTime)) //有开始日期
  {
  ViewBag.startTime = startTime;
  ViewBag.endTime = Convert.ToDateTime(startTime).AddDays(1).ToShortDateString().Replace("/", "-");
  }
  else if (string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime)) //有结束日期
  {
  ViewBag.startTime = Convert.ToDateTime(startTime).AddDays(-1).ToShortDateString().Replace("/", "-");
  ViewBag.endTime = endTime;
  }
  List<PlanModel> List = syMan.GetPlanData(ViewBag.startTime, ViewBag.endTime, PlanName);
  return List;
  }
  //编辑View
  public ActionResult EditPlan(string ActionType, string TaskID, string id)
  {
  #region
  PlanModel model = new PlanModel();
  Session[MyConst.StartTime] = DateTime.Now;
  ViewBag.ActionType = ActionType;
  ViewBag.PlanID = id;
  ViewBag.TaskID = TaskID;
  string ActionContent = string.Empty;
  if (ActionType == "Create")
  {
  ActionContent = "添加任务配置";
  ViewBag.TaskID = 0;
  model.PlanBeginTime = Convert.ToDateTime(DateTime.Now.ToString());  //新增时开始时间为系统当前时间
  }
  else if (ActionType == "Edit")
  {
  ActionContent = "编辑任务配置";
  model = syMan.GetPlanDataByID(id);
  ViewBag.TaskID = model.TaskID;
  }
  else if (ActionType == "View")
  {
  ActionContent = "任务配置详情";
  model = syMan.GetPlanDataByID(id);
  ViewBag.TaskID = model.TaskID;
  }
  //添加日志
  SysLogModel sysModel = new SysLogModel()
  {
  Action = "计划任务配置",
  Content = ActionContent,
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  InitPlan(model.Sn);
  return View(model);
  #endregion
  }
  //初始化时需要的数据
  [NonAction]
  public void InitPlan(string Sn)
  {
  AreaManager arMan = new AreaManager();
  ViewBag.Provinces = CommonTools.GetAreaSelectList(arMan.GetAreas());
  OwnerManager oMan = new OwnerManager();
  ViewBag.Owners = CommonTools.GetOwnerSelectList(oMan.GetAllOwners(""));
  InvestorManager iMan = new InvestorManager();
  ViewBag.Investors = CommonTools.GetInvestorSelectList(iMan.GetAllInvestors(""));
  UnitsManager uMan = new UnitsManager();
  ViewBag.Units = CommonTools.GetUnitsSelectList(uMan.GetAllUnits(""));
  ContractorInfoManager cMan = new ContractorInfoManager();
  ViewBag.Contractors = CommonTools.GetContractorSelectList(cMan.GetAllContractor(""));
  StationInfoManager staInfoMan = new StationInfoManager();
  List<StationInfoModel> stationLists = staInfoMan.GetStations();
  ViewBag.Stations = CommonTools.GetStationSelectList(stationLists.FindAll(t => t.IsUsing != 0)); //获取下拉框数据,电站信息
  //List<TaskModel> taskLists = syMan.GetTaskData("", "","", "", "List");
  //ViewBag.Tasks = CommonTools.GetTaskSelectList(taskLists); //获取下拉框数据,任务配置信息
  ViewBag.PlanIntervalsList = PlanIntervalsSelectList();    //任务类型下拉框数据源
  ViewBag.PlanReceiveMethodsList = PlanReceiveMethodsSelectList();    //接收方式下拉框数据源
  ViewBag.ExecutionIntervalTypeSelectList = ExecutionIntervalTypeSelectList();    //时间间隔下拉框数据源
  ViewBag.ExecutionDayList = ExecutionDayList();    //每月日期数下拉框数据源
  ViewBag.ExecutionWeekList = ExecutionWeekSelectList();    //一周星期数下拉框数据源
  #region 接收人下拉框数据源,获取电站用户
  AccountManager userMan = new AccountManager();
  GroupManager groupMan = new GroupManager();
  List<GroupModel> groupList = groupMan.GetGroups();  //获取所有用户组
  if (!string.IsNullOrEmpty(Sn))
  {
  List<GroupModel> groups = groupList.FindAll(f => f.OwnerID == staInfoMan.GetStationBySN(Sn).OwnModel.ID);    //获取当前电站所属用户组
  ViewBag.PlanReceiverList = CommonTools.GetUserSelectList(userMan.GetUsers().FindAll(u => groups.Contains(u.UserGroup))); //接收人下拉框数据源,获取电站用户
  }
  else
  {
  //ViewBag.PlanReceiverList = "";
  ViewBag.PlanReceiverList = CommonTools.GetUserSelectList(userMan.GetUsers());
  }
  #endregion
  }
  //编辑,Post方法
  [HttpPost]
  public ActionResult EditPlan(PlanModel model, string ActionType)
  {
  #region
  string strContent = string.Empty;
  if (ActionType == "Create")
  {
  strContent = "添加";
  ViewBag.ActionType = "Create";
  }
  else
  {
  strContent = "修改";
  ViewBag.ActionType = "Edit";
  }
  ViewBag.ErrorMsg = string.Empty;
  if (string.IsNullOrEmpty(model.PlanName))
  {
  ViewBag.ErrorMsg += "<label>请输入计划名称!</label><br/>";
  }
  if (string.IsNullOrEmpty(model.Sn))
  {
  ViewBag.ErrorMsg += "<label>请选择电站!</label><br/>";
  }
  else
  {
  InitPlan(model.Sn.Split(',')[0]);
  }
  if (string.IsNullOrEmpty(model.PlanBeginTime.ToString()))
  {
  ViewBag.ErrorMsg += "<label>请选择开始时间!</label><br/>";
  }
  if (string.IsNullOrEmpty(model.PlanReceiver))
  {
  ViewBag.ErrorMsg += "<label>请输入接收人!</label><br/>";
  }
  if (string.IsNullOrEmpty(model.PlanName))
  {
  ViewBag.ErrorMsg += "<label>请输入接收方式!</label><br/>";
  }
  #region 验证执行频率并赋值
  if (!string.IsNullOrEmpty(model.PlanInterval))
  {
  string PlanInterval = model.PlanInterval;       //执行间隔(频率)
  #region
  if (PlanInterval == "0")        //实时
  {
  model.ExecutionInterval = model.ExecutionInterval_InTime;             //每天频率/执行间隔
  model.ExecutionIntervalType = model.ExecutionIntervalType_InTime;     //每天执行间隔类型,注:时、分、秒
  model.ExecutionTime_EveryDayType = null;    //每天频率类型,注:执行一次、执行间隔
  model.ExecutionWeek = null;                 //执行星期数
  model.ExecutionDay = null;                  //执行日期数
  model.ExecutionTime_Hours = null;           //执行时间小时数
  model.ExecutionTime_Minutes = null;         //执行时间分钟数
  model.ExecutionTime_Seconds = null;         //执行时间秒数
  }
  else if (PlanInterval == "1")   //每天
  {
  #region 验证执行时分秒
  if (model.ExecutionTime_EveryDayType == "OneTime") //每天频率类型:执行一次
  {
  #region
  if (!string.IsNullOrEmpty(model.ExecutionTime_DayHours)) //小时数
  {
  model.ExecutionTime_Hours = model.ExecutionTime_DayHours;
  }
  else
  {
  ViewBag.ErrorMsg += "<label>请选择执行时间小时数!</label><br/>";
  }
  if (!string.IsNullOrEmpty(model.ExecutionTime_DayMinutes)) //分钟数
  {
  model.ExecutionTime_Minutes = model.ExecutionTime_DayMinutes;
  }
  else
  {
  ViewBag.ErrorMsg += "<label>请选择执行时间分钟数!</label><br/>";
  }
  if (!string.IsNullOrEmpty(model.ExecutionTime_DaySeconds)) //秒数
  {
  model.ExecutionTime_Seconds = model.ExecutionTime_DaySeconds;
  }
  else
  {
  ViewBag.ErrorMsg += "<label>请选择执行时间秒数!</label><br/>";
  }
  model.ExecutionInterval = null; //每天频率/执行间隔
  model.ExecutionIntervalType = null; //每天执行间隔类型,注:时、分、秒
  #endregion
  }
  else //每天频率:执行间隔
  {
  #region
  if (!string.IsNullOrEmpty(model.ExecutionInterval))  //每天频率/执行间隔
  {
  model.ExecutionInterval = model.ExecutionInterval;
  }
  else
  {
  ViewBag.ErrorMsg += "<label>请选择每天频率的执行间隔!</label><br/>";
  }
  model.ExecutionIntervalType = model.ExecutionIntervalType; //每天执行间隔类型,注:时、分、秒
  model.ExecutionTime_Hours = null;           //执行时间小时数
  model.ExecutionTime_Minutes = null;         //执行时间分钟数
  model.ExecutionTime_Seconds = null;         //执行时间秒数
  #endregion
  }
  #endregion
  model.ExecutionWeek = null; //执行星期数
  model.ExecutionDay = null;  //执行日期数
  }
  else //每周、每月
  {
  #region 验证执行时分秒
  if (!string.IsNullOrEmpty(model.ExecutionTime_Hours)) //小时数
  {
  model.ExecutionTime_Hours = model.ExecutionTime_Hours;
  }
  else
  {
  ViewBag.ErrorMsg += "<label>请选择执行时间小时数!</label><br/>";
  }
  if (!string.IsNullOrEmpty(model.ExecutionTime_Minutes)) //分钟数
  {
  model.ExecutionTime_Minutes = model.ExecutionTime_Minutes;
  }
  else
  {
  ViewBag.ErrorMsg += "<label>请选择执行时间分钟数!</label><br/>";
  }
  if (!string.IsNullOrEmpty(model.ExecutionTime_Seconds)) //秒数
  {
  model.ExecutionTime_Seconds = model.ExecutionTime_Seconds;
  }
  else
  {
  ViewBag.ErrorMsg += "<label>请选择执行时间秒数!</label><br/>";
  }
  #endregion
  #region
  if (PlanInterval == "2") //每周
  {
  model.ExecutionDay = null; //执行日期数
  model.ExecutionWeek = model.ExecutionWeek;
  }
  else if (PlanInterval == "3") //每月
  {
  model.ExecutionWeek = null; //执行星期数
  model.ExecutionDay = model.ExecutionDay;
  }
  model.ExecutionInterval = null;          //每天频率/执行间隔
  model.ExecutionIntervalType = null;      //每天执行间隔类型,注:时、分、秒
  model.ExecutionTime_EveryDayType = null; //每天频率类型,注:执行一次、执行间隔
  #endregion
  }
  #endregion
  }
  #endregion
  if (!string.IsNullOrEmpty(ViewBag.ErrorMsg)) //是否存在验证异常信息
  {
  InitPlan("");
  return View(model);
  }
  if (ModelState.IsValid)
  {
  model.PlanReceiver = Request.Form["PlanReceiver"];  //获取多选框值
  model.PlanReceiveMethod = Request.Form["PlanReceiveMethod"];  //获取多选框值
  if (string.IsNullOrEmpty(model.PlanReceiver)) //验证是否有接收人
  {
  StationInfoManager staMan = new StationInfoManager();
  model.SnName = new StationInfoManager().GetStations().Find(g => g.Sn == model.Sn.Split(',')[0]).Name;
  ViewBag.ErrorMsg = strContent + "失败,请给电站:" + model.SnName + "配置消息接收人!<br/>";
  //插入系统日志
  SysLogModel sysModel = new SysLogModel()
  {
  Action = strContent + "任务配置",
  Content = strContent + "失败",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  return View(model);
  }
  #region
  if (ActionType == "Create")   //新增操作
  {
  #region
  model.PlanMaker = (Session[MyConst.UserModel] as AccountModel).ID.ToString();
  List<PlanModel> list = syMan.GetPlanData("", "", "").FindAll(u => u.PlanName == model.PlanName);
  if (list != null && list.Count > 0) //验证是否重复
  {
  model.PlanReceiver = null;
  ViewBag.ErrorMsg += "<label>任务配置名称已存在!</label></br> ";
  //插入系统日志
  SysLogModel sysModel = new SysLogModel()
  {
  Action = strContent + "任务配置",
  Content = strContent + "失败",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  return View(model);
  }
  else
  {
  int result = syMan.InsertPlanData(model);   //新增数据
  //int result = 0; //测试用
  //插入系统日志
  SysLogModel sysModel = new SysLogModel()
  {
  Action = strContent + "任务配置",
  Content = result > 0 ? strContent + "成功" : strContent + "失败",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  if (result > 0)
  {
  return RedirectToAction("PlanManager", "SystemManager");
  }
  else
  {
  ViewBag.ErrorMsg = strContent + "失败";
  return View(model);
  }
  }
  #endregion
  }
  else //修改操作
  {
  #region
  model.PlanMaker = (Session[MyConst.UserModel] as AccountModel).ID.ToString();
  int result = syMan.ModifyPlanData(model);   //修改数据
  //int result = 0;   //测试用
  //插入系统日志
  SysLogModel sysModel1 = new SysLogModel()
  {
  Action = strContent + "任务配置",
  Content = result > 0 ? strContent + "成功" : strContent + "失败",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel1);
  if (result > 0)
  {
  return RedirectToAction("PlanManager", "SystemManager");
  }
  else
  {
  ViewBag.ErrorMsg = strContent + "失败";
  model = syMan.GetPlanDataByID(model.PlanID.ToString());
  return View(model);
  }
  #endregion
  }
  #endregion
  }
  else
  {
  ViewBag.ErrorMsg = strContent + "失败,请检查录入数据是否正确";
  //插入系统日志
  SysLogModel sysModel = new SysLogModel()
  {
  Action = strContent + "任务配置",
  Content = strContent + "失败",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  return View(model);
  }
  #endregion
  }
  //删除任务配置
  [HttpPost]
  public ContentResult PlanDelete(int id)
  {
  int result = syMan.DeletePlan(id);
  SysLogModel sysModel = new SysLogModel()
  {
  Action = "删除计划配置",
  Content = result > 0 ? "删除成功" : "删除失败",
  ModuleCode = "XTGL-XT-JHRW"
  };
  Syslog.InsertSYSLog(sysModel);
  if (result > 0)
  {
  return Content("ok");
  }
  else
  {
  return Content("");
  }
  }
  //获取电站所属用户,下拉框联动
  [HttpPost]
  public JsonResult GetPlanReceiverBySN(string strSn)
  {
  AccountManager userMan = new AccountManager();
  GroupManager groupMan = new GroupManager();
  List<SelectListItem> items = new List<SelectListItem>();
  StationInfoManager grpMan = new StationInfoManager();
  List<GroupModel> groupList = groupMan.GetGroups();  //获取所有用户组
  List<GroupModel> groups = groupList.FindAll(f => f.OwnerID == grpMan.GetStationBySN(strSn.Split(',')[0]).OwnModel.ID);    //获取当前电站所属用户组
  items.AddRange(CommonTools.GetUserSelectList(userMan.GetUsers().FindAll(u => groups.Contains(u.UserGroup))));   //获取当前电站所属用户
  return Json(items, JsonRequestBehavior.AllowGet);
  }
  #region 把枚举转换成数组
  /// <summary>
  /// 任务类型枚举
  /// </summary>
  public enum TaskTypes
  {
  系统通讯状态报警 = 0,
  电站设备故障报警 = 1,
  电站设备性能预警 = 2,
  生成电站月报报表=3,
  巡检提醒=4
  }
  /// <summary>
  /// 计划任务执行频率--时间间隔枚举
  /// </summary>
  public enum PlanIntervals
  {
  //实时推送 = 0,
  //每天推送一次 = 1,
  //每周推送一次 = 2,
  //每月推送一次 = 3
  实时推送 = 0,
  每天 = 1,
  每周 = 2,
  每月 = 3
  }
  /// <summary>
  /// 每天频率--执行间隔枚举
  /// </summary>
  public enum ExecutionInterval
  {
  时 = 0,
  分 = 1,
  秒 = 2
  }
  /// <summary>
  /// 一周的星期数
  /// </summary>
  public enum ExecutionWeek
  {
  星期日 = 0,
  星期一 = 1,
  星期二 = 2,
  星期三 = 3,
  星期四 = 4,
  星期五 = 5,
  星期六 = 6
  }
  /// <summary>
  /// 接收方式枚举
  /// </summary>
  public enum PlanReceiveMethods
  {
  邮件 = 0,
  微信 = 1
  }
  /// <summary>
  /// 获取每月日期数集合 IList
  /// </summary>
  public static IList ExecutionDayList()
  {
  List<SelectListItem> selectlist = new List<SelectListItem>();
  ArrayList list = new ArrayList();
  for (int i = 1; i <= 31;i++ )
  {
  ListItem listitem = new ListItem(i.ToString(), i.ToString());
  list.Add(listitem);
  }
  return list;
  }
  /// <summary>
  /// 将枚举转换成集合 IList
  /// </summary>
  /// <returns></returns>
  public static IList TaskTypesList()
  {
  List<SelectListItem> selectlist = new List<SelectListItem>();
  ArrayList list = new ArrayList();
  foreach (int i in Enum.GetValues(typeof(TaskTypes)))
  {
  ListItem listitem = new ListItem(Enum.GetName(typeof(TaskTypes), i), i.ToString());
  list.Add(listitem);
  }
  return list;
  }
  /// <summary>
  /// 将任务类型枚举转换成集合 SelectListItem
  /// </summary>
  /// <returns></returns>
  public static List<SelectListItem> TaskTypesSelectList()
  {
  List<SelectListItem> selectlist = new List<SelectListItem>();
  foreach (int i in Enum.GetValues(typeof(TaskTypes)))
  {
  SelectListItem selectitem = new SelectListItem();
  selectitem.Value = i.ToString();
  selectitem.Text = Enum.GetName(typeof(TaskTypes), i);
  selectlist.Add(selectitem);
  }
  return selectlist;
  }
  /// <summary>
  /// 把接收方式枚举转换成数组 SelectListItem
  /// </summary>
  /// <returns></returns>
  public static List<SelectListItem> PlanReceiveMethodsSelectList()
  {
  List<SelectListItem> selectlist = new List<SelectListItem>();
  foreach (int i in Enum.GetValues(typeof(PlanReceiveMethods)))
  {
  SelectListItem selectitem = new SelectListItem();
  selectitem.Value = i.ToString();
  selectitem.Text = Enum.GetName(typeof(PlanReceiveMethods), i);
  selectlist.Add(selectitem);
  }
  return selectlist;
  }
  /// <summary>
  /// 把执行间隔(频率)枚举转换成数组 SelectListItem
  /// </summary>
  /// <returns></returns>
  public static List<SelectListItem> PlanIntervalsSelectList()
  {
  List<SelectListItem> selectlist = new List<SelectListItem>();
  foreach (int i in Enum.GetValues(typeof(PlanIntervals)))
  {
  SelectListItem selectitem = new SelectListItem();
  selectitem.Value = i.ToString();
  selectitem.Text = Enum.GetName(typeof(PlanIntervals), i);
  selectlist.Add(selectitem);
  }
  return selectlist;
  }
  /// <summary>
  /// 把每天频率枚举转换成数组 SelectListItem
  /// </summary>
  /// <returns></returns>
  public static List<SelectListItem> ExecutionWeekSelectList()
  {
  List<SelectListItem> selectlist = new List<SelectListItem>();
  foreach (int i in Enum.GetValues(typeof(ExecutionWeek)))
  {
  SelectListItem selectitem = new SelectListItem();
  selectitem.Value = i.ToString();
  selectitem.Text = Enum.GetName(typeof(ExecutionWeek), i);
  selectlist.Add(selectitem);
  }
  return selectlist;
  }
  /// <summary>
  /// 把时间间隔枚举转换成数组 SelectListItem
  /// </summary>
  /// <returns></returns>
  public static List<SelectListItem> ExecutionIntervalTypeSelectList()
  {
  List<SelectListItem> selectlist = new List
22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号