private void btnSave_Click(object sender, EventArgs e) { try { if (decimal.Parse(lblTotalPOQty.Text) == 0) { MessageBoxUI _mb1 = new MessageBoxUI("Totals of P.O. Qty must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb1.showDialog(); return; } string _SupplierId = ""; string _Employee = ""; try { _SupplierId = cboSupplier.SelectedValue.ToString(); } catch { MessageBoxUI _mb1 = new MessageBoxUI("You must select a Supplier!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb1.showDialog(); cboSupplier.Focus(); return; } try { _Employee = cboRequestedBy.SelectedValue.ToString(); } catch { _Employee = ""; } DialogResult _dr = new DialogResult(); MessageBoxUI _mb = new MessageBoxUI("Continue saving this Purchase Order?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo); _mb.ShowDialog(); _dr = _mb.Operation; if (_dr == DialogResult.Yes) { loPurchaseOrder.Id = lPurchaseOrderId; loPurchaseOrder.Date = dtpDate.Value; try { loPurchaseOrder.PRId = cboPurchaseRequest.SelectedValue.ToString(); } catch { loPurchaseOrder.PRId = ""; } loPurchaseOrder.Reference = GlobalFunctions.replaceChar(txtReference.Text); loPurchaseOrder.SupplierId = _SupplierId; try { loPurchaseOrder.Terms = int.Parse(txtTerms.Text); } catch { loPurchaseOrder.Terms = 0; } loPurchaseOrder.DueDate = dtpDueDate.Value; loPurchaseOrder.Instructions = GlobalFunctions.replaceChar(txtInstructions.Text); loPurchaseOrder.RequestedBy = _Employee; loPurchaseOrder.DateNeeded = dtpDateNeeded.Value; loPurchaseOrder.TotalPOQty = decimal.Parse(lblTotalPOQty.Text); loPurchaseOrder.TotalQtyIn = decimal.Parse(lblTotalQtyIn.Text); loPurchaseOrder.TotalQtyVariance = decimal.Parse(lblTotalQtyVariance.Text); loPurchaseOrder.TotalAmount = decimal.Parse(txtTotalAmount.Text); loPurchaseOrder.Remarks = GlobalFunctions.replaceChar(txtRemarks.Text); loPurchaseOrder.UserId = GlobalVariables.UserId; string _PurchaseOrderId = loPurchaseOrder.save(lOperation); if (_PurchaseOrderId != "") { for (int i = 0; i < dgvDetailStockInventory.Rows.Count; i++) { if (dgvDetailStockInventory.Rows[i].Cells["Status"].Value.ToString() == "Add") { try { loPurchaseOrderDetail.DetailId = dgvDetailStockInventory.Rows[i].Cells["Id"].Value.ToString(); } catch { loPurchaseOrderDetail.DetailId = ""; } try { loPurchaseOrderDetail.PurchaseOrderId = _PurchaseOrderId; loPurchaseOrderDetail.StockId = dgvDetailStockInventory.Rows[i].Cells["StockId"].Value.ToString(); loPurchaseOrderDetail.LocationId = dgvDetailStockInventory.Rows[i].Cells["LocationId"].Value.ToString(); loPurchaseOrderDetail.POQty = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["POQty"].Value.ToString()); loPurchaseOrderDetail.QtyIn = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyIn"].Value.ToString()); loPurchaseOrderDetail.QtyVariance = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyVariance"].Value.ToString()); loPurchaseOrderDetail.UnitPrice = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["UnitPrice"].Value.ToString()); loPurchaseOrderDetail.DiscountId = dgvDetailStockInventory.Rows[i].Cells["DiscountId"].Value.ToString(); loPurchaseOrderDetail.DiscountAmount = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["DiscountAmount"].Value.ToString()); loPurchaseOrderDetail.TotalPrice = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["TotalPrice"].Value.ToString()); loPurchaseOrderDetail.Remarks = dgvDetailStockInventory.Rows[i].Cells["Remarks"].Value.ToString(); loPurchaseOrderDetail.UserId = GlobalVariables.UserId; loPurchaseOrderDetail.save(GlobalVariables.Operation.Add); } catch { } } else if (dgvDetailStockInventory.Rows[i].Cells["Status"].Value.ToString() == "Edit") { try { loPurchaseOrderDetail.DetailId = dgvDetailStockInventory.Rows[i].Cells["Id"].Value.ToString(); } catch { loPurchaseOrderDetail.DetailId = ""; } loPurchaseOrderDetail.PurchaseOrderId = _PurchaseOrderId; loPurchaseOrderDetail.StockId = dgvDetailStockInventory.Rows[i].Cells["StockId"].Value.ToString(); loPurchaseOrderDetail.LocationId = dgvDetailStockInventory.Rows[i].Cells["LocationId"].Value.ToString(); loPurchaseOrderDetail.POQty = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["POQty"].Value.ToString()); loPurchaseOrderDetail.QtyIn = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyIn"].Value.ToString()); loPurchaseOrderDetail.QtyVariance = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["QtyVariance"].Value.ToString()); loPurchaseOrderDetail.UnitPrice = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["UnitPrice"].Value.ToString()); loPurchaseOrderDetail.DiscountId = dgvDetailStockInventory.Rows[i].Cells["DiscountId"].Value.ToString(); loPurchaseOrderDetail.DiscountAmount = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["DiscountAmount"].Value.ToString()); loPurchaseOrderDetail.TotalPrice = decimal.Parse(dgvDetailStockInventory.Rows[i].Cells["TotalPrice"].Value.ToString()); loPurchaseOrderDetail.Remarks = dgvDetailStockInventory.Rows[i].Cells["Remarks"].Value.ToString(); loPurchaseOrderDetail.UserId = GlobalVariables.UserId; loPurchaseOrderDetail.save(GlobalVariables.Operation.Edit); } else if (dgvDetailStockInventory.Rows[i].Cells["Status"].Value.ToString() == "Delete") { loPurchaseOrderDetail.remove(dgvDetailStockInventory.Rows[i].Cells[0].Value.ToString()); } } if (txtId.Text == _PurchaseOrderId) { MessageBoxUI _mb2 = new MessageBoxUI("Purchase Order has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK); _mb2.showDialog(); } else { MessageBoxUI _mb2 = new MessageBoxUI("Purchase Order has been saved successfully! New Purchase Order ID. : " + _PurchaseOrderId, GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK); _mb2.showDialog(); } //previewDetail(_PurchaseOrderId); object[] _params = { }; ParentList.GetType().GetMethod("refresh").Invoke(ParentList, _params); this.Close(); } } } catch (Exception ex) { ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click"); em.ShowDialog(); return; } }