private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView2.Rows[e.RowIndex].Cells[1].Value == null) { return; } if (e.ColumnIndex == 5 && e.RowIndex >= 0) { DialogResult dialogResult = MessageBox.Show("Are you sure to delete Species " + this.dataGridView2.Rows[e.RowIndex].Cells[1].Value + "?", "Delete", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { String speciescode = this.dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString(); MainMenu frm = new MainMenu(); Int32 id = frm.get_id_data_table("tbspecies", "speciescode", e.RowIndex); frm.delete_table_id("tbspecies", id); //frm.delete_table("tbspecies", "speciescode", speciescode); //dataGridView2.Rows.RemoveAt(dataGridView2.SelectedRows[0].Index); loaddataspecies(); } } if (e.ColumnIndex == 4 && e.RowIndex >= 0) { //capture id species MainMenu frm = new MainMenu(); idspecies = frm.get_id_data_table("tbspecies", "speciescode", e.RowIndex); txtspeciesname.Text = this.dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString(); txtscientificname.Text = this.dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString(); txtasfiscode.Text = this.dataGridView2.Rows[e.RowIndex].Cells[3].Value.ToString(); } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == dataGridView1.Columns["Delete"].Index && e.RowIndex >= 0) { DialogResult dialogResult = MessageBox.Show("Are you sure to delete user account " + this.dataGridView1.Rows[e.RowIndex].Cells[1].Value + "?", "Delete", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { MainMenu frm = new MainMenu(); Int32 id = frm.get_id_data_table("tbuser", "username", e.RowIndex); string connString = Konek(); MySqlConnection conn3 = null; conn3 = new MySqlConnection(connString); conn3.Open(); MySqlCommand mySql = conn3.CreateCommand(); mySql.CommandText = "delete from tbuser where id=@id"; mySql.Parameters.AddWithValue("@id", id); mySql.ExecuteNonQuery(); conn3.Close(); //Delete from Receive_Truck dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index); loaddatauser(); } } if (e.ColumnIndex == dataGridView1.Columns["Password"].Index && e.RowIndex >= 0) { DialogResult dialogResult = MessageBox.Show("Are you sure to change password for " + this.dataGridView1.Rows[e.RowIndex].Cells[1].Value + "?", "Change Password", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { panel2.Visible = true; txtuseredit.Text = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); return; } } if (e.ColumnIndex == 8 && e.RowIndex >= 0) { if (dataGridView1.Columns["Edit"].HeaderText.Equals("Edit")) { txtlongname.Text = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); txtpersonalid.Text = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); txtjobtitle.Text = this.dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); txtnationality.Text = this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); String tgl = this.dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); dateTimePicker1.Value = DateTime.Parse(tgl); txtuserid.Text = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); txtuserid.Visible = false; label7.Visible = false; label8.Visible = false; label9.Visible = false; txtpassword.Visible = false; txtretypepassword.Visible = false; this.flag.Text = "edit"; MainMenu frm = new MainMenu(); List <object[]> data = new List <object[]>(); Int32 id = frm.get_id_data_table("tbuser", "username", e.RowIndex); data = frm.get_data_table_id("tbuser", id); //data = frm.get_data_table_string("tbuser", "username", txtuserid.Text); if (data[0][7] != null || !data[0][7].ToString().Equals("")) { comboBox1.Text = data[0][7].ToString(); } else { comboBox1.Text = "Male"; } txtnationality.Text = data[0][8].ToString(); txtpersonalid.Text = data[0][4].ToString(); if (data[0][10] != null) { dateTimePicker1.Value = Convert.ToDateTime(data[0][10]); } String useraccess = data[0][9].ToString(); load_access_user(useraccess); /* * if (useraccess.ToLowerInvariant().Contains("master")) * { * cmaster.Checked = true; * } * else * { * cmaster.Checked = false; * } * * if (useraccess.ToLowerInvariant().Contains("receiving")) * { * creceiving.Checked = true; * } * else * { * creceiving.Checked = false; * } * * if (useraccess.ToLowerInvariant().Contains("cutting")) * { * ccutting.Checked = true; * } * else * { * ccutting.Checked = false; * } * * if (useraccess.ToLowerInvariant().Contains("retouching")) * { * cretouching.Checked = true; * } * else * { * cretouching.Checked = false; * } * * if (useraccess.ToLowerInvariant().Contains("boxing")) * { * cpacking.Checked = true; * } * else * { * cpacking.Checked = false; * } * * if (useraccess.ToLowerInvariant().Contains("boxing")) * { * cpacking.Checked = true; * } * else * { * cpacking.Checked = false; * } * * if (useraccess.ToLowerInvariant().Contains("packing")) * { * cstuffing.Checked = true; * } * else * { * cstuffing.Checked = false; * } * * if (useraccess.ToLowerInvariant().Contains("invoice")) * { * cpackinglist.Checked = true; * } * else * { * cpackinglist.Checked = false; * } */ return; } } }