示例#1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //ColorPicker
            if (dataGridView1.CurrentCell.ColumnIndex == 1 && e.RowIndex != -1 && e.RowIndex != dataGridView1.RowCount - 1)
            {
                if (dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null)
                {
                    Console.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                    ColorPicker cPicker = new ColorPicker(this, dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                    cPicker.ShowDialog();
                }
            }
            //Edit
            if (dataGridView1.CurrentCell.ColumnIndex == 6 && e.RowIndex != -1 && e.RowIndex != dataGridView1.RowCount - 1)
            {
                if (dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null)
                {
                    string       id         = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    AddNewCourse editCourse = new AddNewCourse(this, id);
                    editCourse.Show();
                }
            }
            //Delete
            if (dataGridView1.CurrentCell.ColumnIndex == 7 && e.RowIndex != -1 && e.RowIndex != dataGridView1.RowCount - 1)
            {
                if (dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null)
                {
                    DialogResult dialogResult = MessageBox.Show("กดยืนยัน เพื่อลบรายวิชานี้", "Delete this course", MessageBoxButtons.OKCancel);
                    if (dialogResult == DialogResult.OK)
                    {
                        SQLiteConnection myconn = new SQLiteConnection(@"Data Source = .\Database.db");
                        myconn.Open();
                        string query = "DELETE FROM Course WHERE ID = " + dataGridView1.Rows[e.RowIndex].Cells[0].Value;

                        SQLiteCommand command = new SQLiteCommand(query, myconn);
                        command.ExecuteNonQuery();
                        myconn.Close();
                        //TableCourse.Controls.RemoveByKey(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                        clearTable();
                        updateTable();
                    }
                    else if (dialogResult == DialogResult.Cancel)
                    {
                        //do nothing
                    }
                }
            }
        }
示例#2
0
        private void button2_Click(object sender, EventArgs e)
        {
            AddNewCourse addNewCourse = new AddNewCourse(this);

            addNewCourse.Show();
        }