/// <summary>
        /// Load All Neccessary Data and Bind To DataSource
        /// </summary>
        void LoadAndBind()
        {
            //Bind

            //Load Detail Table To Grid
            Item item = new Item();

            gridReceiveDoc.DataSource = item.GetReceiveDocDetailForDiagnostics(ItemId, ManufacturerId, UnitId,
                                                                               MovingAverageId);

            gridJournalEntries.DataSource = item.GetJournalEntriesForDiagnostics(AffectedLedgerID);

            MovingAverageHistory history     = new MovingAverageHistory();
            CostElement          costElement = new CostElement(ItemId, MovingAverageId, ManufacturerId, UnitId, ManufacturerId);

            gridAllSimilarItems.DataSource = history.GetHistory(costElement);

            //Load Header Information From first row to be displayed

            txtItemName.EditValue         = Item;
            txtItemUnit.EditValue         = Unit;
            txtManufacturerName.EditValue = Manufacturer;
            txtActivityName.EditValue     = MovingAverage;
            txtUnitCost.EditValue         = UnitCost;
            txtMargin.EditValue           = Margin;
            txtSellingPrice.EditValue     = SellingPrice;
        }
コード例 #2
0
        public DataView getPriceChangeReport(CostElement costElement)
        {
            TheDataSet dataSet = new TheDataSet();
            DataRow    dr      = dataSet.PriceOveride.NewRow();

            dataSet.PriceOveride.Rows.Add(costElement.priceChangeReport(dr));
            return(dataSet.PriceOveride.DefaultView);
        }
コード例 #3
0
        private void BindDetails(DataRow dr)
        {
            // txtAdditionalCost.EditValue = 0;
            //txtMargin.EditValue = 100;
            try
            {
                Convert.ToInt16(dr["ItemID"]);
            }
            catch
            {
                ResetForm();
                return;
            }

            if (dr != null)
            {
                costElement = new CostElement(Convert.ToInt32(dr["ItemID"]), Convert.ToInt32(lkAccount.EditValue), Convert.ToInt32(dr["ManufacturerID"]), Convert.ToInt32(dr["UnitID"]));

                //ToDo Remove ReceivedSummary ItemId and Stuff with CostElement
                rs = new ReceivedSummary();
                ReceiveDoc rd = new ReceiveDoc();
                rs.ItemID         = Convert.ToInt32(dr["ItemID"]);
                rs.SupplierID     = Convert.ToInt32(dr["SupplierID"]);
                rs.ManufacturerID = Convert.ToInt32(dr["ManufacturerID"]);
                rs.UnitID         = null;
                if (dr["UnitID"] != DBNull.Value)
                {
                    rs.UnitID = Convert.ToInt32(dr["UnitID"]);
                }
                rs.StoreID = Convert.ToInt32(lkAccount.EditValue);

                // TODO: fix this ( Remove ) try cache
                try
                {
                    txtUnit.Text = dr["Unit"].ToString();
                }
                catch
                {
                }

                txtItemName.Text     = dr["FullItemName"].ToString();
                txtManufacturer.Text = dr["Manufacturer"].ToString();

                rd.LoadForPricing(rs.ItemID, rs.SupplierID, rs.StoreID, rs.ManufacturerID, rs.UnitID);
                gridAllSimilarItems.DataSource = rd.DefaultView;



                LoadDecimalFormatings();

                rs.MovingAverageTable(rs.ItemID, rs.StoreID, rs.SupplierID, rs.ManufacturerID, rs.UnitID);
                txtAverageCost.EditValue  = rs.NewUnitCost;
                txtMargin.EditValue       = rs.Margin;
                txtSellingPrice.EditValue = rs.NewSellingPrice;
            }
        }
コード例 #4
0
 public MovingAverage(int itemID, int itemUnitID, int manufacturerID, int MovingAverageID, double Qty, double UnitCost, double margin, string receivedocs)
 {
     InitializeComponent();
     costElement                 = new CostElement();
     costElement.ItemID          = itemID;
     costElement.ItemUnitID      = itemUnitID;
     costElement.ManufacturerID  = manufacturerID;
     costElement.MovingAverageID = MovingAverageID;
     costElement.UnitCost        = UnitCost;
     costElement.Margin          = margin;
     costElement.Qty             = Qty;
     receiveDocs                 = receivedocs;
 }
