private void btnDelete_Click(object sender, EventArgs e) { Form form = new frmChild_BookTitle(); int selectedrowindex = dgvSearch.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dgvSearch.Rows[selectedrowindex]; if (selectedRow.Cells[0].Value != null && selectedRow.Cells[0].Value.ToString() != string.Empty) { string value = (string)selectedRow.Cells[0].Value; bool result = false; switch (TypeOfSearch) { case 0: BUS.BookTitleBUS bkTitle = new BUS.BookTitleBUS(); result = bkTitle.DeleteBookTitle(value); break; case 1: BUS.AuthorBUS author = new BUS.AuthorBUS(); result = author.DeleteAuthor(value); break; case 2: BUS.CategoryBUS cate = new BUS.CategoryBUS(); result = cate.DeleteCategory(value); break; case 3: BUS.UserBUS user = new BUS.UserBUS(); result = user.DeleteUser(value); break; case 4: BUS.BookBUS bk = new BUS.BookBUS(); result = bk.DeleteAuthor(value); break; case 5: BUS.InventoryBUS inven = new BUS.InventoryBUS(); result = inven.DeleteInventory(value); break; } if (result) { LoadData(); MessageBox.Show(this, "Delete Successful", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Delete Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(this, "Can not delete null cells", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnNew_Click(object sender, EventArgs e) { Form form = new frmChild_BookTitle(0); switch (TypeOfSearch) { case 0: form = new frmChild_BookTitle(0); break; case 1: form = new frmChild_Author(0); break; case 2: form = new frmChild_Category(0); break; case 3: form = new frmChild_User(0); break; case 4: form = new frmChild_Book(0); break; case 5: form = new frmChild_Inventory(0); break; } form.MdiParent = this.MdiParent; form.FormClosing += (object sender1, FormClosingEventArgs ee) => { if (form.DialogResult == DialogResult.OK) { //MessageBox.Show("OK!"); LoadData(); } }; form.Show(); /**DialogResult r = form.ShowDialog(); * if (r == DialogResult.OK) * { * LoadData(); * } **/ }
private void btnUpdate_Click(object sender, EventArgs e) { Form form = new frmChild_BookTitle(1); int selectedrowindex = 0; DataGridViewRow selectedRow = null; try { selectedrowindex = dgvSearch.SelectedCells[0].RowIndex; selectedRow = dgvSearch.Rows[selectedrowindex]; List <String> list = new List <string>(); //MessageBox.Show(selectedRow.Cells[0].Value.ToString()); if (selectedRow.Cells[0].Value != null && selectedRow.Cells[0].Value.ToString() != string.Empty) { //value = (string)selectedRow.Cells[0].Value; foreach (DataGridViewCell cell in selectedRow.Cells) { if (cell.Value != null) { list.Add(cell.Value.ToString()); } else { list.Add(""); } } switch (TypeOfSearch) { case 0: form = new frmChild_BookTitle(1, list); break; case 1: form = new frmChild_Author(1, list); break; case 2: form = new frmChild_Category(1, list); break; case 3: form = new frmChild_User(1, list); break; case 4: form = new frmChild_Book(1, list); break; case 5: form = new frmChild_Inventory(1, list); break; } form.MdiParent = this.MdiParent; form.FormClosing += (object sender1, FormClosingEventArgs ee) => { if (form.DialogResult == DialogResult.OK) { LoadData(); } }; form.Show(); } else { MessageBox.Show(this, "Can not update null cells", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { MessageBox.Show("Choose to update"); } /** * DialogResult r = form.ShowDialog(); * if (r == DialogResult.OK) * { * LoadData(); * } **/ }