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(); }
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); }