Exemplo n.º 1
0
        private TaskExBase CheckChangeTaskStatus(Task task, TaskStatus newStatus)
        {
            //新状态是否和现有状态相同
            CommUtils.Assert(task.TaskStatus != newStatus, "无法将任务状态从[{0}]修改为[{1}]",
                             TranslateUtils.ToCnString(task.TaskStatus), TranslateUtils.ToCnString(newStatus));

            //前置工作是否完成
            if (newStatus == TaskStatus.Running || newStatus == TaskStatus.Finished)
            {
                foreach (var prevTaskId in task.PrevTaskIdArray)
                {
                    var prevTask = m_dbAdapter.Task.GetTask(prevTaskId);
                    CommUtils.Assert(prevTask.TaskStatus == TaskStatus.Finished || prevTask.TaskStatus == TaskStatus.Skipped,
                                     "前置工作[{0}][{1}]未完成", prevTask.ShortCode, prevTask.Description);
                }
            }

            //扩展工作未完成,不能完成工作
            TaskExBase taskEx = null;

            if (task.TaskExtensionId.HasValue)
            {
                var taskExtension = m_dbAdapter.Task.GetTaskExtension(task.TaskExtensionId.Value);
                taskEx = TaskExFactory.CreateInstance(taskExtension.TaskExtensionType, task.ShortCode, CurrentUserName);
                if (taskEx != null)
                {
                    var eventResult = taskEx.InvokeStatusChanging(task.TaskStatus, newStatus);
                    CommUtils.Assert(eventResult.EventResult != EventResult.Cancel, eventResult.Message);
                }
            }

            return(taskEx);
        }
Exemplo n.º 2
0
 private TaskStatus GetTaskStatus(DateTime endTime, string taskStatus)
 {
     if (string.IsNullOrWhiteSpace(taskStatus) || taskStatus == "-")
     {
         if (DateTime.Today <= endTime)
         {
             return(TaskStatus.Waitting);
         }
     }
     else if (taskStatus == TranslateUtils.ToCnString(TaskStatus.Waitting))
     {
         return(TaskStatus.Waitting);
     }
     return(TaskStatus.Overdue);
 }
