public ObservableCollection <Bicycle> Open(string filename) { ObservableCollection <Bicycle> Bicycles = new ObservableCollection <Bicycle>(); List <string> buffer = new List <string>(); using (StreamReader sr = new StreamReader(filename)) //поток чтения файла - локального { while (sr.Peek() >= 0) //контролируем что в файле еще есть символы { buffer.Add(sr.ReadLine()); //записываем всю строку в элемент списка буфер } } for (int i = 0; i < buffer.Count; i++) { string[] words = buffer[i].Split(' '); // разделяем строку на массив строк uint id = uint.Parse(words[0]); string model = words[1]; string manufacture = words[2]; int year = int.Parse(words[3]); int numberOfSpeeds = int.Parse(words[4]); string type = words[5]; BicycleFrame Frame = new BicycleFrame(words[6], int.Parse(words[7])); string creationTime = words[8]; Bicycles.Add(new Bicycle(model, manufacture, year, numberOfSpeeds, type, Frame, id, creationTime)); } buffer.Clear(); return(Bicycles); }
public Bicycle(string model, string manufacture, int year, int numberofspeeds, string type, BicycleFrame frame) { Model = model; Manufacture = manufacture; Year = year; NumberOfSpeeds = numberofspeeds; Type = type; Frame = frame; CreationTime = DateTime.Now.ToString(); ID = Guid2Int(GuidGenerate()); }
public Bicycle(string model, string manufacture, int year, int numberofspeeds, string type, BicycleFrame frame, uint id, string creatiotime) { Model = model; Manufacture = manufacture; Year = year; NumberOfSpeeds = numberofspeeds; Type = type; Frame = frame; ID = id; CreationTime = creatiotime; }
private void AddBicycle() { Random myRandom = new Random((Int32)DateTime.Now.Ticks); string myModel = myModels[GetRandomNumber()]; string myManufacture = myManufactures[GetRandomNumber()]; int myYear = myYears[GetRandomNumber()]; int myNumberOfSpeed = myNumberOfSpeeds[GetRandomNumber()]; string myType = myTypes[GetRandomNumber()]; BicycleFrame Frame = new BicycleFrame(myMaterials[GetRandomNumber()], mySizes[GetRandomNumber()]); Bicycle s = new Bicycle(myModel, myManufacture, myYear, myNumberOfSpeed, myType, Frame); Bicycles.Add(s); int GetRandomNumber() { return(myRandom.Next(0, 6)); } }