Ejemplo n.º 1
0
        }         // Name

        public override void Execute()
        {
            this.loanSources.Clear();
            this.crLoans.Clear();
            this.defaultCustomers.Clear();

            DB.ForEachRowSafe(
                srdc => defaultCustomers.Add(srdc["CustomerID"]),
                "LoadDefaultCustomers",
                CommandSpecies.StoredProcedure
                );

            DB.ForEachResult <LoanMetaData>(
                lmd => {
                if (this.crLoans.ContainsKey(lmd.CashRequestID))
                {
                    this.crLoans[lmd.CashRequestID].Add(lmd);
                }
                else
                {
                    this.crLoans[lmd.CashRequestID] = new List <LoanMetaData> {
                        lmd
                    }
                };

                this.loanSources.Add(lmd.LoanSourceName);
            },
                "LoadAllLoansMetaData",
                CommandSpecies.StoredProcedure
                );

            string top = (topCount > 0) ? "TOP " + topCount : string.Empty;

            string condition = (lastCheckedID > 0)
                                ? "AND r.Id < " + lastCheckedID
                                : string.Empty;

            this.data.Clear();

            DB.ForEachRowSafe(
                ProcessRow,
                string.Format(QueryTemplate, top, condition),
                CommandSpecies.Text
                );

            var pc = new ProgressCounter("{0} cash requests processed.", Log, 50);

            foreach (Datum d in this.data)
            {
                d.IsDefault = defaultCustomers.Contains(d.CustomerID);
                bool isHomeOwner = IsHomeOwner(d.CustomerID);

                d.CheckAutoReject(DB, Log);

                d.AutoThen.Calculate(d.CustomerID, isHomeOwner, DB, Log);
                d.AutoNow.Calculate(d.CustomerID, isHomeOwner, DB, Log);

                pc++;
            }             // for

            pc.Log();

            var lst = new List <string>();

            Log.Debug("Output data - begin:");

            foreach (Datum d in this.data)
            {
                Log.Debug("{0}", d);

                lst.Add(d.ToCsv(crLoans, loanSources));
            }             // for each

            Log.Debug("Output data - end.");

            Log.Debug(
                "\n\nCSV output - begin:\n{0}\n{1}\nCSV output - end.\n",
                Datum.CsvTitles(loanSources),
                string.Join("\n", lst)
                );
        }         // Execute