0% found this document useful (0 votes)
18 views40 pages

Problemsheet-2: Register - Aspx

The document outlines the development of an ASP.NET website for an Automobile EMI Management System, featuring user login and registration functionalities. It includes code snippets for registration and login pages, as well as a report page for displaying loan information based on CarLoanID. The system utilizes a SQL database for user authentication and loan management.

Uploaded by

singhsamridhi813
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views40 pages

Problemsheet-2: Register - Aspx

The document outlines the development of an ASP.NET website for an Automobile EMI Management System, featuring user login and registration functionalities. It includes code snippets for registration and login pages, as well as a report page for displaying loan information based on CarLoanID. The system utilizes a SQL database for user authentication and loan management.

Uploaded by

singhsamridhi813
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Problemsheet-2

Q.1: - Develop website in ASP.NET Website for “Automobile EMI (Equated monthly
Instalments) Management System” with following functionality along with login
according to the user. (Validate all thefields) Use Following tables:
1. Login (Login name, password)
2. CarLoan (CarLoanID,CarName,Customername,Address,City, EmailID,
Installment_of_EMI,EMI_Years, Rate_Interest_loan) Provide following facilities:
1. Provide Login facility; sign up (Registration) facility.
2. Display Report according to CarLoanID.

Register.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs"


Inherits="AutomobileEmiManagementSystem.Register" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Register</title>

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link href="Content\bootstrap.css" rel="stylesheet" />
<style> .regForm { width:40%; margin: 100px auto;
}
</style>
</head>
<body>
<form id="form1" class="regForm form p-3 border rounded bg-warning bgopacity-50"
runat="server">

<div>
<h2>Registration</h2>
<asp:TextBox ID="txtNewLogin" CssClass="form-control" runat="server"
placeholder="Username" Required="true" /> <br />
<asp:TextBox ID="txtNewPassword" CssClass="form-control" runat="server"
placeholder="Password" TextMode="Password" Required="true" /> <br /> <asp:TextBox
ID="txtPhone" CssClass="form-control" runat="server" placeholder="Phone No" Required="true" />
<br />
<asp:TextBox ID="txtDOB" CssClass="form-control" runat="server" placeholder="DOB(YYYY-MM-
DD)" Required="true" /> <br />

<asp:Button ID="btnRegister" runat="server" CssClass="btn btn-primary"


Text="Register" OnClick="btnRegister_Click" /> <br />
<asp:Label ID="lblMessage" runat="server"
ForeColor="Green"></asp:Label>
<br />
<a href="login.aspx"><asp:Label text="Already User? Login!"
runat="server" ></asp:Label></a>
</div>
</form>
</body>

1
2302020101417
Problemsheet-2
</html>

Register.aspx.
cs:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs"


Inherits="AutomobileEmiManagementSystem.Register" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Register</title>

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link href="Content\bootstrap.css" rel="stylesheet" />
<style> .regForm
{ width:40%;
margin: 100px auto;
}
</style>
</head>
<body>
<form id="form1" class="regForm form p-3 border rounded bg-warning bgopacity-50"
runat="server">
<div>
<h2>Registration</h2>
<asp:TextBox ID="txtNewLogin" CssClass="form-control" runat="server"
placeholder="Username" Required="true" /> <br />
<asp:TextBox ID="txtNewPassword" CssClass="form-control" runat="server"
placeholder="Password" TextMode="Password" Required="true" /> <br /> <asp:TextBox
ID="txtPhone" CssClass="form-control" runat="server" placeholder="Phone No" Required="true" />
<br />
<asp:TextBox ID="txtDOB" CssClass="form-control" runat="server" placeholder="DOB(YYYY-MM-
DD)" Required="true" /> <br />

<asp:Button ID="btnRegister" runat="server" CssClass="btn btn-primary"


Text="Register" OnClick="btnRegister_Click" /> <br />
<asp:Label ID="lblMessage" runat="server"
ForeColor="Green"></asp:Label>
<br />
<a href="login.aspx"><asp:Label text="Already User? Login!"
runat="server" ></asp:Label></a>
</div>
</form>
</body>
</html>

login.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs"


Inherits="AutomobileEmiManagementSystem.login" %>

2
2302020101417
Problemsheet-2
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login - Automobile EMI System</title>
<!-- FontAwesome Icons -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link href="Content\bootstrap.css" rel="stylesheet" />
<style>
body {
font-family: Arial; background-color:
#f5f5f5;
}
.login-container { width:
300px; margin: 100px auto;
background: white;
padding: 20px; border-
radius: 10px;
box-shadow: 2px 2px 10px rgba(0,0,0,0.2);
}
.input-icon
{ position: relative;
}
.input-icon i
{ position: absolute;
top: 2px; left: 2px;
color: #888;
}
.input-icon input { padding-
left: 40px; width: 100%;
margin-bottom: 15px;
}
.btn-login { width: 100%;
background-color: #007bff; color:
white; padding: 10px;
border: none; border-radius: 5px;
font-size: 16px;
}
.btn-login i { margin-right:
5px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="login-container">
<h2 style="text-align:center;">Login</h2>

<div class="input-icon">
<i class="fas fa-user bg-danger text-white border rounded p-2 "></i> <asp:TextBox
ID="txtLogin" CssClass="form-control" runat="server" placeholder="Username"></asp:TextBox>
</div>

3
2302020101417
Problemsheet-2
<div class="input-icon">
<i class="fas fa-lock bg-danger text-white border rounded p-2 "></i> <asp:TextBox
ID="txtPassword" CssClass="form-control" runat="server"
TextMode="Password" placeholder="Password"></asp:TextBox>
</div>

<asp:Button ID="btnLogin" runat="server" Text=" Login" CssClass="btnlogin"


OnClick="btnLogin_Click" />
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label> <br />
<a href="Register.aspx"><asp:Label Text="New?,Register Here! " runat="server" /><i class="fa
fa-user-pen"></i> </a>

</div>
</form>
</body>
</html>
login.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs"


Inherits="AutomobileEmiManagementSystem.login" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login - Automobile EMI System</title>
<!-- FontAwesome Icons -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link href="Content\bootstrap.css" rel="stylesheet" />
<style> body {
font-family: Arial; background-color: #f5f5f5;
}
.login-container { width: 300px; margin: 100px auto; background: white;
padding: 20px; border-radius: 10px;
box-shadow: 2px 2px 10px rgba(0,0,0,0.2);
}
.input-icon { position: relative;
}
.input-icon i { position: absolute; top: 2px; left: 2px; color: #888;
}
.input-icon input { padding-left: 40px; width: 100%; margin-bottom: 15px;
}
.btn-login { width: 100%; background-color: #007bff; color: white;
padding: 10px; border: none; border-radius: 5px; font-size: 16px;
}
.btn-login i { margin-right: 5px;
}
</style>
</head>

4
2302020101417
Problemsheet-2
<body>
<form id="form1" runat="server">
<div class="login-container">
<h2 style="text-align:center;">Login</h2>

<div class="input-icon">
<i class="fas fa-user bg-danger text-white border rounded p-2 "></i> <asp:TextBox
ID="txtLogin" CssClass="form-control" runat="server" placeholder="Username"></asp:TextBox>
</div>

<div class="input-icon">
<i class="fas fa-lock bg-danger text-white border rounded p-2 "></i> <asp:TextBox
ID="txtPassword" CssClass="form-control" runat="server"
TextMode="Password" placeholder="Password"></asp:TextBox>
</div>

<asp:Button ID="btnLogin" runat="server" Text=" Login" CssClass="btnlogin"


OnClick="btnLogin_Click" />
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label> <br />
<a href="Register.aspx"><asp:Label Text="New?,Register Here! " runat="server" /><i class="fa
fa-user-pen"></i> </a>

</div>
</form>
</body>
</html>

login.aspx.cs:

using System;
using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

namespace AutomobileEmiManagementSystem
{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\AutomobileEmi
ManagementSystem\\App_Data\\automobile_info_db.mdf;Integrated Security=True");
SqlCommand cmd = new SqlCommand("SELECT * FROM Login WHERE LoginName=@login
AND Password=@pass", con);

5
2302020101417
Problemsheet-2
cmd.Parameters.AddWithValue("@login", txtLogin.Text);
cmd.Parameters.AddWithValue("@pass", txtPassword.Text); con.Open();
SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read())
{
Session["User"] = txtLogin.Text;
Response.Redirect("Dashboard.aspx");
} else {
lblMessage.Text = "Invalid credentials!";
}
con.Close();
}

}
}
Report.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs"


Inherits="AutomobileEmiManagementSystem.Report" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Loan Report - Automobile EMI System</title>
<!-- FontAwesome Icons -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link href="Content\bootstrap.css" rel="stylesheet" />
<style> body {
font-family: Arial; background-color: #f0f2f5;
}
.report-container { width: 70%; margin-top: 100px ; margin-left: 280px ;
background: white; padding: 20px; border-radius: 10px;
box-shadow: 2px 2px 10px rgba(0,0,0,0.2);

}
.btn-search {
background-color: #17a2b8; color: white; padding: 8px 15px; border:
none; border-radius: 5px; font-size: 16px;
}
.btn-search i { margin-right: 5px;
}
.gridview-style { width: 100%;
border-collapse: collapse;
}
.gridview-style th, .gridview-style td { padding: 10px; border: 1px solid #ddd;
text-align: center;
}

6
2302020101417
Problemsheet-2
.gridview-style th { background-color: #007bff; color: white; }
.icon-text { display: flex; align-items: center; justify-content: center;
}
.icon-text i { margin-right: 5px; color: #007bff;
}

.sidebar { width: 220px; height: 100vh; background-color: #343a40;


color: white; position: fixed; top: 0; left: 0; padding-top: 20px;
} .sidebar a { display: block; color: white; padding: 15px 20px; text-
decoration: none; font-size: 18px;
}
.sidebar a:hover {
background-color: #495057;
}
.sidebar i {
margin-right: 10px;
}
.main-content { margin-left: 230px; padding: 20px;
}
</style>
</head>
<body>
<form id="form1" runat="server">

<div class="sidebar">
<h2 style="text-align:center;">EMI System</h2>
<a href="Dashboard.aspx"><i class="fas fa-plus-circle"></i>Add Loan</a>
<a href="Report.aspx"><i class="fas fa-file-alt"></i>View Report</a>
<a href="login.aspx"><i class="fas fa-sign-out-alt"></i>Logout</a>
</div>

<div class="report-container ">


<h2 style="text-align:center;">Loan Report</h2>

<div style="text-align:center; margin-bottom:20px;">


<asp:TextBox ID="txtCarLoanID" CssClass="border rounded p-2" runat="server"
placeholder="Enter CarLoan ID"></asp:TextBox> <asp:Button ID="btnSearch" runat="server"
Text=" Search"
CssClass="btn-search" OnClick="btnSearch_Click" />
</div>

<asp:GridView ID="gvReport" runat="server" AutoGenerateColumns="False"


CssClass="gridview-style">
<Columns>
<asp:BoundField DataField="CarLoanID" HeaderText="Loan ID" />
<asp:TemplateField HeaderText="Car Name">
<ItemTemplate>

7
2302020101417
Problemsheet-2
<div class="icon-text">
<i class="fas fa-car"></i>
<%# Eval("CarName") %>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer">
<ItemTemplate>
<div class="icon-text">
<i class="fas fa-user"></i>
<%# Eval("CustomerName") %>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<div class="icon-text">
<i class="fas fa-city"></i>
<%# Eval("City") %>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EMI Installment">
<ItemTemplate>
<div class="icon-text">
<i class="fas fa-rupee-sign"></i>
<%# Eval("Installment_of_EMI") %>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EMI Years">
<ItemTemplate>
<div class="icon-text">
<i class="fas fa-calendar-alt"></i>
<%# Eval("EMI_Years") %> years
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Rate of Interest">
<ItemTemplate>
<div class="icon-text">
<i class="fas fa-percent"></i>
<%# Eval("Rate_Interest_Loan") %> %
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

8
2302020101417
Problemsheet-2

<asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label>


</div>
</form>
</body>
</html>

Report.aspx.cs:

using System;
using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using
System.Linq; using System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

namespace AutomobileEmiManagementSystem
{
public partial class Report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSearch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\AutomobileEmi
ManagementSystem\\App_Data\\automobile_info_db.mdf;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM CarLoan WHERE CarLoanID=@id",
con);
da.SelectCommand.Parameters.AddWithValue("@id", txtCarLoanID.Text); DataTable dt =
new DataTable();
da.Fill(dt); gvReport.DataSource = dt; gvReport.DataBind();
}

}
}

