0% found this document useful (0 votes)
79 views15 pages

Documentof Tpo

The document describes student registration and semester details submission functionality. It includes classes to handle database connections and functions, student registration page code to insert registration details into the database, and student semester page code to insert semester details by looking up the student id from the registration details. Database connection and CRUD operations are abstracted into classes to be reused across pages.

Uploaded by

Ankit Raj
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views15 pages

Documentof Tpo

The document describes student registration and semester details submission functionality. It includes classes to handle database connections and functions, student registration page code to insert registration details into the database, and student semester page code to insert semester details by looking up the student id from the registration details. Database connection and CRUD operations are abstracted into classes to be reused across pages.

Uploaded by

Ankit Raj
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

Student Registration

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


{
Connection.ClsDBCon objclsDBcon = new Connection.ClsDBCon();
Tpofunctions objTpofunctions = new Tpofunctions();
protected void Page_Load(object sender, EventArgs e)
{
Fillddlbranch();
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = "select count(*) from StudentDetails where username= '" +
txtusername.Text + "'";//Query to Check Availability of User Name in data base;
bool value = objTpofunctions.res(str);//Function to Check Availability of User Name in
data base;
if (value==true)
{
lblmsg.Text = txtusername.Text + " UserName Not Available. Plz try for another
username then register";
txtusername.Text="";
}
else
{
string query = "insert into
StudentDetails(branchid,EnrollmentNumber,yearOfEntry,DOB,FatherName,PermanentAddress,
LocaAddress,ContactNumber,studentName,emailid,username,password,IsActive,HighSchoolPer
cent,HigherSecondryPercent) values('" + Convert.ToInt32(ddlbranch.SelectedValue) + "','" +
txtroll.Text + "','" + txtye.Text + "','" + txtxdob.Text + "','" + txtfathername.Text + "','" +
txtpadd.Text + "','" + txtladd.Text + "','" + txtcontact.Text + "','" + txtname.Text + "','" +
txtemail.Text + "','" + txtusername.Text + "','" + txtpassword.Text + "','" + false + "','" +
txthighsm.Text + "','" + txthigher.Text + "')";
bool result = objTpofunctions.InsertMethod(query);
if (result ==true )
{
lblmsg.Text = "You are registered";
}
else
{
lblmsg.Text = "Registration Failed";
}
}
}
public void Fillddlbranch()
{
string str = "select branchname,branchid from branch";
SqlCommand cmd=new SqlCommand(str);
objclsDBcon.FillDropDownList(ddlbranch, "branchname","branchid",cmd);
}
}
===============ClsDbcon Class===================
using System.Data.SqlClient;
namespace Connection
{
public class ClsDBCon
{
public static SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["Conn"]);
public static SqlConnection GetConnection()
{
try
{
conn.Open();
}
catch (Exception ex)
{
throw ex;
}
return conn;
}
SqlConnection sqlConnection = new
SqlConnection(ConfigurationSettings.AppSettings["Conn"]);
public bool OpenConnection()
{
bool result = false;
try
{
if (sqlConnection.State == ConnectionState.Open)
{
sqlConnection.Close();
}
sqlConnection.Open();
result = true;
}
catch (Exception ex)
{
throw ex;
}
return result;
}
public bool CloseConnection()
{
bool result = false;
try
{
if (sqlConnection.State == ConnectionState.Open)
{
sqlConnection.Close();
}
result = true;
}
catch (Exception ex)
{
throw ex;
}
return result;
}
public DataSet RetrieveRecords(DataSet dataSet, SqlCommand sqlCommand)
{
try
{
sqlCommand.Connection = sqlConnection;
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
if (OpenConnection())
{
sqlDataAdapter.Fill(dataSet);
return dataSet;
}
else
{
return null;
}
}
catch (Exception ex)
{
throw ex;

}
finally
{
CloseConnection();
}
}
public DataTable GetData(DataTable dt, SqlCommand sqlCommand)
{
try
{
sqlCommand.Connection = sqlConnection;

if (OpenConnection())
{
SqlDataReader dr = sqlCommand.ExecuteReader();
dt.Load(dr);
return dt;
}
else
{
return null;
}
}
catch (Exception ex)
{
throw ex;

}
finally
{
CloseConnection();
}
}
public bool ExecuteNonQuerries(SqlCommand sqlCommand)
{
bool result = false;
try
{
sqlCommand.Connection = sqlConnection;
if (OpenConnection())
{
int noOfRecordsAffected = 0;
noOfRecordsAffected = sqlCommand.ExecuteNonQuery();
if (noOfRecordsAffected == 0)
{
result = false;
}
else
{
result = true;
}
}
else
{
result = false;
}
}
catch (Exception ex)
{
result = false;
throw ex;
}
finally
{
CloseConnection();
}
return result;
}
public object ExecuteScaler(SqlCommand sqlCommand)
{
object data = null;
try
{
sqlCommand.Connection = sqlConnection;
if (OpenConnection())
data = sqlCommand.ExecuteScalar();
}
catch (Exception ex)
{
throw ex;
}
finally
{
CloseConnection();
}
return data;
}
public bool FillGridView(GridView gv, SqlCommand sqlCommand)
{
bool result = false;
try
{
DataSet dataSet = new DataSet();
RetrieveRecords(dataSet, sqlCommand);
gv.DataSource = dataSet;
gv.DataBind();
result = true;
}

catch (Exception ex)


{
result = false;
throw ex;
}
return result;

}
public bool FillDropDownList(DropDownList ddl, string textField, string valueField,
SqlCommand sqlCommand)
{
bool result = false;
try
{
DataSet dataSet = new DataSet();
RetrieveRecords(dataSet, sqlCommand);
ddl.DataSource = dataSet;
ddl.DataTextField = textField;
ddl.DataValueField = valueField;
ddl.DataBind();
result = true;
}

catch (Exception ex)


{
result = false;
throw ex;

}
return result;
} }}
====================TpoFunction Class======================
using System.Data.SqlClient;
/// <summary>
/// Summary description for Tpofunctions
/// </summary>

