//运行选中项 private void StartItem(Entity.AutoTask model, string proccessName) { if (model == null) { return; } if (model.TaskType != null && model.TaskType != "0") { Bll.Task.Instance.StartWarn(model, true); return; } if (!File.Exists(model.ApplicationPath)) { MessageBox.Show("运行失败,程序没有找到!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); return; } try { //杀死 Helper.EndApp(proccessName); if (model.StartParameters.Length > 0) { System.Diagnostics.Process.Start(model.ApplicationPath, model.StartParameters); } else { System.Diagnostics.Process.Start(model.ApplicationPath);//可调用bat文件 } } catch (Exception ex) { MessageBox.Show("操作失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error); Log.SaveLog("MainWindow DropList 删除选中项", ex.ToString()); } }
//配置选项 private void lstTask_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.lstTask.SelectedItems.Count > 0) { Entity.AutoTask task = lstTask.SelectedItem as Entity.AutoTask; this.ID = task.Id; OnInit(); } }
private void lstMain_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.lstMain.SelectedItems.Count > 0) { this.mod = lstMain.SelectedItem as Entity.AutoTask; this.cboAudio.SelectedItem = this.mod.AudioPath.Length == 0 ? "无" : this.mod.AudioPath; this.chkEnable.IsChecked = this.mod.AudioEnable == "1" ? true : false; this.sdVolume.Value = this.mod.AudioVolume; } }
//上下文菜单 private void cmClick(object sender, RoutedEventArgs e) { MenuItem item = (MenuItem)sender; string type = item.Header.ToString().Trim(); string proccessName = ""; Entity.AutoTask mod = null; if (type.Equals("查看") || type.Equals("运行记录") || type.Equals("停止实例") || type.Equals("运行")) { mod = (Entity.AutoTask)lstMain.SelectedItem; if (mod.ApplicationPath != null) { proccessName = mod.ApplicationPath.Substring(mod.ApplicationPath.LastIndexOf("\\") + 1).Replace(".exe", ""); } } try { switch (item.Header.ToString().Trim()) { case "运行记录": { View.TaskRunLog trl = new View.TaskRunLog(); trl.ID = mod.Id; trl.Show(); } break; case "停止实例": { if (mod.TaskType == "0") { Helper.EndApp(proccessName); } else { Helper.StopAudio(); } break; } case "运行": StartItem(mod, proccessName); break; } } catch (Exception ex) { Log.SaveLog("MainWindow cmClick 运行", ex.ToString()); MessageBox.Show("操作失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } }
//列表菜单 private void Item_Click(object sender, EventArgs e) { Button btn = (Button)sender; Entity.AutoTask model = (Entity.AutoTask)btn.DataContext; string btnContent = btn.Content.ToString().Replace(" ", ""); if (btnContent == "查看") { View.TaskDetail vTask = new View.TaskDetail(); vTask.ID = model.Id; vTask.ShowDialog(); } else if (btnContent == "删除") { MessageBoxResult mbr = MessageBox.Show("确定删除?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (mbr == MessageBoxResult.Yes) { try { dalAutoTask.Delete(" Id=" + model.Id); MessageBox.Show("操作成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("操作成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); Log.SaveLog("MainWindow DropList 删除选中项", ex.ToString()); } Bind(); } } else if (btnContent == "禁用" || btnContent == "启用") { model.Enable = btnContent == "禁用" ? "0" : "1"; dalAutoTask.Update(model, " Id=" + model.Id); MessageBox.Show("操作成功!", "提示", MessageBoxButton.OK, MessageBoxImage.Information); Bind(); } }
private void OnInit() { if (ID == 0) { this.btnOK.Content = "添加任务"; this.rbtMinute.IsChecked = true; this.cboEnable.IsChecked = true; rbtItem_Click(null, null); } else { this.btnOK.Content = "保 存"; this.cboMinute.SelectedIndex = 0; } this.dp_StartDate.Text = DateTime.Now.AddMinutes(5).ToString("yyyy/MM/dd"); this.dp_StartTime.Value = DateTime.Now; this.dp_StopDate.Text = DateTime.Now.AddDays(10).ToString("yyyy/MM/dd"); this.dp_StopTime.Value = DateTime.Now; Entity.AutoTask model = dalAutoTask.GetEntity(" Id=" + ID); if (model != null) { this.txtPath.Text = model.ApplicationPath; this.txtTitle.Text = model.Title; this.txtStartParameter.Text = model.StartParameters; this.cboEnable.IsChecked = model.Enable == "1" ? true : false; this.txtRemark.Text = model.Remark; this.cboTaskType.SelectedIndex = (model.TaskType == "" || model.TaskType == TaskType.TimingTask.ToString()) ? 0 : Convert.ToInt32(model.TaskType); this.cboAudio.SelectedItem = model.AudioPath.Length == 0 ? "无" : model.AudioPath; this.cboMinute.SelectedIndex = 0; this.cboDay.SelectedIndex = 0; switch (model.TimeType) { case "1": this.rbtMonth.IsChecked = true; _timeType = TimeType.Month; this.cboDay.SelectedValue = model.Dayth; break; case "2": this.rbtDay.IsChecked = true; _timeType = TimeType.Day; break; case "3": this.rbtHour.IsChecked = true; _timeType = TimeType.Hour; break; case "4": this.rbtMinute.IsChecked = true; _timeType = TimeType.Minute; this.cboMinute.SelectedValue = model.Interval; break; case "5": this.rbtOnce.IsChecked = true; _timeType = TimeType.Once; break; } try { switch (_timeType) { case TimeType.Once: this.rbtOnce.IsChecked = true; break; case TimeType.Month: this.rbtMonth.IsChecked = true; break; case TimeType.Day: this.rbtDay.IsChecked = true; break; case TimeType.Hour: this.rbtHour.IsChecked = true; break; case TimeType.Minute: this.rbtMinute.IsChecked = true; break; } rbtItem_Click(null, null); this.dp_StartDate.Text = Convert.ToDateTime(model.StartDate).ToString("yyyy-MM-dd"); this.dp_StartTime.Value = model.StartDate; this.dp_StopDate.Text = Convert.ToDateTime(model.StopDate).ToString("yyyy-MM-dd"); this.dp_StopTime.Value = model.StopDate; } catch (Exception ex) { Log.SaveLog("TaskDetail OnInit", ex.ToString()); } } }