Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public class SweepstakesSubmission
- {
- public int Id;
- private string _FirstName;
- public string FirstName
- {
- get
- {
- return _FirstName;
- }
- set
- {
- if (String.IsNullOrEmpty(value))
- throw new Exception("You must supply your first and last name");
- else
- _FirstName = value;
- }
- }
- private string _LastName;
- public string LastName
- {
- get
- {
- return _LastName;
- }
- set
- {
- if (String.IsNullOrEmpty(value))
- throw new Exception("You must supply your first and last name");
- else
- _LastName = value;
- }
- }
- private string _Email;
- public string Email
- {
- get { return _Email; }
- set
- {
- try
- {
- System.Net.Mail.MailAddress Address = new System.Net.Mail.MailAddress(value);
- _Email = value;
- }
- catch { throw new Exception("The email address supplied appears to be invalid."); }
- }
- }
- private string _ZipCode;
- public string ZipCode
- {
- get { return _ZipCode; }
- set
- {
- if ((String.IsNullOrEmpty(value)) || (value.Length < 4))
- throw new Exception("Please enter your Zip Code");
- else
- _ZipCode = value;
- }
- }
- public void Record()
- {
- try
- {
- SqlConnection objConnection = new SqlConnection();
- objConnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Sweepstakes"].ConnectionString;
- objConnection.Open();
- SqlCommand objCommand = new SqlCommand(
- "INSERT INTO " + ConfigurationManager.AppSettings["SweepstakesSubmission_DbName"] + " (FirstName, LastName, Email, ZipCode, UserAgent, IpAddress, TimeStamp) VALUES (@FirstName,@LastName,@Email,@ZipCode,@UserAgent,@IpAddress,GetDate());",
- objConnection);
- objCommand.Parameters.AddWithValue("@FirstName", this.FirstName);
- objCommand.Parameters.AddWithValue("@LastName", this.LastName);
- objCommand.Parameters.AddWithValue("@Email", this.Email);
- objCommand.Parameters.AddWithValue("@ZipCode", this.ZipCode);
- objCommand.Parameters.AddWithValue("@UserAgent", HttpContext.Current.Request.ServerVariables["http_user_agent"].ToString());
- objCommand.Parameters.AddWithValue("@IpAddress", HttpContext.Current.Request.ServerVariables["remote_addr"].ToString());
- if (!(objCommand.ExecuteNonQuery() == 1))
- throw new Exception();
- objCommand = null;
- objConnection.Close();
- objConnection = null;
- }
- catch (Exception Ex) { throw new Exception("The record could not be recorded to the database."); }
- }
- }
Add Comment
Please, Sign In to add comment