コード例 #1
0
        public OperationResult Insert(TaskManageVM model)
        {
            try
            {
                TaskManage task = _TaskManageRepository.Entities.FirstOrDefault(c => c.TaskID == model.TaskID.Trim());
                if (task != null)
                {
                    return(new OperationResult(OperationResultType.Warning, "数据库中已经存在相同的课题信息,请修改后重新提交!"));
                }
                if (model.TaskName == null || model.TaskName.Trim() == "")
                {
                    return(new OperationResult(OperationResultType.Warning, "课题名称不能为空,请修改后重新提交!"));
                }
                var entity = new TaskManage
                {
                    TaskID        = model.TaskID,
                    TaskName      = model.TaskName,
                    TaskLeader    = model.TaskLeader.Trim(),
                    AvailableFund = model.AvailableFund,
                    Deficit       = model.Deficit,
                    UpdateDate    = DateTime.Now
                };
                _TaskManageRepository.Insert(entity);

                return(new OperationResult(OperationResultType.Success, "新增数据成功!"));
            }
            catch
            {
                return(new OperationResult(OperationResultType.Error, "新增数据失败,数据库插入数据时发生了错误!"));
            }
        }
コード例 #2
0
        void ReadTasks()
        {
            string strServer = Request.Form["tip"];

            if (strServer == null || (strServer = strServer.Trim()) == string.Empty)
            {
                strServer = "127.0.0.1";
            }
            string[] tip = strServer.Split(new[] { ',', ';', ' ', '|' },
                                           StringSplitOptions.RemoveEmptyEntries);
            var all = new List <TaskManage>(tip.Length);
            var err = new StringBuilder();

            foreach (string ip in tip)
            {
                string     msg;
                TaskManage tasks = TaskClient.GetAllTask(ip, 23244, out msg);
                if (tasks != null)
                {
                    all.Add(tasks);
                    //Response.Write(msg);
                    //return;
                }
                else
                {
                    err.AppendFormat("{0}<br/>\r\n", msg);
                }
            }
            OutPutTasks(all, err.ToString());
        }
コード例 #3
0
ファイル: MessageForm.cs プロジェクト: wwkkww1983/ShanxiEPM
        /// <summary>
        /// 绑定列表
        /// </summary>
        private void BindTable()
        {
            List <TaskConfig> list   = TaskManage.LoadConfig();
            List <TaskView>   result = new List <TaskView>();
            var runningTask          = TaskManage.GetAllRunningTask();

            foreach (var item in list)
            {
                TaskView m = new TaskView();
                m.AssemblyPath = item.AssemblyPath;
                m.ClassPath    = item.ClassPath;
                m.ExcuteTime   = item.ExcuteTime;
                m.Id           = item.Id;
                m.IntervalTime = item.IntervalTime;
                m.MethodName   = item.MethodName;
                TaskType type = (TaskType)item.TaskType;
                m.TaskType = type.GetText();
                m.State    = "运行停止";
                if (runningTask.Select(i => i.Name).Contains(m.MethodName))
                {
                    m.State = "运行中";
                }
                result.Add(m);
            }
            gvTables.DataSource = result;
        }
コード例 #4
0
        public TaskManage GetById(int id)
        {
            var model            = new TaskManage();
            var taskManageEntity = _taskManageRepository.GetById(id);

            model = Mapper.Map <TaskManage>(taskManageEntity);

            return(model);
        }
コード例 #5
0
 public OperationResult Delete(TaskManage model)
 {
     try
     {
         model.UpdateDate = DateTime.Now;
         _TaskManageRepository.Delete(model);
         return(new OperationResult(OperationResultType.Success, "更新课题数据成功!"));
     }
     catch
     {
         return(new OperationResult(OperationResultType.Error, "更新课题数据失败!"));
     }
 }
コード例 #6
0
        public void SaveTaskManage(TaskManage taskManage)
        {
            var entity = Mapper.Map <TaskManageEntity>(taskManage);

            if (entity.ID == 0)
            {
                _taskManageRepository.Insert(entity);
            }
            else
            {
                _taskManageRepository.Update(entity);
            }
        }
コード例 #7
0
        // GET: /BasicDataManagement/TaskManage/GetDataByID/
        public String GetDataByID(String projectNumber)
        {
            TaskManage result = this._taskManageService.GetTaskByNumber(projectNumber);
            String     str    = "";

            if (result != null)
            {
                str = result.TaskName + "," + result.TaskLeader;
            }
            else
            {
                str = "该课题号不存在。";
            }
            return(str);
        }
