/// <summary>
        /// Enables and disables the UI. Invokes setting up of the Grid after a
        /// successful search operation.
        /// </summary>
        /// <returns>void</returns>
        private void EnableDisableUI(System.Object AEnable)
        {
            object[] Args;
            TMyUpdateDelegate MyUpdateDelegate;

            // Since this procedure is called from a separate (background) Thread, it is
            // necessary to execute this procedure in the Thread of the GUI
            if (btnSearch.InvokeRequired)
            {
                Args = new object[1];

                try
                {
                    MyUpdateDelegate = new TMyUpdateDelegate(EnableDisableUI);
                    Args[0] = AEnable;
                    btnSearch.Invoke(MyUpdateDelegate, new object[] { AEnable });
                }
                finally
                {
                    Args = new object[0];
                }
            }
            else
            {
                // Enable/disable according to how the search operation ended
                if (Convert.ToBoolean(AEnable))
                {
                    TProgressState ThreadStatus = FGLTransactionFindObject.Progress;

                    if (ThreadStatus.JobFinished)
                    {
                        // Search operation ended without interruption
                        if (FPagedDataTable.Rows.Count > 0)
                        {
                            btnSearch.Enabled = false;

                            // At least one result was found by the search operation
                            lblSearchInfo.Text = "";

                            //
                            // Setup result DataGrid
                            //
                            if (grdResult.Columns.Count < 1)
                            {
                                SetupGrid();
                            }

                            SetupDataGridDataBinding();
                            grdResult.AutoSizeCells();

                            grdResult.Selection.SelectRow(1, true);

                            // Scroll grid to first line (the grid might have been scrolled before to another position)
                            grdResult.ShowCell(new Position(1, 1), true);

                            // For speed reasons we must add the necessary amount of emtpy Rows only here (after .AutoSizeCells() has already
                            // been run! See XML Comment on the called Method TSgrdDataGridPaged.AddEmptyRows() for details!
                            grdResult.AddEmptyRows();

                            grdResult.BringToFront();

                            // set tooltips
                            grdResult.SetHeaderTooltip(3, MFinanceConstants.BATCH_POSTED);
                            grdResult.SetHeaderTooltip(5, Catalog.GetString("Confidential"));

                            // Make the Grid respond on updown keys
                            grdResult.Focus();

                            // Display the number of found gift details
                            UpdateRecordNumberDisplay();

                            Application.DoEvents();

                            btnSearch.Enabled = true;

                            this.Cursor = Cursors.Default;
                        }
                        else
                        {
                            // Search operation has found nothing
                            this.Cursor = Cursors.Default;
                            lblSearchInfo.Text = Catalog.GetString("No GL Transactions found.");
                            Application.DoEvents();

                            btnSearch.Enabled = true;

                            UpdateRecordNumberDisplay();
                        }
                    }
                    else
                    {
                        // Search operation interrupted by user
                        // used to release server System.Object here
                        // (It isn't currently possible for the user to stop the search. I don't think this functionality is necessary)
                        this.Cursor = Cursors.Default;
                        lblSearchInfo.Text = Catalog.GetString("Search stopped!");

                        btnSearch.Enabled = true;
                        Application.DoEvents();
                    }

                    // enable or disable btnView
                    if (FPagedDataTable.Rows.Count > 0)
                    {
                        btnView.Enabled = true;
                    }
                    else
                    {
                        btnView.Enabled = false;
                    }
                }
            }
        }
        /// <summary>
        /// Research using existing criteria so that results can be updated with the edited partner's details
        /// </summary>
        /// <param name="AFormsMessagePartner"></param>
        public void SearchForExistingPartnerSavedThread(object AFormsMessagePartner)
        {
            object[] Args;
            TMyUpdateDelegate MyUpdateDelegate;

            // Since this procedure is called from a separate (background) Thread, it is
            // necessary to execute this procedure in the Thread of the GUI!
            if (btnSearch.InvokeRequired)
            {
                Args = new object[1];

                try
                {
                    MyUpdateDelegate = new TMyUpdateDelegate(SearchForExistingPartnerSavedThread);
                    Args[0] = AFormsMessagePartner;
                    btnSearch.Invoke(MyUpdateDelegate, new object[] { AFormsMessagePartner });
                }
                finally
                {
                    Args = new object[0];
                }
            }
            else
            {
                FBroadcastMessageSearch = true;
                this.Cursor = Cursors.WaitCursor;

                FSelectPartnerAfterSearch = PartnerKey;

                if (grdResult != null)
                {
                    grdResult = null;
                }

                FPagedDataTable = null;

                BtnSearch_Click(this, null);

                Application.DoEvents();

                this.Cursor = Cursors.Default;
            }
        }
        /// <summary>
        /// Search for a newly created partner and display in grid
        /// </summary>
        /// <param name="AFormsMessagePartner"></param>
        public void SearchForNewlyCreatedPartnerThread(object AFormsMessagePartner)
        {
            object[] Args;
            IFormsMessagePartnerInterface FormsMessagePartner;
            TMyUpdateDelegate MyUpdateDelegate;
            bool KeepRetrying = true;

            // Since this procedure is called from a separate (background) Thread, it is
            // necessary to execute this procedure in the Thread of the GUI!
            if (btnSearch.InvokeRequired)
            {
                Args = new object[1];

                try
                {
                    MyUpdateDelegate = new TMyUpdateDelegate(SearchForNewlyCreatedPartnerThread);
                    Args[0] = AFormsMessagePartner;
                    btnSearch.Invoke(MyUpdateDelegate, new object[] { AFormsMessagePartner });
                }
                finally
                {
                    Args = new object[0];
                }
            }
            else
            {
                // Cast the Method Argument from an Object to the concrete Type
                FormsMessagePartner = (IFormsMessagePartnerInterface)AFormsMessagePartner;

                this.Cursor = Cursors.WaitCursor;

                // Prevent saving of a PartnerStatus that we need to temporarily change to at a later point
                if (FormsMessagePartner.PartnerStatus != ucoPartnerFindCriteria.PartnerStatus)
                {
                    FNoSavingOfPartnerStatusUserDefault = true;
                }

                // Reset all the Search Criteria (and Search Result) in preparation for displaying the new Partner
                BtnClearCriteria_Click(this, null);

                // Set PartnerKey Criteria
                ucoPartnerFindCriteria.FocusPartnerKey(FormsMessagePartner.PartnerKey);
                // Set PartnerClass Criteria
                ucoPartnerFindCriteria.FocusPartnerStatus(FormsMessagePartner.PartnerStatus);

                while (KeepRetrying)
                {
                    if (FPagedDataTable == null)
                    {
                        // Search operation not finished yet
                        KeepRetrying = true;
                    }
                    else if (FPagedDataTable.Rows.Count == 0)
                    {
                        // Search operation finished, but Partner not found yet
                        // (due to DataMirroring not having mirrored the Partner yet!)
                        KeepRetrying = true;
                    }
                    else
                    {
                        // Newly created Partner Found!
                        KeepRetrying = false;
                    }

                    if (KeepRetrying)
                    {
                        if (!FKeepUpSearchFinishedCheck)
                        {
                            // Search operation finished, but Partner not found yet
                            // (due to DataMirroring not having mirrored the Partner yet!)
                            // --> Run Search again to try and find the new Partner.
                            BtnSearch_Click(this, null);
                        }

                        Thread.Sleep(500);
                        Application.DoEvents();
                    }
                }

                this.Cursor = Cursors.Default;
            }
        }
        /// <summary>
        /// Enables and disables the UI. Invokes setting up of the Grid after a
        /// successful search operation.
        /// </summary>
        /// <returns>void</returns>
        private void EnableDisableUI(System.Object AEnable)
        {
            object[] Args;
            TMyUpdateDelegate MyUpdateDelegate;
            String SearchTarget;
            bool UpdateUI;
            Int64 MergedPartnerKey;

            // Since this procedure is called from a separate (background) Thread, it is
            // necessary to execute this procedure in the Thread of the GUI
            if (btnSearch.InvokeRequired)
            {
                Args = new object[1];

//TLogging.Log("btnEditPartner.InvokeRequired: yes; AEnable: " + Convert.ToBoolean(AEnable).ToString());
                try
                {
                    MyUpdateDelegate = new TMyUpdateDelegate(EnableDisableUI);
                    Args[0] = AEnable;
                    btnSearch.Invoke(MyUpdateDelegate, new object[] { AEnable });
//TLogging.Log("Invoke finished!");
                }
                finally
                {
                    Args = new object[0];
                }
            }
            else
            {
//TLogging.Log("btnEditPartner.InvokeRequired: NO; AEnable: " + Convert.ToBoolean(AEnable).ToString());
                try
                {
                    // Enable/disable buttons for working with found Partners
                    OnPartnerAvailable(Convert.ToBoolean(AEnable));
                }
                catch (System.ObjectDisposedException)
                {
                    /*
                     * This Exception occurs if the screen has been closed by the user
                     * in the meantime -> don't try to do anything further - it will break!
                     */
                    return;
                }
                catch (Exception)
                {
                    throw;
                }

                // Enable/disable according to how the search operation ended
                if (Convert.ToBoolean(AEnable))
                {
                    if (FPartnerFindObject.Progress.JobFinished)
                    {
                        // Search operation ended without interruption
                        if (FPagedDataTable.Rows.Count > 0)
                        {
                            btnSearch.Enabled = false;

                            // At least one result was found by the search operation
                            lblSearchInfo.Text = "";


                            //
                            // Setup result DataGrid
                            //
                            SetupResultDataGrid();
//                            TLogging.Log("After SetupResultDataGrid()");

                            grdResult.BringToFront();
//                            TLogging.Log("After BringToFront()");

                            // Make the Grid respond on updown keys
                            // Not if this search is called as the result of a broadcast message. We do not want to change the focus.
                            if (!FBroadcastMessageSearch)
                            {
                                grdResult.Focus();

                                // this is needed so that the next 'Enter' press opens the partner edit screen
                                SendKeys.Send("{ENTER}");
                            }

                            DataGrid_FocusRowEntered(this, new RowEventArgs(1));

                            if (!FBankDetailsTab)
                            {
                                // Display the number of found Partners/Locations
                                if (grdResult.TotalRecords > 1)
                                {
                                    SearchTarget = MPartnerResourcestrings.StrPartnerFindSearchTargetPluralText;
                                }
                                else
                                {
                                    SearchTarget = MPartnerResourcestrings.StrPartnerFindSearchTargetText;
                                }
                            }
                            else
                            {
                                // Display the number of found Partners/Bank Accounts
                                if (grdResult.TotalRecords > 1)
                                {
                                    SearchTarget = MPartnerResourcestrings.StrPartnerFindByBankDetailsSearchTargetPluralText;
                                }
                                else
                                {
                                    SearchTarget = MPartnerResourcestrings.StrPartnerFindByBankDetailsSearchTargetText;
                                }
                            }

                            grpResult.Text = MPartnerResourcestrings.StrSearchResult + ": " + grdResult.TotalRecords.ToString() + ' ' +
                                             SearchTarget + ' ' +
                                             MPartnerResourcestrings.StrFoundText;

                            // StatusBar update
                            FPetraUtilsObject.SetStatusBarText(btnSearch, MPartnerResourcestrings.StrSearchButtonHelpText);
                            Application.DoEvents();

                            btnSearch.Enabled = true;

                            this.Cursor = Cursors.Default;

                            // if this was a broadcast search then the search is now finished and bool can be reset
                            FBroadcastMessageSearch = false;
                        }
                        else
                        {
                            // Search operation has found nothing

                            /*
                             * If PartnerKey wasn't 0, check if the Partner searched for
                             * was a MERGED Partner.
                             */
                            if ((Int64)FCriteriaData.Rows[0]["PartnerKey"] != 0)
                            {
                                if (TPartnerMain.MergedPartnerHandling(
                                        (Int64)FCriteriaData.Rows[0]["PartnerKey"],
                                        out MergedPartnerKey))
                                {
                                    FCriteriaData.Rows[0]["PartnerKey"] = MergedPartnerKey;
                                    BtnSearch_Click(this, null);
                                    UpdateUI = false;
                                }
                                else
                                {
                                    UpdateUI = true;
                                }
                            }
                            else
                            {
                                UpdateUI = true;
                            }

                            if (UpdateUI)
                            {
                                this.Cursor = Cursors.Default;
                                grpResult.Text = MPartnerResourcestrings.StrSearchResult;
                                lblSearchInfo.Text = MPartnerResourcestrings.StrNoRecordsFound1Text + ' ' +
                                                     MPartnerResourcestrings.StrPartnerFindSearchTarget2Text +
                                                     MPartnerResourcestrings.StrNoRecordsFound2Text;

                                OnDisableAcceptButton();
                                OnPartnerAvailable(false);

                                // StatusBar update
                                FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrGenericReady);
                                FPetraUtilsObject.SetStatusBarText(btnSearch, MPartnerResourcestrings.StrSearchButtonHelpText);
                                Application.DoEvents();

                                btnSearch.Enabled = true;

                                FCurrentGridRow = -1;
                            }
                            else
                            {
                                return;
                            }
                        }

                        /*
                         * Saves 'Mailing Addresses Only' and 'Partner Status' Criteria
                         * settings to UserDefaults.
                         */
                        if (!FNoSavingOfPartnerStatusUserDefault)
                        {
                            ucoPartnerFindCriteria.FindCriteriaUserDefaultSave();
                        }
                    }
                    else
                    {
                        // Search operation interrupted by user
                        // used to release server System.Object here
                        this.Cursor = Cursors.Default;
                        grpResult.Text = MPartnerResourcestrings.StrSearchResult;
                        lblSearchInfo.Text = MPartnerResourcestrings.StrSearchStopped;

                        OnPartnerAvailable(false);
                        btnSearch.Enabled = true;

                        // StatusBar update

                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrGenericReady);
                        FPetraUtilsObject.SetStatusBarText(btnSearch, MPartnerResourcestrings.StrSearchButtonHelpText);
                        Application.DoEvents();

                        FCurrentGridRow = -1;
                    }
                }

                // Enable/disable remaining controls
                btnClearCriteria.Enabled = Convert.ToBoolean(AEnable);
                chkDetailedResults.Enabled = Convert.ToBoolean(AEnable);
                ucoPartnerFindCriteria.Enabled = Convert.ToBoolean(AEnable);

                // Set search button text
                if (Convert.ToBoolean(AEnable))
                {
                    btnSearch.Text = MPartnerResourcestrings.StrSearchButtonText;
                    OnSearchOperationStateChange(false);
                }
                else
                {
                    btnSearch.Text = MPartnerResourcestrings.StrSearchButtonStopText;
                    OnSearchOperationStateChange(true);
                }

                // messagebox.show('EnableDisableUI ran!');
            }
        }
        /// <summary>
        /// Enables and disables the UI. Invokes setting up of the Grid after a
        /// successful search operation.
        /// </summary>
        /// <returns>void</returns>
        private void EnableDisableUI(System.Object AEnable)
        {
            object[]          Args;
            TMyUpdateDelegate MyUpdateDelegate;

            // Since this procedure is called from a separate (background) Thread, it is
            // necessary to execute this procedure in the Thread of the GUI
            if (btnSearch.InvokeRequired)
            {
                Args = new object[1];

                try
                {
                    MyUpdateDelegate = new TMyUpdateDelegate(EnableDisableUI);
                    Args[0]          = AEnable;
                    btnSearch.Invoke(MyUpdateDelegate, new object[] { AEnable });
                }
                finally
                {
                    Args = new object[0];
                }
            }
            else
            {
                // Enable/disable according to how the search operation ended
                if (Convert.ToBoolean(AEnable))
                {
                    TProgressState ThreadStatus = FGLTransactionFindObject.Progress;

                    if (ThreadStatus.JobFinished)
                    {
                        // Search operation ended without interruption
                        if (FPagedDataTable.Rows.Count > 0)
                        {
                            btnSearch.Enabled = false;

                            // At least one result was found by the search operation
                            lblSearchInfo.Text = "";

                            //
                            // Setup result DataGrid
                            //
                            if (grdResult.Columns.Count < 1)
                            {
                                SetupGrid();
                            }

                            SetupDataGridDataBinding();
                            grdResult.AutoSizeCells();

                            grdResult.Selection.SelectRow(1, true);

                            // Scroll grid to first line (the grid might have been scrolled before to another position)
                            grdResult.ShowCell(new Position(1, 1), true);

                            // For speed reasons we must add the necessary amount of emtpy Rows only here (after .AutoSizeCells() has already
                            // been run! See XML Comment on the called Method TSgrdDataGridPaged.AddEmptyRows() for details!
                            grdResult.AddEmptyRows();

                            grdResult.BringToFront();

                            // set tooltips
                            grdResult.SetHeaderTooltip(3, MFinanceConstants.BATCH_POSTED);
                            grdResult.SetHeaderTooltip(5, Catalog.GetString("Confidential"));

                            // Make the Grid respond on updown keys
                            grdResult.Focus();

                            // Display the number of found gift details
                            UpdateRecordNumberDisplay();

                            Application.DoEvents();

                            btnSearch.Enabled = true;

                            this.Cursor = Cursors.Default;
                        }
                        else
                        {
                            // Search operation has found nothing
                            this.Cursor        = Cursors.Default;
                            lblSearchInfo.Text = Catalog.GetString("No GL Transactions found.");
                            Application.DoEvents();

                            btnSearch.Enabled = true;

                            UpdateRecordNumberDisplay();
                        }
                    }
                    else
                    {
                        // Search operation interrupted by user
                        // used to release server System.Object here
                        // (It isn't currently possible for the user to stop the search. I don't think this functionality is necessary)
                        this.Cursor        = Cursors.Default;
                        lblSearchInfo.Text = Catalog.GetString("Search stopped!");

                        btnSearch.Enabled = true;
                        Application.DoEvents();
                    }

                    // enable or disable btnView
                    if (FPagedDataTable.Rows.Count > 0)
                    {
                        btnView.Enabled = true;
                    }
                    else
                    {
                        btnView.Enabled = false;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Update the User Interface with the data that was retrieved from the PetraServer.
        /// </summary>
        /// <remarks>This Method determines for itself whether it is running on the UI Tread
        /// and runs itself on the UI Thread if it isn't already doing so!</remarks>
        private void UpdateUI()
        {
            TMyUpdateDelegate MyUpdateDelegate;

            if (txtAcquisitionCode.InvokeRequired)
            {
//                MessageBox.Show("txtAcquisitionCode.InvokeRequired: yes");


                // We are not running on the UI Thread -> need to use Invoke to
                // make us run on the UI Thread!
                MyUpdateDelegate = new TMyUpdateDelegate(UpdateUI);

                try
                {
                    txtAcquisitionCode.Invoke(MyUpdateDelegate, new object[] { });
                }
                catch (System.ComponentModel.InvalidAsynchronousStateException)
                {
                    /*
                     * This Exception occurs when the Partner Find screen
                     * is closed while this UserControl is still fetching data.
                     * --> don't try to do any further action!
                     */
                    MyUpdateDelegate = null;
                }
                catch (Exception)
                {
                    throw;
                }


//                MessageBox.Show("Invoke finished!");
            }
            else
            {
                // We are running on the UI Thread -> go ahead and update the UI!

                try
                {
                    if (FServerCallError == String.Empty)
                    {
                        /*
                         * Update Controls with the Data from the passed in DataRow APartnerDR
                         * and with data from the DB, if necessary.
                         */
                        switch (FCurrentServerCallParams.Scope)
                        {
                            case TPartnerInfoAvailDataEnum.piadHeadOnly:
                            case TPartnerInfoAvailDataEnum.piadNone:

                                if ((FCurrentServerCallParams.ServerCallOK)
                                    && (FPartnerInfoDS.PPartnerLocation.Rows.Count > 0))
                                {
//                                                            MessageBox.Show(FPartnerInfoDS.PLocation.Rows[0][PLocationTable.GetStreetNameDBName()].ToString());

//                                                            if(FPartnerInfoDS.PPartnerType.Rows.Count > 0)
//                                                            {
//                                                                MessageBox.Show(FPartnerInfoDS.PPartnerType[0].TypeCode);
//                                                            }

                                    FLocationDataServerRetrieved = true;
                                    UpdateControlsLocationData();

                                    UpdateControlsRestData();

                                    if (FCurrentServerCallParams.Scope == TPartnerInfoAvailDataEnum.piadNone)
                                    {
                                        FHeadDataServerRetrieved = true;
                                        UpdateControlsHeadData();

                                        ShowHideLoadingInfoFullSize(false);
                                    }
                                }
                                else
                                {
                                    ClearControls(false, FCurrentServerCallParams.PartnerKey);
                                    ShowHideLoadingInfo(false, false, FCurrentServerCallParams.LoadRestOfData);
                                }

                                ShowHideLoadingInfo(false, true, FCurrentServerCallParams.LoadRestOfData);

                                break;

                            case TPartnerInfoAvailDataEnum.piadHeadAndLocationOnly:

                                if ((FCurrentServerCallParams.ServerCallOK)
                                    && (FPartnerInfoDS.PPartnerLocation.Rows.Count > 0))
                                {
                                    //                        MessageBox.Show(FPartnerInfoDS.PPartnerLocation.Rows[0][PPartnerLocationTable.GetTelephoneNumberDBName()].ToString());
                                    //
                                    //                        if(FPartnerInfoDS.PPartnerType.Rows.Count > 0)
                                    //                        {
                                    //                            MessageBox.Show(FPartnerInfoDS.PPartnerType[0].TypeCode);
                                    //                        }

                                    UpdateControlsRestData();
                                }
                                else
                                {
                                    ClearControls(false, FCurrentServerCallParams.PartnerKey);
                                    ShowHideLoadingInfo(false, false, FCurrentServerCallParams.LoadRestOfData);
                                }

                                ShowHideLoadingInfo(false, false, FCurrentServerCallParams.LoadRestOfData);

                                break;
                        }

                        /*
                         * Show 'Person / Family' Tab for PERSONs and FAMILYs
                         */
                        if ((FPartnerClass == TPartnerClass.PERSON)
                            || (FPartnerClass == TPartnerClass.FAMILY))
                        {
                            ShowHidePersonFamilyTab(true);
                        }
                        else
                        {
                            ShowHidePersonFamilyTab(false);
                        }

                        OnDataLoaded();
                    }
                    else
                    {
                        /*
                         * An Exception occured while making the call to the PetraServer ->
                         * inform user about that!
                         */
                        ClearControls(false);
                        ShowHideLoadingInfo(false, false, false);
                    }
                }
                catch (Exception Exp)
                {
                    TLogging.Log("Exception in TUC_PartnerInfo.UpdateUI: " + Exp.ToString());
                }
            }
        }