private void btnSave_Click(object sender, EventArgs e) { if (CheckErrors()) { GetDataFromForm(); if (current.Equals("ADD")) { if (frmManagePurchaseOrderProducts.dgv.Rows.Count == 0) { MessageBox.Show("Please add products."); } else { purchaseOrderEL.Purchaseorderid = Convert.ToInt32(purchaseOrderBL.Insert(purchaseOrderEL)); if (purchaseOrderEL.Purchaseorderid > 0) { bool stat = true; foreach (DataGridViewRow row in frmManagePurchaseOrderProducts.dgv.Rows) { purchaseOrderDetailEL.Productid = Convert.ToInt32(row.Cells[0].Value); purchaseOrderDetailEL.Purchaseorderdetailquantity = Convert.ToInt32(row.Cells[3].Value); purchaseOrderDetailEL.Purchaseorderid = purchaseOrderEL.Purchaseorderid; purchaseOrderDetailEL.Purchaseorderdetailprice = Convert.ToInt32(row.Cells[2].Value); if (purchaseOrderDetailBL.Insert(purchaseOrderDetailEL) == 0) { stat = false; } } if (stat) { ShowMessageBox(true); } else { ShowMessageBox(false); } } else { ShowMessageBox(false); } } } ManageForm(false); ClearFields(); } }
private void btnSave_Click(object sender, EventArgs e) { if (dgv.Rows.Count == 0) { MessageBox.Show("No supplies selected."); } else { if (validations()) { getDataFromForm(); long purchaseOrderID; if ((purchaseOrderID = purchaseOrderBL.Insert(purchaseOrderInfo)) > 0) { bool stat = true; foreach (DataGridViewRow row in dgv.Rows) { purchaseOrderDetailInfo.Purchaseorderid = Convert.ToInt32(purchaseOrderID); purchaseOrderDetailInfo.Supplyid = Convert.ToInt32(row.Cells[0].Value); purchaseOrderDetailInfo.Purchaseorderdetailquantity = Convert.ToInt32(row.Cells[4].Value); purchaseOrderDetailInfo.Purchaseorderdetailunitprice = Convert.ToInt32(row.Cells[3].Value); if (purchaseOrderDetailBL.Insert(purchaseOrderDetailInfo) == 0) { stat = false; } } if (stat) { MessageBox.Show("Success."); clearControls(); this.Close(); frmPurchaseOrders.loadData(frmPurchaseOrders.txtSearch.Text); } else { MessageBox.Show("Failed."); } } else { MessageBox.Show("Failed."); } } } }