/
Admin.MakeNotification.aspx.cs
109 lines (84 loc) · 3.49 KB
/
Admin.MakeNotification.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
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Configuration;
public partial class Admin_MakeNotification : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtText.Style.Add("margin", "0px 0px 0px 24px");
txtHeader.Style.Add("width", "500px");
txtText.Style.Add("width", "500px");
txtText.Style.Add("height", "300px");
}
protected void btnSend_Click(object sender, EventArgs e)
{
ArrayList users = new ArrayList();
DateTime date = DateTime.Now;
try
{
SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString); // connection string is in web config
SqlCommand query = new SqlCommand();
sc.Open();
query.Connection = sc;
query.CommandText = "Select EmailAddress From " + ddlUser.SelectedValue.ToString();// Gathers all users of specific type
SqlDataReader read = query.ExecuteReader();
while (read.Read())
{
users.Add(read.GetString(0));
}
for (int i = 0; i < users.Count; i++)
{
query.CommandText = "Insert into Notifications(EmailAddress, NotificationType, NotificationDate, NotificationText, BriefDescription)" +
" Values(@Email, Announcement, @Date, @Text, @Brief)";
query.Parameters.AddWithValue("@Email", users[i]);
query.Parameters.AddWithValue("@Date", date);
query.Parameters.AddWithValue("@Text", txtText.Text);
query.Parameters.AddWithValue("@Brief", txtHeader.Text);
query.ExecuteNonQuery();
}
sc.Close();
}
catch (SqlException SQLe)
{
System.Diagnostics.Debug.Write(SQLe.ToString());
}
}
protected void btnSendEmail_Click(object sender, EventArgs e)
{
ArrayList users = new ArrayList();
DateTime startDate = DateTime.Now;
DateTime endDate = DateTime.Now.AddDays(14);
ArrayList events = new ArrayList();
Debug.WriteLine(DateTime.Now);
Debug.WriteLine(DateTime.Now.AddDays(14));
try
{
SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString); // connection string is in web config
SqlCommand query = new SqlCommand();
sc.Open();
query.Connection = sc;
query.CommandText = "Select EmailAddress From " + ddlUser.SelectedValue.ToString();// Gathers all users of specific type
SqlDataReader read = query.ExecuteReader();
while (read.Read())
{
users.Add(read.GetString(0));
}
query.CommandText = "select * from WBLEvent where EventDateTime between '" +
startDate + "' and '" + endDate + "' Order by EventType;";
read = query.ExecuteReader();
sc.Close();
}
catch (SqlException SQLe)
{
System.Diagnostics.Debug.Write(SQLe.ToString());
}
}
}