static public void SQLiteOutputTransactionsInCSV(List <MSTransaction> trList)
        {
            //MSTransaction to CSV file
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendLine("MSTransactionId, MSIO, MSValue, MSCurrencyCode, MSAccountId, MSCategoryId, MSNote, MSDateTime, MSMulticurrency");
            foreach (var tr in trList)
            {
                sb.AppendLine($"{tr.MSTransactionId}," +
                              $"{tr.MSIO}," +
                              $"{tr.MSValue}," +
                              $"{tr.MSCurrencyCode}," +
                              $"{MSAccount.GetName(tr.MSAccountId)}," +
                              $"{MSCategory.GetName(tr.MSCategoryId)}," +
                              $"{tr.MSNote}," +
                              $"{tr.MSDateTime}," +
                              $"{tr.MSMulticurrency}");
            }

            //Console.WriteLine(sb.ToString());

            System.IO.File.WriteAllText(
                System.IO.Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory, "Transaction.csv"),
                sb.ToString());
        }
示例#2
0
 public MSAccount(MSAccount account)
 {
     MSAccountId     = account.MSAccountId;
     MSIO            = account.MSIO;
     MSName          = account.MSName;
     MSColor         = account.MSColor;
     MSImage         = account.MSImage;
     MSCurrencyCode  = account.MSCurrencyCode;
     MSMulticurrency = account.MSMulticurrency;
 }
示例#3
0
 private static void AddAccount()
 {
     int tAccId = accounts.Count;
     do
     {
         tAccId++;
         if (!(accounts.Exists(x => x.MSAccountId == tAccId)))
         {
             account.ConsoleAdd(tAccId, transactionSymbol);
             break;
         }
     } while (true);
     accounts.Add(new MSAccount(account));
     MSAccount.SQLiteInsertAccountInDatabase(account);
     Console.WriteLine("Аккаунт добавлен.");
     Program.cki = Console.ReadKey();
 }
        static public void ShowAllTransaction(List <MSTransaction> trList)
        {
            int maxWidth = 80;

            Console.SetWindowSize(maxWidth, 25);
            foreach (var tr in trList)
            {
                Console.WriteLine($"{tr.MSTransactionId}," +
                                  $"{tr.MSIO}," +
                                  $"{tr.MSValue}," +
                                  $"{tr.MSCurrencyCode}," +
                                  $"{MSAccount.GetName(tr.MSAccountId)}," +
                                  $"{MSCategory.GetName(tr.MSCategoryId)}," +
                                  $"{tr.MSNote}," +
                                  $"{tr.MSDateTime}," +
                                  $"{tr.MSMulticurrency}\n");
            }
        }
