Ejemplo n.º 1
0
        // populate the motivation detail and motivation group comboboxes
        private void SetupMotivationComboboxes()
        {
            TFinanceControls.InitialiseMotivationGroupList(ref cmbMotivationGroup, FLedgerNumber, false);
            DataRow BlankRow = cmbMotivationGroup.Table.NewRow();

            BlankRow["a_ledger_number_i"]                = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]        = "";
            BlankRow["a_motivation_group_description_c"] = Catalog.GetString("All groups");
            cmbMotivationGroup.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationGroup.cmbCombobox.SelectedIndex   = 0;
            cmbMotivationGroup.ColumnWidthCol2             = 300;
            cmbMotivationGroup.cmbCombobox.SelectionLength = 0;

            TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetail, FLedgerNumber, false);
            BlankRow = cmbMotivationDetail.Table.NewRow();
            BlankRow["a_ledger_number_i"]          = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]  = "";
            BlankRow["a_motivation_detail_code_c"] = "";
            BlankRow["a_motivation_detail_desc_c"] = Catalog.GetString("All details");
            cmbMotivationDetail.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationDetail.cmbCombobox.SelectedIndex   = 0;
            cmbMotivationDetail.ColumnWidthCol2             = 300;
            cmbMotivationDetail.cmbCombobox.SelectionLength = 0;
        }
        /// <summary>
        /// load the gifts into the grid
        /// </summary>
        /// <param name="ALedgerNumber"></param>
        /// <param name="ABatchNumber"></param>
        /// <param name="ABatchStatus"></param>
        /// <param name="AForceLoadFromServer">Set to true to get data from the server even though it is apparently the current batch number and status</param>
        /// <returns>True if gift transactions were loaded from server, false if transactions had been loaded already.</returns>
        public bool LoadGifts(Int32 ALedgerNumber, Int32 ABatchNumber, string ABatchStatus, bool AForceLoadFromServer = false)
        {
            //Set key flags
            bool FirstGiftTransLoad = (FLedgerNumber == -1);
            bool SameCurrentBatch   = ((FLedgerNumber == ALedgerNumber) &&
                                       (FBatchNumber == ABatchNumber) &&
                                       (FBatchStatus == ABatchStatus) &&
                                       !AForceLoadFromServer);

            FBatchRow = GetBatchRow();

            if ((FBatchRow == null) && (GetAnyBatchRow(ABatchNumber) == null))
            {
                MessageBox.Show(String.Format("Cannot load transactions for Gift Batch {0} as the batch is not currently loaded!",
                                              ABatchNumber));
                return(false);
            }

            //Set key values from Batch
            FLedgerNumber         = ALedgerNumber;
            FBatchNumber          = ABatchNumber;
            FBatchCurrencyCode    = FBatchRow.CurrencyCode;
            FBatchMethodOfPayment = FBatchRow.MethodOfPaymentCode;
            FBatchStatus          = ABatchStatus;
            FBatchUnpostedFlag    = (FBatchStatus == MFinanceConstants.BATCH_UNPOSTED);

            if (FirstGiftTransLoad)
            {
                InitialiseControls();
            }

            UpdateCurrencySymbols(FBatchCurrencyCode);

            //Check if the same batch is selected, so no need to apply filter
            if (SameCurrentBatch)
            {
                //Same as previously selected and we have not been asked to force a full refresh
                if (FBatchUnpostedFlag && (GetSelectedRowIndex() > 0))
                {
                    if (FGLEffectivePeriodHasChangedFlag)
                    {
                        //Just in case for the currently selected row, the date field has not been updated
                        FGLEffectivePeriodHasChangedFlag   = false;
                        GetSelectedDetailRow().DateEntered = FBatchRow.GlEffectiveDate;
                        dtpDateEntered.Date = FBatchRow.GlEffectiveDate;
                    }

                    GetDetailsFromControls(GetSelectedDetailRow());
                }

                UpdateControlsProtection();

                if (FBatchUnpostedFlag &&
                    ((FBatchCurrencyCode != FBatchRow.CurrencyCode) ||
                     (FBatchExchangeRateToBase != FBatchRow.ExchangeRateToBase)))
                {
                    UpdateBaseAmount(false);
                }

                return(false);
            }

            //New Batch
            FCurrentGiftInBatch = 0;

            //New set of transactions to be loaded
            TFrmStatusDialog dlgStatus = new TFrmStatusDialog(FPetraUtilsObject.GetForm());

            if (FShowStatusDialogOnLoadFlag == true)
            {
                dlgStatus.Show();
                FShowStatusDialogOnLoadFlag = false;
                dlgStatus.Heading           = String.Format(Catalog.GetString("Batch {0}"), ABatchNumber);
                dlgStatus.CurrentStatus     = Catalog.GetString("Loading transactions ...");
            }

            FGiftTransactionsLoadedFlag = false;
            FSuppressListChangedFlag    = false;

            //Apply new filter
            FPreviouslySelectedDetailRow = null;
            grdDetails.DataSource        = null;

            // if this form is readonly, then we need all codes, because old (inactive) codes might have been used
            if (FirstGiftTransLoad || (FActiveOnlyFlag == (ViewMode || !FBatchUnpostedFlag)))
            {
                FActiveOnlyFlag         = !(ViewMode || !FBatchUnpostedFlag);
                dlgStatus.CurrentStatus = Catalog.GetString("Initialising controls ...");

                try
                {
                    //Without this, the Save button enables even for Posted batches!
                    FPetraUtilsObject.SuppressChangeDetection = true;

                    TFinanceControls.InitialiseMotivationGroupList(ref cmbDetailMotivationGroupCode, FLedgerNumber, FActiveOnlyFlag);
                    TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetailCode, FLedgerNumber, FActiveOnlyFlag);
                    TFinanceControls.InitialiseMethodOfGivingCodeList(ref cmbDetailMethodOfGivingCode, FActiveOnlyFlag);
                    TFinanceControls.InitialiseMethodOfPaymentCodeList(ref cmbDetailMethodOfPaymentCode, FActiveOnlyFlag);
                    TFinanceControls.InitialisePMailingList(ref cmbDetailMailingCode, FActiveOnlyFlag);
                }
                finally
                {
                    FPetraUtilsObject.SuppressChangeDetection = false;
                }
            }

            // This sets the incomplete filter but does check the panel enabled state
            ShowData();

            // This sets the main part of the filter but excluding the additional items set by the user GUI
            // It gets the right sort order
            SetGiftDetailDefaultView();

            // only load from server if there are no transactions loaded yet for this batch
            // otherwise we would overwrite transactions that have already been modified
            if (FMainDS.AGiftDetail.DefaultView.Count == 0)
            {
                dlgStatus.CurrentStatus = Catalog.GetString("Requesting transactions from server ...");
                //Load all partners in Batch
                FMainDS.DonorPartners.Merge(TRemote.MFinance.Gift.WebConnectors.LoadAllPartnerDataForBatch(ALedgerNumber, ABatchNumber)); //LoadAllPartnerDataForBatch();
                //Include Donor fields
                LoadGiftDataForBatch(ALedgerNumber, ABatchNumber);
            }

            //Check if need to update batch period in each gift
            if (FBatchUnpostedFlag)
            {
                dlgStatus.CurrentStatus = Catalog.GetString("Updating batch period ...");
                ((TFrmGiftBatch)ParentForm).GetBatchControl().UpdateBatchPeriod();
            }

            // Now we set the full filter
            FFilterAndFindObject.ApplyFilter();
            UpdateRecordNumberDisplay();
            FFilterAndFindObject.SetRecordNumberDisplayProperties();

            SelectRowInGrid(1);

            UpdateControlsProtection();

            dlgStatus.CurrentStatus = Catalog.GetString("Updating totals for the batch ...");
            UpdateTotals();

            if ((FPreviouslySelectedDetailRow != null) && (FBatchUnpostedFlag))
            {
                bool disableSave = (FBatchRow.RowState == DataRowState.Unchanged && !FPetraUtilsObject.HasChanges);

                if (disableSave && FPetraUtilsObject.HasChanges && !DataUtilities.DataRowColumnsHaveChanged(FBatchRow))
                {
                    FPetraUtilsObject.DisableSaveButton();
                }
            }

            FGiftTransactionsLoadedFlag = true;
            dlgStatus.Close();

            return(true);
        }
        private void SetupMotivationComboboxes()
        {
            /* cmbMotivationGroup */

            TFinanceControls.InitialiseMotivationGroupList(ref cmbMotivationGroup, FLedgerNumber, false);

            // remove motivation groups that are not used in the results
            List <int> RemoveIndexes = new List <int>();

            for (int i = 0; i < cmbMotivationGroup.Table.Rows.Count; i++)
            {
                bool NotFound = true;

                foreach (DataRow DetailRow in FMainDS.Tables[TEMP_TABLE_NAME].Rows)
                {
                    if (cmbMotivationGroup.Table.Rows[i]["a_motivation_group_code_c"].ToString() == DetailRow["MotivationGroupCode"].ToString())
                    {
                        NotFound = false;
                        break;
                    }
                }

                if (NotFound)
                {
                    RemoveIndexes.Add(i);
                }
            }

            for (int i = RemoveIndexes.Count - 1; i >= 0; i--)
            {
                cmbMotivationGroup.Table.Rows.RemoveAt(RemoveIndexes[i]);
            }

            DataRow BlankRow = cmbMotivationGroup.Table.NewRow();

            BlankRow["a_ledger_number_i"]                = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]        = ALL;
            BlankRow["a_motivation_group_description_c"] = Catalog.GetString("All groups");
            cmbMotivationGroup.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationGroup.cmbCombobox.SelectedIndex = 0;
            cmbMotivationGroup.ColumnWidthCol2           = 300;
            cmbMotivationGroup.Enabled = true;
            cmbMotivationGroup.cmbCombobox.SelectionLength = 0;

            /* cmbMotivationDetail */

            TFinanceControls.InitialiseMotivationDetailList(ref cmbMotivationDetail, FLedgerNumber, false);

            // remove motivation details that are not used in the results
            RemoveIndexes.Clear();

            for (int i = 0; i < cmbMotivationDetail.Table.Rows.Count; i++)
            {
                bool NotFound = true;

                foreach (DataRow DetailRow in FMainDS.Tables[TEMP_TABLE_NAME].Rows)
                {
                    if (cmbMotivationDetail.Table.Rows[i]["a_motivation_detail_code_c"].ToString() == DetailRow["MotivationDetailCode"].ToString())
                    {
                        NotFound = false;
                        break;
                    }
                }

                if (NotFound)
                {
                    RemoveIndexes.Add(i);
                }
            }

            for (int i = RemoveIndexes.Count - 1; i >= 0; i--)
            {
                cmbMotivationDetail.Table.Rows.RemoveAt(RemoveIndexes[i]);
            }

            BlankRow = cmbMotivationDetail.Table.NewRow();
            BlankRow["a_ledger_number_i"]          = FLedgerNumber;
            BlankRow["a_motivation_group_code_c"]  = "";
            BlankRow["a_motivation_detail_code_c"] = ALL;
            BlankRow["a_motivation_detail_desc_c"] = Catalog.GetString("All details");
            cmbMotivationDetail.Table.Rows.InsertAt(BlankRow, 0);
            cmbMotivationDetail.cmbCombobox.SelectedIndex = 0;
            cmbMotivationDetail.ColumnWidthCol2           = 300;
            cmbMotivationDetail.Enabled = true;
            cmbMotivationDetail.cmbCombobox.SelectionLength = 0;
        }