Dashboard.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Dashboard.aspx.cs"


Inherits="AutomobileEmiManagementSystem.Dashboard" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Add Car Loan - Automobile EMI System</title>

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css" />

9
2302020101417
Problemsheet-2
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link href="Content\bootstrap.css" rel="stylesheet" />

<style> body {
font-family: Arial; background-color: #eef2f7;
}
.dashboard-container { width: 400px; margin: 50px auto; background: white;
padding: 25px; border-radius: 10px;
box-shadow: 2px 2px 12px rgba(0,0,0,0.2);
}
.input-icon { position: relative; margin-bottom: 15px;
}
.input-icon i { position: absolute; top:2px; left: 2px; color: #888;
}
.input-icon input { padding-left: 40px; width: 100%; }
.btn-submit { width: 100%; background-color: #28a745; color: white;
padding: 10px; border: none; border-radius: 5px; font-size: 16px;
}
.btn-submit i { margin-right: 5px;
}

.sidebar { width: 220px; height: 100vh; background-color: #343a40;


color: white; position: fixed; top: 0; left: 0; padding-top: 20px;
}
.sidebar a { display: block; color: white; padding: 15px 20px; text-
decoration: none; font-size: 18px;
}
.sidebar a:hover {
background-color: #495057;
}
.sidebar i {
margin-right: 10px;
}
.main-content { margin-left: 230px; padding: 20px;
}
</style>
</head>
<body>
<form id="form1" runat="server">

<div class="sidebar">
<h2 style="text-align:center;">EMI System</h2>
<a href="Dashboard.aspx"><i class="fas fa-plus-circle"></i>Add Loan</a>
<a href="Report.aspx"><i class="fas fa-file-alt"></i>View Report</a>
<a href="login.aspx"><i class="fas fa-sign-out-alt"></i>Logout</a>
</div>

10
2302020101417
Problemsheet-2

<div class="main-content">

<div class="dashboard-container">
<h2 style="text-align:center;">Add Car Loan</h2>

<div class="input-icon">
<i class="fas fa-car bg-danger text-white border rounded p-2 "></i> <asp:TextBox
ID="txtCarName" CssClass="form-control" runat="server" placeholder="Car Name"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvCarName" runat="server"
ControlToValidate="txtCarName" ErrorMessage="Car Name Required!" ForeColor="Red"
Display="Dynamic" />

</div>

<div class="input-icon">
<i class="fas fa-user bg-danger text-white border rounded p-2 "></i>
<asp:TextBox ID="txtCustomerName" CssClass="form-control" runat="server"
placeholder="Customer Name"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtCustomerName" ErrorMessage="Customer Name
Required!" ForeColor="Red" Display="Dynamic" />
</div>

<div class="input-icon">
<i class="fas fa-map-marker-alt bg-danger text-white border rounded
p-2 "></i>
<asp:TextBox ID="txtAddress" CssClass="form-control" runat="server"
placeholder="Address"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtAddress" ErrorMessage="Address Required!"
ForeColor="Red" Display="Dynamic" />
</div>

<div class="input-icon">
<i class="fas fa-city bg-danger text-white border rounded p-2 "></i> <asp:TextBox
ID="txtCity" CssClass="form-control" runat="server" placeholder="City"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtCity" ErrorMessage="City Required!"
ForeColor="Red" Display="Dynamic" />
</div>

<div class="input-icon">
<i class="fas fa-envelope bg-danger text-white border rounded p-2 "></i>
<asp:TextBox ID="txtEmailID" CssClass="form-control" runat="server" placeholder="Email
ID"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtEmailID" ErrorMessage="Email Required!"
ForeColor="Red" Display="Dynamic" />

11
2302020101417
Problemsheet-2
</div>

<div class="input-icon">
<i class="fas fa-rupee-sign bg-danger text-white border rounded p-2 "></i>
<asp:TextBox ID="txtInstallment" CssClass="form-control" runat="server"
placeholder="Installment of EMI"></asp:TextBox> <asp:RequiredFieldValidator
ID="RequiredFieldValidator5"
runat="server" ControlToValidate="txtInstallment" ErrorMessage="Installment (Rs.)
Required!" ForeColor="Red" Display="Dynamic" />
</div>

<div class="input-icon">
<i class="fas fa-calendar-alt bg-danger text-white border rounded p-2 "></i>
<asp:TextBox ID="txtYears" CssClass="form-control" runat="server" placeholder="EMI
Years"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txtYears" ErrorMessage="Years Required!"
ForeColor="Red" Display="Dynamic" />
</div>

<div class="input-icon">
<i class="fas fa-percent bg-danger text-white border rounded p-2
"></i>
<asp:TextBox ID="txtRateInterest" CssClass="form-control" runat="server" placeholder="Rate
of Interest"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator7"
runat="server" ControlToValidate="txtRateInterest" ErrorMessage="Rate of Interest
Required!" ForeColor="Red" Display="Dynamic" />
</div>

<asp:Button ID="btnAddLoan" runat="server" Text="+ Add Loan"


CssClass="btn-submit" OnClick="btnAddLoan_Click" /> <br />

<asp:Label ID="lblMessage" runat="server" ForeColor="Green"></asp:Label>


</div>
</div>
</form>
</body>
</html>

Dashboard.aspx.cs:

using System;
using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using
System.Web; using System.Web.UI;
using System.Web.UI.WebControls;

namespace AutomobileEmiManagementSystem
{

12
2302020101417
Problemsheet-2
public partial class Dashboard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAddLoan_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\AutomobileEmi
ManagementSystem\\App_Data\\automobile_info_db.mdf;Integrated Security=True");
SqlCommand cmd = new SqlCommand("INSERT INTO CarLoan (CarName,
CustomerName, Address, City, EmailID, Installment_of_EMI, EMI_Years,
Rate_Interest_Loan) VALUES (@car, @cust, @addr, @city, @email, @emi, @years,
@rate)", con);
cmd.Parameters.AddWithValue("@car", txtCarName.Text);
cmd.Parameters.AddWithValue("@cust", txtCustomerName.Text);
cmd.Parameters.AddWithValue("@addr", txtAddress.Text);
cmd.Parameters.AddWithValue("@city", txtCity.Text);
cmd.Parameters.AddWithValue("@email", txtEmailID.Text);
cmd.Parameters.AddWithValue("@emi", txtInstallment.Text);
cmd.Parameters.AddWithValue("@years", txtYears.Text);
cmd.Parameters.AddWithValue("@rate", txtRateInterest.Text);

con.Open();

cmd.ExecuteNonQuery();

con.Close();
lblMessage.Text = "Loan added successfully!";
}

}
}

OUTPUT:

13
2302020101417
Problemsheet-2

14
2302020101417
Problemsheet-2

Q.2: Develop a website for online shopping using propervalidations


(Make proper Website in which you must give functionalities like
Registration, Login, Home, Product list category wise, Final Order list
ofUser, Log Out).

Code:
Register.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs"
Inherits="OnlineShoppingWebsite.Register" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Content\bootstrap.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css"/>

</head>
<body>
<form id="form1" class="form w-50 mt-5 mb-5 m-auto p-3 border rounded" runat="server">
<div>
<h2 class="text-danger text-center"><i class="bi bi-pen"></i>
Registration</h2>
<asp:RequiredFieldValidator ID="rfv1"
ControlToValidate="txtUsername" runat="server" ErrorMessage="Username is
required"></asp:RequiredFieldValidator>
<asp:TextBox ID="txtUsername" class="form-control" runat="server"
placeholder="Username"></asp:TextBox> <br />

15
2302020101417
Problemsheet-2
<asp:RequiredFieldValidator ID="rfv2"
ControlToValidate="txtUsername" runat="server" ErrorMessage="Username is
required"></asp:RequiredFieldValidator>
<asp:TextBox ID="txtPassword" class="form-control" runat="server" placeholder="Password"
TextMode="Password"></asp:TextBox> <br />

<asp:RequiredFieldValidator ID="rfv3"
ControlToValidate="txtUsername" runat="server" ErrorMessage="Username is
required"></asp:RequiredFieldValidator>
<asp:TextBox ID="txtEmail" class="form-control" runat="server"
placeholder="Email"></asp:TextBox><br />

<asp:Button ID="btnRegister" runat="server" class="btn btn-primary"


Text="Register" > </asp:Button> <br />
<asp:Label Text="text" ID="lblMessage" runat="server" />
<a href="Login.aspx" ><asp:Label Text="Already User? Login!"
ID="Label1" runat="server" /></a>
</div>
</form>
</body>
</html>

Register.aspx.

cs: using System;