コード例 #5
0
        private void btnSave_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 = Math.Round(Convert.ToDouble(dr["AverageCost"]), BLL.Settings.NoOfDigitsAfterTheDecimalPoint, MidpointRounding.AwayFromZero);
                    costElement.Margin      = Convert.ToDouble(dr["Margin"]);

                    costElement.SellingPrice = Math.Round(Convert.ToDouble(dr["SellingPrice"]), BLL.Settings.NoOfDigitsAfterTheDecimalPoint, MidpointRounding.AwayFromZero);
                    try
                    {
                        transaction.BeginTransaction();
                        var journalService = new JournalService();
                        journalService.StartRecordingSession();
                        costElement.SetPriceForReceiveDocs();
                        costElement.SavePrice(CurrentContext.UserId, costElement.ReceiptID.ToString(), journalService,
                                              ChangeMode.ErrorCorrection);
                        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.SetPrice(CurrentContext.UserId);
                receipt.ChangeStatus(ReceiptConfirmationStatus.Constants.PRICE_CALCULATED, null,
                                     this.GetFormIdentifier(), CurrentContext.UserId, "Price Set");
            }
        }
コード例 #6
0
        public ActionResult Create(CostElement model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.Created_By   = User.Identity.Name;
                    model.Created_Date = DateTime.Now.Date;
                    dbcontext.CostElement.Add(model);
                    dbcontext.SaveChanges();
                    //=================================check for alert==================================

                    var get_result_check = HR.Controllers.check.check_alert("cost elements", HR.Models.user.Action.Create, HR.Models.user.type_field.form);
                    if (get_result_check != null)
                    {
                        var inbox = new Models.user.Alert_inbox {
                            send_from_user_id = User.Identity.Name, send_to_user_id = get_result_check.send_to_ID_user, title = get_result_check.Subject, Subject = get_result_check.Message
                        };
                        if (get_result_check.until != null)
                        {
                            if (get_result_check.until.Value.Year != 0001)
                            {
                                inbox.until = get_result_check.until;
                            }
                        }
                        ApplicationDbContext dbcontext = new ApplicationDbContext();
                        dbcontext.Alert_inbox.Add(inbox);
                        dbcontext.SaveChanges();
                    }
                    //===================================================================================
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(model));
                }
            }
            catch (DbUpdateException e)
            {
                TempData["Message"] = HR.Resource.Basic.thiscodeIsalreadyexists;
                return(View(model));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }
コード例 #7
0
        public ActionResult Create()
        {
            //////
            var modell = new CostElement();

            var stru  = dbcontext.StructureModels.FirstOrDefault(m => m.All_Models == ChModels.Talent_Development).Structure_Code;
            var model = dbcontext.CostElement.ToList();

            if (model.Count() == 0)
            {
                modell.CostElement_Code = stru + "1";
            }
            else
            {
                modell.CostElement_Code = stru + (model.LastOrDefault().ID + 1).ToString();
            }
            /////
            return(View(modell));
        }
コード例 #8
0
        private void gridMasterView_DoubleClick(object sender, EventArgs e)
        {
            if (gridMasterView.GetFocusedRow() != null)
            {
                DataRow drv = gridMasterView.GetFocusedDataRow();
                if (Convert.ToBoolean(drv["pendingAverage"]))
                {
                    CostElement costElement = new CostElement(Convert.ToInt32(drv["ItemID"]), Convert.ToInt32(drv["MovingAverageID"]), Convert.ToInt32(drv["ManufacturerID"]), Convert.ToInt32(drv["UnitID"]));
                    costElement.Qty      = Convert.ToDouble(drv["NoOfPack"]);
                    costElement.UnitCost = Math.Round(Convert.ToDouble(drv["PricePerPack"]),
                                                      BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                      MidpointRounding.AwayFromZero);

                    costElement.Margin = Convert.ToDouble(drv["Margin"]) / 100;
                    MovingAverage movingAverage = new MovingAverage(costElement, drv["ReceiveDocIDs"].ToString());
                    movingAverage.ShowDialog(this);
                    lkWarehouse_EditValueChanged(null, null);
                }
            }
        }
