private string insertInventory(string pTransactionNo, string pCustomer, decimal pTotalQtyOut) { string _InventoryId = ""; try { loInventory.Id = ""; loInventory.Date = DateTime.Now; loInventory.Type = "Stock Withdrawal - POS"; loInventory.POId = ""; loInventory.SOId = ""; loInventory.STInId = ""; loInventory.STOutId = ""; loInventory.Reference = "Transaction No. " + pTransactionNo; loInventory.CustomerId = pCustomer; loInventory.SupplierId = "0"; loInventory.TotalPOQty = 0; loInventory.TotalQtyIn = 0; loInventory.TotalSOQty = 0; loInventory.TotalQtyOut = pTotalQtyOut; loInventory.TotalVariance = 0; loInventory.FromLocationId = ""; loInventory.ToLocationId = ""; loInventory.Remarks = ""; loInventory.UserId = GlobalVariables.UserId; try { _InventoryId = loInventory.save(GlobalVariables.Operation.Add); if (_InventoryId != "") { foreach (DataGridViewRow _dr in loDataGrid.Rows) { loInventoryDetail.DetailId = ""; loInventoryDetail.InventoryId = _InventoryId; loInventoryDetail.PODetailId = "0"; loInventoryDetail.SODetailId = "0"; loInventoryDetail.StockId = _dr.Cells["DetailStockId"].Value.ToString(); loInventoryDetail.LocationId = GlobalVariables.CurrentLocationId; loInventoryDetail.POQty = 0; loInventoryDetail.QtyIn = 0; loInventoryDetail.SOQty = 0; loInventoryDetail.QtyOut = decimal.Parse(_dr.Cells["DetailQty"].Value.ToString()); loInventoryDetail.Variance = 0; loInventoryDetail.Remarks = ""; loInventoryDetail.UserId = GlobalVariables.UserId; loInventoryDetail.save(GlobalVariables.Operation.Add); } } } catch { } } catch { } return(_InventoryId); }
private string insertInventory(string pStockId, decimal pTotalQtyIn) { string _InventoryId = ""; try { loInventory.Id = ""; loInventory.Date = DateTime.Now; loInventory.Type = "Stock Receiving - POS"; loInventory.POId = ""; loInventory.SOId = ""; loInventory.STInId = ""; loInventory.STOutId = ""; loInventory.Reference = "Returned Item "; loInventory.CustomerId = "0"; loInventory.SupplierId = "0"; loInventory.TotalPOQty = 0; loInventory.TotalQtyIn = pTotalQtyIn; loInventory.TotalSOQty = 0; loInventory.TotalQtyOut = 0; loInventory.TotalVariance = 0; loInventory.FromLocationId = ""; loInventory.ToLocationId = ""; loInventory.Remarks = ""; loInventory.UserId = GlobalVariables.UserId; try { _InventoryId = loInventory.save(GlobalVariables.Operation.Add); if (_InventoryId != "") { loInventoryDetail.DetailId = ""; loInventoryDetail.InventoryId = _InventoryId; loInventoryDetail.PODetailId = "0"; loInventoryDetail.SODetailId = "0"; loInventoryDetail.StockId = pStockId; loInventoryDetail.LocationId = GlobalVariables.CurrentLocationId; loInventoryDetail.POQty = 0; loInventoryDetail.QtyIn = pTotalQtyIn; loInventoryDetail.SOQty = 0; loInventoryDetail.QtyOut = 0; loInventoryDetail.Variance = 0; loInventoryDetail.Remarks = ""; loInventoryDetail.UserId = GlobalVariables.UserId; loInventoryDetail.save(GlobalVariables.Operation.Add); } } catch { } } catch { } return(_InventoryId); }
private void btnSave_Click(object sender, EventArgs e) { try { if (decimal.Parse(txtTotalQtyOUT.Text) == 0) { MessageBoxUI _mb1 = new MessageBoxUI("Totals of Qty must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb1.showDialog(); return; } string _ToLocationId = ""; try { _ToLocationId = cboToLocation.SelectedValue.ToString(); } catch { MessageBoxUI _mb1 = new MessageBoxUI("You must select a Location To!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb1.showDialog(); cboToLocation.Focus(); return; } if (_ToLocationId == GlobalVariables.CurrentLocationId) { MessageBoxUI _mb1 = new MessageBoxUI("Location To must not the same with Current Location!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb1.showDialog(); return; } DialogResult _dr = new DialogResult(); MessageBoxUI _mb = new MessageBoxUI("Continue saving this Stock Transfer Out?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo); _mb.ShowDialog(); _dr = _mb.Operation; if (_dr == DialogResult.Yes) { loInventory.Id = lInventoryId; loInventory.Date = dtpDate.Value; loInventory.Type = "Stock Transfer Out"; loInventory.POId = ""; loInventory.SOId = ""; loInventory.STInId = ""; loInventory.STOutId = ""; loInventory.Reference = GlobalFunctions.replaceChar(txtReference.Text); loInventory.CustomerId = "0"; loInventory.SupplierId = "0"; loInventory.TotalPOQty = 0; loInventory.TotalQtyIn = 0; loInventory.TotalSOQty = 0; loInventory.TotalQtyOut = decimal.Parse(txtTotalQtyOUT.Text); loInventory.TotalVariance = 0; loInventory.FromLocationId = GlobalVariables.CurrentLocationId; loInventory.ToLocationId = _ToLocationId; loInventory.Remarks = GlobalFunctions.replaceChar(txtRemarks.Text); loInventory.UserId = GlobalVariables.UserId; try { string _InventoryId = loInventory.save(lOperation); if (_InventoryId != "") { for (int i = 0; i < dgvDetail.Rows.Count; i++) { if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Add") { try { loInventoryDetail.DetailId = dgvDetail.Rows[i].Cells[0].Value.ToString(); } catch { loInventoryDetail.DetailId = ""; } try { loInventoryDetail.InventoryId = _InventoryId; loInventoryDetail.PODetailId = "0"; loInventoryDetail.SODetailId = "0"; loInventoryDetail.StockId = dgvDetail.Rows[i].Cells[1].Value.ToString(); loInventoryDetail.LocationId = dgvDetail.Rows[i].Cells[5].Value.ToString(); loInventoryDetail.POQty = 0; loInventoryDetail.QtyIn = 0; loInventoryDetail.SOQty = 0; loInventoryDetail.QtyOut = decimal.Parse(dgvDetail.Rows[i].Cells[7].Value.ToString()); loInventoryDetail.Variance = 0; loInventoryDetail.Remarks = dgvDetail.Rows[i].Cells[8].Value.ToString(); loInventoryDetail.UserId = GlobalVariables.UserId; loInventoryDetail.save(GlobalVariables.Operation.Add); } catch { } } else if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Edit") { try { loInventoryDetail.DetailId = dgvDetail.Rows[i].Cells[0].Value.ToString(); } catch { loInventoryDetail.DetailId = ""; } try { loInventoryDetail.InventoryId = _InventoryId; loInventoryDetail.PODetailId = "0"; loInventoryDetail.SODetailId = "0"; loInventoryDetail.StockId = dgvDetail.Rows[i].Cells[1].Value.ToString(); loInventoryDetail.LocationId = dgvDetail.Rows[i].Cells[5].Value.ToString(); loInventoryDetail.POQty = 0; loInventoryDetail.QtyIn = 0; loInventoryDetail.SOQty = 0; loInventoryDetail.QtyOut = decimal.Parse(dgvDetail.Rows[i].Cells[7].Value.ToString()); loInventoryDetail.Variance = 0; loInventoryDetail.Remarks = dgvDetail.Rows[i].Cells[8].Value.ToString(); loInventoryDetail.UserId = GlobalVariables.UserId; loInventoryDetail.save(GlobalVariables.Operation.Edit); } catch { } } else if (dgvDetail.Rows[i].Cells["Status"].Value.ToString() == "Delete") { loInventoryDetail.remove(dgvDetail.Rows[i].Cells[0].Value.ToString()); } } if (txtStockTransferOutNo.Text == _InventoryId) { MessageBoxUI _mb2 = new MessageBoxUI("Stock Transfer Out has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK); _mb2.showDialog(); } else { MessageBoxUI _mb2 = new MessageBoxUI("Stock Transfer Out has been saved successfully! New Stock Transfer Out Id : " + _InventoryId, GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK); _mb2.showDialog(); } //previewDetail(_InventoryId); object[] _params = { "Stock Transfer Out" }; ParentList.GetType().GetMethod("refresh").Invoke(ParentList, _params); this.Close(); } } catch (Exception ex) { if (ex.Message.Contains("Unclosed quotation mark after the character string")) { MessageBoxUI _mb3 = new MessageBoxUI("Do not use this character( ' ).", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb3.showDialog(); return; } else { MessageBoxUI _mb3 = new MessageBoxUI(ex.Message, GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb3.showDialog(); return; } } } } catch (Exception ex) { ErrorMessageUI em = new ErrorMessageUI(ex.Message, this.Name, "btnSave_Click"); em.ShowDialog(); return; } }
private void btnSave_Click(object sender, EventArgs e) { /*if (decimal.Parse(txtTotalQty.Text) == 0) * { * MessageBoxUI _mb1 = new MessageBoxUI("Totals of Qty-IN must not be Zero(0)!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); * _mb1.showDialog(); * return; * }*/ DialogResult _dr = new DialogResult(); MessageBoxUI _mb = new MessageBoxUI("Continue saving this Stock Receiving?", GlobalVariables.Icons.QuestionMark, GlobalVariables.Buttons.YesNo); _mb.ShowDialog(); _dr = _mb.Operation; if (_dr == DialogResult.Yes) { loInventoryHeader.HeaderId = lInventoryId; loInventoryHeader.Date = dtpDate.Value; loInventoryHeader.Type = "Stock Receiving"; loInventoryHeader.Reference = GlobalFunctions.replaceChar(txtReference.Text); loInventoryHeader.CustomerId = ""; loInventoryHeader.SalesInchargeId = ""; try { loInventoryHeader.SupplierId = cboSupplier.SelectedValue.ToString(); } catch { MessageBoxUI _mb0 = new MessageBoxUI("You must select a correct Supplier!", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb0.showDialog(); return; } loInventoryHeader.TotalIN = decimal.Parse(txtTotalQty.Text); loInventoryHeader.TotalOUT = 0; loInventoryHeader.TotalAmount = decimal.Parse(txtTotalAmount.Text); loInventoryHeader.Remarks = GlobalFunctions.replaceChar(txtRemarks.Text); MySqlTransaction _Trans = GlobalVariables.Connection.BeginTransaction(); try { string _InventoryId = loInventoryHeader.save(lOperation, ref _Trans); if (_InventoryId != "") { for (int i = 0; i < dgvDetail.Rows.Count; i++) { if (dgvDetail.Rows[i].Cells[14].Value.ToString() == "Add") { try { loInventoryDetail.DetailId = dgvDetail.Rows[i].Cells[0].Value.ToString(); } catch { loInventoryDetail.DetailId = ""; } try { loInventoryDetail.HeaderId = _InventoryId; loInventoryDetail.StockId = dgvDetail.Rows[i].Cells[1].Value.ToString(); loInventoryDetail.StockDescription = dgvDetail.Rows[i].Cells[2].Value.ToString(); loInventoryDetail.Unit = dgvDetail.Rows[i].Cells[3].Value.ToString(); loInventoryDetail.Brand = dgvDetail.Rows[i].Cells[4].Value.ToString(); loInventoryDetail.Supplier = dgvDetail.Rows[i].Cells[5].Value.ToString(); loInventoryDetail.Picture = dgvDetail.Rows[i].Cells[6].Value.ToString(); loInventoryDetail.LocationId = dgvDetail.Rows[i].Cells[7].Value.ToString(); loInventoryDetail.IN = decimal.Parse(dgvDetail.Rows[i].Cells[9].Value.ToString()); loInventoryDetail.OUT = 0; loInventoryDetail.Balance = decimal.Parse(dgvDetail.Rows[i].Cells[10].Value.ToString()); loInventoryDetail.UnitPrice = decimal.Parse(dgvDetail.Rows[i].Cells[11].Value.ToString()); loInventoryDetail.TotalPrice = decimal.Parse(dgvDetail.Rows[i].Cells[12].Value.ToString()); loInventoryDetail.Remarks = dgvDetail.Rows[i].Cells[13].Value.ToString(); loInventoryDetail.save(GlobalVariables.Operation.Add, ref _Trans); } catch { } } else if (dgvDetail.Rows[i].Cells[14].Value.ToString() == "Edit") { try { loInventoryDetail.DetailId = dgvDetail.Rows[i].Cells[0].Value.ToString(); } catch { loInventoryDetail.DetailId = ""; } loInventoryDetail.HeaderId = _InventoryId; loInventoryDetail.StockId = dgvDetail.Rows[i].Cells[1].Value.ToString(); loInventoryDetail.StockDescription = dgvDetail.Rows[i].Cells[2].Value.ToString(); loInventoryDetail.Unit = dgvDetail.Rows[i].Cells[3].Value.ToString(); loInventoryDetail.Brand = dgvDetail.Rows[i].Cells[4].Value.ToString(); loInventoryDetail.Supplier = dgvDetail.Rows[i].Cells[5].Value.ToString(); loInventoryDetail.Picture = dgvDetail.Rows[i].Cells[6].Value.ToString(); loInventoryDetail.LocationId = dgvDetail.Rows[i].Cells[7].Value.ToString(); loInventoryDetail.IN = decimal.Parse(dgvDetail.Rows[i].Cells[9].Value.ToString()); loInventoryDetail.OUT = 0; loInventoryDetail.Balance = decimal.Parse(dgvDetail.Rows[i].Cells[10].Value.ToString()); loInventoryDetail.UnitPrice = decimal.Parse(dgvDetail.Rows[i].Cells[11].Value.ToString()); loInventoryDetail.TotalPrice = decimal.Parse(dgvDetail.Rows[i].Cells[12].Value.ToString()); loInventoryDetail.Remarks = dgvDetail.Rows[i].Cells[13].Value.ToString(); loInventoryDetail.save(GlobalVariables.Operation.Edit, ref _Trans); } else if (dgvDetail.Rows[i].Cells[11].Value.ToString() == "Delete") { loInventoryDetail.remove(dgvDetail.Rows[i].Cells[0].Value.ToString(), ref _Trans); } } _Trans.Commit(); if (txtStockReceivingNo.Text == _InventoryId) { MessageBoxUI _mb2 = new MessageBoxUI("Stock Receiving has been saved successfully!", GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK); _mb2.showDialog(); } else { MessageBoxUI _mb2 = new MessageBoxUI("Stock Receiving has been saved successfully! New Receiving No. : " + _InventoryId, GlobalVariables.Icons.Save, GlobalVariables.Buttons.OK); _mb2.showDialog(); } //previewDetail(_InventoryId); object[] _params = { "ViewAll", "", "", "Stock Receiving" }; ParentList.GetType().GetMethod("refresh").Invoke(ParentList, _params); this.Close(); } } catch (Exception ex) { if (ex.Message.Contains("Unclosed quotation mark after the character string")) { MessageBoxUI _mb3 = new MessageBoxUI("Do not use this character( ' ).", GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb3.showDialog(); return; } else { MessageBoxUI _mb3 = new MessageBoxUI(ex.Message, GlobalVariables.Icons.Error, GlobalVariables.Buttons.OK); _mb3.showDialog(); return; } } } }