public MainWindow() { InitializeComponent(); OnReloadButtonClick(null, null); using (var db = new TimeLoggerContext()) { var todayData = db.AttendanceLeaves.Where(a => a.TargetDate == DateTime.Today).ToList(); if (todayData == null || todayData.Count == 0) { var attendance = new AttendanceWindow(); attendance.Topmost = true; Task startupTask = attendance.doAttendance(); if (startupTask != null) { onTaskStart(startupTask); } var attendanceRecord = new AttendanceLeave(); attendanceRecord.TargetDate = DateTime.Today; attendanceRecord.Attendance = DateTime.Now; db.AttendanceLeaves.Add(attendanceRecord); db.SaveChanges(); } } if (runningTask == null) { CurrentTaskLabel.Content = "未割当"; } }
public TaskManageWindow() { InitializeComponent(); using (var db = new TimeLoggerContext()) { taskTable.ItemsSource = db.Tasks.OrderBy(t => t.Id).ToList(); } }
public AttendanceWindow() { InitializeComponent(); using (var db = new TimeLoggerContext()) { var tasks = db.Tasks.Where(t => t.IsEnabled).OrderBy(t => t.TaskCode).ToList().ConvertAll(t => TaskModel.of(t)); tasks.Insert(0, new EmptyTaskModel()); TaskSelector.ItemsSource = tasks; } }
private void onLeaveClick(object sender, RoutedEventArgs e) { onTaskStop(runningTask); using (var db = new TimeLoggerContext()) { var todayData = db.AttendanceLeaves.Where(a => a.TargetDate == DateTime.Today).First(); todayData.Leave = DateTime.Now; db.SaveChanges(); } Close(); }
private List <TaskWorkFact> loadDailyWorkFacts(DateTime targetDate) { List <TaskWorkFact> dailyWorkFact; using (var db = new TimeLoggerContext()) { var from = targetDate.Date; var to = from.AddDays(1).AddMilliseconds(-1); dailyWorkFact = db.TaskWorkFacts.Where(f => from <= f.StartAt && f.EndAt <= to) // .OrderBy(f => f.TaskId).ToList(); } return(dailyWorkFact); }
private void OnReloadButtonClick(object sender, RoutedEventArgs e) { var latestTaskRows = new List <TaskRow>(); using (var db = new TimeLoggerContext()) { foreach (var task in db.Tasks.Where(t => t.IsEnabled).OrderBy(t => t.TaskCode)) { var row = new TaskRow(task); row.OnTaskStart += onTaskStart; row.OnTaskStop += onTaskStop; latestTaskRows.Add(row); } } TaskList.Children.Clear(); latestTaskRows.ForEach(r => TaskList.Children.Add(r)); }
private void onTaskStart(Task task) { if (runningTask != null) { onTaskStop(runningTask); } runningTask = task; runningFact = new TaskWorkFact(); runningFact.TaskId = task.Id.Value; runningFact.StartAt = DateTime.Now; using (var db = new TimeLoggerContext()) { db.TaskWorkFacts.Add(runningFact); db.SaveChanges(); } CurrentTaskLabel.Content = runningTask; }
public async Task <IActionResult> PostInTime(LogTimeRequest request) { IServiceProvider provider = TestServiceProvider.CreateProvider( services => _setup(services)); using IServiceScope scope = provider.CreateScope(); var result = await scope.ServiceProvider .GetRequiredService <TimesheetController>() .PostInTime(request); TimeLoggerContext dbContext = scope.ServiceProvider.GetRequiredService <TimeLoggerContext>(); Timesheets.AddRange(dbContext.TimeSheets); return(result); }
private void onTaskStop(Task task) { if (runningTask == null) { return; } runningFact.EndAt = DateTime.Now; runningFact.updateManhour(); using (var db = new TimeLoggerContext()) { db.TaskWorkFacts.Attach(runningFact); db.Entry(runningFact).State = EntityState.Modified; db.SaveChanges(); } runningFact = null; runningTask = null; CurrentTaskLabel.Content = "未割当"; }
private void OnReportButtonClick(object sender, RoutedEventArgs e) { var todayWorkFact = loadDailyWorkFacts(DateTime.Today); var factByTask = todayWorkFact.GroupBy(f => f.TaskId, (t, fs) => new KeyValuePair <long, decimal>(t, fs.Sum(f => f.Manhour))).ToDictionary(p => p.Key, p => p.Value); if (runningFact != null) { TimeSpan span = DateTime.Now.Subtract(runningFact.StartAt); decimal hour = new decimal(span.Hours); decimal min = new decimal(span.Minutes); min = decimal.Divide(min, 60); min = decimal.Round(min, 2); var manhour = hour + min; if (factByTask.Keys.Contains(runningFact.TaskId)) { factByTask[runningFact.TaskId] = factByTask[runningFact.TaskId] + manhour; } else { factByTask[runningFact.TaskId] = manhour; } } if (factByTask.Keys.Count == 0) { MessageBox.Show("実績データがありません"); return; } Dictionary <long?, Task> tasks; using (var db = new TimeLoggerContext()) { tasks = db.Tasks.ToDictionary(t => t.Id); } StringBuilder builder = new StringBuilder(); foreach (var fact in factByTask) { var task = tasks[fact.Key]; builder.AppendLine(String.Format("{0}:{1} \t{2}h", task.TaskCode, task.TaskName, fact.Value)); } MessageBox.Show(builder.ToString()); }
private void OnOkButtonClick(object sender, RoutedEventArgs e) { using (var db = new TimeLoggerContext()) { var tasks = taskTable.ItemsSource.OfType <Task>().ToList(); foreach (var task in tasks) { if (task.Id == null) { db.Tasks.Add(task); } else { db.Tasks.Attach(task); // FIXME すべてのレコードが必ず更新される db.Entry(task).State = System.Data.Entity.EntityState.Modified; } } db.SaveChanges(); } Close(); }
public RepositoryHealthCheck(TimeLoggerContext context, ILogger <RepositoryHealthCheck> logger) { _context = context; _logger = logger; }
public TimeLoggerRepository(TimeLoggerContext context) { _context = context; }
private async System.Threading.Tasks.Task loadMonthlyData(DateTime targetYearMonth) { status.Content = "集計中..."; await System.Threading.Tasks.Task.Run(() => { DateTime monthFrom = targetYearMonth.AddDays(-(targetYearMonth.Day - 1)); DateTime monthTo = monthFrom.AddMonths(1).AddMilliseconds(-1); Dictionary <DateTime, AttendanceLeave> attendanceLeaves; List <TaskWorkFact> taskWorkFacts; using (var db = new TimeLoggerContext()) { attendanceLeaves = db.AttendanceLeaves.Where(a => a.TargetDate >= monthFrom && a.TargetDate <= monthTo).ToDictionary(a => a.TargetDate.Date); // ↓DBで集計させるべき taskWorkFacts = db.TaskWorkFacts.Where(f => f.StartAt >= monthFrom && f.StartAt <= monthTo).ToList(); var hoge = from task in db.TaskWorkFacts where task.StartAt >= monthFrom && task.StartAt <= monthTo select task; } var workFactByDate = new Dictionary <DateTime, List <TaskWorkFact> >(); foreach (var workfact in taskWorkFacts) { var date = workfact.StartAt.Date; var workFacts = workFactByDate.Get(date); if (workFacts == null) { workFacts = new List <TaskWorkFact>(); workFactByDate[date] = workFacts; } workFacts.Add(workfact); } var workFactSummary = new Dictionary <DateTime, Dictionary </*task id*/ long, TaskWorkFact> >(); var taskIds = new HashSet <long>(); foreach (var workfacts in workFactByDate) { var summaries = new Dictionary <long, TaskWorkFact>(); foreach (var workfact in workfacts.Value) { var summary = summaries.Get(workfact.TaskId); if (summary == null) { summary = new TaskWorkFact(); summary.TaskId = workfact.TaskId; summaries[workfact.TaskId] = summary; } summary.Manhour += workfact.Manhour; if (summary.Manhour > 0) { taskIds.Add(summary.TaskId); } } workFactSummary[workfacts.Key] = summaries; } Dictionary <long, Task> tasks; using (var db = new TimeLoggerContext()) { tasks = db.Tasks.Where(t => taskIds.Contains(t.Id.Value)).OrderBy(t => t.TaskCode).ToDictionary(t => t.Id.Value); } Dispatcher.Invoke(() => { workFactGrid.Columns.Clear(); foreach (var task in tasks) { var column = new DataGridTextColumn(); column.Header = task.Value.ToString(); column.Binding = new Binding("Data[t" + task.Value.Id + "].Manhour"); workFactGrid.Columns.Add(column); } }); var attendanceGridSource = new List <AttendanceLeave>(); var workFactGridSource = new List <MonthlySummaryWorkFactModel>(); for (var processDate = monthFrom; processDate <= monthTo; processDate = processDate.AddDays(1)) { var attendanceLeave = attendanceLeaves.Get(processDate); if (attendanceLeave == null) { attendanceLeave = new AttendanceLeave(); attendanceLeave.TargetDate = processDate; } attendanceGridSource.Add(attendanceLeave); var workFacts = new Dictionary <String, TaskWorkFact>(); var summaries = workFactSummary.Get(processDate); if (summaries != null) { foreach (var summary in summaries.Values) { workFacts["t" + summary.TaskId] = summary; } } workFactGridSource.Add(MonthlySummaryWorkFactModel.of(workFacts)); } Dispatcher.Invoke(() => { attendanceGrid.ItemsSource = attendanceGridSource; workFactGrid.ItemsSource = workFactGridSource; }); var totalManhour = new Dictionary </*taskId*/ long, /*manhour*/ decimal>(); foreach (var workFact in taskWorkFacts) { var taskId = workFact.TaskId; var manhour = workFact.Manhour; if (totalManhour.ContainsKey(taskId)) { manhour += totalManhour[taskId]; } totalManhour[taskId] = manhour; } var totalManhourGridSource = new List <TotalManhourModel>(); foreach (var item in totalManhour) { var task = tasks[item.Key]; var model = new TotalManhourModel(); model.DisplayName = task.ToString(); model.TotalManhour = item.Value; totalManhourGridSource.Add(model); } totalManhourGridSource.Sort((o1, o2) => o1.DisplayName.CompareTo(o2.DisplayName)); Dispatcher.Invoke(() => totalWorkFactGrid.ItemsSource = totalManhourGridSource); }); status.Content = ""; }
public DatabaseMigrator(TimeLoggerContext context) { _context = context; }