コード例 #1
0
 private void removeButton_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure?", "delete student", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         StuDB student = new StuDB();
         int   id      = Convert.ToInt32(AF_id_txt.Text);
         if (MessageBox.Show("Are you sure?", "delete student", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             if (student.deleteStudent(id))
             {
                 MessageBox.Show("Done", "delete student", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 AF_address_txt.Text  = "";
                 AF_dob_txt.Value     = DateTime.Now;
                 AF_id_txt.Text       = "";
                 AF_fullname_txt.Text = "";
                 AF_phone_txt.Text    = "";
                 AF_picture_pic       = null;
             }
             else
             {
                 MessageBox.Show("Error", "delete student", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }
コード例 #2
0
        private void statics_Load(object sender, EventArgs e)
        {
            DB mydb = new DB();

            panTotalColor  = PanelTotal.BackColor;
            panMaleColor   = PanelMale.BackColor;
            panFemaleColor = PanelFemale.BackColor;



            StuDB student = new StuDB();

            mydb.openConnectionState();
            SqlDataAdapter adapter = new SqlDataAdapter("Select * from student11 ", mydb.GetConnection);
            DataTable      table   = new DataTable();

            adapter.Fill(table);
            double total = Convert.ToDouble(table.Rows.Count);


            SqlDataAdapter adapter1 = new SqlDataAdapter("Select * from student11 where gender ='Male      '", mydb.GetConnection);
            DataTable      table1   = new DataTable();

            adapter1.Fill(table1);
            double totalMale = Convert.ToDouble(table1.Rows.Count);


            SqlDataAdapter adapter2 = new SqlDataAdapter("Select * from student11 where gender ='Female    '", mydb.GetConnection);
            DataTable      table2   = new DataTable();

            adapter2.Fill(table2);
            double totalFemale = Convert.ToDouble(table2.Rows.Count);

            mydb.closeConnection();


            double maleStudentsPercentage   = (totalMale * (100 / total));
            double femaleStudentsPercentage = (totalFemale * (100 / total));

            LabelTotal.Text = ("Total Students: " + total.ToString());
            maleLable.Text  = ("Male : " + (maleStudentsPercentage.ToString("0.00") + "%"));
            Female.Text     = ("Female : " + (femaleStudentsPercentage.ToString("0.00") + "%"));

            if (femaleStudentsPercentage == 0)
            {
                chart2.Series["s1"].Points.AddXY("Male", "" + maleStudentsPercentage);
            }
            else if (maleStudentsPercentage == 0)
            {
                chart2.Series["s1"].Points.AddXY(" ", "" + maleStudentsPercentage);
                chart2.Series["s1"].Points.AddXY("Female", "" + femaleStudentsPercentage);
            }
            else
            {
                chart2.Series["s1"].Points.AddXY("Male", "" + maleStudentsPercentage);
                chart2.Series["s1"].Points.AddXY("Female", "" + femaleStudentsPercentage);
            }
        }
コード例 #3
0
        public DataTable MakeStudentScoreResultTable()
        {
            try
            {
                StuDB  student = new StuDB();
                COURSE course  = new COURSE();
                SCORE  score   = new SCORE();

                //create column

                DataTable result = student.getAllBriefInfo();
                result.Columns[0].ColumnName = "Id";
                result.Columns[1].ColumnName = "Full Name";


                DataTable coursesLabel = course.allLabel_IdOrder();
                DataTable briefInfo    = student.getAllBriefInfo();
                DataTable scores       = score.getALL_IdCourseOrder();
                DataTable avgScore     = score.getAvg_byStudent();

                for (int i = 0; i < coursesLabel.Rows.Count; i++)
                {
                    result.Columns.Add(coursesLabel.Rows[i][1].ToString().Trim());
                }

                result.Columns.Add("Result");

                //fill score to table
                int scoreRow = 0;
                for (int row = 0; row < result.Rows.Count; row++)
                {
                    int courseIndex = 0;
                    while (result.Rows[row][0].ToString().Trim() == scores.Rows[scoreRow][0].ToString().Trim())
                    {
                        result.Rows[row][courseIndex + 3] = scores.Rows[scoreRow][2].ToString().Trim();
                        courseIndex++;
                        scoreRow++;
                        if (scoreRow > scores.Rows.Count - 1)
                        {
                            break;
                        }
                    }
                }
                for (int row = 0; row < result.Rows.Count; row++)
                {
                    result.Rows[row][result.Columns.Count - 1] = avgScore.Rows[row][1].ToString().Trim();
                }

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #4
0
        private void edit_Click(object sender, EventArgs e)
        {
            StuDB    student = new StuDB();
            int      id      = Convert.ToInt32(ER_id_txt.Text);
            string   fname   = ER_name_txt.Text;
            DateTime dob     = ER_dob1.Value;
            string   phone   = ER_phone_txt.Text;
            string   address = ER_address_txt.Text;
            string   gender  = "Other";

            if (ER_male.Checked)
            {
                gender = "Male";
            }

            if (ER_female.Checked)
            {
                gender = "Female";
            }

            MemoryStream pic = new MemoryStream();

            int born_year = ER_dob1.Value.Year;
            int this_year = DateTime.Now.Year;

            if (((this_year - born_year) < 10) || ((this_year - born_year) > 100))
            {
                MessageBox.Show("The student's age must be between 10 and 100 years old", "Invalid Date of birth", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (Verify())
            {
                ER_picture.Image.Save(pic, ER_picture.Image.RawFormat);
                if (student.updateStudent(id, fname, dob, gender, phone, address, pic))
                {
                    MessageBox.Show("Student update successfully!", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Error!", "update student", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Empty fields", "edit student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #5
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            StuDB    student = new StuDB();
            int      id      = Convert.ToInt32(AF_id_txt.Text);
            string   fname   = AF_fullname_txt.Text;
            DateTime dob     = AF_dob_txt.Value;
            string   phone   = AF_phone_txt.Text;
            string   address = AF_address_txt.Text;
            string   gender  = "Other";

            if (AF_male_check.Checked)
            {
                gender = "Male";
            }

            if (AF_female_check.Checked)
            {
                gender = "Female";
            }

            MemoryStream pic       = new MemoryStream();
            int          born_year = AF_dob_txt.Value.Year;
            int          this_year = DateTime.Now.Year;

            if (((this_year - born_year) < 10) || ((this_year - born_year) > 100))
            {
                MessageBox.Show("The student's age must be between 10 and 100 years old", "Invalid Date of birth", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (Verify())
            {
                AF_picture_pic.Image.Save(pic, AF_picture_pic.Image.RawFormat);
                if (student.insertStudent(id, fname, dob, gender, phone, address, pic))
                {
                    MessageBox.Show("New student added successfully!", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Error!", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Empty fields", "Add student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            string name = search_txt.Text;

            if (search_txt.Text.Trim() == "")
            {
                MessageBox.Show("Error", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                DB         dataBase = new DB();
                SqlCommand command  = new SqlCommand(
                    "SELECT id, fullname, dob, gender, phone, address, picture FROM student11 WHERE address = @address or fullname = @address", dataBase.GetConnection);
                command.Parameters.Add("@address", SqlDbType.NVarChar).Value = search_txt.Text;

                dataBase.openConnectionState();
                StuDB     student = new StuDB();
                DataTable table   = student.getStudents(command);
                if (table.Rows.Count > 0)
                {
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    adapter.SelectCommand = command;
                    DataSet dataSet = new DataSet();
                    adapter.Fill(dataSet, "std");
                    dataBase.closeConnection();
                    listStu.RowTemplate.Height = 50;
                    DataTable table1 = dataSet.Tables["std"];
                    listStu.DataSource = table1;
                    listStu.ReadOnly   = true;
                    DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
                    imageColumn                = (DataGridViewImageColumn)listStu.Columns[6];
                    imageColumn.ImageLayout    = DataGridViewImageCellLayout.Stretch;
                    listStu.AllowUserToAddRows = false;
                }
                else
                {
                    MessageBox.Show("not found", "Find Student", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }