You are on page 1of 9

REGISTER.ASPX.

CS
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;

using System.Xml.Linq;

public partial class Services_NewCustomer :


System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void SubmitButton_Click(object sender,
EventArgs e)
{
try
{
//retrieve customer name from session object
Session["CustomerName"] = NameTextBox.Text;

//connection string for locating database


SqlConnection con = new SqlConnection("Data
Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Smart\\Docu
ments\\Visual Studio 2008\\WebSites\\Online Gas
Service\\App_Data\\OGS.mdf;Integrated Security=True;User
Instance=True");

//sql query
SqlCommand cmd = new SqlCommand("insert into
Customer values(' " + CustomerIdTextBox.Text + "','" +
PasswordTextBox.Text + "','" + NameTextBox.Text + "','" +
DateTextBox.Text +
"','" + SexTextBox.Text + "','" +
DOBTextBox.Text + "','" + AddressTextBox.Text + "'," +
PhoneTextBox.Text + ",'" + EmailTextBox.Text + "')");
//creating connection object con
cmd.Connection = con;

//opening Database connection


con.Open();

int rows = cmd.ExecuteNonQuery();

//redirecting to contratulation page after


successful registration

Response.Redirect("~/Services/frmRegOut.aspx",false);
}
catch (Exception ex)
{
//redirecting any error catched by try-catche
block
Session["Error"] = ex.Message;
Response.Redirect("~/frmError.aspx",false);
}

}
HOME.ASPX.CS

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;
using System.Data.Sql;

public partial class Home : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
TimestampLabel.Text = DateTime.Now.ToString();
//to display the current date and time.

protected void LoginButton_Click(object sender,


EventArgs e)
{

try
{
Session["UserId"] = UserIdTextBox.Text;

//creating SqlConection Object con


SqlConnection con = new
System.Data.SqlClient.SqlConnection();
DataSet ds1 = new DataSet();

//connecting Database using data source


connectionString
con.ConnectionString = "Data
Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\Smart\\Docu
ments\\Visual Studio 2008\\WebSites\\Online Gas
Service\\App_Data\\OGS.mdf;Integrated Security=True;User
Instance=True";

//opening Database connection


con.Open();

string sql = "SELECT * from Customer WHERE


(Customer_Id=' "+UserIdTextBox.Text+"' and
Customer_Pwd='"+PasswordTextBox.Text+"')";

//SqlDataAdapter make bridge between database


and temp data storage user using datafill
SqlDataAdapter da = new
System.Data.SqlClient.SqlDataAdapter(sql, con);

//storing rows in temp variable user


da.Fill(ds1, "user");

int status = ds1.Tables["user"].Rows.Count;

if (status == 1)
{
DataRow drow = ds1.Tables["user"].Rows[0];
//session for retrieving customer
information
Session["CustomerInfo"] = drow;

//redirecting the user to main Customer


window for performing different operation after successfully
login

Response.Redirect("~/Services/MainCustomer.aspx", false);
}
else
{
// display the error for wrong password or
user id
InvalidLoginLabel.Text = "User Id or
Password do not match";
}
}
catch (Exception ex)
{
//redirecting the exception error catched by
try-catche block
Session["Error"] = ex.Message;
Response.Redirect("~/frmError.aspx", false);

}
}
}

You might also like