Beispiel #1
0
        private void biUploadSelect_Click(object sender, EventArgs e)
        {
            List <Maticsoft.Model.SMT_CTRLR_TASK> tasks = GetTasks(false);

            if (tasks.Count == 0)
            {
                WinInfoHelper.ShowInfoWindow(this, "没有选择定时任务待上传!");
                return;
            }
            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    UploadPrivate.UploadTimeTasks(tasks);
                }
                catch (Exception ex)
                {
                    WinInfoHelper.ShowInfoWindow(this, "上传定时任务发生异常:" + ex.Message);
                    log.Error("上传定时任务发生异常:", ex);
                }
            });

            waiting.Show(this);
        }
Beispiel #2
0
        private void biDelete_Click(object sender, EventArgs e)
        {
            if (dgvData.SelectedRows.Count > 0)
            {
                if (MessageBox.Show("确定删除选择任务?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }
                List <Maticsoft.Model.SMT_CTRLR_TASK> tasks = new List <Maticsoft.Model.SMT_CTRLR_TASK>();
                List <DataGridViewRow> rows = new List <DataGridViewRow>();
                foreach (DataGridViewRow item in dgvData.SelectedRows)
                {
                    tasks.Add((Maticsoft.Model.SMT_CTRLR_TASK)item.Tag);
                    rows.Add(item);
                }
                List <Maticsoft.Model.SMT_CTRLR_TASK> alltasks = new List <Maticsoft.Model.SMT_CTRLR_TASK>();
                foreach (DataGridViewRow item in dgvData.Rows)
                {
                    if (tasks.Contains((Maticsoft.Model.SMT_CTRLR_TASK)item.Tag))
                    {
                        continue;
                    }
                    alltasks.Add((Maticsoft.Model.SMT_CTRLR_TASK)item.Tag);
                }
                CtrlWaiting waiting = new CtrlWaiting(() =>
                {
                    try
                    {
                        try
                        {
                            UploadPrivate.DeleteTimeTasks(tasks);
                            if (alltasks.Count > 0)
                            {
                                UploadPrivate.UploadTimeTasks(alltasks);
                            }
                        }
                        catch (Exception ex)
                        {
                            WinInfoHelper.ShowInfoWindow(this, "删除控制器定时任务发生异常:" + ex.Message);
                            log.Error("上传定时任务发生异常:", ex);
                            return;
                        }

                        Maticsoft.BLL.SMT_CTRLR_TASK taskBll = new Maticsoft.BLL.SMT_CTRLR_TASK();
                        string ids = "";
                        foreach (var item in tasks)
                        {
                            ids += item.ID + ",";
                        }
                        ids = ids.TrimEnd(',');
                        taskBll.DeleteList(ids);
                        this.Invoke(new Action(() =>
                        {
                            foreach (var item in rows)
                            {
                                dgvData.Rows.Remove(item);
                            }
                        }));
                    }
                    catch (Exception ex)
                    {
                        log.Error("删除任务异常:", ex);
                        WinInfoHelper.ShowInfoWindow(this, "删除任务异常!" + ex.Message);
                    }
                });
                waiting.Show(this);
            }
        }