using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Configuration; public partial class BudgetSummary : System.Web.UI.Page { decimal approvedOSTotalRevenue = 0; decimal budgetTotalRevenue = 0; decimal actualTotalRevenue = 0; decimal varianceTotalRevenue = 0; decimal approvedOSTotalExpenses = 0; decimal budgetTotalExpenses = 0; decimal actualTotalExpenses = 0; decimal varianceTotalExpenses = 0; int RevenueBudgetTypeID = 1; int ExpensesBudgetTypeID = 2; int HRBudgetTypeID = 3; int BeneficiariesBudgetTypeID = 4; string eventBoardPortfolioName; int matchesFound; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //string bodyOnloadJS = "SetValOfFormCtrlWithValOfParentCtrl('projectIDHiddenParent', 'projectIDHiddenChild');"; //HtmlGenericControl body = (HtmlGenericControl)Page.FindControl("body"); //body.Attributes.Add("onload", bodyOnloadJS); // Get the ProjectID from the QueryString int projectID = Convert.ToInt32(Request.QueryString["ProjectID"]); // DEBUG //projectID = 508; // Check that Project ID belongs to this Board/Portfolio // Determine the Board/Portfolio the user belongs to string userBoardPortfolioName = ReadWriteManager.GetUserBoardPortfolio(); // Get the Board/Portfolio to which event belongs from DB dsProjectTableAdapters.mspProjectCommitteeGetByProjectIDTableAdapter project_committeeTableAdapter = new dsProjectTableAdapters.mspProjectCommitteeGetByProjectIDTableAdapter(); dsProject.mspProjectCommitteeGetByProjectIDDataTable dtProjectCommittee = new dsProject.mspProjectCommitteeGetByProjectIDDataTable(); dtProjectCommittee = project_committeeTableAdapter.GetByProjectID(projectID); DataTableReader dtReader = new DataTableReader(dtProjectCommittee); // Loop through datatable to get the primary Board/Portfolio name while (dtReader.Read()) { // If IsPrimaryOrganizerYN = 1, grab the value if (dtReader["IsPrimaryOrganizerYN"].ToString() == 1.ToString()) { boardPortfolioValueLabel.Text = eventBoardPortfolioName = dtReader["BoardPortfolioName"].ToString(); // Concatenate the committee name if available if (dtReader["CommitteeName"].ToString().Length > 0) { boardPortfolioValueLabel.Text = boardPortfolioValueLabel.Text.ToString() + " (" + dtReader["CommitteeName"].ToString() + ")"; } } } // Determine if user's portfolio matches event organizer portfolio switch (userBoardPortfolioName) { case "AdminPlanning": case "AdminFinance": case "ReadOnlyFull": matchesFound = 1; break; default: matchesFound = Utilities.CharCount(userBoardPortfolioName, eventBoardPortfolioName); break; } // If the Board/Portfolio name do not match, redirect to error page if (matchesFound == 0) { Server.Transfer("accessdenied.html", false); } // If we got here then we're doing good // Get project details for this project from DB dsProjectTableAdapters.tblProjectTableAdapter projectTableAdapter = new dsProjectTableAdapters.tblProjectTableAdapter(); dsProject.tblProjectDataTable dtProject = new dsProject.tblProjectDataTable(); dsProject.tblProjectRow projectRow; dtProject = projectTableAdapter.GetByID(projectID); // We have a single row of data projectRow = (dsProject.tblProjectRow)dtProject.Rows[0]; // Project Details coeRefNumValueLabel.Text = projectRow.COENumber; if (!projectRow.IsGLCodeNull()) { glCodeValueLabel.Text = projectRow.GLCode.ToString(); } else { glCodeValueLabel.Text = "None"; } proposalStatusValueLabel.Text = projectRow.PPStatus; projectTitleValueLabel.Text = projectRow.ProjectTitle; //Get date/venue/eval details from DB for this project setDateVenueEvalControls(projectID, null); //Revenue this.RevenueSqlDataSource.SelectParameters.Add("ProjectId", "1"); this.RevenueSqlDataSource.SelectParameters["ProjectId"].DefaultValue = projectID.ToString(); this.RevenueSqlDataSource.SelectParameters.Add("BudgetTypeID", "1"); this.RevenueSqlDataSource.SelectParameters["BudgetTypeID"].DefaultValue = RevenueBudgetTypeID.ToString(); //RevenueGridView.GridLines = GridLines.Horizontal; //RevenueGridView.GridLines = GridLines.Vertical; //Expenses this.ExpensesSqlDataSource.SelectParameters.Add("ProjectId", "1"); this.ExpensesSqlDataSource.SelectParameters["ProjectId"].DefaultValue = projectID.ToString(); this.ExpensesSqlDataSource.SelectParameters.Add("BudgetTypeID", "1"); this.ExpensesSqlDataSource.SelectParameters["BudgetTypeID"].DefaultValue = ExpensesBudgetTypeID.ToString(); //ExpensesGridView.GridLines = GridLines.Horizontal; //ExpensesGridView.GridLines = GridLines.Vertical; //HR this.HRSqlDataSource.SelectParameters.Add("ProjectId", "1"); this.HRSqlDataSource.SelectParameters["ProjectId"].DefaultValue = projectID.ToString(); this.HRSqlDataSource.SelectParameters.Add("BudgetTypeID", "1"); this.HRSqlDataSource.SelectParameters["BudgetTypeID"].DefaultValue = HRBudgetTypeID.ToString(); //HRGridView.GridLines = GridLines.Horizontal; //HRGridView.GridLines = GridLines.Vertical; //Beneficiaries this.BeneficiariesSqlDataSource.SelectParameters.Add("ProjectId", "1"); this.BeneficiariesSqlDataSource.SelectParameters["ProjectId"].DefaultValue = projectID.ToString(); this.BeneficiariesSqlDataSource.SelectParameters.Add("BudgetTypeID", "1"); this.BeneficiariesSqlDataSource.SelectParameters["BudgetTypeID"].DefaultValue = BeneficiariesBudgetTypeID.ToString(); //BeneficiariesGridView.GridLines = GridLines.Horizontal; //BeneficiariesGridView.GridLines = GridLines.Vertical; } // This approach allows you to dynamically assign connection string and sp to the SqlDataSource // UI also contains binding in a form this.RevenueSqlDataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPPDB"].ToString(); this.RevenueSqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; this.RevenueSqlDataSource.SelectCommand = "mspBudgetGetByProjectID"; this.ExpensesSqlDataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPPDB"].ToString(); this.ExpensesSqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; this.ExpensesSqlDataSource.SelectCommand = "mspBudgetGetByProjectID"; this.HRSqlDataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPPDB"].ToString(); this.HRSqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; this.HRSqlDataSource.SelectCommand = "mspBudgetGetByProjectID"; this.BeneficiariesSqlDataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["cnPPDB"].ToString(); this.BeneficiariesSqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; this.BeneficiariesSqlDataSource.SelectCommand = "mspBudgetGetByProjectID"; } // Rather than overloading, chose to use int? so method accepts null for ProjectDateID protected void setDateVenueEvalControls(int projectID, int? ProjectDateID) { //Get date/venue details from DB for this project dsProjectTableAdapters.mspProjectDateGetByIDTableAdapter dateVenueAdapter = new dsProjectTableAdapters.mspProjectDateGetByIDTableAdapter(); dsProject.mspProjectDateGetByIDDataTable dtDateVenue = new dsProject.mspProjectDateGetByIDDataTable(); dsProject.mspProjectDateGetByIDRow dateVenueRow; dtDateVenue = dateVenueAdapter.GetByID(projectID, ProjectDateID); if (dtDateVenue.Rows.Count > 0) { dateVenueRow = (dsProject.mspProjectDateGetByIDRow)dtDateVenue.Rows[0]; eventDateValueLabel.Visible = true; eventDateValueLabel.Text = dateVenueRow.ProposedProjectDate.ToString() + ", " + dateVenueRow.formattedStartTime.ToString() + " - " + dateVenueRow.formattedEndTime.ToString() + " at " + dateVenueRow.AbsoluteVenueName.ToString(); if (dateVenueRow.IsJKIDNull()) { if (!dateVenueRow.IsCityNameNull()) { eventDateValueLabel.Text = eventDateValueLabel.Text.ToString() + ", " + dateVenueRow.CityName.ToString(); } } if (!dateVenueRow.IsProvinceAbbrevNull()) { eventDateValueLabel.Text = eventDateValueLabel.Text.ToString() + ", " + dateVenueRow.ProvinceAbbrev.ToString(); } } } protected void RevenueGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { try { if (DataBinder.Eval(e.Row.DataItem, "ApprovedBudget").ToString().Length > 0) approvedOSTotalRevenue += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ApprovedBudget")); if(DataBinder.Eval(e.Row.DataItem, "Expected").ToString().Length>0) budgetTotalRevenue += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Expected")); if(DataBinder.Eval(e.Row.DataItem, "Actual").ToString().Length > 0) actualTotalRevenue += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Actual")); if(DataBinder.Eval(e.Row.DataItem, "Variance").ToString().Length > 0) varianceTotalRevenue += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Variance")); } catch(Exception ex) { throw (ex); } } //Determines the type of row it's a footer we will add running totals else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = "Totals:"; // for the Footer, display the running totals e.Row.Cells[5].Text = approvedOSTotalRevenue.ToString("c"); e.Row.Cells[6].Text = budgetTotalRevenue.ToString("c"); e.Row.Cells[7].Text = actualTotalRevenue.ToString("c"); e.Row.Cells[8].Text = varianceTotalRevenue.ToString("c"); e.Row.Cells[5].HorizontalAlign = e.Row.Cells[6].HorizontalAlign = e.Row.Cells[7].HorizontalAlign = e.Row.Cells[8].HorizontalAlign = HorizontalAlign.Right; e.Row.Font.Bold = true; } } //Expenses protected void ExpensesGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { try { if (DataBinder.Eval(e.Row.DataItem, "ApprovedBudget").ToString().Length > 0) approvedOSTotalExpenses += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "ApprovedBudget")); if (DataBinder.Eval(e.Row.DataItem, "Expected").ToString().Length > 0) budgetTotalExpenses += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Expected")); if (DataBinder.Eval(e.Row.DataItem, "Actual").ToString().Length > 0) actualTotalExpenses += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Actual")); if (DataBinder.Eval(e.Row.DataItem, "Variance").ToString().Length > 0) varianceTotalExpenses += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Variance")); } catch (Exception ex) { throw (ex); } } //Determines the type of row it's a footer we will add running totals else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = "Totals:"; // for the Footer, display the running totals e.Row.Cells[5].Text = approvedOSTotalExpenses.ToString("c"); e.Row.Cells[6].Text = budgetTotalExpenses.ToString("c"); e.Row.Cells[7].Text = actualTotalExpenses.ToString("c"); e.Row.Cells[8].Text = varianceTotalExpenses.ToString("c"); e.Row.Cells[5].HorizontalAlign = e.Row.Cells[6].HorizontalAlign = e.Row.Cells[7].HorizontalAlign = e.Row.Cells[8].HorizontalAlign = HorizontalAlign.Right; e.Row.Font.Bold = true; } } protected void NetIncomeLossGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //do not display the row. Using the data source of revenue to force gridview to render //but we are just interested in the footer to show revenue minus expenses e.Row.Visible = false; } else if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[3].Text = " "; // for the Footer, display revenue - expenses e.Row.Cells[5].Text = (approvedOSTotalRevenue-approvedOSTotalExpenses).ToString("c"); e.Row.Cells[6].Text = (budgetTotalRevenue-budgetTotalExpenses).ToString("c"); e.Row.Cells[7].Text = (actualTotalRevenue-actualTotalExpenses).ToString("c"); e.Row.Cells[8].Text = (varianceTotalRevenue-varianceTotalExpenses).ToString("c"); e.Row.Cells[5].HorizontalAlign = e.Row.Cells[6].HorizontalAlign = e.Row.Cells[7].HorizontalAlign = e.Row.Cells[8].HorizontalAlign = HorizontalAlign.Right; e.Row.Font.Bold = true; } } }