You are on page 1of 19

Code:

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


AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login"
Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cn1" Runat="Server">


<br />
<br />
<br />
<br />
<br />
<br />
<br />
<center>
<asp:Label ID="Label1" runat="server" Text="Login Page"></asp:Label>
<table border="2">
<tr>
<td>
<asp:Label ID="lblusername" runat="server"
Text="Username"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtusername" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblpassword" runat="server"
Text="Password"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtpassword" runat="server"
TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblpassword0" runat="server"
Text="Role"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server"
Height="16px" Width="124px">
<asp:ListItem>HOD</asp:ListItem>
<asp:ListItem>Staff</asp:ListItem>
<asp:ListItem>Student</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnlogin" runat="server" OnClick="btnlogin_Click"
Text="Log In" />
</td>
</tr>
</table>
</center>

</asp:Content>

Imports System.Data.SqlClient

Partial Class Login


Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim con As New SqlConnection("server=.;database=trans;integrated
security=true;uid=sa;")
con.Open()
Dim cmd As New SqlCommand("select uname,pwd from login where
uname='" & TextBox1.Text & "' and pwd='" & TextBox2.Text & "'", con)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader
If dr.Read Then
Response.Redirect("administrator.aspx")
End If
con.Close()

End Sub
End Class
Imports System.Data
Imports System.Data.SqlClient
Partial Class student
Inherits System.Web.UI.Page
Dim con As New SqlConnection("Data Source=.\sqlexpress;Initial
Catalog=ayyappa;Integrated Security=True")

Public conn As New SqlConnection


Public rs As SqlDataReader
Public sql As String
Public qry As String
Dim image As String
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim da As SqlDataAdapter
Dim ds As DataSet
Public Function opendb() As Object
conn = New SqlConnection("Data Source=.\sqlexpress;Initial
Catalog=ayyappa;Integrated Security=True")

If conn.State = 1 Then conn.Close()


conn.Open()
Return 0
End Function
Sub loadcat()
sql = "select * from tbl_category"
Dim cmd As New SqlCommand
cmd = New SqlCommand(sql, conn)
rs = cmd.ExecuteReader()

drpcategory.Items.Clear()
While rs.Read()
drpcategory.Items.Add(rs(1).ToString())
' rs.MoveNext()
End While

End Sub
Sub loadid()
conn.Close()
conn.Open()
Dim i As Integer
sql = "select max(p_id) from tbl_student"
Dim cmd As New SqlCommand
cmd = New SqlCommand(sql, conn)
rs = cmd.ExecuteReader()
If rs.Read() Then
Try

i = Convert.ToInt32(rs(0).ToString())
Catch ex As Exception
i=0

End Try
i=i+1
txtid.Text = i

Else
i=1
txtid.Text = i
End If

End Sub
Sub clear()
drpcategory.SelectedIndex = 0
txtdepartment.Text = ""
txtcolor.Text = ""
txtdesc.Text = ""
txtamount.Text = ""
txtquan.Text = ""
txtid.Text = ""
End Sub
Sub loadgrid()

qry = "select p_id as STUDENT_ID,p_cat as CATEGORY,p_department as


DEPARTMENT,p_color AS COLOUR,p_desc AS DESCRIPTION,p_amount as
AMOUNT,p_quantity as QUANTITY,p_image as IMAGE from tbl_student"
da = New SqlDataAdapter(qry, con)
ds = New DataSet
da.Fill(ds, "tbl_student")
GridView1.DataSource = ds
GridView1.DataMember = ds.Tables(0).ToString
GridView1.DataBind()

End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
opendb()
If Session("usertype") = "Admin" Then
loadcat()
loadid()
loadgrid()
Else
Response.Redirect("frmviewstudents.aspx")
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles Button1.Click
image = FileUpload1.FileName
FileUpload1.SaveAs(Server.MapPath("~") + "/images/" & image)
If FileUpload1.HasFile Then
Try
' a_pic.ImageUrl = FileUpload1.PostedFile.FileName
a_pic.ImageUrl = "~/images/" & image
Catch ex As Exception

End Try
End If
End Sub

Protected Sub btnadd_Click(ByVal sender As Object, ByVal e As


System.EventArgs) Handles btnadd.Click
conn.Close()
conn.Open()

image = a_pic.ImageUrl
sql = "insert into
tbl_student(p_id,p_cat,p_department,p_color,p_desc,p_amount,p_quantity,p_imag
e)"
sql = sql & "values('" & txtid.Text & "','" & drpcategory.Text & "','" &
txtdepartment.Text & "','" & txtcolor.Text & "','" & txtdesc.Text & "','" &
txtamount.Text & "','" & txtquan.Text & "','" & image & "')"
Dim cmd As New SqlCommand
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
'conn.Execute(sql)
Label.Text = "student added"
clear()
loadid()
loadgrid()
End Sub
End Class

You might also like