コード例 #8
0
        /// <summary>
        /// 获取用户对任务的管理权限
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="taskid"></param>
        /// <returns></returns>
        public static bool GetAccess(int userid, int taskid, HandleAccess access)
        {
            bool flag = false;
            UserInfoRepository userinfo = new UserInfoRepository(new TaskSchedulerRepository.DbContexts.TaskSchedulerDbContext());
            UserInfo           user     = userinfo.FindFirst(n => n.Id == userid) ?? new UserInfo();

            if (user.Super)
            {
                return(user.Super);
            }
            TaskManageRepository task   = new TaskManageRepository(new TaskSchedulerRepository.DbContexts.TaskSchedulerDbContext());
            TaskManage           manage = task.FindFirst(n => n.UserId == userid && n.TaskId == taskid) ?? new TaskManage();

            if ((access == HandleAccess.AddTask) && (manage.Access & HandleAccess.AddTask) == HandleAccess.AddTask)
            {
                flag = true;
            }
            if ((access == HandleAccess.UpdateTask) && (manage.Access & HandleAccess.UpdateTask) == HandleAccess.UpdateTask)
            {
                flag = true;
            }
            if ((access == HandleAccess.DeleteTask) && (manage.Access & HandleAccess.DeleteTask) == HandleAccess.DeleteTask)
            {
                flag = true;
            }
            if ((access == HandleAccess.RunTask) && (manage.Access & HandleAccess.RunTask) == HandleAccess.RunTask)
            {
                flag = true;
            }
            if ((access == HandleAccess.HandleCommand) && (manage.Access & HandleAccess.HandleCommand) == HandleAccess.HandleCommand)
            {
                flag = true;
            }
            if ((access == HandleAccess.HandleConfig) && (manage.Access & HandleAccess.HandleConfig) == HandleAccess.HandleConfig)
            {
                flag = true;
            }
            if ((access == HandleAccess.SelectTask) && (manage.Access & HandleAccess.SelectTask) == HandleAccess.SelectTask)
            {
                flag = true;
            }
            return(flag);
        }
コード例 #9
0
        void SaveTask()
        {
            TaskItem task = new TaskItem();
            int      id;

            if (!int.TryParse(Request.Form["id"], out id))
            {
                id = -1;// 表示新增
            }
            task.id   = id;
            task.desc = Request.Form["desc"];

            string exepath = Request.Form["exepath"];

            // ReSharper disable AssignNullToNotNullAttribute
            // 防止出现 c:\\\\a.exe 或 c:/a.exe这样的路径,统一格式化成:c:\a.exe形式
            exepath = Path.Combine(Path.GetDirectoryName(exepath), Path.GetFileName(exepath));
            // ReSharper restore AssignNullToNotNullAttribute
            task.exepath = exepath;

            task.exepara  = Request.Form["exepara"];
            task.taskpara = Request.Form["taskpara"];
            int runtype;

            if (!int.TryParse(Request.Form["runtype"], out runtype))
            {
                runtype = 0;
            }
            task.runtype = (RunType)runtype;

            string     msg;
            TaskManage tasks = TaskClient.SaveTask(Request.Form["server"], 23244, task, out msg);

            if (tasks == null)
            {
                Response.Write(msg);
                return;
            }
            OutPutTasks(tasks);
        }
コード例 #10
0
 public OperationResult Update(TaskManageVM model)
 {
     try
     {
         TaskManage task = _TaskManageRepository.Entities.FirstOrDefault(c => c.TaskID == model.TaskID.Trim());
         if (task == null)
         {
             throw new Exception();
         }
         task.TaskID        = model.TaskID;
         task.TaskName      = model.TaskName;
         task.TaskLeader    = model.TaskLeader.Trim();
         task.AvailableFund = model.AvailableFund;
         task.Deficit       = model.Deficit;
         task.UpdateDate    = DateTime.Now;
         _TaskManageRepository.Update(task);
         return(new OperationResult(OperationResultType.Success, "更新数据成功!"));
     }
     catch
     {
         return(new OperationResult(OperationResultType.Error, "更新数据失败!"));
     }
 }
