Exemple #1
0
        private async Task <TCGPrice> Update(int TcgId)
        {
            ProgBar.IsIndeterminate = true;

            var prices = await App.GetPrice(TcgId);

            ProgBar.IsIndeterminate = false;

            return(prices);
        }
Exemple #2
0
        private async void GetPricesButton_Click(object sender, RoutedEventArgs e)
        {
            GetPricesButton.IsEnabled = false;
            ExportButton.IsEnabled    = false;
            UpdateButton.IsEnabled    = false;
            PriceGrid.ItemsSource     = null;

            DataTable dt = new DataTable();
            string    dataJson;

            List <Inventory> Inventory  = new List <Inventory>();
            List <Result>    PriceLists = new List <Result>();

            using (SqlConnection conn = new SqlConnection(App.connstring))
            {
                SqlCommand pullComm = new SqlCommand($"select * from Inventory where SetCode = '{SetBox.SelectedItem.ToString().ToUpper()}'", conn);
                conn.Open();

                using (SqlDataAdapter da = new SqlDataAdapter(pullComm))
                {
                    da.Fill(dt);
                    dataJson = JsonConvert.SerializeObject(dt, Formatting.Indented);

                    Inventory = JsonConvert.DeserializeObject <List <Inventory> >(dataJson);
                }

                StatBlock.Text  = $"0/{Inventory.Count}";
                ProgBar.Maximum = Inventory.Count;

                try
                {
                    foreach (var item in Inventory)
                    {
                        var prices = await App.GetPrice(item.TCGProdId);

                        PriceLists.AddRange(prices.Results);
                        ProgBar.Value += 1;
                        StatBlock.Text = $"{ProgBar.Value}/{Inventory.Count}";
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Please check your internet connection and try again.");
                    ProgBar.Value             = 0;
                    GetPricesButton.IsEnabled = true;

                    conn.Close();
                    conn.Dispose();
                }

                MergeData(Inventory, PriceLists);

                StatBlock.Text            = "Completed";
                ProgBar.Value             = 0;
                GetPricesButton.IsEnabled = true;
                ExportButton.IsEnabled    = true;
                UpdateButton.IsEnabled    = true;

                conn.Close();
                conn.Dispose();
            }
        }