private void EditProduct() { int rowIdxNeedEdit = dgvProduct.CurrentRow.Index; int productIDNeedEdit = Convert.ToInt32(dgvProduct.Rows[rowIdxNeedEdit].Cells["ProductID"].Value.ToString().Trim()); int categoryID = Convert.ToInt32(cbCate.SelectedValue.ToString()); int supplierID = Convert.ToInt32(cbSup.SelectedValue.ToString()); int price = Convert.ToInt32(txtPrice.Text); bool isSuccess = ProductHelpers.EditProduct( productIDNeedEdit, txtName.Text, price, txtDesc.Text, categoryID, supplierID ); if (isSuccess) { DataRow editRow = dataTable.Rows[rowIdxNeedEdit]; editRow["ProductName"] = txtName.Text; editRow["Price"] = price; editRow["Description"] = txtDesc.Text; editRow["CategoryID"] = categoryID; editRow["SupplierID"] = supplierID; editRow["CategoryName"] = cbCate.Text; editRow["SupplierName"] = cbSup.Text; } else { MyMessageBox.Error("Sửa bản ghi thất bại!"); } }
private void btnSelect_Click(object sender, EventArgs e) { if (dgvCustomer.CurrentRow != null) { int curRowIdx = dgvCustomer.CurrentRow.Index; int idCur = Convert.ToInt32(dgvCustomer.Rows[curRowIdx].Cells["CustomerID"].Value.ToString()); string fName = dgvCustomer.Rows[curRowIdx].Cells["FirstName"].Value.ToString(); string LName = dgvCustomer.Rows[curRowIdx].Cells["LastName"].Value.ToString(); this.ReturnCustumerID = idCur; this.ReturnCustumerName = $"{fName} {LName}"; this.Close(); } else { MyMessageBox.Error("Không thể chọn!"); } }
private void btnDelete_Click(object sender, EventArgs e) { int rowIdxNeedDel = dgvProduct.CurrentRow.Index; int idNeedDel = Convert.ToInt32(dgvProduct.Rows[rowIdxNeedDel].Cells["ProductID"].Value.ToString()); if (MyMessageBox.Question("Bạn có chắn xóa bản ghi đã chọn không?")) { bool isSuccess = ProductHelpers.Delete(idNeedDel); if (isSuccess) { dataTable.Rows[rowIdxNeedDel].Delete(); } else { MyMessageBox.Error("Xoá bản ghi thất bại!"); } } }
private void AddProduct() { int categoryID = Convert.ToInt32(cbCate.SelectedValue.ToString()); int supplierID = Convert.ToInt32(cbSup.SelectedValue.ToString()); int price = Convert.ToInt32(txtPrice.Text); bool isSuccess = ProductHelpers.AddProduct( txtName.Text, price, txtDesc.Text, categoryID, supplierID ); if (isSuccess) { // TODO: Cập nhập lại dataGripView mà không cần GetDataGridView() lại GetDataGridView(); } else { MyMessageBox.Error("Thêm bản ghi thất bại!"); } }