コード例 #1
0
        private void GetDateBtn_Click(object sender, EventArgs e)
        {
            //check if the records exist if yes load them for editing if not create each record for each student
            // and load for edit
            AttendanceRecTableTableAdapter ada = new AttendanceRecTableTableAdapter();
            DataTable dt = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text);

            if (dt.Rows.Count > 0)
            {
                // we have records we can edit
                DataTable dt_new = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text);
                dataGridView1.DataSource = dt_new;
            }
            else
            {
                // create record for each student here
                // get class students list
                StudentTableTableAdapter student_adaptor = new StudentTableTableAdapter();

                DataTable dt_students = student_adaptor.GetDataByClassID((int)metroComboBox1.SelectedValue);


                foreach (DataRow row in dt_students.Rows)
                {
                    // insert new rec for student
                    ada.InsertQuery((int)row[0], (int)metroComboBox1.SelectedValue, dateTimePicker1.Text, "", row[1].ToString(), metroComboBox1.Text);
                }

                DataTable dt_new = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text);
                dataGridView1.DataSource = dt_new;
            }

            // TODO: This line of code loads data into the 'dataSet1.AttendanceRecTable' table. You can move, or remove it, as needed.
            this.attendanceRecTableTableAdapter.Fill(this.dataSet1.AttendanceRecTable);
        }
コード例 #2
0
        private void metroButton5_Click(object sender, EventArgs e)
        {
            // get students of this selection
            StudentTableTableAdapter student_adaptor = new StudentTableTableAdapter();
            DataTable dt_students = student_adaptor.GetDataByClassID((int)metroComboBox2.SelectedValue);

            AttendanceRecTableTableAdapter ada = new AttendanceRecTableTableAdapter();
            int presence = 0;
            int absense  = 0;
            int late     = 0;
            int excused  = 0;


            // loop through students and get values
            foreach (DataRow row in dt_students.Rows)
            {
                presence = ada.ScalarQuery(dateTimePicker2.Value.Month, row[1].ToString(), "present").Value;
                absense  = ada.ScalarQuery(dateTimePicker2.Value.Month, row[1].ToString(), "absent").Value;
                late     = ada.ScalarQuery(dateTimePicker2.Value.Month, row[1].ToString(), "late").Value;
                excused  = ada.ScalarQuery(dateTimePicker2.Value.Month, row[1].ToString(), "excused").Value;

                // add to list view
                ListViewItem litem = new ListViewItem();

                litem.Text = row[1].ToString();
                litem.SubItems.Add(presence.ToString());
                litem.SubItems.Add(absense.ToString());
                litem.SubItems.Add(late.ToString());
                litem.SubItems.Add(excused.ToString());

                listView1.Items.Add(litem);
            }
        }