Code Behind Page Page /Admin/Newsletter.aspx.cs (C#)
Used by Page /Admin/Newsletter.aspx (C#)
1: using System;  
2: using System.Data;  
3: using System.Data.SqlClient;  
4: using System.Web.UI.WebControls;  
5: using QuizNetOnline.Logic;  
6: using QuiznetOnline.Web.UI.BusinessClasses;  
7: using QuiznetOnline.Data;  
8: using Microsoft.ApplicationBlocks.Data;  
9:   
10: namespace QuiznetOnline.Web.UI.Admin  
11: {  
12:     public partial class Newsletter : System.Web.UI.Page  
13:     {  
14:         public string Tblout = "";  
15:   
16:         protected void Page_Load(object sender, EventArgs e)  
17:         {  
18:             if (!Page.IsPostBack)  
19:             {  
20:                 if ((Session["Validated"] == null || (bool)Session["Validated"] == false) && FormOperations.IsWebServerLocalHost(Request.Url.ToString()) == false)  
21:                 {  
22:                     Response.Redirect("Default.aspx");  
23:                 }  
24:   
25:                 PopulateNewsletterDdl();  
26:             }  
27:         }  
28:   
29:         public void PopulateNewsletterDdl()  
30:         {  
31:             ddlNewsletter.DataSource = SqlDataSource1;  
32:             ddlNewsletter.DataTextField = "Name";  
33:             ddlNewsletter.DataValueField = "NewsletterID";  
34:             ddlNewsletter.DataBind();  
35:   
36:             ddlNewsletter.Items.Insert(0,new ListItem("New Newsletter", "NEW"));  
37:         }  
38:   
39:         protected void cmdShowSQL_Click(object sender, EventArgs e)  
40:         {  
41:             BuildSqLtable(txtUserSQLscript.Text);  
42:         }  
43:   
44:         private void BuildSqLtable(string sql)  
45:         {  
46:             DataFunctions dataFunctions = DataFunctions.GetInstance();  
47:             SqlConnection sqlconnection = new SqlConnection(dataFunctions.GetConnectionString());  
48:             sqlconnection.Open();  
49:   
50:             try  
51:             {  
52:                 DataTable tbl = SqlHelper.ExecuteDataset(sqlconnection, CommandType.Text, sql).Tables[0];  
53:                 tblSQLresults.DataSource = tbl;  
54:                 tblSQLresults.DataBind();  
55:             }  
56:             catch (Exception ex)  
57:             {  
58:                 lblError.Text = ex.Message;  
59:             }                  
60:         }  
61:   
62:         protected void cmdSave_Click(object sender, EventArgs e)  
63:         {  
64:             DataFunctions dataFunctions = DataFunctions.GetInstance();  
65:             SqlConnection sqlconnection = new SqlConnection(dataFunctions.GetConnectionString());  
66:             sqlconnection.Open();  
67:   
68:   
69:             using (SqlCommand cmd = new SqlCommand())  
70:             {  
71:                 SaveNewsletter(sqlconnection, cmd);  
72:             }  
73:         }  
74:   
75:         public void SaveNewsletter(SqlConnection sqlconnection, SqlCommand cmd)  
76:         {  
77:             int newsletterID=0;  
78:             cmd.Connection = sqlconnection;  
79:             cmd.CommandType = CommandType.StoredProcedure;  
80:   
81:             if (ddlNewsletter.SelectedValue == "NEW")  
82:             {  
83:                 cmd.CommandText = "CreateNewsletter";  
84:             }  
85:             else  
86:             {  
87:                 cmd.CommandText = "UpdateNewsletter";  
88:                 cmd.Parameters.Add(new SqlParameter("@NewsletterID", ddlNewsletter.SelectedValue));  
89:                 newsletterID = Convert.ToInt32(ddlNewsletter.SelectedValue);  
90:             }  
91:   
92:   
93:             cmd.Parameters.Add(new SqlParameter("@Name",txtName.Text));  
94:             cmd.Parameters.Add(new SqlParameter("@AuthorName",txtAuthorName.Text));  
95:             cmd.Parameters.Add(new SqlParameter("@EmailSubject",txtEmailSubject.Text));  
96:             cmd.Parameters.Add(new SqlParameter("@EmailBody",txtEmailBody.Text));  
97:             cmd.Parameters.Add(new SqlParameter("@IsActive",chkIsActive.Checked));  
98:             cmd.Parameters.Add(new SqlParameter("@UserSQLscript",txtUserSQLscript.Text));  
99:   
100:             int newnewsletterID=Convert.ToInt32(cmd.ExecuteScalar());  
101:   
102:             if (ddlNewsletter.SelectedValue == "NEW")  
103:             {  
104:                 newsletterID = newnewsletterID;  
105:             }  
106:   
107:             SaveNewsletterEmail(sqlconnection,newsletterID);  
108:   
109:             if (ddlNewsletter.SelectedValue == "NEW")  
110:             {  
111:                 ClearForm();  
112:                 PopulateNewsletterDdl();  
113:             }  
114:         }  
115:   
116:         public void SaveNewsletterEmail(SqlConnection sqlconnection,int newsLetterID)  
117:         {  
118:   
119:             using (SqlCommand cmd1 = new SqlCommand())  
120:             {  
121:   
122:                 cmd1.Connection = sqlconnection;  
123:                 cmd1.CommandType = CommandType.StoredProcedure;  
124:                 cmd1.CommandText = "DeleteNewsletterEmail";  
125:                 cmd1.Parameters.Add(new SqlParameter("@NewsletterID", newsLetterID));  
126:   
127:                 cmd1.ExecuteNonQuery();  
128:             }  
129:   
130:             foreach (TableRow row in tblSQLresults.Rows)  
131:             {  
132:                 foreach (TableCell cell in row.Cells)  
133:                 {  
134:                     using (SqlCommand cmd2 = new SqlCommand())  
135:                     {  
136:   
137:                         cmd2.Connection = sqlconnection;  
138:                         cmd2.CommandType = CommandType.StoredProcedure;  
139:                         cmd2.CommandText = "CreateNewsletterEmail";  
140:                         cmd2.Parameters.Add(new SqlParameter("@NewsletterID", newsLetterID));  
141:                         cmd2.Parameters.Add(new SqlParameter("@Email", cell.Text));  
142:   
143:                         Convert.ToInt32(cmd2.ExecuteNonQuery());  
144:                     }  
145:                 }                          
146:             }  
147:         }  
148:   
149:         protected void ddlNewsletter_SelectedIndexChanged(object sender, EventArgs e)  
150:         {  
151: There is a limit of 150 source code lines in the evaluation version
152: There is a limit of 150 source code lines in the evaluation version
153: There is a limit of 150 source code lines in the evaluation version
154: There is a limit of 150 source code lines in the evaluation version
155: There is a limit of 150 source code lines in the evaluation version
156: There is a limit of 150 source code lines in the evaluation version
157: There is a limit of 150 source code lines in the evaluation version
158: There is a limit of 150 source code lines in the evaluation version
159: There is a limit of 150 source code lines in the evaluation version
160: There is a limit of 150 source code lines in the evaluation version
161: There is a limit of 150 source code lines in the evaluation version
162: There is a limit of 150 source code lines in the evaluation version
163: There is a limit of 150 source code lines in the evaluation version
164: There is a limit of 150 source code lines in the evaluation version
165: There is a limit of 150 source code lines in the evaluation version
166: There is a limit of 150 source code lines in the evaluation version
167: There is a limit of 150 source code lines in the evaluation version
168: There is a limit of 150 source code lines in the evaluation version
169: There is a limit of 150 source code lines in the evaluation version
170: There is a limit of 150 source code lines in the evaluation version
171: There is a limit of 150 source code lines in the evaluation version
172: There is a limit of 150 source code lines in the evaluation version
173: There is a limit of 150 source code lines in the evaluation version
174: There is a limit of 150 source code lines in the evaluation version
175: There is a limit of 150 source code lines in the evaluation version
176: There is a limit of 150 source code lines in the evaluation version
177: There is a limit of 150 source code lines in the evaluation version
178: There is a limit of 150 source code lines in the evaluation version
179: There is a limit of 150 source code lines in the evaluation version
180: There is a limit of 150 source code lines in the evaluation version
181: There is a limit of 150 source code lines in the evaluation version
182: There is a limit of 150 source code lines in the evaluation version
183: There is a limit of 150 source code lines in the evaluation version
184: There is a limit of 150 source code lines in the evaluation version
185: There is a limit of 150 source code lines in the evaluation version
186: There is a limit of 150 source code lines in the evaluation version
187: There is a limit of 150 source code lines in the evaluation version
188: There is a limit of 150 source code lines in the evaluation version
189: There is a limit of 150 source code lines in the evaluation version
190: There is a limit of 150 source code lines in the evaluation version
191: There is a limit of 150 source code lines in the evaluation version
192: There is a limit of 150 source code lines in the evaluation version
193: There is a limit of 150 source code lines in the evaluation version
194: There is a limit of 150 source code lines in the evaluation version
195: There is a limit of 150 source code lines in the evaluation version
196: There is a limit of 150 source code lines in the evaluation version
197: There is a limit of 150 source code lines in the evaluation version
198: There is a limit of 150 source code lines in the evaluation version
199: There is a limit of 150 source code lines in the evaluation version
200: There is a limit of 150 source code lines in the evaluation version
201: There is a limit of 150 source code lines in the evaluation version
202: There is a limit of 150 source code lines in the evaluation version
203: There is a limit of 150 source code lines in the evaluation version
204: There is a limit of 150 source code lines in the evaluation version
205: There is a limit of 150 source code lines in the evaluation version
206: There is a limit of 150 source code lines in the evaluation version
207: There is a limit of 150 source code lines in the evaluation version
208: There is a limit of 150 source code lines in the evaluation version
209: There is a limit of 150 source code lines in the evaluation version
210: There is a limit of 150 source code lines in the evaluation version
211: There is a limit of 150 source code lines in the evaluation version
212: There is a limit of 150 source code lines in the evaluation version
213: There is a limit of 150 source code lines in the evaluation version
214: There is a limit of 150 source code lines in the evaluation version
215: There is a limit of 150 source code lines in the evaluation version
216: There is a limit of 150 source code lines in the evaluation version
217: There is a limit of 150 source code lines in the evaluation version
218: There is a limit of 150 source code lines in the evaluation version
219: There is a limit of 150 source code lines in the evaluation version
220: There is a limit of 150 source code lines in the evaluation version
221: There is a limit of 150 source code lines in the evaluation version
222: There is a limit of 150 source code lines in the evaluation version
223: There is a limit of 150 source code lines in the evaluation version
224: There is a limit of 150 source code lines in the evaluation version
225: There is a limit of 150 source code lines in the evaluation version
226: There is a limit of 150 source code lines in the evaluation version
227: There is a limit of 150 source code lines in the evaluation version
228: There is a limit of 150 source code lines in the evaluation version
229: There is a limit of 150 source code lines in the evaluation version
230: There is a limit of 150 source code lines in the evaluation version
231: There is a limit of 150 source code lines in the evaluation version
232: There is a limit of 150 source code lines in the evaluation version
233: There is a limit of 150 source code lines in the evaluation version
234: There is a limit of 150 source code lines in the evaluation version
235: There is a limit of 150 source code lines in the evaluation version
236: There is a limit of 150 source code lines in the evaluation version
237: There is a limit of 150 source code lines in the evaluation version
238: There is a limit of 150 source code lines in the evaluation version

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.