Header Ads

Header ADS

Part 9. Teacher Panel (Taking Attendance) Part - II





In this attendance management system project video's we are going to see how a teacher can take attendance of students for a particular course, class and semester.


Source Code Starts Here :-

Mark_Attendance.aspx


<center>
<div style="background-image: url('Images/background1.jpg'); width: 1200px">
    <center>
        <table align="center" style="width: 1200px; height: 366px">
            <tr style="width: 1200px;">
                <td>
                    <b>Course: </b>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server" Height="40px" Width="115px" AutoPostBack="true">
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    <b>Year: </b>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server" Height="40px" Width="125px" AutoPostBack="true">
                        <asp:ListItem>Select Year</asp:ListItem>
                        <asp:ListItem>First Year</asp:ListItem>
                        <asp:ListItem>Second Year</asp:ListItem>
                        <asp:ListItem>Third Year</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    <b>Semester: </b>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList5" runat="server" Height="40px" Width="125px" OnSelectedIndexChanged="DropDownList5_SelectedIndexChanged"
                        AutoPostBack="true">
                        <asp:ListItem>Select Semester</asp:ListItem>
                        <asp:ListItem>Sem I</asp:ListItem>
                        <asp:ListItem>Sem II</asp:ListItem>
                        <asp:ListItem>Sem III</asp:ListItem>
                        <asp:ListItem>Sem IV</asp:ListItem>
                        <asp:ListItem>Sem V</asp:ListItem>
                        <asp:ListItem>Sem VI</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    <b>Subject: </b>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList3" runat="server" Height="40px" Width="215px" AutoPostBack="true">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr style="width: 1200px;">
                <td colspan="10" align="center">
                    <b>Total Lectures:</b>
                    <asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="true">
                        <asp:ListItem>select</asp:ListItem>
                        <asp:ListItem>1</asp:ListItem>
                        <asp:ListItem>2</asp:ListItem>
                        <asp:ListItem>3</asp:ListItem>
                        <asp:ListItem>4</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td colspan="10" align="center">
                    <asp:Button ID="Button1" runat="server" Text="Select" Font-Bold="True" Height="40px"
                        Width="92px" OnClick="Button1_Click" />
                </td>
            </tr>
            <tr>
                <td colspan="10" align="center">
                    <asp:Label ID="Label4" runat="server" Font-Bold="True" ForeColor="#9900FF"></asp:Label>
                    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="10" align="center">
                    <asp:GridView ID="GridView1" runat="server">
                        <Columns>
                            <asp:TemplateField HeaderText="Mark Attendance">
                                <ItemTemplate>
                                    <asp:RadioButton ID="RadioButton1" runat="server" Checked="True" Text="Present" GroupName="attend" />
                                    &nbsp;<asp:RadioButton ID="RadioButton2" runat="server" Text="Absent" GroupName="attend" />
                                    &nbsp;
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                        <EmptyDataTemplate>
                            <asp:Label ID="Label2" runat="server" Text="No such Records found!" ForeColor="Red"
                                Font-Bold="True"></asp:Label></EmptyDataTemplate>
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td colspan="10" align="center">
                    <asp:Button ID="Button2" runat="server" Text="Mark Attendance" Font-Bold="True" Height="41px"
                        Width="144px" OnClick="Button2_Click" />
                </td>
            </tr>
            <tr>
                <td colspan="10" align="center">
                    <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
                </td>
            </tr>
        </table>
    </center>
    </div>
</center>



Mark_Attendance.aspx.cs


