private void dataGridAnnounce_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { AddStafID.Text = dataGridAnnounce.Rows[e.RowIndex].Cells[1].Value.ToString(); AnnonceCombo.SelectedIndex = AnnonceCombo.FindStringExact(dataGridAnnounce.Rows[e.RowIndex].Cells[2].Value.ToString()); AddDate.Value = Convert.ToDateTime(dataGridAnnounce.Rows[e.RowIndex].Cells[3].Value.ToString()); Addsubject.Text = dataGridAnnounce.Rows[e.RowIndex].Cells[4].Value.ToString(); AddDescription.Text = dataGridAnnounce.Rows[e.RowIndex].Cells[5].Value.ToString(); hidebox.Text = dataGridAnnounce.Rows[e.RowIndex].Cells[6].Value.ToString(); }
private void SAveAdd_Click(object sender, EventArgs e) { string query = ""; int AnnonceKey = ((KeyValuePair <int, string>)AnnonceCombo.SelectedItem).Key; String AnnounceValue = ((KeyValuePair <int, string>)AnnonceCombo.SelectedItem).Value; if (AddStafID.Text.Trim() == "") { MessageBox.Show("Please Enter Staff ID"); AddStafID.Focus(); return; } if (AnnonceKey < 1) { MessageBox.Show("Please Enter Announce Type"); AnnonceCombo.Focus(); return; } if (AddDate.Text == "") { MessageBox.Show("Please Enter Announce Date"); AddDate.Focus(); return; } if (Addsubject.Text.Trim() == "") { MessageBox.Show("Please Enter Subject"); Addsubject.Focus(); return; } if (AddDescription.Text.Trim() == "") { MessageBox.Show("Please Add Description "); AddDescription.Focus(); return; } try { if (hidebox.Text == "") { query = "INSERT INTO Announcement_Info(StaffID,AnnounceType,Date,Subject,Description) VALUES(" + Convert.ToInt32(AddStafID.Text) + ", '" + AnnounceValue + "', '" + AddDate.Value.ToString("yyyy/MM/dd") + "', '" + Addsubject.Text + "', '" + AddDescription.Text + "' )"; } else { query = "UPDATE Announcement_Info SET AnnounceType = '" + AnnounceValue + "', Date = '" + AddDate.Text + "', Subject= '" + Addsubject.Text + "',Description = '" + Addsubject.Text + "' WHERE Id = " + Convert.ToInt32(hidebox.Text); } if (DbAccess.ExecuteToDB(query)) { if (hidebox.Text == "") { MessageBox.Show("Saved Successfully!!!"); } else { MessageBox.Show("Updated Successfully!!!"); } } else { MessageBox.Show("Failed To Save!!!"); } } catch (Exception ex) { MessageBox.Show("Connection Error!!!"); } finally { Reset(); } }