There is one small problem I have found with it though, and it seems to be a problem with the way ReportDataSource.GetProductBreakdownSummary gets the results. If a product has no sales during the selected time-period, a report is not even generated for it. My code covers up this error most of the time, but if it has no sales in the LAST 30 days, it causes my months to be off by 1.
If anyone can use my code to help me with this problem it could be useful to others.
How to use the code:
On Admin/products/EditProduct.aspx:
At the top:
Code: Select all
<%@ Register Src="~/ConLib/productPerformance.ascx" TagName="Perform" TagPrefix="uc" %>
Code: Select all
<uc:Perform id="performanceControl" runat="server" />
Code: Select all
<%@ Control Language="C#" ClassName="productPerformance" %>
<script runat="server">
private int _ProductId = 0;
int monthSelect=1;
int quantityRoller=0;
LSDecimal amountRoller=0;
List<ProductBreakdownSummary> cleanreport=new List<ProductBreakdownSummary>();
protected void Page_Init(object sender, EventArgs e)
{
_ProductId = PageHelper.GetProductId();
}
protected void ProcessButton_Click(object sender, EventArgs e)
{
BindGrid();
}
protected void BindGrid()
{
DateTime toDate =DateTime.Today;
for(int i=0;i<=3;i++){
DateTime theDay =new DateTime(DateTime.Today.Year, (DateTime.Today.Month)-i, 1);
List<ProductBreakdownSummary> breakdownReport = ReportDataSource.GetProductBreakdownSummary(theDay.Date, toDate.Date, 0, "Quantity");
foreach (ProductBreakdownSummary pbs in breakdownReport)
{
if(pbs.ProductId==_ProductId){
pbs.Quantity=pbs.Quantity-quantityRoller;
quantityRoller+=pbs.Quantity;
pbs.Amount=pbs.Amount-amountRoller;
amountRoller+=pbs.Amount;
cleanreport.Add(pbs);
}
}
}
ProductBreakdownGrid.DataSource = cleanreport;
ProductBreakdownGrid.DataBind();
}
</script>
<ajax:UpdatePanel ID="ReportAjax" runat="server">
<ContentTemplate>
<div class="pageHeader">
<div class="caption">
<h1>
<asp:Localize ID="Caption" runat="server" Text="Product Performance"></asp:Localize>
</h1>
</div>
</div>
<asp:Label ID="msg" runat="server" Text="Sales figures are represented as a total for each month. Month 0 is the current month."></asp:Label>
<table align="left" class="form" cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<div style="text-align: left; vertical-align: middle">
<asp:Button ID="ProcessButton" runat="server" Text="Generate Report" OnClick="ProcessButton_Click" />
</div>
</td>
</tr>
<tr>
<td class="dataSheet" >
<asp:GridView ID="ProductBreakdownGrid" runat="server" AutoGenerateColumns="False" PageSize="20" Width="100%" SkinID="PagedList">
<Columns>
<asp:TemplateField HeaderText="Months">
<ItemTemplate>
<%# -Container.DataItemIndex %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="CustomerLabel" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sku">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="Label0" runat="server" Text='<%# Eval("Sku", "{0}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vendor">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Vendor", "{0:lc}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="QuantityLabel" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="AmountLabel" runat="server" Text='<%# string.Format("{0:lc}", Eval("Amount")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<div class="emptyResult">
<asp:Label ID="EmptyResultsMessage" runat="server" Text="There are no results"></asp:Label>
</div>
</EmptyDataTemplate>
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</ajax:UpdatePanel>