Special Examination Absent Entry

<%@ Page Title=”” Language=”C#” MasterPageFile=”~/Site.Master” AutoEventWireup=”true”
CodeBehind=”frmExamAbsentListEntry2.aspx.cs” Inherits=”Registration_and_Examination.frmExamAbsentListEntry2″
Theme=”MainSkin” %>

<%@ Register Assembly=”AjaxControlToolkit” Namespace=”AjaxControlToolkit” TagPrefix=”cc1″ %>
<asp:Content ID=”Content1″ ContentPlaceHolderID=”HeadContent” runat=”server”>
<style type=”text/css”>
.mGrid
{
width: 100%;
background-color: #fff;
margin: 5px 0 10px 0;
border: solid 1px #525252;
border-collapse: collapse;
}
.mGrid td
{
padding: 2px;
border: solid 1px #c1c1c1;
color: #717171;
}
.mGrid th
{
padding: 4px 2px;
color: #fff;
background: #424242 url(Styles/images/grd_head.png) repeat-x top;
border-left: solid 1px #525252;
font-size: 0.9em;
}
.mGrid .alt
{
background: #fcfcfc url(Styles/images/grd_alt.png) repeat-x top;
}
.mGrid .pgr
{
background: #424242 url(Styles/images/grd_pgr.png) repeat-x top;
}
.mGrid .pgr table
{
margin: 5px 0;
}
.mGrid .pgr td
{
border-width: 0;
padding: 0 6px;
border-left: solid 1px #666;
font-weight: bold;
color: #fff;
line-height: 12px;
}
.mGrid .pgr a
{
color: #666;
text-decoration: none;
}
.mGrid .pgr a:hover
{
color: #000;
text-decoration: none;
}
</style>
</asp:Content>
<asp:Content ID=”Content2″ ContentPlaceHolderID=”MainContent” runat=”server”>
<br />
<div align=”center”>
<div align=”center” style=”font-family: Garamond; font-size: 16px; font-weight: bold;
color: MenuText; width: 590px;”>
Examination Absent Entry</div>
<asp:Label ID=”lblMessage” runat=”server” ForeColor=”Red”></asp:Label>
<br />
</div>
<fieldset>
<table>
<tr>
<td align=”right”>
Select Term:
</td>
<td align=”left”>
<asp:DropDownList ID=”ddlTermId” runat=”server” AutoPostBack=”true” OnSelectedIndexChanged=”ddlTermId_SelectedIndexChanged”>
</asp:DropDownList>
</td>
</tr>
<tr>
<td align=”right”>
Select Course:
</td>
<td align=”left”>
<asp:DropDownList ID=”ddlCourseId” runat=”server” AutoPostBack=”true” OnSelectedIndexChanged=”ddlCourseId_SelectedIndexChanged”>
</asp:DropDownList>
</td>
</tr>
<tr>
<td align=”right”>
Examination Date:
</td>
<td align=”left”>
<asp:TextBox ID=”txtExamDate” runat=”server”></asp:TextBox>
dd/MM/yyyy
<asp:RegularExpressionValidator ID=”RegularExpressionValidator1″ ValidationGroup=”feesverification”
ValidationExpression=”[0-9]*[/][0-9]*[/][0-9]*” ControlToValidate=”txtExamDate”
ForeColor=”Red” runat=”server” ErrorMessage=”Your Date Format is wrong…”></asp:RegularExpressionValidator>
<cc1:CalendarExtender ID=”Calen1From” runat=”server” PopupPosition=”BottomLeft” PopupButtonID=”imgCalen1″
TargetControlID=”txtExamDate” Format=”dd/MM/yyyy”>
</cc1:CalendarExtender>
</td>
</tr>
<tr>
<td align=”right”>
Total Number Student:
</td>
<td align=”left”>
<asp:TextBox ID=”txtTotalStudent” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td align=”right”>
Number of Absent:
</td>
<td align=”left”>
<asp:TextBox ID=”txtAbsentStd” Enabled=”false” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td align=”center” colspan=”2″>
<div>Examination Absent Students</div>
<asp:GridView ID=”gvExamAbsentEntry” SkinID=”gvExamAbsent” runat=”server” ShowFooter=”true”
AutoGenerateColumns=”false” GridLines=”None” AllowPaging=”True” AllowSorting=”True”
CssClass=”mGrid” PagerStyle-CssClass=”pgr” AlternatingRowStyle-CssClass=”alt”
PageSize=”200″>
<AlternatingRowStyle CssClass=”alt”></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField=”RowNumber” HeaderText=”Sl. ” />
<asp:TemplateField HeaderText=”Roll”>
<ItemTemplate>
<asp:TextBox ID=”txtRoll” runat=”server” Text='<% #Eval(“Roll”) %>’ AutoPostBack=”true”
OnTextChanged=”txtRoll_TextChanged”></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText=”Name”>
<ItemTemplate>
<asp:TextBox ID=”txtName” Text='<% #Eval(“Name”) %>’ runat=”server”></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign=”Right” />
<FooterTemplate>
<asp:LinkButton ID=”ButtonAdd” runat=”server” Text=”Add New Row” OnClick=”ButtonAdd_Click” />
<%–<asp:Button ID=”ButtonAdd” runat=”server” Text=”Add New Row” OnClick=”ButtonAdd_Click” />–%>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass=”pgr”></PagerStyle>
</asp:GridView>
</td>
</tr>
<tr>
<td colspan=”2″ align=”right”>
<asp:Button ID=”btnUpdate” runat=”server” Text=”Update” OnClick=”btnUpdate_Click”
ValidationGroup=”feesverification” />
<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit” OnClick=”btnSubmit_Click”
ValidationGroup=”feesverification” />
</td>
</tr>
</table>
</fieldset>
</asp:Content>

 

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

using RegistrationandExamination.BLL;
using RegistrationandExamination.CommonLayer;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Collections;
namespace Registration_and_Examination
{
public partial class frmExamAbsentListEntry2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//if (CommonMethods.PermissionReturn1(“TermMarksDistribution”, “R”))
//{
//}
//else
// Response.Redirect(“Home.aspx”);

if (!Page.IsPostBack)
{
getTermId();
// SetInitialRow();
}
}

void getTermId()
{
string query = “SELECT TermId, TermName FROM T_Term_Setup WHERE TermClosingStatus=0”;
ClsCommon.drplistAddNew(ddlTermId, query, “TermName”, “TermId”);

//txtAbsentRoll.Text = “”;
txtAbsentStd.Text = “”;
txtExamDate.Text = “”;
txtTotalStudent.Text = “”;
}

protected void ddlTermId_SelectedIndexChanged(object sender, EventArgs e)
{
string query = “SELECT CourseId, CourseCode FROM T_Term_Course_Offer WHERE TermId='” + ddlTermId.Text.ToString().Trim() + “‘ AND CourseType=’Theory'”;
ClsCommon.drplistAddNew(ddlCourseId, query, “CourseCode”, “CourseId”);

String Qs = “SELECT ExaminationStart FROM T_Term_Setup WHERE TermId='” + ddlTermId.Text.ToString().Trim() + “‘”;
txtExamDate.Text = GetFixedLengthString(ClsCommon.GetAdhocResult(Qs).Tables[0].Rows[0][0].ToString(), 10);
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
String StudentRollList = “”.Trim();

foreach (GridViewRow rowItem in gvExamAbsentEntry.Rows)
{
TextBox txtRoll = (TextBox)rowItem.FindControl(“txtRoll”);
StudentRollList = StudentRollList + txtRoll.Text.Trim() + “, “;
}

StudentRollList = StudentRollList.Substring(0, StudentRollList.Length – 2);
SqlConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings[“RegistrationandExamination”].ConnectionString);
SqlCommand com = new SqlCommand();

SqlTransaction tran;
db.Open();
tran = db.BeginTransaction();

