protected void RefreshData() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); DateTime thisMonth = Convert.ToDateTime(dropdownMonth.SelectedValue); var thisMonthKPIs = from kpi in entities.FinancialKPIsMonths where kpi.KPIMonth == thisMonth select kpi; var budgetData = from person in entities.People join kpi in thisMonthKPIs on person.PersonCode equals kpi.PersonCode into gj from subkpi in gj.DefaultIfEmpty() orderby person.Name select new { person.PersonCode, person.Name, subkpi.InvoiceDollarsBudget, subkpi.TimesheetDollarsBudget, subkpi.WriteOffDollarsBudget, subkpi.WIPDollarsBudget }; rptBudget.DataSource = budgetData; rptBudget.DataBind(); }
protected void newGoal(object sender, EventArgs e) { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); TextBox newGoal = (TextBox)rptTrainingGoals.Controls[rptTrainingGoals.Controls.Count - 1].Controls[0].FindControl("newGoal"); TextBox newGoalURL = (TextBox)rptTrainingGoals.Controls[rptTrainingGoals.Controls.Count - 1].Controls[0].FindControl("newGoalURL"); // User has entered a new goal // Create the promise with relevant attributes FRT.DAL.TrainingGoal goal = new FRT.DAL.TrainingGoal(); goal.PersonCode = dropdownPerson.SelectedValue; goal.Date = DateTime.Today; goal.Goal = newGoal.Text; goal.URL = newGoalURL.Text; // Add to DB and commit entities.AddToTrainingGoals(goal); entities.SaveChanges(); // Refresh data RefreshTrainingGoals(); // Set focus to the new caption ScriptManager.GetCurrent(Page).SetFocus(rptTrainingGoals.Controls[rptTrainingGoals.Controls.Count - 1].Controls[0].FindControl("newGoal")); }
protected void Page_Load(object sender, EventArgs e) { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); // is this the first page load? if (!IsPostBack) { // Grab the weeks from the database and populate the dropdown box var months = from m in entities.Months select m; dropdownMonthWIP.DataSource = months; dropdownMonthWIP.DataTextField = "MonthCommencing"; dropdownMonthWIP.DataValueField = "MonthCommencing"; dropdownMonthWIP.DataTextFormatString = "{0:ddd dd/MM/yy}"; // Look up the date of last Monday DateTime dateFirstofMonth = (DateTime.Today.AddDays(-((int)DateTime.Today.Day - 1))); var month = from m in months where m.MonthCommencing == dateFirstofMonth select m; var descendingMonths = from m in months orderby m.MonthCommencing descending select m; // If it doesn't exist, just select the last week we can. Otherwise grab last Monday. if (month.Count() == 0) { dropdownMonthWIP.SelectedValue = descendingMonths.First().MonthCommencing.ToString(); } else { dropdownMonthWIP.SelectedValue = month.First().MonthCommencing.ToString(); } dropdownMonthWIP.DataBind(); // add options to stat selection drop-down Dictionary <string, string> graphStats = new Dictionary <string, string>(); graphStats.Add("budgetpc", "WIP as percentage of budget"); graphStats.Add("dollars", "WIP in dollars"); graphStat.DataSource = graphStats; graphStat.DataTextField = "Value"; graphStat.DataValueField = "Key"; graphStat.DataBind(); RefreshWIP(); } // Not the first page load, nothing to do. Other events are handled by their // relevant events }
protected void RefreshLeave() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); var leave = from l in entities.Leaves where l.PersonCode == dropdownPerson.SelectedValue select l; Leave.DataSource = leave; Leave.DataBind(); }
protected void RefreshXPMJobs() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); var jobs = from j in entities.XPMJobs where j.PersonCode == dropdownPerson.SelectedValue select j; XPMJobs.DataSource = jobs; XPMJobs.DataBind(); }
protected void SaveGoals_Click(object sender, EventArgs e) { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); // Go through each of the items in the repeater and update foreach (RepeaterItem item in rptTrainingGoals.Items) { HiddenField lblGoalID = (HiddenField)item.FindControl("lblGoalID"); TextBox txtGoal = (TextBox)item.FindControl("txtGoal"); TextBox txtGoalURL = (TextBox)item.FindControl("txtGoalURL"); int goalID = Convert.ToInt32(lblGoalID.Value); // See if the goal exists in the database var goals = from g in entities.TrainingGoals where g.GoalID == goalID select g; if (goals.Count() != 0) { // It does exist FRT.DAL.TrainingGoal goal = goals.First(); // If the textbox is empty, delete the row if (txtGoal.Text.Equals("")) { entities.DeleteObject(goal); } else { // Otherwise update the goal goal.Goal = txtGoal.Text; goal.URL = txtGoalURL.Text; } } else { // it doesn't exist. wtf?? } } // Save changes and refresh data entities.SaveChanges(); RefreshTrainingGoals(); pnlTrainingGoals.Visible = false; }
protected void RefreshTrainingGoals() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); var trainingGoals = from t in entities.TrainingGoals where t.PersonCode == dropdownPerson.SelectedValue select new { t.PersonCode, t.GoalID, t.Goal, t.URL, DisplayLink = t.URL == null ? false : true, HideLink = t.URL == null ? true: false }; rptTrainingGoals.DataSource = trainingGoals; rptTrainingGoals.DataBind(); lvTrainingGoals.DataSource = trainingGoals; lvTrainingGoals.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); if (!IsPostBack) { // First load - refresh var months = from m in entities.Months orderby m.MonthCommencing select m; dropdownMonth.DataSource = months; dropdownMonth.DataTextField = "MonthCommencing"; dropdownMonth.DataValueField = "MonthCommencing"; dropdownMonth.DataTextFormatString = "{0:MMMM yyyy}"; dropdownMonth.DataBind(); RefreshData(); } }
protected void RefreshWIP() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); DateTime selectedMonth = Convert.ToDateTime(dropdownMonthWIP.SelectedValue); // Subtract the day of the month to get the first DateTime thisMonth = selectedMonth; // selectedMonth.AddDays((-selectedWeek.Day) + 1); bool showHidden = showHiddenStaff.Checked; // include both non-hidden and optionally hidden staff var KPIMs = from k in entities.FinancialKPIsMonths where k.KPIMonth == thisMonth && (k.Person.Hidden == false || k.Person.Hidden == showHidden) select new { k.Person.Name, k.WIPDollars, k.WIPDollarsBudget, WIPPercent = k.WIPDollarsBudget == 0 ? 0 : k.WIPDollars / k.WIPDollarsBudget }; var orderedKPIMs = from k in KPIMs orderby k.Name select k; fvWIP.DataSource = orderedKPIMs; fvWIP.DataBind(); decimal maxGraphValue; decimal scaledPercentage, myGraphValue; string graphValueFormat; if (graphStat.SelectedItem.Value == "dollars") { maxGraphValue = Convert.ToDecimal(orderedKPIMs.Max(s => s.WIPDollars)); graphValueFormat = "C0"; } else { maxGraphValue = Convert.ToDecimal(orderedKPIMs.Max(s => s.WIPPercent)); graphValueFormat = "P0"; } if (orderedKPIMs.Count() > 1) { for (int i = 0; i <= fvWIP.Items.Count - 1; i++) { Panel myPanel = (Panel)fvWIP.Items[i].FindControl("WIPGraph"); if (graphStat.SelectedItem.Value == "dollars") { myGraphValue = Convert.ToDecimal(orderedKPIMs.Skip(i).First().WIPDollars); } else { myGraphValue = Convert.ToDecimal(orderedKPIMs.Skip(i).First().WIPPercent); } Label insideLabel = (Label)fvWIP.Items[i].FindControl("lblWIPGraph"); Label outsideLabel = (Label)fvWIP.Items[i].FindControl("lblWIPGraphOutside"); if (myGraphValue <= 0) { scaledPercentage = 0; } else { scaledPercentage = (myGraphValue / maxGraphValue) * 100; } if (scaledPercentage >= 100) { myPanel.Width = Unit.Percentage(100); } else if (scaledPercentage <= 0) { myPanel.Width = Unit.Percentage(0); } else { myPanel.Width = Unit.Percentage(Convert.ToDouble(scaledPercentage)); } if (scaledPercentage > 75) { outsideLabel.Text = " "; insideLabel.Text = myGraphValue.ToString(graphValueFormat); outsideLabel.Visible = false; } else { insideLabel.Text = " "; outsideLabel.Text = myGraphValue.ToString(graphValueFormat); outsideLabel.Visible = true; } myPanel.CssClass = "graph"; if ((Convert.ToDecimal(orderedKPIMs.Skip(i).First().WIPPercent)) > 1) { myPanel.CssClass += " red"; } } } }
protected void RefreshFinancialKPIs() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); DateTime selectedWeek = Convert.ToDateTime(dropdownWeek.SelectedValue); // Subtract the day of the month to get the first DateTime thisMonth = selectedWeek.AddDays((-selectedWeek.Day) + 1); var KPIMs = from k in entities.FinancialKPIsMonths where k.PersonCode == dropdownPerson.SelectedValue && k.KPIMonth == thisMonth select new { k.TimesheetDollars, k.TimesheetDollarsBudget, k.InvoiceDollars, k.InvoiceDollarsBudget, k.WriteOffDollars, k.WriteOffDollarsBudget, k.WIPDollars, k.WIPDollarsBudget, TimesheetPercent = k.TimesheetDollarsBudget == 0 ? 0 : k.TimesheetDollars / k.TimesheetDollarsBudget, InvoicePercent = k.InvoiceDollarsBudget == 0 ? 0 : k.InvoiceDollars / k.InvoiceDollarsBudget, WriteOffPercent = k.WriteOffDollarsBudget == 0 ? 0 : k.WriteOffDollars / k.WriteOffDollarsBudget, WIPPercent = k.WIPDollarsBudget == 0 ? 0 : k.WIPDollars / k.WIPDollarsBudget }; fvFinancialKPIsMonth.DataSource = KPIMs; fvFinancialKPIsMonth.DataBind(); Panel myPanel; decimal myPercentage; Label insideLabel, outsideLabel; if (KPIMs.Count() == 1) { string[] graphList = { "Timesheet", "Invoice", "WriteOff", "WIP" }; foreach (string item in graphList) { switch (item) { case "Timesheet": myPercentage = Convert.ToInt32(KPIMs.First().TimesheetPercent * 100); break; case "Invoice": myPercentage = Convert.ToInt32(KPIMs.First().InvoicePercent * 100); break; case "WriteOff": myPercentage = Convert.ToInt32(KPIMs.First().WriteOffPercent * 100); break; case "WIP": myPercentage = Convert.ToInt32(KPIMs.First().WIPPercent * 100); break; default: myPercentage = 0; break; } myPanel = (Panel)fvFinancialKPIsMonth.FindControl(item + "Graph"); if (myPercentage > 100) { myPanel.Width = Unit.Percentage(100); } else if (myPercentage < 0) { myPanel.Width = Unit.Percentage(0); } else { myPanel.Width = Unit.Percentage((Convert.ToDouble(myPercentage))); } insideLabel = (Label)myPanel.FindControl("lbl" + item + "Graph"); outsideLabel = (Label)fvFinancialKPIsMonth.FindControl("lbl" + item + "GraphOutside"); if (myPercentage > 65) { outsideLabel.Text = " "; insideLabel.Text = myPercentage.ToString("F0") + "%"; outsideLabel.Visible = false; } else { insideLabel.Text = " "; outsideLabel.Text = myPercentage.ToString("F0") + "%"; outsideLabel.Visible = true; } myPanel.CssClass = "graph"; if (item == "WIP" && myPercentage > 100) { myPanel.CssClass += " red"; } if (item == "WriteOff" && myPercentage > 100) { myPanel.CssClass += " red"; } if (item == "Timesheet" && myPercentage > 100) { myPanel.CssClass += " green"; } if (item == "Invoice" && myPercentage > 100) { myPanel.CssClass += " green"; } } } }
protected void Page_Load(object sender, EventArgs e) { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); // is this the first page load? if (!IsPostBack) { // Grab the weeks from the database and populate the dropdown box var weeks = from w in entities.Weeks select w; dropdownWeek.DataSource = weeks; dropdownWeek.DataTextField = "WeekCommencing"; dropdownWeek.DataValueField = "WeekCommencing"; dropdownWeek.DataTextFormatString = "{0:ddd dd/MM/yy}"; // Look up the date of last Friday DateTime dateLastFriday = DateTime.Now; // if it's friday if (dateLastFriday.DayOfWeek == DayOfWeek.Friday) { // set the drop down date as today dateLastFriday = dateLastFriday.Date; } else // if not, get the last Friday { while ((dateLastFriday.DayOfWeek != DayOfWeek.Friday)) { dateLastFriday = dateLastFriday.AddDays(-1); dateLastFriday = dateLastFriday.Date; System.Diagnostics.Trace.WriteLine(dateLastFriday); } } var week = from w in weeks where w.WeekCommencing == dateLastFriday select w; var descendingWeeks = from w in weeks orderby w.WeekCommencing descending select w; // If it doesn't exist, just select the last week we can. Otherwise grab last Monday. if (week.Count() == 0) { dropdownWeek.SelectedValue = descendingWeeks.First().WeekCommencing.ToString(); } else { dropdownWeek.SelectedValue = week.First().WeekCommencing.ToString(); } dropdownWeek.DataBind(); var people = (from p in entities.People where p.PersonCode != "FIRM" && p.Hidden == false orderby p.Name ascending select p).ToList(); // Grab the people from the database and populate the dropdown box dropdownPerson.DataSource = people; dropdownPerson.DataTextField = "Name"; dropdownPerson.DataValueField = "PersonCode"; dropdownPerson.DataBind(); dropdownPerson.Items.Insert(0, new ListItem("- Please select a name -", "")); dropdownPerson.SelectedIndex = 0; // Refresh the 'Timesheets' section SetPanelVisibility(); //RefreshTimesheetPromise(); RefreshTrainingGoals(); RefreshXPMJobs(); RefreshLeave(); } // Not the first page load, nothing to do. Other events are handled by their // relevant events }
protected void SaveChanges() { FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities(); // Go through the each repeater item for this month foreach (RepeaterItem item in rptBudget.Items) { Label lblPersonCode = ((Label)item.FindControl("lblPersonCode")); TextBox txtTimesheet = ((TextBox)item.FindControl("txtTimesheet")); TextBox txtInvoice = ((TextBox)item.FindControl("txtInvoice")); TextBox txtWOF = ((TextBox)item.FindControl("txtWOF")); TextBox txtWIP = ((TextBox)item.FindControl("txtWIP")); // Try to convert all the textboxes to decimal values // If the conversion fails, it will convert with 0 decimal dTimesheet, dInvoice, dWOF, dWIP; Decimal.TryParse(txtTimesheet.Text, out dTimesheet); Decimal.TryParse(txtInvoice.Text, out dInvoice); Decimal.TryParse(txtWOF.Text, out dWOF); Decimal.TryParse(txtWIP.Text, out dWIP); DateTime thisMonth = Convert.ToDateTime(dropdownMonth.SelectedValue); // See if the kpi exists in the database var kpis = from kpi in entities.FinancialKPIsMonths where kpi.KPIMonth == thisMonth && kpi.PersonCode.Equals(lblPersonCode.Text) select kpi; if (kpis.Count() != 0) { // It does exist FRT.DAL.FinancialKPIsMonth kpi = kpis.First(); kpi.TimesheetDollarsBudget = dTimesheet; kpi.InvoiceDollarsBudget = dInvoice; kpi.WriteOffDollarsBudget = dWOF; kpi.WIPDollarsBudget = dWIP; } else { // It doesn't exist, make a new row FRT.DAL.FinancialKPIsMonth kpi = new FRT.DAL.FinancialKPIsMonth(); kpi.PersonCode = lblPersonCode.Text; kpi.KPIMonth = thisMonth; kpi.TimesheetDollarsBudget = dTimesheet; kpi.InvoiceDollarsBudget = dInvoice; kpi.WriteOffDollarsBudget = dWOF; kpi.WIPDollarsBudget = dWIP; kpi.TimesheetDollars = 0; kpi.InvoiceDollars = 0; kpi.WriteOffDollars = 0; kpi.WIPDollars = 0; entities.AddToFinancialKPIsMonths(kpi); } } // Save changes and refresh data entities.SaveChanges(); RefreshData(); }