Aucune description

ebakhtin 176c7c9994 first il y a 6 mois
.vs 176c7c9994 first il y a 6 mois
Model 176c7c9994 first il y a 6 mois
assets 176c7c9994 first il y a 6 mois
bin 176c7c9994 first il y a 6 mois
img 176c7c9994 first il y a 6 mois
obj 176c7c9994 first il y a 6 mois
App.xaml 176c7c9994 first il y a 6 mois
App.xaml.cs 176c7c9994 first il y a 6 mois
AssemblyInfo.cs 176c7c9994 first il y a 6 mois
MainWindow.xaml 176c7c9994 first il y a 6 mois
MainWindow.xaml.cs 176c7c9994 first il y a 6 mois
readme.md 176c7c9994 first il y a 6 mois
wpf_data_csv.csproj 176c7c9994 first il y a 6 mois
wpf_data_csv.csproj.user 176c7c9994 first il y a 6 mois
wpf_data_csv.sln 176c7c9994 first il y a 6 mois

readme.md

Получение данных из внешних источников. JSON.

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 = "Все компании" });
        }
...

Результат: