static public void SQLiteInsertTransactionInDatabase(MSTransaction tr) { using (System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection("Data Source=MSBase.sqlite;Version=3;")) { conn.Open(); int tbool = tr.MSMulticurrency == true ? 1 : 0; string tstr = (tr.MSValue.ToString()).Replace(',', '.'); string sql_command = "INSERT INTO MSTransactions (MSTransactionId, " + "MSIO, " + "MSValue, " + "MSCurrencyCode, " + "MSAccountId, " + "MSCategoryId, " + "MSNote, " + "MSDateTime, " + "MSMulticurrency) " + $"VALUES ({tr.MSTransactionId}," + $"'{tr.MSIO}'," + $" {tstr}," + $"'{tr.MSCurrencyCode}'," + $" {tr.MSAccountId}," + $" {tr.MSCategoryId}," + $"'{tr.MSNote}'," + $"'{(tr.MSDateTime).ToString()}'," + $" {tbool});"; System.Data.SQLite.SQLiteCommand command = new System.Data.SQLite.SQLiteCommand(sql_command, conn); command.ExecuteNonQuery(); conn.Close(); } }
public MSTransaction(MSTransaction msTransaction) { MSTransactionId = msTransaction.MSTransactionId; MSIO = msTransaction.MSIO; MSValue = msTransaction.MSValue; MSCurrencyCode = msTransaction.MSCurrencyCode; MSAccountId = msTransaction.MSAccountId; MSCategoryId = msTransaction.MSCategoryId; MSNote = msTransaction.MSNote; MSDateTime = msTransaction.MSDateTime; MSMulticurrency = msTransaction.MSMulticurrency; }
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(); }
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); }