/// <summary>
 /// This function used to insert the StudentAttendance record in studentAttendance List
 /// </summary>
 /// <param name="query">Query to retrieve the data from database</param>
 public void StudentAttendenceRecord(string query)
 {
     try
     {
         SqlCommand command = new SqlCommand(query, conn);
         conn.Open();
         SqlDataReader reader;
         reader = command.ExecuteReader();
         if (reader.HasRows)
         {
             ListofClasses Lt1 = new ListofClasses();
             Lt1.SAC1.Clear();
             while (reader.Read())
             {
                 StudentAttendenceClass SRC = new StudentAttendenceClass();
                 SRC.StudentId1        = Convert.ToInt32(reader[1]);
                 SRC.AttendanceId1     = Convert.ToInt32(reader[0]);
                 SRC.AttendanceStatus1 = Convert.ToInt32(reader[2]);
                 Lt1.addIntoStudentAttendence(SRC);
             }
         }
     }
     catch (Exception ex)
     {
         throw (ex);
     }
     finally
     {
         conn.Close();
     }
 }
        private void StudentAttendence_Load(object sender, EventArgs e)
        {
            StudentAttendenceClass Acc = new StudentAttendenceClass();
            ListofClasses          lt1 = new ListofClasses();

            StudentAttendenceRecord.DataSource = null;
            Acc.Record();
            StudentName1.Text                  = "";
            AttendenceAtatus.Text              = "";
            AttendencedateComobox.Text         = "";
            StudentAttendenceRecord.DataSource = lt1.SAC1;
            comoboxvalues();
        }
        private void Save_Click(object sender, EventArgs e)
        {
            StudentAttendenceClass SR = new StudentAttendenceClass();
            string status             = AttendenceAtatus.GetItemText(AttendenceAtatus.SelectedItem);
            string Attendence         = AttendencedateComobox.Text;
            string student            = StudentName1.GetItemText(StudentName1.SelectedItem);

            SR.Edit(globalindex, globalindex2, student, Attendence, status);
            StudentAttendenceRecord.DataSource = null;
            AttendenceAtatus.Text      = "";
            AttendencedateComobox.Text = "";
            StudentName1.Text          = "";
            StudentAttendence_Load(sender, e);
            ADD.Visible = true;
        }
        private void StudentAttendenceRecord_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            StudentAttendenceClass STR = new StudentAttendenceClass();
            ListofClasses          lt  = new ListofClasses();
            int index = StudentAttendenceRecord.CurrentCell.RowIndex;

            DataGridViewRow r     = StudentAttendenceRecord.Rows[index];
            int             STUid = Convert.ToInt32(r.Cells[0].Value);
            int             ASSid = Convert.ToInt32(r.Cells[1].Value);

            if (StudentAttendenceRecord.Columns[e.ColumnIndex].Name == "Delete")
            {
                DialogResult result = MessageBox.Show("Do You Want to delete data against the id ?" + STUid, "Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result.Equals(DialogResult.OK))
                {
                    STR.Delete(ASSid, STUid);
                    MessageBox.Show("Data has been deleted successfully");
                    StudentAttendenceRecord.DataSource = null;
                    StudentAttendence_Load(sender, e);
                    if (ADD.Visible == false)
                    {
                        ADD.Visible = true;
                    }
                }
                else
                {
                    return;
                }
            }
            if (StudentAttendenceRecord.Columns[e.ColumnIndex].Name == "Edit")
            {
                StudentAttendenceClass SC = new StudentAttendenceClass();
                comoboxvalues();
                StudentName1.Text = SC.RegistrationNoStudent(Convert.ToInt32(r.Cells[1].Value));
                int ATTId = Convert.ToInt32(r.Cells[0].Value);
                AttendencedateComobox.SelectedText = SC.AttendenceDate(ATTId);
                int ASS = Convert.ToInt32(r.Cells[2].Value);
                AttendenceAtatus.SelectedText = SC.Staus(ASS);
                globalindex  = Convert.ToInt32(r.Cells[1].Value);
                globalindex2 = Convert.ToInt32(r.Cells[0].Value);
                if (ADD.Visible)
                {
                    ADD.Visible = false;
                }
            }
        }
 private void ADD_Click(object sender, EventArgs e)
 {
     if (AttendenceAtatus.Text != "" && AttendencedateComobox.Text != "" && StudentName1.Text != "")
     {
         StudentAttendenceClass SR = new StudentAttendenceClass();
         string status             = AttendenceAtatus.Text;
         string Attendence         = AttendencedateComobox.Text;
         string student            = StudentName1.Text;
         SR.ADD(student, Attendence, status);
         StudentAttendenceRecord.DataSource = null;
         AttendenceAtatus.Text      = "";
         AttendencedateComobox.Text = "";
         StudentName1.Text          = "";
         StudentAttendence_Load(sender, e);
     }
     else
     {
         MessageBox.Show("Please fill all the fields to further proceed");
     }
 }
        public void comoboxvalues()
        {
            StudentAttendenceClass SR  = new StudentAttendenceClass();
            ListofClasses          lt1 = new ListofClasses();

            SR.AddAttendenceDate();
            int length = lt1.AttendenceDate1.Count();

            AttendencedateComobox.Items.Clear();

            for (int i = 0; i < length; i++)
            {
                AttendencedateComobox.Items.Add(lt1.AttendenceDate1.ElementAt(i));
            }
            SR.addStudentname();
            int length1 = lt1.Studentname.Count();

            StudentName1.Items.Clear();

            for (int i = 0; i < length1; i++)
            {
                StudentName1.Items.Add(lt1.Studentname.ElementAt(i));
            }
        }
 /// <summary>
 ///  This function used to Add  Student Aytendancein the StudentAttendenceClass
 /// </summary>
 /// <param name="st">Indicate the object of type StudentAttendanceClass</param>
 public void addIntoStudentAttendence(StudentAttendenceClass st)
 {
     SAC.Add(st);
 }