public class Tpofunctions


{
Connection.ClsDBCon clsDBCon = new Connection.ClsDBCon();

public bool Registration(string insertQuery)


{
SqlCommand cmd = new SqlCommand(insertQuery);
bool result = clsDBCon.ExecuteNonQuerries(cmd);
return result;
}
public bool res(string str)
{
bool result;
//clsDBCon.OpenConnection();
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand(str);
ds = clsDBCon.RetrieveRecords(ds,cmd);
if (Convert.ToInt16(ds.Tables[0].Rows[0][0].ToString()) > 0)
{
result = true;
}
else
{
result = false;
}
return result;
}
public bool InsertMethod(string Query)
{
SqlCommand cmd = new SqlCommand(Query);
bool result = clsDBCon.ExecuteNonQuerries(cmd);
return result;
}
}
Student Semester Details

using System.Data.SqlClient;
public partial class StrudentSemester : System.Web.UI.Page
{
Connection.ClsDBCon objclsDBcon = new Connection.ClsDBCon();
Tpofunctions objTpofunctions = new Tpofunctions();
protected void Page_Load(object sender, EventArgs e)
{
FillddlSem();
}

protected void Button1_Click(object sender, EventArgs e)


{
//To Find the student records from student table
string QueryToFetchStudentId = "select studentid from studentdetails where
EnrollmentNumber='" + txtstudentenroll.Text + "' and
studentName='"+txtStudentName.Text+"'";
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand(QueryToFetchStudentId);
ds = objclsDBcon.RetrieveRecords(ds,cmd);
int studentid = Convert.ToInt16(ds.Tables[0].Rows[0][0]);
//To submit records
bool flag;
if (chkisclear.Checked)
{
flag = true;
}
else
{
flag = false;
}
string queryinsert = "insert into student_semester values('" +
Convert.ToString(studentid) + "','" + ddlsem.SelectedValue + "','" + txttYearOfSem.Text +
"','" + flag+ "','" + txtAggrigatePercent.Text + "')";
bool result = objTpofunctions.InsertMethod(queryinsert);
if (result == true)
{
lblsms.Text=("Your Records are submitted");
}
else
{
lblsms.Text = ("Your Records are not submitted");
}
}
public void FillddlSem()
{
string str = "select semid from semester";
SqlCommand cmd = new SqlCommand(str);
objclsDBcon.FillDropDownList(ddlsem, "semid", "semid", cmd);
}
}
==============Connection Class======================
public DataSet RetrieveRecords(DataSet dataSet, SqlCommand sqlCommand)
{;
try
{
sqlCommand.Connection = sqlConnection;
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
if (OpenConnection())
{
sqlDataAdapter.Fill(dataSet);
return dataSet;
}
else
{
return null;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
CloseConnection();
}
}
public bool FillDropDownList(DropDownList ddl, string textField, string valueField,
SqlCommand sqlCommand)
{
bool result = false;
try
{
DataSet dataSet = new DataSet();
RetrieveRecords(dataSet, sqlCommand);
ddl.DataSource = dataSet;
ddl.DataTextField = textField;
ddl.DataValueField = valueField;
ddl.DataBind();
result = true;
}
catch (Exception ex)
{
result = false;
throw ex;
}
return result;
}
===========TpoFunction Class==============
public bool InsertMethod(string Query)
{
SqlCommand cmd = new SqlCommand(Query);
bool result = clsDBCon.ExecuteNonQuerries(cmd);
return result;
}
Company Detail Entry

using System.Data.SqlClient;
public partial class company : System.Web.UI.Page
{
Connection.ClsDBCon objClsDBCon = new Connection.ClsDBCon();
Tpofunctions objTpofunctions = new Tpofunctions();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewAllCompanyName();
}
}
void ViewAllCompanyName()
{
SqlCommand cmd = new SqlCommand("Select
CompanyName,Address,Website,Email1,Email2 from Company");
DataSet ds = new DataSet();
ds = objClsDBCon.RetrieveRecords(ds, cmd);
if (ds.Tables[0].Rows.Count != 0)
{
GVCompany.DataSource = ds;
GVCompany.DataBind();
}
else
{
lblMsg.Text = "There is not any company in your record.Please add New Companies
in your Contact";
}
}
protected void butsubmit_Click(object sender, EventArgs e)
{
string query = "insert into Company values('" + txtCompName.Text + "','" +
txtaddress.Text + "','" + txtwebsite.Text + "','" + txtemail1.Text + "','" + txtemail2.Text +
"')";
bool result = objTpofunctions.InsertMethod(query);
ViewAllCompanyName();
}
protected void BtnGetAllComp_Click(object sender, EventArgs e)
{
ViewAllCompanyName();
}
}
==============Student can view his/her records=============

using System.Data.SqlClient;
public partial class ViewStudentRecords : System.Web.UI.Page
{
Connection.ClsDBCon objClsDBCon = new Connection.ClsDBCon();
Tpofunctions objTpofunctions = new Tpofunctions();
int studentid;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSearch_Click(object sender, EventArgs e)
{
//Code to find student Id
string QueryToFetchStudentId = "select studentid from StudentDetails where
EnrollmentNumber='" + txtEnrolment.Text + "' and IsApproved='"+false+"'";
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand(QueryToFetchStudentId);
ds=objClsDBCon.RetrieveRecords(ds, cmd);
if (ds.Tables[0].Rows.Count > 0)
{
lblMsg.Text = "";
studentid = Convert.ToInt16(ds.Tables[0].Rows[0][0]);
FillGrid();
}
else
{
lblMsg.Text = "There is no records of this enrollment";
}
}
protected void GVStudentAcademicRecords_RowEditing(object sender,
GridViewEditEventArgs e)
{
GVStudentAcademicRecords.EditIndex = e.NewEditIndex;
GetStudentId();
FillGrid();
}
public void FillGrid()
{
DataSet dsfillgrid = new DataSet();
string queryToFetchRecords = "select
StudentDetails.studentName,StudentDetails.HighSchoolPercent,StudentDetails.HigherSecondr
yPercent,student_semester.semid,student_semester.Year_of_sem,student_semester.sem_res
ult_total_percent from StudentDetails,student_semester where StudentDetails.studentid=" +
studentid + " and student_semester.Studentid=" + studentid + "";
SqlCommand cmdfillgrid = new SqlCommand(queryToFetchRecords);
dsfillgrid = objClsDBCon.RetrieveRecords(dsfillgrid, cmdfillgrid);
GVStudentAcademicRecords.DataSource = dsfillgrid;
GVStudentAcademicRecords.DataBind();
}
public void GetStudentId()
{
string QueryToFetchStudentId = "select studentid from StudentDetails where
EnrollmentNumber='" + txtEnrolment.Text + "' and IsApproved='" + false + "'";
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand(QueryToFetchStudentId);
ds = objClsDBCon.RetrieveRecords(ds, cmd);
studentid = Convert.ToInt16(ds.Tables[0].Rows[0][0]);
}
protected void GVStudentAcademicRecords_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
TextBox txtHS =
(TextBox)GVStudentAcademicRecords.Rows[e.RowIndex].Cells[1].Controls[0];
TextBox txtHSS =
(TextBox)GVStudentAcademicRecords.Rows[e.RowIndex].Cells[2].Controls[0];
TextBox txtSem =
(TextBox)GVStudentAcademicRecords.Rows[e.RowIndex].Cells[3].Controls[0];
TextBox txtYearOfSem =
(TextBox)GVStudentAcademicRecords.Rows[e.RowIndex].Cells[4].Controls[0];
TextBox txtAggrigate =
(TextBox)GVStudentAcademicRecords.Rows[e.RowIndex].Cells[5].Controls[0];
GetStudentId();//to get studentId
//Update Student Details table
string queryToUpdateStudentDetails = "update StudentDetails set HighSchoolPercent='"
+ txtHS.Text + "',HigherSecondryPercent='" + txtHSS.Text + "' where studentid=" +
studentid + "";
bool result1 = objTpofunctions.UpdateMethod(queryToUpdateStudentDetails);
//Update student_semester table
string queryToUpdatestudent_semeste = "update student_semester set semid='" +
Convert.ToInt16(txtSem.Text) + "',Year_of_sem='" + txtYearOfSem.Text + "',
sem_result_total_percent='" + txtAggrigate.Text + "' where Studentid=" + studentid + "";
bool result2 = objTpofunctions.UpdateMethod(queryToUpdatestudent_semeste);
FillGrid();
}
protected void GVStudentAcademicRecords_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)
{
GVStudentAcademicRecords.EditIndex = -1; }}
==========TpoFunction======================
public bool UpdateMethod(string Query)
{
SqlCommand cmd = new SqlCommand(Query);
bool result = clsDBCon.ExecuteNonQuerries(cmd);
return result;
}
================Add New Job====================

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


{
Tpofunctions objTpofunctions = new Tpofunctions();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string queryToInsertJob = "insert into Job values('" + txtJob.Text + "','" +
txtJobDescription.Text + "')";
bool result = objTpofunctions.InsertMethod(queryToInsertJob);
if (result == true)
{
Response.Redirect("postedjobrequired.aspx");
}
else
{
lblMsg.Text = "Insertion failed";
}
}}

You might also like