using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Infragistics.Web.UI.GridControls;
using Infragistics.Web.UI.ListControls;
using Infragistics.Web.UI.DataSourceControls;
using PFOM.Business;
using PFOM.Business.Utility;
using CH2MHILL.IT.Common.ExceptionManagement;
using System.Text;
using System.Data;
namespace WebSite.BudgetSetup
{
public partial class BudgetVerification : System.Web.UI.Page
{
# region "Properties"
///
/// Returns a reference to the BudgetSetupManager
///
private static BudgetSetupManager BsManager
{
get { return new BudgetSetupManager(); }
}
///
/// Returns a reference to the page's master page: BudgetSetup
///
private MasterPages.Menu MenuMaster
{
get { return (MasterPages.Menu)Master; }
}
///
/// Returns a reference to the SiteMaster.AuthUser object
///
protected User AuthUser
{
get { return MenuMaster != null ? MenuMaster.AuthUser : null; }
}
# endregion
# region "Public Methods"
public int miProjectID;
public int miBudgetID;
public string msProjectName;
public string msProjectDisplayName;
public DataSet mdsBudgetVerification;
protected void Page_Load(object sender, EventArgs e)
{
// Get Reference to Selected ProjectID from AuthUser Object
miProjectID = AuthUser.SelectedProjectID;
miBudgetID = AuthUser.SelectedBudgetID;
msProjectName = AuthUser.SelectedProjectName;
msProjectDisplayName = miProjectID.ToString() + " " + msProjectName;
//TODO: get rid of this once we have the real values set in the user object
if (msProjectDisplayName == "0 ")
msProjectDisplayName = "351283 Prescott Vale, Town Of";
if (miProjectID == 0)
miProjectID = 4;
if (miBudgetID == 0)
miBudgetID = 1;
this.lblProjectDisplayName.Text = msProjectDisplayName;
if (!IsPostBack)
{
LoadBudgetVerification();
InitializeGrid();
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.grdVerification.InitializeRow +=new InitializeRowEventHandler(grdVerification_InitializeRow);
}
void grdVerification_InitializeRow(object sender, RowEventArgs e)
{
//loop through the cells to check for certain cases - starting with the third column
for (int i = 2; i < e.Row.Items.Count; i++)
{
if (e.Row.Items[i].Column.Header.Text != "TaskNumber")
{
if (Convert.ToInt32(e.Row.Items[i].Value) < 0)
{
e.Row.Items[i].CssClass = "ighg_NegativeNumber";
e.Row.Items[i].Text = "(" + e.Row.Items[i].Value + ")";
}
}
}
}
# endregion
# region "Private Methods"
///
/// Look up & display budget verification details for the selected budget
///
private void LoadBudgetVerification()
{
try
{
mdsBudgetVerification = new DataSet();
mdsBudgetVerification = BsManager.GetBudgetVerificationByBudgetID(miBudgetID);
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
}
///
/// Processes the dataset and formats the grid
///
private void InitializeGrid()
{
try
{
//create the webhierarchicaldatasource to be used with the grid
WebHierarchicalDataSource whdsVerification = new WebHierarchicalDataSource();
// Create the dataviews to be used with the datasource
Infragistics.Web.UI.DataSourceControls.DataView dv = new Infragistics.Web.UI.DataSourceControls.DataView();
dv.DataSource = mdsBudgetVerification.Tables["BVSummary"];
dv.ID = "dvSummary";
whdsVerification.DataViews.Add(dv);
// Create the dataviews to be used with the datasource
dv = new Infragistics.Web.UI.DataSourceControls.DataView();
dv.DataSource = mdsBudgetVerification.Tables["BVDetails"];
dv.ID = "dvDetails";
whdsVerification.DataViews.Add(dv);
//create the relationship between the two views
Infragistics.Web.UI.DataSourceControls.DataRelation relVerification = new Infragistics.Web.UI.DataSourceControls.DataRelation();
relVerification.ParentDataViewID = "dvSummary";
relVerification.ChildDataViewID = "dvDetails";
relVerification.ParentColumns = new string[] { "ExpenditureType" };
relVerification.ChildColumns = new string[] { "ExpenditureType" };
whdsVerification.DataRelations.Add(relVerification);
//now create the parent columns
for (int i = 0; i < mdsBudgetVerification.Tables["BVSummary"].Columns.Count; i++)
{
BoundDataField bf = new BoundDataField();
bf.DataFieldName = mdsBudgetVerification.Tables["BVSummary"].Columns[i].Caption;
bf.Key = "Key" + (i + 2).ToString();
//bf.Header.Text = mdsBudgetVerification.Tables["BVSummary"].Columns[i].Caption;
bf.Header.Text = "Test";
bf.Width = 200;
grdVerification.Columns.Add(bf);
}
//now create the details band
Band bandDetails = new Band();
bandDetails.DataMember = "dvVerificationDetails";
bandDetails.AutoGenerateColumns = false;
for (int i = 0; i < mdsBudgetVerification.Tables["BVDetails"].Columns.Count; i++)
{
BoundDataField bf = new BoundDataField();
bf.DataFieldName = mdsBudgetVerification.Tables["BVDetails"].Columns[i].Caption;
bf.Key = "Key" + (i + 2).ToString();
bf.Header.Text = mdsBudgetVerification.Tables["BVDetails"].Columns[i].Caption;
bf.Width = 200;
bandDetails.Columns.Add(bf);
}
grdVerification.Bands.Add(bandDetails);
grdVerification.Columns[0].Width = 100;
grdVerification.Columns[1].Width = 500;
grdVerification.DataSource = whdsVerification;
grdVerification.DataBind();
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
}
# endregion
}
}