/// <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> /// Load thông tin Tcpip /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LoadTcpip() { try { _dtTcpip = HaBusiness.GetAllTCPIP(); grdTcpip.DataSource = _dtTcpip; } 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); } } } }
private void buttonX1_Click(object sender, EventArgs e) { LTcpip items; for (int i = 0; i < _dtTcpip.Rows.Count; i++) { DataRow dataRow = _dtTcpip.Rows[i]; if (dataRow.RowState == DataRowState.Modified) { items = new LTcpip(dataRow[LTcpip.Columns.Id]); items.IPAddress = dataRow[LTcpip.Columns.IPAddress].ToString(); items.Description = dataRow[LTcpip.Columns.Description].ToString(); HaBusiness.UpdateTcpip(items); MessageBox.Show("Bạn đã cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (dataRow.RowState == DataRowState.Added) { items = new LTcpip(); items.IPAddress = dataRow[LTcpip.Columns.IPAddress].ToString(); items.Description = dataRow[LTcpip.Columns.Description].ToString(); string id = HaBusiness.InsertTCPIP(items); //check địa chỉ Ip nếu đã tồn tại if (id == "-1") { MessageBox.Show("Tên cổng đã" + items.IPAddress.ToString() + "đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); dataRow.Delete(); grdTcpip.Focus(); } // ko tồn tại sẽ insert else { dataRow[LTcpip.Columns.Id] = id; MessageBox.Show("Bạn đã Thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); //dataRow[LTcpip.Columns.Id] = id; } } } _dtTcpip.AcceptChanges(); }
private void LoadAllTCPIPPORT() { _tblTCPIP = HaBusiness.GetAllTCPIP(); grdTCP.DataSource = _tblTCPIP; }