ebakhtin 176c7c9994 first | há 6 meses atrás | |
---|---|---|
.vs | há 6 meses atrás | |
Model | há 6 meses atrás | |
assets | há 6 meses atrás | |
bin | há 6 meses atrás | |
img | há 6 meses atrás | |
obj | há 6 meses atrás | |
App.xaml | há 6 meses atrás | |
App.xaml.cs | há 6 meses atrás | |
AssemblyInfo.cs | há 6 meses atrás | |
MainWindow.xaml | há 6 meses atrás | |
MainWindow.xaml.cs | há 6 meses atrás | |
readme.md | há 6 meses atrás | |
wpf_data_csv.csproj | há 6 meses atrás | |
wpf_data_csv.csproj.user | há 6 meses atrás | |
wpf_data_csv.sln | há 6 meses atrás |
JSON:
[
{
"Title":"Redmi A3",
"Company":"Xiaomi",
"Price": 6999,
"Category": "Смартфон",
"Existence": true,
"ArrivalDate": "2023-12-15",
"Rating": 3.9,
"Photo": null
},
{
"Title":"12",
"Company":"Xiaomi",
"Price": 44999,
"Category": "Смартфон",
"Existence": true,
"ArrivalDate": "2024-03-21",
"Rating": 4.7,
"Photo": null
},
{
"Title":"iPhone 11 Pro",
"Company":"Apple",
"Price": 48999,
"Category": "Смартфон",
"Existence": false,
"ArrivalDate": "2023-09-19",
"Rating": 4.3,
"Photo": null
},
{
"Title":"iPhone SE 2022",
"Company":"Apple",
"Price": 36999,
"Category": "Смартфон",
"Existence": false,
"ArrivalDate": "2023-10-25",
"Rating": 4.1,
"Photo": null
},
{
"Title":"Galaxy S22",
"Company":"Samsung",
"Price": 61299,
"Category": "Смартфон",
"Existence": true,
"ArrivalDate": "2024-02-21",
"Rating": 4.8,
"Photo": null
},
{
"Title":"Redmi Watch 2",
"Company":"Xiaomi",
"Price": 5299,
"Category": "Смарт-Часы",
"Existence": true,
"ArrivalDate": "2023-11-09",
"Rating": 3.2,
"Photo": null
},
{
"Title":"ExpertBook B1",
"Company":"Asus",
"Price": 33999,
"Category": "Ноутбук",
"Existence": true,
"ArrivalDate": "2023-01-09",
"Rating": 4,
"Photo": null
},
{
"Title":"MateBook D 15",
"Company":"Huawei",
"Price": 44999,
"Category": "Ноутбук",
"Existence": false,
"ArrivalDate": "2023-08-17",
"Rating": 4.4,
"Photo": null
},
{
"Title":"Watch SE 2022",
"Company":"Apple",
"Price": 29499,
"Category": "Смарт-Часы",
"Existence": true,
"ArrivalDate": "2023-08-29",
"Rating": 3.8,
"Photo": null
},
{
"Title":"R272ymix",
"Company":"Acer",
"Price": 10999,
"Category": "Монитор",
"Existence": true,
"ArrivalDate": "2023-11-11",
"Rating": 4.6,
"Photo": null
},
{
"Title":"27B3HM",
"Company":"AOC",
"Price": 12999,
"Category": "Монитор",
"Existence": true,
"ArrivalDate": "2024-04-05",
"Rating": 4.7,
"Photo": null
},
{
"Title":"Watch Ultra 49mm",
"Company":"Apple",
"Price": 75999,
"Category": "Смарт-Часы",
"Existence": false,
"ArrivalDate": "2023-05-06",
"Rating": 4.8,
"Photo": null
},
]
C#:
namespace wpf_template.Model
{
public class JSONDataProvider : IDataProvider
{
private List<Product> products;
public JSONDataProvider()
{
var serializer = new DataContractJsonSerializer(typeof(Product[]));
using(var sr = new StreamReader("./products.json"))
{
products = ((Product[])serializer.ReadObject(sr.BaseStream)).ToList();
}
}
public IEnumerable<Product> GetProducts()
{
return products;
}
public IEnumerable<ProductCategory> GetCategories()
{
return new ProductCategory[]
{
new ProductCategory {title = "Смартфон"},
new ProductCategory {title = "Ноутбук"},
new ProductCategory {title = "Смарт-Часы"},
new ProductCategory {title = "Монитор"}
};
}
public IEnumerable<ProductPrice> GetPrices()
{
return new ProductPrice[]
{
new ProductPrice{title="Все цены", priceFrom = 0, priceTo = 999999},
new ProductPrice{title="До 10.000", priceFrom = 0, priceTo = 10000},
new ProductPrice{title="От 10.000 до 20.000", priceFrom = 10000, priceTo = 20000},
new ProductPrice{title="От 20.000 до 50.000", priceFrom = 20000, priceTo = 50000},
new ProductPrice{title="Дороже 50.000", priceFrom = 50000, priceTo = 999999 }
};
}
public IEnumerable<ProductCompany> GetCompanies()
{
return new ProductCompany[]
{
new ProductCompany{title = "Apple"},
new ProductCompany{title = "Xiaomi"},
new ProductCompany{title = "Huawei"},
new ProductCompany{title = "POCO"},
new ProductCompany{title = "Asus"},
new ProductCompany{title = "Lenovo"},
new ProductCompany{title = "Samsung"},
new ProductCompany{title = "Acer"},
new ProductCompany{title = "AOC"}
};
}
}
}
...
public MainWindow()
{
InitializeComponent();
DataContext = this;
Globals.dataProvider = new JSONDataProvider();
ProductList = Globals.dataProvider.GetProducts();
ProductPrices = Globals.dataProvider.GetPrices().ToList();
CategoryList = Globals.dataProvider.GetCategories().ToList();
CategoryList.Insert(0, new ProductCategory { title = "Все категории" });
ProductCompanies = Globals.dataProvider.GetCompanies().ToList();
ProductCompanies.Insert(0, new ProductCompany { title = "Все компании" });
}
...