コード例 #1
0
        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 MSCategory(MSCategory MScategory)
 {
     MSCategoryId = MScategory.MSCategoryId;
     MSIO         = MScategory.MSIO;
     MSName       = MScategory.MSName;
     MSAccountId  = MScategory.MSAccountId;
     MSColor      = MScategory.MSColor;
     MSImage      = MScategory.MSImage;
 }
コード例 #3
0
 private static void AddCategory()
 {
     int tCatId = categories.Count;
     do
     {
         tCatId++;
         if (!(categories.Exists(x => x.MSAccountId == tCatId)))
         {
             category.ConsoleAdd(tCatId, transactionSymbol);
             break;
         }
     } while (true);
     categories.Add(new MSCategory(category));
     MSCategory.SQLiteInsertCategoryInDatabase(category);
     Console.WriteLine("Категория добавлена.");
     Program.cki = Console.ReadKey();
 }
コード例 #4
0
        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
        static public void SQLiteInsertCategoryInDatabase(MSCategory c)
        {
            Program.conn.Open();
            string sql_command = "INSERT INTO MSCategories (MSCategoryId, " +
                                 "MSIO,     " +
                                 "MSName, " +
                                 "MSAccountId, " +
                                 "MSColor, " +
                                 "MSImage) "
                                 + $"VALUES ({c.MSCategoryId}," +
                                 $"'{c.MSIO}'," +
                                 $"'{c.MSName}'," +
                                 $" {c.MSCategoryId}," +
                                 $" {(int)c.MSColor}," +
                                 $"'{c.MSImage})');";

            System.Data.SQLite.SQLiteCommand command = new System.Data.SQLite.SQLiteCommand(sql_command, Program.conn);
            command.ExecuteNonQuery();
            Program.conn.Close();
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        public static int ChooseCategory(ref List <MSCategory> msCategoryList, int msAccountId)
        {
            int left = Console.CursorLeft;
            int top  = Console.CursorTop;

            List <MSCategory> TmsCategoryList = new List <MSCategory>();

            for (int i = 0; i < msCategoryList.Count; i++)
            {
                if (msCategoryList[i].MSAccountId == msAccountId)
                {
                    TmsCategoryList.Add(new MSCategory(msCategoryList[i]));
                }
            }

            int    maxLen  = 0;
            string xSynbol = "↓ "; // ↓   ↑   ↓↑

            if (TmsCategoryList.Count > 0)
            {
                maxLen = TmsCategoryList.Max(s => s.MSName).Length;
                if (TmsCategoryList.Count == 1)
                {
                    xSynbol = "  ";
                }
            }
            else
            {
                int tCatCount = Program.categories.Count;
                do
                {
                    tCatCount++;
                    if (!TmsCategoryList.Exists(x => x.MSCategoryId == tCatCount)) //Error?
                    {
                        Console.WriteLine();
                        int maxWidth = 40, maxheight = 65;
                        Console.SetWindowSize(maxWidth, 25);
                        Console.SetBufferSize(maxWidth, maxheight);
                        Program.category.ConsoleAdd(tCatCount, Program.transactionSymbol);
                        Program.categories.Add(new MSCategory(Program.category));
                        MSCategory.SQLiteInsertCategoryInDatabase(Program.category);
                        break;
                    }
                } while (true);
            }
            if (TmsCategoryList.Exists(x => x.MSAccountId == msAccountId)) //Error?
            {
                Console.WriteLine($"{TmsCategoryList.Where(x => x.MSAccountId == msAccountId).Select(g => g.MSImage).First()} " +
                                  $"{TmsCategoryList.Where(x => x.MSAccountId == msAccountId).Select(g => g.MSName).First()} {xSynbol}");
            }
            else
            {
                int tCatCount = Program.categories.Count;
                do
                {
                    tCatCount++;
                    if (!TmsCategoryList.Exists(x => x.MSCategoryId == tCatCount))
                    {
                        Console.WriteLine();
                        int maxWidth = 40, maxheight = 65;
                        Console.SetWindowSize(maxWidth, 25);
                        Console.SetBufferSize(maxWidth, maxheight);
                        Program.category.ConsoleAdd(tCatCount, Program.transactionSymbol);
                        Program.categories.Add(new MSCategory(Program.category));
                        MSCategory.SQLiteInsertCategoryInDatabase(Program.category);
                        break;
                    }
                } while (true);
            }

            int changeAccountId = 0;

            do
            {
                //if (Console.KeyAvailable)
                //{
                Program.cki = Console.ReadKey();
                //}
                switch (Program.cki.Key)
                {
                case ConsoleKey.DownArrow:
                    if (++changeAccountId >= TmsCategoryList.Count)
                    {
                        changeAccountId = TmsCategoryList.Count - 1;
                    }
                    for (int i = 0; i < maxLen + 3; i++)
                    {
                        Console.Write(" ");
                    }
                    break;

                case ConsoleKey.UpArrow:
                    if (--changeAccountId < 0)
                    {
                        changeAccountId = 0;
                    }
                    for (int i = 0; i < maxLen + 3; i++)
                    {
                        Console.Write(" ");
                    }
                    break;

                case ConsoleKey.Enter:
                    Program.cki = default(ConsoleKeyInfo);
                    Console.SetCursorPosition(0, top + 1);
                    return(TmsCategoryList[changeAccountId].MSCategoryId);

                default:
                    break;
                }
                Console.SetCursorPosition(left, top);
                Console.WriteLine($"{TmsCategoryList[changeAccountId].MSImage} {TmsCategoryList[changeAccountId].MSName} {xSynbol}");
            } while (true);
        }
コード例 #8
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);
        }