Пример #1
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <LoginOptions, WithdrawOptions, InstantTransferOptions, DelayedTransferOptions,
                                           PermanentTransferOptions, CreateSavingsAccountOptions, DeleteSavingsAccountOptions, InfoSavingAccountsOptions,
                                           InfoCurrentAccountsOptions, CreateClientOptions, DeleteClientOptions, ModifyPasssOptions, InfoUserOptions,
                                           InfoTransactionOptions, ExportOptions, AddDonatorsOptions>(args)
            .WithParsed <LoginOptions>(RunLoginUser)
            .WithParsed <WithdrawOptions>(RunWithdrawOptions)
            .WithParsed <InstantTransferOptions>(RunInstantTransferOptions)
            .WithParsed <DelayedTransferOptions>(RunDelayedTransferOptions)
            .WithParsed <PermanentTransferOptions>(RunPermanentTransferOptions)

            .WithParsed <CreateClientOptions>(RunCreateClientOptions)
            .WithParsed <DeleteClientOptions>(RunDeleteClientOptions)
            .WithParsed <ModifyPasssOptions>(RunModifyPassOptions)
            .WithParsed <CreateSavingsAccountOptions>(RunCreateSavingsAccountOptions)
            .WithParsed <DeleteSavingsAccountOptions>(RunDeleteSavingsAccountOptions)
            .WithParsed <InfoSavingAccountsOptions>(RunSavingAccountsInfoOptions)
            .WithParsed <InfoCurrentAccountsOptions>(RunCurrentAccountsInfoOptions)
            .WithParsed <InfoUserOptions>(RunInfoUserOptions)
            .WithParsed <InfoTransactionOptions>(RunInfoTransactionOptions)
            .WithParsed <ExportOptions>(RunExportOptions)
            .WithParsed <AddDonatorsOptions>(RunAddDonatorOptions);

            ConnectionDB.GetConnectionString();
        }
Пример #2
0
        public static void ExportCSVFile(string exportPath)
        {
            string        queryString = GetTransactions();
            SqlConnection connection  = new SqlConnection(ConnectionDB.GetConnectionString());

            connection.Open();

            Random randomNumber = new Random();
            int    a            = randomNumber.Next(1, int.MaxValue);

            string exportCsv = $"exportFileDB{a}.csv";

            if (Directory.Exists(exportPath))
            {
                try
                {
                    SqlCommand command = new SqlCommand(queryString, connection);

                    SqlDataReader reader = command.ExecuteReader();

                    StreamWriter csvFile = new StreamWriter(@exportPath + "\\" + exportCsv);

                    object[] output = new object[reader.FieldCount];

                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        output[i] = reader.GetName(i);
                    }

                    csvFile.WriteLine(string.Join(", ", output));


                    while (reader.Read())
                    {
                        reader.GetValues(output);
                        csvFile.WriteLine(string.Join(", ", output));
                    }
                    Console.WriteLine("Data export successful.");

                    csvFile.Close();
                    reader.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Data export unsuccessful." + e);
                    Environment.Exit(0);
                }
            }
            else
            {
                Console.WriteLine("File path does not exist.");
            }
            connection.Close();
        }