com.CommandText = ” INSERT INTO T_Absent_List(TermId,CourseId,ExamDate,TotalStudent,AbsStudent,AbsStudentRoll)” +
” VALUES(@TermId,@CourseId,@ExamDate,@TotalStudent,@AbsStudent,@AbsStudentRoll)”;

com.Connection = db;
com.Transaction = tran;
com.Parameters.Add(“@TermId”, SqlDbType.VarChar);
com.Parameters.Add(“@CourseId”, SqlDbType.VarChar);
com.Parameters.Add(“@ExamDate”, SqlDbType.Date);
com.Parameters.Add(“@TotalStudent”, SqlDbType.Int);
com.Parameters.Add(“@AbsStudent”, SqlDbType.Int);
com.Parameters.Add(“@AbsStudentRoll”, SqlDbType.VarChar);

try
{
com.Parameters[“@TermId”].Value = ddlTermId.Text.ToString();
com.Parameters[“@CourseId”].Value = ddlCourseId.Text.ToString();
com.Parameters[“@ExamDate”].Value = Convert.ToDateTime(txtExamDate.Text.ToString()).ToString(“dd/MM/yyyy”);
com.Parameters[“@TotalStudent”].Value = Convert.ToInt32(txtTotalStudent.Text.ToString().Trim());
com.Parameters[“@AbsStudent”].Value = Convert.ToInt32(txtAbsentStd.Text.ToString().Trim());
com.Parameters[“@AbsStudentRoll”].Value = StudentRollList;

com.ExecuteNonQuery();

lblMessage.Text = “Absent List Insertion Successful.”;
}
catch (SqlException sqlex)
{
tran.Rollback();
lblMessage.Text = “Absent List Insertion Failed. Error: ” + sqlex.Message;
}
finally
{
tran.Commit();
db.Close();
}

btnSubmit.Visible = true;
btnUpdate.Visible = true;
btnUpdate.Enabled = true;
btnSubmit.Enabled = false;
getTermId();

try
{
Log(((Control)sender).ID.ToString(), this.Page.ToString());
}
catch (Exception ex) { lblMessage.Text = ex.Message.ToString(); }
}

protected void btnUpdate_Click(object sender, EventArgs e)
{
String StudentRollList = “”.Trim();

foreach (GridViewRow rowItem in gvExamAbsentEntry.Rows)
{
TextBox txtRoll = (TextBox)rowItem.FindControl(“txtRoll”);
StudentRollList = StudentRollList + txtRoll.Text.Trim() + “, “;
}

StudentRollList = StudentRollList.Substring(0, StudentRollList.Length – 2);

SqlConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings[“RegistrationandExamination”].ConnectionString);
SqlCommand com = new SqlCommand();

SqlTransaction tran;
db.Open();
tran = db.BeginTransaction();

com.CommandText = ” UPDATE T_Absent_List SET TermId=@TermId,CourseId=@CourseId,ExamDate=@ExamDate,” +
” TotalStudent=@TotalStudent,AbsStudent=@AbsStudent,AbsStudentRoll=@AbsStudentRoll” +
” WHERE TermId=@TermId AND CourseId=@CourseId”;

com.Connection = db;
com.Transaction = tran;
com.Parameters.Add(“@TermId”, SqlDbType.VarChar);
com.Parameters.Add(“@CourseId”, SqlDbType.VarChar);
com.Parameters.Add(“@ExamDate”, SqlDbType.Date);
com.Parameters.Add(“@TotalStudent”, SqlDbType.Int);
com.Parameters.Add(“@AbsStudent”, SqlDbType.Int);
com.Parameters.Add(“@AbsStudentRoll”, SqlDbType.VarChar);

