private void btnConfirm_Click(object sender, EventArgs e) { MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr(); var dt = grdDetailView.DataSource as DataView; if ((dt) != null) { // This is where we set the Price foreach (DataRow dr in dt.Table.Rows) { var costElement = new CostElement(); costElement.LoadFromDataRow(dr, receipt.ID); costElement.AverageCost = Convert.ToDouble(dr["AverageCost"]); costElement.Margin = Convert.ToDouble(dr["Margin"]); costElement.SellingPrice = Convert.ToDouble(dr["SellingPrice"]); try { transaction.BeginTransaction(); var journalService = new JournalService(); journalService.StartRecordingSession(); costElement.ConfirmPrice(CurrentContext.UserId, "", journalService, ChangeMode.PriceOverride); var receiveDoc = new ReceiveDoc(); receiveDoc.SavePrice(costElement, CurrentContext.UserId); journalService.CommitRecordingSession(); transaction.CommitTransaction(); } catch (Exception exception) { transaction.RollbackTransaction(); XtraMessageBox.Show("Error : " + exception.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error); throw exception; } var report = new PriceOverridePrintout { xrCostedBy = {Text = CurrentContext.LoggedInUserName}, lblDate = {Text = DateTimeHelper.ServerDateTime.ToString()}, DataSource = getPriceChangeReport(costElement) }; report.ShowPreviewDialog(); } var recDoc = new ReceiveDoc(); recDoc.LoadByReceiptID(receipt.ID); recDoc.ConfirmGRVPrinted(CurrentContext.UserId); receipt.ChangeStatus(ReceiptConfirmationStatus.Constants.GRV_PRINTED, null, this.GetFormIdentifier(), CurrentContext.UserId, "Price Set"); } }
private void btnSave_Click(object sender, EventArgs e) { MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr(); if (gridPriceList.DataSource != null && (gridPriceList.DataSource as DataTable).GetChanges() != null) { DataTable dtChangedPricelist = (gridPriceList.DataSource as DataTable).GetChanges(); if (dtChangedPricelist != null) { foreach (DataRowView drw in dtChangedPricelist.DefaultView) { var dialogResult = XtraMessageBox.Show( String.Format("Are you Sure you want to Change Price for {0}", drw["ItemName"]), "Are you sure", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dialogResult == DialogResult.Cancel) { return; } if (dialogResult == DialogResult.Yes) { try { transaction.BeginTransaction(); // This is where we set the Price JournalService journalService = new JournalService(); journalService.StartRecordingSession(); CostElement costElement = new CostElement(Convert.ToInt32(drw["ItemID"]) , Convert.ToInt32(drw["MovingAverageGroupID"]) , Convert.ToInt32(drw["ManufacturerID"]) , Convert.ToInt32(drw["UnitID"])); costElement.AverageCost = Math.Round(Convert.ToDouble(drw["UnitCost"]), BLL.Settings.NoOfDigitsAfterTheDecimalPoint, MidpointRounding.AwayFromZero); costElement.Margin = Math.Round(Convert.ToDouble(drw["Margin"]), BLL.Settings.NoOfDigitsAfterTheDecimalPoint+2, MidpointRounding.AwayFromZero); if(BLL.Settings.IsCenter) { costElement.SellingPrice = costElement.AverageCost; } else { costElement.SellingPrice = Math.Round(Convert.ToDouble(drw["SellingPrice"]), BLL.Settings.NoOfDigitsAfterTheDecimalPoint, MidpointRounding.AwayFromZero); } costElement.SavePrice(CurrentContext.UserId, "", journalService, ChangeMode.PriceOverride); PriceOverridePrintout report = new PriceOverridePrintout(); report.xrCostedBy.Text = CurrentContext.LoggedInUserName; report.lblDate.Text = DateTimeHelper.ServerDateTime.ToString(); report.DataSource = getPriceChangeReport(costElement); journalService.CommitRecordingSession(); transaction.CommitTransaction(); report.ShowPreviewDialog(); } catch (Exception exception) { transaction.RollbackTransaction(); XtraMessageBox.Show("Error : " + exception.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error); throw exception; } } } BindDataSet(); XtraMessageBox.Show("Change was Successfull", "Success...", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } XtraMessageBox.Show("No Changes have been made", "No Changes...", MessageBoxButtons.OK, MessageBoxIcon.Error); }