Exemplo n.º 3
0
        public ActionResult ImportTable(string projectSeriesGuid)
        {
            return(ActionUtils.Json(() =>
            {
                var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid);
                var project = projectSeriesLogicModel.CurrentProject.Instance;
                CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Write);

                var file = Request.Files[0];
                byte[] bytes = new byte[file.InputStream.Length];
                file.InputStream.Read(bytes, 0, bytes.Length);
                file.InputStream.Seek(0, SeekOrigin.Begin);

                Stream newStream = new MemoryStream(bytes);
                var tableHeaderRowsCount = ExcelUtils.GetTableHeaderRowsCount(newStream, 0, 0, tableHeader);
                var table = ExcelUtils.ParseExcel(file.InputStream, 0, tableHeaderRowsCount, 0, 9);

                var validation = new ExcelValidation();
                validation.Add(CellRange.Column(0), new CellTextValidation(1, 30));
                validation.Add(CellRange.Column(1), new CellTextValidation(1, 500));
                validation.Add(CellRange.Column(2), new CellTextValidation(1, 30));
                validation.Add(CellRange.Column(3), new CellDateValidation());
                validation.Add(CellRange.Column(4), new CellDateValidation(false));
                //检查工作状态
                Func <string, string> checkTaskStatus = (cellText) =>
                {
                    if (!string.IsNullOrWhiteSpace(cellText) && cellText != "-" && cellText != TranslateUtils.ToCnString(TaskStatus.Waitting) &&
                        cellText != TranslateUtils.ToCnString(TaskStatus.Overdue))
                    {
                        return "导入工作的工作状态只能为空、[等待]或[逾期]";
                    }
                    return string.Empty;
                };
                validation.Add(CellRange.Column(5), new CellCustomValidation(checkTaskStatus));
                //检查负责人
                int projectId = project.ProjectId;
                var personInCharges = GetPersonInCharges(projectSeriesLogicModel, projectId);
                Func <List <string>, string, string> checkPersonInCharge = (personInChargeList, cellText) =>
                {
                    var userName = GetPersonInCharge(cellText);
                    if (!personInChargeList.Contains(userName))
                    {
                        return "负责人[" + cellText + "]不存在";
                    }
                    return string.Empty;
                };
                validation.Add(CellRange.Column(6), new CellCustomValidation(checkPersonInCharge, personInCharges));
                //不检查只有taskGroup列,其他列均为空的行
                var columns = new List <CellRange>()
                {
                    CellRange.Column(2), CellRange.Column(3), CellRange.Column(4),
                    CellRange.Column(5), CellRange.Column(6), CellRange.Column(7), CellRange.Column(8)
                };
                Func <string, bool> ExceptCondition = (x) =>
                {
                    return x != string.Empty;
                };
                validation.JudgeColumn = new ColumnJudge(columns, ExceptCondition);
                //检查开始时间是否大于截止时间
                Func <object, object, string> lessThanOrEqualTo = (left, right) =>
                {
                    var leftText = left.ToString();
                    var rightText = right.ToString();
                    if (!string.IsNullOrWhiteSpace(leftText) && leftText != "-")
                    {
                        var startTime = DateTime.Parse(leftText);
                        var endTime = DateTime.Parse(rightText);
                        if (startTime > endTime)
                        {
                            return "开始时间[" + leftText + "]不能大于结束时间[" + rightText + "]";
                        }
                    }
                    return string.Empty;
                };
                validation.CompareColumn = new ColumnComparison(CellRange.Column(3), CellRange.Column(4), lessThanOrEqualTo);
                validation.Check(table, tableHeaderRowsCount);

                //创建taskGroups
                List <TaskGroup> newTaskGroups = new List <TaskGroup>();
                for (int iRow = 0; iRow < table.Count; iRow++)
                {
                    var row = table[iRow];
                    var taskGroup = ParseTaskGroups(newTaskGroups, row, iRow, projectId);
                    if (taskGroup != null)
                    {
                        newTaskGroups.Add(taskGroup);
                    }
                }

                var projectLogicModel = new ProjectLogicModel(CurrentUserName, project);
                var permissionLogicModel = new PermissionLogicModel(projectLogicModel);
                var projectSeries = projectSeriesLogicModel.Instance;

                newTaskGroups.ForEach(x => {
                    var taskGroup = m_dbAdapter.TaskGroup.NewTaskGroup(x.ProjectId, x.Name, x.Description);
                    permissionLogicModel.SetPermission(projectSeries, project, taskGroup.Guid, PermissionObjectType.TaskGroup);
                    projectLogicModel.Activity.Add(x.ProjectId, ActivityObjectType.TaskGroup, taskGroup.Guid, "新建工作组:" + taskGroup.Name);
                });

                //创建tasks
                var taskGroups = m_dbAdapter.TaskGroup.GetByProjectId(projectId);
                var dicTaskGroups = taskGroups.ToDictionary(x => x.Name);

                List <Task> tasks = new List <Task>();
                for (int iRow = 0; iRow < table.Count; iRow++)
                {
                    var row = table[iRow].ToList();
                    if (row.Count > 2 && (!string.IsNullOrWhiteSpace(row[2].ToString())) && row[2].ToString() != "-")
                    {
                        var taskGroup = dicTaskGroups[row[0].ToString()];
                        tasks.Add(ParseTasks(row, iRow, taskGroup.Id, project));
                    }
                }
                tasks.ForEach(x => m_dbAdapter.Task.NewTask(x));

                Dictionary <string, string> msgDic = new Dictionary <string, string>();
                foreach (var task in tasks)
                {
                    var msg = string.Format("创建task:shortCode={0};name={1};startTime={2};endTime={3};personInCharge={4};"
                                            + "taskStatus={5};taskTarget={6};taskDetail={7};projectId={8};projectName={9};taskGroupId={10}",
                                            task.ShortCode, task.Description, task.StartTime, task.EndTime, task.PersonInCharge, task.TaskStatus,
                                            task.TaskTarget, task.TaskDetail, task.ProjectId, task.ProjectName, task.TaskGroupId);
                    msgDic[task.ShortCode] = msg;
                }

                tasks.ForEach(x => {
                    permissionLogicModel.SetPermission(projectSeries, project, x.ShortCode, PermissionObjectType.Task);
                    projectLogicModel.Activity.Add(projectId, ActivityObjectType.Task, x.ShortCode, "创建工作:" + x.Description);
                    m_dbAdapter.Project.NewEditProductLog(EditProductType.CreateTask, x.ProjectId, msgDic[x.ShortCode], "");
                });

                var result = new {
                    taskGroupCount = newTaskGroups.Count,
                    taskCount = tasks.Count
                };
                return ActionUtils.Success(result);
            }));
        }
