-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.aspx.cs
142 lines (123 loc) · 4.16 KB
/
default.aspx.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace waDEIG
{
public partial class _default : System.Web.UI.Page
{
string dash = "-";
// string zero = "0";
string comma = ", ";
// enum day of week and remove it from db.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack )
{
ddlDOW.SelectedIndex = 1;
}
}
protected void lbGet_Click(object sender, EventArgs e)
{
// Get the data from the selection and filter the data.
//
int dow = Int32.Parse(ddlDOW.SelectedValue);
int time = Int32.Parse(ddlTime.SelectedValue);
string town = ddlTown.SelectedValue;
StringBuilder sbGet = new StringBuilder();
// get day selection
if (dow != 0)
{
sbGet.Append(string.Format(" DOW = {0}", dow));
}
else
{
sbGet.Append(String.Format(" DOW > {0}", 0));
}
// Get time selection
if (time != 0)
{
if (sbGet.Length > 0)
{
sbGet.Append(String.Format(" AND TimeID = {0}", time));
}
}
// Get Town selection
if (town != dash)
{
if (sbGet.Length > 0)
{
sbGet.Append(String.Format(" AND Town = '{0}'", town));
}
}
else
{
sbGet.Append(String.Format(" AND Town like '{0}'", "%"));
}
// Set the filter
if (sbGet.Length > 0)
{
SqlDsList.FilterExpression = sbGet.ToString();
}
else
{
SqlDsList.FilterExpression = null;
}
// lblFilter.Text = "Filter: " + SqlDsList.FilterExpression.ToString();
}
protected void LnkExport_Click(object sender, EventArgs e)
{
int rc = -1;
string cnStr = ConfigurationManager.ConnectionStrings["cnDEIG"].ConnectionString;
SqlConnection cn = new SqlConnection(cnStr);
SqlCommand cmd = new SqlCommand("GetMeetingList");
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
// Get the connection into the SqlCommand object
cmd.Connection = cn;
da.SelectCommand = cmd;
DataTable dt = new DataTable();
try
{
rc = da.Fill(dt);
}
catch (InvalidCastException ex)
{
lblFilter.Text = ex.ToString();
}
// Read the table to create a file for export
StringBuilder sb = new StringBuilder();
foreach (DataColumn column in dt.Columns)
{
// Add the Header row for the text file
sb.Append(column.ColumnName + comma);
}
// Add new line
sb.AppendLine();
// Get the data
foreach (DataRow row in dt.Rows)
{
foreach (DataColumn column in dt.Columns)
{
sb.Append(row[column.ColumnName].ToString() + comma);
}
// Add new line
sb.AppendLine();
}
// Download the text file
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=MeetingList.csv");
Response.Charset = "";
Response.ContentType = "application/text";
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();
}
}
}