예제 #1
0
        public static string Start(string AReportID, System.Data.DataTable AParameters)
        {
            string session        = TSession.GetSessionID();
            string configfilename = TAppSettingsManager.ConfigFileName;

            TParameterList ParameterList = new TParameterList();

            ParameterList.LoadFromDataTable(AParameters);

            String PathStandardReports = TAppSettingsManager.GetValue("Reporting.PathStandardReports");
            String PathCustomReports   = TAppSettingsManager.GetValue("Reporting.PathCustomReports");

            TRptDataCalculator Datacalculator = new TRptDataCalculator(PathStandardReports, PathCustomReports);

            ThreadStart myThreadStart = delegate {
                Run(configfilename, session, AReportID, Datacalculator, ParameterList);
            };
            Thread TheThread = new Thread(myThreadStart);

            TheThread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            TheThread.Name           = AReportID + "_" + UserInfo.GetUserInfo().UserID + "__TReportGeneratorUIConnector.Start_Thread";
            TLogging.LogAtLevel(7, TheThread.Name + " starting.");
            TheThread.Start();

            return(AReportID);
        }
예제 #2
0
        /// <summary>
        /// Calculates the report, which is specified in the parameters table
        ///
        /// </summary>
        /// <returns>void</returns>
        public void Start(System.Data.DataTable AParameters)
        {
            FProgressID = "ReportCalculation" + Guid.NewGuid();
            TProgressTracker.InitProgressTracker(FProgressID, string.Empty, -1.0m);

            FParameterList = new TParameterList();
            FParameterList.LoadFromDataTable(AParameters);

            FSuccess = false;

            String PathStandardReports = TAppSettingsManager.GetValue("Reporting.PathStandardReports");
            String PathCustomReports   = TAppSettingsManager.GetValue("Reporting.PathCustomReports");

            FDatacalculator = new TRptDataCalculator(PathStandardReports, PathCustomReports);

            // setup the logging to go to the TProgressTracker
            TLogging.SetStatusBarProcedure(new TLogging.TStatusCallbackProcedure(WriteToStatusBar));

            string      session       = TSession.GetSessionID();
            ThreadStart myThreadStart = delegate {
                Run(session);
            };
            Thread TheThread = new Thread(myThreadStart);

            TheThread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            TheThread.Name           = FProgressID + "_" + UserInfo.GetUserInfo().UserID + "__TReportGeneratorUIConnector.Start_Thread";
            TLogging.LogAtLevel(7, TheThread.Name + " starting.");
            TheThread.Start();
        }
예제 #3
0
        /// <summary>
        /// Calculates the report, which is specified in the parameters table
        ///
        /// </summary>
        /// <returns>void</returns>
        public void Start(System.Data.DataTable AParameters)
        {
            TRptUserFunctionsFinance.FlushSqlCache();
            FProgressID = "ReportCalculation" + Guid.NewGuid();
            TProgressTracker.InitProgressTracker(FProgressID, string.Empty, -1.0m);
            FParameterList = new TParameterList();
            FParameterList.LoadFromDataTable(AParameters);
            FSuccess = false;
            String PathStandardReports = TAppSettingsManager.GetValue("Reporting.PathStandardReports");
            String PathCustomReports   = TAppSettingsManager.GetValue("Reporting.PathCustomReports");

            FDatacalculator = new TRptDataCalculator(DBAccess.GDBAccessObj, PathStandardReports, PathCustomReports);

            // setup the logging to go to the TProgressTracker
            TLogging.SetStatusBarProcedure(new TLogging.TStatusCallbackProcedure(WriteToStatusBar));
            string      session       = TSession.GetSessionID();
            ThreadStart myThreadStart = delegate {
                Run(session);
            };
            Thread TheThread = new Thread(myThreadStart);

            TheThread.Name           = FProgressID;
            TheThread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            TheThread.Start();
        }
