// Adds various reports to the worksheet.
void AddReportDataToSheet(Excel.Worksheet currentSheet, Excel.Range chartSeriesRange,
string reportType, DataTable dataTable, Excel.Chart infoBoxChart, ref int rowIndex)
{
try
{
switch (reportType)
{
case Constants.SalesReport.SALES_TERRITORY:
AddTerritoryData(currentSheet, chartSeriesRange, dataTable, infoBoxChart, ref rowIndex);
break;
case Constants.SalesReport.SALES_PERSON:
AddSalesPersonData(currentSheet, chartSeriesRange, dataTable, infoBoxChart,
ref rowIndex);
break;
case Constants.SalesReport.SALES_STORE:
AdSalesStoreData(currentSheet, chartSeriesRange, dataTable, infoBoxChart,
ref rowIndex);
break;
}
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
}
// Adds the data for the Sales Territory report.
void AddTerritoryData(Excel.Worksheet currentSheet, Excel.Range chartSeriesRange,
DataTable dataTable, Excel.Chart infoBoxChart, ref int rowIndex)
{
int index = 0;
foreach (DataRow dr in dataTable.Rows)
{
rowIndex++;
index++;
// Gets the values for the columns.
string territoryName = dr[Constants.SalesTerritoryDataColumn.NAME].ToString();
string salesYTD = dr[Constants.SalesTerritoryDataColumn.SALESYTD].ToString();
string salesLastYear = dr[Constants.SalesTerritoryDataColumn.SALESLAST].ToString();
string latitude = dr[Constants.SalesTerritoryDataColumn.LATITUDE].ToString();
string longitude = dr[Constants.SalesTerritoryDataColumn.LONGITUDE].ToString();
string territoryPerson = dr[Constants.SalesTerritoryDataColumn.PERSON].ToString();
// Adds data to the worksheet, cell by cell.
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SRNO] = index;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.NAME] = territoryName;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESLAST] = salesLastYear;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESYTD] = salesYTD;
// Gets the source data range for the chart.
Excel.Range sourceDataRange = currentSheet.get_Range(currentSheet.Cells
[rowIndex, Constants.ColumnIndex.SALESLAST],
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESYTD]);
// Gets the graph image name and path for the InfoBox.
string graphImageFileName = GetChartImageFilePath(rowIndex);
// Sets the chart source data and exports the data as an image for the InfoBox.
SetInfoBoxChartSourceDataAndExport(infoBoxChart, sourceDataRange, chartSeriesRange,
graphImageFileName);
// Replaces placeholders in the HTML string for the InfoBox.
string htmlTable = string.Format(Constants.InfoBoxHTML.SALES_TERRITORY, territoryName,
territoryPerson, salesLastYear, salesYTD);
// Adds pushpins to the map.
mapUserControl.AddPushPinOnMap(latitude, longitude, GetImageURLPath(graphImageFileName),
htmlTable, Constants.SalesReport.SALES_TERRITORY);
}
}
// Adds data for the Sales Territory report.
void AddSalesPersonData(Excel.Worksheet currentSheet, Excel.Range chartSeriesRange, DataTable dataTable,
Excel.Chart infoBoxChart, ref int rowIndex)
{
int index = 0;
try
{
foreach (DataRow dr in dataTable.Rows)
{
rowIndex++;
index++;
// Gets the values for the columns.
string salesPerson = dr[Constants.SalesPersonDataColumn.NAME].ToString();
string salesLastYear = "$" + dr[Constants.SalesPersonDataColumn.SALESLAST].ToString();
string salesYTD = "$" + dr[Constants.SalesPersonDataColumn.SALESYTD].ToString();
string latitude = dr[Constants.SalesPersonDataColumn.LATITUDE].ToString();
string longitude = dr[Constants.SalesPersonDataColumn.LONGITUDE].ToString();
string emailAddress = dr[Constants.SalesPersonDataColumn.EMAIL].ToString();
// Adds data to the worksheet, cell by cell.
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SRNO] = index;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.NAME] = salesPerson;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESLAST] = salesLastYear;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESYTD] = salesYTD;
// Gets the data range for the row chart.
Excel.Range sourceDataRange = currentSheet.get_Range(currentSheet.Cells
[rowIndex, Constants.ColumnIndex.SALESLAST],
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESYTD]);
// Gets the graph image name and path for the InfoBox.
string graphImageFileName = GetChartImageFilePath(rowIndex);
// Sets the chart source data and exports the data as an image for the InfoBox.
SetInfoBoxChartSourceDataAndExport(infoBoxChart, sourceDataRange,
chartSeriesRange, graphImageFileName);
// Replaces placeholders in the HTML string for the InfoBox.
string htmlTable = string.Format(Constants.InfoBoxHTML.SALES_PERSON, salesPerson,
emailAddress, salesLastYear, salesYTD);
// Adds pushpins to the map.
mapUserControl.AddPushPinOnMap(latitude, longitude, GetImageURLPath(graphImageFileName),
htmlTable, Constants.SalesReport.SALES_PERSON);
}
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
}
// Adds data for the Sales by Store report.
void AdSalesStoreData(Excel.Worksheet currentSheet, Excel.Range chartSeriesRange, DataTable dataTable,
Excel.Chart infoBoxChart, ref int rowIndex)
{
int index = 0;
try
{
foreach (DataRow dr in dataTable.Rows)
{
rowIndex++;
index++;
// Gets the values for the columns.
string storeName = dr[Constants.SalesStoreDataColumn.NAME].ToString();
string salesLastYear = "$" + dr[Constants.SalesStoreDataColumn.SALESLAST].ToString();
string salesYTD = "$" + dr[Constants.SalesStoreDataColumn.SALESYTD].ToString();
string latitude = dr[Constants.SalesStoreDataColumn.LATITUDE].ToString();
string longitude = dr[Constants.SalesStoreDataColumn.LONGITUDE].ToString();
string manager = dr[Constants.SalesStoreDataColumn.MANAGER].ToString();
// Adds data to the worksheet, cell by cell.
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SRNO] = index;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.NAME] = storeName;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESLAST] = salesLastYear;
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESYTD] = salesYTD;
// Gets the source data range for the InfoBox chart.
Excel.Range sourceDataRange = currentSheet.get_Range(currentSheet.Cells
[rowIndex, Constants.ColumnIndex.SALESLAST],
currentSheet.Cells[rowIndex, Constants.ColumnIndex.SALESYTD]);
// Gets the graph image name and path for the InfoBox.
string graphImageFileName = GetChartImageFilePath(rowIndex);
// Sets the chart source data and export the data as an image for the InfoBox.
SetInfoBoxChartSourceDataAndExport(infoBoxChart, sourceDataRange,
chartSeriesRange, graphImageFileName);
// Replaces placeholders in the HTML string for the InfoBox.
string htmlTable = string.Format(Constants.InfoBoxHTML.SALES_STORE, storeName,
manager, salesLastYear, salesYTD);
// Adds pushpins to the map.
mapUserControl.AddPushPinOnMap(latitude, longitude, GetImageURLPath(graphImageFileName),
htmlTable, Constants.SalesReport.SALES_STORE);
}
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
}
// Gets the URL for the InfoBox image.
private string GetImageURLPath(string filePath)
{
string returnValue = "";
try
{
if (filePath.Trim().Length != 0)
returnValue = "file:///" + filePath.Replace(@"\", "/");
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
return returnValue;
}
// Gets the temporary image file name for the InfoBox chart.
private string GetChartImageFilePath(int imageIndex)
{
string retVal = "";
try
{
string _temporaryFolderPath = System.IO.Path.GetTempPath();
retVal = _temporaryFolderPath + "ST_" + imageIndex.ToString() + ".gif";
}
catch (Exception ex)
{
DisplayException(ex.Message);
}
return retVal;
}