// Ham co nhiem vu tach chuoi doc duoc tu file // gan gia tri vao bien fc static bool TachGiaTri(string input, out Flashcard fc) { fc = new Flashcard(); string[] items = input.Split('|'); // phai chua 5 thanh phan if (items.Length != 5) { return(false); } fc.tu = items[0]; fc.nghia = items[1]; if (!bool.TryParse(items[2], out fc.dahoc)) { return(false); } if (!bool.TryParse(items[3], out fc.dathuoc)) { return(false); } if (!bool.TryParse(items[4], out fc.dakiemtra)) { return(false); } return(true); }
static void Hoc() { Console.WriteLine("\nHOC"); // neu la rong thi bo qua if (LaRong("de hoc")) { return; } // nhap so luong tu can hoc, tu 10 - 20 tu int sotu = XulyNhapSo(); List <Flashcard> listHoc = new List <Flashcard>(); LayFCDeHoc(sotu, ref listHoc); // Hoc for (int i = 0; i < listHoc.Count; i++) { Flashcard fc = listHoc[i]; Console.WriteLine("{0}.", i + 1); InMotFC(fc); fc.dahoc = true; ThayThe(fc); Console.ReadKey(); // bam phim bat ky de hoc tiep } }
static void KiemTra() { Console.WriteLine("\nKIEM TRA"); // neu la rong thi bo qua if (LaRong("de kiem tra")) { return; } if (!DaCoHoc()) { Console.Write("Ban chua hoc flashcard nao ca!"); Console.ReadKey(); return; } List <Flashcard> listKT = new List <Flashcard>(); LayFCDeKiemTra(ref listKT); if (listKT.Count == 0) { Console.WriteLine("Ban da thuoc het tat ca cac flashcard."); Console.ReadKey(); return; } int demDung = 0; for (int i = 0; i < listKT.Count; i++) { Flashcard fc = listKT[i]; Console.WriteLine("{0}.", i + 1); fc.dakiemtra = true; Console.WriteLine("Nghia : {0}", fc.nghia); Console.Write("Tu : "); string tu = Console.ReadLine(); if (tu == fc.tu) { Console.WriteLine("DUNG ROI!"); fc.dathuoc = true; demDung++; } else { Console.WriteLine("SAI ROI, tu dung la: {0}", fc.tu); } ThayThe(fc); Console.ReadKey(); // bam phim bat ky de kiem tra tiep } Console.WriteLine("Ban thuoc {0} tu / {1} so tu kiem tra.", demDung, listKT.Count); Console.ReadKey(); }
// Thay the flashcard voi tu da co bang flashcard moi static void ThayThe(Flashcard fcmoi) { int index; if ((index = LayIndexTheoTu(fcmoi.tu)) != -1) { listFC.RemoveAt(index); listFC.Insert(index, fcmoi); } }
// Ham xu ly in thong tin mot flashcard // Flashcard fc : la flashcard can in static void InMotFC(Flashcard fc, bool indaydu = false) { Console.WriteLine("Tu : {0}", fc.tu); // in tu Console.WriteLine("Nghia : {0}", fc.nghia); // in nghia cua tu if (indaydu) { Console.WriteLine(fc.dahoc ? "Da hoc" : "Chua hoc"); Console.WriteLine(fc.dathuoc ? "Da thuoc" : "Chua thuoc"); Console.WriteLine(fc.dakiemtra ? "Da kiem tra" : "Chua kiem tra"); } }
// Ham cho phep nhap vao cac flashcard moi // viec nhap chi dung lai khi nguoi su dung muon static void ThemFCMoi() { Console.WriteLine("\nTHEM FLASHCARD MOI"); do { Flashcard fc = ThemMotFCMoi(); // nhap thong tin cho mot flashcard listFC.Add(fc); // hoi nguoi su dung co muon tiep tuc khong } while (XuLyCauHoiYesNo("\nBan co muon nhap them flashcard khac khong ? (Y/N) : ")); }
// XU LY THEM FLASHCARD #region Them flashcard // Ham cho phep nhap them n flashcard moi // ham nhap voi so luong nhap xac dinh truoc static void ThemFCMoi(int n) { Console.WriteLine("\nTHEM DON DANG KY MOI"); for (int i = 0; i < n; i++) { Console.WriteLine("{0}.", i + 1); Flashcard fc = ThemMotFCMoi(); // nhap cho mot flashcard listFC.Add(fc); } }
// Ham xu ly nhap thong tin cho mot flashcard static Flashcard ThemMotFCMoi() { Flashcard fc = new Flashcard(); // khoi tao Console.WriteLine("\nMoi ban nhap thong tin flashcard :"); Console.Write("Tu : "); fc.tu = Console.ReadLine(); Console.Write("Nghia : "); fc.nghia = Console.ReadLine(); fc.dahoc = false; fc.dathuoc = false; fc.dakiemtra = false; return(fc); }