private void btnSave_Click(object sender, EventArgs e) { string valid = ValidateFields(); if (valid == "true") { if (XtraMessageBox.Show("Are You Sure, You want to save this Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Disposal dis = new Disposal(); Balance bal = new Balance(); ReceiveDoc rec = new ReceiveDoc(); DataTable dtAdjVal = (DataTable)AdjustmentGrid.DataSource; for (int i = 0; i < dtAdjVal.Rows.Count; i++) { dis.AddNew(); dis.StoreId = Convert.ToInt32(cboStores.EditValue); dis.ItemID = Convert.ToInt32(dtAdjVal.Rows[i]["ID"]); dis.ApprovedBy = txtApprovedBy.Text; DateTime xx = dtAdjustDate.Value; dtAdjustDate.CustomFormat = "MM/dd/yyyy"; DateTime dtRec = new DateTime(); dis.Date = ConvertDate.DateConverter(dtAdjustDate.Text); dtRec = ConvertDate.DateConverter(dtAdjustDate.Text); dis.RefNo = txtRefNo.Text; dis.BatchNo = dtAdjVal.Rows[i]["Batch No"].ToString(); double price = ((Convert.ToDouble(dtAdjVal.Rows[i]["BU Qty"]) != 0) ? (Convert.ToDouble(dtAdjVal.Rows[i]["Price"]) / Convert.ToDouble(dtAdjVal.Rows[i]["BU Qty"])) : 0); dis.Cost = price; dis.Remark = txtRemark.Text; if (dtAdjVal.Rows[i]["Losses"].ToString() != "") { if (Convert.ToInt64(dtAdjVal.Rows[i]["Losses"]) <= Convert.ToInt64(dtAdjVal.Rows[i]["BU Qty"])) { dis.Losses = true; dis.Quantity = Convert.ToInt64(dtAdjVal.Rows[i]["Losses"]); } else { XtraMessageBox.Show("You can't loss more quantity than what you have in the store!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); ResetFields(); return; } } else { dis.Losses = false; dis.Quantity = Convert.ToInt64(dtAdjVal.Rows[i]["Adjustment"]); } dis.ReasonId = Convert.ToInt32(dtAdjVal.Rows[i]["Reason"]); if (VisibilitySetting.HandleUnits == 1) { dis.UnitID = 0; } else if (VisibilitySetting.HandleUnits == 2) { dis.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); } else if (VisibilitySetting.HandleUnits == 3) { dis.UnitID = Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); } dis.RecID = Convert.ToInt32(dtAdjVal.Rows[i]["RecID"]); dis.EurDate = dtAdjustDate.Value; dis.Save(); rec.LoadByPrimaryKey(Convert.ToInt32(dtAdjVal.Rows[i]["RecID"])); if (rec.RowCount > 0) { if (dis.Losses) { rec.QuantityLeft = rec.QuantityLeft - dis.Quantity; if (rec.QuantityLeft == 0) rec.Out = true; else rec.Out = false; // rec.UnitID = Convert.ToInt32(dtAdjVal.Rows[i]["UnitID"]); rec.Save(); //Log Activity, ActivityID for save is 1 // logger.SaveAction(1, 1, "Transaction\\LossesAdjustment.cs", "Loss/Adjustmet of " + dis.Quantity +" LOSS has been made."); } else { rec.QuantityLeft = rec.QuantityLeft + dis.Quantity; if (rec.QuantityLeft != 0) rec.Out = false; else rec.Out = true; rec.Save(); //Log Activity, ActivityID for save is 1 //logger.SaveAction(1, 1, "Transaction\\LossesAdjustment.cs", "Loss/Adjustmet of " + dis.Quantity + " ADJUSTMENT has been made."); } } dtAdjustDate.Value = xx; } XtraMessageBox.Show("Transaction successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFields(); } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }