public ReportPackage GetReportByUser(string User_CAI, DateTime myDateFrom, DateTime myDateTo) { //The Report Package is a container for all data that must be displayed on the Report View //The Report Package is used as the Model for the report index View //The Report Package contains the following: // 1. user information in the form of a user object // 2. collection of timesheets for active(unhidden) projects for the date period. // The timesheet object contains project information and a collection of days. ReportPackage myPackage = new ReportPackage(); tbl_User myuser = userdb.GetUserByID(User_CAI); myPackage.User = myuser; myPackage.DateFrom = myDateFrom; myPackage.DateTo = myDateTo; myPackage.User_CAI = User_CAI; myPackage.GrandTotal = 0; myPackage.DayTotals = new List <day>(); myPackage.DaySacoTotals = sacodb.SacoDays(myuser.EmployeeNumber, myDateFrom, myDateTo); myPackage.TimeSheets = new List <timesheet>(); int i = 1; for (DateTime d = myDateFrom; d < myDateTo.AddDays(1); d = d.AddDays(1)) { myPackage.DayTotals.Add(new day() { Number = i, Day = i, HoursWorked = 0M }); i++; } IQueryable <tbl_Resource> myResources = rdb.FindResourcesByCAI(User_CAI).OrderBy(t => t.tbl_Project.Project_Number); if (myResources.Count() > 0) { foreach (var res in myResources) { if (ProjectExists((int)res.Project_ID)) { timesheet resourceTimeSheet = new timesheet(); resourceTimeSheet.editStatus = true; if (res.tbl_Project.tbl_Status.Status == "CLSD") { resourceTimeSheet.editStatus = false; } if (res.active == false) { resourceTimeSheet.editStatus = false; } resourceTimeSheet.Resource_ID = res.Resource_ID; resourceTimeSheet.Project_ID = (int)res.Project_ID; resourceTimeSheet.Project_Number = (int)res.tbl_Project.Project_Number; resourceTimeSheet.Project_Name = res.tbl_Project.Project_Name; resourceTimeSheet.Project_Name_Abrv = res.tbl_Project.Project_Name; resourceTimeSheet.SAP = res.tbl_Project.SAP_Number; resourceTimeSheet.WBS = res.tbl_Project.WBS; resourceTimeSheet.Status = res.tbl_Project.tbl_Status.Status; resourceTimeSheet.hide = res.Hide; resourceTimeSheet.ProjectHours = (!res.ResourceHours.HasValue) ? 0M : res.ResourceHours.Value; decimal?test = this.GetHoursByResourceAndDate(res.Resource_ID, DateTime.Parse("01-Jan-2007"), DateTime.Now).Sum(s => s.Hours); resourceTimeSheet.Total = (!test.HasValue) ? 0M : test.Value; IQueryable <tbl_TimeSheet> timeList = this.GetHoursByResourceAndDate( res.Resource_ID, DateTime.Parse(String.Format("{0: yyyy/MM/dd 00:00:00}", myDateFrom)), DateTime.Parse(String.Format("{0: yyyy/MM/dd 23:59:59}", myDateTo))).OrderBy(t => t.Date); decimal Monthtotal = 0M; resourceTimeSheet.Days = new List <day>(); //Initialize Days to null values for (DateTime d = myDateFrom; d < myDateTo.AddDays(1); d = d.AddDays(1)) { resourceTimeSheet.Days.Add(new day() { Day = d.Day, Month = d.Month, Year = d.Year, HoursWorked = null }); } if (timeList.Count() > 0) { foreach (var t in timeList) { foreach (var d in resourceTimeSheet.Days) { if (((DateTime)t.Date).Day == d.Day && ((DateTime)t.Date).Month == d.Month && ((DateTime)t.Date).Year == d.Year) { d.HoursWorked = (decimal)t.Hours; Monthtotal += (decimal)t.Hours; } } } } resourceTimeSheet.MonthTotal = Monthtotal; if (resourceTimeSheet.SAP != "Leave") { myPackage.GrandTotal += Monthtotal; } for (int j = 0; j < resourceTimeSheet.Days.Count; j++) { if (resourceTimeSheet.Days[j].HoursWorked.HasValue) { if (resourceTimeSheet.SAP != "Leave") { myPackage.DayTotals[j].HoursWorked += resourceTimeSheet.Days[j].HoursWorked.Value; } } } if (Monthtotal > 0 || resourceTimeSheet.hide == false) { myPackage.TimeSheets.Add(resourceTimeSheet); } } } } return(myPackage); }
public ReportPackage GetReportByUser(string User_CAI, DateTime myDateFrom, DateTime myDateTo) { //The Report Package is a container for all data that must be displayed on the Report View //The Report Package is used as the Model for the report index View //The Report Package contains the following: // 1. user information in the form of a user object // 2. collection of timesheets for active(unhidden) projects for the date period. // The timesheet object contains project information and a collection of days. ReportPackage myPackage = new ReportPackage(); tbl_User myuser = userdb.GetUserByID(User_CAI); myPackage.User = myuser; myPackage.DateFrom = myDateFrom; myPackage.DateTo = myDateTo; myPackage.User_CAI = User_CAI; myPackage.GrandTotal = 0; myPackage.DayTotals = new List<day>(); myPackage.DaySacoTotals = sacodb.SacoDays(myuser.EmployeeNumber, myDateFrom, myDateTo); myPackage.TimeSheets = new List<timesheet>(); int i = 1; for (DateTime d = myDateFrom; d < myDateTo.AddDays(1); d= d.AddDays(1)) { myPackage.DayTotals.Add(new day() {Number = i, Day = i, HoursWorked = 0M }); i++; } IQueryable<tbl_Resource> myResources = rdb.FindResourcesByCAI(User_CAI).OrderBy(t => t.tbl_Project.Project_Number); if (myResources.Count() > 0) { foreach (var res in myResources) { if (ProjectExists((int)res.Project_ID)) { timesheet resourceTimeSheet = new timesheet(); resourceTimeSheet.editStatus = true; if (res.tbl_Project.tbl_Status.Status == "CLSD") resourceTimeSheet.editStatus = false; if (res.active == false) resourceTimeSheet.editStatus = false; resourceTimeSheet.Resource_ID = res.Resource_ID; resourceTimeSheet.Project_ID = (int)res.Project_ID; resourceTimeSheet.Project_Number = (int)res.tbl_Project.Project_Number; resourceTimeSheet.Project_Name = res.tbl_Project.Project_Name; resourceTimeSheet.Project_Name_Abrv = res.tbl_Project.Project_Name; resourceTimeSheet.SAP = res.tbl_Project.SAP_Number; resourceTimeSheet.WBS = res.tbl_Project.WBS; resourceTimeSheet.Status = res.tbl_Project.tbl_Status.Status; resourceTimeSheet.hide = res.Hide; resourceTimeSheet.ProjectHours = (!res.ResourceHours.HasValue) ? 0M : res.ResourceHours.Value; decimal? test = this.GetHoursByResourceAndDate(res.Resource_ID, DateTime.Parse("01-Jan-2007"), DateTime.Now).Sum(s => s.Hours); resourceTimeSheet.Total = (!test.HasValue) ? 0M : test.Value; IQueryable<tbl_TimeSheet> timeList = this.GetHoursByResourceAndDate( res.Resource_ID, DateTime.Parse(String.Format("{0: yyyy/MM/dd 00:00:00}", myDateFrom)), DateTime.Parse(String.Format("{0: yyyy/MM/dd 23:59:59}", myDateTo))).OrderBy(t => t.Date); decimal Monthtotal = 0M; resourceTimeSheet.Days = new List<day>(); //Initialize Days to null values for (DateTime d = myDateFrom; d < myDateTo.AddDays(1); d = d.AddDays(1)) { resourceTimeSheet.Days.Add(new day() { Day = d.Day, Month = d.Month, Year=d.Year , HoursWorked = null }); } if (timeList.Count() > 0) { foreach (var t in timeList) { foreach (var d in resourceTimeSheet.Days) { if (((DateTime)t.Date).Day == d.Day && ((DateTime)t.Date).Month == d.Month && ((DateTime)t.Date).Year == d.Year) { d.HoursWorked = (decimal)t.Hours; Monthtotal += (decimal)t.Hours; } } } } resourceTimeSheet.MonthTotal = Monthtotal; if (resourceTimeSheet.SAP != "Leave") myPackage.GrandTotal += Monthtotal; for (int j = 0; j < resourceTimeSheet.Days.Count; j++) { if (resourceTimeSheet.Days[j].HoursWorked.HasValue) { if (resourceTimeSheet.SAP != "Leave") myPackage.DayTotals[j].HoursWorked += resourceTimeSheet.Days[j].HoursWorked.Value; } } if (Monthtotal > 0 || resourceTimeSheet.hide == false) myPackage.TimeSheets.Add(resourceTimeSheet); } } } return myPackage; }
private void GeneratePDF(ReportPackage myReportPackage) { if (myReportPackage.TimeSheets.Count > 0) { #region Table Header Collection List<string> ColList = new List<string>(); ColList.Add("Prj No."); ColList.Add("SAP"); ColList.Add("Cost Code"); ColList.Add("Project Name"); for (DateTime dt = myReportPackage.DateFrom; dt < myReportPackage.DateTo.AddDays(1); dt = dt.AddDays(1)) { ColList.Add(dt.ToString("ddd\ndd\nMMM")); } ColList.Add("Total"); #endregion #region Detail Collection List<ReportRow> rows = new List<ReportRow>(); int colcount = 0; int rowcount = 1; foreach (var r in myReportPackage.TimeSheets) { colcount = 0; List<ReportCell> cells = new List<ReportCell>(); cells.Add(new ReportCell() { colnum = colcount, rownum = rowcount, colspan = 1, type = CellType.String, value = r.Project_Number.ToString() }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.SAP }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.WBS }); cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.String, value = r.Project_Name }); foreach (var d in r.Days) { cells.Add(new ReportCell(){ colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = (!d.HoursWorked.HasValue) ? string.Empty : d.HoursWorked.Value.ToString("#0.00")}); } cells.Add(new ReportCell() { colnum = colcount++, rownum = rowcount, colspan = 1, type = CellType.Number, value = r.Total.ToString() }); rows.Add(new ReportRow() { row = cells }); rowcount++; } #endregion #region Footer Collection List<string> FooterList = new List<string>(); FooterList.Add(""); FooterList.Add(""); FooterList.Add(""); FooterList.Add(""); foreach (var d in myReportPackage.DayTotals) { FooterList.Add((String.IsNullOrEmpty(d.HoursWorked.ToString())) ? string.Empty : (d.HoursWorked.Value == 0) ? string.Empty : d.HoursWorked.Value.ToString("#0.00")); } FooterList.Add(myReportPackage.GrandTotal.ToString()); #endregion #region Saco Collection List<string> SacoList = new List<string>(); SacoList.Add(""); SacoList.Add(""); SacoList.Add(""); SacoList.Add(""); foreach (var d in myReportPackage.DaySacoTotals) { SacoList.Add((String.IsNullOrEmpty(d.HoursWorked.ToString())) ? string.Empty : (d.HoursWorked.Value == 0) ? string.Empty : d.HoursWorked.Value.ToString("#0.00")); } decimal sacototal = myReportPackage.DaySacoTotals.Sum(s => (decimal)s.HoursWorked); SacoList.Add(sacototal.ToString("#0.00")); #endregion #region Set the Column Widths float[] HeaderWidths = new float[colcount+1]; HeaderWidths[0] = 26f; HeaderWidths[1] = 30f; HeaderWidths[2] = 30f; HeaderWidths[3] = 60f; for (int col = 4; col < colcount; col++) { HeaderWidths[col] = 20f; } HeaderWidths[colcount] = 22f; #endregion //Create New PDF Timesheet Report IPDFReport myReport = new TimeSheetReport(true); //Assgin Column, Row and Footer collections to MyReport Object myReport.ColList = ColList; myReport.FooterList = FooterList; myReport.ReportRows = rows; myReport.SacoList = SacoList; //Set Report Properties myReport.Name = myReportPackage.User +" ["+ myReportPackage.User_CAI + "]"; myReport.Start = myReportPackage.DateFrom; myReport.End = myReportPackage.DateTo; myReport.filename = "TSD_TimeSheets_" + myReportPackage.User_CAI + "_" + myReportPackage.DateFrom.ToString("dd-MMM-yyyy") + "_" + myReportPackage.DateTo.ToString("dd-MMM-yyyy"); myReport.PageHeight = 595; myReport.LogoImagePath = "~/images/img_hallmark.gif"; myReport.ReportDescription = "TimeSheet"; //Assign Column Widths to myReport myReport.Headerwidths = HeaderWidths; //Write myReport myReport.GenerateXMLReport(); //Open Report and browswer myReport.OpenPDF(); } }