Пример #1
0
        // GET: Reports
        public ActionResult HoursPerWorkAssignment()
        {
            TimesheetMobileEntities entities = new TimesheetMobileEntities();

            try
            {
                DateTime today    = DateTime.Today.AddDays(-100);
                DateTime tomorrow = today.AddDays(101);

                //haetaan kaikki kuluvan päivän tuntikirjaukset

                List <Timesheet> allTimesheetsToday = (from ts in entities.Timesheet
                                                       where (ts.StartTime > today) &&
                                                       (ts.StartTime < tomorrow) &&
                                                       (ts.WorkComplete == true)
                                                       select ts).ToList();

                //ryhmitellään kirjaukset tehtävittäin ja lasketaan kestot
                List <HoursPerWorkAssignmentModel> model = new List <HoursPerWorkAssignmentModel>();

                foreach (Timesheet timesheet in allTimesheetsToday)
                {
                    int assignmentId = timesheet.Id_WorkAssignment.Value;
                    HoursPerWorkAssignmentModel existing = model.Where(
                        m => m.Id_WorkAssignment == assignmentId).FirstOrDefault();

                    if (existing != null)
                    {
                        existing.TotalHours += (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours;
                    }
                    else
                    {
                        //Timesheet timesheet = timesheet;
                        existing = new HoursPerWorkAssignmentModel()
                        {
                            Id_WorkAssignment  = assignmentId,
                            WorkAssignmentName = timesheet.WorkAssignments.Title,
                            TotalHours         = (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours,
                            WorkComplete       = timesheet.WorkComplete,
                            StartTime          = timesheet.StartTime.Value,
                            StopTime           = timesheet.StopTime.Value,
                            Comments           = timesheet.Comments
                        };
                        model.Add(existing);
                    }
                }

                return(View(model));
            }
            finally
            {
                entities.Dispose();
            }
        }
Пример #2
0
        public ActionResult HoursPerWorkAssignmentAsExcel3(DateTime dateFrom, DateTime dateTo)
        {
            HoursPerWorkAssignmentModel dates = new HoursPerWorkAssignmentModel();

            dates.dateFrom = dateFrom;
            dates.dateTo   = dateTo;



            StringBuilder csv = new StringBuilder();

            // luodaan CSV-muotoinen tiedosto
            TimesheetMobileEntities entities = new TimesheetMobileEntities();

            try
            {
                // haetaan kaikki kuluvan päivän tuntikirjaukset
                List <Timesheet> allTimesheetsTime = (from ts in entities.Timesheet
                                                      where (ts.StartTime > dateFrom) &&
                                                      (ts.StartTime < dateTo) &&
                                                      (ts.WorkComplete == true)
                                                      select ts).ToList();


                {
                    {
                        csv.AppendLine("Id_WorkAssignment" + ";" + "Id_Employee" + ";" + "StartTime" + ";" + "StopTime" + ";" + "TotalHours" + ";" + "Comments" + ";");


                        foreach (Timesheet timesheet in allTimesheetsTime)
                        {
                            csv.AppendLine(timesheet.Id_WorkAssignment + ";" + timesheet.Id_Employee + ";" +
                                           timesheet.StartTime + ";" + timesheet.StopTime + ";" + (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours + ";" + timesheet.Comments + ";");
                        }
                    }
                }
            }
            finally
            {
                entities.Dispose();
            }
            //Palautetaan CSV-tiedot selaimelle
            byte[] buffer = Encoding.UTF8.GetBytes(csv.ToString());
            return(File(buffer, "text/csv", "Työtunnit3.csv"));
        }
Пример #3
0
        public ActionResult HoursPerWorkAssignment()
        {
            panconDatabaseEntities entities = new panconDatabaseEntities();

            try
            {
                DateTime today     = DateTime.Today;
                DateTime tommorrow = today.AddDays(1);

                List <Timesheets> allTimesheetsToday = (from ts in entities.Timesheets
                                                        where (ts.StartTime > today) &&
                                                        (ts.StartTime < tommorrow) &&
                                                        (ts.WorkComplete == true)
                                                        select ts).ToList();

                List <HoursPerWorkAssignmentModel> model = new List <HoursPerWorkAssignmentModel>();

                foreach (Timesheets timesheet in allTimesheetsToday)
                {
                    int assignmentId = timesheet.WorkAssignmentId.Value;
                    HoursPerWorkAssignmentModel existing = model.Where(
                        m => m.WorkAssignmentId == assignmentId).FirstOrDefault();

                    if (existing != null)
                    {
                        existing.TotalHours += (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours;
                    }
                    else
                    {
                        existing = new HoursPerWorkAssignmentModel()
                        {
                            WorkAssignmentId   = assignmentId,
                            WorkAssignmentName = timesheet.WorkAssignments.Title,
                            TotalHours         = (timesheet.StopTime.Value - timesheet.StartTime.Value).TotalHours
                        };
                        model.Add(existing);
                    }
                }
                return(View(model));
            }
            finally
            {
                entities.Dispose();
            }
        }