string str = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "";
        if (!IsPostBack)
        {
            DrpCourse();
            DateTime now = DateTime.Now;
            Label4.Text = "Today's Date: " + now;
        }
    }

    private void DrpCourse()
    {
        SqlConnection con = new SqlConnection(str);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Course", con);
        DropDownList1.DataSource = cmd.ExecuteReader();
        DropDownList1.DataTextField = "CourseName";
        DropDownList1.DataValueField = "CID";
        DropDownList1.DataBind();
        DropDownList1.Items.Insert(0, "Select Course");
        con.Close();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue == "Select Course" && DropDownList2.SelectedValue == "Select Year" && DropDownList5.SelectedValue == "Select Semester" && DropDownList4.SelectedValue == "select" && DropDownList3.SelectedValue == "Select Subject")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList1.SelectedValue == "Select Course")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList4.SelectedValue == "select")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }

        else if (DropDownList2.SelectedValue == "Select Year")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList3.SelectedValue == "Select Subject")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList5.SelectedValue == "Select Semester")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList1.SelectedValue == "Select Course" && DropDownList2.SelectedValue == "Select Year")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList1.SelectedValue == "Select Course" && DropDownList5.SelectedValue == "Select Semester")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList1.SelectedValue == "Select Course" && DropDownList3.SelectedValue == "Select Subject")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }

        else if (DropDownList1.SelectedValue == "Select Course" && DropDownList4.SelectedValue == "select")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList2.SelectedValue == "Select Year" && DropDownList5.SelectedValue == "Select Semester")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }

        else if (DropDownList2.SelectedValue == "Select Year" && DropDownList4.SelectedValue == "select")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList2.SelectedValue == "Select Year" && DropDownList3.SelectedValue == "Select Subject")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList5.SelectedValue == "Select Semester" && DropDownList4.SelectedValue == "select")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else if (DropDownList5.SelectedValue == "Select Semester" && DropDownList3.SelectedValue == "Select Subject")
        {
            Label1.Text = "Please select all the fields.";
            Label1.ForeColor = System.Drawing.Color.Red;
        }
        else
        {
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlDataAdapter sda = new SqlDataAdapter("select STID,Roll as RollNo,SName as StudentName from Student where Course='" + DropDownList1.SelectedItem.Text + "' and Year='" + DropDownList2.SelectedItem.Text + "' and Sem='" + DropDownList5.SelectedItem.Text + "'", con);
            DataSet ds = new DataSet();
            sda.Fill(ds, "Student");
            GridView1.DataSource = ds;
            GridView1.DataBind();
            con.Close();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            int Roll_No = Convert.ToInt32(row.Cells[2].Text);
            String Stud_Name = row.Cells[3].Text;
            int Stud_ID = Convert.ToInt32(row.Cells[1].Text);
            RadioButton rb1 = (row.Cells[0].FindControl("RadioButton1") as RadioButton);
            RadioButton rb2 = (row.Cells[0].FindControl("RadioButton2") as RadioButton);
            int status;
            if (rb1.Checked)
            {
                status = 1;
            }
            else
            {
                status = 0;
            }
            String course = DropDownList1.SelectedItem.Text;
            String year = DropDownList2.SelectedItem.Text;
            String subject = DropDownList3.SelectedItem.Text;
            int Total_Lect = Int32.Parse(DropDownList4.SelectedItem.Text);
            
            int TLecture = (Total_Lect * status);
            String sem = DropDownList5.SelectedItem.Text;
            DateTime date = DateTime.Now;
            
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand cmd = new SqlCommand(" insert into StudentAttendance(STID,StudentName,Course,Year,Subject,Roll,Status,Date,Lecture,Sem) values(@1,@2,@3,@4,@5,@6,@7,@8,@9,@10)", con);
            cmd.Parameters.AddWithValue("@1", Stud_ID);
            cmd.Parameters.AddWithValue("@2", Stud_Name);
            cmd.Parameters.AddWithValue("@3", course);
            cmd.Parameters.AddWithValue("@4", year);
            cmd.Parameters.AddWithValue("@5", subject);
            cmd.Parameters.AddWithValue("@6", Roll_No);
            cmd.Parameters.AddWithValue("@7", status);
            cmd.Parameters.AddWithValue("@8", date);
            cmd.Parameters.AddWithValue("@9", TLecture);
            cmd.Parameters.AddWithValue("@10", sem);
            cmd.ExecuteNonQuery();
            con.Close();
            Label3.Text = "Attendance Saved Successfully";
            Label3.ForeColor = System.Drawing.Color.Green;
        }

        if (Session["TeacherID"] != null)
        {
            String course = DropDownList1.SelectedItem.Text;
            String year = DropDownList2.SelectedItem.Text;
            String subject = DropDownList3.SelectedItem.Text;
            int Total_Lect = Int32.Parse(DropDownList4.SelectedItem.Text);
            String sem = DropDownList5.SelectedItem.Text;
            DateTime date = DateTime.Now;

            SqlConnection con1 = new SqlConnection(str);
            con1.Open();
            SqlCommand cmd1 = new SqlCommand("insert into T_Lectures(TID,TName,Date,LTaken,Course,Year,Subject,Sem) values(@1,@2,@3,@4,@5,@6,@7,@8)", con1);
            cmd1.Parameters.AddWithValue("@1", Session["TeacherID"]);
            cmd1.Parameters.AddWithValue("@2", Session["TeacherName"]);
            cmd1.Parameters.AddWithValue("@3", date);
            cmd1.Parameters.AddWithValue("@4", Total_Lect);
            cmd1.Parameters.AddWithValue("@5", course);
            cmd1.Parameters.AddWithValue("@6", year);
            cmd1.Parameters.AddWithValue("@7", subject);
            cmd1.Parameters.AddWithValue("@8", sem);
            cmd1.ExecuteNonQuery();
            con1.Close();
        }
    }
    protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
    {
        int courseID = Convert.ToInt32(DropDownList1.SelectedValue);
        string year = DropDownList2.SelectedItem.Text;
        string sem = DropDownList5.SelectedItem.Text;
        SqlConnection con = new SqlConnection(str);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from Subject where CID='" + courseID + "' and Year='" + year + "' and Sem='" + sem + "'", con);
        DropDownList3.DataSource = cmd.ExecuteReader();
        DropDownList3.DataTextField = "SubjectName";
        DropDownList3.DataValueField = "SID";
        DropDownList3.DataBind();
        DropDownList3.Items.Insert(0, "Select Subject");
        con.Close();
    }

Thanks for watching:)

No comments

Please do not enter any spam link in the comment box.

Powered by Blogger.