/// <summary> /// Hàm thực hiện lệnh Insert, Update, Delete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PerformmAction(UserAction status) { try { var items = new LTcpip(); items.Id = Convert.ToInt32(txtPortID.Text); items.IPAddress = txtAddresIP.Text.Trim(); items.Description = txtDes.Text.Trim(); switch (status) { case UserAction.Insert: HaBusiness.InsertTCPIP(items); break; case UserAction.Update: HaBusiness.UpdateTcpip(items); break; case UserAction.Delete: HaBusiness.DeleteTcpip(items.Id); break; } } catch (Exception ex) { throw ex; } }
/// <summary> /// Xóa dữ liệu trên grdview /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void grdTcpip_KeyUp(object sender, KeyEventArgs e) { DataGridViewRow currentRow = grdTcpip.CurrentRow; if (currentRow != null) { if ((e.KeyCode == Keys.Delete) && (grdTcpip.CurrentRow != null)) { int pid = Convert.ToInt32(currentRow.Cells["colTcpId"].Value); if (MessageBox.Show("Bạn có muốn xóa ? ", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { HaBusiness.DeleteTcpip(pid); grdTcpip.Rows.Remove(currentRow); MessageBox.Show("Bạn đã xóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }