Professional Documents
Culture Documents
Documentof Tpo
Documentof Tpo
Documentof Tpo
}
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;
}
}
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;
}
}
return result;
} }}
====================TpoFunction Class======================
using System.Data.SqlClient;
/// <summary>
/// Summary description for Tpofunctions
/// </summary>
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();
}
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====================
}
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";
}
}}