-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExportItem-old.aspx
208 lines (194 loc) · 7.86 KB
/
ExportItem-old.aspx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="Sitecore.Globalization" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="Sitecore.Collections" %>
<%@ Import Namespace="Sitecore.Data.Managers" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Sitecore.Data.Fields" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Event Report</title>
<style>
body {
font-family: verdana, arial, sans-serif;
}
table.table-style-three {
font-family: verdana, arial, sans-serif;
font-size: 11px;
color: #333333;
border-width: 1px;
border-color: #3A3A3A;
border-collapse: collapse;
}
table.table-style-three th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #FFA6A6;
background-color: #D56A6A;
color: #ffffff;
}
table.table-style-three tr:nth-child(even) td {
background-color: #F7CFCF;
}
table.table-style-three td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #FFA6A6;
background-color: #ffffff;
}
</style>
<script language="CS" runat="server">
StringBuilder sb;
DataTable tb;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Sitecore.Context.User.IsAuthenticated == false)
{
Response.Redirect("login.aspx?returnUrl=exportitem.aspx");
}
}
protected void btnGetReport_Click(object sender, EventArgs e)
{
try
{
string path = txtPath.Text;
Database db = Database.GetDatabase("web");
Language lang = Sitecore.Globalization.Language.Parse(txtLang.Text);
Item parent = db.GetItem(path, lang);
tb = new DataTable();
tb.Columns.Add("Item Path");
int rowNumber = 0;
foreach (Item childItem in parent.Axes.GetDescendants())
{
if (childItem.TemplateName == txtTemplateName.Text)// && childItem["Type"] == "{612536F4-3F71-4C5F-8A94-FE6580F7103A}")
{
// Ucomment below section for date filter *************
//DateTime dtFrom = Sitecore.DateUtil.ParseDateTime(childItem["Event From"],DateTime.MinValue);
//DateTime dtTo = Sitecore.DateUtil.ParseDateTime(childItem["Event To"],DateTime.MaxValue);
//DateTime txtFrom = DateTime.Parse(txtEventFrom.Text);
//DateTime txtTo = DateTime.Parse(txtEventTo.Text);
//if ((dtFrom >= txtFrom && dtFrom <= txtTo) || (dtTo >= txtFrom && dtTo <=txtTo))
//{
// Ucomment above section for date filter ***************
DataRow itemRow = tb.NewRow();
//int colNumber = 0;
childItem.Fields.ReadAll();
foreach (Field fld in childItem.Fields)
{
if (!fld.Name.StartsWith("__"))
{
if (rowNumber == 0)
{
if (tb.Columns.Contains(fld.Name))
{
tb.Columns.Add(fld.SectionDisplayName + "_" + fld.Name + Guid.NewGuid().ToString());
}
else
{
tb.Columns.Add(fld.Name);
}
}
}
}
rowNumber++;
foreach (Field fld in childItem.Fields)
{
if (!fld.Name.StartsWith("__"))
{
if (tb.Columns[fld.Name] != null)
{
itemRow["Item Path"] = childItem.ID.ToString();
itemRow[fld.Name] = fld.GetValue(true);
}
}
}
tb.Rows.Add(itemRow);
//}
}
}
lblCount.Text = "Total items: " + tb.Rows.Count.ToString();
grdLanguageReport.DataSource = tb;
grdLanguageReport.DataBind();
Session.Add("Data", tb);
}
catch (Exception ex)
{
lblCount.Text = ex.ToString();
}
}
protected void ExportToExcel(object sender, EventArgs e)
{
string attachment = "attachment; filename=Report.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
tb = (DataTable)Session["Data"];
foreach (DataColumn dc in tb.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in tb.Rows)
{
tab = "";
for (i = 0; i < tb.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h2>Export Item Tool - Visit Dubai</h2>
<table>
<tr>
<td>Provide Parent Item Path:<asp:TextBox ID="txtPath" Width="700px" runat="server"></asp:TextBox></td>
<td>Template Name:<asp:TextBox ID="txtTemplateName" Width="700px" runat="server"></asp:TextBox></td>
<%--<td>Event From:<asp:TextBox ID="txtEventFrom" runat="server"></asp:TextBox></td>
<td>Event To:<asp:TextBox ID="txtEventTo" runat="server"></asp:TextBox></td>--%>
<td>Language:<asp:TextBox ID="txtLang" Text="en" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button ID="btnGetReport" Text="Export" runat="server" OnClick="btnGetReport_Click" />
<%--<asp:Button ID="btnDownload" runat="server" Text="Download Report" OnClick="ExportToExcel" />--%>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCount" runat="server"></asp:Label></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="4">
<asp:GridView ID="grdLanguageReport" CssClass="table-style-three" runat="server"></asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>