Exemple #1
0
        public void ItemClick(string type, Model.Plan mod)
        {
            Error error = GetEnableChange(mod);

            if (error.ErrCode != 0)
            {
                Helper.Instance.AlertError(error.ErrText);
                return;
            }
            // 1:查看 2:删除 3:开始/结束
            if (type == "1")
            {
                View.PlanEdit vPlan = new View.PlanEdit();
                vPlan.ID = mod.PlanID;
                vPlan.ShowDialog();
            }
            else if (type == "2")
            {
                Helper.Instance.AlertConfirm(null, "确定删除?", () =>
                {
                    try
                    {
                        _bllPlan.Delete(" PlanID=" + mod.PlanID);
                        Helper.Instance.AlertSuccess("操作成功!");
                    }
                    catch (Exception ex)
                    {
                        Helper.Instance.AlertError("操作失败!");
                        MSL.Tool.LogHelper.Instance.WriteLog("MainWindow DropList 删除选中项\r\n" + ex.ToString());
                    }
                });
            }
        }
Exemple #2
0
        public PlanListViewModel()
        {
            if (!IsInDesignMode)
            {
                Load(filter);
                this._plan       = new PlanMGMT.Model.Plan();
                this.LoadCommand = new ViewModelCommand((Object parameter) =>
                {
                    if (parameter == null)
                    {
                        Load(filter);
                    }
                    else
                    {
                        filter = (Entity.PlanFilter)parameter;
                        Load(filter);
                    }
                });

                #region 温馨提示
                string msg = "您有:" + PlanBLL.Instance.RunningTaskCnt() + "条正在进行中任务,正在为您自动计时\r\n";
                msg += " 您有:" + PlanBLL.Instance.UnStartTaskCnt() + "条未开始任务\r\n";
                msg += " 您有:" + PlanBLL.Instance.StopTaskCnt() + "条暂停中任务\r\n";
                msg += " 您有:" + PlanBLL.Instance.PastTaskCnt() + "条任务已延期\r\n";
                Helper.Instance.ShowPupUp("任务提示!", null, msg);
                #endregion

                this.SaveCommand = new ViewModelCommand((Object parameter) => Save());
                this.AddCommand  = new ViewModelCommand((Object parameter) =>
                {
                    View.PlanEdit edit = new View.PlanEdit();
                    edit.ID            = 0;
                    edit.Closed       += new EventHandler(Edit_Closed);//注册关闭事件
                    edit.Show();
                });
                this.ContextMenuCommand = new ViewModelCommand((Object n) => { TaskListContextClick(n.ToString()); });
                this.TimerCommand       = new ViewModelCommand((Object parameter) =>
                {
                    PlanModel = parameter == null ? null : parameter as Model.Plan;
                    if (this.PlanModel == null || PlanModel.PlanID == 0)
                    {
                        Helper.Instance.AlertWarning("没有任何选中项!");
                        return;
                    }
                    if (PlanModel.Status == 0)
                    {
                        Helper.Instance.AlertConfirm("不可撤销操作!", "是否开始任务?", () =>
                        {
                            try
                            {
                                PlanBLL.Instance.StartPlan(PlanModel.PlanID);
                            }
                            catch (Exception e)
                            {
                                Helper.Instance.AlertError("操作失败:" + e.Message);
                            }
                        });
                    }
                    else if (PlanModel.Status == 1)
                    {
                        Helper.Instance.AlertChoice("不可撤销操作!", "请选择要执行的操作?",
                                                    () =>
                        {
                            try
                            {
                                PlanBLL.Instance.StopPlan(PlanModel.PlanID);
                            }
                            catch (Exception e)
                            {
                                Helper.Instance.AlertError("操作失败:" + e.Message);
                            }
                        },
                                                    () =>
                        {
                            try
                            {
                                PlanBLL.Instance.CompeletePlan(PlanModel.PlanID);
                            }
                            catch (Exception e)
                            {
                                Helper.Instance.AlertError("操作失败:" + e.Message);
                            }
                        });
                    }
                    else if (PlanModel.Status == 2)
                    {
                        Helper.Instance.AlertWarning("您无法操作已经完成的任务");
                    }
                    else if (PlanModel.Status == 3)
                    {
                        Helper.Instance.AlertConfirm(null, "继续开始您的任务?", () =>
                        {
                            try
                            {
                                PlanBLL.Instance.ContinuePlan(PlanModel.PlanID);
                            }
                            catch (Exception e)
                            {
                                Helper.Instance.AlertError("操作失败:" + e.Message);
                            }
                        });
                    }
                    Load(filter);
                });
            }
            this.TaskListItemCommand = new ViewModelCommand((Object m) => TaskListItemClick(m.ToString()));
            System.Timers.Timer timer = new System.Timers.Timer();
            timer.Interval = 60000;//1分钟执行一次
            timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Task);
            timer.Start();
        }