/// <summary> /// 用户单击“保存”按钮时的事件处理方法。 /// </summary> private void BtnSave_Click(object sender, EventArgs e) { var formSysMessage = FormSysMessage.ShowLoading(); BindFormlToObject(); // 进行数据绑定 try { if (jobDetail.JobId > 0) { int effected = CustomJobDetailBLL.CreateInstance().Update(jobDetail); // 调用“业务逻辑层”的方法,检查有效性后更新至数据库。 if (effected == 0) { return; } // 根据新的配置,更新寄宿服务里的任务计划 CustomJobDetailBLL.CreateInstance().ModifyHostJob(jobHostSite, jobDetail.JobId, jobDetail.JobName); #region 开启或关闭任务计划 if (jobDetail.State == (byte)JobState.Running) { CustomJobDetailBLL.CreateInstance().StartHostJob(jobHostSite, jobDetail.JobId, jobDetail.JobName, () => { this.Invoke(new CallBackDelegate(CallBackFunc), formSysMessage, "启动任务计划成功。"); }, () => { this.Invoke(new CallBackDelegate(CallBackFunc), formSysMessage, "启动任务计划失败。"); }); } else if (jobDetail.State == (byte)JobState.Stopping || jobDetail.State == (byte)JobState.Waiting) { CustomJobDetailBLL.CreateInstance().StopHostJob(jobHostSite, jobDetail.JobId, jobDetail.JobName, () => { this.Invoke(new CallBackDelegate(CallBackFunc), formSysMessage, "关闭任务计划成功。"); }, () => { this.Invoke(new CallBackDelegate(CallBackFunc), formSysMessage, "关闭任务计划失败。"); }); } #endregion } else { #region 添加任务计划 int newId = CustomJobDetailBLL.CreateInstance().Insert(jobDetail); // 调用“业务逻辑层”的方法,检查有效性后插入至数据库。 if (newId == 0) { return; } CustomJobDetailBLL.CreateInstance().AddHostJob(jobHostSite, jobDetail.JobId, jobDetail.JobName, () => { this.Invoke(new CallBackDelegate(CallBackFunc), formSysMessage, "添加任务计划成功。"); }, () => { this.Invoke(new CallBackDelegate(CallBackFunc), formSysMessage, "添加任务计划失败。"); }); #endregion } } catch (Exception ex) { this.Invoke(new CallBackDelegate(CallBackFunc), formSysMessage, "保存失败。"); Log4NetHelper.WriteExcepetion(ex); } }
private void btnImportEventConfig_Click(object sender, EventArgs e) { var formSysMessage = FormSysMessage.ShowLoading(); var filePath = TxtEventConfigFile.Text; if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { throw new CustomException("请输入上传文件存储地址!", ExceptionType.Warn); } List <EventDetail> listEventDetail = new List <EventDetail>(); using (var fileStream = new FileStream(filePath, FileMode.Open)) { IWorkbook workbook = new XSSFWorkbook(fileStream); ISheet sheet = workbook.GetSheetAt(0); for (int i = (sheet.FirstRowNum + 1); i < sheet.LastRowNum - 1; i++) { IRow row = sheet.GetRow(i); EventDetail entity = new EventDetail(); if (string.IsNullOrEmpty(row.GetCell(0).ToString()) || string.IsNullOrEmpty(row.GetCell(1).ToString())) { continue; } entity.EventId = row.GetCell(0).ToString(); entity.EventName = row.GetCell(1).ToString(); entity.EventDate = Convert.ToDateTime(row.GetCell(2).ToString()); listEventDetail.Add(entity); } } if (listEventDetail.Any()) { EventDetailBLL.CreateInstance().Insert(listEventDetail); } formSysMessage.SetMessage("上传成功!"); FormMain.LoadNewControl(EventConfigList.Instance); // 载入该模块的信息列表界面至主窗体显示。 }
private void DgvGrid_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex < 0) { return; } int jobId = Convert.ToInt32(DgvGrid["ColAction", e.RowIndex].Value.ToString()); // 获取所要修改关联对象的主键。 string jobIdentity = DgvGrid["ScheduleJobName", e.RowIndex].Value.ToString(); CustomJobDetail jobDetail = CustomJobDetailBLL.CreateInstance().Get(jobId, jobIdentity); #region 修改 //用户单击DataGridView“操作”列中的“修改”按钮。 if (JobDataGridViewActionButtonCell.IsModifyButtonClick(sender, e)) { FormMain.LoadNewControl(ScheduleJobEdit.BindJobDetail(jobDetail)); // 载入该模块的修改信息界面至主窗体显示。 } #endregion #region 除 //用户单击DataGridView“操作”列中的“删除”按钮。 if (JobDataGridViewActionButtonCell.IsDeleteButtonClick(sender, e)) { DialogResult dialogResult = FormSysMessage.ShowMessage("确定要删除该任务计划吗?"); if (dialogResult == DialogResult.OK) { var formSysMessage = FormSysMessage.ShowLoading(); int effected = CustomJobDetailBLL.CreateInstance().Delete(jobId, jobIdentity); if (effected > 0) { CustomJobDetailBLL.CreateInstance().DeleteHostJob( jobHostSite, jobId, jobIdentity, () => { this.Invoke(new RefreshDataGrid(SetLoadingDialog), formSysMessage, "删除任务计划成功。"); }, () => { this.Invoke(new RefreshDataGrid(SetLoadingDialog), formSysMessage, "删除任务计划失败。"); }); } BindDataGrid(); } } #endregion #region 启动任务计划 //用户单击DataGridView“操作”列中的“启动”按钮。 if (JobDataGridViewActionButtonCell.IsStartButtonClick(sender, e)) { var formSysMessage = FormSysMessage.ShowLoading(); CustomJobDetailBLL.CreateInstance().StartHostJob(jobHostSite, jobId, jobIdentity, () => { this.Invoke(new RefreshDataGrid(SetLoadingDialog), formSysMessage, "启动任务计划成功。"); }, () => { this.Invoke(new RefreshDataGrid(SetLoadingDialog), formSysMessage, "启动任务计划失败。"); }); } #endregion #region 停止任务计划 //用户单击DataGridView“操作”列中的“停止”按钮。 if (JobDataGridViewActionButtonCell.IsStopButtonClick(sender, e)) { var formSysMessage = FormSysMessage.ShowLoading(); CustomJobDetailBLL.CreateInstance().StopHostJob(jobHostSite, jobId, jobIdentity, () => { this.Invoke(new RefreshDataGrid(SetLoadingDialog), formSysMessage, "停止任务计划成功。"); }, () => { this.Invoke(new RefreshDataGrid(SetLoadingDialog), formSysMessage, "停止任务计划失败。"); }); } #endregion }