Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            seleteForm2 f = new seleteForm2();

            if (modify_studentID == null)
            {
                f.strr = dataGridView1.Rows[0].Cells[0].Value.ToString();
            }
            else
            {
                f.strr = modify_studentID;
            }
            this.Visible = false;
            f.Visible    = true;
            this.Hide();
        }
Example #2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboboxItem item = comboBox1.Items[comboBox1.SelectedIndex] as ComboboxItem;
            string       a    = item.Value.ToString();

            if (a == "newForm2")
            {
                newForm2 f = new newForm2();
                this.Visible = false;
                f.Visible    = true;
            }
            else if (a == "seleteForm2")
            {
                seleteForm2 f = new seleteForm2();
                if (modify_studentID == null)
                {
                    modify_studentID = dataGridView1.Rows[0].Cells[0].Value.ToString();
                    f.strr           = modify_studentID;
                }
                else
                {
                    f.strr = modify_studentID;
                }
                this.Visible = false;
                f.Visible    = true;
            }
            else if (a == "modifyForm2")
            {
                modifyForm2 f = new modifyForm2();
                this.Visible = false;
                if (modify_studentID == null)
                {
                    f.strr               = dataGridView1.Rows[0].Cells[0].Value.ToString();
                    f.aname              = dataGridView1.Rows[0].Cells[1].Value.ToString();
                    f.fmodifyChinese     = dataGridView1.Rows[0].Cells[2].Value.ToString();
                    f.fmodifyEnglish     = dataGridView1.Rows[0].Cells[3].Value.ToString();
                    f.fmodifymathematics = dataGridView1.Rows[0].Cells[4].Value.ToString();
                }
                else
                {
                    f.strr               = modify_studentID;
                    f.aname              = modify_name;
                    f.fmodifyChinese     = modify_Chinese;
                    f.fmodifyEnglish     = modify_English;
                    f.fmodifymathematics = modify_mathematics;
                }
                f.Visible = true;
            }
            else
            {
                string con, sql;
                con = "Server=.\\SQLExpress;Database=School_information_system;Integrated Security=true";
                sql = @"Delete From student WHERE StudentID = @value1;
                    Delete From DBsubject WHERE StudentID = @value2;";
                SqlConnection mycon    = new SqlConnection(con);
                SqlCommand    mySqlCmd = new SqlCommand(sql, mycon);
                mycon.Open();
                if (modify_studentID == null)
                {
                    modify_studentID = dataGridView1.Rows[0].Cells[0].Value.ToString();//讀取dataGrideview第一行資料Rows橫、cells直
                    //MessageBox.Show(modify_studentID);//對話視窗
                    //MessageBox.Show("!");
                    mySqlCmd.Parameters.AddWithValue("@value1", modify_studentID);
                    mySqlCmd.Parameters.AddWithValue("@value2", modify_studentID);
                    mySqlCmd.ExecuteNonQuery();
                    Form1 f = new Form1();
                    this.Visible = false;
                    f.Visible    = true;
                }
                else
                {
                    mySqlCmd.Parameters.AddWithValue("@value1", modify_studentID);
                    mySqlCmd.Parameters.AddWithValue("@value2", modify_studentID);
                    mySqlCmd.ExecuteNonQuery();
                    Form1 f = new Form1();
                    this.Visible = false;
                    f.Visible    = true;
                }
                mycon.Close();
            }
        }