public ActionResult UploadProductivity(string imageData) { long teamId, repId; int month, year; teamId = (long)Session["IS_Team"]; repId = (long)Session["IS_Rep"]; month = (int)Session["IS_Month"]; year = (int)Session["IS_Year"]; OSC_Team oSC_Team = db.Teams.Find(teamId); OSC_Representative oSC_Representative = db.Representatives.Find(repId); string exportPath = Server.MapPath("~/Export"); string fileNameWitPath = exportPath + "/IndividualScorecard_" + oSC_Representative.LastName + oSC_Representative.FirstName + "_" + month.ToString() + "_" + year.ToString() + "_prodchart.png"; using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(imageData);//convert from base64 bw.Write(data); bw.Close(); } } return(null); }
public ActionResult ScorecardView(long?teamId, long?repId, int?month, int?year) { OSC_Team oSC_Team = db.Teams.Find((long)teamId); if (oSC_Team == null) { return(HttpNotFound()); } OSC_Representative oSC_Representative = db.Representatives.Find((long)repId); if (oSC_Representative == null) { return(HttpNotFound()); } oSC_Representative.FullName = oSC_Representative.FirstName + " " + oSC_Representative.LastName; ViewBag.Title = oSC_Representative.FullName; ViewBag.Team = oSC_Team.TeamName; ViewBag.Representative = oSC_Representative.FullName; ViewBag.Month = db.months.Where(m => m.Value == Convert.ToString((int)month)).First().Text; ViewBag.Year = year; Session["IS_Team"] = teamId; Session["IS_Rep"] = repId; Session["IS_Month"] = month; Session["IS_Year"] = year; return(View()); }
// GET: Representative/Details/5 public ActionResult Details(long?id) { #region "BTSS" string role; string user_name; try { role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); string grp_id = Session["grp_id"].ToString(); ViewBag.CanView = af.CanView(grp_id, "Representative"); ViewBag.CanEdit = af.CanEdit(grp_id, "Representative"); if (!ViewBag.CanView) { return(HttpNotFound()); } } catch (Exception exception) { string result = exception.Message.ToString(); return(HttpNotFound()); } #endregion "BTSS" #region "Method" if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OSC_Representative oSC_Representative = db.Representatives.Find(id); if (oSC_Representative == null) { return(HttpNotFound()); } if (!af.IsManaged(oSC_Representative.TeamId, user_name, role)) { return(HttpNotFound()); } oSC_Representative.Team = db.Teams.Find(oSC_Representative.TeamId); oSC_Representative.CoreRole = db.CoreRoles.Find(oSC_Representative.CoreRoleId); oSC_Representative.Location = db.Locations.Find(oSC_Representative.LocationId); #endregion "Method" #region "ViewBag" ViewBag.Years = db.years; ViewBag.Months = db.months; #endregion "ViewBag" #region "Return" return(View(oSC_Representative)); #endregion "Return" }
// GET: Representative/Edit/5 public ActionResult Edit(long?id) { #region "BTSS" string role; string user_name; try { role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); string grp_id = Session["grp_id"].ToString(); ViewBag.CanEdit = af.CanEdit(grp_id, "Representative"); if (!ViewBag.CanEdit) { return(HttpNotFound()); } } catch (Exception exception) { string result = exception.Message.ToString(); return(HttpNotFound()); } #endregion "BTSS" #region "ViewBagTeams" ViewBag.Teams = new SelectList(db.Teams, "TeamId", "TeamName"); #endregion "ViewBagTeams" #region "ViewBagLocations" ViewBag.Locations = new SelectList(db.Locations, "LocationId", "Location"); #endregion "ViewBagLocations" #region "ViewBagCoreRoles" ViewBag.CoreRoles = new SelectList(db.CoreRoles, "CoreRoleId", "CoreRole"); #endregion "ViewBagCoreRoles" #region "Method" if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OSC_Representative oSC_Representative = db.Representatives.Find(id); if (oSC_Representative == null) { return(HttpNotFound()); } #endregion "Method" #region "Return" return(View(oSC_Representative)); #endregion "Return" }
public ActionResult DeleteConfirmed(long id) { #region "BTSS" string role; string user_name; try { role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); string grp_id = Session["grp_id"].ToString(); ViewBag.CanDelete = af.CanDelete(grp_id, "Representative"); if (!ViewBag.CanDelete) { return(HttpNotFound()); } } catch (Exception exception) { string result = exception.Message.ToString(); return(HttpNotFound()); } #endregion "BTSS" #region "AddValues" OSC_Representative oSC_Representative = db.Representatives.Find(id); if (oSC_Representative == null) { return(HttpNotFound()); } oSC_Representative.IsActive = false; #endregion "AddValues" #region "Method" if (ModelState.IsValid) { db.Entry(oSC_Representative).State = EntityState.Modified; db.SaveChanges(); } #endregion "Method" #region "Return" return(RedirectToAction("Index")); #endregion "Return" //OSC_Representative oSC_Representative = db.Representatives.Find(id); //db.Representatives.Remove(oSC_Representative); //db.SaveChanges(); //return RedirectToAction("Index"); }
public PartialViewResult ScorecardCover() { long teamId, repId; int month, year; teamId = (long)Session["IS_Team"]; repId = (long)Session["IS_Rep"]; month = (int)Session["IS_Month"]; year = (int)Session["IS_Year"]; OSC_Team oSC_Team = db.Teams.Find(teamId); OSC_Representative oSC_Representative = db.Representatives.Find(repId); oSC_Representative.FullName = oSC_Representative.FirstName + " " + oSC_Representative.LastName; ViewBag.Team = oSC_Team.TeamName; ViewBag.Representative = oSC_Representative.FullName; ViewBag.Month = db.months.Where(m => m.Value == Convert.ToString(month)).First().Text; ViewBag.Year = year; return(PartialView()); }
public ActionResult Edit([Bind(Include = "RepId,PRDUserId,AIQUserId,BIUserId,WorkdayId,FirstName,MiddleName,LastName,TeamId,CoreRoleId,StartDate,EndDate,Comments,OnShoreRep,PhoneRep,IsVPN,WorkHours,LocationId,HasPrevious,PreviousId,IsCurrent,IsActive")] OSC_Representative oSC_Representative) { #region "BTSS" string role; string user_name; try { role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); string grp_id = Session["grp_id"].ToString(); ViewBag.CanEdit = af.CanEdit(grp_id, "Representative"); if (!ViewBag.CanEdit) { return(HttpNotFound()); } } catch (Exception exception) { string result = exception.Message.ToString(); return(HttpNotFound()); } #endregion "BTSS" #region "AddValues" if (Session["role"].ToString() != "Admin") { oSC_Representative.IsActive = true; } #endregion "AddValues" #region "Method" if (ModelState.IsValid) { db.Entry(oSC_Representative).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } #endregion "Method" #region "Return" return(View(oSC_Representative)); #endregion "Return" }
//Filter by role and group access public List <OSC_Team> GetList(_Access paramAccess) { List <OSC_Team> result = new List <OSC_Team>(); if (paramAccess.LogonUser == "" || paramAccess.LogonUser == null || paramAccess.Role == "" || paramAccess.Role == null) { return(result); } try { switch (paramAccess.Role) { case "Admin": result = this.idb; break; case "Staff": OSC_Representative rep = this.db.Representatives.Where(t => t.PRDUserId == paramAccess.LogonUser && t.IsActive && t.IsCurrent).FirstOrDefault(); if (rep != null) { result = this.GetList().Where(t => t.TeamId == rep.TeamId && t.IsActive).ToList(); } break; case "Manager": case "Department Analyst": case "Team Leader": List <long> list = this.access.GetList(paramAccess.LogonUser, paramAccess.Role, "TEAM"); result = this.GetList().Where(t => list.Contains((long)t.TeamId) && t.IsActive).ToList(); break; } } catch (Exception ex) { _err.MessageType = "Server Error"; _err.MessageDescription = ex.Message.ToString(); return(result); } return(result.OrderBy(t => t.TeamName).ToList()); }
public FileResult GetPDF() { #region "GetSessionVariables" string logon_user = (string)Session["logon_user"]; long teamId, repId; int month, year; teamId = (long)Session["IS_Team"]; repId = (long)Session["IS_Rep"]; month = (int)Session["IS_Month"]; year = (int)Session["IS_Year"]; OSC_Team oSC_Team = db.Teams.Find(teamId); OSC_Representative oSC_Representative = db.Representatives.Find(repId); #endregion "GetSessionVariables" #region "WorkbookUsingClosedXML" string templateFileName = Server.MapPath("~/Templates/Template.xlsx"); XLWorkbook workbook = new XLWorkbook(templateFileName); string exportPath = Server.MapPath("~/Export"); string excelFileName = "IndividualScorecard_" + oSC_Representative.LastName + oSC_Representative.FirstName + "_" + month.ToString() + year.ToString() + "_" + logon_user + ".xlsx"; string pdfFileName = "IndividualScorecard_" + oSC_Representative.LastName + oSC_Representative.FirstName + "_" + month.ToString() + year.ToString() + "_" + logon_user + ".pdf"; string tempFileName = exportPath + "/" + excelFileName; string outputFileName = exportPath + "/" + pdfFileName; if (System.IO.File.Exists(tempFileName)) { System.IO.File.Delete(tempFileName); } workbook.SaveAs(tempFileName); IXLWorksheet worksheet = workbook.Worksheet("Scorecard"); IXLWorksheet worksheet2 = workbook.Worksheet("Workitems"); IXLWorksheet worksheet3 = workbook.Worksheet("NPT"); #region "Table" List <IndividualScorecard> list = new List <IndividualScorecard>(); list = af.GetIndividualScorecardFull(teamId, repId, month, year); int x = 2; int y = 29; IXLCell cell = worksheet.Cell(y, x); cell.SetValue("Attendance"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("Overtime"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("NPT Hours"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("Processing Time"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("Total Transactions"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("Rate of Production"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("Processing Quality"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("Total Utilization"); x += 1; cell = worksheet.Cell(29, x); cell.SetValue("Efficiency"); for (int i = 1; i <= list.Count; i++) { y += 1; x = 2; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].individualActivities.Attendance_Days.ToString()); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].individualActivities.Overtime_Hours.ToString()); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].individualNonProcessing.NPTHours.ToString()); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].individualBIProd.ProcessingHours.ToString()); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].individualBIProd.Count.ToString()); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].ProductivityRating.ToString() + "%"); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].individualBIQual.QualityRating.ToString() + "%"); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].TotalUtilization.ToString() + "%"); x += 1; cell = worksheet.Cell(y, x); cell.SetValue(list[i - 1].Efficiency.ToString() + "%"); } do { x += 1; worksheet.Column(x).Clear(); }while (x <= 23); #endregion "Table" #region "Highlights" IndividualScorecard ind = af.GetIndividualScorecard(teamId, repId, month, year); cell = worksheet.Cell("A47"); cell.SetValue(ind.Highlights); #endregion "Highlights" #region "Worktypes" List <IndividualWorkTypes> worktypes = af.GetIndividualWorkTypes(teamId, repId, month, year); y = 1; x = 1; IXLCell cell2 = worksheet2.Cell(y, x); for (int i = 1; i <= worktypes.Count; i++) { y += 1; x = 1; cell2 = worksheet2.Cell(y, x); cell2.SetValue(worktypes[i - 1].WorkType.ToString()); x += 1; cell2 = worksheet2.Cell(y, x); cell2.SetValue(((int)worktypes[i - 1].Count)); } do { y += 1; worksheet2.Row(y).Clear(); }while(y <= 200); #endregion "Worktypes" #region "NPT" List <PieList> npts = af.GetIndividualNPT(teamId, repId, month, year); y = 1; x = 1; IXLCell cell3 = worksheet3.Cell(y, x); for (int i = 1; i <= npts.Count; i++) { y += 1; x = 1; cell3 = worksheet3.Cell(y, x); cell3.SetValue(npts[i - 1].Category.ToString()); x += 1; cell3 = worksheet3.Cell(y, x); cell3.SetValue((double)npts[i - 1].TimeSpent); } do { y += 1; worksheet3.Row(y).Clear(); }while (y <= 200); #endregion "NPT" #region "SaveWorkBook"" workbook.SaveAs(tempFileName); #endregion "SaveWorkBook" #endregion "WorkbookUsingClosedXML" #region "UsingSpireXLS" sxl.Workbook swb = new sxl.Workbook(); swb.LoadFromFile(tempFileName); sxl.Worksheet sws1 = swb.Worksheets[0]; sxl.Worksheet sws2 = swb.Worksheets[1]; sxl.Worksheet sws3 = swb.Worksheets[2]; sws1.TextBoxes[0].Text = oSC_Team.TeamName + " Monthly Scorecard"; sws1.TextBoxes[1].Text = oSC_Representative.FirstName + " " + oSC_Representative.LastName; sws1.TextBoxes[2].Text = db.months.Where(m => m.Value == Convert.ToString((int)month)).First().Text + "-" + year.ToString(); sxl.Chart chart1 = sws1.Charts[0]; chart1.DataRange = sws2.Range[1, 1, sws2.Rows.Count(), 2]; sxl.Chart chart2 = sws1.Charts[1]; chart2.DataRange = sws3.Range[1, 1, sws3.Rows.Count(), 2]; swb.Save(); #endregion "UsingSpireXLS" #region "WorkbookUsingInterop" //remove this codes when 403 - 454 when closedXML can generate this to PDF xl.Application app = new xl.Application(); xl.Workbook wb = app.Workbooks.Open(tempFileName); #region "Cover" xl.Sheets xs = wb.Worksheets; xl.Worksheet ws = (xl.Worksheet)xs.get_Item("Scorecard"); xl.Worksheet ws2 = (xl.Worksheet)xs.get_Item("Workitems"); xl.Worksheet ws3 = (xl.Worksheet)xs.get_Item("NPT"); int txt_ctr = 1; foreach (xl.Shape shp in ws.Shapes) { if (shp.Type == Microsoft.Office.Core.MsoShapeType.msoTextBox) { if (txt_ctr == 1) { shp.TextFrame.Characters(Type.Missing, Type.Missing).Text = oSC_Team.TeamName + " Monthly Scorecard"; } else if (txt_ctr == 2) { shp.TextFrame.Characters(Type.Missing, Type.Missing).Text = oSC_Representative.FirstName + " " + oSC_Representative.LastName; shp.ZOrder(MsoZOrderCmd.msoBringToFront); } else { shp.TextFrame.Characters(Type.Missing, Type.Missing).Text = db.months.Where(m => m.Value == Convert.ToString((int)month)).First().Text + "-" + year.ToString(); shp.ZOrder(MsoZOrderCmd.msoBringToFront); } } txt_ctr += 1; } int cht_ctr = 1; foreach (xl.ChartObject cht in ws.ChartObjects()) { if (cht_ctr == 1) { xl.Range last = ws2.Cells.SpecialCells(xl.XlCellType.xlCellTypeLastCell, Type.Missing); xl.Range chartRange = ws2.get_Range("A1", last); cht.Chart.SetSourceData(chartRange); } else { xl.Range last = ws3.Cells.SpecialCells(xl.XlCellType.xlCellTypeLastCell, Type.Missing); xl.Range chartRange = ws3.get_Range("A1", last); cht.Chart.SetSourceData(chartRange); } cht_ctr += 1; } #endregion "Cover" wb.Save(); wb.ExportAsFixedFormat(xl.XlFixedFormatType.xlTypePDF, outputFileName, xl.XlFixedFormatQuality.xlQualityStandard); wb.Close(); app.Quit(); #endregion "WorkbookUsingInterop" #region "Return" byte[] fileBytes = System.IO.File.ReadAllBytes(outputFileName); string fileName = pdfFileName; return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); #endregion "Return" }
public ActionResult GetWord() { string logon_user = (string)Session["logon_user"]; long teamId, repId; int month, year; teamId = (long)Session["IS_Team"]; repId = (long)Session["IS_Rep"]; month = (int)Session["IS_Month"]; year = (int)Session["IS_Year"]; OSC_Team oSC_Team = db.Teams.Find(teamId); OSC_Representative oSC_Representative = db.Representatives.Find(repId); word.Application app = new word.Application(); string templateFileName = Server.MapPath("~/Templates/ScorecardTemplate.docx"); word.Document doc = app.Documents.Open(templateFileName); string exportPath = Server.MapPath("~/Export"); string fileName = exportPath + "/IndividualScorecard_" + oSC_Representative.LastName + oSC_Representative.FirstName + "_" + month.ToString() + year.ToString() + "_" + logon_user + ".docx"; if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } doc.SaveAs(fileName); doc.Activate(); #region "CoverValues" if (doc.Bookmarks.Exists("TeamName")) { doc.Bookmarks["TeamName"].Range.Text = oSC_Team.TeamName; } if (doc.Bookmarks.Exists("RepName")) { doc.Bookmarks["RepName"].Range.Text = oSC_Representative.FirstName + " " + oSC_Representative.LastName; } if (doc.Bookmarks.Exists("Month")) { doc.Bookmarks["Month"].Range.Text = db.months.Where(m => m.Value == Convert.ToString((int)month)).First().Text; } if (doc.Bookmarks.Exists("Year")) { doc.Bookmarks["Year"].Range.Text = year.ToString(); } #endregion "CoverValues" #region "Table" List <IndividualScorecard> list = new List <IndividualScorecard>(); list = af.GetIndividualScorecardFull(teamId, repId, month, year); int noOfRows = list.Count(); int noOfCols = 10; word.Table table = doc.Tables[1]; for (int i = 1; i <= noOfCols - 1; i++) { table.Columns.Add(table.Columns[1]); } table.Rows[1].Cells[1].Range.Text = "Month"; table.Rows[1].Cells[2].Range.Text = "Attendance"; table.Rows[1].Cells[3].Range.Text = "Overtime"; table.Rows[1].Cells[4].Range.Text = "NPT Hours"; table.Rows[1].Cells[5].Range.Text = "Processing Time"; table.Rows[1].Cells[6].Range.Text = "Total Transactions"; table.Rows[1].Cells[7].Range.Text = "Rate of Production"; table.Rows[1].Cells[8].Range.Text = "Processing Quality"; table.Rows[1].Cells[9].Range.Text = "Total Utilization"; table.Rows[1].Cells[10].Range.Text = "Efficiency"; for (int i = 1; i <= list.Count - 1; i++) { table.Rows.Add(table.Rows[2]); } for (int i = 1; i <= list.Count; i++) { table.Rows[i + 1].Cells[1].Range.Text = list[i - 1].MonthName; table.Rows[i + 1].Cells[2].Range.Text = list[i - 1].individualActivities.Attendance_Days.ToString(); table.Rows[i + 1].Cells[3].Range.Text = list[i - 1].individualActivities.Overtime_Hours.ToString(); table.Rows[i + 1].Cells[4].Range.Text = list[i - 1].individualNonProcessing.NPTHours.ToString(); table.Rows[i + 1].Cells[5].Range.Text = list[i - 1].individualBIProd.ProcessingHours.ToString(); table.Rows[i + 1].Cells[6].Range.Text = list[i - 1].individualBIProd.Count.ToString(); table.Rows[i + 1].Cells[7].Range.Text = list[i - 1].ProductivityRating.ToString() + "%"; table.Rows[i + 1].Cells[8].Range.Text = list[i - 1].individualBIQual.QualityRating.ToString() + "%"; table.Rows[i + 1].Cells[9].Range.Text = list[i - 1].TotalUtilization.ToString() + "%"; table.Rows[i + 1].Cells[10].Range.Text = list[i - 1].Efficiency.ToString() + "%"; } #endregion "Table" #region "Highlights" IndividualScorecard ind = af.GetIndividualScorecard(teamId, repId, month, year); if (doc.Bookmarks.Exists("Highlights")) { doc.Bookmarks["Highlights"].Range.Text = ind.Highlights; } #endregion "Highlights" #region "ProdChart" #endregion "ProdChart" #region "NPTChart" #endregion "NPTChart" string pdfFileName = exportPath + "/IndividualScorecard_" + oSC_Representative.LastName + oSC_Representative.FirstName + "_" + month.ToString() + year.ToString() + "_" + logon_user + ".pdf"; doc.SaveAs2(pdfFileName, word.WdSaveFormat.wdFormatPDF); doc.Close(); app.Quit(); var mimeType = "application/pdf"; var pdf = System.IO.File.ReadAllBytes(pdfFileName); FileResult fileResult = new FileContentResult(pdf, mimeType); fileResult.FileDownloadName = "IndividualScorecard_" + oSC_Representative.LastName + oSC_Representative.FirstName + "_" + month.ToString() + year.ToString() + "_" + logon_user + ".pdf"; System.IO.File.Delete(fileName); return(fileResult); }
// GET: Representative public ActionResult Index(int?page, int?pageSize, string searchByRep, string searchByTeam, string searchByRole, string searchByLocation) { #region "InitializeRepresentatives" af.InitializeRepresentatives(db); #endregion "InitializeRepresentatives" #region "BTSS" string role; string user_name; try { role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); string grp_id = Session["grp_id"].ToString(); ViewBag.CanView = af.CanView(grp_id, "Representative"); ViewBag.CanAdd = af.CanAdd(grp_id, "Representative"); ViewBag.CanEdit = af.CanEdit(grp_id, "Representative"); ViewBag.CanDelete = af.CanDelete(grp_id, "Representative"); if (!ViewBag.CanView) { return(HttpNotFound()); } } catch (Exception exception) { //session expired string result = exception.Message.ToString(); return(HttpNotFound()); } var reps = (from r in db.Representatives select r); List <long> TeamIds = new List <long>(); switch (role) { case "Manager": case "Team Leader": case "Department Analyst": foreach (OSC_Representative obj in reps) { if (af.IsManaged(obj.TeamId, user_name, role)) { if (!TeamIds.Contains((long)obj.TeamId)) { TeamIds.Add((long)obj.TeamId); } } } reps = (from r in db.Representatives where TeamIds.Contains((long)r.TeamId) && r.IsActive == true select r); break; case "Staff": OSC_Representative oSC_Representative = af.GetRepresentativeByPRD(user_name); long repId; repId = 0; if (oSC_Representative != null) { repId = oSC_Representative.RepId; } reps = reps.Where(r => r.RepId == repId && r.IsActive); break; } #endregion "BTSS" #region "Table" int?defaultPageSize = 10; if (pageSize != null) { defaultPageSize = pageSize; } if (searchByRep != null || searchByTeam != null || searchByRole != null || searchByLocation != null) { //Session["RepFilter"] = true; List <long> TeamIdResult = new List <long>(); TeamIdResult = null; if (!String.IsNullOrEmpty(searchByTeam)) { TeamIdResult = (from list in db.Teams where list.TeamName == searchByTeam select list.TeamId).ToList(); if (role != "Admin") { TeamIdResult = (from list in db.Teams where list.TeamName == searchByTeam && list.IsActive select list.TeamId).ToList(); } } List <int> RoleIdResult = new List <int>(); RoleIdResult = null; if (!String.IsNullOrEmpty(searchByRole)) { RoleIdResult = (from list in db.CoreRoles where list.CoreRole == searchByRole select list.CoreRoleId).ToList(); } List <int> LocationIdResult = new List <int>(); LocationIdResult = null; if (!String.IsNullOrEmpty(searchByLocation)) { LocationIdResult = (from list in db.Locations where list.Location == searchByLocation select list.LocationId).ToList(); } if (searchByRep != "") { reps = reps.Where(t => t.FirstName + " " + t.LastName == searchByRep); } if (searchByTeam != "") { reps = reps.Where(t => TeamIdResult.Contains((long)t.TeamId)); } if (searchByRole != "") { reps = reps.Where(t => RoleIdResult.Contains((int)t.CoreRoleId)); } if (searchByLocation != "") { reps = reps.Where(t => LocationIdResult.Contains((int)t.LocationId)); } if (role != "Admin") { reps = reps.Where(t => t.IsActive); } } #endregion "Table" #region "ViewBagFilters" if (searchByRep != null) { //Session["RepFilter_Rep"] = searchByRep; ViewBag.Representative = searchByRep; } else { //Session["RepFilter_Rep"] = ""; ViewBag.Representative = ""; } if (searchByTeam != null) { //Session["RepFilter_Team"] = searchByTeam; ViewBag.Team = searchByTeam; } else { //Session["RepFilter_Team"] = ""; ViewBag.Team = ""; } if (searchByRole != null) { //Session["RepFilter_Role"] = searchByRole; ViewBag.CoreRole = searchByRole; } else { //Session["RepFilter_Role"] = ""; ViewBag.CoreRole = ""; } if (searchByLocation != null) { //Session["RepFilter_Location"] = searchByLocation; ViewBag.Location = searchByLocation; } else { //Session["RepFilter_Location"] = ""; ViewBag.Location = ""; } #endregion "ViewBagFilters" #region "Return" return(View(reps.OrderBy(r => r.TeamId).ThenBy(r => r.FirstName).ToPagedList(page ?? 1, (int)defaultPageSize))); #endregion "Return" }
// GET: ActivityTracker public ActionResult Index(int?page, int?pageSize, string searchByActivity, string searchByTeam, string searchByRep, string searchByDateFrom, string searchByDateTo) { #region "Initialize" af.InitializeActivities(db); #endregion "Initialize" #region "BTSS" string role; string user_name; try { role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); string grp_id = Session["grp_id"].ToString(); ViewBag.CanView = af.CanView(grp_id, "Activity Tracker"); ViewBag.CanAdd = af.CanAdd(grp_id, "Activity Tracker"); ViewBag.CanEdit = af.CanEdit(grp_id, "Activity Tracker"); ViewBag.CanDelete = af.CanDelete(grp_id, "Activity Tracker"); if (!ViewBag.CanView) { return(HttpNotFound()); } } catch (Exception exception) { //session expired string result = exception.Message.ToString(); return(HttpNotFound()); } var acts = (from a in db.ActivityTrackers where a.Activity != "Attendance" select a); List <long> TeamIds = new List <long>(); switch (role) { case "Manager": case "Team Leader": case "Department Analyst": foreach (OSC_ActivityTracker obj in acts) { if (af.IsManaged(obj.TeamId, user_name, role)) { if (!TeamIds.Contains(obj.TeamId)) { TeamIds.Add(obj.TeamId); } } } acts = (from a in db.ActivityTrackers where a.Activity != "Attendance" && TeamIds.Contains(a.TeamId) && a.IsActive select a); break; case "Staff": OSC_Representative oSC_Representative = af.GetRepresentativeByPRD(user_name); long repId; repId = 0; if (oSC_Representative != null) { repId = oSC_Representative.RepId; } acts = acts.Where(a => a.RepId == repId && a.IsActive); break; } #endregion "BTSS" #region "Table" int?defaultPageSize = 10; if (pageSize != null) { defaultPageSize = pageSize; } if (searchByActivity != null || searchByTeam != null || searchByRep != null || searchByDateFrom != null || searchByDateTo != null) { Session["ActivityFilter"] = true; List <long> TeamIdResult = new List <long>(); TeamIdResult = null; if (!String.IsNullOrEmpty(searchByTeam)) { TeamIdResult = (from list in db.Teams where list.TeamName == searchByTeam select list.TeamId).ToList(); if (role != "Admin") { TeamIdResult = (from list in db.Teams where list.TeamName == searchByTeam && list.IsActive select list.TeamId).ToList(); } } List <long> RepIdResult = new List <long>(); if (!String.IsNullOrEmpty(searchByRep)) { RepIdResult = (from list in db.Representatives where list.FirstName + " " + list.LastName == searchByRep select list.RepId).ToList(); if (role != "Admin") { RepIdResult = (from list in db.Representatives where (list.FirstName + " " + list.LastName == searchByRep) && list.IsActive select list.RepId).ToList(); } } if (searchByActivity != "") { acts = acts.Where(t => t.Activity == searchByActivity); } if (searchByTeam != "") { acts = acts.Where(t => TeamIdResult.Contains((long)t.TeamId)); } if (searchByRep != "") { acts = acts.Where(t => RepIdResult.Contains((long)t.RepId)); } if (searchByDateFrom != "") { var dt = Convert.ToDateTime(searchByDateFrom); acts = acts.Where(t => dt == t.DateFrom); } if (searchByDateTo != "") { var dt = Convert.ToDateTime(searchByDateTo); acts = acts.Where(t => dt == t.DateTo); } if (role != "Admin") { acts = acts.Where(t => t.IsActive); } } #endregion "Table" #region "ViewBagFilters" if (searchByActivity != null) { Session["ActivityFilter_Activity"] = searchByActivity; ViewBag.Activity = searchByActivity; } else { Session["ActivityFilter_Activity"] = ""; ViewBag.Activity = ""; } if (searchByTeam != null) { Session["ActivityFilter_Team"] = searchByTeam; ViewBag.Team = searchByTeam; } else { Session["ActivityFilter_Team"] = ""; ViewBag.Team = ""; } if (searchByRep != null) { Session["ActivityFilter_Rep"] = searchByRep; ViewBag.Representative = searchByRep; } else { Session["ActivityFilter_Rep"] = ""; ViewBag.Representative = ""; } if (searchByDateFrom != null) { Session["ActivityFilter_DateFrom"] = searchByDateFrom; ViewBag.DateFrom = searchByDateFrom; } else { Session["ActivityFilter_DateFrom"] = ""; ViewBag.DateFrom = ""; } if (searchByDateTo != null) { Session["ActivityFilter_DateTo"] = searchByDateTo; ViewBag.DateTo = searchByDateTo; } else { Session["ActivityFilter_DateTo"] = ""; ViewBag.DateTo = ""; } #endregion "ViewBagFilters" #region "Return" return(View(acts.OrderByDescending(a => a.Year).ThenByDescending(a => a.Month).ThenByDescending(a => a.TeamId).ToPagedList(page ?? 1, (int)defaultPageSize))); #endregion "Return" }
public FileResult Export() { #region "Initialize" af.InitializeActivities(db); #endregion "Initialize" #region "BTSS" string role; string user_name; role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); #endregion "BTSS" #region "TransferData" DataTable dt = new DataTable("Activities"); dt.Columns.AddRange(new DataColumn[9] { new DataColumn("Team"), new DataColumn("Representative"), new DataColumn("Activity"), new DataColumn("Date From"), new DataColumn("Date To"), new DataColumn("No of Hours"), new DataColumn("No of Days"), new DataColumn("Modified By"), new DataColumn("Date Modified") }); var acts = (from a in db.ActivityTrackers where a.Activity != "Attendance" select a); List <long> TeamIds = new List <long>(); switch (role) { case "Manager": case "Team Leader": case "Department Analyst": foreach (OSC_ActivityTracker obj in acts) { if (af.IsManaged(obj.TeamId, user_name, role)) { if (!TeamIds.Contains(obj.TeamId)) { TeamIds.Add(obj.TeamId); } } } acts = (from a in db.ActivityTrackers where a.Activity != "Attendance" && TeamIds.Contains(a.TeamId) && a.IsActive select a); break; case "Staff": OSC_Representative oSC_Representative = af.GetRepresentativeByPRD(user_name); long repId; repId = 0; if (oSC_Representative != null) { repId = oSC_Representative.RepId; } acts = acts.Where(a => a.RepId == repId && a.IsActive); break; } string searchByActivity = "", searchByTeam = "", searchByRep = "", searchByDateFrom = "", searchByDateTo = ""; if ((bool)Session["ActivityFilter"]) { searchByActivity = (string)Session["ActivityFilter_Activity"]; searchByTeam = (string)Session["ActivityFilter_Team"]; searchByRep = (string)Session["ActivityFilter_Rep"]; searchByDateFrom = (string)Session["ActivityFilter_DateFrom"]; searchByDateTo = (string)Session["ActivityFilter_DateTo"]; } List <long> TeamIdResult = new List <long>(); TeamIdResult = null; if (!String.IsNullOrEmpty(searchByTeam)) { TeamIdResult = (from list in db.Teams where list.TeamName == searchByTeam select list.TeamId).ToList(); if (role != "Admin") { TeamIdResult = (from list in db.Teams where list.TeamName == searchByTeam && list.IsActive select list.TeamId).ToList(); } } List <long> RepIdResult = new List <long>(); if (!String.IsNullOrEmpty(searchByRep)) { RepIdResult = (from list in db.Representatives where list.FirstName + " " + list.LastName == searchByRep select list.RepId).ToList(); if (role != "Admin") { RepIdResult = (from list in db.Representatives where (list.FirstName + " " + list.LastName == searchByRep) && list.IsActive select list.RepId).ToList(); } } if (searchByActivity != "") { acts = acts.Where(t => t.Activity == searchByActivity); } if (searchByTeam != "") { acts = acts.Where(t => TeamIdResult.Contains((long)t.TeamId)); } if (searchByRep != "") { acts = acts.Where(t => RepIdResult.Contains((long)t.RepId)); } if (searchByDateFrom != "") { var df = Convert.ToDateTime(searchByDateFrom); acts = acts.Where(t => df == t.DateFrom); } if (searchByDateTo != "") { var df = Convert.ToDateTime(searchByDateTo); acts = acts.Where(t => df == t.DateTo); } if (role != "Admin") { acts = acts.Where(t => t.IsActive); } foreach (var act in acts) { dt.Rows.Add(act.Team.TeamName, act.Representative.FullName, act.Activity, act.DateFrom, act.DateTo, act.NoOfHours, act.NoOfDays, act.ModifiedBy, act.DateModified); } #endregion "TransferData" #region "GenerateSpreadsheet" using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt); using (MemoryStream stream = new MemoryStream()) { wb.SaveAs(stream); return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ActivityList_" + DateTime.Now.ToShortDateString() + ".xlsx")); } } #endregion "GenerateSpreadsheet" }
// GET: ManualEntry public ActionResult Index(int?page, int?pageSize, string searchString) { #region "Initialize" af.InitializeManualEntries(db); #endregion "Initialize" #region "BTSS" string role; string user_name; try { role = Session["role"].ToString(); user_name = Session["logon_user"].ToString(); string grp_id = Session["grp_id"].ToString(); ViewBag.CanView = af.CanView(grp_id, "Manual Entries"); ViewBag.CanAdd = af.CanAdd(grp_id, "Manual Entries"); ViewBag.CanEdit = af.CanEdit(grp_id, "Manual Entries"); ViewBag.CanDelete = af.CanDelete(grp_id, "Manual Entries"); if (!ViewBag.CanView) { return(HttpNotFound()); } } catch (Exception exception) { //session expired string result = exception.Message.ToString(); return(HttpNotFound()); } var mes = (from m in db.ManualEntries select m); List <long> TeamIds = new List <long>(); switch (role) { case "Manager": case "Team Leader": case "Department Analyst": foreach (OSC_ManualEntry obj in mes) { if (af.IsManaged(obj.TeamId, user_name, role)) { if (!TeamIds.Contains((long)obj.TeamId)) { TeamIds.Add((long)obj.TeamId); } } } mes = (from m in db.ManualEntries where TeamIds.Contains((long)m.TeamId) && m.IsActive == true select m); break; case "Staff": OSC_Representative oSC_Representative = af.GetRepresentativeByPRD(user_name); long repId; repId = 0; if (oSC_Representative != null) { repId = oSC_Representative.RepId; } mes = mes.Where(m => m.RepId == repId && m.IsActive); break; } #endregion "BTSS" #region "Table" int?defaultPageSize = 10; if (pageSize != null) { defaultPageSize = pageSize; } if (!String.IsNullOrEmpty(searchString)) { mes = mes.Where(m => m.MonthName.Contains(searchString) || m.Year.ToString().Contains(searchString)); } #endregion "Table" #region "Return" return(View(mes.OrderByDescending(m => m.Year).ThenByDescending(m => m.Month).ThenByDescending(m => m.TeamId).ToPagedList(page ?? 1, (int)defaultPageSize))); #endregion "Return" }