InvenToryForm
Она не заполняет пространство, хотя ее док-станция уже заполнена. И у меня есть два DataGridViewImageCellLayout: «Редактировать» и «Удалить» в столбце, и они не отображаются. Это должно выглядеть так.
TransactiomForm
Вот мой код в моем DataGridView в InventoryForm
Код: Выделить всё
private void dgvInventory_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
DataGridViewRow row = dgvInventory.Rows[e.RowIndex];
string columnName = dgvInventory.Columns[e.ColumnIndex].Name;
if (columnName == "Edit")
{
ManageInventoryForm manageInventory = new ManageInventoryForm(this);
manageInventory.txtProductID.Text = row.Cells["product_id"].Value.ToString();
manageInventory.txtProductName.Text = row.Cells["product_name"].Value.ToString();
manageInventory.txtQuantity.Text = row.Cells["quantity"].Value.ToString();
manageInventory.txtStock.Text = row.Cells["minimum_stock"].Value.ToString();
manageInventory.txtPrice.Text = row.Cells["price"].Value.ToString();
manageInventory.EnableButtons(false, true);
manageInventory.ShowDialog();
}
else if (columnName == "Delete")
{
if (MessageBox.Show("Are you sure you want to delete this Product?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
// Delete from tbl_product
SqlCommand cmdProduct = new SqlCommand("DELETE FROM tbl_product WHERE product_id = @product_id", conn);
cmdProduct.Parameters.AddWithValue("@product_id", row.Cells["product_id"].Value);
cmdProduct.ExecuteNonQuery();
// Delete from tbl_stock
SqlCommand cmdStock = new SqlCommand("DELETE FROM tbl_stock WHERE product_id = @product_id", conn);
cmdStock.Parameters.AddWithValue("@product_id", row.Cells["product_id"].Value);
cmdStock.ExecuteNonQuery();
MessageBox.Show("Product and stock records have been successfully deleted!");
LoadInventory(); // Refresh the grid after deletion
}
}
}
}
}
}
вот также код для моей TransactionForm
Код: Выделить всё
private void dgvTransaction_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
DataGridViewRow row = dgvTransaction.Rows[e.RowIndex];
string columnName = dgvTransaction.Columns[e.ColumnIndex].Name;
if (columnName == "Edit")
{
TransactionForm manageTransaction = new TransactionForm();
manageTransaction.txtProductID.Text = row.Cells[1].Value.ToString();
manageTransaction.txtQuantity.Text = row.Cells[2].Value.ToString();
manageTransaction.txtTime.Text = row.Cells[4].Value.ToString();
manageTransaction.ShowDialog();
}
else if (columnName == "Delete")
{
if (MessageBox.Show("Are you sure you want to delete this transaction?", "Delete Record", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM tbl_transactions WHERE transaction_id = @transaction_id", conn);
cmd.Parameters.AddWithValue("@transaction_id", row.Cells[0].Value);
cmd.ExecuteNonQuery();
MessageBox.Show("Transaction record has been successfully deleted!");
LoadTransaction(); // Refresh the grid after deletion
}
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... ndows-form
Мобильная версия