コード例 #9
0
        //This is a fix It
        //It will fix the Cost if it is set on the ReceiveDoc but if not set on the picklistdetail
        //But if the receiveDoc is not set or GRV is not printed it will return false

        private static bool ValidateAndFixDeliveryNoteHasBeenProperlyPrice(DataView dv)
        {
            foreach (DataRowView drv in dv)
            {
                int         issueDocId, pickListDetailId;
                CostElement costElement = new CostElement();
                try
                {
                    issueDocId       = Convert.ToInt32(drv["IssueDocID"]);
                    pickListDetailId = Convert.ToInt32(drv["PickListDetailID"]);
                    PickListDetail pickListDetail = costElement.FixDeliveryNoteCostReceiveDoc(issueDocId, pickListDetailId);
                    drv["Cost"]      = pickListDetail.Cost;
                    drv["UnitPrice"] = pickListDetail.UnitPrice;
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(string.Format("You cannot print this STV:{0}", ex.Message), "Warning",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw ex;
                }
            }
            return(true);
        }
コード例 #10
0
 public WeightedAverageHistory(CostElement costElement)
 {
     this.costElement = costElement;
     InitializeComponent();
 }
コード例 #11
0
 public WeightedAverageHistory(int ItemID, int AccountID, int ManufacturerID, int ItemUnitID)
 {
     costElement = new CostElement(ItemID, AccountID, ManufacturerID, ItemUnitID);
     InitializeComponent();
 }
コード例 #12
0
        private UFIDA.U9.ISV.MFG.BOM.BOMComponentDTO4CreateSv CreateBOMComponentDTO(BOMComponent _bomComponent, int _iSeq, BOMMaster _bom, Organization _beOrg)
        {
            try
            {
                UFIDA.U9.ISV.MFG.BOM.BOMComponentDTO4CreateSv dtoComponent = new UFIDA.U9.ISV.MFG.BOM.BOMComponentDTO4CreateSv();

                dtoComponent.Sequence     = _iSeq;
                dtoComponent.OperationNum = "10";//默认工序号:空
                ItemMaster beItemComponent = ItemMaster.Finder.Find("Code=@code and Org=@org",
                                                                    new OqlParam[] { new OqlParam(_bomComponent.ItemCode), new OqlParam(_beOrg.ID) });
                if (beItemComponent == null)
                {
                    throw new Exception(string.Format("子件料号{0}在组织{1}下不存在!", _bomComponent.ItemCode, _beOrg.Code));
                }

                dtoComponent.ItemMaster      = new CommonArchiveDataDTO();
                dtoComponent.ItemMaster.ID   = beItemComponent.ID;
                dtoComponent.ItemMaster.Code = beItemComponent.Code;
                dtoComponent.ItemMaster.Name = beItemComponent.Name;
                //子项物料启用了版本管理
                if (beItemComponent.ItemMasterVersions != null && beItemComponent.ItemMasterVersions.Count > 0)
                {
                    dtoComponent.ItemVersionCode = _bomComponent.ItemVersionCode;
                }

                dtoComponent.ComponentType = ComponentTypeEnum.StandardComp;//标准

                dtoComponent.BOMCompSubstituteDTO4CreateSv = new List <BOMComponentDTO4CreateSv>();
                dtoComponent.UsageQtyType    = UsageQuantityTypeEnum.Variable;
                dtoComponent.UsageQty        = _bomComponent.UsageQty;
                dtoComponent.IssueUOM        = new CommonArchiveDataDTO();
                dtoComponent.IssueUOM.ID     = beItemComponent.MaterialOutUOM.ID;
                dtoComponent.IssueUOM.Code   = beItemComponent.MaterialOutUOM.Code;
                dtoComponent.IssueUOM.Name   = beItemComponent.MaterialOutUOM.Name;
                dtoComponent.PlanPercent     = 0;
                dtoComponent.IsCharge        = true;
                dtoComponent.FromQty         = 0;
                dtoComponent.ToQty           = 0;
                dtoComponent.IsEffective     = true;
                dtoComponent.SubstituteStyle = SubstituteStyleEnum.None;
                dtoComponent.ScrapType       = ScrapTypeEnum.SingleScrap;
                dtoComponent.FixedScrap      = beItemComponent.MfgInfo.ImmovableWaste; //固定损耗率
                dtoComponent.Scrap           = _bomComponent.Scrap;                    //损耗率
                dtoComponent.ParentQty       = _bomComponent.ParentQty;


                dtoComponent.SupplyStyle   = SupplyStyleEnum.Org;
                dtoComponent.IssueOrg      = new CommonArchiveDataDTO();
                dtoComponent.IssueOrg.ID   = _beOrg.ID;
                dtoComponent.IssueOrg.Code = _beOrg.Code;
                dtoComponent.IssueOrg.Name = _beOrg.Name;

                if (beItemComponent.InventoryInfo.Warehouse != null)
                {
                    dtoComponent.SupplyWareHouse      = new CommonArchiveDataDTO();//供应地点
                    dtoComponent.SupplyWareHouse.ID   = beItemComponent.InventoryInfo.Warehouse.ID;
                    dtoComponent.SupplyWareHouse.Code = beItemComponent.InventoryInfo.Warehouse.Code;
                    dtoComponent.SupplyWareHouse.Name = beItemComponent.InventoryInfo.Warehouse.Name;
                }
                dtoComponent.SetChkAtComplete    = false;
                dtoComponent.SetChkAtOptComplete = false;
                dtoComponent.SetChkAtOptStart    = false;
                if (_bom.BOMType == 1)
                {
                    dtoComponent.IsWholeSetIssue = true;
                }
                else
                {
                    dtoComponent.IsWholeSetIssue = false;
                }
                dtoComponent.StandardMaterialScale = 0;
                dtoComponent.IsOverIssue           = false;
                dtoComponent.IsATP             = false;
                dtoComponent.IsCTP             = false;
                dtoComponent.LeadTimeOffSet    = 0;
                dtoComponent.IsMandatory       = false;
                dtoComponent.IsExclude         = false;
                dtoComponent.IsDefault         = false;
                dtoComponent.IsOptionDependent = false;
                dtoComponent.IsCalcPrice       = false;
                dtoComponent.MinSelectedQty    = 1;
                dtoComponent.MaxSelectedQty    = 1;
                dtoComponent.CostElement       = new CommonArchiveDataDTO();
                CostElement beCost = CostElement.Finder.Find("Name='材料费'", new OqlParam[] { });
                if (beCost != null)
                {
                    dtoComponent.CostElement.ID   = beCost.ID;
                    dtoComponent.CostElement.Code = beCost.Code;
                    dtoComponent.CostElement.Name = beCost.Name;
                }
                dtoComponent.CostPercent = 0;//成本百分比
                dtoComponent.Remark      = _bomComponent.Remark;
                //直接读取料品属性,属于虚拟
                if (beItemComponent.ItemFormAttribute == ItemTypeAttributeEnum.Phantom)
                {
                    //如果子项勾选‘虚拟’,此处选择‘不发料
                    dtoComponent.IsPhantomPart = true;
                    dtoComponent.IssueStyle    = IssueStyleEnum.Phantom;
                }
                else
                {
                    dtoComponent.IsPhantomPart = false;
                    dtoComponent.IssueStyle    = IssueStyleEnum.Push;
                }
                //收货审核属性RCVApproved,标准接口未提供。

                dtoComponent.IsCeiling        = false; //是否取整
                dtoComponent.IsSpecialUseItem = false; //是否专项控制:默认不启用
                if (!String.IsNullOrEmpty(_bomComponent.CompProject))
                {
                    Project itemProject = Project.Finder.Find("Name=@name and Org=@org",
                                                              new OqlParam[] { new OqlParam(_bomComponent.CompProject), new OqlParam(_beOrg.ID) });

                    if (itemProject != null)
                    {
                        dtoComponent.CompProject      = new CommonArchiveDataDTO();
                        dtoComponent.CompProject.ID   = itemProject.ID;
                        dtoComponent.CompProject.Code = itemProject.Code;
                        dtoComponent.CompProject.Name = itemProject.Name;

                        dtoComponent.IsSpecialUseItem = true;//是否专项控制:指定项目后则设定为启用。
                    }
                    else
                    {
                        throw new Exception(string.Format("在{0}组织下没有找到{1}的项目号.", _beOrg.Name, _bomComponent.CompProject));
                    }
                }

                return(dtoComponent);
            }
            catch (Exception ex)
            {
                strbError.AppendLine(string.Format(strErrorItem, _bom.ItemMasterCode, _bomComponent.ItemCode, ex.Message));
                return(null);
            }
        }
コード例 #13
0
 public MovingAverage(CostElement costElement, string receivedocs)
 {
     InitializeComponent();
     this.costElement = costElement;
     receiveDocs      = receivedocs;
 }
コード例 #14
0
        private void btnApprove_Click(object sender, EventArgs e)
        {
            //dxCostingValidation.RemoveControlError(lkPeriod);
            if (!dxCostingValidation.Validate())
            {
                return;
            }
            if (lkWarehouse.EditValue != null && lkAccount.EditValue != null && XtraMessageBox.Show(String.Format("Are you sure you want to Approve All Items, Once Approved the item will be available for release"), "Are you sure...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    ReceiveDocConfirmation receiveDocConfirmation = new ReceiveDocConfirmation();
                    string   receiveDocs       = "";
                    string   rdPendingAverages = "";
                    var      ledgerService     = new LedgerService();
                    DataView dataView          = (gridMain.DataSource as DataView);
                    dataView.RowFilter = "PricePerPack <>0 and isConfirmed = 1";
                    foreach (DataRowView drv in dataView)
                    {
                        var costElement = new CostElement
                        {
                            ItemID          = Convert.ToInt32(drv["ItemID"]),
                            ItemUnitID      = Convert.ToInt32(drv["UnitID"]),
                            ManufacturerID  = Convert.ToInt32(drv["ManufacturerID"]),
                            MovingAverageID = Convert.ToInt32(drv["MovingAverageID"])
                        };

                        var ledgerObject = ledgerService.GetLedger(costElement.ItemID, costElement.ItemUnitID,
                                                                   costElement.ManufacturerID, costElement.MovingAverageID);

                        costElement.UnitCost = Math.Round(Convert.ToDouble(ledgerObject.UnitCost),
                                                          BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                          MidpointRounding.AwayFromZero);
                        costElement.AverageCost = Math.Round(Convert.ToDouble(drv["PricePerPack"]),
                                                             BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                             MidpointRounding.AwayFromZero);
                        costElement.Margin       = Convert.ToDouble(drv["Margin"]) / 100;
                        costElement.SellingPrice = costElement.AverageCost * (1 + costElement.Margin);
                        var isSound = drv["Remark"].Equals("Sound");
                        if ((Math.Abs(costElement.UnitCost - costElement.AverageCost) == 0) || !isSound)
                        {
                            receiveDocs = receiveDocs != ""
                                       ? receiveDocs + ',' + drv["ReceiveDocIDs"].ToString()
                                       : receiveDocs + drv["ReceiveDocIDs"].ToString();
                        }
                        else if (ReceiveDoc.GetSoundStock(costElement) > 0)
                        {
                            rdPendingAverages = rdPendingAverages != ""
                                             ? rdPendingAverages + ',' + drv["ReceiveDocIDs"].ToString()
                                             : rdPendingAverages + drv["ReceiveDocIDs"].ToString();
                        }
                        else
                        {
                            IJournalService journal = new JournalService();
                            journal.StartRecordingSession();
                            costElement.SavePrice(CurrentContext.UserId, "", journal, ChangeMode.BeginningBalance);
                            journal.CommitRecordingSession();

                            journal.StartRecordingSession();
                            costElement.ConfirmPrice(CurrentContext.UserId, "", journal, ChangeMode.BeginningBalance);
                            journal.CommitRecordingSession();

                            receiveDocs = receiveDocs != ""
                                       ? receiveDocs + ',' + drv["ReceiveDocIDs"].ToString()
                                       : receiveDocs + drv["ReceiveDocIDs"].ToString();
                        }
                    }

                    receiveDocConfirmation.ChangeStatusByAccountReceiveDocs(receiveDocs,
                                                                            ReceiptConfirmationStatus.Constants.GRV_PRINTED,
                                                                            ReceiptConfirmationStatus.Constants.GRNF_PRINTED);
                    receiveDocConfirmation.ChangeStatusByAccountReceiveDocs(rdPendingAverages,
                                                                            ReceiptConfirmationStatus.Constants.
                                                                            PRICE_CALCULATED,
                                                                            ReceiptConfirmationStatus.Constants.GRNF_PRINTED);
                    XtraMessageBox.Show("Price has been successfully confirmed", "Success...", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                }
                catch (Exception exception)
                {
                    XtraMessageBox.Show(exception.Message, "Success...", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    throw;
                }
                lkWarehouse_EditValueChanged(null, null);
            }
        }
コード例 #15
0
        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);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            DataView dtChangedPricelist = gridViewPriceList.DataSource as DataView;

            if (dtChangedPricelist != null)
            {
                dtChangedPricelist.RowFilter = "IsConfirmed = 1";

                foreach (DataRowView drw in dtChangedPricelist)
                {
                    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);
                            costElement.SellingPrice = Math.Round(Convert.ToDouble(drw["SellingPrice"]),
                                                                  BLL.Settings.NoOfDigitsAfterTheDecimalPoint,
                                                                  MidpointRounding.AwayFromZero);


                            costElement.ConfirmPrice(CurrentContext.UserId, "", journalService, ChangeMode.PriceOverride);
                            ReceiveDoc 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;
                        }
                    }
                }
                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);
        }