Example #1
0
        private void operationDataGrid(object sender, DataGridViewCellEventArgs e, int which)
        {
            var senderGrid            = (DataGridView)sender;
            DataGridViewColumn column = senderGrid.Columns[e.ColumnIndex];
            DataGridViewRow    row    = senderGrid.Rows[e.RowIndex];
            String             table  = (which == 0) ? "candidate" : "society";

            if (column is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                if (column.HeaderText == "Edit")
                {
                    string[] value = new string[4];
                    if (table == "candidate")
                    {
                        value[0] = row.Cells["NoKTP"].Value.ToString();
                        value[1] = row.Cells["NoUrut"].Value.ToString();
                        value[2] = row.Cells["Jabatan"].Value.ToString();
                        value[3] = row.Cells["Quote"].Value.ToString();
                        FormCandidate formCandidate = new FormCandidate(value);
                        formCandidate.Show();
                    }
                    else if (table == "society")
                    {
                        value[0] = row.Cells["NoKTP"].Value.ToString();
                        value[1] = row.Cells["Nama"].Value.ToString();
                        value[2] = row.Cells["Alamat"].Value.ToString();
                        value[3] = row.Cells["Kependudukan"].Value.ToString();
                        FormSociety formSociety = new FormSociety(value);
                        formSociety.Show();
                    }
                }
                else if (column.HeaderText == "Remove")
                {
                    string       nama   = row.Cells["Nama"].Value.ToString();
                    string       noKTP  = row.Cells["NoKTP"].Value.ToString();
                    DialogResult result = MessageBox.Show("Really remove " + nama + "?", "WARNING", MessageBoxButtons.YesNo);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        try
                        {
                            MySqlConnection connectDelete = new MySqlConnection(conInfo);
                            connectDelete.Open();
                            string       query   = "delete from " + table + " where NoKTP=" + noKTP;
                            MySqlCommand command = new MySqlCommand(query, connectDelete);
                            command.ExecuteNonQuery();
                            MessageBox.Show("Finish");
                            connectDelete.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        loadDatabase();
                    }
                }
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            FormSociety formSociety = new FormSociety();

            formSociety.Show();
        }