<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<xml runat="server" id="dimensions">
<dimensions>
<entities>
<entity>1</entity>
</entities>
<scenarios>All</scenarios>
<measures>
<measure>Output</measure>
</measures>
<accounts>
<account>1030.00.000</account>
<account>1040.00.000</account>
<account>-</account>
<account>1070.00.000</account>
<account></account>
<account>1080.00.010</account>
<account>1080.00.020</account>
<account>1080.00.030</account>
<account>-</account>
<account>1080.00.000</account>
<account>1115.00.000</account>
<account>1110.00.000</account>
<account>-</account>
<account>1150.00.000</account>
<account></account>
<account>1160.00.000</account>
<account>1170.00.000</account>
<account>-</account>
<account>1200.00.000</account>
<account></account>
<account>1240.00.000</account>
<account>1420.00.000</account>
<account>-</account>
<account>1600.00.000</account>
<account>1690.00.000</account>
<account>-</account>
<account>1700.00.000</account>
<account></account>
<account>1730.00.000</account>
<account></account>
<account>1750.00.000</account>
<account>=</account>
<account></account>
<account>7027.00.000</account>
<account></account>
<account>1800.00.000</account>
<account>-</account>
<account>1850.00.000</account>
<account></account>
<account>1900.00.000</account>
<account></account>
<account></account>
</accounts>
<time>All</time>
</dimensions>
</xml>
<script runat="server">
protected void Page_Load(object sender, System.EventArgs eventArgs)
{
string user = Request.Params["user"];
if (user == null || user == "") user = "username";
string password = Request.Params["password"];
if (password == null || password == "") password = "password";
string hsfServer = Request.Params["hsfServer"];
if (hsfServer == null || hsfServer == "") hsfServer = "HSFServer";
string database = Request.Params["database"];
string entity = Request.Params["entity"];
if (entity == null || entity == "") entity = "1";
string scenario = Request.Params["scenario"];
if (scenario == null || scenario == "") scenario = "Base";
string measure = Request.Params["measure"];
if (measure == null || measure == "") measure = "Output";
bool entityOpened = false;
string sessionID = "";
HSFEntityWebService.HSFEntityWebService hsfEntityWebService = null;
try
{
// Create general web service link.
HSFWebService.HSFWebService hsfWebService = new HSFWebService.HSFWebService();
// Create session with user/password.
sessionID = hsfWebService.CreateSession(user, password);
if (sessionID == "") throw new Exception("Can not create a valid session.");
// Open server.
hsfWebService.OpenServer(sessionID, hsfServer);
// Enum databases and make sure there is at least one.
string[] databases = hsfWebService.EnumDatabases(sessionID);
if (databases.Length < 1) throw new Exception("There are no databases in the current server.");
// Open database.
if (database == null || database == "") database = databases[0];
hsfWebService.OpenDatabase(sessionID, database);
// Get a list of entities.
System.Data.DataSet entities = hsfWebService.EnumEntities(sessionID, "", "All");
if(entities == null || entities.Tables["Entities"] == null) throw new Exception("There are no entities in this database");
System.Data.DataRow[] entityRows = entities.Tables["Entities"].Select();
if (entityRows.Length < 1) throw new Exception("There are no entities in this database");
entity = (string)entityRows[0]["ID"];
// Create entity web service link.
hsfEntityWebService = new HSFEntityWebService.HSFEntityWebService();
// Open entity.
hsfEntityWebService.OpenEntity(sessionID, entity, false);
// Mark entity as opened.
entityOpened = true;
// Get list of time periods.
System.Data.DataSet timePeriods = hsfEntityWebService.EnumTimePeriods(sessionID);
if(timePeriods == null || timePeriods.Tables["TimePeriods"] == null) throw new Exception("There are no time periods in this entity");
System.Data.DataRow[] timePeriodRows = timePeriods.Tables["TimePeriods"].Select();
if (timePeriodRows.Length < 1) throw new Exception("here are no time periods in this entity");
int timeCols = timePeriodRows.Length;
System.Data.DataSet scenarios = hsfEntityWebService.EnumScenarios(sessionID);
if (scenarios == null || scenarios.Tables["Scenarios"] == null) throw new Exception("There are no scenarios in this entity");
System.Data.DataRow[] scenarioRows = scenarios.Tables["Scenarios"].Select();
if (scenarioRows.Length < 1) throw new Exception("here are no scenarios in this entity");
System.Data.DataSet accounts = hsfEntityWebService.EnumAccounts(sessionID);
if (accounts == null || accounts.Tables["Accounts"] == null) throw new Exception("There are no accounts in this entity");
System.Data.DataTable accountTable = accounts.Tables["Accounts"];
System.Data.DataRow[] accountRows = accountTable.Select();
if (accountRows.Length < 1) throw new Exception("here are no accounts in this entity");
string[] accountList = null;
string xml = this.dimensions.InnerText;
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xml);
System.Xml.XmlNodeList accountNodes = xmlDoc.SelectNodes("descendant::dimensions/accounts/account");
if (accountNodes != null && accountNodes.Count > 0)
{
accountList = new string[accountNodes.Count];
for (int j = 0; j < accountNodes.Count; j++)
{
// Get node and create a new data cell info object.
System.Xml.XmlNode accountNode = accountNodes.Item(j);
if (accountNode != null)
{
accountList[j] = accountNode.InnerText;
if (accountList[j] == "") accountList[j] = " ";
}
}
}
System.Data.DataSet dataCellsOut = null;
// Create data set for GetCellData call.
System.Data.DataSet dataCellsIn = new System.Data.DataSet();
System.Data.DataTable dataCellsInTable = dataCellsIn.Tables.Add("DataCells");
// Add columns to the table.
dataCellsInTable.Columns.Add("Entity", typeof(string));
dataCellsInTable.Columns.Add("Account", typeof(string));
dataCellsInTable.Columns.Add("Time", typeof(string));
dataCellsInTable.Columns.Add("Scenario", typeof(string));
dataCellsInTable.Columns.Add("Measure", typeof(string));
dataCellsInTable.Columns.Add("CustomMembers", typeof(string));
foreach (string account in accountList)
{
for (int j = 0; j < timeCols; j++)
{
System.Data.DataRow dataRow = dataCellsInTable.NewRow();
dataRow["Entity"] = entity;
dataRow["Account"] = account;
dataRow["Measure"] = measure;
dataRow["Scenario"] = scenario;
dataRow["Time"] = timePeriodRows[j]["ID"];
dataRow["CustomMembers"] = "";
dataCellsInTable.Rows.Add(dataRow);
}
}
// Call GetDataCells.
dataCellsOut = hsfEntityWebService.GetEntityDataCells(sessionID, dataCellsIn);
if (dataCellsOut == null) throw new Exception("DataCells data set not found.");
System.Data.DataTable dataCellsOutTable = dataCellsOut.Tables["DataCells"];
if (dataCellsOutTable == null) throw new Exception("DataCells table not found.");
// Create table.
HtmlTable table = new HtmlTable();
HtmlTableRow row;
HtmlTableCell cell;
// Create the top header row.
row = new HtmlTableRow();
// Create the first two header cells and add them to the current row.
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell("th");
cell.Align = "center";
cell.InnerHtml = "Account Names";
row.Cells.Add(cell);
// Create the time header.
int i;
for (i = 0; i < timeCols; i++)
{
System.Data.DataRow timePeriodRow = timePeriodRows[i];
cell = new HtmlTableCell("th");
cell.InnerHtml = (string)timePeriodRow["Name"];
row.Cells.Add(cell);
}
// Add the row to the table.
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "left";
cell.ColSpan = 4;
cell.InnerHtml = "File: 1.alc Last Calculated 9:38:05 PM 6/10/2008";
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "right";
cell.ColSpan = timeCols - 3;
string scenarioList = "Scenario:<select name=\"scenarioList\" onChange=\"gotosite(this.options[this.selectedIndex].value)\">";
for (i = 0; i < scenarioRows.Length; i++)
{
scenarioList += "<option value=\"IncomeStatement.aspx?scenario=" + (string)scenarioRows[i]["ID"] + "\"";
if (scenario == (string)scenarioRows[i]["ID"]) scenarioList += " selected";
scenarioList += ">" + scenarioRows[i]["ID"] + "</option>";
}
scenarioList += "</select>";
cell.InnerHtml = scenarioList;
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "center";
cell.ColSpan = timeCols + 1;
cell.InnerHtml = "Income Statement for Sample Incorporated";
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "center";
cell.ColSpan = timeCols + 1;
cell.InnerHtml = "Strategic Plan 2006-2012";
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.ColSpan = timeCols + 1;
cell.InnerHtml = " ";
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.InnerHtml = "Author: Hyperion Solutions";
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "left";
cell.ColSpan = timeCols;
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.InnerHtml = "SIC Code: 4800";
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "left";
cell.ColSpan = timeCols;
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.InnerHtml = "Scenario: Base";
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "left";
cell.ColSpan = timeCols;
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.InnerHtml = "Millions of Dollars";
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "left";
cell.ColSpan = timeCols;
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.ColSpan = timeCols + 1;
cell.InnerHtml = " ";
row.Cells.Add(cell);
table.Rows.Add(row);
// Create the top header row.
row = new HtmlTableRow();
// Create the first two header cells and add them to the current row.
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell("td");
row.Cells.Add(cell);
// Create the time cells.
for (i = 0; i < timeCols; i++)
{
System.Data.DataRow timePeriodRow = timePeriodRows[i];
cell = new HtmlTableCell();
cell.Align = "center";
cell.InnerHtml = (string)timePeriodRow["Name"];
row.Cells.Add(cell);
}
// Add the row to the table.
table.Rows.Add(row);
// Create the next header row and add it to the table;
row = new HtmlTableRow();
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.ColSpan = timeCols + 1;
cell.InnerHtml = " ";
row.Cells.Add(cell);
table.Rows.Add(row);
foreach (string account in accountList)
{
// Create the account row.
row = new HtmlTableRow();
if (account == "-")
{
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
row.Cells.Add(cell);
for (i = 0; i < timeCols; i++)
{
cell = new HtmlTableCell();
cell.InnerHtml = "<hr />";
row.Cells.Add(cell);
}
}
else if (account == "=")
{
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
row.Cells.Add(cell);
for (i = 0; i < timeCols; i++)
{
cell = new HtmlTableCell();
cell.InnerHtml = "======";
row.Cells.Add(cell);
}
}
else if (account == " ")
{
cell = new HtmlTableCell("th");
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.ColSpan = timeCols + 1;
cell.InnerHtml = " ";
row.Cells.Add(cell);
}
else
{
cell = new HtmlTableCell("th");
cell.Align = "left";
cell.InnerHtml = account;
row.Cells.Add(cell);
cell = new HtmlTableCell();
cell.Align = "left";
accountRows = accountTable.Select("ID='" + account + "'");
if (accountRows.Length > 0)
{
cell.InnerHtml = (string)accountRows[0]["Name"];
}
row.Cells.Add(cell);
for (int j = 0; j < timeCols; j++)
{
cell = new HtmlTableCell();
cell.Align = "right";
try
{
System.Data.DataRow[] valueRows = dataCellsOutTable.Select("Account='" + account + "' AND Time='" + timePeriodRows[j]["ID"] + "'");
if (valueRows.Length > 0)
{
Double d = Double.Parse((string)valueRows[0]["Value"]) / 1000000;
cell.InnerHtml = d.ToString("N2");
}
else
{
cell.InnerHtml = "N/A";
}
}
catch (Exception)
{
cell.InnerHtml = "N/A";
}
row.Cells.Add(cell);
}
}
table.Rows.Add(row);
}
// Add the table to the page.
this.Controls.Add(table);
}
catch (Exception e)
{
Response.Write("<center><h3>" + e.Message + "</h3></center>");
}
try
{
if (hsfEntityWebService != null && entity != null && entity != "" && entityOpened)
{
hsfEntityWebService.ReleaseEntityLock(sessionID, entity);
}
}
catch (Exception e)
{
}
}
</script>
<script language="JavaScript">
function gotosite(site)
{
if(site != "")
{
self.location=site;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Income Statement</title>
<style type="text/css">
th { color: white; background-color: darkgray }
table { font-size: 90%; }
</style>
</head>
<body>
</body>
</html>