try
{
com.Parameters[“@TermId”].Value = ddlTermId.Text.ToString();
com.Parameters[“@CourseId”].Value = ddlCourseId.Text.ToString();
com.Parameters[“@ExamDate”].Value = Convert.ToDateTime(txtExamDate.Text.ToString()).ToString(“dd/MM/yyyy”);
com.Parameters[“@TotalStudent”].Value = Convert.ToInt32(txtTotalStudent.Text.ToString().Trim());
com.Parameters[“@AbsStudent”].Value = Convert.ToInt32(txtAbsentStd.Text.ToString().Trim());
com.Parameters[“@AbsStudentRoll”].Value = StudentRollList;

com.ExecuteNonQuery();

lblMessage.Text = “Absent List Update Successful.”;
}
catch (SqlException sqlex)
{
tran.Rollback();
lblMessage.Text = “Absent List Update Failed. Error: ” + sqlex.Message;
}
finally
{
tran.Commit();
db.Close();
}

btnSubmit.Visible = true;
btnUpdate.Visible = true;
btnUpdate.Enabled = true;
btnSubmit.Enabled = false;
getTermId();

try
{
Log(((Control)sender).ID.ToString(), this.Page.ToString());
}
catch (Exception ex) { lblMessage.Text = ex.Message.ToString(); }
}

void Log(String ControlName, String formName)
{
if ((Session[“UserId”] != null))
{
String UserId = “”;
try { UserId = Session[“UserId”].ToString(); }
catch (Exception ex) { UserId = Session[“StudentId”].ToString(); }
String LogText = “\t” + UserId + “\t” + Session[“_HOST”].ToString() + “\t” + Session[“_IP”].ToString() + “\t” + Session[“_MAC”].ToString() + “\t” + formName + “\t” + ControlName;
String StrDate = DateTime.Today.ToString(“dd-MMM-yyyy”);
CommonMethods.ProcessButtonPressLog(StrDate, LogText);
}
}

protected void ddlCourseId_SelectedIndexChanged(object sender, EventArgs e)
{
txtAbsentStd.Text = “1”;

String Qs = “SELECT * FROM T_Absent_List WHERE TermId='” + ddlTermId.Text.Trim() + “‘ AND CourseId='” + ddlCourseId.Text.Trim() + “‘”;
Int32 Count = ClsCommon.GetAdhocResult(Qs).Tables[0].Rows.Count;
if (Count > 0)
{
btnSubmit.Enabled = false;
btnUpdate.Enabled = true;

txtExamDate.Text = GetFixedLengthString(ClsCommon.GetAdhocResult(Qs).Tables[0].Rows[0][“ExamDate”].ToString(), 10);
txtTotalStudent.Text = ClsCommon.GetAdhocResult(Qs).Tables[0].Rows[0][“TotalStudent”].ToString();
txtAbsentStd.Text = ClsCommon.GetAdhocResult(Qs).Tables[0].Rows[0][“AbsStudent”].ToString();
//txtAbsentRoll.Text = ClsCommon.GetAdhocResult(Qs).Tables[0].Rows[0][“AbsStudentRoll”].ToString();

string myString = ClsCommon.GetAdhocResult(Qs).Tables[0].Rows[0][“AbsStudentRoll”].ToString();
ArrayList al = new ArrayList(myString.Split(‘,’));
Int32 count = al.Count;

/// DataTable Definition
DataTable dt = new DataTable();
dt.Columns.Add(“RowNumber”, typeof(string));
dt.Columns.Add(“Roll”, typeof(string));
dt.Columns.Add(“Name”, typeof(string));
for (Int32 i = 0; i < count; i++)
{
/// DataTable Row value Insert
DataRow dRow = dt.NewRow();
dRow[“RowNumber”] = i + 1;
dRow[“Roll”] = al[i].ToString().Trim();
dRow[“Name”] = ClsCommon.GetAdhocResult(“SELECT StudentsName FROM T_Std_General_Information WHERE StudentId='” + al[i].ToString().Trim() + “‘”).Tables[0].Rows[0][0].ToString();
dt.Rows.Add(dRow);
}

ViewState[“CurrentTable”] = dt;
gvExamAbsentEntry.DataSource = dt;
gvExamAbsentEntry.DataBind();
}
else
{
SetInitialRow();

btnUpdate.Enabled = false;
btnSubmit.Enabled = true;
}

String Qstr = “SELECT COUNT(*) FROM T_Term_Std_Result_Theory_Details WHERE TermId='” + ddlTermId.Text.Trim() + “‘ AND CourseId='” + ddlCourseId.Text.Trim() + “‘”;
txtTotalStudent.Text = ClsCommon.GetAdhocResult(Qstr).Tables[0].Rows[0][0].ToString();
}

String GetFixedLengthString(string input, int length)
{
input = input ?? string.Empty;
input = input.Length > length ? input.Substring(0, length) : input;
return string.Format(“{0,-” + length + “}”, input);
}

private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn(“RowNumber”, typeof(string)));
dt.Columns.Add(new DataColumn(“Roll”, typeof(string)));
dt.Columns.Add(new DataColumn(“Name”, typeof(string)));
dr = dt.NewRow();
dr[“RowNumber”] = 1;
dr[“Roll”] = string.Empty;
dr[“Name”] = string.Empty;
dt.Rows.Add(dr);
//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState[“CurrentTable”] = dt;
gvExamAbsentEntry.DataSource = dt;
gvExamAbsentEntry.DataBind();
}