示例#5
0
        public void ConsoleAdd(int categoryId, char msIO, int left = 0)
        {
            left = Console.CursorLeft;
            int top = Console.CursorTop;

            MSCategoryId = categoryId;

            if (msIO == '+' | msIO == '-')
            {
                MSIO = msIO;
            }
            else
            {
                bool xreplace = true;
                do
                {
                    Console.SetCursorPosition(left, top);
                    Console.WriteLine("Введите тип категории (+,-): ");
                    string temp = Console.ReadLine();
                    if (temp[0] == '+' | temp[0] == '-')
                    {
                        MSIO     = temp[0];
                        xreplace = false;
                    }
                } while (xreplace);
            }

            Console.WriteLine("Введите наименование категории: ");
            MSName = Console.ReadLine();
            Console.WriteLine("Выберите аккаунт: ");
            if (Program.accounts.Count > 0)
            {
                MSAccountId = MSAccount.ChooseAccount(ref Program.accounts);
            }
            else
            {
                Program.account.ConsoleAdd(Program.accounts.Count + 1, '+');
                Program.accounts.Add(Program.account);
            }
            Console.WriteLine("Выберите цвет категории: ");
            MSColor = MSIntro.ChooseColor();
            Console.WriteLine("Введите символ категории: ");
            MSImage = Console.ReadLine();
        }
        public static void Show(ref List <MSAccount> accounts,
                                ref List <MSCategory> categories,
                                ref List <MSTransaction> transactions)
        {
            int left = Console.CursorLeft;
            int top  = Console.CursorTop;

            Dictionary <string, float> sumAccount = new Dictionary <string, float>();
            var transactions_grouped = transactions.GroupBy(x => x.MSAccountId)
                                       .Select(g => new
            {
                Id  = g.Key,
                Sum = g.Sum(x => x.MSValue)
            });

            foreach (var item in transactions_grouped)
            {
                //sumAccount.Add(MSAccount.GetName(item.Id), item.Sum);
                Console.Write($"{MSAccount.GetName(item.Id)} {item.Sum:f2}\n");
            }
            //foreach (var item_ac in accounts)
            //{
            //    Console.Write($"{item_ac.MSName} {sumAccount[item_ac.MSName]}");
            //}

            //Dictionary<string, Dictionary<string, float>> sumCategory = new Dictionary<string, Dictionary<string, float>>();
            //var category_grouped = transactions.GroupBy(x => new { x.MSAccountId, x.MSCategoryId }, (key, group) => new
            //{
            //    Key1 = key.MSAccountId,
            //    Key2 = key.MSCategoryId,
            //    Sum = group.Sum(x => x.MSValue)
            //});
            //foreach (var item in category_grouped)
            //{
            //    if (item == )
            //    Dictionary<string, float> tete = new Dictionary<string, float>();
            //    sumCategory.Add(MSCategory.GetName(item.Key1), );
            //}
        }
示例#7
0
        static public void SQLiteInsertAccountInDatabase(MSAccount a)
        {
            Program.conn.Open();
            int    tbool       = a.MSMulticurrency == true ? 1 : 0;
            string sql_command = "INSERT INTO MSAccounts (MSAccountId, " +
                                 "MSIO,     " +
                                 "MSName, " +
                                 "MSColor, " +
                                 "MSImage, " +
                                 "MSCurrencyCode, " +
                                 "MSMulticurrency) "
                                 + $"VALUES ({a.MSAccountId}, " +
                                 $"'{a.MSIO}'," +
                                 $"'{a.MSName}'," +
                                 $" {(int)a.MSColor}, " +
                                 $"'{a.MSImage}'," +
                                 $"'{a.MSCurrencyCode}'," +
                                 $" {tbool});";

            System.Data.SQLite.SQLiteCommand command = new System.Data.SQLite.SQLiteCommand(sql_command, Program.conn);
            command.ExecuteNonQuery();
            Program.conn.Close();
        }
        public void ConsoleAdd(int msTransactionId, char msIO)
        {
            int left = Console.CursorLeft;
            int top  = Console.CursorTop;

            MSTransactionId = msTransactionId;
            //bool xreplace = true;
            //do
            //{
            //    Console.SetCursorPosition(left, top);
            //    Console.WriteLine("Введите тип транзакции (+,-): ");
            //    string temp = Console.ReadLine();
            //    if (temp[0] == '+' | temp[0] == '-')
            //    {
            //        MSIO = temp[0];
            MSIO = msIO;
            //        xreplace = false;
            //    }
            //} while (xreplace);

            string insertSumm = "Введите значение (сумма): ";

            Console.WriteLine(insertSumm);
            left = Console.CursorLeft;
            top  = Console.CursorTop;
            //string tReadLine = "";
            do
            {
                Console.SetCursorPosition(left, top);
                if (MSValue > 0)
                {
                    string str = Convert.ToString(MSValue);
                    for (int i = 0; i < str.Length; i++)
                    {
                        Console.WriteLine(" ");
                    }
                }
                Console.SetCursorPosition(left, top);
                //    tReadLine = Console.ReadLine();
                //    float.TryParse(tReadLine, out float tMSValue);
                //    MSValue = tMSValue;
                MSValue = Program.MSReadDouble();
            } while (!(MSValue > 0));
            if (MSIO == '+')
            {
                if (MSValue < 0)
                {
                    MSValue *= -1;
                }
            }
            else if (MSIO == '-')
            {
                if (MSValue > 0)
                {
                    MSValue *= -1;
                }
            }
            Console.SetCursorPosition(insertSumm.Length + 1, top - 1);
            Console.WriteLine($"{MSValue:f2}");
            Program.cki = default(ConsoleKeyInfo);

            Console.WriteLine("Выберите тип валюты: ");
            MSCurrencyCode = MSCurrency.ChooseCurrency(ref Program.currencies);

            Console.WriteLine("Выберите аккаунт: ");
            if (Program.accounts.Count > 0)
            {
                MSAccountId = MSAccount.ChooseAccount(ref Program.accounts);
            }

            Console.WriteLine("Выберите категорию: ");
            if (Program.categories.Count > 0)
            {
                MSCategoryId = MSCategory.ChooseCategory(ref Program.categories, MSAccountId);
            }

            Console.WriteLine("Введите заметку: ");
            MSNote = Console.ReadLine();
            if (MSNote.Length == 0)
            {
                MSNote = " ";
            }

            Console.WriteLine("Введите дату и время\n(DD.MM.YYYY hh.mm.ss): "); Console.Write($" {Program.msCompDateTime()}");
            int xtop = Console.CursorTop;

            Console.SetCursorPosition(0, xtop + 1);
            string tDateTime = Console.ReadLine();

            if (tDateTime.Length == 0 | tDateTime == " ")
            {
                MSDateTime = Program.msCompDateTime();
            }
            else
            {
                MSDateTime = DateTime.Parse(tDateTime);
            }
            if (MSCurrencyCode == "ALL")
            {
                MSMulticurrency = true;
            }
            else
            {
                MSMulticurrency = false;
            }
            Program.cki = default(ConsoleKeyInfo);
            Console.Clear();
        }
        public static void ConsoleTransfer(ref List <MSTransaction> transactions, int msTransactionId)
        {
            int           tAccount2      = 0;
            MSTransaction tMSTransaction = new MSTransaction();
            int           left           = Console.CursorLeft;
            int           top            = Console.CursorTop;

            tMSTransaction.MSTransactionId = msTransactionId;

            tMSTransaction.MSIO = '-';

            string insertSumm = "Введите значение (сумма): ";

            Console.WriteLine(insertSumm);
            left = Console.CursorLeft;
            top  = Console.CursorTop;
            do
            {
                Console.SetCursorPosition(left, top);
                if (Convert.ToString(tMSTransaction.MSValue).Length > 0)
                {
                    for (int i = 0; i < Convert.ToString(tMSTransaction.MSValue).Length; i++)
                    {
                        Console.WriteLine(" ");
                    }
                }
                Console.SetCursorPosition(left, top);
                tMSTransaction.MSValue = Program.MSReadDouble();
            } while (!(tMSTransaction.MSValue > 0));
            if (tMSTransaction.MSIO == '+')
            {
                if (tMSTransaction.MSValue < 0)
                {
                    tMSTransaction.MSValue *= -1;
                }
            }
            else if (tMSTransaction.MSIO == '-')
            {
                if (tMSTransaction.MSValue > 0)
                {
                    tMSTransaction.MSValue *= -1;
                }
            }
            Console.SetCursorPosition(insertSumm.Length + 1, top - 1);
            Console.WriteLine($"{tMSTransaction.MSValue:f2}");
            Program.cki = default(ConsoleKeyInfo);

            Console.WriteLine("Выберите аккаунт вывода суммы: "); //1
            if (Program.accounts.Count > 0)
            {
                tMSTransaction.MSAccountId = MSAccount.ChooseAccount(ref Program.accounts);
            }

            left = Console.CursorLeft;
            top  = Console.CursorTop;
            bool xreplace = true;

            do
            {
                Console.SetCursorPosition(left, top);
                Console.WriteLine("Выберите тип валюты: ");
                string tMSCurrencyCode = MSCurrency.ChooseCurrency(ref Program.currencies);

                if (tMSCurrencyCode != "ALL")
                {
                    tMSTransaction.MSCurrencyCode = tMSCurrencyCode;
                    xreplace = false;
                }
            } while (xreplace);

            Console.WriteLine("Выберите аккаунт ввода суммы: "); //2
            if (Program.accounts.Count > 0)
            {
                tAccount2 = MSAccount.ChooseAccount(ref Program.accounts);
            }

            Console.WriteLine("Введите заметку: ");
            tMSTransaction.MSNote = Console.ReadLine();
            if (tMSTransaction.MSNote.Length == 0)
            {
                tMSTransaction.MSNote = " ";
            }

            Console.WriteLine("Введите дату и время\n(DD.MM.YYYY hh.mm.ss): ");
            Console.Write($" {Program.msCompDateTime()}");
            int xtop = Console.CursorTop;

            Console.SetCursorPosition(0, xtop + 1);
            string tDateTime = Console.ReadLine();

            if (tDateTime.Length == 0 | tDateTime == " ")
            {
                tMSTransaction.MSDateTime = Program.msCompDateTime();
            }
            else
            {
                tMSTransaction.MSDateTime = DateTime.Parse(tDateTime);
            }

            transactions.Add(new MSTransaction(tMSTransaction));
            MSTransaction.SQLiteInsertTransactionInDatabase(tMSTransaction);

            tMSTransaction.MSIO = '+';

            tMSTransaction.MSAccountId = tAccount2;

            if (tMSTransaction.MSIO == '+')
            {
                if (tMSTransaction.MSValue < 0)
                {
                    tMSTransaction.MSValue *= -1;
                }
            }
            else if (tMSTransaction.MSIO == '-')
            {
                if (tMSTransaction.MSValue > 0)
                {
                    tMSTransaction.MSValue *= -1;
                }
            }

            transactions.Add(new MSTransaction(tMSTransaction));
            MSTransaction.SQLiteInsertTransactionInDatabase(tMSTransaction);

            Program.cki = default(ConsoleKeyInfo);
            Console.Clear();
        }
