Example #1
0
        static void TestWriteComputerList(string path)
        {
            var list  = new ComputerList();
            var comp1 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 1
            };
            var comp2 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 2
            };
            var comp3 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 3
            };
            var comp4 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 4
            };

            list.Push(comp1);
            list.Push(comp2);
            list.Push(comp3);
            list.Push(comp4);

            FileHelper.CreateComputerList(path, list);
        }
Example #2
0
        static void TestCreateNotEmptyRoom(string path)
        {
            var list  = new ComputerList();
            var comp1 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 1
            };
            var comp2 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 2
            };
            var comp3 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 3
            };
            var comp4 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 4
            };

            list.Push(comp1);
            list.Push(comp2);
            list.Push(comp3);
            list.Push(comp4);

            var room = new Room()
            {
                Num       = "a5",
                Computers = list
            };

            FileHelper.CreateRoom(path, room);
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            decimal price;

            try { price = decimal.Parse(textBoxPrice.Text); }
            catch
            {
                MessageBox.Show("Введите сумму числом");
                return;
            }

            if (_computer == null)
            {
                _computerList.Push(new Computer()
                {
                    Id    = Guid.Parse(labelId.Text),
                    Price = price
                });
                FileHelper.CreateComputerList(_path, _computerList);
                _contextForm.FillData();
                Close();
            }
            else
            {
                _computer.Price = price;
                FileHelper.UpdateComputer(_path, _computer);
                _contextForm.FillData();
                Close();
            }
        }
Example #4
0
        public static ComputerList ReadComputerList(string path)
        {
            var list     = new ComputerList();
            var allFiles = Directory.GetFiles(path);

            if (allFiles.Length == 0)
            {
                return(list);
            }

            var serializer = new XmlSerializer(typeof(ComputerXmlModel));
            var filePath   = allFiles.First();

            var isLoop = false;

            while (!isLoop)
            {
                using (var reader = new StreamReader(filePath))
                {
                    var xmlModel = (ComputerXmlModel)serializer.Deserialize(reader);
                    var computer = new Computer()
                    {
                        Id = xmlModel.Id, Price = xmlModel.Price
                    };
                    list.Push(computer);
                    filePath = $@"{path}\{xmlModel.Next.ToString()}.xml";
                    if (xmlModel.Next == list.Head.Id)
                    {
                        isLoop = true;
                    }
                }
            }
            return(list);
        }
Example #5
0
        static void TestComputers()
        {
            var list  = new ComputerList();
            var comp1 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 1
            };
            var comp2 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 2
            };
            var comp3 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 3
            };
            var comp4 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 4
            };

            list.Push(comp1);
            list.Push(comp2);
            list.Push(comp3);
            list.Push(comp4);

            foreach (var item in list)
            {
                Console.WriteLine(((Computer)item).Price);
            }
            Console.WriteLine();

            list.Remove(comp4);

            foreach (var item in list)
            {
                Console.WriteLine(((Computer)item).Price);
            }
        }
Example #6
0
        static void TestRooms()
        {
            var list1  = new ComputerList();
            var comp11 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 1
            };
            var comp21 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 2
            };
            var comp31 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 3
            };
            var comp41 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 4
            };

            list1.Push(comp11);
            list1.Push(comp21);
            list1.Push(comp31);
            list1.Push(comp41);

            var list2  = new ComputerList();
            var comp12 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 1
            };
            var comp22 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 2
            };
            var comp32 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 3
            };
            var comp42 = new Computer()
            {
                Id = Guid.NewGuid(), Price = 4
            };

            list1.Push(comp12);
            list1.Push(comp22);
            list1.Push(comp32);
            list1.Push(comp42);

            var queue = new RoomQueue();

            queue.Push(new Room()
            {
                Num       = "a1",
                Computers = list1
            });
            queue.Push(new Room()
            {
                Num       = "b1",
                Computers = list2
            });


            foreach (var item in queue)
            {
                Console.WriteLine(((Room)item).Num);
            }
        }