Exemplo n.º 4
0
        public ActionResult ExportTable(string projectSeriesGuid)
        {
            return(ActionUtils.Json(() =>
            {
                var projectSeries = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid);
                var project = projectSeries.CurrentProject.Instance;
                CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Read);

                var taskGroups = projectSeries.CurrentProject.TaskGroups;
                var allPermissionTaskGroupUid = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.TaskGroup, PermissionType.Read).ToDictionary(x => x);
                var hasPermissionTaskGroups = taskGroups.Where(x => allPermissionTaskGroupUid.ContainsKey(x.Instance.Guid)).ToList();

                var tableDic = new Dictionary <TaskGroup, List <Task> >();
                var tasks = new List <Task>();

                var projectLogicModel = new ProjectLogicModel(CurrentUserName, project);
                hasPermissionTaskGroups.ForEach(x => {
                    var taskGroupLogicModel = projectLogicModel.TaskGroups.Single(y => y.Instance.Guid == x.Instance.Guid);
                    var allPermissionTaskUid = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.Task, PermissionType.Read).ToDictionary(y => y);
                    var hasPermissionTasks = taskGroupLogicModel.Tasks.Where(y => allPermissionTaskUid.ContainsKey(y.ShortCode)).ToList();
                    tableDic.Add(x.Instance, hasPermissionTasks);
                    tasks.AddRange(hasPermissionTasks);
                });

                var personInCharges = tasks.Where(x => !string.IsNullOrWhiteSpace(x.PersonInCharge)).Select(x => x.PersonInCharge);
                Platform.UserProfile.Precache(personInCharges);

                var table = new DataTable();
                table.Columns.Add("工作组名称", typeof(System.String));
                table.Columns.Add("工作组描述", typeof(System.String));
                table.Columns.Add("工作名称", typeof(System.String));
                table.Columns.Add("开始时间", typeof(System.String));
                table.Columns.Add("截止时间", typeof(System.String));
                table.Columns.Add("工作状态", typeof(System.String));
                table.Columns.Add("负责人", typeof(System.String));
                table.Columns.Add("工作目标", typeof(System.String));
                table.Columns.Add("工作描述", typeof(System.String));
                foreach (var taskGroupName in tableDic.Keys)
                {
                    if (tableDic[taskGroupName].Count == 0)
                    {
                        var row = table.NewRow();
                        row["工作组名称"] = taskGroupName.Name;
                        row["工作组描述"] = taskGroupName.Description;
                        row["工作名称"] = string.Empty;
                        row["开始时间"] = string.Empty;
                        row["截止时间"] = string.Empty;
                        row["工作状态"] = string.Empty;
                        row["负责人"] = string.Empty;
                        row["工作目标"] = string.Empty;
                        row["工作描述"] = string.Empty;
                        table.Rows.Add(row);
                    }
                    else
                    {
                        foreach (var task in tableDic[taskGroupName])
                        {
                            var row = table.NewRow();
                            row["工作组名称"] = taskGroupName.Name;
                            row["工作组描述"] = taskGroupName.Description;
                            row["工作名称"] = task.Description;
                            row["开始时间"] = Toolkit.DateToString(task.StartTime);
                            row["截止时间"] = Toolkit.DateToString(task.EndTime);
                            row["工作状态"] = string.IsNullOrWhiteSpace(task.TaskStatus.ToString()) || task.TaskStatus.ToString() == "-"? task.TaskStatus.ToString()
                                : TranslateUtils.ToCnString(CommUtils.ParseEnum <TaskStatus>(task.TaskStatus.ToString()));
                            row["负责人"] = string.IsNullOrWhiteSpace(task.PersonInCharge) ? string.Empty :
                                         Platform.UserProfile.Get(task.PersonInCharge).RealName +   "(" + Platform.UserProfile.Get(task.PersonInCharge).UserName + ")";
                            row["工作目标"] = task.TaskTarget;
                            row["工作描述"] = task.TaskDetail;
                            table.Rows.Add(row);
                        }
                    }
                }

                var taskStatusIndex = table.Columns.IndexOf("工作状态");

                var sheet = new Sheet("TaskGroupTable", table);
                sheet.SheetStyle.Add(new CellRangeStyle()
                {
                    Range = CellRange.Column(taskStatusIndex), Style = new CellRangeStyleTaskStatus(), Rule = CellRangeRule.IgnoreEmptyCell
                });
                var workbook = new Workbook("TaskGroupTable", sheet);
                var resource = workbook.ToExcel(CurrentUserName);

                return ActionUtils.Success(resource.Guid);
            }));
        }
