Oke lets you see code below:
default.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="default.ascx.cs" Inherits="Module.GridViewTxtfile._default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<style type="text/css">
.Exportcssexelbutton {
margin-left: 610px;
margin-top: 12px;
}
</style>
<table>
<tr>
<td>Upload</td>
<td>
<telerik:raddatepicker id="rdpstardatelog" runat="server" width="150px"
autopostback="false" dateinput-emptymessage="Tanggal" mindate="01/01/1000" maxdate="01/01/3000">
<calendar>
<SpecialDays>
<telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday" />
</SpecialDays>
</calendar>
</telerik:raddatepicker></td>
<td>Approve/Reject</td>
<td>
<telerik:raddatepicker id="rdpenddatelog" runat="server" width="150px"
autopostback="false" dateinput-emptymessage="Tanggal" mindate="01/01/1000" maxdate="01/01/3000">
<calendar>
<SpecialDays>
<telerik:RadCalendarDay Repeatable="Today" ItemStyle-CssClass="rcToday" />
</SpecialDays>
</calendar>
</telerik:raddatepicker></td>
<td>
<asp:Button ID="btnfilterlog" runat="server" Text="Filter" OnClick="btnfilterlog_click" /></td>
</tr>
</table>
<div runat="server" id="divPrint">
<asp:GridView ID="grdshowlog" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Uploadby" SortExpression="Uploadby">
<ItemTemplate>
<asp:Label ID="lbluploadby" runat="server" Text='<%#Eval("Uploadby") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DatetimeUploadby" SortExpression="DatetimeUploadby">
<ItemTemplate>
<asp:Label ID="lbldatetmeuploadby" runat="server" Text='<%#Eval("DatetimeUploadby") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Datetimekurs" SortExpression="Datetimekurs">
<ItemTemplate>
<asp:Label ID="lblDatetimekurs" runat="server" Text='<%#Eval("Datetimekurs") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ApprovedRejectedby" SortExpression="ApprovedRejectedby">
<ItemTemplate>
<asp:Label ID="lblApprovedRejectedby" runat="server" Text='<%#Eval("ApprovedRejectedby") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DatetimeApprovedreject" SortExpression="DatetimeApprovedreject">
<ItemTemplate>
<asp:Label ID="lblDatetimeApprovedreject" runat="server" Text='<%#Eval("DatetimeApprovedreject") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" SortExpression="Status">
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%#Eval("Status") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Notes" SortExpression="Notes">
<ItemTemplate>
<asp:Label ID="lblNotes" runat="server" Text='<%#Eval("Notes") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</div>
<div id="divExport" class="Exportcssexelbutton">
<asp:Button ID="btnExportExel" runat="server" Text="ExportToExell" OnClick="btnExportExel_click" />
</div>
default.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using Telerik.Web.UI;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
namespace Module.GridViewTxtfile
{
public partial class _default : PortalModuleBase
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
grdshowlog.DataSource = bindgrdLogview();
grdshowlog.DataBind();
}
}
protected void btnExportExel_click(object sender, EventArgs e)
{
//perintah untuk melakukan Export to Exeel
HttpResponse Response = HttpContext.Current.Response;
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.ContentType = "applicatio/excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
HtmlForm frm = new HtmlForm();
grdshowlog.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(grdshowlog);
frm.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
private List<FXRateslog> bindgrdLogview()
{
List<FXRateslog> listData = new List<FXRateslog>();
readandsplitdata(listData);
return listData;
}
protected void btnfilterlog_click(object sender, EventArgs e)
{
if (rdpstardatelog.SelectedDate !=null)
{
grdshowlog.DataSource = bindgridfilterUpload();
grdshowlog.DataBind();
}
if(rdpenddatelog.SelectedDate !=null)
{
grdshowlog.DataSource = bindgridfilterApprove();
grdshowlog.DataBind();
}
}
private List<FXRateslog> bindgridfilterUpload()
{
List<FXRateslog> listDatafilterUpload = new List<FXRateslog>();
readandsplidfilterUpload(listDatafilterUpload);
return listDatafilterUpload;
}
private List<FXRateslog> bindgridfilterApprove()
{
List<FXRateslog> listDatafilterApproved = new List<FXRateslog>();
readsplitfilterApprovereject(listDatafilterApproved);
return listDatafilterApproved;
}
private void readsplitfilterApprovereject(List<FXRateslog> lisdatafilterapprove)
{
string ApprovDateReject = Convert.ToDateTime(rdpenddatelog.SelectedDate.Value).ToString("MM/dd/yyyy");
string ApprovDateRejectData = ApprovDateReject;
List<string> lines = new List<string>();
using (System.IO.StreamReader file = new System.IO.StreamReader(Server.MapPath("~/App_Data/data.txt")))
{
string line;
while ((line = file.ReadLine()) != null)
{
lines.Add(line);
}
}
foreach (string s in lines)
{
string[] f = s.Split('#');
FXRateslog data = new FXRateslog();
DateTime Aprovedrejectdate=Convert.ToDateTime(f[5]);
string ApprovedrejectDateData=Convert.ToDateTime(Aprovedrejectdate).ToString("MM/dd/yyyy");
if (ApprovDateRejectData == ApprovedrejectDateData)
{
data.Uploadby = f[1];
data.DatetimeUploadby = f[2];
data.Datetimekurs = f[3];
data.ApprovedRejectedby = f[4];
data.DatetimeApprovedreject = f[5];
data.Status = f[6];
data.Notes = f[7];
lisdatafilterapprove.Add(data);
}
else
{
}
}
}
private void readandsplidfilterUpload(List<FXRateslog> lisdatafilterUpload)
{
string UploadDatelog = Convert.ToDateTime(rdpstardatelog.SelectedDate.Value).ToString("MM/dd/yyyy");
string UploadDate = UploadDatelog;
List<string> lines = new List<string>();
using (System.IO.StreamReader file = new System.IO.StreamReader(Server.MapPath("~/App_Data/data.txt")))
{
string line;
while ((line = file.ReadLine()) != null)
{
lines.Add(line);
}
}
foreach (string s in lines)
{
string[] f = s.Split('#');
FXRateslog data = new FXRateslog();
DateTime DatetimeUpload = Convert.ToDateTime(f[2]);
string DatetimeUploadData = Convert.ToDateTime(DatetimeUpload).ToString("MM/dd/yyyy");
if (UploadDate == DatetimeUploadData)
{
data.Uploadby = f[1];
data.DatetimeUploadby = f[2];
data.Datetimekurs = f[3];
data.ApprovedRejectedby = f[4];
data.DatetimeApprovedreject = f[5];
data.Status = f[6];
data.Notes = f[7];
lisdatafilterUpload.Add(data);
}
else
{
}
}
}
private void readandsplitdata(List<FXRateslog> lisdata)
{
List<string> lines = new List<string>();
using (System.IO.StreamReader file = new System.IO.StreamReader(Server.MapPath("~/App_Data/data.txt")))
{
string line;
while ((line = file.ReadLine()) != null)
{
lines.Add(line);
}
}
foreach (string s in lines)
{
string[] f = s.Split('#');
FXRateslog data = new FXRateslog();
data.Uploadby= f[1];
data.DatetimeUploadby=f[2];
data.Datetimekurs = f[3];
data.ApprovedRejectedby = f[4];
data.DatetimeApprovedreject = f[5];
data.Status = f[6];
data.Notes = f[7];
lisdata.Add(data);
}
}
public class FXRateslog
{
public string Uploadby { get; set; }
public string DatetimeUploadby { get; set; }
public string Datetimekurs { get; set; }
public string ApprovedRejectedby { get; set; }
public string DatetimeApprovedreject { get; set; }
public string Status { get; set; }
public string Notes { get; set; }
}
public object[] dr { get; set; }
}
}
if you click button ExportExel you can see result display at below:
http://www.4shared.com/rar/GRx8iwBR/ModuleByAndriyanto_LampungUtar.html?
Tidak ada komentar:
Posting Komentar