예제 #1
0
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(constring);

            con.Open();
            SqlCommand cmd = new SqlCommand("INSERT INTO StudentMes (Sender, Receiver, Body) VALUES (@Sender, @Receiver, @Body)", con);

            cmd.Parameters.Add("@Sender", secretary.getName());
            cmd.Parameters.Add("@Receiver", student.getID());
            cmd.Parameters.Add("@Body", textBox1.Text);

            if (cmd.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Inserting Data Successfully");
                con.Close();
                pictureBox1_Click(sender, e);   //  exit
            }
            else
            {
                MessageBox.Show("Inserting Data Failed");
            }
        }
예제 #2
0
        private void StudentMessage_Load(object sender, EventArgs e)
        {
            SqlConnection conDataBase = new SqlConnection(constring);
            SqlCommand    cmdDataBase = new SqlCommand("select * from StudentMes", conDataBase);

            try
            {
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmdDataBase;
                DataTable dt = new DataTable();
                sda.Fill(dt);

                DataView dv = new DataView(dt);
                dv.RowFilter = string.Format("Receiver Like '%{0}%'", student.getID());



                dataGridView1.DataSource = dv;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private void student_schedule_Load(object sender, EventArgs e)
        {
            // start build schedule

            int top = 50, index = 0;
            int left = 100;
            int i, j, counter = 0;

            for (i = 0; i < 6; i++)
            {
                for (j = 0; j < 12; j++)
                {
                    buttonArray[i, j]        = new Button();
                    buttonArray[i, j].Click += new System.EventHandler(ClickedButton);
                    buttonArray[i, j].Size   = new Size(120, 40);
                    buttonArray[i, j].Left   = left;
                    buttonArray[i, j].Top    = top;
                    this.Controls.Add(buttonArray[i, j]);
                    top += buttonArray[i, j].Height + 2;
                }
                top   = 50;
                left += 125;
            }

            // finish build schedule visualy

            //load the schedule of the student
            //----------------------------------------------

            SqlConnection conn = new SqlConnection(constring);

            conn.Open();
            SqlCommand cmd0 = conn.CreateCommand();

            cmd0.CommandType = CommandType.Text;
            cmd0.CommandText = "select * from student_schedule";
            cmd0.ExecuteNonQuery();
            DataTable      dt0 = new DataTable();
            SqlDataAdapter da0 = new SqlDataAdapter(cmd0);

            da0.Fill(dt0);

            SqlCommand cmd1 = conn.CreateCommand();

            cmd1.CommandType = CommandType.Text;
            cmd1.CommandText = "select * from Courses";
            cmd1.ExecuteNonQuery();
            DataTable      dt1 = new DataTable();
            SqlDataAdapter da1 = new SqlDataAdapter(cmd1);

            da1.Fill(dt1);

            SqlCommand cmd2 = conn.CreateCommand();

            cmd2.CommandType = CommandType.Text;
            cmd2.CommandText = "select * from Lessons";
            cmd2.ExecuteNonQuery();
            DataTable      dt2 = new DataTable();
            SqlDataAdapter da2 = new SqlDataAdapter(cmd2);

            da2.Fill(dt2);

            foreach (DataRow dr0 in dt0.Rows)
            {
                if (dr0["StudentID"].Equals(student.getID()))
                {
                    foreach (DataRow dr2 in dt2.Rows)
                    {
                        if (dr0["LessonID"].Equals(dr2["LessonID"].ToString()))
                        {
                            foreach (DataRow dr1 in dt1.Rows)
                            {
                                if (dr2["CourseID"].Equals(dr1["Id"].ToString()))
                                {
                                    Courses temp = new Courses(dr2["CourseID"].ToString(), dr1["Name"].ToString(), dr2["Day"].ToString(), dr2["StartH"].ToString(), dr2["EndH"].ToString(), dr2["ClassName"].ToString(), dr2["LessonType"].ToString(), dr2["LessonID"].ToString(), dr2["TSID"].ToString(), dr1["Pre"].ToString(), student.getID());
                                    index++;
                                    for (int k = temp.getStartH(); k < temp.getEndH(); k++)
                                    {
                                        buttonArray[temp.getDay(), k].Text = temp.getName() + " " + temp.getType();
                                    }
                                    buttonArray[temp.getDay(), temp.getStartH()].Height = buttonArray[temp.getDay(), temp.getStartH()].Height * (temp.getEndH() - temp.getStartH()) + 2 * (temp.getEndH() - temp.getStartH() - 1);
                                    buttonArray[temp.getDay(), temp.getStartH()].Text   = temp.getName() + " " + temp.getType();
                                }
                            }
                        }
                    }
                }
            }

            //----------------------------------------------

            //-------------------------------------------------------
            //load combobox - courses that student able to register

            // getting the courses by semester and department into combobox1
            comboBox2.Items.Clear();
            comboBox1.Items.Clear();

            foreach (DataRow dr2 in dt2.Rows)
            {
                foreach (DataRow dr in dt1.Rows)
                {
                    if (student.getDep().Equals(dr["Department"]) && student.getSemester().Equals(dr["Semester"]))
                    {
                        if (dr["Id"].ToString().Equals(dr2["CourseID"]))
                        {
                            {
                                if (checkifclassisfull(dr2["LessonID"].ToString()) == 1)
                                {
                                    comboBox1.Items.Add(dr["Name"].ToString() + " " + dr2["LessonType"]);
                                    comboBox2.Items.Add(dr["Name"].ToString() + " " + dr2["LessonType"]);
                                    counter++;
                                }
                            }
                        }
                    }
                }
            }
            courses = new Courses[counter];
            i       = 0;

            // fill courses array with courses that the student can learn

            j = 0;
            foreach (DataRow dr2 in dt2.Rows)
            {
                foreach (DataRow dr in dt1.Rows)
                {
                    if (student.getDep().Equals(dr["Department"]) && student.getSemester().Equals(dr["Semester"]))
                    {
                        if (dr["Id"].ToString().Equals(dr2["CourseID"]))
                        {
                            for (j = 0; j < i; j++)
                            {
                                if (courses[j].getLessonID().Equals(dr2["LessonID"]))
                                {
                                    break;
                                }
                            }
                            if (i == j)
                            {
                                courses[i] = new Courses(dr["Id"].ToString(), dr["Name"].ToString(), dr2["Day"].ToString(), dr2["StartH"].ToString(), dr2["EndH"].ToString(), dr2["ClassName"].ToString(), dr2["LessonType"].ToString(), dr2["LessonID"].ToString(), dr2["TSID"].ToString(), dr["Pre"].ToString(), student.getID());
                                i++;
                            }
                        }
                    }
                }
            }
            conn.Close();
        }