using System.Collections.Generic;
using System.Configuration; using
System.Data.SqlClient; using
System.Linq; using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineShoppingWebsite
{
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnRegister_Click(object sender, EventArgs e)
{

SqlConnection conn = new SqlConnection("Data


Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\OnlineShoppin
gWebsite\\App_Data\\OnlineShoppingDb.mdf;Integrated Security=True");

SqlCommand cmd = new SqlCommand("INSERT INTO Users (Username, Password, Email)


VALUES (@Username, @Password, @Email)", conn);
cmd.Parameters.AddWithValue("@Username", txtUsername.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text); // Ideally hash passwords

16
2302020101417
Problemsheet-2
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
conn.Open(); cmd.ExecuteNonQuery(); conn.Close();
lblMessage.Text = "Registration successful!";

Login.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs"
Inherits="OnlineShoppingWebsite.Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Page</title>
<link href="Content\bootstrap.css" rel="stylesheet" /> <link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css"/>

</head>
<body>
<form id="form1" class="form mt-5 mb-5 m-auto p-3 w-50 border rounded" runat="server">
<div>

<h2 class="text-danger text-center"><i class="fa fauser"></i>Login</h2>


<asp:TextBox ID="txtUsername" class="form-control" runat="server"
placeholder="Username"></asp:TextBox> <br />
<asp:TextBox ID="txtPassword" class="form-control" runat="server" placeholder="Password"
TextMode="Password"></asp:TextBox> <br />

<asp:Button runat="server" class="btn btn-primary" Text="Login" ID="btnLogin"


></asp:Button> <br />
<asp:Label ID="lblMessage" runat="server" /> <br />

<a href="Register.aspx" ><asp:Label Text="New? Register Here!" runat="server"


/></a>

</div>
</form>
</body>
</html>

Login.aspx.cs:

17
2302020101417
Problemsheet-2
using System;
using System.Collections.Generic;
using System.Configuration; using
System.Data.SqlClient; using
System.Linq; using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineShoppingWebsite
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnLogin_Click(object sender, EventArgs e)
{
if (!IsPostBack)
{

SqlConnection con = new SqlConnection("Data


Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\OnlineShoppin
gWebsite\\App_Data\\OnlineShoppingDb.mdf;Integrated Security=True"); SqlCommand
cmd = new SqlCommand("SELECT * FROM Users WHERE Username = @Username AND Password =
@Password", con);
cmd.Parameters.AddWithValue("@Username", txtUsername.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text); con.Open();

SqlDataReader dr = cmd.ExecuteReader(); if
(dr.Read())
{
Session["UserID"] = dr["UserID"].ToString();
Session["Username"] = dr["Username"].ToString();

Response.Redirect("Home.aspx");
}
else {
lblMessage.Text = "Invalid username or password!";
}
con.Close();
}
}

}
}
Home.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs"
Inherits="OnlineShoppingWebsite.Home" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

18
2302020101417
Problemsheet-2
<title></title>
<link href="Content\bootstrap.css" rel="stylesheet" /> <link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-
[email protected]/font/bootstrap-icons.css"/>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/6.5.0/css/all.min.css"/>
<style>
.contentDiv
{ width:100%;
background-image:url('Img/shoppingImg1.jpg'); background-
position:center; background-size:cover; background-
repeat:no-repeat;

}
.welcometxt { font-size:80px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="container-fluid bg-light">
<div class="row p-3 text-center">
<div class="col-4 border-end">
<h3>Online Shopping Website</h3>
</div>
<div class="col-2"><a href="Home.aspx" class="btn btnoutline-danger"><i class="fa fa-
home"></i> HOME</a></div>
<div class="col-2"><a href="ProductList.aspx" class="btn"><i class="fa fa-bag-
shopping"></i> PRODUCTS</a></div>
<div class="col-2"><a href="OrderList"class="btn"><i class="fa fa-truck-ramp-box"></i>
ORDER</a></div>
<div class="col-2"><a href="OrderList" class="btn"><i class="fa fa-cart-shopping"></i>
CART</a></div>
</div>
</div>

<div style="height:90vh;" class="contentDiv container-fluid d-flex justify-content-center align-


items-center " runat="server">

<h1 class="welcometxt text-white fw-bold ">

Welcome <%=Session["Username"] %> to the <br />


Online Shopping Website

</h1>

</div>

</div>
</form>
</body>
</html>

Home.aspx.cs:

19
2302020101417
Problemsheet-2
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineShoppingWebsite
{
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

ProductList.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductList.aspx.cs"
Inherits="OnlineShoppingWebsite.Products" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Content\bootstrap.css" rel="stylesheet" /> <link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-
icons.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/6.5.0/css/all.min.css"/>

</head>
<body>
<form id="form1" runat="server">
<div>

<div class="container-fluid bg-light">


<div class="row p-3 text-center">
<div class="col-4 border-end">
<h3>Online Shopping Website</h3>
</div>
<div class="col-2"><a href="Home.aspx" class="btn"><i class="fa fahome"></i>
HOME</a></div>

20
2302020101417
Problemsheet-2
<div class="col-2"><a href="ProductList.aspx" class="btn btnoutline-danger "><i class="fa
fa-bag-shopping"></i> PRODUCTS</a></div> <div class="col-2"><a
href="OrderList"class="btn"><i class="fa fatruck-ramp-box"></i> ORDER</a></div>
<div class="col-2"><a href="OrderList" class="btn"><i class="fa facart-shopping"></i>
CART</a></div>
</div>
</div>

<div style="height:90vh;" class="container-fluid bg-warning bg-opacity-25 text-center pt-5"


runat="server">

<div class="border p-3 rounded bg-white" >


<asp:DropDownList ID="ddlCategory" runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="ddlCategory_SelectedIndexChan
ged" CssClass="btn btnprimary"></asp:DropDownList>

<asp:GridView ID="gvProducts" runat="server"


AutoGenerateColumns="False" OnRowCommand="gvProducts_RowCommand" CssClass="mt-3
table table-bordered"> <Columns>
<asp:BoundField DataField="ProductName"
HeaderText="Product Name" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:ButtonField Text="Order" CommandName="OrderNow"
ButtonType="Button" />
</Columns>
</asp:GridView>

</div>
</div>

</div>
</form>
</body>
</html>

ProductList.as
px.cs:
using System;
using System.Collections.Generic;
using System.Configuration; using
System.Data.SqlClient; using
System.Data; using System.Linq;
using System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineShoppingWebsite
{
public partial class Products : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

21
2302020101417
Problemsheet-2
{
if (!IsPostBack)
{
LoadCategories();
}
}
private void LoadCategories()
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\OnlineShoppin
gWebsite\\App_Data\\OnlineShoppingDb.mdf;Integrated Security=True"); con.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM
Categories", con);
DataTable dt = new DataTable(); da.Fill(dt);
ddlCategory.DataSource = dt;
ddlCategory.DataTextField = "CategoryName"; ddlCategory.DataValueField =
"CategoryID"; ddlCategory.DataBind();
}

protected void ddlCategory_SelectedIndexChanged(object sender,


EventArgs e)
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\OnlineShoppin
gWebsite\\App_Data\\OnlineShoppingDb.mdf;Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Products WHERE CategoryID =
@CategoryID", con);
da.SelectCommand.Parameters.AddWithValue("@CategoryID",
ddlCategory.SelectedValue);
DataTable dt = new DataTable(); da.Fill(dt);
gvProducts.DataSource = dt; gvProducts.DataBind();

protected void gvProducts_RowCommand(object sender,


GridViewCommandEventArgs e)
{
if (e.CommandName == "OrderNow")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvProducts.Rows[index]; string productName =
row.Cells[0].Text;

SqlConnection con = new SqlConnection("Data


Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\OnlineShoppin
gWebsite\\App_Data\\OnlineShoppingDb.mdf;Integrated Security=True"); con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO Orders
(UserID, ProductID) VALUES (@UserID, (SELECT ProductID FROM Products WHERE
ProductName=@ProductName))", con);
cmd.Parameters.AddWithValue("@UserID", Session["UserID"]);
cmd.Parameters.AddWithValue("@ProductName", productName);
cmd.ExecuteNonQuery(); con.Close();

Response.Write("<script>alert('Product Ordered
Successfully');</script>");
}

22
2302020101417
Problemsheet-2
}

OrderList.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OrderList.aspx.cs"
Inherits="OnlineShoppingWebsite.OrderList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Content\bootstrap.css" rel="stylesheet" /> <link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-
icons.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-
awesome/6.5.0/css/all.min.css"/>
</head>
<body>
<form id="form1" runat="server">
<div>

<div class="container-fluid bg-light">


<div class="row p-3 text-center">
<div class="col-4 border-end">
<h3>Online Shopping Website</h3>
</div>
<div class="col-2"><a href="Home.aspx" class="btn"><i class="fa fahome"></i> HOME</a></div>
<div class="col-2"><a href="ProductList.aspx" class="btn "><i class="fa fa-bag-shopping"></i>
PRODUCTS</a></div>
<div class="col-2"><a href="OrderList"class="btn btn-outline-danger"><i class="fa fa-truck-
ramp-box"></i> ORDER</a></div>
<div class="col-2"><a href="OrderList" class="btn"><i class="fa fa-cartshopping"></i>
CART</a></div>
</div>
</div>

<div style="height:90vh;" class="container-fluid bg-primary bg-opacity-25 pt-5" runat="server">

<asp:GridView ID="gvOrders" runat="server" CssClass=" table table-bordered table-


striped"></asp:GridView>

</div>

23
2302020101417
Problemsheet-2
</div>
</form>
</body>
</html>

OrderList.asp
x.cs:
using System;
using System.Collections.Generic;
using System.Configuration; using
System.Data.SqlClient; using
System.Data; using System.Linq;
using System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineShoppingWebsite
{
public partial class OrderList : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)


{
if (!IsPostBack)
{
LoadOrders();
}

}
private void LoadOrders()
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\OnlineShoppin
gWebsite\\App_Data\\OnlineShoppingDb.mdf;Integrated Security=True"); SqlDataAdapter da
= new SqlDataAdapter("SELECT Products.ProductName,
Orders.OrderDate FROM Orders INNER JOIN Products ON Orders.ProductID =
Products.ProductID WHERE Orders.UserID=@UserID", con);

da.SelectCommand.Parameters.AddWithValue("@UserID", 1);
DataTable dt = new DataTable();
da.Fill(dt); gvOrders.DataSource = dt;
gvOrders.DataBind();
}
}
OUTPUT:

24
2302020101417
Problemsheet-2

25
2302020101417
Problemsheet-2

Q.3: Develop a web application which maintains books in libraryBook-


issue Table (Book_issue_no , Roll_no, Book_no, Issus_date,

26
2302020101417
Problemsheet-2
Return_date) Perform insert, delete and update operations
onBook_issue. Display list of students who must return book today.

Code:
BookIssue.as
px:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BookIssue.aspx.cs"
Inherits="LibraryManagementSystem.BookIssue" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Content\bootstrap.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<h1 class="mt-3 text-danger text-center">Library Management
System</h1>
<div class="mx-5 mt-2 p-3 border rounded">
<asp:TextBox ID="txtIssueNo" CssClass="form-control w-50 m-2" runat="server"
Placeholder="Issue No" />
<asp:TextBox ID="txtRollNo" CssClass="form-control w-50 m-2" runat="server"
Placeholder="Roll No" />
<asp:TextBox ID="txtBookNo" CssClass="form-control w-50 m-2" runat="server"
Placeholder="Book No" />
<asp:TextBox ID="txtIssueDate" CssClass="form-control w-50 m-2" runat="server"
Placeholder="Issue Date" />
<asp:TextBox ID="txtReturnDate" CssClass="form-control w-50 m-2" runat="server"
Placeholder="Return Date" />
<asp:Button ID="btnInsert" CssClass="btn btn-success" runat="server" Text="Insert"
OnClick="btnInsert_Click" />
<asp:Button ID="btnUpdate" CssClass="btn btn-warning" runat="server" Text="Update"
OnClick="btnUpdate_Click" />
<asp:Button ID="btnDelete" CssClass="btn btn-danger" runat="server" Text="Delete"
OnClick="btnDelete_Click" />
<asp:Button ID="btnDueToday" CssClass="btn btn-primary" runat="server"
Text="Due Today" OnClick="btnDueToday_Click" /> <asp:Button ID="btnShowList"
CssClass="btn btn-info" runat="server" Text="Show List" OnClick="btnShowList_Click" />

<asp:Label Text="" ID="lblMsg" runat="server" />


<asp:GridView ID="gvBookIssues" runat="server"
AutoGenerateColumns="true" CssClass="table table-bordered table-striped m-4" />
<asp:GridView ID="gvDueToday" runat="server"
AutoGenerateColumns="true" CssClass="table table-bordered table-striped-columns m-4" />
</div>

</div>
</form>

27
2302020101417
Problemsheet-2
</body>
</html>

BookIssue.as
px.cs:
using System;
using System.Collections.Generic;
using System.Configuration; using
System.Data.SqlClient; using
System.Data; using System.Linq;
using System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

namespace LibraryManagementSystem
{
public partial class BookIssue : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

string connStr =
ConfigurationManager.ConnectionStrings["LibraryDB"].ConnectionString;

protected void btnInsert_Click(object sender, EventArgs e)


{
SqlConnection conn = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\LibraryManage
mentSystem\\App_Data\\LibraryDB.mdf;Integrated Security=True");
string query = "INSERT INTO Book_issue VALUES (@IssueNo, @RollNo,
@BookNo, @IssueDate, @ReturnDate)";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@IssueNo", txtIssueNo.Text);
cmd.Parameters.AddWithValue("@RollNo", txtRollNo.Text);
cmd.Parameters.AddWithValue("@BookNo", txtBookNo.Text);
cmd.Parameters.AddWithValue("@IssueDate", txtIssueDate.Text);
cmd.Parameters.AddWithValue("@ReturnDate", txtReturnDate.Text);

conn.Open();

cmd.ExecuteNonQuery();
lblMsg.Text = "Inserted Successfully!";

}
protected void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\LibraryManage
mentSystem\\App_Data\\LibraryDB.mdf;Integrated Security=True");

string query = "UPDATE Book_issue SET Roll_no=@RollNo,


Book_no=@BookNo, Issue_date=@IssueDate, Return_date=@ReturnDate WHERE
Book_issue_no=@IssueNo";

28
2302020101417
Problemsheet-2
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@IssueNo", txtIssueNo.Text);
cmd.Parameters.AddWithValue("@RollNo", txtRollNo.Text);
cmd.Parameters.AddWithValue("@BookNo", txtBookNo.Text);
cmd.Parameters.AddWithValue("@IssueDate", txtIssueDate.Text);
cmd.Parameters.AddWithValue("@ReturnDate", txtReturnDate.Text);

conn.Open(); cmd.ExecuteNonQuery();
lblMsg.Text = "Updated Successfully!";

}
protected void btnDelete_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\LibraryManage
mentSystem\\App_Data\\LibraryDB.mdf;Integrated Security=True");

string query = "DELETE FROM Book_issue WHERE


Book_issue_no=@IssueNo";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@IssueNo", txtIssueNo.Text);

conn.Open(); cmd.ExecuteNonQuery();
lblMsg.Text = "Deleted Successfully!";

}
protected void btnDueToday_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\LibraryManage
mentSystem\\App_Data\\LibraryDB.mdf;Integrated Security=True");

string query = "SELECT * FROM Book_issue WHERE Return_date =


CAST(GETDATE() AS DATE)";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable(); da.Fill(dt);
gvDueToday.DataSource = dt; gvDueToday.DataBind();

}
protected void btnShowList_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\LibraryManage
mentSystem\\App_Data\\LibraryDB.mdf;Integrated Security=True");

string query = "SELECT * FROM Book_issue";


SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataTable dt = new DataTable(); da.Fill(dt);
gvBookIssues.DataSource = dt; gvBookIssues.DataBind();

29
2302020101417
Problemsheet-2

OUTPUT:

30
2302020101417
Problemsheet-2

31
2302020101417
Problemsheet-2
Q.4: Develop a website for online Shaadi.com using proper validations
in which you must implement Login, Registration web page.
(Implement six different validations)
NOTE: IMPLEMENT MASTER PAGE AND MAINTAIN USER’S STATE
ALSO, APPLY VALIDATION.

CODE:

MasterPage.Master:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs"
Inherits="shadidotcom.MasterPage" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Shaadi.com - Find Your Match</title>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="Content\bootstrap.css" rel="stylesheet" />

</head>
<body>
<form id="form2" runat="server">
<div class="container-fluid">
<!-- Header -->
<div class="bg-danger text-white p-3 text-center">
<h1>Shaadi.com</h1>
<p>Find Your Perfect Match</p>
</div>

<!-- Navigation -->


<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="Home.aspx">Home</a>
<div class="collapse navbar-collapse">
<ul class="navbar-nav me-auto">
<li class="nav-item"> <a
class="nav-link" href="Register.aspx">Register</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Login.aspx">Login</a>
</li>
<li class="nav-item">
<asp:LinkButton ID="btnLogout" runat="server"
CssClass="nav-link text-danger" OnClick="BtnLogout_Click"
Visible="false">Logout</asp:LinkButton>
</li>
</ul>
<span class="navbar-text text-success">
<asp:Label ID="lblUser" runat="server" />

32
2302020101417
Problemsheet-2
</span>
</div>
</div>
</nav>

<!-- Page Content -->


<asp:ContentPlaceHolder ID="MainContentHolder" runat="server" />
<!-- Footer -->
<footer class="bg-dark text-white text-center p-3 mt-4">
&copy; 2025 Shaadi.com. All rights reserved.
</footer>
</div>
</form>

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js
"></script>
</body>
</html>

MasterPage.Master.cs:
using System;
using System.Collections.Generic;
using System.Linq; using
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

namespace shadidotcom
{
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)

{
if (Session["Username"] != null)
{
lblUser.Text = "Welcome, " + Session["Username"].ToString(); btnLogout.Visible =
true;
}
else {
lblUser.Text = ""; btnLogout.Visible = false;
}

}
protected void BtnLogout_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("Login.aspx");
}

