private void btnConfirm_Click(object sender, EventArgs e) { var confirmedItemsQuantity = new Dictionary<int, long>(); var confirmedItems = new List<int>(); var valid = ValidateFields(); if (valid == "true") { if (XtraMessageBox.Show("Are You Sure, You Want To Save This Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var issDoc = new IssueDoc(); var recDoc = new ReceiveDoc(); DataTable dtConfirm; long currentSOH = 0; var storeId = 0; var itemId = 0; using (dtConfirm = (DataTable)gridConfirmation.DataSource) { for (int i = 0; i < dtConfirm.Rows.Count; i++) { var receivedocid = Convert.ToInt32(dtConfirm.Rows[i]["RecId"]); issDoc.GetDULastIssue(Convert.ToInt32(dtConfirm.Rows[i]["ItemID"]), Convert.ToInt32(cboReceivingUnits.EditValue)); confirmedItems.Add(Convert.ToInt32(dtConfirm.Rows[i]["ItemID"])); if (issDoc.RowCount > 0) { //issDoc.DUSOH = ((dtConfirmation.Rows[i]["DUSOH"] != null) ? Convert.ToInt64(dtConfirmation.Rows[i]["DUSOH"]) : 0); //issDoc.Save(); } //Saving the issue issDoc.AddNew(); issDoc.StoreId = Convert.ToInt32(cboStores.EditValue); issDoc.RefNo = txtRefNo.Text.Trim(); issDoc.ReceivingUnitID = Convert.ToInt32(cboReceivingUnits.EditValue); DateTime xx = dtIssueDate.Value; dtIssueDate.CustomFormat = "MM/dd/yyyy"; DateTime dtCurrent = ConvertDate.DateConverter(dtIssueDate.Text); issDoc.Date = dtCurrent; dtIssueDate.IsGregorianCurrentCalendar = true; issDoc.EurDate = dtIssueDate.Value; dtIssueDate.IsGregorianCurrentCalendar = false; issDoc.RecievDocID =Convert.ToInt32(dtConfirm.Rows[i]["RecId"]); // Used to have 8 as an index recDoc.LoadByPrimaryKey(receivedocid); issDoc.IsApproved = true; issDoc.IsTransfer = false; issDoc.Remark = txtRemark.Text; issDoc.RecipientName = txtRecipientName.Text; issDoc.IssuedBy = txtIssuedBy.Text; issDoc.DUSOH = Convert.ToInt32(dtConfirm.Rows[i]["DUSOH"]); issDoc.ItemID = Convert.ToInt32(dtConfirm.Rows[i]["ItemId"]); issDoc.Quantity = Convert.ToInt64(dtConfirm.Rows[i]["Quantity"]); issDoc.NoOfPack = Convert.ToInt32(dtConfirm.Rows[i]["No Of Pack"]); issDoc.QtyPerPack = Convert.ToInt32(dtConfirm.Rows[i]["Qty Per Pack"]); switch (VisibilitySetting.HandleUnits) { case 1: issDoc.UnitID = 0; break; case 2: issDoc.UnitID = Convert.ToInt32(dtConfirm.Rows[i]["UnitID"]); break; default: issDoc.UnitID = Convert.ToInt32(dtConfirm.Rows[i]["UnitID"]); break; } issDoc.BatchNo = dtConfirm.Rows[i]["BatchNo"].ToString(); issDoc.Cost = Convert.ToDouble(dtConfirm.Rows[i]["Unit Price"]); issDoc.RecomendedQty = Convert.ToInt32(dtConfirm.Rows[i]["DURecomended"]);// ((recQty > 0) ? Convert.ToInt64(recQty) : 0); //End DU issDoc.Save(); //updating the receiving doc recDoc.LoadByPrimaryKey(Convert.ToInt32(dtConfirm.Rows[i]["RecId"])); //this line calculates the current SOH recDoc.QuantityLeft = recDoc.QuantityLeft - issDoc.Quantity; currentSOH = currentSOH + recDoc.QuantityLeft; itemId = Convert.ToInt32(dtConfirm.Rows[i]["ItemId"]); var unitId = Convert.ToInt32(dtConfirm.Rows[i]["UnitID"]); if (recDoc.QuantityLeft != 0) recDoc.Out = false; else recDoc.Out = true; if (confirmedItemsQuantity.ContainsKey(itemId)) confirmedItemsQuantity[itemId] += recDoc.QuantityLeft; else { confirmedItemsQuantity.Add(itemId, recDoc.QuantityLeft); } recDoc.Save(); storeId = Convert.ToInt32(cboStores.EditValue); //Log Activity dtIssueDate.Value = xx; Builder.RefreshAMCValues(storeId, confirmedItemsQuantity,unitId); } //save stockout information for the current item in current store //if current SOH after this issue is 0 if (currentSOH == 0) { StockoutLog stockoutLog = new StockoutLog(); stockoutLog.AddNew(); stockoutLog.StoreID = storeId; stockoutLog.ItemID = itemId; stockoutLog.StartDate = DateTime.Today; stockoutLog.Save(); } } XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } xpButton2_Click(sender, e); issueGrid.DataSource = null; issueGridView.RefreshData(); RefreshItems(); }