|
@@ -156,49 +156,25 @@ namespace WpfApp3
|
|
|
|
|
|
### MusicalInsrument
|
|
|
```
|
|
|
+using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using WpfApp3.Class;
|
|
|
-using System.IO;
|
|
|
-using CsvHelper;
|
|
|
-using CsvHelper.Configuration;
|
|
|
using System.Linq;
|
|
|
-using System.Globalization;
|
|
|
-namespace WpfApp3
|
|
|
+using System.Runtime.Serialization;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace WpfApp3.Class
|
|
|
{
|
|
|
- class InstrumentDataManager
|
|
|
+ [DataContract]
|
|
|
+ public class MusicalInstrument
|
|
|
{
|
|
|
- private List<MusicalInstrument> instruments;
|
|
|
-
|
|
|
- public InstrumentDataManager()
|
|
|
- {
|
|
|
- instruments = new List<MusicalInstrument>
|
|
|
- {
|
|
|
- new MusicalInstrument { Name = "Гитара", Type = "Струнные", Price = 300 },
|
|
|
- new MusicalInstrument { Name = "Барабаны", Type = "Ударные", Price = 500 },
|
|
|
- new MusicalInstrument { Name = "Фортепиано", Type = "Клавишные", Price = 1000 },
|
|
|
- new MusicalInstrument { Name = "Скрипка", Type = "Струнные", Price = 400 },
|
|
|
- new MusicalInstrument { Name = "Труба", Type = "Медные", Price = 600 },
|
|
|
- };
|
|
|
- CsvConfiguration configuration = new CsvConfiguration(CultureInfo.InvariantCulture)
|
|
|
- {
|
|
|
- Delimiter = ",",
|
|
|
- HasHeaderRecord = true,
|
|
|
- IgnoreBlankLines = true
|
|
|
- };
|
|
|
-
|
|
|
- using (var reader = new StreamReader("./data.csv"))
|
|
|
- using (var csv = new CsvReader(reader, configuration))
|
|
|
- {
|
|
|
- instruments = csv.GetRecords<MusicalInstrument>().ToList();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public List<MusicalInstrument> GetInstruments()
|
|
|
- {
|
|
|
- return instruments;
|
|
|
- }
|
|
|
+ public string Name { get; set;
|
|
|
+ public string Type { get; set; }
|
|
|
+ public string Brand { get; set; }
|
|
|
+ public double Price { get; set; }
|
|
|
}
|
|
|
}
|
|
|
+```
|
|
|
<Window x:Class="WpfApp3.MainWindow"
|
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|