33
2302020101417
Problemsheet-2

Register.aspx:
<%@ Page Title="Register" MasterPageFile="~/MasterPage.master" Language="C#"
AutoEventWireup="true" CodeBehind="Register.aspx.cs"
Inherits="shadidotcom.Register" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">


<div class="container mt-4">
<h2 class="text-center text-danger">Register</h2>
<div class="col-md-6 mx-auto">
<asp:TextBox ID="txtUsername" CssClass="form-control my-2" runat="server"
Placeholder="Username"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="txtUsername"
ErrorMessage="Username is required" ForeColor="Red" runat="server" />
<asp:TextBox ID="txtEmail" CssClass="form-control my-2" runat="server"
Placeholder="Email"></asp:TextBox>
<asp:RegularExpressionValidator ControlToValidate="txtEmail"
ErrorMessage="Invalid email!" ForeColor="Red" ValidationExpression="^[a-zA-Z09._%+-]+@[a-zA-
Z0-9.-]+\.[a-zA-Z]{2,}$" runat="server" />
<asp:CustomValidator ID="cvEmail" runat="server"
ControlToValidate="txtEmail" OnServerValidate="CvEmail_ServerValidate"
ErrorMessage="Email already exists" ForeColor="Red" />

<asp:TextBox ID="txtPassword" CssClass="form-control my-2" runat="server"