コード例 #11
0
 public Result Add([FromForm] int userId, [FromForm] int taskId)
 {
     if (userId <= 0)
     {
         return(Fail("用户错误"));
     }
     if (taskId <= 0)
     {
         return(Fail("任务错误"));
     }
     try
     {
         var task = _manager.GetTasks(n => n.Id == taskId).FirstOrDefault();
         if (task == null)
         {
             return(Fail("添加失败,没有找到任务"));
         }
         if (_repository.Exists(n => n.TaskId == taskId && n.UserId == userId))
         {
             return(Fail("添加失败,该用户存在此任务的查看权限"));
         }
         var manege = new TaskManage {
             UserId = userId, TaskId = taskId, Access = HandleAccess.SelectTask
         };
         if (_repository.Insert(manege) <= 0)
         {
             return(Fail("添加任务权限失败"));
         }
         return(Success(manege));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message + ex.StackTrace);
         return(Fail("系统错误"));
     }
 }
コード例 #12
0
ファイル: MessageForm.cs プロジェクト: wwkkww1983/ShanxiEPM
 /// <summary>
 /// 停止
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnStopAll_Click(object sender, EventArgs e)
 {
     TaskManage.Stop();
     BindTable();
 }
コード例 #13
0
ファイル: MessageForm.cs プロジェクト: wwkkww1983/ShanxiEPM
 private void MessageForm_Load(object sender, EventArgs e)
 {
     LogHelper.SetConfig(path + "timerlog.config");
     TaskManage.Start(JobStart, JobEnd, JobEx);
     BindTable();
 }
コード例 #14
0
ファイル: Form1.cs プロジェクト: tytok/PlanServer
        private void dgvTask_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            DataGridView dgv = (DataGridView)sender;

            #region 点击删除按钮
            if (e.ColumnIndex == COLIDX_DEL)
            {
                if (e.RowIndex < 0 || e.RowIndex >= dgv.Rows.Count - 1)//Rows.Count - 1是不让点击未提交的新行
                {
                    return;
                }

                var    row = dgv.Rows[e.RowIndex];
                string tmp = Convert.ToString(row.Cells[COLIDX_ID].Value);
                int    id;
                if (string.IsNullOrEmpty(tmp) || !int.TryParse(tmp, out id))
                {
                    MessageBox.Show("未保存的数据,不能删除");
                    return;
                }

                if (MessageBox.Show("确认要删除吗?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                    MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    if (isSocketAccess)
                    {
                        // 通过Socket删除
                        string str = TaskClient.DelTaskById(txtServerIP.Text, int.Parse(txtPort.Text), id);
                        if (!string.IsNullOrEmpty(str))
                        {
                            MessageBox.Show(str);
                            return;
                        }
                        SetSocketStatus("删除成功 ");
                        MessageBox.Show(str);
                    }
                    else
                    {
                        // 本地文件删除
                        dbaccess.DelTaskById(id);
                    }
                    dgv.Rows.RemoveAt(e.RowIndex);
                    dgv.ClearSelection();
                }
                return;
            }
            #endregion

            #region 点击保存按钮
            if (e.ColumnIndex == COLIDX_SAVE)
            {
                if (e.RowIndex < 0 || e.RowIndex >= dgv.Rows.Count - 1)//Rows.Count - 1是不让点击未提交的新行
                {
                    return;
                }

                var      row  = dgv.Rows[e.RowIndex];
                TaskItem task = GetRowData(row);
                if (task != null)
                {
                    if (isSocketAccess)
                    {
                        // 通过Socket保存
                        string     msg;
                        TaskManage tasks = TaskClient.SaveTask(txtServerIP.Text, int.Parse(txtPort.Text), task, out msg);
                        if (tasks == null)
                        {
                            MessageBox.Show(msg);
                            return;
                        }
                        SetSocketStatus("保存成功 \r\n服务器的时间:" + tasks.serverTime + "\r\n上次轮询时间:" + tasks.lastRunTime);
                        if (tasks.tasks != null)
                        {
                            GetTaskToView(dgvTask, tasks.tasks);
                        }
                    }
                    else
                    {
                        // 本地文件保存
                        if (task.id <= 0)
                        {
                            dbaccess.AddTask(task);
                        }
                        else
                        {
                            dbaccess.UpdateTask(task);
                        }

                        GetTaskToView(dgvTask);
                    }
                }
                return;
            }

            #endregion

            #region 点击定时参数列
            if (e.ColumnIndex == COLIDX_TYPEPARA)
            {
                if (e.RowIndex < 0 || e.RowIndex >= dgv.Rows.Count - 1) //Rows.Count - 1是不让点击未提交的新行
                {
                    return;
                }

                var row = dgv.Rows[e.RowIndex];
                //TaskItem task = GetRowData(row);
                //string typepara = Convert.ToString(row.Cells[e.ColumnIndex].Value).Trim();
                var     cell       = row.Cells[e.ColumnIndex];
                string  runtypeStr = Convert.ToString(row.Cells[COLIDX_TYPE].Value).Trim();
                RunType runtype    = (from pair in GetRunTypeDesc()
                                      where pair.Value == runtypeStr
                                      select(RunType) pair.Key).FirstOrDefault();
                switch (runtype)
                {
                case RunType.PerDay:
                case RunType.PerWeek:
                case RunType.PerMonth:
                    new ParaSet(runtype, cell).ShowDialog(this);
                    return;

                default:
                    return;
                }
                //return;
            }

            #endregion
        }
