Beispiel #1
0
        /// <summary>
        /// Export the accounts
        /// </summary>
        public static void ExportAccounts(string AOutputPath,
                                          char ACSVSeparator,
                                          string ANewLine,
                                          Int32 ALedgerNumber,
                                          List <string> AAccounts)
        {
            string filename = Path.GetFullPath(Path.Combine(AOutputPath, "account.csv"));

            Console.WriteLine("Writing file: " + filename);

            // only export accounts that are actually used with these cost centres
            string sql =
                String.Format("SELECT {0}, {1}, {2} from PUB_{3} WHERE {4} = {5} AND " +
                              " {6}=true ORDER BY {0}",
                              AAccountTable.GetAccountCodeDBName(),
                              AAccountTable.GetAccountCodeLongDescDBName(),
                              AAccountTable.GetDebitCreditIndicatorDBName(),
                              AAccountTable.GetTableDBName(),
                              AAccountTable.GetLedgerNumberDBName(),
                              ALedgerNumber,
                              AAccountTable.GetPostingStatusDBName());

            TDBTransaction Transaction = null;
            DataTable      accounts    = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                                                           delegate
            {
                accounts = DBAccess.GDBAccessObj.SelectDT(sql, "accounts", Transaction);
            });

            StringBuilder sb = new StringBuilder();

            if (accounts != null)
            {
                foreach (DataRow row in accounts.Rows)
                {
                    if (AAccounts.Contains(row[0].ToString()))
                    {
                        sb.Append(StringHelper.StrMerge(new string[] { row[0].ToString(), row[1].ToString(),
                                                                       Convert.ToBoolean(row[2]) ? "Soll" : "Haben" }, ACSVSeparator));
                        sb.Append(ANewLine);
                    }
                }
            }

            StreamWriter sw = new StreamWriter(filename, false, Encoding.GetEncoding(1252));

            sw.Write(sb.ToString());
            sw.Close();
        }