/// <summary>
        /// Verify and if necessary update partner data in an extract
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void VerifyAndUpdateExtract(System.Object sender, EventArgs e)
        {
            bool ChangesMade;
            ExtractTDSMExtractTable ExtractTable = FMainDS.MExtract;

            TFrmExtractMaster.VerifyAndUpdateExtract(FindForm(), ref ExtractTable, out ChangesMade);

            if (ChangesMade)
            {
                FPetraUtilsObject.SetChangedFlag();

                MessageBox.Show(String.Format(Catalog.GetString("Verification and Update of Extract {0} was successful. \n\r" +
                                                                "Please press the Save button to save the changes."), FExtractName),
                                Catalog.GetString("Verify and Update Extract"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(String.Format(Catalog.GetString("Extract {0} was already up to date"), FExtractName),
                                Catalog.GetString("Verify and Update Extract"),
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// initialize internal data before control is shown
        /// </summary>
        public void InitializeData()
        {
            // set fixed column widths as otherwise grid will spend a long time recalculating optimal width with big extracts
            grdDetails.Columns.Clear();
            grdDetails.AddTextColumn("Partner Key", FMainDS.MExtract.Columns[ExtractTDSMExtractTable.GetPartnerKeyDBName()], 100);
            grdDetails.AddTextColumn("Class", FMainDS.MExtract.Columns[ExtractTDSMExtractTable.GetPartnerClassDBName()], 100);
            grdDetails.AddTextColumn("Partner Name", FMainDS.MExtract.Columns[ExtractTDSMExtractTable.GetPartnerShortNameDBName()], 300);
            grdDetails.AddTextColumn("Location Key", FMainDS.MExtract.Columns[ExtractTDSMExtractTable.GetLocationKeyDBName()], 100);

            LoadData();

            // get the grid columns to fill the available space
            grdDetails.AutoStretchColumnsToFitWidth = true;
            grdDetails.Columns[2].AutoSizeMode      = SourceGrid.AutoSizeMode.EnableStretch | SourceGrid.AutoSizeMode.EnableAutoSize;
            grdDetails.Rows.AutoSizeMode            = SourceGrid.AutoSizeMode.None;

            // allow multiselection of list items so several records can be deleted at once
            grdDetails.Selection.EnableMultiSelection = true;

            // initialize button state
            if (grdDetails.Rows.Count > 1)
            {
                grdDetails.SelectRowInGrid(1);
                ShowDetails(1);

                UpdateRecordNumberDisplay();
            }
            else
            {
                btnEdit.Enabled = false;
            }
        }
        private void AddPartner(System.Object sender, EventArgs e)
        {
            ExtractTDSMExtractRow NewRow;

            System.Int64  PartnerKey = 0;
            string        PartnerShortName;
            TPartnerClass?PartnerClass;
            TPartnerClass PartnerClass2;
            TLocationPK   ResultLocationPK;

            DataRow[]             ExistingPartnerDataRows;
            ExtractTDSMExtractRow ExisitingPartnerRow;

            // If the delegate is defined, the host form will launch a Modal Partner Find screen for us
            if (TCommonScreensForwarding.OpenPartnerFindScreen != null)
            {
                // delegate IS defined
                try
                {
                    TCommonScreensForwarding.OpenPartnerFindScreen.Invoke
                        ("",
                        out PartnerKey,
                        out PartnerShortName,
                        out PartnerClass,
                        out ResultLocationPK,
                        this.ParentForm);

                    if (PartnerKey != -1)
                    {
                        ExistingPartnerDataRows = FMainDS.MExtract.Select(ExtractTDSMExtractTable.GetPartnerKeyDBName() + " = " + PartnerKey.ToString());

                        if (ExistingPartnerDataRows.Length > 0)
                        {
                            // check if partner already exists in extract
                            MessageBox.Show(Catalog.GetString("A record for this partner already exists in this extract"),
                                            Catalog.GetString("Add Partner to Extract"),
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);

                            // select the already existing partner record in the grid so the user can see it
                            ExisitingPartnerRow = (ExtractTDSMExtractRow)ExistingPartnerDataRows[0];
                            SelectByPartnerKey(PartnerKey, ExisitingPartnerRow.SiteKey);

                            return;
                        }

                        TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(
                            PartnerKey,
                            out PartnerShortName,
                            out PartnerClass2);

                        // add new record to extract
                        NewRow                  = FMainDS.MExtract.NewRowTyped();
                        NewRow.ExtractId        = FExtractId;
                        NewRow.PartnerKey       = PartnerKey;
                        NewRow.PartnerShortName = PartnerShortName;
                        NewRow.PartnerClass     = SharedTypes.PartnerClassEnumToString(PartnerClass2);
                        NewRow.SiteKey          = ResultLocationPK.SiteKey;
                        NewRow.LocationKey      = ResultLocationPK.LocationKey;
                        FMainDS.MExtract.Rows.Add(NewRow);

                        // Refresh DataGrid to show the added partner record
                        grdDetails.Refresh();

                        // select the added partner record in the grid so the user can see the change
                        SelectByPartnerKey(PartnerKey, ResultLocationPK.SiteKey);

                        // enable save button on screen
                        FPetraUtilsObject.SetChangedFlag();
                    }
                }
                catch (Exception exp)
                {
                    throw new EOPAppException("Exception occured while calling PartnerFindScreen Delegate!", exp);
                }
                // end try
            }
        }
        /// <summary>
        /// Verify and if necessary update partner data in an extract
        /// </summary>
        public static void VerifyAndUpdateExtract(System.Windows.Forms.Form AForm,
            ref ExtractTDSMExtractTable AExtractTable,
            out bool AChangesMade)
        {
            bool AddressExists;
            bool AddressNeitherCurrentNorMailing;
            bool ReplaceAddress;
            bool ReplaceAddressYesToAll = false;
            bool ReplaceAddressNoToAll = false;
            string CountryName;
            string EmailAddress;
            PLocationTable LocationTable;
            PLocationRow LocationRow;
            PPartnerLocationTable PartnerLocationTable;
            TFrmExtendedMessageBox MsgBox = new TFrmExtendedMessageBox(AForm);

            TFrmExtendedMessageBox.TResult MsgBoxResult;
            bool DontShowPartnerRemovePartnerKeyNonExistent = false;
            bool DontShowReplaceAddress = false;
            bool DontShowPartnerRemoveNoAddress = false;


            // initialize output parameter
            AChangesMade = false;

            // build a collection of objects to be deleted before actually deleting them (as otherwise
            // indexes may not be valid any longer)
            List <ExtractTDSMExtractRow>RowsToDelete = new List <ExtractTDSMExtractRow>();

            // prepare mouse cursor so user knows something is happening
            AForm.Cursor = Cursors.WaitCursor;

            // look at every single extract row
            foreach (ExtractTDSMExtractRow Row in AExtractTable.Rows)
            {
                // initialize for this row
                ReplaceAddress = false;

                // check if the partner record still exists, otherwise remove from extract
                if (!TRemote.MPartner.Partner.ServerLookups.WebConnectors.VerifyPartner(Row.PartnerKey))
                {
                    if (!DontShowPartnerRemovePartnerKeyNonExistent)
                    {
                        MsgBox.ShowDialog(String.Format(Catalog.GetString("The following partner record does not exist any longer and " +
                                    "will therefore be removed from this extract: \n\r\n\r" +
                                    "{0} ({1})"), Row.PartnerShortName, Row.PartnerKey),
                            Catalog.GetString("Verify and Update Extract"),
                            Catalog.GetString("Don't show this message again"),
                            TFrmExtendedMessageBox.TButtons.embbOK,
                            TFrmExtendedMessageBox.TIcon.embiInformation);
                        MsgBoxResult = MsgBox.GetResult(out DontShowPartnerRemovePartnerKeyNonExistent);
                    }

                    RowsToDelete.Add(Row);
                }
                else
                {
                    AddressExists = TRemote.MPartner.Partner.ServerLookups.WebConnectors.VerifyPartnerAtLocation
                                        (Row.PartnerKey, new TLocationPK(Row.SiteKey, Row.LocationKey), out AddressNeitherCurrentNorMailing);

                    if (!AddressExists)
                    {
                        if (!DontShowReplaceAddress)
                        {
                            MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract no longer exists and " +
                                        "will therefore be replaced with a current address"),
                                    Row.PartnerShortName, Row.PartnerKey),
                                Catalog.GetString("Verify and Update Extract"),
                                Catalog.GetString("Don't show this message again"),
                                TFrmExtendedMessageBox.TButtons.embbOK,
                                TFrmExtendedMessageBox.TIcon.embiInformation);
                            MsgBoxResult = MsgBox.GetResult(out DontShowReplaceAddress);
                        }

                        ReplaceAddress = true;
                    }
                    else if (AddressNeitherCurrentNorMailing)
                    {
                        if (!ReplaceAddressYesToAll
                            && !ReplaceAddressNoToAll)
                        {
                            MsgBoxResult =
                                MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract is not current. " +
                                            "Do you want to update it with a current address if there is one?"),
                                        Row.PartnerShortName, Row.PartnerKey),
                                    Catalog.GetString("Verify and Update Extract"),
                                    "",
                                    TFrmExtendedMessageBox.TButtons.embbYesYesToAllNoNoToAll,
                                    TFrmExtendedMessageBox.TIcon.embiQuestion);

                            if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrYesToAll)
                            {
                                ReplaceAddressYesToAll = true;
                            }
                            else if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrYes)
                            {
                                ReplaceAddress = true;
                            }
                            else if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrNoToAll)
                            {
                                ReplaceAddressNoToAll = true;
                            }
                        }

                        // need to set the flag each time we come through here.
                        if (ReplaceAddressYesToAll)
                        {
                            ReplaceAddress = true;
                        }
                    }

                    if (ReplaceAddress)
                    {
                        if (!TRemote.MPartner.Mailing.WebConnectors.GetBestAddress(Row.PartnerKey,
                                out LocationTable, out PartnerLocationTable, out CountryName, out EmailAddress))
                        {
                            // in this case there is no address at all for this partner (should not really happen)
                            if (!DontShowPartnerRemoveNoAddress)
                            {
                                MsgBox.ShowDialog(String.Format(Catalog.GetString("No address could be found for {0} ({1}). " +
                                            "Therefore the partner record will be removed from this extract"),
                                        Row.PartnerShortName, Row.PartnerKey),
                                    Catalog.GetString("Verify and Update Extract"),
                                    Catalog.GetString("Don't show this message again"),
                                    TFrmExtendedMessageBox.TButtons.embbOK,
                                    TFrmExtendedMessageBox.TIcon.embiInformation);
                                MsgBoxResult = MsgBox.GetResult(out DontShowPartnerRemoveNoAddress);
                            }

                            RowsToDelete.Add(Row);
                        }
                        else
                        {
                            if (LocationTable.Rows.Count > 0)
                            {
                                LocationRow = (PLocationRow)LocationTable.Rows[0];

                                /* it could be that GetBestAddress still returns a non-current address if
                                 * there is no better one */
                                if ((Row.SiteKey != LocationRow.SiteKey)
                                    || (Row.LocationKey != LocationRow.LocationKey))
                                {
                                    AChangesMade = true;

                                    Row.SiteKey = LocationRow.SiteKey;
                                    Row.LocationKey = LocationRow.LocationKey;
                                }
                            }
                        }
                    }
                }
            }

            // now delete the actual rows
            foreach (ExtractTDSMExtractRow Row in RowsToDelete)
            {
                AChangesMade = true;
                Row.Delete();
            }

            // prepare mouse cursor so user knows something is happening
            AForm.Cursor = Cursors.Default;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// save the changes on the screen (code is copied from auto-generated code)
        /// </summary>
        /// <returns></returns>
        public bool SaveChanges()
        {
            bool ReturnValue = false;

            FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs());

            if (FPetraUtilsObject.VerificationResultCollection.Count == 0)
            {
                foreach (DataRow InspectDR in FMainDS.MExtract.Rows)
                {
                    InspectDR.EndEdit();
                }

                if (!FPetraUtilsObject.HasChanges)
                {
                    return(true);
                }
                else
                {
                    FPetraUtilsObject.WriteToStatusBar("Saving data...");
                    this.Cursor = Cursors.WaitCursor;

                    TSubmitChangesResult SubmissionResult;

                    //Ict.Common.Data.TTypedDataTable SubmitDT = FMainDS.MExtract.GetChangesTyped();
                    MExtractTable           SubmitDT  = new MExtractTable();
                    ExtractTDSMExtractTable ChangesDT = FMainDS.MExtract.GetChangesTyped();

                    if (ChangesDT != null)
                    {
                        SubmitDT.Merge(ChangesDT);
                    }
                    else
                    {
                        SubmitDT = null;
                    }

                    if (SubmitDT == null)
                    {
                        // There is nothing to be saved.
                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved."));
                        this.Cursor = Cursors.Default;

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        return(true);
                    }

                    // Submit changes to the PETRAServer
                    try
                    {
                        SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtract
                                               (FExtractId, ref SubmitDT);
                    }
                    catch (ESecurityDBTableAccessDeniedException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgSecurityException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (EDBConcurrencyException Exp)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        TMessages.MsgDBConcurrencyException(Exp, this.GetType());

                        ReturnValue = false;
                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(ReturnValue);
                    }
                    catch (Exception)
                    {
                        FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException);
                        this.Cursor = Cursors.Default;

                        FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        throw;
                    }

                    switch (SubmissionResult)
                    {
                    case TSubmitChangesResult.scrOK:

                        // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server
                        FMainDS.MExtract.AcceptChanges();

                        // Merge back with data from the Server (eg. for getting Sequence values)
                        FMainDS.MExtract.Merge(SubmitDT, false);

                        // need to accept the new modification ID
                        FMainDS.MExtract.AcceptChanges();

                        // Update UI
                        FPetraUtilsObject.WriteToStatusBar("Data successfully saved.");
                        this.Cursor = Cursors.Default;

                        // TODO EnableSave(false);

                        // We don't have unsaved changes anymore
                        FPetraUtilsObject.DisableSaveButton();

                        SetPrimaryKeyReadOnly(true);

                        // refresh extract master screen if it is open
                        TFormsMessage BroadcastMessage = new TFormsMessage(TFormsMessageClassEnum.mcExtractCreated);
                        BroadcastMessage.SetMessageDataName(ExtractName);
                        TFormsList.GFormsList.BroadcastFormMessage(BroadcastMessage);
                        this.Focus();     // keeps the focus on the current form

                        // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue));
                        return(true);

                    case TSubmitChangesResult.scrError:

                        // TODO scrError
                        this.Cursor = Cursors.Default;
                        break;

                    case TSubmitChangesResult.scrNothingToBeSaved:

                        // TODO scrNothingToBeSaved
                        this.Cursor = Cursors.Default;
                        return(true);

                    case TSubmitChangesResult.scrInfoNeeded:

                        // TODO scrInfoNeeded
                        this.Cursor = Cursors.Default;
                        break;
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        //
        // This will be called if the Fast Reports Wrapper loaded OK.
        // Returns True if the data apparently loaded OK and the report should be printed.
        private bool LoadReportData(TRptCalculator ACalc)
        {
            ArrayList reportParam = ACalc.GetParameters().Elems;

            Dictionary <String, TVariant> paramsDictionary = new Dictionary <string, TVariant>();

            foreach (Shared.MReporting.TParameter p in reportParam)
            {
                if (p.name.StartsWith("param") && (p.name != "param_calculation") && (!paramsDictionary.ContainsKey(p.name)))
                {
                    paramsDictionary.Add(p.name, p.value);
                }
            }

            DataTable ReportTable = new DataTable();

            ReportTable.Columns.Add("DonorKey", typeof(Int64));
            ReportTable.Columns.Add("DonorShortName", typeof(String));
            ReportTable.Columns.Add("DonorAddress", typeof(String));

            ReportTable.Columns.Add("RecipientKey", typeof(Int64));
            ReportTable.Columns.Add("RecipientShortName", typeof(String));
            ReportTable.Columns.Add("RecipientAddress", typeof(String));

            ReportTable.Columns.Add("MailingCode", typeof(Int32));
            ReportTable.Columns.Add("CodeWithSpaces", typeof(String));
            ReportTable.Columns.Add("CodeForOcr", typeof(String));

            Int32   Copies;
            Boolean numbersOk = true;

            if (txtDonorKey.Enabled)
            {
                numbersOk &= txtDonorKey.FValueIsValid;
            }

            if (txtExtract.Enabled)
            {
                numbersOk &= txtExtract.FValueIsValid;
            }

            numbersOk &= txtRecipientKey.FValueIsValid;
            numbersOk &= Int32.TryParse(txtCopies.Text, out Copies);

            if (!numbersOk)
            {
                MessageBox.Show(
                    Catalog.GetString("Please ensure that Donor, Recipient, and Copies are correctly set."),
                    Catalog.GetString("ESR Inpayment Slip")
                    );
                return(false);
            }

            Int64 RecipientKey = Convert.ToInt64(txtRecipientKey.Text);

            Int32 MailingCode = 8; // If the mailing code box is left empty, I'll accept that.

            if (txtMailingCode.Text.Length > 0)
            {
                numbersOk = Int32.TryParse(txtMailingCode.Text, out MailingCode);

                if (!numbersOk)
                {
                    MessageBox.Show(
                        Catalog.GetString("For ESR, Mailing Code must be numeric."),
                        Catalog.GetString("ESR Inpayment Slip")
                        );
                    return(false);
                }
            }

            String MailingCodeString = MailingCode.ToString();

            MailingCodeString = (MailingCodeString + "8888888").Substring(0, 6);

            if (rbtExtract.Checked)
            {
                Int32 ExtractId = TRemote.MPartner.Partner.WebConnectors.GetExtractId(txtExtract.Text);

                if (ExtractId < 0)
                {
                    MessageBox.Show(
                        Catalog.GetString("Extract with this name does not exist."),
                        Catalog.GetString("ESR Inpayment Slip"),
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                ExtractTDSMExtractTable ExtractDT = TRemote.MPartner.Partner.WebConnectors.GetExtractRowsWithPartnerData(ExtractId);

                foreach (ExtractTDSMExtractRow Row in ExtractDT.Rows)
                {
                    AddRowToTable(ReportTable, Row.PartnerKey, RecipientKey, MailingCodeString, Copies);
                }
            }
            else // Otherwise just a single donor was selected:
            {
                Int64 DonorKey = Convert.ToInt64(txtDonorKey.Text);
                AddRowToTable(ReportTable, DonorKey, RecipientKey, MailingCodeString, Copies);
            }

            FPetraUtilsObject.FFastReportsPlugin.RegisterData(ReportTable, "EsrInpaymentSlip");
            return(true);
        }
Ejemplo n.º 7
0
        public static ExtractTDSMExtractTable GetExtractRowsWithPartnerData(int AExtractId)
        {
            ExtractTDSMExtractTable ExtractDT = new ExtractTDSMExtractTable();
            string SqlStmt;

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted,
                ref Transaction,
                delegate
                {
                    // Use a direct sql statement rather than db access classes to improve performance as otherwise
                    // we would need an extra query for each row of an extract to retrieve partner name and class
                    SqlStmt = "SELECT pub_" + MExtractTable.GetTableDBName() + ".*" +
                              ", pub_" + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerShortNameDBName() +
                              ", pub_" + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerClassDBName() +
                              " FROM pub_" + MExtractTable.GetTableDBName() + ", pub_" + PPartnerTable.GetTableDBName() +
                              " WHERE pub_" + MExtractTable.GetTableDBName() + "." + MExtractTable.GetExtractIdDBName() +
                              " = " + AExtractId.ToString() +
                              " AND pub_" + MExtractTable.GetTableDBName() + "." + MExtractTable.GetPartnerKeyDBName() +
                              " = pub_" + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerKeyDBName() +
                              " ORDER BY " + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerShortNameDBName();

                    DBAccess.GDBAccessObj.SelectDT(ExtractDT, SqlStmt, Transaction, null, -1, -1);
                });

            return ExtractDT;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Verify and if necessary update partner data in an extract
        /// </summary>
        public static void VerifyAndUpdateExtract(System.Windows.Forms.Form AForm,
                                                  ref ExtractTDSMExtractTable AExtractTable,
                                                  out bool AChangesMade)
        {
            bool                   AddressExists;
            bool                   AddressNeitherCurrentNorMailing;
            bool                   ReplaceAddressYesToAll = false;
            bool                   ReplaceAddressNoToAll  = false;
            string                 CountryName;
            PLocationTable         LocationTable;
            PLocationRow           LocationRow;
            TFrmExtendedMessageBox MsgBox;

            TFrmExtendedMessageBox.TResult MsgBoxResult;
            bool DontShowPartnerRemovePartnerKeyNonExistent = false;
            bool DontShowReplaceAddress         = false;
            bool DontShowPartnerRemoveNoAddress = false;


            // initialize output parameter
            AChangesMade = false;

            // build a collection of objects to be deleted before actually deleting them (as otherwise indexes may not be valid any longer)
            List <ExtractTDSMExtractRow> ReplaceAddressList = new List <ExtractTDSMExtractRow>();

            // collection of partners that need their address updated
            List <ExtractTDSMExtractRow> RowsToDelete = new List <ExtractTDSMExtractRow>();

            // collection of partners who's addresses no longer exist
            List <ExtractTDSMExtractRow> AddressNotExistsList = new List <ExtractTDSMExtractRow>();

            // collection of partners who's addresses are not current or mailing
            List <ExtractTDSMExtractRow> AddressNeitherCurrentNorMailingList = new List <ExtractTDSMExtractRow>();

            // prepare mouse cursor so user knows something is happening
            AForm.Cursor = Cursors.WaitCursor;

            // look at every single extract row
            foreach (ExtractTDSMExtractRow Row in AExtractTable.Rows)
            {
                // check if the partner record still exists, otherwise remove from extract
                if (!TRemote.MPartner.Partner.ServerLookups.WebConnectors.VerifyPartner(Row.PartnerKey))
                {
                    RowsToDelete.Add(Row);
                }
                else
                {
                    AddressExists = TRemote.MPartner.Partner.ServerLookups.WebConnectors.VerifyPartnerAtLocation
                                        (Row.PartnerKey, new TLocationPK(Row.SiteKey, Row.LocationKey), out AddressNeitherCurrentNorMailing);

                    if (!AddressExists) // if address no longer exists
                    {
                        AddressNotExistsList.Add(Row);
                    }
                    else if (AddressNeitherCurrentNorMailing) // address still exists but is not longer current or mailing
                    {
                        AddressNeitherCurrentNorMailingList.Add(Row);
                    }
                }
            }

            int i = 1;

            // for each partner that needs removed from the extract
            foreach (ExtractTDSMExtractRow Row in RowsToDelete)
            {
                MsgBox = new TFrmExtendedMessageBox(AForm);

                if (!DontShowPartnerRemovePartnerKeyNonExistent) // if user has not requested to not see these messages
                {
                    // warn the user what is happening
                    if (RowsToDelete.Count != i) // multiple left to delete
                    {
                        MsgBox.ShowDialog(String.Format(Catalog.GetString("The following partner record does not exist any longer and " +
                                                                          "will therefore be removed from this extract: \n\r\n\r" +
                                                                          "{0} ({1})"), Row.PartnerShortName, Row.PartnerKey),
                                          Catalog.GetString("Verify and Update Extract"),
                                          String.Format(Catalog.GetString("Don't show this message again ({0} more)"), RowsToDelete.Count - i),
                                          TFrmExtendedMessageBox.TButtons.embbOK,
                                          TFrmExtendedMessageBox.TIcon.embiInformation);
                    }
                    else // only one left to delete
                    {
                        MsgBox.ShowDialog(String.Format(Catalog.GetString("The following partner record does not exist any longer and " +
                                                                          "will therefore be removed from this extract: \n\r\n\r" +
                                                                          "{0} ({1})"), Row.PartnerShortName, Row.PartnerKey),
                                          Catalog.GetString("Verify and Update Extract"),
                                          "",
                                          TFrmExtendedMessageBox.TButtons.embbOK,
                                          TFrmExtendedMessageBox.TIcon.embiInformation);
                    }

                    MsgBoxResult = MsgBox.GetResult(out DontShowPartnerRemovePartnerKeyNonExistent);
                }

                AChangesMade = true;
                Row.Delete();  // now delete the actual row

                i++;
            }

            i = 1;

            // for each partner that has an address that no longer exists
            foreach (ExtractTDSMExtractRow Row in AddressNotExistsList)
            {
                MsgBox = new TFrmExtendedMessageBox(AForm);

                if (!DontShowReplaceAddress) // if user has not requested to not see these messages
                {
                    // warn the user what is happening
                    if (AddressNotExistsList.Count != i) // multiple rows left
                    {
                        MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract no longer exists and " +
                                                                          "will therefore be replaced with a current address."),
                                                        Row.PartnerShortName, Row.PartnerKey),
                                          Catalog.GetString("Verify and Update Extract"),
                                          String.Format(Catalog.GetString("Don't show this message again ({0} more)"), AddressNotExistsList.Count - i),
                                          TFrmExtendedMessageBox.TButtons.embbOK,
                                          TFrmExtendedMessageBox.TIcon.embiInformation);
                    }
                    else // only one row left
                    {
                        MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract no longer exists and " +
                                                                          "will therefore be replaced with a current address."),
                                                        Row.PartnerShortName, Row.PartnerKey),
                                          Catalog.GetString("Verify and Update Extract"),
                                          "",
                                          TFrmExtendedMessageBox.TButtons.embbOK,
                                          TFrmExtendedMessageBox.TIcon.embiInformation);
                    }

                    MsgBoxResult = MsgBox.GetResult(out DontShowReplaceAddress);
                }

                ReplaceAddressList.Add(Row);

                i++;
            }

            i = 1;

            // for each partner that has an address that is no longer current or mailing
            foreach (ExtractTDSMExtractRow Row in AddressNeitherCurrentNorMailingList)
            {
                MsgBox = new TFrmExtendedMessageBox(AForm);

                if (!ReplaceAddressYesToAll && !ReplaceAddressNoToAll) // if user has not requested to not see these messages
                {
                    // ask the user if the address should be updates
                    if (AddressNeitherCurrentNorMailingList.Count != i) // multiple rows left
                    {
                        MsgBoxResult =
                            MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract is not current. " +
                                                                              "Do you want to update it with a current address if there is one?{2}{2}" +
                                                                              "({3} more like this.)"),
                                                            Row.PartnerShortName, Row.PartnerKey, Environment.NewLine, AddressNeitherCurrentNorMailingList.Count - i),
                                              Catalog.GetString("Verify and Update Extract"),
                                              "",
                                              TFrmExtendedMessageBox.TButtons.embbYesYesToAllNoNoToAll,
                                              TFrmExtendedMessageBox.TIcon.embiQuestion);
                    }
                    else // only one row left
                    {
                        MsgBoxResult =
                            MsgBox.ShowDialog(String.Format(Catalog.GetString("Address for {0} ({1}) in this extract is not current. " +
                                                                              "Do you want to update it with a current address if there is one?"),
                                                            Row.PartnerShortName, Row.PartnerKey),
                                              Catalog.GetString("Verify and Update Extract"),
                                              "",
                                              TFrmExtendedMessageBox.TButtons.embbYesNo,
                                              TFrmExtendedMessageBox.TIcon.embiQuestion);
                    }

                    if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrYesToAll)
                    {
                        ReplaceAddressYesToAll = true;
                    }
                    else if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrYes)
                    {
                        ReplaceAddressList.Add(Row);
                    }
                    else if (MsgBoxResult == TFrmExtendedMessageBox.TResult.embrNoToAll)
                    {
                        ReplaceAddressNoToAll = true;
                    }
                }

                // need to set the flag each time we come through here.
                if (ReplaceAddressYesToAll)
                {
                    ReplaceAddressList.Add(Row);
                }

                i++;
            }

            // for each partner that needs their address updated
            foreach (ExtractTDSMExtractRow Row in ReplaceAddressList)
            {
                MsgBox = new TFrmExtendedMessageBox(AForm);

                if (!TRemote.MPartner.Mailing.WebConnectors.GetBestAddress(Row.PartnerKey,
                                                                           out LocationTable, out CountryName))
                {
                    // in this case there is no address at all for this partner (should not really happen)
                    if (!DontShowPartnerRemoveNoAddress)
                    {
                        MsgBox.ShowDialog(String.Format(Catalog.GetString("No address could be found for {0} ({1}). " +
                                                                          "Therefore the partner record will be removed from this extract"),
                                                        Row.PartnerShortName, Row.PartnerKey),
                                          Catalog.GetString("Verify and Update Extract"),
                                          Catalog.GetString("Don't show this message again"),
                                          TFrmExtendedMessageBox.TButtons.embbOK,
                                          TFrmExtendedMessageBox.TIcon.embiInformation);
                        MsgBoxResult = MsgBox.GetResult(out DontShowPartnerRemoveNoAddress);
                    }

                    RowsToDelete.Add(Row);
                }
                else
                {
                    if (LocationTable.Rows.Count > 0)
                    {
                        LocationRow = (PLocationRow)LocationTable.Rows[0];

                        /* it could be that GetBestAddress still returns a non-current address if
                         * there is no better one */
                        if ((Row.SiteKey != LocationRow.SiteKey) ||
                            (Row.LocationKey != LocationRow.LocationKey))
                        {
                            AChangesMade = true;

                            Row.SiteKey     = LocationRow.SiteKey;
                            Row.LocationKey = LocationRow.LocationKey;
                        }
                    }
                }
            }

            // prepare mouse cursor so user knows something is happening
            AForm.Cursor = Cursors.Default;
        }