コード例 #15
0
 void OutPutTasks(TaskManage task)
 {
     OutPutTasks(new[] { task });
 }
コード例 #16
0
ファイル: MessageForm.cs プロジェクト: wwkkww1983/ShanxiEPM
 /// <summary>
 /// 开始
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnStart_Click(object sender, EventArgs e)
 {
     TaskManage.Start(JobStart, JobEnd, JobEx);
     BindTable();
 }
コード例 #17
0
 private void Awake()
 {
     _instance = this;
     ReadTaskInfo();
 }
コード例 #18
0
        public Result Add([FromForm] string name, [FromForm] IFormFile file)
        {
            if (!User.Super)
            {
                return(Fail("添加任务失败,你没有权限操作"));
            }
            try
            {
                if (name == null)
                {
                    return(Fail("名称不能为空"));
                }
                if (file == null)
                {
                    return(Fail("文件不能为空"));
                }

                _repository.DbContext.Database.BeginTransaction();
                TaskInfo task = new TaskInfo {
                    Name = name, ExecFile = ""
                };
                _repository.Insert(task);

                var path = _config.TaskAppPath + task.TaskGuid.ToString("N");
                try
                {
                    using (ZipArchive archive = new ZipArchive(file.OpenReadStream()))
                    {
                        if (!System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.CreateDirectory(path);
                        }
                        archive.ExtractToDirectory(path);
                    }
                }
                catch (Exception ex)
                {
                    _repository.DbContext.Database.RollbackTransaction();
                    if (System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.Delete(path, true);
                    }
                    _logger.LogError(ex.Message + ex.StackTrace);
                    return(Fail("解压文件失败"));
                }
                try
                {
                    //复制可执行文件
                    task.ExecFile = path + "/" + task.Name + Path.GetExtension(_config.ExecAppFile);
                    System.IO.File.Copy(_config.ExecAppFile, task.ExecFile, true);

                    //复制配置文件
                    //var configFilePath = task.ExecFile + Path.GetExtension(_config.ExecAppConfig);
                    //System.IO.File.Copy(_config.ExecAppConfig, configFilePath, true);

                    //复制类库
                    if (_config.ExecLibFile != null)
                    {
                        foreach (var item in _config.ExecLibFile)
                        {
                            var libFile = path + "/" + Path.GetFileName(item);
                            System.IO.File.Copy(item, libFile, true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _repository.DbContext.Database.RollbackTransaction();
                    if (System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.Delete(path, true);
                    }
                    _logger.LogError(ex.Message + ex.StackTrace);
                    return(Fail("复制执行文件失败"));
                }
                if (_repository.Update(task) <= 0)
                {
                    _repository.DbContext.Database.RollbackTransaction();
                    return(Fail("更新执行文件路径失败"));
                }

                _repository.DbContext.Database.CommitTransaction();

                _manager.Add(task);

                var config = new TaskManage {
                    UserId = User.Id, TaskId = task.Id, Access = (HandleAccess)64
                };
                _mapository.Insert(config);

                return(Success(task, "添加成功"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + ex.StackTrace);
                return(Fail("系统错误"));
            }
        }
コード例 #19
0
        public ActionResult ApplyAudit(ApplicationFormVM formVM)
        {
            bool hasAudit      = false;
            var  serialNumbers = Session["AuditSerials"] as String[];

            foreach (var serialNumber in serialNumbers)
            {
                ApplicationForm form = _applicationFormService.ApplicationForms.FirstOrDefault(t => t.SerialNumber == serialNumber);
                if (form != null)
                {
                    if (form.AuditStatus.Equals("审核通过") && formVM.AuditStatus.Equals("审核通过"))
                    {
                        continue;
                    }

                    form.AuditStatus = formVM.AuditStatus;
                    if (!string.IsNullOrEmpty(formVM.AuditOpinion))
                    {
                        form.AuditOpinion = formVM.AuditOpinion;
                        form.AuditTime    = DateTime.Now;
                    }

                    hasAudit = true;
                    //若审核通过,开始算税,单笔税保存在TaxPerOrder表
                    if (formVM.AuditStatus.Equals("审核通过"))
                    {
                        List <PersonalRecord> records     = GetPersonalDatas(serialNumber);
                        TaxPerOrder           taxPerOrder = null;
                        //check totalsum is equal or not 20210108
                        //begin
                        int    equalFlag   = 0;
                        double sumTotalApp = form.Summation;
                        double sumTotalRec = 0.0;
                        if (records != null)
                        {
                            for (int c = 0; c < records.Count; c++)
                            {
                                sumTotalRec = sumTotalRec + records[c].Amount;
                            }
                        }
                        if (sumTotalApp == sumTotalRec)
                        {
                            equalFlag = 1;
                        }

                        //end
                        //check totalamonutY by projectnumber is available or not 20210509
                        //begin
                        string     pjNum               = form.ProjectNumber.Split('|')[0].Trim();
                        TaskManage taskManage          = _taskManageService.GetTaskByNumber(pjNum);
                        double     totalAmonutYByPjNum = _taxPerOrderService.GetTotalAmountYByPjNum(pjNum) + form.Summation;
                        if (taskManage != null && taskManage.Deficit != null)
                        {
                            if ("否".Equals(taskManage.Deficit.Trim()))
                            {
                                if (taskManage.AvailableFund - totalAmonutYByPjNum < 0)
                                {
                                    return(Json("availableFund insufficient,课题号为:" + form.ProjectNumber, JsonRequestBehavior.AllowGet));
                                    //return Json("availableFund insufficient", JsonRequestBehavior.AllowGet);
                                }
                            }
                        }
                        //end


                        if (equalFlag == 1)
                        {
                            if (records != null)
                            {
                                for (int i = 0; i < records.Count; i++)
                                {
                                    taxPerOrder = new TaxPerOrder();
                                    taxPerOrder.SerialNumber = form.SerialNumber;
                                    if (!String.IsNullOrEmpty(form.ProjectNumber) && !form.ProjectNumber.Equals("无"))
                                    {
                                        string[] projectSep = form.ProjectNumber.Split('|');
                                        taxPerOrder.ProjectNumber = projectSep[0].Trim();
                                        if (projectSep.Length > 1)
                                        {
                                            taxPerOrder.TaskName = projectSep[1].Trim();
                                        }
                                        else
                                        {
                                            taxPerOrder.TaskName = form.TaskName;
                                        }
                                    }
                                    else
                                    {
                                        taxPerOrder.ProjectNumber = "无";
                                        taxPerOrder.TaskName      = "无";
                                    }
                                    taxPerOrder.RefundType      = form.RefundType;
                                    taxPerOrder.ProjectDirector = form.ProjectDirector;
                                    taxPerOrder.Agent           = form.Agent;
                                    taxPerOrder.Name            = records[i].Name;
                                    taxPerOrder.PersonType      = records[i].PersonType;
                                    taxPerOrder.CertificateType = records[i].CertificateType;
                                    taxPerOrder.CertificateID   = records[i].CertificateID;
                                    taxPerOrder.Amount          = records[i].Amount;
                                    taxPerOrder.TaxOrNot        = records[i].TaxOrNot;
                                    taxPerOrder.Bank            = records[i].Bank;
                                    taxPerOrder.BankDetailName  = records[i].BankDetailName;
                                    taxPerOrder.ProvinceCity    = records[i].ProvinceCity;
                                    taxPerOrder.CityField       = records[i].CityField;
                                    taxPerOrder.AccountName     = records[i].AccountName;
                                    taxPerOrder.AccountNumber   = records[i].AccountNumber;
                                    taxPerOrder.PaymentType     = form.PaymentType;
                                    taxPerOrder.Tele            = records[i].Tele;
                                    _taxPerOrderService.Insert(taxPerOrder);
                                }
                            }
                        }
                        else
                        {
                            return(Json("sum error", JsonRequestBehavior.AllowGet));
                        }
                    }
                    else if (formVM.AuditStatus.Equals("已退回"))
                    {
                        //删除TaxPerOrder表中审核通过时的记录(主要是保证多次审核的情况,如第一次审核通过,发现问题,重新审核为退回)
                        _taxPerOrderService.DeleteBySerialNumber(serialNumber);
                    }
                    form.UpdateDate = DateTime.Now;
                    _applicationFormService.Update(form);
                }
            }
            Session.Remove("AuditSerials");

            if (hasAudit)
            {
                return(Json("sum success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("no sum", JsonRequestBehavior.AllowGet));
            }
        }