private void AddNewRowToGrid()
{
int rowIndex = 0;
if (ViewState[“CurrentTable”] != null)
{

DataTable dtCurrentTable = (DataTable)ViewState[“CurrentTable”];
DataRow drCurrentRow = null;

if (dtCurrentTable.Rows.Count > 0)
{

for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
//extract the TextBox values
TextBox box1 = (TextBox)gvExamAbsentEntry.Rows[rowIndex].Cells[1].FindControl(“txtRoll”);
TextBox box2 = (TextBox)gvExamAbsentEntry.Rows[rowIndex].Cells[2].FindControl(“txtName”);
drCurrentRow = dtCurrentTable.NewRow();

drCurrentRow[“RowNumber”] = i + 1;
dtCurrentTable.Rows[i – 1][“Roll”] = box1.Text;
dtCurrentTable.Rows[i – 1][“Name”] = box2.Text;
rowIndex++;
}

dtCurrentTable.Rows.Add(drCurrentRow);
ViewState[“CurrentTable”] = dtCurrentTable;
gvExamAbsentEntry.DataSource = dtCurrentTable;
gvExamAbsentEntry.DataBind();
}
}
else
{
//Response.Write(“ViewState is null”);
lblMessage.Text = “ViewState is null”;
}
//Set Previous Data on Postbacks
SetPreviousData();

}

private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState[“CurrentTable”] != null)
{
DataTable dt = (DataTable)ViewState[“CurrentTable”];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
TextBox box1 = (TextBox)gvExamAbsentEntry.Rows[rowIndex].Cells[1].FindControl(“txtRoll”);
TextBox box2 = (TextBox)gvExamAbsentEntry.Rows[rowIndex].Cells[2].FindControl(“txtName”);
box1.Text = dt.Rows[i][“Roll”].ToString();
box2.Text = dt.Rows[i][“Name”].ToString();
rowIndex++;
}
}
}
}

protected void ButtonAdd_Click(object sender, EventArgs e)
{
AddNewRowToGrid();
txtAbsentStd.Text = gvExamAbsentEntry.Rows.Count.ToString();
}

protected void txtRoll_TextChanged(object sender, EventArgs e)
{
foreach (GridViewRow rowItem in gvExamAbsentEntry.Rows)
{
TextBox txtRoll = (TextBox)rowItem.FindControl(“txtRoll”);
TextBox txtName = (TextBox)rowItem.FindControl(“txtName”);

String Qs = “SELECT StudentsName FROM T_Std_General_Information WHERE StudentId='” + txtRoll.Text.Trim() + “‘”;

txtName.Text = ClsCommon.GetAdhocResult(Qs).Tables[0].Rows[0][0].ToString();
}
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s