public override void RenderContent(HtmlTextWriter writer) { exportExcel = Request["exporttoexcel.x"] != null ? true : false; UserTypes userType = UserTypes.Agent; BetListType betlistType = BetListType.Winlost; DataTable betListData = View as DataTable; GetCachePropertyById funcGetOddsTypeName = CacheRef.GetOddsTypeName; ITicketHelper ticketHelper = new ExampleTicketHelper(); ticketHelper.CurrentLanguage = UserSession.Current.LangKey; IList<ITicket> tickets = new List<ITicket>(); if (betListData != null) { tickets = TicketTransformer.Transform(betListData); betListData.Dispose(); } List<ITicketData> ticketData = new List<ITicketData>(); if (commandData != null) { ticketData = TicketDataTransformer.Transform(commandData); commandData.Dispose(); } bool isAdminCanViewVNIP = true; string reportTitle = "Member Bet List 11/1/2012 --> 12/5/2012- JJB5656566"; int index = 0; if (exportExcel) { BetListExcelFactory factory = new BetListExcelFactory(); BetListExcelBuilder builder = factory.CreateBuilder(); bool isShowWinLost = true; bool isShowSuperPT = false; bool isShowMasterPT = false; bool isShowAgentPT = true; bool isShowMember = false; builder.BuildWorksheet("BetList", 8); builder.AddCaption(reportTitle, 8); builder.AddHeader(isShowWinLost, isShowSuperPT, isShowMasterPT, isShowAgentPT, isShowMember); foreach (ITicket ticket in tickets) { index++; ticketHelper.Index = index; builder .AddNo(index) .AddTrans(ticket, ticketHelper) .AddChoice(ticket, ticketHelper, ticketData) .AddOdds(ticket, ticketData, funcGetOddsTypeName) .AddStake(ticket) .AddWinLoss(ticket) .AddStatus(ticket, ticketHelper, ticketData, isAdminCanViewVNIP) .AddAgentPT(ticket, ticketData); } if (tickets.Count == 0 || (betlistType & BetListType.Winlost) == BetListType.Winlost) { builder.AddFooter(tickets, isShowMember, 8); } MemoryStream ms = new MemoryStream(); IWorkbook resultWorkbook = builder.GetBetList(); resultWorkbook.Write(ms); ExportToExcel(ms, "BetList.xls"); ms.Dispose(); return; } else { BetListTemplate tpl = new BetListTemplate(); StringBuilder content = new StringBuilder(); tpl.title = "Member Bet List 11/1/2012 --> 12/5/2012- JJB5656566"; OpenBetList_Template betlistOpenTag = new OpenBetList_Template(); content.Append(betlistOpenTag); Header1_Template betlistHeader = new Header1_Template(); betlistHeader.Member.Hide(); betlistHeader.Super.Hide(); betlistHeader.Master.Hide(); content.Append(betlistHeader); content.Append("<tbody>"); ForecastBO bo = new ForecastBO(UserSession.Current.NetSessionId); List<int> lstScoremap = bo.GetListBetTypeScoreMap(); bool isShowScoremap = false; BetListHTMLFactory factory = new BetListHTMLFactory(); BetListHTMLBuilder builder = factory.CreateBuilder(); foreach (ITicket ticket in tickets) { index++; ticketHelper.Index = index; builder.Append("<tr>") .AddNo(index, "<td class='w-order'>", "</td>") .AddTrans(ticket, "<td class='c'>", "</td>") .AddChoice(ticket, ticketHelper, ticketData, "<td class='r bl_evt'><div>", "</div></td>", isShowScoremap) .AddOdds(ticket, ticketData, "<td class='bl_underdog'>", "</td>", funcGetOddsTypeName) .AddStake(ticket, "<td class='bl_underdog'>", "</td>") .AddWinLoss(ticket, "<td class='r'>", "</td>") .AddStatus(ticket, ticketHelper, ticketData, "<td class='c'>", "</td>", isAdminCanViewVNIP) .AddAgentPT(ticket, ticketData, "<td class='r'>", "</td>") .Append("</tr>"); } builder.AddFooter(tickets, string.Empty, string.Empty, userType, (Fanex.BetList.Age.Definition.BetListType)betlistType); content.Append(builder.GetBetList()); content.Append("</tbody></table>"); tpl.content = content.ToString(); tpl.ToString(writer); } }
/// <summary> /// Exports the excel. /// </summary> public void ExportExcel(BetListData query) { GetCachePropertyById funcGetOddsTypeName = CacheRef.GetOddsTypeName; var factory = new BetListExcelFactory(); BetListExcelBuilder builder = factory.CreateBuilder(); ITicketHelper ticketHelper = new TicketHelper(); const short excelColumns = 7; builder.BuildWorksheet("BetList", excelColumns); var index = 0; var model = GetDataSource(query, sourcePath: DataSourcePath); _tickets = model.Tickets; _ticketData = model.TicketData; if (_tickets != null) { foreach (ITicket ticket in _tickets) { index++; ticketHelper.Index = index; builder.AddNo(index) .AddTrans(ticket, ticketHelper) .AddUsername(ticket, ticketHelper) .AddChoice(ticket, ticketHelper, _ticketData) .AddOdds(ticket, _ticketData, funcGetOddsTypeName) .AddStatus(ticket, ticketHelper, _ticketData, true) .AddStake(ticket); } var ms = new MemoryStream(); var resultWorkbook = builder.GetBetList(); resultWorkbook.Write(ms); ExportToExcel(ms, "BetList.xls"); } }