示例#10
0
        static void MSMainMenyu()
        {
            Console.Clear();
            maxWidth = 40; maxheight = 25;
            Console.SetWindowSize(maxWidth, maxheight);
            Console.SetBufferSize(maxWidth, maxheight);
            
            bool xreplace = true;
            int i = 0;
            do
            {
                string str = "Добро пожаловать!";
                if (i >= maxWidth - str.Length)
                {
                    Console.SetCursorPosition(maxWidth - str.Length,0);
                    for (int j = 0; j < str.Length; j++)
                    {
                        Console.Write(" ");
                    }
                    i = 0;
                } 
                
                Console.SetCursorPosition(i - 1 < 0 ? i >= maxWidth-str.Length ? 0 : 0 : i - 1, 0);
                Console.Write("                  ");
                Console.SetCursorPosition(i++ < maxWidth - str.Length ? i : 0, 0);
                Console.Write(str);
                Thread.Sleep(333);
                
                if (Console.KeyAvailable)
                {
                    cki = Console.ReadKey();
                }
                Console.SetCursorPosition(0, 3);

                Console.SetCursorPosition(0, 1);
                Console.WriteLine($"1. {dictionary["newaccount"].RetLang(staticLanguage)} ");
                Console.SetCursorPosition(0, 2);
                Console.WriteLine($"2. {dictionary["newcategory"].RetLang(staticLanguage)} ");

                switch (cki.KeyChar)
                {
                    case '1':
                        Console.Clear();
                        AddAccount();
                        cki = default(ConsoleKeyInfo);
                        MSMainMenyu();
                        break;
                    case '2':
                        Console.Clear();
                        AddCategory();
                        cki = default(ConsoleKeyInfo);
                        MSMainMenyu();
                        break;
                    default:
                        break;
                }

                switch (cki.Key)
                {
                    case ConsoleKey.Tab:
                        if (++menyuId > maxMenyuId-1) menyuId = 0;
                        break;
                    case ConsoleKey.RightArrow:
                        if (++menyuId > maxMenyuId-1) menyuId = maxMenyuId-1;
                        break;
                    case ConsoleKey.LeftArrow:
                        if (--menyuId < 0) menyuId = 0;
                        break;
                    case ConsoleKey.DownArrow:
                        if (++menyuId > maxMenyuId-1) menyuId = maxMenyuId-1;
                        break;
                    case ConsoleKey.UpArrow:
                        if (--menyuId < 0) menyuId = 0;
                        break;
                    case ConsoleKey.Enter:
                        Program.cki = default(ConsoleKeyInfo);
                        Console.Clear();
                        int tTranCount = 0;
                        switch (menyuId)
                        {
                            case 0: //+
                                transactionSymbol = '+';
                                if (accounts.Count == 0)
                                {
                                    Console.WriteLine("В базе не найдены счёта.");
                                    Console.WriteLine("Создайте новый счёт.");
                                    Program.AddAccount();
                                }
                                if (categories.Count == 0)
                                {
                                    Console.WriteLine("В базе не найдены котегории.");
                                    Console.WriteLine("Создайте новую котегорию.");
                                    Program.AddCategory();
                                }
                                tTranCount = transactions.Count;
                                bool xReplaceTrCount = true;
                                do
                                {
                                    tTranCount++;
                                    if (!transactions.Exists(x => x.MSTransactionId == tTranCount))
                                    {
                                        xReplaceTrCount = false;
                                        transaction.ConsoleAdd(tTranCount, transactionSymbol);
                                    }
                                } while (xReplaceTrCount);
                                transactions.Add(new MSTransaction(transaction));
                                MSTransaction.SQLiteInsertTransactionInDatabase(transaction);
                                goto case 99;
                                //break;
                            case 1: //-
                                transactionSymbol = '-';
                                if (accounts.Count == 0)
                                {
                                    Console.WriteLine("В базе не найдены счёта.");
                                    Console.WriteLine("Создайте новый счёт.");
                                    Program.AddAccount();
                                }
                                if (categories.Count == 0)
                                {
                                    Console.WriteLine("В базе не найдены котегории.");
                                    Console.WriteLine("Создайте новую котегорию.");
                                    Program.AddCategory();
                                }
                                tTranCount = transactions.Count;
                                do
                                {
                                    tTranCount++;
                                    transaction.ConsoleAdd(tTranCount, transactionSymbol);
                                } while (transactions.Exists(x => x.MSTransactionId == tTranCount));
                                transactions.Add(new MSTransaction(transaction));
                                MSTransaction.SQLiteInsertTransactionInDatabase(transaction);
                                goto case 99;
                                //break;
                            case 2: //=
                                transactionSymbol = '=';
                                if (accounts.Count < 2)
                                {
                                    Console.WriteLine("В базе не достаточно счётов.");
                                    Console.WriteLine("Создайте новый счёт.");
                                    Program.AddAccount();
                                }
                                if (categories.Count == 0)
                                {
                                    Console.WriteLine("В базе не найдены котегории.");
                                    Console.WriteLine("Создайте новую котегорию.");
                                    Program.AddCategory();
                                }
                                MSTransaction.ConsoleTransfer(ref transactions, categories.Count + 1);
                                goto case 99;
                                //break;
                            case 3: //param
                                transactionSymbol = '=';
                                bool xReplace = true;
                                do
                                {
                                    Console.Clear();
                                    Console.WriteLine($"1. {dictionary["newaccount"].RetLang(staticLanguage)} ");
                                    Console.WriteLine($"2. {dictionary["newcategory"].RetLang(staticLanguage)} ");
                                    Console.WriteLine($"3. Выберите язык программы: ");
                                    Console.WriteLine($"4. Сброс базы данных: ");
                                    Console.WriteLine($"5. Выгрузка в CSV файл: ");
                                    Console.WriteLine($"6. Просмотреть все транзакции: ");
                                    Console.WriteLine($"7. Назад: ");
                                    
                                    cki = Console.ReadKey();
                                    //Console.WriteLine($"2. {dictionary["newcategory"].RetLang(staticLanguage)} ");
                                    switch (cki.KeyChar)
                                    {
                                        case '1':
                                            Console.Clear();
                                            Console.WriteLine($"1. {dictionary["newaccount"].RetLang(staticLanguage)} ");
                                            Program.AddAccount();
                                            break;
                                        case '2':
                                            Console.Clear();
                                            Console.WriteLine($"2. {dictionary["newcategory"].RetLang(staticLanguage)} ");
                                            Program.AddCategory();
                                            break;
                                        case '3':
                                            Console.Write($"3. Выберите язык программы: ");
                                            staticLanguage = MSLanguage.ChooseLanguage();
                                            Console.WriteLine("Язык изменён.");
                                            Program.cki = Console.ReadKey();
                                            break;
                                        case '4':
                                            Console.WriteLine($"4. Сброс базы данных: ");
                                            MSSaveLoad.CreateDatabase();
                                            MSSaveLoad.InsertStandartValue();
                                            currency = new MSCurrency();
                                            currencies = new List<MSCurrency>();
                                            account = new MSAccount();
                                            accounts = new List<MSAccount>();
                                            category = new MSCategory();
                                            categories = new List<MSCategory>();
                                            transaction = new MSTransaction();
                                            transactions = new List<MSTransaction>();
                                            break;
                                        case '5':
                                            Console.WriteLine($"5. Выгрузка в CSV файл: ");
                                            MSTransaction.SQLiteOutputTransactionsInCSV(transactions);
                                            break;
                                        case '6':
                                            Console.WriteLine($"6. Просмотреть все транзакции: ");
                                            Console.Clear();
                                            MSTransaction.ShowAllTransaction(transactions);
                                            Console.ReadKey();
                                            Console.Clear();
                                            break;
                                        case '7':
                                            xReplace = false;
                                            break;
                                        default:
                                            break;
                                    }
                                    cki = default(ConsoleKeyInfo);
                                } while (xReplace);
                                Console.Clear();
                                break;
                            case 4: //help
                                maxWidth = 80; maxheight = 25;
                                Console.SetWindowSize(maxWidth, maxheight);
                                Console.SetBufferSize(maxWidth, maxheight);
                                Console.WriteLine(">> Money Supervisor << предназначена для ведения записей о Ваших доходах и расходах");
                                MSIntro.Show();
                                Console.Clear();
                                maxWidth = 40; maxheight = 25;
                                Console.SetWindowSize(maxWidth, maxheight);
                                Console.SetBufferSize(maxWidth, maxheight);
                                break;
                            case 99:
                                Console.WriteLine("Информация добавлена.");
                                Program.cki = Console.ReadKey();
                                Program.cki = default(ConsoleKeyInfo);
                                Console.Clear();
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
                
                cki = default(ConsoleKeyInfo);

                MSIntro.Plus(menyuId, 5, 5, ConsoleColor.Green, ConsoleColor.Black);
                MSIntro.Minus(menyuId, 15, 5, ConsoleColor.Red, ConsoleColor.Black);
                MSIntro.Transfer(menyuId, 25, 5, ConsoleColor.Blue, ConsoleColor.Black);
                MSIntro.NotFound(menyuId, maxWidth - 14, maxheight - 5, ConsoleColor.Magenta, ConsoleColor.Black);
                MSIntro.Param(menyuId, 1, maxheight - 5, ConsoleColor.Yellow, ConsoleColor.Black);
                Console.SetCursorPosition(0,11);
                MSStatistics.Show(ref accounts, ref categories, ref transactions);

                //Console.WriteLine($"3. {dictionary[" "].RetLang(staticLanguage)} ");
                //Console.WriteLine($"4. {dictionary[" "].RetLang(staticLanguage)} ");
                //Console.WriteLine($"5. {dictionary[" "].RetLang(staticLanguage)} ");
                //Console.WriteLine($"6. {dictionary[" "].RetLang(staticLanguage)} ");
                //Console.ReadKey();
            } while (xreplace);
        }