Exemplo n.º 1
0
 public void Them(MayTinh mt) => listMayTinh.Add(mt);
Exemplo n.º 2
0
        public void ImportFromFile()
        {
            //string path = "E:\\data.txt";
            string path = @"maytinh.txt";

            Write("Nhap ten tap tin de mo >> ");
            string keyOpen = ReadLine().ToLower();
            string keyWord = ".txt";
            string a;

            if (keyOpen.Contains('.'))
            {
                a = $@"{keyOpen}";
            }
            else
            {
                a = $@"{keyOpen + keyWord}";
            }
            if (a != path)
            {
                Write("\nFail! Please try...");
                Read();
                return;
            }
            else
            {
                Write("\nAccess...");
            }
            StreamReader file = new StreamReader(a);
            string       str  = "";

            while ((str = file.ReadLine()) != null)
            {
                MayTinh  mayTinh = new MayTinh();
                string[] s       = str.Split('*');
                mayTinh.TenMayTinh = s[0];
                foreach (string item in s)
                {
                    if (item.IndexOf("CPU") == 0)
                    {
                        mayTinh.Them(new CPU(item));
                    }
                    if (item.IndexOf("RAM") == 0)
                    {
                        mayTinh.Them(new RAM(item));
                    }
                    if (item.IndexOf("HDD") == 0)
                    {
                        mayTinh.Them(new HDD(item));
                    }
                    if (item.IndexOf("Mainboard") == 0)
                    {
                        mayTinh.Them(new MAINBOARD(item));
                    }
                    if (item.IndexOf("Power") == 0)
                    {
                        mayTinh.Them(new PSU(item));
                    }
                }
                Them(mayTinh);
            }
        }