Ejemplo n.º 1
0
        // automatically select the currently selected Bank (if it exists)
        private void SelectRowInGrid()
        {
            int RowPos = 1;

            // if no bank is selected then no row should be selected
            if ((grdDetails.Rows.Count <= 1) || (FBankPartnerKey == 0))
            {
                // select the first row in the grid
                if (grdDetails.Rows.Count > 1)
                {
                    grdDetails.SelectRowWithoutFocus(1);
                }
                else
                {
                    btnAccept.Enabled = false;
                    btnEdit.Enabled   = false;
                }

                return;
            }

            BankTDSPBankRow BankRow = null;

            // Multiple rows could have the same partner keys but different locations.
            // We just want the first row.
            foreach (BankTDSPBankRow Row in FMainDS.PBank.Rows)
            {
                if (Row.PartnerKey == FBankPartnerKey)
                {
                    BankRow = Row;
                    break;
                }
            }

            // if current bank is 'inactive' then make sure chkShowInactive is checked (unchecked by default)
            if ((BankRow != null) &&
                (BankRow.StatusCode != SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscACTIVE)) &&
                (chkShowInactive.Checked == false))
            {
                chkShowInactive.Checked = true;
            }

            if (BankRow == null)
            {
                grdDetails.SelectRowWithoutFocus(1);
            }
            else
            {
                // look through each row in the grid
                foreach (DataRowView RowView in FCriteriaData.DefaultView)
                {
                    // if current grid row is the row we are looking for the select it
                    if (Convert.ToInt64(RowView[PBankTable.GetPartnerKeyDBName()]) == FBankPartnerKey)
                    {
                        grdDetails.SelectRowWithoutFocus(RowPos);

                        btnAccept.Enabled = true;
                        btnEdit.Enabled   = true;

                        return;
                    }

                    // account for grid rows being filtered by being inactive
                    if (chkShowInactive.Checked ||
                        (!chkShowInactive.Checked &&
                         (RowView[BankTDSPBankTable.GetStatusCodeDBName()].ToString() ==
                          SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscACTIVE))))
                    {
                        RowPos++;
                    }
                }
            }
        }
        // when cmbBankName is changed
        private void BankNameChanged(System.Object sender, EventArgs e)
        {
            // if a blank name has just been selected
            if (string.IsNullOrEmpty(cmbBankName.GetSelectedString())
                && ((FCurrentBankRow == null) || string.IsNullOrEmpty(FCurrentBankRow.BranchName)))
            {
                txtBankKey.Text = "0";
            }
            // cmbBankName.ContainsFocus is needed because the combobox automatically changes the selection
            // to the first row with that name when the focus is left. This was a problem with multiple banks with the same name.
            else if (((FCurrentBankRow == null) || (FCurrentBankRow.PartnerKey.ToString() != cmbBankName.GetSelectedString()))
                     && (cmbBankName.GetSelectedString() != "")
                     && cmbBankName.ContainsFocus)
            {
                FCurrentBankRow = GetCurrentRow(Convert.ToInt64(cmbBankName.GetSelectedString()));

                // update partner key in txtBankKey
                if (FCurrentBankRow != null)
                {
                    txtBankKey.Text = FCurrentBankRow.PartnerKey.ToString();
                    PartnerKeyChanged(FCurrentBankRow.PartnerKey, "", true);
                }
                else
                {
                    txtBankKey.Text = "0";
                    PartnerKeyChanged(0, "", true);
                }
            }
        }
        // when cmbBankCode is changed
        private void BankCodeChanged(System.Object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmbBankCode.GetSelectedString()) && (FCurrentBankRow == null))
            {
                return;
            }
            else if ((string.IsNullOrEmpty(cmbBankCode.GetSelectedString()) && !string.IsNullOrEmpty(FCurrentBankRow.BranchCode))
                     || ((cmbBankCode.GetSelectedString() == SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " ")
                         && ((FCurrentBankRow == null) || (FCurrentBankRow.BranchCode != SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " "))))
            {
                // if "<INACTIVE>" has been selected change it to blank
                cmbBankCode.SelectedIndex = -1;
                txtBankKey.Text = "0";
            }
            else if ((FCurrentBankRow == null) || (FCurrentBankRow.BranchCode != cmbBankCode.GetSelectedString()))
            {
                FCurrentBankRow = GetCurrentRow(Convert.ToInt64(cmbBankCode.GetSelectedDescription()));

                // update partner key in txtBankKey
                txtBankKey.Text = FCurrentBankRow.PartnerKey.ToString();
                PartnerKeyChanged(FCurrentBankRow.PartnerKey, "", true);
            }
        }
        // called when FindBank dialog is accepted
        private void PartnerKeyChanged(long APartnerKey, String APartnerShortName, bool AValidSelection)
        {
            if (!FComboBoxesCreated)
            {
                return;
            }

            FCurrentBankRow = GetCurrentRow(APartnerKey);

            // change the BankName combo (if it was not the control used to change the bank)
            if ((FCurrentBankRow != null) && (cmbBankName.GetSelectedString() != FCurrentBankRow.PartnerKey.ToString()))
            {
                // temporarily remove event
                cmbBankName.SelectedValueChanged -= BankNameChanged;

                cmbBankName.SetSelectedString(FCurrentBankRow.BranchName);

                // If other banks have the same name then we must iterate through all banks to select the one we want
                while (cmbBankName.GetSelectedString() != FCurrentBankRow.BranchName
                       && cmbBankName.GetSelectedDescription() != FCurrentBankRow.BranchCode)
                {
                    cmbBankName.cmbCombobox.SelectedIndex += 1;
                }

                cmbBankName.SelectedValueChanged += new System.EventHandler(this.BankNameChanged);
            }
            else if ((FCurrentBankRow == null) && (cmbBankName.GetSelectedString() != ""))
            {
                // temporarily remove event
                cmbBankName.SelectedValueChanged -= BankNameChanged;

                cmbBankName.SetSelectedString("");

                cmbBankName.SelectedValueChanged += new System.EventHandler(this.BankNameChanged);
            }

            // change the BankCode combo (if it was not the control used to change the bank)
            if ((FCurrentBankRow != null) && (cmbBankCode.GetSelectedString() != FCurrentBankRow.BranchCode))
            {
                cmbBankCode.SetSelectedString(FCurrentBankRow.BranchCode);
            }
            else if ((FCurrentBankRow == null) && (cmbBankCode.GetSelectedString() != ""))
            {
                // temporarily remove event
                cmbBankCode.SelectedValueChanged -= BankCodeChanged;

                cmbBankCode.SetSelectedString("");

                cmbBankCode.SelectedValueChanged += new System.EventHandler(this.BankCodeChanged);
            }

            // change the bank info
            if ((FCurrentBankRow != null) && (APartnerKey != 0) && (APartnerKey != -1))
            {
                lblBicSwiftCode.Text = Catalog.GetString("BIC/SWIFT Code: ") + FCurrentBankRow.Bic;
                lblCountry.Text = Catalog.GetString("Country: ");

                if (!string.IsNullOrEmpty(FCurrentBankRow.CountryCode))
                {
                    lblCountry.Text += FCurrentBankRow.CountryCode;
                }
                else
                {
                    lblCountry.Text += Catalog.GetString("No Valid Address On File");
                }
            }
            else
            {
                lblBicSwiftCode.Text = "BIC/SWIFT Code: ";
                lblCountry.Text = "Country: ";
            }
        }