-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.aspx
executable file
·162 lines (140 loc) · 5.55 KB
/
print.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
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<title>Print Schedule</title>
</head>
<body background="../../Images/Background.gif" bgcolor=#FFFFFF link=#0000FF vlink=#0000FF alink=#000080 topmargin=2>
<span style="font-family: sans-serif">
<pre>
<%@ Page LANGUAGE="CSHARP" %>
<%
/********************************************
Cablecast Print Schedule Plugin
Generates a printable schedule form the
Cablecast Database.
This page prints the schedule selected from the
default.asp, the channelID is passed via the
query string 'ChannelID'
Date: 18/02/2004
Programmer: Scott Jann
********************************************/
string ChannelName = "";
int ChannelID = Convert.ToInt32(Request.QueryString["ChannelID"]);
DateTime startDate = DateTime.Parse(Request.QueryString["Start"]);
int numDays = Convert.ToInt32(Request.QueryString["Length"]);
DateTime endDate = startDate.AddDays(numDays);
string dateFormat = "dddd, MMMM d, yyyy";
System.Data.SqlClient.SqlConnection SqlConn = new System.Data.SqlClient.SqlConnection();
System.Data.SqlClient.SqlDataReader SqlDr = null;
try
{
//open database connection
SqlConn.ConnectionString = "Data Source=(local);Initial Catalog=Cablecast40;Integrated Security=SSPI;Persist Security Info=False;Packet Size=4096";
SqlConn.Open();
System.Data.SqlClient.SqlCommand SqlCmd = new System.Data.SqlClient.SqlCommand("SELECT stChannels.* FROM stChannels WHERE ChannelID=" + ChannelID + ";", SqlConn);
//set data reader
SqlDr = SqlCmd.ExecuteReader();
if(SqlDr.Read())
{
ChannelName = SqlDr["ChannelName"].ToString();
}
SqlDr.Close();
Response.Write("Schedule for " + ChannelName + " starting " + startDate.ToString("d") + " for " + numDays.ToString() + " days\n\n");
string sql = @"DECLARE @PrintSchedule TABLE (RunStart datetime, RunEnd dateTime, Length int, CGTitle varchar(255), Producer varchar(255))
INSERT @PrintSchedule SELECT ScheduleView.RunStart, ScheduleView.RunEnd, ScheduleView.Length, Shows.CGTitle, stLocationProducers.ProducerName
FROM ScheduleView
INNER JOIN Shows ON ScheduleView.ShowID = Shows.ShowID
LEFT OUTER JOIN stLocationProducers ON Shows.Producer = stLocationProducers.ID
WHERE ScheduleView.RunStart >= '" + startDate.ToString("g") + @"'
AND ScheduleView.RunStart <= '" + endDate.ToString("g") + @"'
AND (ScheduleView.ChannelID = " + ChannelID + @")
AND (ScheduleView.CGExempt <> 1)
AND (ScheduleView.Deleted = 0)
ORDER BY ScheduleView.RunStart
SELECT * FROM @PrintSchedule ORDER BY RunStart";
SqlCmd = new System.Data.SqlClient.SqlCommand(sql, SqlConn);
SqlDr = SqlCmd.ExecuteReader();
int Count = 0;
string LastRunDate = "";
while(SqlDr.Read())
{
// convert length to nice format
int inputSecs = Convert.ToInt32(SqlDr["Length"]);
int seconds = 0;
int minutes = 0;
int hours = 0;
string secondsStr = "";
if (inputSecs > 0)
{
seconds = inputSecs % 60;
inputSecs = inputSecs - seconds;
if (inputSecs > 0)
{
inputSecs = inputSecs / 60;
minutes = inputSecs % 60;
inputSecs = inputSecs - minutes;
if (inputSecs > 0)
{
inputSecs = inputSecs / 60;
hours = inputSecs;
}
}
if (hours < 10)
secondsStr = "0" + hours.ToString() + ":";
else
secondsStr = hours.ToString() + ":";
if (minutes < 10)
secondsStr += "0" + minutes.ToString() + ":";
else
secondsStr += minutes.ToString() + ":";
if (seconds < 10)
secondsStr += "0" + seconds.ToString();
else
secondsStr += seconds.ToString();
}
else
secondsStr = "00:00:00";
string Length = secondsStr;
DateTime RunDate = Convert.ToDateTime(SqlDr["RunStart"]);
DateTime RunEnd = Convert.ToDateTime(SqlDr["RunEnd"]);
string Title = SqlDr["CGTitle"].ToString();
if(RunDate.ToString(dateFormat) != LastRunDate)
Response.Write("\n" + RunDate.ToString(dateFormat) + "\n");
string TimeString = RunDate.ToString("t");
if((TimeString.Split(':'))[0].Length == 1)
TimeString = " " + TimeString;
Response.Write(TimeString + " - " + RunEnd.ToString("t") + "\t" + Length + "\t" + Title + "\t" + SqlDr["Producer"] + "\n");
LastRunDate = RunDate.ToString(dateFormat);
Count++;
}
SqlDr.Close();
if(Count == 0)
Response.Write("There is no schedule information.");
}
catch(System.Threading.ThreadAbortException){}
catch(Exception ex)
{
Response.Write("Error: " + ex.ToString() + "<br>");
}
finally
{
// make sure the things get closed
//close data reader
if(SqlDr != null)
{
if(SqlDr.IsClosed == false)
SqlDr.Close();
}
// close database connection
if(SqlConn != null)
{
if(SqlConn.State != System.Data.ConnectionState.Closed)
SqlConn.Close();
}
}
%>
</pre>
</span>
</body>
</html>