public void insertSessions(sessionModel session)
        {
            if (con.State.ToString() != "Open")
            {
                con.Open();
            }
            string q1 = "";

            if (session.Type == "Lecture")
            {
                q1 = "select LecHrs  from SubjectTable where SubCode = '" + session.subCode + "'";
            }
            else if (session.Type == "Tutorial ")
            {
                q1 = "select TuteHrs  from SubjectTable where SubCode = '" + session.subCode + "'";
            }
            else
            {
                q1 = "select LabHrs  from SubjectTable where SubCode = '" + session.subCode + "'";
            }


            SqlDataReader data = new SqlCommand(q1, con).ExecuteReader();
            string        hrs  = "";

            while (data.Read())
            {
                int i = 0;
                hrs = data.GetValue(0).ToString();
                i++;
            }


            string query = "INSERT INTO Session(Subject,subjectCode,type,GroupID,subgroup,studentcount,typeduration,Lecturers)  VALUES ('" + session.SubName + "','" + session.subCode + "','" + session.Type + "','" + session.groupId + "','" + session.subgId + "','" + session.studentcount + "','" + hrs.ToString() + "','" + session.lec + "')";

            SqlCommand com = new SqlCommand(query, con);
            int        ret = com.ExecuteNonQuery();

            if (ret != 0)
            {
                /*  string searchId = "select subjectCode from Session where subjectCode = '" + session.subCode + "'";
                 * SqlDataReader data = new SqlCommand(searchId, con).ExecuteReader();
                 * string id = data.GetValue(0).ToString();*/

                foreach (string str in session.lecturers)
                {
                    string     insertlectures = "INSERT INTO sessionLecturer(subjectCode,Lecturer)  VALUES ('" + session.subCode + "','" + str + "')";
                    SqlCommand com1           = new SqlCommand(insertlectures, con);
                    int        ret1           = NewMethod(com1);
                }
                System.Windows.Forms.MessageBox.Show("Adding Successful !!");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Adding Error !!");
            }


            con.Close();
        }
        private void searchSession_Click(object sender, EventArgs e)
        {
            session searchsession = new session();

            sessionModel sessionModel = new sessionModel();

            sessionModel.SubName = subjectBox.Text;
            sessionModel.groupId = Int32.Parse(GroupBox.Text);
            sessionModel.lec     = lecturerbox.Text;

            //System.Windows.Forms.MessageBox.Show(sessionModel.lec.ToString());

            findSessionList.DataSource = searchsession.SearchSession(sessionModel);
        }
        public DataTable SearchSession(sessionModel sessionModel)
        {
            if (con.State.ToString() != "Open")
            {
                con.Open();
            }

            DataTable dataTable = new DataTable();
            string    query     = "SELECT Session.Subject, Session.subjectCode, Session.type,Session.GroupID ,Session.subgroup, Session.studentcount, " +
                                  "Session.typeduration,sessionLecturer.Lecturer FROM Session left JOIN sessionLecturer ON Session.subjectCode = sessionLecturer.subjectCode " +
                                  " where Session.GroupID ='" + sessionModel.groupId + "' and Session.Subject = '" + sessionModel.SubName + "' and sessionLecturer.Lecturer = '" + sessionModel.lec + "' ";

            SqlDataReader data = new SqlCommand(query, con).ExecuteReader();

            dataTable.Load(data);

            return(dataTable);
        }
        private void Createsessions_Click(object sender, EventArgs e)
        {
            if (type.Text != "" && Gid.Text != "" && Scount.Text != "" && subNamelist.Text != "" && subcodeList.Text != "" && lecList.Items.Count != 0)
            {
                foreach (DataGridViewRow row in sessionList.Rows)
                {
                    if (row.Cells[1].Value.ToString().Equals(subcodeList.Text) && row.Cells[2].Value.ToString().Equals(type.Text) && row.Cells[3].Value.ToString().Equals(Gid.Text))
                    {
                        if (type.Text == "Practical")
                        {
                            if (row.Cells[4].Value.ToString().Equals(subBox.Text))
                            {
                                System.Windows.Forms.MessageBox.Show("This session already added !", "Warning").ToString();
                                return;
                            }
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("This session already added !", "Warning").ToString();
                            return;
                        }
                    }
                }

                sessionModel sessionmodel = new sessionModel();
                sessionmodel.SubName = subNamelist.Text;
                sessionmodel.subCode = subcodeList.Text;
                sessionmodel.Type    = type.Text;
                sessionmodel.groupId = Int32.Parse(Gid.Text);

                sessionmodel.subgId       = subBox.Text;
                sessionmodel.studentcount = Int32.Parse(Scount.Text);

                sessionmodel.lec = "";

                for (int i = 0; i < lecList.Items.Count; i++)
                {
                    sessionmodel.lec = sessionmodel.lec + lecList.Items[i].Text + ",";
                }

                sessionmodel.lecturers = lec;
                session session = new session();
                session.insertSessions(sessionmodel);

                lecList.Items.Clear();
                lecturerlist.Text = "";
                subNamelist.Text  = "";
                subcodeList.Text  = "";

                lecturerbox.DataSource = session.getLectures();

                subjectBox.DataSource = session.getSubjects();

                GroupBox.DataSource = session.getGroupID();

                //sessionList.DataSource = session.getSessiondatatoTable();


                sessionList.DataSource = session.getSessiondatatoTable();

                flowLayoutPanel1.Controls.Clear();

                for (int i = 0; i < session.getSessiondatatoTable().Rows.Count; i++)
                {
                    show_data(session.getSessiondatatoTable(), i);
                }
            }
            else
            {
                string ans = System.Windows.Forms.MessageBox.Show("Please fill all the require fields !", "Warning").ToString();
            }
        }