Exemplo n.º 5
0
        public MemoryStream GenerateCompareResultExcel(DataTable newTable, int taskStatusIndex)
        {
            IWorkbook  workbook = new XSSFWorkbook();
            ISheet     sheet    = workbook.CreateSheet("TaskGroupTable");
            ICellStyle style    = ExcelUtils.CreateBorderedStyle(workbook);

            //文字颜色的样式(四种:红色,绿色,灰色,蓝色)
            ICellStyle fontRedStyle   = ExcelUtils.GetFontColorStyle(workbook, ExcelFontColor.Red);
            ICellStyle fontGreenStyle = ExcelUtils.GetFontColorStyle(workbook, ExcelFontColor.Green);
            ICellStyle fontBlueStyle  = ExcelUtils.GetFontColorStyle(workbook, ExcelFontColor.Blue);

            IRow headerRow = sheet.CreateRow(0);

            foreach (DataColumn column in newTable.Columns)
            {
                var cell = headerRow.CreateCell(column.Ordinal);
                cell.SetCellValue(column.Caption);
                cell.CellStyle = style;
            }

            for (int iRow = 0; iRow < newTable.Rows.Count; iRow++)
            {
                var  row     = newTable.Rows[iRow];
                IRow dataRow = sheet.CreateRow(iRow + 1);

                for (int iColumn = 0; iColumn < newTable.Columns.Count; iColumn++)
                {
                    var column = newTable.Columns[iColumn];
                    var cell   = dataRow.CreateCell(column.Ordinal);
                    cell.CellStyle = style;
                    var cellValue = row[column].ToString();
                    if (iColumn != taskStatusIndex || cellValue == string.Empty || cellValue == "-")
                    {
                        cell.SetCellValue(cellValue);
                    }
                    else
                    {
                        cell.SetCellValue(TranslateUtils.ToCnString(CommUtils.ParseEnum <TaskStatus>(cellValue)));
                        if (cellValue == "Finished" || cellValue == "Error")
                        {
                            cell.CellStyle = fontGreenStyle;
                        }
                        else if (cellValue == "Running" || cellValue == "Waitting")
                        {
                            cell.CellStyle = fontBlueStyle;
                        }
                        else if (cellValue == "Overdue")
                        {
                            cell.CellStyle = fontRedStyle;
                        }
                    }
                }
            }

            //列宽自适应
            for (int i = 0; i < newTable.Columns.Count; i++)
            {
                sheet.AutoSizeColumn(i);
            }

            //转为字节数组
            MemoryStream ms = new MemoryStream();

            workbook.Write(ms);
            var buf = ms.ToArray();


            var temproaryFolder = CommUtils.CreateTemporaryFolder(m_userName);
            var filePath        = Path.Combine(temproaryFolder, "Temporary.xlsx");

            //保存为Excel文件
            using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
            {
                fs.Write(buf, 0, buf.Length);
                fs.Flush();
            }

            var buffer = System.IO.File.ReadAllBytes(filePath);

            CommUtils.DeleteFolderAync(temproaryFolder);

            return(new MemoryStream(buffer));
        }