private void btnSaveLocationRelatedInformation_Click(object sender, EventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                if (gridLocationRelatedInventory.DataSource != null && (gridLocationRelatedInventory.DataSource as DataTable).GetChanges() != null)
                {
                    transaction.BeginTransaction();
                    foreach (DataRow dataRow in (gridLocationRelatedInventory.DataSource as DataTable).GetChanges().Rows)
                    {
                        InventoryService.SaveInventoryRow(dataRow);
                    }


                    transaction.CommitTransaction();
                    XtraMessageBox.Show("Draft successfully saved!", "Success",
                                        System.Windows.Forms.MessageBoxButtons.OK,
                                        System.Windows.Forms.MessageBoxIcon.Information);
                    btnLoadInventory_Click(null, null);
                }
                else
                {
                    throw new Exception("No Record Was Change");
                }
            }
            catch (Exception ex)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Пример #2
0
        private void btnCancelVoidRequest_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("Are you sure you want to cancel the void request?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                try
                {
                    mgr.BeginTransaction();
                    BLL.Issue stv = new BLL.Issue();
                    stv.LoadByPrimaryKey(_activeSTVID);
                    stv.CancelVoidRequest(CurrentContext.UserId);
                    mgr.CommitTransaction();
                    this.LogActivity("Cancel-Void", _activeSTVID);
                    XtraMessageBox.Show("Void request cancelled!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exp)
                {
                    mgr.RollbackTransaction();
                    XtraMessageBox.Show("System couldn't perform the requested action, Please contact administrator", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ErrorHandler.Handle(exp);
                }

                BindUnconfirmedIssues();
                gridUndispatchedIssueDetails.DataSource = null;
            }
        }
        private void btnSaveAndForward_Click(object sender, EventArgs e)
        {
            if (ValidateForm() && XtraMessageBox.Show(String.Format("Are you sure,you want to Transfer Items To {0}", TransferTypeID != 2?lkForHub.Text:lkToActivity.Text), "Are you Sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                DataView dv = orderGrid.DataSource as DataView;

                if (dv != null && dv.Count != 0)
                {
                    MyGeneration.dOOdads.TransactionMgr transactionMgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

                    try
                    {
                        transactionMgr.BeginTransaction();
                        SaveOrder();

                        transactionMgr.CommitTransaction();
                    }
                    catch (Exception exp)
                    {
                        transactionMgr.RollbackTransaction();
                        XtraMessageBox.Show(exp.Message.ToString());
                    }
                    ResetOrder();
                    BindMainOrderGrid();
                }
                else
                {
                    XtraMessageBox.Show("Please select item");
                }
            }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ordID"></param>
        /// <param name="returnToApproval">When false, the order is cancelled completely</param>
        /// <returns></returns>
        public static bool ReleaseReservation(int ordID, bool returnToApproval)
        {
            BLL.Order ord = new BLL.Order();
            ord.LoadByPrimaryKey(ordID);
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                transaction.BeginTransaction();
                if (ord.RowCount > 0 && (ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_GENERATED || ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_CONFIRMED))
                {
                    ord.ReleaseReservation();
                    if (returnToApproval)
                    {
                        ord.ChangeStatus(OrderStatus.Constant.ORDER_FILLED, CurrentContext.UserId);
                    }
                    else
                    {
                        ord.ChangeStatus(OrderStatus.Constant.CANCELED, CurrentContext.UserId);
                    }
                    ord.Save();
                }

                transaction.CommitTransaction();
                return(true);
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw (exp);
            }
        }
Пример #5
0
        private void btnApproveVoidRequest_Click(object sender, EventArgs e)
        {
            BLL.Issue stv = new BLL.Issue();
            stv.LoadByPrimaryKey(_activeSTVID);

            if (!stv.IsColumnNull("VoidRequest") && !stv.VoidRequest)
            {
                XtraMessageBox.Show("There is no void request for this STV", "No Void Request",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                return;
            }

            if (XtraMessageBox.Show("Are you sure you want to void this STV/Invoice?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                try
                {
                    mgr.BeginTransaction();
                    MarkSTVAsVoid(CurrentContext.UserId);
                    mgr.CommitTransaction();
                    this.LogActivity("Approve-Void", _activeSTVID);
                    XtraMessageBox.Show("STV/Invoice Voided!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exp)
                {
                    mgr.RollbackTransaction();
                    XtraMessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //XtraMessageBox.Show("System couldn't perform the requested action, Please contact administrator", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ErrorHandler.Handle(exp);
                }

                BindUnconfirmedIssues();
                gridUndispatchedIssueDetails.DataSource = null;
            }
        }
Пример #6
0
        private void btnReturn_Click(object sender, EventArgs e)
        {
            //TODO: finish updating the changed locations
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            if (gridGRVs.DataSource == null)
            {
                return;
            }
            transaction.BeginTransaction();
            try
            {
                PalletLocation pl     = new PalletLocation();
                BLL.ReceiveDoc recDoc = new ReceiveDoc();
                recDoc.LoadByReceiptID(ReceiptID);
                recDoc.SetStatusAsReceived(null);
                BLL.Receipt receiptStatus = new BLL.Receipt();
                receiptStatus.LoadByPrimaryKey(ReceiptID);
                receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.RECEIVE_ENTERED, null, this.GetFormIdentifier(), CurrentContext.UserId, "Return For Quantity Editing");

                transaction.CommitTransaction();
                this.LogActivity("Return-Receipt-To-Quantity-Confirmation", ReceiptID);
                XtraMessageBox.Show("Receipt Returned!", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw exp;
            }
            PutAwayListsLoad(null, null);
        }
        private void btnSetNewPrice_Click(object sender, EventArgs e)
        {
            bool       validated = false;
            ReceiveDoc rd        = new ReceiveDoc();

            validated = dxValidationProviderPrice.Validate();


            if (!validated)
            {
                XtraMessageBox.Show("Please fill in all required fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!isConfirmation)
            {
                if (XtraMessageBox.Show("Are u sure, you want to save the new price change?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    MyGeneration.dOOdads.TransactionMgr transactionMgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                    transactionMgr.BeginTransaction();
                    try
                    {
                        rs.NewUnitCost     = Convert.ToDouble(txtAverageCost.EditValue);
                        rs.Margin          = Convert.ToDouble(txtMargin.EditValue);
                        rs.NewSellingPrice = Convert.ToDouble(txtSellingPrice.EditValue);
                        rs.NewPrice        = rs.NewSellingPrice;
                        //rs.Remark = txtRemark.EditValue.ToString();
                        // set the item as  weighted average item
                        Item itm = new Item();
                        itm.LoadByPrimaryKey(rs.ItemID);
                        itm.IsFree = false;

                        itm.Save();

                        rd.SavePrice(rs, CurrentContext.UserId);

                        transactionMgr.CommitTransaction();
                        XtraMessageBox.Show("Price setting successful", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        transactionMgr.RollbackTransaction();
                        XtraMessageBox.Show("Price setting failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw ex;
                    }
                }
            }
            else
            {
                if (XtraMessageBox.Show("Are you sure you want to approve the new price change.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    rd.ConfirmMovingAverage(rs, CurrentContext.UserId);
                    XtraMessageBox.Show("Price setting successful", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

            ResetForm();
        }
        private void btnPrintSTV_Click(object sender, EventArgs e)
        {
            DataRow dataView = gridDeliveryNoteView.GetFocusedDataRow();

            if (dataView != null)
            {
                int stvlogID = Convert.ToInt32(dataView["ID"]);

                DataView dv = PickList.GetPickedItemsOnSTV(stvlogID, false);

                if (dv.Count > 0 && ValidateAndFixDeliveryNoteHasBeenProperlyPrice(dv))
                {
                    LogIssues logScreen = new LogIssues();

                    BLL.Issue stvLog = new BLL.Issue();
                    stvLog.LoadByPrimaryKey(stvlogID);

                    PickList pickList = new PickList();
                    pickList.LoadByPrimaryKey(stvLog.PickListID);
                    XtraReport  xtraReport;
                    PrintDialog printDialog = new PrintDialog();
                    if (printDialog.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }

                    MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

                    try
                    {
                        mgr.BeginTransaction();

                        xtraReport = logScreen.RePrintSTV(dv, pickList.OrderID, pickList, stvlogID, true);
                        stvLog.HasDeliveryNoteBeenConverted = true;
                        stvLog.Save();
                        mgr.CommitTransaction();
                    }
                    catch (Exception exception)
                    {
                        mgr.RollbackTransaction();
                        XtraMessageBox.Show("Print Problem:" + exception.Message, "Print Problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw;
                    }
                    if (xtraReport != null)
                    {
                        xtraReport.Print(printDialog.PrinterSettings.PrinterName);
                    }
                    lkStore_EditValueChanged(null, null);
                }
                else
                {
                    XtraMessageBox.Show(
                        "You cannot print this STV because price has not been set for all item. Please try again");
                }
            }
        }
Пример #9
0
        private void btnReturnToApprovalStep_Click(object sender, EventArgs e)
        {
            //int ordId = Convert.ToInt32(gridApprovedOrdersView.GetFocusedDataRow()["ID"].ToString());

            Order ord = new Order();

            ord.LoadByPrimaryKey(_orderID);
            if (ord.RowCount == 0)
            {
                XtraMessageBox.Show("You have to select an Order to return to approval, ", "Error - Select Order");
                return;
            }
            if (!ord.IsColumnNull("OrderTypeID") && ord.OrderTypeID != OrderType.CONSTANTS.STANDARD_ORDER)
            {
                XtraMessageBox.Show("You cannot return this order to approval, you can either cancel or confirm this order", "Error - You cannot return this order");
                return;
            }

            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                transaction.BeginTransaction();

                if (ord.RowCount > 0 && ord.OrderStatusID == OrderStatus.Constant.ORDER_APPROVED)
                {
                    ord.ChangeStatus(OrderStatus.Constant.ORDER_FILLED, CurrentContext.UserId);
                    BindApprovedOrders();
                }
                else if (ord.RowCount > 0 && ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_GENERATED)
                {
                    ord.ReleaseReservation();
                    ord.ChangeStatus(OrderStatus.Constant.ORDER_FILLED, CurrentContext.UserId);
                    BindApprovedOrders();
                }
                transaction.CommitTransaction();
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw exp;
            }
            gridPickListDetail.DataSource = null;
            //HCMISLoader.MarkAsDirtyUsingOrderID(_orderID, NewMainWindow.UserId, true);
            if (BLL.Settings.IsCenter)
            {
                XtraMessageBox.Show("The Issue Order List has been returned to approval stage", "Confirmation",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                XtraMessageBox.Show("The Pick list has been returned to approval stage", "Confirmation",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void ReturnToStoreForQuantityEdit()
        {
            //TODO: finish updating the changed locations
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            transaction.BeginTransaction();
            try
            {
                PalletLocation pl        = new PalletLocation();
                String         reference = gridReceiveView.GetFocusedDataRow()["RefNo"].ToString();
                //           pl.ConfirmAllReceived(reference);
                if (gridDetailView.DataSource == null)
                {
                    return;
                }

                foreach (DataRowView drv in gridDetailView.DataSource as DataView)
                {
                    int PalletLocationID         = Convert.ToInt32(drv["PalletLocationID"]);
                    int ProposedPalletLocationID = Convert.ToInt32(drv["ProposedPalletLocationID"]);
                    int PalletID  = Convert.ToInt32(drv["PalletID"]);
                    int receiveID = Convert.ToInt32(drv["ReceiveID"]);

                    if (PalletLocationID != ProposedPalletLocationID)
                    {
                        pl.LoadByPrimaryKey(PalletLocationID);
                        if (pl.IsColumnNull("PalletID"))
                        {
                            pl.Confirmed = false;
                            pl.Save();
                        }
                    }
                    else
                    {
                        pl.LoadByPrimaryKey(PalletLocationID);
                        pl.Confirmed = false;
                        pl.Save();
                    }
                }



                BLL.ReceiveDoc recDoc = new ReceiveDoc();
                recDoc.LoadByReferenceNo(reference);
                recDoc.SetStatusAsReceived(null);
                transaction.CommitTransaction();
                XtraMessageBox.Show("Receipt Returned!", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                BindFormContents();
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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");
            }
        }
Пример #12
0
        public void RecordAverageCostAndSellingPrice(int userID)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                transaction.BeginTransaction();
                DataTable           ReceiveDocDetails;
                IList <CostElement> costElements = new List <CostElement>();

                foreach (DataRowView drv in GRVSoundDetail.DefaultView as DataView)
                {
                    double NewUnitCost, NewSellingPrice;
                    if (drv["AverageCost"] != DBNull.Value && drv["SellingPrice"] != DBNull.Value)
                    {
                        CostElement costElement = new CostElement();
                        costElement.ItemID          = Convert.ToInt32(drv["ItemID"]);
                        costElement.ItemUnitID      = Convert.ToInt32(drv["ItemUnitID"]);
                        costElement.MovingAverageID = Convert.ToInt32(drv["MovingAverageID"]);
                        costElement.ManufacturerID  = Convert.ToInt32(drv["ManufacturerID"]);
                        costElement.AverageCost     = costElement.SellingPrice = Math.Round(Convert.ToDouble(drv["SellingPrice"]), Settings.NoOfDigitsAfterTheDecimalPoint);
                        costElement.Margin          = drv["Margin"] != DBNull.Value ? Convert.ToDouble(drv["Margin"]) : 0;
                        ReceiveDocDetails           =
                            ReceiveDoc.GetRelatedReceiveForUnitCostAndSellingPrice(ReceiptID, costElement);


                        foreach (DataRowView Cursor in ReceiveDocDetails.AsDataView())
                        {
                            int ID = Convert.ToInt32(Cursor["ID"]);
                            ReceiveDoc.SetAverageCostByReceiveDoc(ID, costElement.AverageCost, userID);
                            ReceiveDoc.SetSellingPriceByReceiveDoc(ID, costElement.SellingPrice, userID);
                        }
                        costElements.Add(costElement);
                    }
                }
                try
                {
                    CostingService.SavePriceChange(costElements.AsEnumerable(), userID, ChangeMode.Recieve, ReceiptID.ToString());
                }
                catch (Exception)
                {
                    //Until Cost Tier Implementation
                }
                transaction.CommitTransaction();
            }
            catch (Exception ex)
            {
                transaction.RollbackTransaction();
                throw ex;
            }
        }
Пример #13
0
        private void OnConfirmClicked(object sender, EventArgs e)
        {
            printDialog = new PrintDialog();

            if (printDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                XtraMessageBox.Show("Print has been Canceled By User");
                return;
            }
            if (BLL.Settings.IsCenter)
            {
                GRV = new CenterCostCalculator();
                GRV.LoadGRV(ReceiptID);
                GRV.CalculateFinalCost();
            }
            else
            {
                GRV = new CostCalculator();
                GRV.LoadGRV(ReceiptID);
                (GRV as CostCalculator).LoadGRVPreviousStock();
                GRV.CalculateFinalCost();
            }
            if (!SetSellingPrice(GRV))
            {
                return;
            }

            HCMIS.Desktop.Reports.ReceiptConfirmationPrintout printout = new HCMIS.Desktop.Reports.ReceiptConfirmationPrintout(CurrentContext.LoggedInUserName);
            MyGeneration.dOOdads.TransactionMgr transaction            = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                transaction.BeginTransaction();
                // This is where we set the Price for the previous Stock
                foreach (CostElement costElement in GRV.CostElements)
                {
                    costElement.PreviousCostDetials.Confirm(CurrentContext.UserId);
                }
                printout = PrintConfirmation(null);
                CostingService.ConfirmPriceChange(GRV.CostElements, CurrentContext.UserId, ChangeMode.Recieve, ReceiptID.ToString());
                GRV.SetFinalCostlog(CurrentContext.UserId);
                transaction.CommitTransaction();
            }
            catch (Exception ex)
            {
                transaction.RollbackTransaction();

                XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
            printout.Print(printDialog.PrinterSettings.PrinterName);
        }
        /// <summary>
        /// Handles the Click event of the btnReprint control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void btnReprint_Click(object sender, EventArgs e)
        {
            var issue = new Issue();

            issue.LoadByPrimaryKey(_stvLogIdChosen.Value);
            if (!Validate(issue))
            {
                return;
            }

            var orderId = Convert.ToInt32(gridViewTransaction.GetFocusedDataRow()["OrderID"]);
            var pl      = new PickList();
            var dv      = pl.GetPickedOrderDetailForOrder(_stvLogIdChosen.Value, false);

            MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            XtraReport  xtraReport;
            PrintDialog printDialog = new PrintDialog();

            if (printDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }


            try
            {
                mgr.BeginTransaction();

                xtraReport = RePrintSTV(dv, orderId, pl, _stvLogIdChosen, _isConvertedDn);

                mgr.CommitTransaction();
            }
            catch (Exception exception)
            {
                mgr.RollbackTransaction();
                XtraMessageBox.Show("Print Problem:" + exception.Message, "Print Problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }

            if (xtraReport != null)
            {
                xtraReport.Print(printDialog.PrinterSettings.PrinterName);
            }

            FilterStvLog();
        }
 private void btnReprintGRV_Click(object sender, EventArgs e)
 {
     MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
     try
     {
         transaction.BeginTransaction();
         DataRow dr = gridReceiveView.GetFocusedDataRow();
         int?    receiptConfirmationPrintoutID = Convert.ToInt32(dr["ID"]);
         PrintConfirmation(receiptConfirmationPrintoutID);
         transaction.CommitTransaction();
     }
     catch (Exception ex)
     {
         transaction.RollbackTransaction();
         XtraMessageBox.Show(ex.Message);
     }
 }
        private void btnMovingAverage_Click(object sender, EventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            var dialogResult =
                XtraMessageBox.Show(
                    String.Format("Are you Sure you want to Set the  Price for {0}", txtItemName.Text),
                    "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.SavePrice(CurrentContext.UserId, "", journalService, ChangeMode.BeginningBalance);
                    journalService.CommitRecordingSession();
                    journalService.StartRecordingSession();
                    costElement.ConfirmPrice(CurrentContext.UserId, "", journalService, ChangeMode.BeginningBalance);
                    journalService.CommitRecordingSession();
                    ReceiveDoc receiveDoc = new ReceiveDoc();
                    receiveDoc.SavePrice(costElement, CurrentContext.UserId);

                    ReceiveDocConfirmation receiveDocConfirmation = new ReceiveDocConfirmation();
                    receiveDocConfirmation.ChangeStatusByAccountReceiveDocs(receiveDocs, ReceiptConfirmationStatus.Constants.GRV_PRINTED, ReceiptConfirmationStatus.Constants.PRICE_CALCULATED);
                    transaction.CommitTransaction();
                    this.Close();
                }
                catch (Exception exception)
                {
                    transaction.RollbackTransaction();
                    XtraMessageBox.Show("Error : " + exception.Message, "Error...", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    throw exception;
                }
            }
        }
        private void btnReturnToApprovalStep_Click(object sender, EventArgs e)
        {
            //int ordId = Convert.ToInt32(gridApprovedOrdersView.GetFocusedDataRow()["ID"].ToString());
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                transaction.BeginTransaction();
                Order ord = new Order();
                ord.LoadByPrimaryKey(_orderID);
                if (ord.RowCount > 0 && ord.OrderStatusID == OrderStatus.Constant.ORDER_APPROVED)
                {
                    ord.OrderStatusID = OrderStatus.Constant.ORDER_FILLED;
                    ord.Save();
                    BindApprovedOrders();
                }
                else if (ord.RowCount > 0 && ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_GENERATED)
                {
                    ord.ReleaseReservation();
                    ord.OrderStatusID = OrderStatus.Constant.ORDER_FILLED;
                    ord.Save();
                    BindApprovedOrders();
                }
                transaction.CommitTransaction();
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw exp;
            }
            gridPickListDetail.DataSource = null;
            //HCMISLoader.MarkAsDirtyUsingOrderID(_orderID, NewMainWindow.UserId, true);
            if (BLL.Settings.IsCenter)
            {
                XtraMessageBox.Show("The Issue Order List has been returned to approval stage", "Confirmation",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                XtraMessageBox.Show("The Pick list has been returned to approval stage", "Confirmation",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 private void OnConfirmClicked(object sender, EventArgs e)
 {
     if (currentMode == Modes.DeliveryNotePrinting)
     {
         MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
         try
         {
             transaction.BeginTransaction();
             SetFinalCost();
             PrintConfirmation(null);
             transaction.CommitTransaction();
         }
         catch (Exception ex)
         {
             transaction.RollbackTransaction();
             XtraMessageBox.Show(ex.Message);
         }
     }
 }
Пример #19
0
        private void btnReturnToApprovalStep_Click(object sender, EventArgs e)
        {
            //int ordId = Convert.ToInt32(gridApprovedOrdersView.GetFocusedDataRow()["ID"].ToString());
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                transaction.BeginTransaction();
                Order ord = new Order();
                ord.LoadByPrimaryKey(_orderID);
                if (ord.RowCount > 0 && ord.OrderStatusID == OrderStatus.Constant.ORDER_APPROVED)
                {
                    ord.ChangeStatus(OrderStatus.Constant.ORDER_FILLED, CurrentContext.UserId);;
                    BindApprovedOrders();
                }

                transaction.CommitTransaction();

                this.LogActivity("Return-Pick-List-To-Approval", ord.ID);
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw exp;
            }
            gridPickListDetail.DataSource = null;

            if (BLL.Settings.IsCenter)
            {
                XtraMessageBox.Show("The Issue Order List has been returned to approval stage", "Confirmation",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                XtraMessageBox.Show("The Pick list has been returned to approval stage", "Confirmation",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private void btnRowSave_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            DataRow dataRow = gridLocationRelatedInventoryView.GetFocusedDataRow();

            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                transaction.BeginTransaction();
                if (this.HasPermission("Edit-Commited"))
                {
                    if (dataRow.RowState == DataRowState.Unchanged &&
                        XtraMessageBox.Show("No Record Was Changeed! , Du you still want to proceed? ", "Confirmation",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes)
                    {
                        return;
                    }

                    InventoryService.SaveInventoryRow(dataRow);

                    transaction.CommitTransaction();
                    XtraMessageBox.Show("Draft successfully saved!", "Success",
                                        System.Windows.Forms.MessageBoxButtons.OK,
                                        System.Windows.Forms.MessageBoxIcon.Information);
                    btnLoadInventory_Click(null, null);
                }
                else
                {
                    throw new Exception("You have no permission, please contact Administrator!");
                }
            }
            catch (Exception exception)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #21
0
        private void SavePickListItems(object sender, EventArgs e)
        {
            var ord = new Order();
            var rus = new Institution();

            ord.LoadByPrimaryKey(_orderID);
            rus.LoadByPrimaryKey(ord.RequestedBy);

            if (_dvPickListMakeup == null || ValidatePickList())
            {
                return;
            }

            // First of all .. print the pick list
            var pls = new PickList();

            PrintPickList(ord, rus);

            MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                mgr.BeginTransaction();
                pls.SavePickList(_orderID, _dvPickListMakeup, CurrentContext.UserId);
                mgr.CommitTransaction();

                BindApprovedOrders();
                this.LogActivity("Print-Pick-List", ord.ID);
                XtraMessageBox.Show("Your pick list has been saved! please continue to the next step or prepare another Picklist here.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exp)
            {
                mgr.RollbackTransaction();
                ViewHelper.ShowErrorMessage("System couldn't save the Pick List, Please contact administrator for additional help", exp);
                ErrorHandler.Handle(exp);
            }
        }
Пример #22
0
        private void tpDelete_Click(object sender, EventArgs e)
        {
            DataRow dr = gridViewBinCard.GetFocusedDataRow();

            if (Convert.ToInt32(dr["Precedance"]) != 3)
            {
                XtraMessageBox.Show("You cannot delete this");
                return;
            }
            if (CurrentContext.LoggedInUser.UserType == UserType.Constants.DISTRIBUTION_MANAGER_WITH_DELETE)
            {
                if (
                    XtraMessageBox.Show(
                        "Are you sure you want to delete this transaction? You will not be able to undo this.",
                        "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    MyGeneration.dOOdads.TransactionMgr tranMgr =
                        MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

                    try
                    {
                        tranMgr.BeginTransaction();

                        ReceiveDoc    rdoc = new ReceiveDoc();
                        ReceivePallet rp   = new ReceivePallet();
                        IssueDoc      idoc = new IssueDoc();

                        PickListDetail pld     = new PickListDetail();
                        int            issueID = Convert.ToInt32(dr["ID"]);
                        //pld.LoadByOrderAndItem(Convert.ToInt32(dr["OrderID"]), Convert.ToInt32(dr["ItemID"]),
                        //                       Convert.ToInt32(dr["Quantity"]));
                        idoc.LoadByPrimaryKey(issueID);
                        pld.LoadByPrimaryKey(idoc.PLDetailID);

                        string RefNo = idoc.RefNo;

                        rdoc.LoadByPrimaryKey(idoc.RecievDocID);


                        //if (pld.RowCount == 0)
                        //{
                        //    pld.LoadByOrderAndItem(Convert.ToInt32(dr["OrderID"]), Convert.ToInt32(dr["ItemID"]));
                        //}

                        rp.LoadByPrimaryKey(pld.ReceivePalletID);
                        PalletLocation pl = new PalletLocation();
                        pl.loadByPalletID(rp.PalletID);

                        if (pl.RowCount == 0)
                        {
                            pl.LoadByPrimaryKey(pld.PalletLocationID);
                            if (pl.IsColumnNull("PalletID"))
                            {
                                pl.PalletID = rp.PalletID;
                                pl.Save();
                            }
                            //rp.LoadNonZeroRPByReceiveID(rdoc.ID);
                        }


                        if (rp.RowCount == 0)
                        {
                            XtraMessageBox.Show("You cannot delete this item, please contact the administrator", "Error");
                            return;
                        }
                        if (rp.RowCount > 0)
                        {
                            rdoc.QuantityLeft += idoc.Quantity;
                            rp.Balance        += idoc.Quantity;
                            pld.QuantityInBU   = 0;


                            // are we adding it the pick face?
                            // if so add it to the balance of the pick face also
                            pl.loadByPalletID(rp.PalletID);

                            if (pl.RowCount == 0)
                            {
                                PutawayLocation plocation = new PutawayLocation(rdoc.ItemID);

                                // we don't have a location for this yet,
                                // select a new location
                                //PutawayLocataion pl = new PutawayLocataion();
                                if (plocation.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    pl.LoadByPrimaryKey(plocation.PalletLocationID);
                                    if (pl.RowCount > 0)
                                    {
                                        pl.PalletID = rp.PalletID;
                                        pl.Save();
                                    }
                                }
                            }

                            if (pl.RowCount > 0)
                            {
                                PickFace pf = new PickFace();
                                pf.LoadByPalletLocation(pl.ID);
                                if (pf.RowCount > 0)
                                {
                                    pf.Balance += Convert.ToInt32(idoc.Quantity);
                                    pf.Save();
                                }


                                IssueDocDeleted.AddNewLog(idoc, CurrentContext.UserId);
                                idoc.MarkAsDeleted();
                                rdoc.Save();
                                rp.Save();
                                idoc.Save();


                                // now refresh the window
                                XtraMessageBox.Show("Issue Deleted!", "Confirmation", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Information);
                                tranMgr.CommitTransaction();
                                //TODO: refresh the list
                                // gridViewReferences_FocusedRowChanged(null, null);
                            }
                        }
                        else
                        {
                            XtraMessageBox.Show(
                                "This delete is not successfull because a free pick face location was not selected. please select a free location and try again.",
                                "Error Deleteing issue transaction", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            tranMgr.RollbackTransaction();
                        }
                    }
                    catch
                    {
                        XtraMessageBox.Show("This delete is not successfull", "Warning ...", MessageBoxButtons.OK,
                                            MessageBoxIcon.Warning);
                        tranMgr.RollbackTransaction();
                    }
                }
            }
            else
            {
                XtraMessageBox.Show(
                    "You cannot delete this transaction because you don't have previlage. Please contact the administrator if you thing this is an error.",
                    "Delete is not allowed");
            }
        }
        private void SavePickListItems(object sender, EventArgs e)
        {
            BLL.Order       ord = new BLL.Order();
            BLL.Institution rus = new Institution();
            ord.LoadByPrimaryKey(_orderID);


            // if the pick list has already been printed ... go ahead and pass it to the next level
            if (ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_GENERATED)
            {
                ord.OrderStatusID = OrderStatus.Constant.PICK_LIST_CONFIRMED;
                ord.Save();
                BindApprovedOrders();
                gridPickListDetail.DataSource = null;
                XtraMessageBox.Show("The Pick List has been Confirmed", "Confirmation", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                return;
            }

            if (_dvPickListMakeup != null)
            {
                MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                try
                {
                    mgr.BeginTransaction();
                    // First of all .. print the pick list

                    rus.LoadByPrimaryKey(ord.RequestedBy);

                    var pl = HCMIS.Desktop.Reports.WorkflowReportFactory.CreatePicklistReport(ord, rus,
                                                                                              _dvPickListMakeup);
                    pl.PrintDialog();
                    var pls = new PickList();

                    pls.SavePickList(_orderID, _dvPickListMakeup, CurrentContext.UserId);

                    // Refresh the current window
                    BindApprovedOrders();
                    // clear the working grid
                    gridPickListDetail.DataSource = null;
                    mgr.CommitTransaction();
                    XtraMessageBox.Show("Your pick list has been saved! please continue to the next step or prepare another Picklist here.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exp)
                {
                    mgr.RollbackTransaction();
                    BLL.User user = new User();
                    //user.LoadByPrimaryKey(NewMainWindow.UserId);
                    user = CurrentContext.LoggedInUser;
                    if (user.UserType == UserType.Constants.ADMIN || user.UserType == UserType.Constants.SUPER_ADMINISTRATOR)
                    {
                        XtraMessageBox.Show(exp.Message);
                    }
                    else
                    {
                        XtraMessageBox.Show("System couldn't save the Pick List, Please contact administrator for additional help", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    ErrorHandler.Handle(exp);
                }
            }
        }
Пример #24
0
        private void btnConfirmIssue_Click(object sender, EventArgs e)
        {
            var Instance = new SoftwareSettings();

            Instance.GetValue("IsCenter");
            dxValidationProvider1.Validate();
            BLL.Issue stv = new BLL.Issue();
            stv.LoadByPrimaryKey(_activeSTVID);
            // bool isValid = dxValidationProvider1.Validate();
            var activity = new Activity();

            activity.LoadByPrimaryKey(stv.StoreID);

            if (activity.IsHealthProgram()) // if (!isValid && Mode.IsFreeStore(stv.StoreID))
            {
                dxValidationProvider1.RemoveControlError(txtPreprintedInvoiceNo);
            }

            if (Convert.ToBoolean(Instance.Value)) // When IsCenter is true. txtPreprintedInvoiceNo should be disabled as a requirment
            {
                dxValidationProvider1.RemoveControlError(txtPreprintedInvoiceNo);
            }

            if (Convert.ToBoolean(Instance.Value) && !activity.IsHealthProgram())
            {
                dxValidationProvider1.RemoveControlError(txtPreprintedInvoiceNo);
            }
            if (!Convert.ToBoolean(Instance.Value) && !activity.IsHealthProgram())  //   if (!isValid && !Mode.IsFreeStore(stv.StoreID))
            {
                if (!dxValidationProvider1.Validate())
                {
                    return;
                }
                //XtraMessageBox.Show("Please input the required fields.", "Required Fields Missing", MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                //return;
            }
            if (XtraMessageBox.Show("Are you sure you want to confirm this dispatch?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                try
                {
                    mgr.BeginTransaction();
                    //Mark the dispatch as confirmed. (Store the differences in the dispatched values somewhere)
                    int?preprintedID;
                    if (txtPreprintedInvoiceNo.Text == "")
                    {
                        preprintedID = null;
                    }
                    else
                    {
                        preprintedID = int.Parse(txtPreprintedInvoiceNo.Text);
                    }

                    if (!stv.MarkAsDispatched(CurrentContext.UserId, preprintedID))
                    {
                        XtraMessageBox.Show("Void request has been sent for this STV, you can't dispatch it!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        throw new Exception("Void request sent on this STV number");
                    }
                    if (_discrepancyIssueDoc.Count > 0)
                    {
                        //Save the discrepancies.
                        BLL.IssueDoc.RecordDiscrepancy(_discrepancyIssueDoc);
                    }
                    this.LogActivity("Confirm-Dispatch", _activeSTVID);
                    mgr.CommitTransaction();
                    XtraMessageBox.Show("STV marked as dispatched!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception exp)
                {
                    mgr.RollbackTransaction();
                    XtraMessageBox.Show("System couldn't save the dispatch, Please contact administrator", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ErrorHandler.Handle(exp);
                }
                BindUnconfirmedIssues();
                gridUndispatchedIssueDetails.DataSource = null;
            }
        }
        private void startbgWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            MyGeneration.dOOdads.TransactionMgr transactionMgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                // Add the inventory details.
                // For each Activity, populate the inventory.
                //ToDO: this grid reading in a non ui thread is dangerous
                //please don't do it this way.
                transactionMgr.BeginTransaction();
                int           physicalStoreID = Convert.ToInt32(gridManageInvetoryView.GetFocusedDataRow()["ID"]);
                PhysicalStore physicalStore   = new PhysicalStore();
                physicalStore.LoadByPrimaryKey(physicalStoreID);


                DateTime startDate = dtStartInventory.Value;
                if (!physicalStore.IsColumnNull("CurrentInventoryPeriodID"))
                {
                    // create the inventory period
                    InventoryPeriod oldPeriod = new InventoryPeriod();
                    oldPeriod.LoadByPrimaryKey(physicalStore.CurrentInventoryPeriodID);
                    oldPeriod.EndDate = dtStartInventory.Value;
                    oldPeriod.Save();
                }
                InventoryPeriod period = new InventoryPeriod();
                period.AddNew();
                period.InventoryStatusID = InventoryPeriod.Constants.BEGIN_INVENTORY;
                period.PhysicalStoreID   = physicalStoreID;
                period.StartDate         = dtStartInventory.Value;
                period.EndDate           = FiscalYear.Current.EndDate;
                period.StartedBy         = CurrentContext.UserId;
                period.FiscalYearID      = FiscalYear.Current.ID;
                if (memoEdit1.EditValue != null)
                {
                    period.Remark = memoEdit1.EditValue.ToString();
                }

                period.Save();
                //ChangePhysicalStoreToCurrentPeriod

                physicalStore = new PhysicalStore();
                physicalStore.LoadByPrimaryKey(physicalStoreID);
                physicalStore.CurrentInventoryPeriodID = period.ID;
                physicalStore.CurrentPeriodStartDate   = period.StartDate;
                physicalStore.Save();

                Activity activity = new Activity();
                activity.LoadAll();
                int activityIndex = 1;
                while (!activity.EOF)
                {
                    // report that this activity is being processed.
                    startbgWorker.ReportProgress(activityIndex++, "Activity: " + activity.FullActivityName);

                    DataTable dtbl  = Balance.GetBalanceByPhysicalStore(physicalStoreID, activity.ID, false);
                    decimal   total = dtbl.Rows.Count;
                    decimal   i     = 0;
                    foreach (DataRow dr in dtbl.Rows)
                    {
                        Inventory inv = new Inventory();
                        inv.AddNew();

                        inv.IsDraft         = true;
                        inv.PhysicalStoreID = physicalStoreID;
                        inv.RecordedBy      = CurrentContext.UserId;
                        inv.RecordedDate    = BLL.DateTimeHelper.ServerDateTime;

                        inv.InventoryPeriodID = period.ID;
                        inv.ItemID            = Convert.ToInt32(dr["ID"]);
                        inv.UnitID            = Convert.ToInt32(dr["UnitID"]);
                        inv.ActivityID        = activity.ID;
                        inv.ManufacturerID    = Convert.ToInt32(dr["ManufacturerID"]);
                        inv.SetColumn("BatchNo", dr["BatchNo"]);
                        inv.SetColumn("ExpiryDate", dr["ExpDate"]);
                        if (!inv.IsColumnNull("ExpiryDate") && inv.ExpiryDate < BLL.DateTimeHelper.ServerDateTime)
                        {
                            inv.SystemExpiredQuantity = Convert.ToDecimal(dr["SoundSOH"]);
                        }
                        else
                        {
                            inv.SystemSoundQuantity = Convert.ToDecimal(dr["SoundSOH"]);
                        }

                        inv.SystemDamagedQuantity = Convert.ToDecimal(dr["DamagedSOH"]);
                        inv.SetColumn("Cost", dr["Cost"]);
                        inv.Margin = dr["Margin"] == DBNull.Value ? 0 : Convert.ToDecimal(dr["Margin"]);
                        inv.SetColumn("PalletLocationID", dr["PalletLocationID"]);
                        inv.Save();


                        startbgWorker.ReportProgress(Convert.ToInt32((i / total) * 100), "Detail");
                        //inventory
                        i++;
                    }


                    activity.MoveNext();
                }
                transactionMgr.CommitTransaction();
                XtraMessageBox.Show("The new Inventory Period has been defined.");
            }
            catch (Exception exception)
            {
                transactionMgr.RollbackTransaction();
                XtraMessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public static void DeleteIssueDoc(int issueID)
        {
            MyGeneration.dOOdads.TransactionMgr tranMgr =
                MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                tranMgr.BeginTransaction();


                var pld  = new PickListDetail();
                var rdoc = new ReceiveDoc();
                var rp   = new ReceivePallet();
                var idoc = new IssueDoc();

                idoc.LoadByPrimaryKey(issueID);
                pld.LoadByPrimaryKey(idoc.PLDetailID);
                rdoc.LoadByPrimaryKey(idoc.RecievDocID);

                rp.LoadByPrimaryKey(pld.ReceivePalletID);
                var pl = new PalletLocation();
                pl.loadByPalletID(rp.PalletID);

                if (pl.RowCount == 0)
                {
                    pl.LoadByPrimaryKey(pld.PalletLocationID);
                    if (pl.IsColumnNull("PalletID"))
                    {
                        pl.PalletID = rp.PalletID;
                        pl.Save();
                    }
                }


                if (rp.RowCount == 0)
                {
                    XtraMessageBox.Show("You cannot delete this item, please contact the administrator", "Error");
                    return;
                }
                if (rp.RowCount > 0)
                {
                    // in error cases this could lead to a number greater than the received quantity
                    // instead of being an error, it should just delete the respective issue and
                    // adjust the remaining quantity to the received quantity.
                    if (rdoc.QuantityLeft + idoc.Quantity > rdoc.Quantity)
                    {
                        rdoc.QuantityLeft = rp.Balance = rdoc.Quantity;
                    }
                    else
                    {
                        rdoc.QuantityLeft += idoc.Quantity;
                        rp.Balance        += idoc.Quantity;
                    }

                    //Delete from picklistDetail and add to pickListDetailDeleted
                    PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId);
                    pld.MarkAsDeleted();

                    // are we adding it the pick face?
                    // if so add it to the balance of the pick face also
                    pl.loadByPalletID(rp.PalletID);

                    if (pl.RowCount == 0)
                    {
                        var plocation = new PutawayLocation(rdoc.ItemID);

                        // we don't have a location for this yet,
                        // select a new location
                        //PutawayLocataion pl = new PutawayLocataion();
                        if (plocation.ShowDialog() == DialogResult.OK)
                        {
                            pl.LoadByPrimaryKey(plocation.PalletLocationID);
                            if (pl.RowCount > 0)
                            {
                                pl.PalletID = rp.PalletID;
                                pl.Save();
                            }
                        }
                    }

                    if (pl.RowCount > 0)
                    {
                        var pf = new PickFace();
                        pf.LoadByPalletLocation(pl.ID);
                        if (pf.RowCount > 0)
                        {
                            pf.Balance += Convert.ToInt32(idoc.Quantity);
                            pf.Save();
                        }


                        IssueDocDeleted.AddNewLog(idoc, CurrentContext.UserId);
                        idoc.MarkAsDeleted();
                        rdoc.Save();
                        rp.Save();
                        idoc.Save();
                        pld.Save();


                        // now refresh the window
                        XtraMessageBox.Show("Issue Deleted!", "Confirmation", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        tranMgr.CommitTransaction();
                    }
                }
                else
                {
                    XtraMessageBox.Show(
                        "This delete is not successfull because a free pick face location was not selected. please select a free location and try again.",
                        "Error Deleteing issue transaction", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tranMgr.RollbackTransaction();
                }
            }
            catch
            {
                XtraMessageBox.Show("This delete is not successfull", "Warning ...", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                tranMgr.RollbackTransaction();
            }
        }
        private void btnCommit_Click(object sender, EventArgs e)
        {
            if (ValidateQuarantine())
            {
                MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                transaction.BeginTransaction();
                if (DialogResult.Yes == XtraMessageBox.Show("Are you sure you want to commit the Loss and Adjustment on this screen?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    // do the actual commit here.
                    int            printNubmer = InternalTransfer.GetNewPrintNumber() + 1;
                    PalletLocation pl          = new PalletLocation();
                    Pallet         p           = new Pallet();
                    ReceiveDoc     rdoc        = new ReceiveDoc();
                    ReceivePallet  rp          = new ReceivePallet();
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        DataRow dr       = gridView1.GetDataRow(i);
                        Double  writeoff = 0;
                        Double  reLocate = 0;
                        try
                        {
                            if (dr["WriteOff"] != DBNull.Value)
                            {
                                writeoff = Double.Parse(dr["WriteOff"].ToString());
                            }
                            if (dr["ReLocate"] != DBNull.Value)
                            {
                                reLocate = Double.Parse(dr["ReLocate"].ToString());
                            }
                        }
                        catch (Exception exc)
                        {
                        }

                        if (dr["WriteOff"] != DBNull.Value & writeoff > 0)
                        {
                            if (Double.Parse(dr["WriteOff"].ToString()) > Double.Parse(dr["Balance"].ToString()))
                            {
                                XtraMessageBox.Show("Couldn't commit to the numbers you specified. Please specify number less than the balance.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            int writeoffAmout = Convert.ToInt32(dr["WriteOff"]);
                            int qtyPerPack    = Convert.ToInt32(dr["QtyPerPack"]);
                            writeoffAmout *= qtyPerPack;
                            rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                            rdoc.LoadByPrimaryKey(rp.ReceiveID);
                            string x = dr["NewPalletLocation"].ToString();
                            rp.Balance -= writeoffAmout;
                            try
                            {
                                //  rp.ReceivedQuantity -= writeoffAmout;
                            }
                            catch { }
                            rdoc.QuantityLeft -= writeoffAmout;

                            ReceivePallet nrp = new ReceivePallet();
                            nrp.AddNew();
                            nrp.ReceiveID = rp.ReceiveID;
                            nrp.PalletID  = pl.GetpalletidbyPalletLocationOrgetnew(int.Parse(dr["NewPalletLocation"].ToString()));
                            //nrp.ReceivedQuantity = rp.ReceivedQuantity;
                            nrp.Balance       = writeoffAmout;
                            nrp.ReservedStock = 0;
                            //nrp.ReserveOrderID = rp.ReserveOrderID;
                            nrp.BoxSize           = rp.BoxSize;
                            nrp.PalletLocationID  = int.Parse(dr["NewPalletLocation"].ToString());
                            nrp.IsOriginalReceive = rp.IsOriginalReceive;



                            BLL.LossAndAdjustment d = new BLL.LossAndAdjustment();
                            d.AddNew();
                            d.GenerateRefNo();
                            d.ItemID   = Convert.ToInt32(dr["ItemID"]);
                            d.ReasonId = Convert.ToInt32(dr["Reason"]);
                            d.RecID    = rdoc.ID;
                            d.Quantity = writeoffAmout;
                            d.BatchNo  = rdoc.BatchNo;

                            CalendarLib.DateTimePickerEx edate = new CalendarLib.DateTimePickerEx();
                            edate.Value = DateTime.Today;
                            //TODO: fix to an ethiopian date here
                            edate.CustomFormat = "MM/dd/yyyy";

                            d.Date = ConvertDate.DateConverter(edate.Text);

                            d.EurDate = DateTime.Today;
                            d.Cost    = rdoc.IsColumnNull("Cost")? 0: Math.Abs(rdoc.Cost * writeoffAmout);
                            d.StoreId = rdoc.StoreID;
                            d.Losses  = true;
                            //todo:
                            d.ApprovedBy = CurrentContext.UserId.ToString();
                            //d.Remarks

                            InternalTransfer it = new  InternalTransfer();
                            it.AddNew();
                            it.ItemID = d.ItemID;
                            it.FromPalletLocationID = pl.GetPalletLocationIDByPalletID(int.Parse(dr["PalletID"].ToString()));
                            it.ToPalletLocationID   = nrp.PalletLocationID;
                            it.BatchNumber          = d.BatchNo;
                            if (!rdoc.IsColumnNull("ExpDate"))
                            {
                                it.ExpireDate = rdoc.ExpDate;
                            }
                            it.ReceiveDocID   = rdoc.ID;
                            it.ManufacturerID = rdoc.ManufacturerId;
                            it.QtyPerPack     = Convert.ToInt32(dr["QtyPerPack"]);
                            it.Packs          = rdoc.NoOfPack;
                            it.QuantityInBU   = nrp.Balance;


                            LossAndAdjustmentReason r = new LossAndAdjustmentReason();
                            it.Type = r.GetReasonByID(d.ReasonId);


                            // d.Save();
                            rdoc.Save();
                            rp.Save();

                            rdoc.QuantityLeft += writeoffAmout;
                            rdoc.Save();
                            nrp.Save();
                            it.Save();
                            int xs = it.ID;
                        }
                        else if (dr["ReLocate"] != DBNull.Value & reLocate > 0)
                        {
                            if (dr["ReLocate"] != DBNull.Value)
                            {
                                int amount     = Convert.ToInt32(dr["ReLocate"]);
                                int qtyPerPack = Convert.ToInt32(dr["QtyPerPack"]);
                                amount *= qtyPerPack;
                                rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                                rdoc.LoadByPrimaryKey(rp.ReceiveID);
                                int palletLocationID = Convert.ToInt32(dr["PalletLocationID"]);

                                int qPalletLocationID =
                                    PalletLocation.GetQuaranteenPalletLocationByPalletLocationID(palletLocationID); //PalletLocation.GetQuaranteenPalletLocation(Convert.ToInt32(dr["ID"]));
                                pl.LoadByPrimaryKey(qPalletLocationID);

                                ReceivePallet rp2    = new ReceivePallet();
                                ReceiveDoc    rd     = new ReceiveDoc();
                                Pallet        pallet = new Pallet();
                                rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                                rd.LoadByPrimaryKey(rp.ReceiveID);
                                pallet.AddNew();
                                Item item = new Item();
                                item.LoadByPrimaryKey(rdoc.ItemID);
                                if (item.StorageTypeID.ToString() == StorageType.BulkStore)
                                {
                                    pallet.PalletNo = Pallet.GetLastPanelNumber();
                                }
                                pallet.Save();
                                rp2.AddNew();
                                rp2.PalletID          = pl.GetpalletidbyPalletLocationOrgetnew(int.Parse(dr["NewPalletLocation"].ToString()));//pallet.ID;
                                rp2.ReceiveID         = rp.ReceiveID;
                                rp2.IsOriginalReceive = rp.IsOriginalReceive;
                                // calculate the new balance
                                BLL.ItemManufacturer im = new BLL.ItemManufacturer();
                                //im.LoadDefaultReceiving(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]));
                                //im.LoadIMbyLevel(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]), Convert.ToInt32(dr["BoxLevel"]));
                                //int packqty = (amount / im.QuantityInBasicUnit);
                                rd.QuantityLeft -= amount;
                                rp.Balance      -= amount;
                                rd.Save();
                                rp.Save();

                                rd.QuantityLeft += amount;
                                rp2.Balance      = amount;//packqty * im.QuantityInBasicUnit;
                                rd.Save();

                                rp2.BoxSize          = rp.BoxSize;
                                rp2.ReservedStock    = 0;
                                rp2.PalletLocationID = int.Parse(dr["NewPalletLocation"].ToString());
                                rp2.Save();

                                pl.Confirmed = false;
                                pl.Save();

                                // select the new pallet location here.

                                /*   XtraForm xdb = new XtraForm();
                                 * xdb.Controls.Add(panelControl2);
                                 * Item itms= new Item();
                                 * itms.GetItemByPrimaryKey(Convert.ToInt32(dr["ItemID"]));
                                 * lblItemName.Text = itms.FullItemName;
                                 * panelControl2.Visible = true;
                                 * panelControl2.Dock = DockStyle.Fill;
                                 * xdb.Text = "Select Location for relocated Item";
                                 * lkLocation.Properties.DataSource = PalletLocation.GetAllFreeFor(Convert.ToInt32(dr["ItemID"]));
                                 * xdb.ShowDialog();
                                 *
                                 * PalletLocation pl2 = new PalletLocation();
                                 * pl2.LoadByPrimaryKey(Convert.ToInt32(lkLocation.EditValue));
                                 * pl2.PalletID = pallet.ID;
                                 * pl2.Confirmed = false;
                                 * pl2.Save();
                                 */
                                InternalTransfer it = new InternalTransfer();

                                it.AddNew();
                                it.ItemID   = rd.ItemID;
                                it.BoxLevel = 0; // im.PackageLevel;
                                //it.ExpireDate = rd.ExpDate;
                                if (!rd.IsColumnNull("ExpDate"))
                                {
                                    it.ExpireDate = rd.ExpDate;
                                }
                                it.BatchNumber          = rd.BatchNo;
                                it.ManufacturerID       = Convert.ToInt32(dr["ManufacturerID"]);         //im.ManufacturerID;
                                it.FromPalletLocationID = qPalletLocationID;
                                it.ToPalletLocationID   = int.Parse(dr["NewPalletLocation"].ToString()); //pl2.ID;
                                it.QtyPerPack           = 1;
                                //it.Packs = pack qty;
                                it.ReceiveDocID = rp.ReceiveID;
                                it.QuantityInBU = amount; // it.QtyPerPack;
                                it.Type         = "ReLocation";
                                it.IssuedDate   = DateTime.Today;
                                it.Status       = 0;
                                it.PrintNumber  = printNubmer;
                                it.Save();
                            }
                        }
                    }
                    transaction.CommitTransaction();
                    BindQuarantine();
                    XtraMessageBox.Show("Quarantine Write off/Adjustment was commitd.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        /// <summary>
        /// Change the UnitID of one item to another UnitID.
        /// </summary>
        /// <param name="storeID"></param>
        /// <param name="itemID"></param>
        /// <param name="fromUnitID"></param>
        /// <param name="toUnitID"></param>
        public static void ChangeItemUnit(int storeID, int itemID, int fromUnitID, int toUnitID)
        {
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                transaction.BeginTransaction();
                ItemUnit iuFrom = new ItemUnit(), iuTo = new ItemUnit(), iuExecute = new ItemUnit();
                iuFrom.LoadByPrimaryKey(fromUnitID);
                iuTo.LoadByPrimaryKey(toUnitID);

                var receiveTableFilterQuery = HCMIS.Repository.Queries.ItemUnit.SelectChangeItemUnit(storeID, itemID, iuFrom.ID);

                string query;
                // Update Issue Doc
                query =
                    HCMIS.Repository.Queries.ItemUnit.UpdateChangeItemUnitIssueDoc(iuTo.QtyPerUnit, iuFrom.QtyPerUnit, receiveTableFilterQuery);
                iuExecute.LoadFromRawSql(query);

                // Update disposal table
                query =
                    HCMIS.Repository.Queries.ItemUnit.UpdateChangeItemUnitLossAndAdjustment(iuTo.QtyPerUnit, iuFrom.QtyPerUnit, receiveTableFilterQuery);
                iuExecute.LoadFromRawSql(query);

                // Update Order.
                query =
                    HCMIS.Repository.Queries.ItemUnit.UpdateChangeItemUnitOrderDetail(itemID, iuFrom.ID, iuFrom.QtyPerUnit, iuTo.QtyPerUnit);

                iuExecute.LoadFromRawSql(query);

                // Update Pick List Detail
                query =
                    HCMIS.Repository.Queries.ItemUnit.UpdateChangeItemUnitPickListDetail(iuTo.QtyPerUnit, iuFrom.QtyPerUnit, receiveTableFilterQuery);

                iuExecute.LoadFromRawSql(query);

                // change the Weighted Average Log
                try
                {
                    query = HCMIS.Repository.Queries.ItemUnit.UpdateChangeItemUnitMovingAverageHistory(storeID, iuTo.ID, iuFrom.ID);

                    iuExecute.LoadFromRawSql(query);
                }

                catch
                {
                }

                BLL.ReceiveDoc rd = new ReceiveDoc();
                rd.LoadByItemIDUnitIDStoreID(itemID, iuFrom.ID, storeID);
                rd.ChangeUnitID(iuTo.ID);

                //Change the YearEnd
                //If there is already an entry with the other UnitID, we need to merge the two.

                BLL.YearEnd yEndFrom = new YearEnd();
                yEndFrom.Where.UnitID.Value  = iuFrom.ID;
                yEndFrom.Where.ItemID.Value  = itemID;
                yEndFrom.Where.StoreID.Value = storeID;
                yEndFrom.Query.Load();

                if (yEndFrom.RowCount > 0)
                {
                    //There is a year end entry.
                    //If there is one by the new UnitID, we merge them.  If there is no entry by the new UnitID, we just change the values.
                    BLL.YearEnd yEndTo = new YearEnd();
                    yEndTo.Where.UnitID.Value  = iuTo.ID;
                    yEndTo.Where.ItemID.Value  = itemID;
                    yEndTo.Where.StoreID.Value = storeID;
                    yEndTo.Query.Load();
                    if (yEndTo.RowCount > 0)
                    {
                        //We need to merge.
                        if (!yEndTo.IsColumnNull("EndingPrice"))
                        {
                            yEndTo.EndingPrice += yEndFrom.EndingPrice;
                        }
                        else
                        {
                            yEndTo.EndingPrice = yEndFrom.EndingPrice;
                        }
                        if (!yEndTo.IsColumnNull("EBalance"))
                        {
                            yEndTo.EBalance += yEndFrom.EBalance;
                        }
                        else
                        {
                            yEndTo.EBalance = yEndFrom.EBalance;
                        }
                        if (!yEndTo.IsColumnNull("PhysicalInventory"))
                        {
                            yEndTo.PhysicalInventory += yEndFrom.PhysicalInventory;
                        }
                        else
                        {
                            yEndTo.PhysicalInventory = yEndFrom.PhysicalInventory;
                        }
                        if (!yEndTo.IsColumnNull("PhysicalInventoryPrice"))
                        {
                            yEndTo.PhysicalInventoryPrice += yEndFrom.PhysicalInventoryPrice;
                        }
                        else
                        {
                            yEndTo.PhysicalInventoryPrice = yEndFrom.PhysicalInventoryPrice;
                        }

                        yEndTo.Save();
                        yEndFrom.MarkAsDeleted();
                        yEndFrom.Save();
                    }
                    else
                    {
                        yEndFrom.UnitID = iuTo.ID;
                        yEndFrom.Save();
                    }
                }
                transaction.CommitTransaction();
            }
            catch (Exception ex)
            {
                transaction.RollbackTransaction();
                throw ex;
            }
        }
        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);
        }
        /// <summary>
        /// Handles the Click event of the btnConfirmIssue control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        /// <exception cref="System.Exception"></exception>
        private void btnConfirmIssue_Click(object sender, EventArgs e)
        {
            // This is where the Issue is actually recorded and the stv is printed.
            // Do all kinds of validations.
            XtraReport STVReport = null; XtraReport DeliveryNoteReport = null;

            btnConfirmIssue1.Enabled = false;
            if (!IssueValid())
            {
                XtraMessageBox.Show("Please Correct the Items Marked in Red before Proceeding with Issue", "Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnConfirmIssue1.Enabled = (BLL.Settings.UseNewUserManagement && this.HasPermission("Print-Invoice")) ? true : (!BLL.Settings.UseNewUserManagement);
                return;
            }

            if (XtraMessageBox.Show("Are You Sure, You want to save this Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                DateTimePickerEx dtDate = ConvertDate.GetCurrentEthiopianDateText();

                DateTime dtCurrent = ConvertDate.DateConverter(dtDate.Text);
                // The User is now sure that the STV has to be printed and that
                // the order is also good to save.
                // This is the section that does the saving.

                BLL.Order order = new Order();
                order.LoadByPrimaryKey(_orderID);

                // what are the pick lists, do we have devliery notes too?
                DataView  dv         = _dvOutstandingPickList;
                DataTable dvUnpriced = new DataTable();
                DataTable dvPriced   = dv.ToTable();

                if (BLL.Settings.HandleGRV)
                {
                    if (BLL.Settings.IsCenter)
                    {
                        dv.RowFilter = "(Cost is null or Cost=0)";
                    }
                    else
                    {
                        dv.RowFilter = "DeliveryNote = true and (Cost is null or Cost=0)";
                    }
                    dvUnpriced = dv.ToTable();

                    dv.RowFilter = "Cost is not null and Cost <> 0";
                    dvPriced     = dv.ToTable();
                }
                else
                {
                    dvPriced = dv.ToTable();
                }

                string stvPrinterName      = "";
                string deliveryNotePrinter = "";

                if (!ConfirmPrinterSettings(dvPriced, dvUnpriced, out stvPrinterName, out deliveryNotePrinter))
                {
                    return;
                }
                bool saveSuccessful = false;

                MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                try
                {
                    if (dvPriced.Rows.Count == 0 && dvUnpriced.Rows.Count == 0)
                    {
                        throw new Exception("The Items doesn’t meet the requirement: please check the price status for non-delivery notes!");
                    }

                    mgr.BeginTransaction();

                    if (dvPriced.Rows.Count > 0)
                    {
                        STVReport = SaveAndPrintSTV(dvPriced.DefaultView, false, stvPrinterName, dtDate, dtCurrent);
                    }


                    if (dvUnpriced.Rows.Count > 0)
                    {
                        DeliveryNoteReport = SaveAndPrintSTV(dvUnpriced.DefaultView, true, deliveryNotePrinter, dtDate,
                                                             dtCurrent);
                    }
                    var ordr = new Order();
                    ordr.LoadByPrimaryKey(_orderID);

                    if (!ordr.IsColumnNull("OrderTypeID") &&

                        (ordr.OrderTypeID == BLL.OrderType.CONSTANTS.ACCOUNT_TO_ACCOUNT_TRANSFER || ordr.OrderTypeID == BLL.OrderType.CONSTANTS.STORE_TO_STORE_TRANSFER))
                    {
                        var      transfer         = new Transfer();
                        DateTime convertedEthDate = ConvertDate.DateConverter(dtDate.Text);
                        transfer.CommitAccountToAccountTransfer(ordr.ID, CurrentContext.UserId, convertedEthDate);
                    }

                    mgr.CommitTransaction();

                    saveSuccessful = true;
                }
                catch (Exception exp)
                {
                    mgr.RollbackTransaction();
                    //Removed the reset logic
                    //MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgrReset();
                    XtraMessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ErrorHandler.Handle(exp);
                    saveSuccessful = false;
                }

                if (saveSuccessful)
                {
                    if (STVReport != null)
                    {
                        if (InstitutionIType.IsVaccine(GeneralInfo.Current))
                        {
                            for (int i = 0; i < BLL.Settings.STVCopies; i++)
                            {
                                STVReport.Print(stvPrinterName);
                            }
                        }
                        else
                        {
                            STVReport.Print(stvPrinterName);
                        }
                    }

                    if (DeliveryNoteReport != null)
                    {
                        DeliveryNoteReport.Print(deliveryNotePrinter);
                    }

                    XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                }

                btnConfirmIssue1.Enabled = (BLL.Settings.UseNewUserManagement && this.HasPermission("Print-Invoice")) ? true : (!BLL.Settings.UseNewUserManagement);
                BindOutstandingPicklists();
                gridOutstandingPicklistDetail.DataSource = null;
                PalletLocation.GarbageCollection();

                if (BLL.Settings.AllowOnlineOrders)
                {
                    Helpers.RRFServiceIntegration.SubmitOnlineIssue(_orderID);
                }
            }
        }