예제 #4
0
        public static string Create()
        {
            string session = TSession.GetSessionID();

            string ReportID = "ReportCalculation" + session + Guid.NewGuid();

            TProgressTracker.InitProgressTracker(ReportID, string.Empty, -1.0m);

            return(ReportID);
        }
        public static bool TrainBankStatementsLastMonth(Int32 ALedgerNumber, DateTime AToday)
        {
            string sessionID = TSession.GetSessionID();
            Int32  clientID  = DomainManager.GClientID;
            Thread t         = new Thread(() => TrainBankStatementsLastMonthThread(
                                              sessionID,
                                              clientID,
                                              ALedgerNumber, AToday));

            t.Name = Guid.NewGuid().ToString();

            t.Start();
            return(true);
        }
예제 #6
0
        /// <summary>
        /// Calculates the report, which is specified in the parameters table
        ///
        /// </summary>
        /// <returns>void</returns>
        public void Start(System.Data.DataTable AParameters)
        {
            FProgressID = "ReportCalculation" + Guid.NewGuid();
            TProgressTracker.InitProgressTracker(FProgressID, string.Empty, -1.0m);

            // First check whether the 'globally available' DB Connection isn't busy - we must not allow the start of a
            // Report Calculation when that is the case (as this would lead to a nested DB Transaction exception,
            // EDBTransactionBusyException).
            if (DBAccess.GDBAccessObj.Transaction != null)
            {
                FErrorMessage = Catalog.GetString(SharedConstants.NO_PARALLEL_EXECUTION_OF_XML_REPORTS_PREFIX +
                                                  "The OpenPetra Server is currently too busy to prepare this Report. " +
                                                  "Please retry once other running tasks (eg. a Report) are finished!");
                TProgressTracker.FinishJob(FProgressID);
                FSuccess = false;

                // Return to the Client immediately!
                return;
            }

            TRptUserFunctionsFinance.FlushSqlCache();

            FParameterList = new TParameterList();
            FParameterList.LoadFromDataTable(AParameters);

            FSuccess = false;

            String PathStandardReports = TAppSettingsManager.GetValue("Reporting.PathStandardReports");
            String PathCustomReports   = TAppSettingsManager.GetValue("Reporting.PathCustomReports");

            FDatacalculator = new TRptDataCalculator(DBAccess.GDBAccessObj, PathStandardReports, PathCustomReports);

            // setup the logging to go to the TProgressTracker
            TLogging.SetStatusBarProcedure(new TLogging.TStatusCallbackProcedure(WriteToStatusBar));

            string      session       = TSession.GetSessionID();
            ThreadStart myThreadStart = delegate {
                Run(session);
            };
            Thread TheThread = new Thread(myThreadStart);

            TheThread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            TheThread.Name           = FProgressID + "_" + UserInfo.GUserInfo.UserID + "__TReportGeneratorUIConnector.Start_Thread";
            TLogging.LogAtLevel(7, TheThread.Name + " starting.");
            TheThread.Start();
        }
        /// <summary>
        /// Procedure to execute a Find query. Although the full
        /// query results are retrieved from the DB and stored internally in an object,
        /// data will be returned in 'pages' of data, each page holding a defined number
        /// of records.
        /// </summary>
        /// <param name="ACriteriaData">HashTable containing non-empty Partner Find parameters</param>
        public void PerformSearch(DataTable ACriteriaData)
        {
            String CustomWhereCriteria;

            OdbcParameter[] ParametersArray;

            FPagedDataSetObject = new TPagedDataSet(new PartnerFindTDSSearchResultTable());

            // Pass the TAsynchronousExecutionProgress object to FPagedDataSetObject so that it

            // Build WHERE criteria string based on AFindCriteria
            CustomWhereCriteria = BuildCustomWhereCriteria(ACriteriaData, out ParametersArray);

            TLogging.LogAtLevel(6, "WHERE CLAUSE: " + CustomWhereCriteria);

            FPagedDataSetObject.FindParameters = new TPagedDataSet.TAsyncFindParameters(
                " p_city_c, p_postal_code_c,  p_locality_c, p_street_name_c, p_address_3_c, p_county_c, p_country_code_c, p_location_key_i, p_site_key_n ",
                "PUB_p_location ",
                " p_location_key_i<>-1 " + CustomWhereCriteria + ' ',
                "p_city_c ",
                null,
                ParametersArray);

            // fields
            // table
            // where
            // order by
            // both empty for now

            string session        = TSession.GetSessionID();
            string configfilename = TAppSettingsManager.ConfigFileName;

            //
            // Start the Find Thread
            //
            ThreadStart myThreadStart = delegate {
                FPagedDataSetObject.ExecuteQuery(configfilename, session);
            };

            FFindThread      = new Thread(myThreadStart);
            FFindThread.Name = "PartnerLocationFind" + Guid.NewGuid().ToString();
        }
예제 #8
0
        /// <summary>
        /// Procedure to execute a Find query. Although the full query results are retrieved from the DB and stored
        /// internally in an object, data will be returned in 'pages' of data, each page holding a defined number
        /// of records.
        /// </summary>
        /// <param name="ACriteriaData">HashTable containing non-empty Find parameters.</param>
        public void PerformSearch(DataTable ACriteriaData)
        {
            string PaymentNumberSQLPart;

            FPagedDataSetObject = new TPagedDataSet(null);

            DataRow CriteriaRow  = PrepareDataRow(ACriteriaData);
            Int32   ledgerNumber = (Int32)CriteriaRow["LedgerNumber"];

            if (FSearchTransactions)
            {
                if (CommonTypes.ParseDBType(DBAccess.GDBAccessObj.DBType) == TDBType.SQLite)
                {
                    // Fix for SQLite: it does not support the 'to_char' Function
                    PaymentNumberSQLPart = "PUB_a_ap_payment.a_payment_number_i as InvNum, ";
                }
                else
                {
                    // whereas PostgreSQL does!
                    PaymentNumberSQLPart = "to_char(PUB_a_ap_payment.a_payment_number_i, '99999') as InvNum, ";
                }

                Int64  PartnerKey = Convert.ToInt64(CriteriaRow["PartnerKey"]);
                String SqlQuery   = "SELECT DISTINCT " +
                                    "0 as ApDocumentId, " +
                                    "PUB_a_ap_payment.a_payment_number_i as ApNum, " +
                                    PaymentNumberSQLPart +
                                    "true as CreditNote, " +
                                    "'Payment' as Type, " +
                                    "PUB_a_ap_payment.a_currency_code_c as Currency, " +
                                    "PUB_a_ap_payment.a_amount_n as Amount, " +
                                    "0 AS OutstandingAmount, " +
                                    "'' as Status, " +
                                    "0 as DiscountPercent, " +
                                    "0 as DiscountDays, " +
                                    "PUB_a_ap_payment.s_date_created_d as Date " +
                                    " FROM PUB_a_ap_payment LEFT JOIN PUB_a_ap_document_payment on PUB_a_ap_payment.a_payment_number_i = PUB_a_ap_document_payment.a_payment_number_i"
                                    +
                                    " LEFT JOIN PUB_a_ap_document on PUB_a_ap_document_payment.a_ap_document_id_i = PUB_a_ap_document.a_ap_document_id_i\n"
                                    +
                                    " WHERE PUB_a_ap_document_payment.a_ledger_number_i=" + ledgerNumber +
                                    " AND p_partner_key_n=" + PartnerKey +
                                    "\n UNION\n" +
                                    " SELECT " +
                                    "a_ap_document_id_i as ApDocumentId, " +
                                    "a_ap_number_i as ApNum, " +
                                    "a_document_code_c as InvNum, " +
                                    "a_credit_note_flag_l as CreditNote, " +
                                    "'Invoice' as Type, " +
                                    "a_currency_code_c AS Currency, " +
                                    "a_total_amount_n as Amount, " +
                                    "a_total_amount_n AS OutstandingAmount, " +
                                    "a_document_status_c as Status, " +
                                    "a_discount_percentage_n as DiscountPercent, " +
                                    "a_discount_days_i as DiscountDays, " +
                                    "a_date_issued_d as Date " +
                                    "FROM PUB_a_ap_document " +
                                    "WHERE a_ledger_number_i=" + ledgerNumber + " " +
                                    "AND p_partner_key_n=" + PartnerKey + " " +
                                    "ORDER BY Date DESC";
                FPagedDataSetObject.FindParameters             = new TPagedDataSet.TAsyncFindParameters(SqlQuery);
                FPagedDataSetObject.FindParameters.FSearchName = "ATransactions";
            }
            else
            {
                if (!FSearchSupplierOrInvoice)
                {
                    String SqlQuery = "SELECT " +
                                      "PUB_a_ap_document.a_ap_number_i AS ApNumber, " +
                                      "PUB_a_ap_document.a_document_code_c AS DocumentCode, " +
                                      "PUB_p_partner.p_partner_short_name_c AS PartnerShortName, " +
                                      "PUB_a_ap_document.a_currency_code_c AS CurrencyCode, " +
                                      "PUB_a_ap_document.a_total_amount_n AS TotalAmount, " +
                                      "PUB_a_ap_document.a_total_amount_n AS OutstandingAmount, " +
                                      "PUB_a_ap_document.a_document_status_c AS DocumentStatus, " +
                                      "PUB_a_ap_document.a_date_issued_d AS DateIssued, " +
                                      "PUB_a_ap_document.a_date_issued_d AS DateDue, " +
                                      "PUB_a_ap_document.a_date_issued_d AS DateDiscountUntil, " +
                                      "PUB_a_ap_document.a_credit_terms_i AS CreditTerms, " +
                                      "PUB_a_ap_document.a_discount_percentage_n AS DiscountPercentage, " +
                                      "PUB_a_ap_document.a_discount_days_i AS DiscountDays, " +
                                      "'none' AS DiscountMsg, " +
                                      "false AS Selected, " +
                                      "PUB_a_ap_document.a_credit_note_flag_l AS CreditNoteFlag, " +
                                      "PUB_a_ap_document.a_ap_document_id_i AS ApDocumentId " +
                                      "FROM PUB_a_ap_document, PUB_a_ap_supplier, PUB_p_partner " +
                                      "WHERE PUB_a_ap_document.a_ledger_number_i=" + ledgerNumber + " " +
                                      "AND PUB_a_ap_document.a_document_status_c <> 'CANCELLED' " +
                                      "AND PUB_a_ap_document.a_document_status_c <> 'PAID' " +
                                      "AND PUB_a_ap_supplier.p_partner_key_n = PUB_p_partner.p_partner_key_n " +
                                      "AND PUB_a_ap_document.p_partner_key_n = PUB_p_partner.p_partner_key_n " +
                                      "ORDER BY PUB_a_ap_document.a_ap_number_i DESC";
                    FPagedDataSetObject.FindParameters             = new TPagedDataSet.TAsyncFindParameters(SqlQuery);
                    FPagedDataSetObject.FindParameters.FSearchName = "AInvoices";
                }
                else
                {
                    String SqlQuery = "SELECT " +
                                      "PUB_a_ap_supplier.p_partner_key_n AS PartnerKey, " +
                                      "PUB_p_partner.p_partner_short_name_c AS PartnerShortName, " +
                                      "PUB_a_ap_supplier.a_currency_code_c AS CurrencyCode, " +
                                      "PUB_p_partner.p_status_code_c AS StatusCode " +
                                      "FROM PUB_a_ap_supplier, PUB_p_partner " +
                                      "WHERE ";

                    if (((String)CriteriaRow["SupplierId"]).Length > 0)  // If the search box is empty, I'll not add this at all...
                    {
                        SqlQuery += String.Format("p_partner_short_name_c LIKE '{0}' AND ", (String)CriteriaRow["SupplierId"] + "%");
                    }

                    SqlQuery += "PUB_a_ap_supplier.p_partner_key_n = PUB_p_partner.p_partner_key_n " +
                                "ORDER BY PartnerShortName";

                    FPagedDataSetObject.FindParameters             = new TPagedDataSet.TAsyncFindParameters(SqlQuery);
                    FPagedDataSetObject.FindParameters.FSearchName = "ASuppliers";
                }
            }

            string session = TSession.GetSessionID();

            //
            // Start the Find Thread
            //
            try
            {
                ThreadStart myThreadStart = delegate {
                    FPagedDataSetObject.ExecuteQuery(session, "AP TFindUIConnector");
                };
                FFindThread      = new Thread(myThreadStart);
                FFindThread.Name = "APFind" + Guid.NewGuid().ToString();
                FFindThread.Start();
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #9
0
        /// <summary>
        /// Procedure to execute a Find query. Although the full query results are retrieved from the DB and stored
        /// internally in an object, data will be returned in 'pages' of data, each page holding a defined number
        /// of records.
        /// </summary>
        /// <param name="ACriteriaData">HashTable containing non-empty Find parameters.</param>
        public void PerformSearch(DataTable ACriteriaData)
        {
            String    CustomWhereCriteria;
            Hashtable ColumnNameMapping;

            OdbcParameter[] ParametersArray;
            String          FieldList;
            String          FromClause;
            String          WhereClause;

            System.Text.StringBuilder sb;
            TLogging.LogAtLevel(7, "TGLTransactionFind.PerformSearch called.");

            FPagedDataSetObject = new TPagedDataSet(new ATransactionTable());

            // Build WHERE criteria string based on AFindCriteria
            CustomWhereCriteria = BuildCustomWhereCriteria(ACriteriaData, out ParametersArray);

            //
            // Set up find parameters
            //
            ColumnNameMapping = new Hashtable();

            // Create Field List
            sb = new System.Text.StringBuilder();
            sb.AppendFormat("{0},{1}", "PUB_a_transaction.*", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_journal.a_journal_description_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_batch.a_batch_description_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_batch.a_batch_period_i", Environment.NewLine);
            sb.AppendFormat("{0}{1}", "PUB.a_batch.a_batch_year_i", Environment.NewLine);

            // short
            FieldList = sb.ToString();

            // Create FROM From Clause
            sb = new System.Text.StringBuilder();
            System.Text.StringBuilder sbWhereClause = new System.Text.StringBuilder();

            sb.AppendFormat("{0},{1}", "PUB_a_transaction", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB_a_journal", Environment.NewLine);
            sb.AppendFormat("{0}{1}", "PUB_a_batch", Environment.NewLine);

            sbWhereClause.AppendFormat("{0}{1}",
                                       "PUB_a_transaction.a_ledger_number_i = PUB_a_batch.a_ledger_number_i " +
                                       "AND PUB_a_transaction.a_batch_number_i = PUB_a_batch.a_batch_number_i " +
                                       "AND PUB_a_transaction.a_ledger_number_i = PUB_a_journal.a_ledger_number_i " +
                                       "AND PUB_a_transaction.a_batch_number_i = PUB_a_journal.a_batch_number_i " +
                                       "AND PUB_a_transaction.a_journal_number_i = PUB_a_journal.a_journal_number_i", Environment.NewLine);

            FromClause  = sb.ToString();
            WhereClause = CustomWhereCriteria;

            if (WhereClause.StartsWith(" AND") == true)
            {
                WhereClause = WhereClause.Substring(4);
            }

            if (sbWhereClause.ToString().Length > 0)
            {
                WhereClause += " AND " + sbWhereClause.ToString();
            }

            FPagedDataSetObject.FindParameters = new TPagedDataSet.TAsyncFindParameters(FieldList,
                                                                                        FromClause,
                                                                                        WhereClause,
                                                                                        "PUB_a_transaction.a_batch_number_i, PUB_a_transaction.a_journal_number_i, PUB_a_transaction.a_transaction_number_i",
                                                                                        ColumnNameMapping,
                                                                                        ParametersArray);

            string session = TSession.GetSessionID();

            //
            // Start the Find Thread
            //
            try
            {
                ThreadStart myThreadStart = delegate {
                    FPagedDataSetObject.ExecuteQuery(session, "GL Transaction Find");
                };
                FFindThread      = new Thread(myThreadStart);
                FFindThread.Name = "GLTransactionFind" + Guid.NewGuid().ToString();
                FFindThread.Start();
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #10
0
        /// <summary>
        /// run the report
        /// </summary>
        private static void Run(string AConfigFileName, string ASessionID, string AReportID, TRptDataCalculator ADatacalculator, TParameterList AParameterList)
        {
            // need to initialize the database session
            TSession.InitThread("Reporting Webconnector", AConfigFileName, ASessionID);

            TDataBase db = DBAccess.Connect("TReportGeneratorWebConnector");

            TDBTransaction Transaction  = new TDBTransaction();
            bool           Success      = false;
            bool           Submit       = true;
            string         HTMLOutput   = String.Empty;
            HtmlDocument   HTMLDocument = new HtmlDocument();
            string         ErrorMessage = String.Empty;

            try
            {
                db.ReadTransaction(ref Transaction,
                                   delegate
                {
                    Exception myException = null;
                    if (ADatacalculator.GenerateResult(ref AParameterList, ref HTMLOutput, out HTMLDocument, ref ErrorMessage, ref myException, Transaction))
                    {
                        Success = true;
                    }
                    else
                    {
                        TLogging.Log(ErrorMessage);
                    }
                });
            }
            catch (Exception Exc)
            {
                TLogging.Log("Problem calculating report: " + Exc.ToString());
                TLogging.Log(Exc.StackTrace, TLoggingType.ToLogfile);

                Success      = false;
                ErrorMessage = Exc.Message;
            }

/*
 *          if (TDBExceptionHelper.IsTransactionSerialisationException(FException))
 *          {
 *              // do nothing - we want this exception to bubble up
 *          }
 *          else if (FException is Exception && FException.InnerException is EOPDBException)
 *          {
 *              EOPDBException DbExc = (EOPDBException)FException.InnerException;
 *
 *              if (DbExc.InnerException is Exception)
 *              {
 *                  if (DbExc.InnerException is PostgresException)
 *                  {
 *                      PostgresException PgExc = (PostgresException)DbExc.InnerException;
 *
 *                      if (PgExc.SqlState == "57014") // SQL statement timeout problem
 *                      {
 *                          FErrorMessage = Catalog.GetString(
 *                              "Error - Database took too long to respond. Try different parameters to return fewer results.");
 *                      }
 *                  }
 *                  else
 *                  {
 *                      FErrorMessage = DbExc.InnerException.Message;
 *                  }
 *
 *                  FException = null;
 *              }
 *          }
 */

            try
            {
                // store the report result
                db.WriteTransaction(ref Transaction,
                                    ref Submit,
                                    delegate
                {
                    // delete report results that are expired.
                    string sql = "DELETE FROM PUB_s_report_result WHERE s_valid_until_d < NOW()";
                    db.ExecuteNonQuery(sql, Transaction);

                    // TODO: only keep maximum of 10 report results per user (s_created_by_c)

                    // store success, store parameter list, store html document
                    SReportResultTable table = new SReportResultTable();
                    SReportResultRow row     = table.NewRowTyped();
                    row.ReportId             = AReportID;
                    row.SessionId            = TSession.GetSessionID();
                    row.ValidUntil           = DateTime.Now.AddHours(12);
                    row.ParameterList        = AParameterList.ToJson();
                    row.ResultHtml           = HTMLOutput;
                    row.Success      = Success;
                    row.ErrorMessage = ErrorMessage;
                    table.Rows.Add(row);
                    SReportResultAccess.SubmitChanges(table, Transaction);
                    Submit = true;
                });
            }
            catch (Exception Exc)
            {
                TLogging.Log("Problem storing report result: " + Exc.ToString());
                TLogging.Log(Exc.StackTrace, TLoggingType.ToLogfile);

                Success      = false;
                ErrorMessage = Exc.Message;
            }

            db.CloseDBConnection();

            TProgressTracker.FinishJob(AReportID);
        }
예제 #11
0
        /// <summary>
        /// contructor
        /// </summary>
        /// <param name="ACriteriaData"></param>
        public TPartnerLocationFindUIConnector(DataTable ACriteriaData) : base()
        {
            Hashtable     ColumnNameMapping;
            String        CustomWhereCriteria;
            ArrayList     InternalParameters;
            OdbcParameter miParam;
            DataRow       CriteriaRow;

            FPagedDataSetObject = new TPagedDataSet(new PartnerFindTDSSearchResultTable());
            ColumnNameMapping   = null;

            // get the first and only row
            CriteriaRow = ACriteriaData.Rows[0];

            // used to help with strong typing of columns
            InternalParameters  = new ArrayList();
            CustomWhereCriteria = "";

            if (CriteriaRow["Addr1"].ToString().Length > 0)
            {
                new TDynamicSearchHelper(PLocationTable.TableId,
                                         PLocationTable.ColumnLocalityId, CriteriaRow, "Addr1", "Addr1Match", ref CustomWhereCriteria,
                                         ref InternalParameters);
            }

            if (CriteriaRow["Street2"].ToString().Length > 0)
            {
                new TDynamicSearchHelper(PLocationTable.TableId,
                                         PLocationTable.ColumnStreetNameId, CriteriaRow, "Street2", "Street2Match",
                                         ref CustomWhereCriteria,
                                         ref InternalParameters);
            }

            if (CriteriaRow["Addr3"].ToString().Length > 0)
            {
                new TDynamicSearchHelper(PLocationTable.TableId,
                                         PLocationTable.ColumnAddress3Id, CriteriaRow, "Addr3", "Addr3Match", ref CustomWhereCriteria,
                                         ref InternalParameters);
            }

            if (CriteriaRow["City"].ToString().Length > 0)
            {
                new TDynamicSearchHelper(PLocationTable.TableId,
                                         PLocationTable.ColumnCityId, CriteriaRow, "City", "CityMatch", ref CustomWhereCriteria,
                                         ref InternalParameters);
            }

            if (CriteriaRow["PostCode"].ToString().Length > 0)
            {
                new TDynamicSearchHelper(PLocationTable.TableId,
                                         PLocationTable.ColumnPostalCodeId, CriteriaRow, "PostCode", "PostCodeMatch",
                                         ref CustomWhereCriteria,
                                         ref InternalParameters);
            }

            if (CriteriaRow["County"].ToString().Length > 0)
            {
                new TDynamicSearchHelper(PLocationTable.TableId,
                                         PLocationTable.ColumnCountyId, CriteriaRow, "County", "CountyMatch", ref CustomWhereCriteria,
                                         ref InternalParameters);
            }

            if (CriteriaRow["Country"].ToString().Length > 0)
            {
                new TDynamicSearchHelper(PLocationTable.TableId,
                                         PLocationTable.ColumnCountryCodeId, CriteriaRow, "Country", "CountryMatch",
                                         ref CustomWhereCriteria,
                                         ref InternalParameters);
            }

            if (CriteriaRow["LocationKey"].ToString().Length > 0)
            {
                // DISREGARD ALL OTHER SEARCH CRITERIA!!!
                CustomWhereCriteria = "";
                InternalParameters  = new ArrayList();

                CustomWhereCriteria = String.Format("{0} AND PUB.{1}.{2} = ?", CustomWhereCriteria,
                                                    PLocationTable.GetTableDBName(), PLocationTable.GetLocationKeyDBName());

                miParam            = new OdbcParameter("", OdbcType.Decimal, 10);
                miParam.Value      = (object)CriteriaRow["LocationKey"];
                InternalParameters = new ArrayList();
                InternalParameters.Add(miParam);
            }

            Console.WriteLine("WHERE CLAUSE: " + CustomWhereCriteria);
            FPagedDataSetObject.FindParameters = new TPagedDataSet.TAsyncFindParameters(
                " p_city_c, p_postal_code_c,  p_locality_c, p_street_name_c, p_address_3_c, p_county_c, p_country_code_c, p_location_key_i, p_site_key_n ",
                "PUB_p_location ",
                " p_location_key_i<>-1 " + CustomWhereCriteria + ' ',
                "p_city_c ",
                ColumnNameMapping,
                ((OdbcParameter[])(InternalParameters.ToArray(typeof(OdbcParameter)))));

            // fields
            // table
            // where
            // order by
            // both empty for now

            string session = TSession.GetSessionID();

            //
            // Start the Find Thread
            //
            try
            {
                ThreadStart myThreadStart = delegate {
                    FPagedDataSetObject.ExecuteQuery(session);
                };
                FFindThread      = new Thread(myThreadStart);
                FFindThread.Name = "PartnerLocationFind" + Guid.NewGuid().ToString();
                FFindThread.Start();
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #12
0
        /// <summary>
        /// Procedure to execute a Find query. Although the full query results are retrieved from the DB and stored
        /// internally in an object, data will be returned in 'pages' of data, each page holding a defined number
        /// of records.
        /// </summary>
        /// <param name="ACriteriaData">HashTable containing non-empty Find parameters.</param>
        public void PerformSearch(DataTable ACriteriaData)
        {
            String    CustomWhereCriteria;
            Hashtable ColumnNameMapping;

            OdbcParameter[] ParametersArray;
            String          FieldList;
            String          FromClause;
            String          WhereClause;

            System.Text.StringBuilder sb;
            TLogging.LogAtLevel(7, "TGiftDetailFind.PerformSearch called.");

            FPagedDataSetObject = new TPagedDataSet(new GiftBatchTDSAGiftDetailTable());

            // Build WHERE criteria string based on AFindCriteria
            CustomWhereCriteria = BuildCustomWhereCriteria(ACriteriaData, out ParametersArray);

            //
            // Set up find parameters
            //
            ColumnNameMapping = new Hashtable();

            // Create Field List
            sb = new System.Text.StringBuilder();
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_batch_number_i", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_gift_transaction_number_i", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_detail_number_i", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_confidential_gift_flag_l", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_gift_amount_n", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift.a_receipt_number_i", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "DonorPartner.p_partner_short_name_c DonorPartnerShortName", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "RecipientPartner.p_partner_short_name_c RecipientPartnerShortName", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_motivation_group_code_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_motivation_detail_code_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift.a_date_entered_d", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_cost_centre_code_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_gift_comment_one_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_gift_comment_two_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail.a_gift_comment_three_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_batch.a_batch_status_c", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_batch.a_batch_period_i", Environment.NewLine);
            sb.AppendFormat("{0}{1}", "PUB.a_gift_batch.a_batch_year_i", Environment.NewLine);

            // short
            FieldList = sb.ToString();

            // Create FROM From Clause
            sb = new System.Text.StringBuilder();
            System.Text.StringBuilder sbWhereClause = new System.Text.StringBuilder();

            sb.AppendFormat("{0},{1}", "PUB.a_gift_detail", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.a_gift_batch", Environment.NewLine);
            sb.AppendFormat("{0},{1}", "PUB.p_partner DonorPartner", Environment.NewLine);
            sb.AppendFormat("{0}{1}", "PUB.p_partner RecipientPartner", Environment.NewLine);
            sbWhereClause.AppendFormat("{0}{1}",
                                       "DonorPartner.p_partner_key_n = PUB.a_gift.p_donor_key_n " +
                                       "AND RecipientPartner.p_partner_key_n = PUB.a_gift_detail.p_recipient_key_n " +
                                       "AND PUB.a_gift.a_ledger_number_i = PUB.a_gift_detail.a_ledger_number_i " +
                                       "AND PUB.a_gift.a_batch_number_i = PUB.a_gift_detail.a_batch_number_i " +
                                       "AND PUB.a_gift.a_gift_transaction_number_i = PUB.a_gift_detail.a_gift_transaction_number_i " +
                                       "AND PUB.a_gift_batch.a_ledger_number_i = PUB.a_gift_detail.a_ledger_number_i " +
                                       "AND PUB.a_gift_batch.a_batch_number_i = PUB.a_gift_detail.a_batch_number_i", Environment.NewLine);

            FromClause  = sb.ToString();
            WhereClause = CustomWhereCriteria;

            if (WhereClause.StartsWith(" AND") == true)
            {
                WhereClause = WhereClause.Substring(4);
            }

            if (sbWhereClause.ToString().Length > 0)
            {
                WhereClause += " AND " + sbWhereClause.ToString();
            }

            FPagedDataSetObject.FindParameters = new TPagedDataSet.TAsyncFindParameters(FieldList,
                                                                                        FromClause,
                                                                                        WhereClause,
                                                                                        "PUB.a_gift_detail.a_batch_number_i, PUB.a_gift_detail.a_gift_transaction_number_i, PUB.a_gift_detail.a_detail_number_i",
                                                                                        ColumnNameMapping,
                                                                                        ParametersArray);

            string session        = TSession.GetSessionID();
            string configfilename = TAppSettingsManager.ConfigFileName;

            //
            // Start the Find Thread
            //
            try
            {
                ThreadStart myThreadStart = delegate {
                    FPagedDataSetObject.ExecuteQuery(configfilename, session, "Gift Detail Find");
                };
                FFindThread      = new Thread(myThreadStart);
                FFindThread.Name = "GiftDetailFind" + Guid.NewGuid().ToString();
                FFindThread.Start();
            }
            catch (Exception)
            {
                throw;
            }
        }