Ejemplo n.º 9
0
        public static ExtractTDSMExtractTable GetExtractRowsWithPartnerData(int AExtractId)
        {
            ExtractTDSMExtractTable ExtractDT = new ExtractTDSMExtractTable();
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);
            string SqlStmt;

            try
            {
                // Use a direct sql statement rather than db access classes to improve performance as otherwise
                // we would need an extra query for each row of an extract to retrieve partner name and class
                SqlStmt = "SELECT pub_" + MExtractTable.GetTableDBName() + ".*" +
                          ", pub_" + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerShortNameDBName() +
                          ", pub_" + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerClassDBName() +
                          " FROM pub_" + MExtractTable.GetTableDBName() + ", pub_" + PPartnerTable.GetTableDBName() +
                          " WHERE pub_" + MExtractTable.GetTableDBName() + "." + MExtractTable.GetExtractIdDBName() +
                          " = " + AExtractId.ToString() +
                          " AND pub_" + MExtractTable.GetTableDBName() + "." + MExtractTable.GetPartnerKeyDBName() +
                          " = pub_" + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerKeyDBName();

                DBAccess.GDBAccessObj.SelectDT(ExtractDT, SqlStmt, Transaction, null, -1, -1);

                DBAccess.GDBAccessObj.CommitTransaction();
            }
            catch (Exception e)
            {
                TLogging.Log("Problem during load of an extract: " + e.Message);
                DBAccess.GDBAccessObj.CommitTransaction();
            }

            return ExtractDT;
        }