//Action Performed #region [Perform Action On Student Attendance] public int StudentAttendance_DL(EWA_StudentAttendance objEWA, DataTable StudentClassAttendance) { try { cmd = new SqlCommand("SP_StudentAttendance", con); con.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Action", objEWA.Action); cmd.Parameters.AddWithValue("@OrgID", objEWA.OrgId); cmd.Parameters.AddWithValue("@ClassId", objEWA.ClassId); cmd.Parameters.AddWithValue("@CourseId", objEWA.CourseId); cmd.Parameters.AddWithValue("@BranchId", objEWA.BranchId); cmd.Parameters.AddWithValue("@DivId", objEWA.DivisionId); cmd.Parameters.AddWithValue("@SubjectId", objEWA.SubjectId); cmd.Parameters.AddWithValue("@EmployeeId", objEWA.EmployeeId); cmd.Parameters.AddWithValue("@AttendanceDate", objEWA.Date); cmd.Parameters.AddWithValue("@AttendanceTime", objEWA.Time); //SqlParameter tblvaluetype = cmd.Parameters.AddWithValue("@DataStudentClassAttendance", StudentClassAttendance); //Passing table value parameter //tblvaluetype.SqlDbType = SqlDbType.Structured; int flag = Convert.ToInt32(cmd.ExecuteScalar().ToString()); con.Close(); return(flag); } catch (Exception) { throw; } }
//go Event #region [Go event] protected void btnGo_Click(object sender, EventArgs e) { try { EWA_StudentAttendance objEWA = new EWA_StudentAttendance(); BL_StudentAttendance objBAL = new BL_StudentAttendance(); objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); objEWA.CourseId = ddlCourses.SelectedValue.Trim(); objEWA.ClassId = ddlClasses.SelectedValue.Trim(); objEWA.DivisionId = ddlDivision.SelectedValue.Trim(); objEWA.BranchId = ddlBranches.SelectedValue.Trim(); objEWA.SubjectId = ddlSelectSubject.SelectedValue.Trim(); objEWA.Date = txtSelectDate.Text; objEWA.Time = txtTime.Text; DataSet ds = new DataSet(); ds = objBAL.BL_StudentAttendanceData(objEWA); if (ds.Tables[0] == null) { //btnUpdate.Visible = false; //btnSave.Visible = true; BindGrid(); } else { } db.cnopen(); if (RadioButtonList1.SelectedValue == "Present") { grdAttendance.DataSource = db.Displaygrid("SELECT isnull(tblStudent.RollNo,0)RollNo, tblStudetnClassAttendanceMaster.AttendanceDate, tblStudetnClassAttendanceMaster.AttendanceTime, tblStudent.FirstName + ' ' + tblStudent.MiddleName + ' ' + tblStudent.LastName AS Studentname, tblClass.ClassName, tblCourse.CourseName, tblBranch.BranchName, tblOrganization.OrgName, tblSubject.SubjectName FROM tblStudetnClassAttendanceMaster INNER JOIN tblStudentClassAttendance ON tblStudetnClassAttendanceMaster.AttendanceId = tblStudentClassAttendance.AttendanceID INNER JOIN tblClass ON tblStudetnClassAttendanceMaster.ClassId = tblClass.ClassId INNER JOIN tblCourse ON tblStudetnClassAttendanceMaster.CourseId = tblCourse.CourseId INNER JOIN tblBranch ON tblClass.BranchId = tblBranch.BranchId AND tblCourse.CourseId = tblBranch.CourseId AND tblStudetnClassAttendanceMaster.BranchId = tblBranch.BranchId INNER JOIN tblOrganization ON tblCourse.OrgId = tblOrganization.OrganizationId AND tblStudetnClassAttendanceMaster.OrgId = tblOrganization.OrganizationId INNER JOIN tblSubject ON tblClass.ClassId = tblSubject.ClassId AND tblCourse.CourseId = tblSubject.CourseId AND tblBranch.BranchId = tblSubject.BranchId AND tblOrganization.OrganizationId = tblSubject.OrgId AND tblStudetnClassAttendanceMaster.SubjectId = tblSubject.SubjectId INNER JOIN tblEmployee ON tblOrganization.OrganizationId = tblEmployee.OrgId AND tblStudetnClassAttendanceMaster.EmployeeId = tblEmployee.UserCode INNER JOIN tblStudent ON tblStudentClassAttendance.StudentID = tblStudent.UserCode and tblStudent.orgid= tblStudetnClassAttendanceMaster.OrgID WHERE(tblStudentClassAttendance.Status = 'P' And tblStudetnClassAttendanceMaster.CourseId='" + ddlCourses.SelectedValue.Trim() + "' and tblStudetnClassAttendanceMaster.ClassId='" + ddlClasses.SelectedValue.Trim() + "' and tblSubject.SubjectId = '" + ddlSelectSubject.SelectedValue + "' and tblStudetnClassAttendanceMaster.AttendanceDate='" + txtSelectDate.Text + "' and tblStudetnClassAttendanceMaster.OrgID=" + Session["OrgId"].ToString() + ") Order By tblStudent.RollNo"); grdAttendance.DataBind(); } else { //grdAttendance.DataSource = db.Displaygrid(" SELECT tblStudetnClassAttendanceMaster.AttendanceDate, tblStudetnClassAttendanceMaster.AttendanceTime, tblStudentClassAttendance.StudentID, tblStudentClassAttendance.StudentName, tblClass.ClassName, tblCourse.CourseName, tblBranch.BranchName, tblOrganization.OrgName, tblDivision.DivisionName, tblSubject.SubjectName FROM tblStudetnClassAttendanceMaster INNER JOIN tblStudentClassAttendance ON tblStudetnClassAttendanceMaster.AttendanceId = tblStudentClassAttendance.AttendanceID INNER JOIN tblClass ON tblStudetnClassAttendanceMaster.ClassId = tblClass.ClassId INNER JOIN tblCourse ON tblStudetnClassAttendanceMaster.CourseId = tblCourse.CourseId INNER JOIN tblBranch ON tblClass.BranchId = tblBranch.BranchId AND tblCourse.CourseId = tblBranch.CourseId AND tblStudetnClassAttendanceMaster.BranchId = tblBranch.BranchId INNER JOIN tblOrganization ON tblCourse.OrgId = tblOrganization.OrganizationId AND tblStudetnClassAttendanceMaster.OrgId = tblOrganization.OrganizationId INNER JOIN tblDivision ON tblClass.ClassId = tblDivision.ClassId AND tblStudetnClassAttendanceMaster.DivId = tblDivision.DivisionId INNER JOIN tblSubject ON tblClass.ClassId = tblSubject.ClassId AND tblCourse.CourseId = tblSubject.CourseId AND tblBranch.BranchId = tblSubject.BranchId AND tblOrganization.OrganizationId = tblSubject.OrgId AND tblStudetnClassAttendanceMaster.SubjectId = tblSubject.SubjectId INNER JOIN tblEmployee ON tblOrganization.OrganizationId = tblEmployee.OrgId AND tblStudetnClassAttendanceMaster.EmployeeId = tblEmployee.UserCode WHERE (tblStudentClassAttendance.Status = ' ' And tblStudetnClassAttendanceMaster.CourseId='" + ddlCourses.SelectedValue.Trim() + "' and tblStudetnClassAttendanceMaster.ClassId='" + ddlClasses.SelectedValue.Trim() + "' and tblSubject.SubjectId = '" + ddlSelectSubject.SelectedValue + "' and tblStudetnClassAttendanceMaster.AttendanceDate='" + txtSelectDate.Text + "')"); grdAttendance.DataSource = db.Displaygrid("SELECT isnull(tblStudent.RollNo,0)RollNo, tblStudetnClassAttendanceMaster.AttendanceDate, tblStudetnClassAttendanceMaster.AttendanceTime, tblStudent.FirstName + ' ' + tblStudent.MiddleName + ' ' + tblStudent.LastName AS Studentname, tblClass.ClassName, tblCourse.CourseName, tblBranch.BranchName, tblOrganization.OrgName, tblSubject.SubjectName FROM tblStudetnClassAttendanceMaster INNER JOIN tblStudentClassAttendance ON tblStudetnClassAttendanceMaster.AttendanceId = tblStudentClassAttendance.AttendanceID INNER JOIN tblClass ON tblStudetnClassAttendanceMaster.ClassId = tblClass.ClassId INNER JOIN tblCourse ON tblStudetnClassAttendanceMaster.CourseId = tblCourse.CourseId INNER JOIN tblBranch ON tblClass.BranchId = tblBranch.BranchId AND tblCourse.CourseId = tblBranch.CourseId AND tblStudetnClassAttendanceMaster.BranchId = tblBranch.BranchId INNER JOIN tblOrganization ON tblCourse.OrgId = tblOrganization.OrganizationId AND tblStudetnClassAttendanceMaster.OrgId = tblOrganization.OrganizationId INNER JOIN tblSubject ON tblClass.ClassId = tblSubject.ClassId AND tblCourse.CourseId = tblSubject.CourseId AND tblBranch.BranchId = tblSubject.BranchId AND tblOrganization.OrganizationId = tblSubject.OrgId AND tblStudetnClassAttendanceMaster.SubjectId = tblSubject.SubjectId INNER JOIN tblEmployee ON tblOrganization.OrganizationId = tblEmployee.OrgId AND tblStudetnClassAttendanceMaster.EmployeeId = tblEmployee.UserCode INNER JOIN tblStudent ON tblStudentClassAttendance.StudentID = tblStudent.UserCode and tblStudent.orgid= tblStudetnClassAttendanceMaster.OrgID WHERE(tblStudentClassAttendance.Status = 'A' And tblStudetnClassAttendanceMaster.CourseId='" + ddlCourses.SelectedValue.Trim() + "' and tblStudetnClassAttendanceMaster.ClassId='" + ddlClasses.SelectedValue.Trim() + "' and tblSubject.SubjectId = '" + ddlSelectSubject.SelectedValue + "' and tblStudetnClassAttendanceMaster.AttendanceDate='" + txtSelectDate.Text + "' and tblStudetnClassAttendanceMaster.OrgID=" + Session["OrgId"].ToString() + ") Order By tblStudent.RollNo"); grdAttendance.DataBind(); } db.cnclose(); // BindGrid(); } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
//Student Attendane Data #region [Student Attendance Data] public DataSet BL_StudentAttendanceData(EWA_StudentAttendance objEWA) { try { DL_StudentAttendance objDL = new DL_StudentAttendance(); DataSet ds = objDL.GetAttendanceData_DL(objEWA); return(ds); } catch (Exception) { throw; } }
//Attendance #region [Attendance Region] public int SaveAttendance(EWA_StudentAttendance ObjEWA, DataTable StudentClassAttendance) { try { DL_StudentAttendance ObjDL = new DL_StudentAttendance(); int flag = ObjDL.StudentAttendance_DL(ObjEWA, StudentClassAttendance); return(flag); } catch (Exception) { throw; } }
//Update Event #region [Update Event] protected void btnUpdate_Click(object sender, EventArgs e, string str) { try { EWA_StudentAttendance objEWA = new EWA_StudentAttendance(); BL_StudentAttendance objBL = new BL_StudentAttendance(); int i = 0; int count = grdAttendance.Rows.Count; string[] StudentId = new string[count]; string[] StudentName = new string[count]; string[] Status = new string[count]; //string str; foreach (GridViewRow gvrow in grdAttendance.Rows) { RadioButtonList rbl = ((RadioButtonList)gvrow.FindControl("rbtnlStatus")); objEWA.Action = str; if (str == "Update" || str == "Delete") { objEWA.StudentId = ViewState["StudentId"].ToString(); } objEWA.AttendanceStatus = rbl.SelectedValue.ToString(); objEWA.StudentId = rbl.SelectedValue.ToString(); objEWA.StudentFullName = rbl.SelectedValue.ToString(); //int flag = objBL.SaveAttendance(objEWA); if (rbl != null && rbl.SelectedValue == "A") { Status[i] = "A"; } else if (rbl != null && rbl.SelectedValue == "P") { Status[i] = "P"; } StudentId[i] = grdAttendance.Rows[gvrow.RowIndex].Cells[0].Text; StudentName[i] = grdAttendance.Rows[gvrow.RowIndex].Cells[1].Text; i++; } } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
//Get Attendance Data #region [Get Attendance Data] public DataSet GetAttendanceData_DL(EWA_StudentAttendance objEWA) { DataSet ds = new DataSet(); try { prmList = new string[10]; prmList[0] = "@Action"; prmList[1] = "CheckAttendace"; prmList[2] = "@OrgId"; prmList[3] = objEWA.OrgId.ToString(); prmList[4] = "@CourseId"; prmList[5] = objEWA.CourseId; prmList[6] = "@BranchId"; prmList[7] = objEWA.BranchId; prmList[8] = "@ClassId "; prmList[9] = objEWA.ClassId; //prmList[8] = "@DivisionId"; //prmList[9] = objEWA.Division; //prmList[10] = "@SubjectId"; //prmList[11] = objEWA.SubjectId; //prmList[12] = "@Date"; //prmList[13] = objEWA.Date; //prmList[14] = "@Time"; //prmList[15] = objEWA.Time; ds = ObjHelper.FillControl(prmList, "SP_StudentAttendance"); if (ds.Tables[0].Rows.Count > 0) { return(ds); } else { } return(ds); } catch (Exception) { // GeneralErr(exp.Message.ToString()); throw; } }
//Bind Grid #region [Bind Grid] private void BindGrid() { try { EWA_StudentAttendance objEWA = new EWA_StudentAttendance(); BL_StudentAttendance objBAL = new BL_StudentAttendance(); objEWA.CourseId = ddlCourses.SelectedValue; objEWA.ClassId = ddlClasses.SelectedValue; objEWA.BranchId = ddlBranches.SelectedValue; objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); DataSet ds = new DataSet(); ds = objBAL.BL_StudentAttendanceData(objEWA); if (ds.Tables[0].Rows.Count > 0) { grdAttendance.DataSource = ds.Tables[0]; grdAttendance.DataBind(); btnSave.Visible = true; } else { msgBox.ShowMessage("No Record Found !!!", "Saved", UserControls.MessageBox.MessageStyle.Information); //DataTable dt = new DataTable(); //dt.Columns.Add("UserCode"); //dt.Columns.Add("FullName"); //dt.Columns.Add("Mobile"); //dt.Rows.Add(); //dt.Rows.Add(); //grdAttendance.DataSource = dt; //grdAttendance.DataBind(); } } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
//go Event #region [Go event] protected void btnGo_Click(object sender, EventArgs e) { try { EWA_StudentAttendance objEWA = new EWA_StudentAttendance(); BL_StudentAttendance objBAL = new BL_StudentAttendance(); objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); objEWA.CourseId = ddlCourses.SelectedValue.Trim(); objEWA.ClassId = ddlClasses.SelectedValue.Trim(); objEWA.DivisionId = ddlDivision.SelectedValue.Trim(); objEWA.SubjectId = ddlSelectSubject.SelectedValue.Trim(); objEWA.BranchId = ddlBranches.SelectedValue.Trim(); objEWA.Date = txtSelectDate.Text; objEWA.Time = txtTime.Text; objEWA.DivisionId = ddlDivision.SelectedValue.Trim(); DataSet ds = new DataSet(); ds = objBAL.BL_StudentAttendanceData(objEWA); if (ds.Tables[0] == null) { btnUpdate.Visible = false; btnSave.Visible = true; // BindGrid(); } else { } BindGrid(); } catch (Exception exp) { //GeneralErr(exp.Message.ToString()); } }
//Bind Grid #region [Bind Grid] private void BindGrid() { try { EWA_StudentAttendance objEWA = new EWA_StudentAttendance(); BL_StudentAttendance objBAL = new BL_StudentAttendance(); objEWA.CourseId = ddlCourses.SelectedValue; objEWA.ClassId = ddlClasses.SelectedValue; objEWA.BranchId = ddlBranches.SelectedValue; objEWA.OrgId = Convert.ToInt32(Session["OrgId"]); DataSet ds = new DataSet(); ds = objBAL.BL_StudentAttendanceData(objEWA); if (ds.Tables[0].Rows.Count > 0) { grdAttendance.DataSource = ds.Tables[0]; grdAttendance.DataBind(); } else { DataTable dt = new DataTable(); dt.Columns.Add("UserCode"); dt.Columns.Add("FullName"); dt.Rows.Add(); dt.Rows.Add(); grdAttendance.DataSource = dt; grdAttendance.DataBind(); } } catch (Exception exp) { GeneralErr(exp.Message.ToString()); } }
//Save Click #region [Save Event] protected void btnSave_Click(object sender, EventArgs e) { try { EWA_StudentAttendance ObjEWA = new EWA_StudentAttendance(); BL_StudentAttendance ObjBL = new BL_StudentAttendance(); ObjEWA.Action = "SaveStudentClassAttendance"; ObjEWA.CourseId = ddlCourses.SelectedValue; ObjEWA.BranchId = ddlBranches.SelectedValue; ObjEWA.ClassId = ddlClasses.SelectedValue; ObjEWA.DivisionId = ddlDivision.SelectedValue; ObjEWA.SubjectId = ddlSelectSubject.SelectedValue; ObjEWA.EmployeeId = Session["UserCode"].ToString(); ObjEWA.OrgId = Convert.ToInt32(Session["OrgId"]); ObjEWA.Date = txtSelectDate.Text; ObjEWA.Time = txtTime.Text; DataTable DataStudentClassAttendance = new DataTable(); int flag = ObjBL.SaveAttendance(ObjEWA, DataStudentClassAttendance); if (flag > 0) { btnSave.Visible = false; DataStudentClassAttendance.Columns.Add("AttendanceID"); DataStudentClassAttendance.Columns.Add("StudentID"); DataStudentClassAttendance.Columns.Add("StudentName"); DataStudentClassAttendance.Columns.Add("Status"); int i = 0; string id, name, Astatus; foreach (GridViewRow gvrow in grdAttendance.Rows) { CheckBox chk = ((CheckBox)gvrow.FindControl("chkboxStatus")); if (chk.Checked == true) { Astatus = "P"; } else { Astatus = "A"; //SendSMSParents("SentToParent"); } id = grdAttendance.Rows[gvrow.RowIndex].Cells[4].Text; name = grdAttendance.Rows[gvrow.RowIndex].Cells[2].Text; mobile = grdAttendance.Rows[gvrow.RowIndex].Cells[3].Text; //DataStudentClassAttendance.Rows.Add("0", id, name, Astatus); DataStudentClassAttendance.Rows.Add(flag, id, name, Astatus); i++; } string cs = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; using (SqlConnection sqlConn = new SqlConnection(cs)) { sqlConn.Open(); using (SqlBulkCopy sqlbc = new SqlBulkCopy(sqlConn)) { sqlbc.DestinationTableName = "tblStudentClassAttendance"; sqlbc.WriteToServer(DataStudentClassAttendance); sqlConn.Close(); //Response.Write("Bulk data stored successfully"); msgBox.ShowMessage("Attendance Saved Successfully !!!", "Saved", UserControls.MessageBox.MessageStyle.Successfull); clearcontrol(); } } } else if (flag == -1) { msgBox.ShowMessage("Record already exists !!!", "Information", UserControls.MessageBox.MessageStyle.Critical); } else { msgBox.ShowMessage("Try Again with different attendance Time !!!", "Information", UserControls.MessageBox.MessageStyle.Critical); } //if (flag > 0) //{ // msgBox.ShowMessage("Attendance Saved Successfully !!!", "Saved", UserControls.MessageBox.MessageStyle.Successfull); // // // Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true); //} } catch (Exception exp) { // GeneralErr(exp.Message.ToString()); } }