Exemplo n.º 1
0
 public void Edit(WorkingTimeRange workingTimeRange)
 {
     RepositoryAction.Transaction((c, t) =>
     {
         var row = WorkingTimeTableRow.FromDomainObject(workingTimeRange);
         var dao = new WorkingTimeDao(c, t);
         dao.Update(row);
     });
 }
Exemplo n.º 2
0
        public WorkTaskWithTimesDto[] SelectByYmd(YmdString ymd, bool containsCompleted)
        {
            var list = new List <WorkTaskWithTimesDto>();

            RepositoryAction.Query(c =>
            {
                var workTaskDao    = new WorkTaskDao(c, null);
                var workingTimeDao = new WorkingTimeDao(c, null);
                var processes      = new WorkProcessDao(c, null).SelectAll();
                var products       = new ProductDao(c, null).SelectAll();
                var clients        = new ClientDao(c, null).SelectAll();
                var completedDao   = new WorkTaskCompletedDao(c, null);

                var tasks     = workTaskDao.SelectPlaned(ymd, containsCompleted);
                var times     = workingTimeDao.SelectByTaskIds(tasks.Select(t => t.Id).Distinct().ToArray());
                var completed = completedDao.SelectCompleted(tasks.Select(t => t.Id).Distinct().ToArray());

                foreach (var task in tasks)
                {
                    var dto = new WorkTaskWithTimesDto
                    {
                        TaskId       = new Identity <Domain.Domain.Tasks.WorkTask>(task.Id),
                        ClientName   = clients.FirstOrDefault(c => c.Id == task.ClientId)?.Name ?? "",
                        ProcessName  = processes.FirstOrDefault(p => p.Id == task.ProcessId)?.Title ?? "",
                        ProductName  = products.FirstOrDefault(p => p.Id == task.ProductId)?.Name ?? "",
                        TaskCategory = task.TaskCategory,
                        Title        = task.Title,
                        IsCompleted  = completed.Any(c => c == task.Id),
                        IsScheduled  = task.TaskSource == Domain.Domain.Tasks.TaskSource.Schedule,
                    };

                    dto.WorkingTimes = times.Where(t => t.TaskId == task.Id)
                                       .Select(t => t.ToDomainObject())
                                       .OrderBy(t => t.TimePeriod.StartDateTime)
                                       .ThenBy(t => t.Id)
                                       .ToArray();

                    list.Add(dto);
                }
            });

            try
            {
                return(list.OrderBy(i => i.WorkingTimes.Any(t => t.IsDoing) ? 0 : 1)
                       .ThenByDescending(i => i.WorkingTimes.Where(t => t.TimePeriod.IsFuture == false).Any() ? i.WorkingTimes.Where(t => t.TimePeriod.IsFuture == false).Max(t => t.TimePeriod.StartDateTime) : DateTime.MinValue)
                       .ThenBy(i => i.WorkingTimes.Where(t => t.TimePeriod.IsFuture).Any() ? i.WorkingTimes.Where(t => t.TimePeriod.IsFuture).Min(t => t.TimePeriod.StartDateTime) : DateTime.MaxValue)
                       .ThenBy(i => i.TaskId.Value).ToArray());
            }
            catch (Exception)
            {
                return(list.ToArray());
            }
        }
Exemplo n.º 3
0
        public WorkingTimeRange SelectById(Identity <WorkingTimeRange> id)
        {
            WorkingTimeRange result = null;

            RepositoryAction.Query(c =>
            {
                var dao = new WorkingTimeDao(c, null);

                result = dao.SelectId(id.Value)?.ToDomainObject();
            });

            return(result);
        }
Exemplo n.º 4
0
        public WorkingTimeRange[] SelectByTaskId(Identity <WorkTask> taskId)
        {
            WorkingTimeRange[] result = null;

            RepositoryAction.Query(c =>
            {
                var dao = new WorkingTimeDao(c, null);

                result = dao.SelectByTaskIds(new int[] { taskId.Value })
                         .Select(t => t.ToDomainObject())
                         .ToArray();
            });

            return(result);
        }
