Exemplo n.º 1
0
        //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());
            }
        }
        //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());
            }
        }
        //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());
            }
        }
Exemplo n.º 5
0
        //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());
            }
        }