private void btnSave_Click(object sender, EventArgs e) { var transfer = new Transfer(); var newreceiveDoc = new ReceiveDoc(); var receiveDoc = new ReceiveDoc(); var issuedoc = new IssueDoc(); 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) { try{ var dtRecGrid = (DataTable)receivingGrid.DataSource; for (int i = 0; i < dtRecGrid.Rows.Count; i++) { transfer.AddNew(); var receiveid = Convert.ToInt32(dtRecGrid.Rows[i]["RecID"]); transfer.ItemID = _itemID = Convert.ToInt32(dtRecGrid.Rows[i]["ID"]); transfer.RecID = receiveid; transfer.BatchNo = dtRecGrid.Rows[i]["Batch No"].ToString(); transfer.FromStoreID = Convert.ToInt32(lkFromStore.EditValue); transfer.ToStoreID = Convert.ToInt32(lkToStore.EditValue); transfer.Quantity = Convert.ToInt64(dtRecGrid.Rows[i]["Qty To Transfer"]); transfer.RefNo = txtRefNo.Text; transfer.UnitID = VisibilitySetting.HandleUnits == 1 ? 0 : Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]); DateTime xx = dtRecDate.Value; dtRecDate.CustomFormat = "MM/dd/yyyy"; new DateTime(); transfer.Date = ConvertDate.DateConverter(dtRecDate.Text); ConvertDate.DateConverter(dtRecDate.Text); dtRecDate.IsGregorianCurrentCalendar = true; transfer.EurDate = dtRecDate.Value; dtRecDate.IsGregorianCurrentCalendar = false; transfer.TransferReason = txtTransferReason.Text; transfer.ApprovedBy = txtApprovedBy.Text; transfer.TransferRequestedBy = txtRequestedBy.Text; transfer.Save(); transfer.GetTransfered(receiveid, _itemID, Convert.ToInt32(lkFromStore.EditValue)); issuedoc.AddNew(); issuedoc.StoreId = transfer.FromStoreID; issuedoc.ItemID = transfer.ItemID; issuedoc.Quantity = transfer.Quantity; issuedoc.Date = transfer.Date; issuedoc.EurDate = transfer.EurDate; issuedoc.BatchNo = transfer.BatchNo; issuedoc.UnitID = transfer.UnitID; issuedoc.RecievDocID = transfer.RecID; issuedoc.IsTransfer = true; issuedoc.RefNo = transfer.RefNo; var allstores = new Stores(); allstores.LoadByPrimaryKey(transfer.ToStoreID); issuedoc.ReceivingUnitID = (int)allstores.GetColumn("ReceivingUnitID"); issuedoc.Save(); receiveDoc.GetReceivedItems(receiveid, _itemID, Convert.ToInt32(lkFromStore.EditValue)); receiveDoc.QuantityLeft = receiveDoc.QuantityLeft - transfer.Quantity; newreceiveDoc.AddNew(); newreceiveDoc.StoreID = transfer.ToStoreID; newreceiveDoc.RefNo = transfer.RefNo; newreceiveDoc.BatchNo = transfer.BatchNo; newreceiveDoc.ItemID = transfer.ItemID; newreceiveDoc.Quantity = transfer.Quantity; newreceiveDoc.QuantityLeft = transfer.Quantity; newreceiveDoc.NoOfPack = Convert.ToInt32(transfer.Quantity) / receiveDoc.QtyPerPack; newreceiveDoc.QtyPerPack = receiveDoc.QtyPerPack; newreceiveDoc.Cost = receiveDoc.Cost; newreceiveDoc.Date = transfer.Date; newreceiveDoc.EurDate = transfer.EurDate; newreceiveDoc.UnitID = transfer.UnitID; newreceiveDoc.Out = false; newreceiveDoc.ReceivedBy = transfer.ApprovedBy; newreceiveDoc.ExpDate = receiveDoc.ExpDate; allstores.LoadByPrimaryKey(transfer.FromStoreID); newreceiveDoc.SupplierID = (int)allstores.GetColumn("SupplierID"); newreceiveDoc.BoxLevel = 1; newreceiveDoc.Save(); receiveDoc.Save(); } XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); ResetFields(); } catch (Exception exp) { XtraMessageBox.Show(exp.InnerException.Message, "Error"); } } } else { XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }