السلام عليكم عند اضافة صنف لفاتورة موجودة مسبقا لا يتم اضافة صنف
نعم يوجد في كود شرط اذا كان صنف موجود مسبقا عدل كمية فقط لكن انا متاكد انه صنف غير موجود
اضفت رسالة ظهرت تم اضافة صنف لكن لم يظهر في داتا قريد فيو
if (e.KeyCode == Keys.Enter)
{
try
{
int quantity = 0;
decimal price = 0;
if (!int.TryParse(qty.Text, out quantity) || !decimal.TryParse(label5.Text, out price))
{
MessageBox.Show("تأكد من صحة إدخال الكمية أو السعر", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
bool itemFound = false;
foreach (DataGridViewRow row in buybillForm.dataGridView1.Rows)
{
if (!row.IsNewRow && row.Cells[5].Value?.ToString() == label11.Text)
{
// تعديل الصف
row.Cells[0].Value = label3.Text;
row.Cells[1].Value = label7.Text;
row.Cells[2].Value = qty.Text;
row.Cells[3].Value = label5.Text;
row.Cells[4].Value = quantity * price;
// رقم الصنف يبقى كما هو
itemFound = true;
break;
}
}
// إذا لم يكن موجودًا، تتم إضافته كصف جديد
if (!itemFound)
{
DataRow newRow = buybillForm.BillItemsTable.NewRow();
newRow["item_name"] = label3.Text;
newRow["item_date"] = label7.Text;
newRow["qty"] = quantity;
newRow["price"] = price;
newRow["total"] = quantity * price;
newRow["item_code"] = label11.Text;
buybillForm.BillItemsTable.Rows.Add(newRow);
}
}
catch (Exception ex)
{
this.Dispose();
MessageBox.Show("حدث خطأ:\n" + ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error);
}