TextMode="Password" Placeholder="Password"></asp:TextBox> <asp:RequiredFieldValidator
ControlToValidate="txtPassword"
ErrorMessage="Password is required" ForeColor="Red" runat="server" />

<asp:TextBox ID="txtConfirmPassword" CssClass="form-control my-2" runat="server"


TextMode="Password" Placeholder="Confirm Password"></asp:TextBox>
<asp:CompareValidator ControlToCompare="txtPassword"
ControlToValidate="txtConfirmPassword" ErrorMessage="Passwords do not match"
ForeColor="Red" runat="server" />

<asp:TextBox ID="txtAge" CssClass="form-control my-2" runat="server"


Placeholder="Age"></asp:TextBox>
<asp:RangeValidator ControlToValidate="txtAge" MinimumValue="18"
MaximumValue="70" Type="Integer" ErrorMessage="Age must be between 18 and 70"
ForeColor="Red" runat="server" />

<asp:ValidationSummary CssClass="text-danger" runat="server" /> <asp:Button


ID="btnRegister" CssClass="btn btn-danger w-100 mt-3" runat="server" Text="Register"
OnClick="BtnRegister_Click" />
</div>
</div>
</asp:Content>

Register.aspx.cs:
using System;

34
2302020101417
Problemsheet-2
using System.Collections.Generic;
using System.Configuration; using
System.Data.SqlClient; using
System.Drawing; using
System.Linq; using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace shadidotcom
{
public partial class Register : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)


{

protected void BtnRegister_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\shadidotcom\\
App_Data\\shaadiDB.mdf;Integrated Security=True");

con.Open();
string checkUser = "SELECT COUNT(*) FROM Users WHERE Email=@Email"; using
(SqlCommand checkCmd = new SqlCommand(checkUser, con))
{
checkCmd.Parameters.AddWithValue("@Email", txtEmail.Text);

int exists = (int)checkCmd.ExecuteScalar(); if (exists > 0)


{
cvEmail.IsValid = false; return;
}
}

string query = "INSERT INTO Users (Username, Email, Password, Age)


VALUES (@Username, @Email, @Password, @Age)";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@Username", txtUsername.Text);
cmd.Parameters.AddWithValue("@Email", txtEmail.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@Age", txtAge.Text);

cmd.ExecuteNonQuery();
Response.Redirect("Login.aspx");

}
protected void CvEmail_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\shadidotcom\\
App_Data\\shaadiDB.mdf;Integrated Security=True");

35
2302020101417
Problemsheet-2
con.Open();
string query = "SELECT COUNT(*) FROM Users WHERE Email=@Email";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@Email", args.Value); int count =
(int)cmd.ExecuteScalar(); args.IsValid = count == 0;

}
}

Login.aspx:
<%@ Page Title="Login" MasterPageFile="~/MasterPage.master" Language="C#"
AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="shadidotcom.Login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
<div class="container mt-4">
<h2 class="text-center text-primary">Login</h2>
<div class="col-md-6 mx-auto">

<asp:TextBox ID="txtUsername" CssClass="form-control my-2" runat="server"


Placeholder="Username"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="txtUsername"
ErrorMessage="Username is required" ForeColor="Red" runat="server" />
<asp:TextBox ID="txtPassword" CssClass="form-control my-2" runat="server"
TextMode="Password" Placeholder="Password"></asp:TextBox> <asp:RequiredFieldValidator
ControlToValidate="txtPassword"
ErrorMessage="Password is required" ForeColor="Red" runat="server" />

<asp:ValidationSummary CssClass="text-danger" runat="server" /> <asp:Button


ID="btnLogin" CssClass="btn btn-primary w-100 mt-3"
runat="server" Text="Login" OnClick="BtnLogin_Click" />
</div>
</div>
</asp:Co
ntent>

Login.aspx.cs:
using System;
using System.Collections.Generic;
using System.Configuration; using
System.Data.SqlClient; using
System.Linq; using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace shadidotcom
{

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


{

36
2302020101417
Problemsheet-2
protected void Page_Load(object sender, EventArgs e)
{

}
protected void BtnLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data
Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\DotNetProjects\\shadidotcom\\
App_Data\\shaadiDB.mdf;Integrated Security=True");

con.Open();
string query = "SELECT Username FROM Users WHERE
Username=@Username AND Password=@Password";
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@Username", txtUsername.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);

object result = cmd.ExecuteScalar(); if


(result != null)
{
Session["Username"] = result.ToString();
Response.Redirect("Home.aspx");
}
else
{
Response.Write("<script>alert('Invalid credentials!');</script>");
}
}
}
}

Home.aspx:

<%@ Page Title="Home" MasterPageFile="~/MasterPage.master" Language="C#"


AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="shadidotcom.Home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">

<div class="mainDiv p-5 text-white" style="height:50vh; backgroundimage:linear-


gradient(red,orange,red,white);" runat="server">
<h2 style="font-size:80px; margin:50px auto;" >Welcome to
Shaadi.com</h2>
<asp:Label Text="" ID="lblUser" runat="server" />
</div>
</asp:Content>

Home.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq; using

37
2302020101417
Problemsheet-2
System.Web; using
System.Web.UI;
using System.Web.UI.WebControls;

namespace shadidotcom
{
public partial class Home : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)


{
if (Session["Username"] != null)
lblUser.Text = "Hello, " + Session["Username"]; else
Response.Redirect("Login.aspx");
}

}
}

OUTPUT:

38
2302020101417
Problemsheet-2

Welcome t0 Shaadi.com

Welcome t0 Shaadi.com

39
2302020101417
Problemsheet-2

40
2302020101417

You might also like