Exemplo n.º 5
0
        public WorkingTimeRange Add(WorkingTimeRange workingTimeRange)
        {
            var row = WorkingTimeTableRow.FromDomainObject(workingTimeRange);

            RepositoryAction.Transaction((c, t) =>
            {
                var dao = new WorkingTimeDao(c, t);
                var id  = dao.Insert(row);

                // ID採番結果
                row.Id = id;
            });

            return(row.ToDomainObject());
        }
Exemplo n.º 6
0
        public WorkingTimeRange[] SelectByYmd(string ymd)
        {
            WorkingTimeRange[] results = null;

            RepositoryAction.Query(c =>
            {
                var dao = new WorkingTimeDao(c, null);

                results = dao.SelectYmd(ymd)
                          .Select(r => r.ToDomainObject())
                          .OrderBy(r => r.TimePeriod.StartDateTime)
                          .ToArray();
            });

            return(results);
        }
        public DailyWorkResults SelectByYearMonth(YearMonth yearMonth)
        {
            var list            = new List <WorkingTimeRecordForReport>();
            var listWorkingHour = new List <WorkingHour>();

            RepositoryAction.Query(c =>
            {
                var workTaskDao    = new WorkTaskDao(c, null);
                var workingTimeDao = new WorkingTimeDao(c, null);

                var processes = new WorkProcessDao(c, null).SelectAll()
                                .Select(d => d.ToDomainObject())
                                .ToDictionary(p => p.Id);

                var products = new ProductDao(c, null).SelectAll()
                               .Select(d => d.ToDomainObject())
                               .ToDictionary(p => p.Id);

                var clients = new ClientDao(c, null).SelectAll()
                              .Select(d => d.ToDomainObject())
                              .ToDictionary(p => p.Id);

                var param = new {
                    start = yearMonth.StartDate.ToString("yyyyMMdd"),
                    end   = yearMonth.EndDate.ToString("yyyyMMdd")
                };

                var rows = c.Query <TableRow>(sql, param);

                foreach (var task in rows)
                {
                    processes.TryGetValue(new Identity <WorkProcess>(task.WorkProcessId), out WorkProcess targetProcess);
                    products.TryGetValue(new Identity <Product>(task.ProductId), out Product targetProduct);
                    clients.TryGetValue(new Identity <Client>(task.ClientId), out Client targetClient);

                    if (string.IsNullOrEmpty(task.EndTime))
                    {
                        continue;
                    }

                    var dto = new WorkingTimeRecordForReport
                    {
                        Ymd           = new YmdString(task.Ymd),
                        TaskCategory  = task.TaskCategory,
                        WorkProcess   = targetProcess,
                        Product       = targetProduct ?? Product.Empty,
                        Client        = targetClient ?? Client.Empty,
                        StartDateTime = DateTimeParser.ConvertFromYmdHHmmss(task.Ymd, task.StartTime).Value,
                        EndDateTime   = DateTimeParser.ConvertFromYmdHHmmss(task.Ymd, task.EndTime).Value,
                        Title         = task.Title,
                        WorkingTimeId = new Identity <WorkingTimeRange>(task.WorkingTimeId),
                        WorkTaskId    = new Identity <WorkTask>(task.WorkTaskId),
                        IsTemporary   = task.IsTemporary == "1",
                        IsScheduled   = string.IsNullOrEmpty(task.ImportKey) == false,
                    };

                    list.Add(dto);
                }

                var workingHourDao = new WorkingHourDao(c, null);
                listWorkingHour.AddRange(workingHourDao.SelectByYmdRange(param.start, param.end).Select(r => r.ConvertToDomainObjects()));
            });

            return(new DailyWorkResults
            {
                WorkingTimeRecordForReports = list.OrderBy(t => t.StartDateTime).ToArray(),
                WorkingHours = listWorkingHour.OrderBy(h => h.Ymd).ToArray(),
            });
        }