Example #1
0
        public void initCardView()
        {
            cardView.Items.Clear();
            cardView.View          = View.Details;
            cardView.GridLines     = true;
            cardView.FullRowSelect = true;

            cardView.BackColor = Color.WhiteSmoke;

            cardView.Columns.Add("ProductID", 60);
            cardView.Columns.Add("Card Name", 220);
            cardView.Columns.Add("Edition", 120);

            dj = new DataTable();

            // note - we have expansions only for MTG cards, so non-mtg will not have the expansion name
            var inventorySinglesOnly = MKMDbManager.Instance.InventorySinglesOnly.CopyToDataTable();

            dj = MKMDbManager.JoinDataTables(inventorySinglesOnly, MKMDbManager.Instance.Expansions,
                                             (row1, row2) => row1.Field <string>(MKMDbManager.InventoryFields.ExpansionID) == row2.Field <string>(MKMDbManager.ExpansionsFields.ExpansionID));

            foreach (DataRow row in dj.Rows)
            {
                var item = new ListViewItem(row[MKMDbManager.InventoryFields.ProductID].ToString());

                item.SubItems.Add(row[MKMDbManager.InventoryFields.Name].ToString());
                item.SubItems.Add(row[MKMDbManager.ExpansionsFields.Name].ToString());

                cardView.Items.Add(item);
            }
        }
Example #2
0
        // reload data each time the form is made visible in case the user's stock has changed so they can reload the stockview this way
        private void StockView_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                int start    = 1;
                var articles = new DataTable();
                try
                {
                    while (true)
                    {
                        var doc = MKMInteract.RequestHelper.readStock(start);
                        if (doc.HasChildNodes)
                        {
                            var result       = doc.GetElementsByTagName("article");
                            int elementCount = 0;
                            foreach (XmlNode article in result)
                            {
                                if (article["condition"] != null) // is null for articles that are not cards (boosters etc.) - don't process those
                                {
                                    MKMMetaCard m = new MKMMetaCard(article);
                                    m.WriteItselfIntoTable(articles, true, MCFormat.MKM);
                                    elementCount++;
                                }
                            }
                            if (elementCount != 100)
                            {
                                break;
                            }
                            start += elementCount;
                        }
                        else
                        {
                            break;  // document is empty -> end*/
                        }
                    }

                    // Remove columns we don't want showing
                    // TODO - what is and isn't shown should probably be customizable and left to the user to choose in some way
                    articles.Columns.Remove(MCAttribute.ArticleID);
                    articles.Columns.Remove(MCAttribute.ProductID);
                    articles.Columns.Remove(MCAttribute.LanguageID);
                    articles.Columns.Remove(MCAttribute.CardNumber);

                    var dj = MKMDbManager.JoinDataTables(articles, MKMDbManager.Instance.Expansions,
                                                         (row1, row2) => row1.Field <string>(MKMDbManager.InventoryFields.ExpansionID) == row2.Field <string>(MKMDbManager.ExpansionsFields.ExpansionID));

                    dj.Columns.Remove(MCAttribute.ExpansionID);                   // duplicated
                    dj.Columns.Remove(MKMDbManager.ExpansionsFields.ExpansionID); // ...and we don't want it anyway
                    dj.Columns.Remove(MKMDbManager.ExpansionsFields.Name);        // duplicated

                    dj.Columns[dj.Columns.IndexOf(MCAttribute.Name)].SetOrdinal(0);
                    dj.Columns[dj.Columns.IndexOf(MCAttribute.Expansion)].SetOrdinal(1);
                    dj.Columns[dj.Columns.IndexOf(MCAttribute.Language)].SetOrdinal(2);

                    stockGridView.DataSource = dj;

                    buttonExport.Enabled = true;
                }
                catch (Exception eError)
                {
                    MKMHelpers.LogError("listing stock in Stock View", eError.Message, true);
                }
            }
        }
Example #3
0
        // reload data each time the form is made visible in case the user's stock has changed so they can reload the stockview this way
        private void stockView_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                var articles = new DataTable();
                try
                {
                    // getAllStockSingles creates a DataTable and converts it to list of cards, so theoretically we are wasting some work
                    // but it also filters out non-singles and converting to MKMcard will make sure we use the primary column names rather than synonyms
                    var cards = MKMInteract.RequestHelper.GetAllStockSingles(MainView.Instance.Config.UseStockGetFile);
                    if (cards.Count == 0)
                    {
                        MainView.Instance.LogMainWindow("Stock is empty. Did you select correct idGame in config.xml?");
                        return;
                    }
                    foreach (var card in cards)
                    {
                        card.WriteItselfIntoTable(articles, true, MCFormat.MKM, true);
                    }
                    // Remove columns we don't want showing
                    // TODO - what is and isn't shown should probably be customizable and left to the user to choose in some way
                    if (articles.Columns.Contains(MCAttribute.ArticleID))
                    {
                        articles.Columns.Remove(MCAttribute.ArticleID);
                    }
                    if (articles.Columns.Contains(MCAttribute.LanguageID))
                    {
                        articles.Columns.Remove(MCAttribute.LanguageID);
                    }
                    if (articles.Columns.Contains(MCAttribute.MetaproductID))
                    {
                        articles.Columns.Remove(MCAttribute.MetaproductID);
                    }
                    if (articles.Columns.Contains("onSale"))
                    {
                        articles.Columns.Remove("onSale"); // don't even know what this one is supposed to be, it's not even in the API documentation
                    }
                    if (articles.Columns.Contains(MCAttribute.MKMCurrencyCode))
                    {
                        articles.Columns.Remove(MCAttribute.MKMCurrencyCode);
                    }
                    if (articles.Columns.Contains(MCAttribute.MKMCurrencyId))
                    {
                        articles.Columns.Remove(MCAttribute.MKMCurrencyId);
                    }

                    var dj = MKMDbManager.JoinDataTables(articles, MKMDbManager.Instance.Expansions,
                                                         (row1, row2) => row1.Field <string>(MCAttribute.ExpansionID) == row2.Field <string>(MKMDbManager.ExpansionsFields.ExpansionID));

                    if (dj.Columns.Contains(MCAttribute.ExpansionID))
                    {
                        dj.Columns.Remove(MCAttribute.ExpansionID); // duplicated
                    }
                    if (dj.Columns.Contains(MKMDbManager.ExpansionsFields.ExpansionID))
                    {
                        dj.Columns.Remove(MKMDbManager.ExpansionsFields.ExpansionID); // ...and we don't want it anyway
                    }
                    if (dj.Columns.Contains(MKMDbManager.ExpansionsFields.Name))
                    {
                        dj.Columns.Remove(MKMDbManager.ExpansionsFields.Name); // duplicated
                    }
                    // use the same order with or without UseStockGetFile
                    System.Collections.Generic.List <string> attsOrdered = new System.Collections.Generic.List <string>
                    {
                        MCAttribute.Name, MCAttribute.Expansion, MCAttribute.Language, MCAttribute.ProductID,
                        MCAttribute.MKMPrice, MCAttribute.Condition, MCAttribute.Comments, MCAttribute.Foil,
                        MCAttribute.Altered, MCAttribute.Signed, MCAttribute.Playset, MCAttribute.Count,
                        MCAttribute.Rarity, MCAttribute.ExpansionAbb
                    };
                    int ordinal = 0;
                    foreach (string att in attsOrdered)
                    {
                        if (dj.Columns.Contains(att))
                        {
                            dj.Columns[dj.Columns.IndexOf(att)].SetOrdinal(ordinal++);
                        }
                    }

                    // convert columns with numerical data from string so that sorting works correctly
                    if (dj.Columns.Contains(MCAttribute.ProductID))
                    {
                        convertNumberColumn(dj, MCAttribute.ProductID, false);
                    }
                    if (dj.Columns.Contains(MCAttribute.Count))
                    {
                        convertNumberColumn(dj, MCAttribute.Count, false);
                    }
                    if (dj.Columns.Contains(MCAttribute.MKMPrice))
                    {
                        convertNumberColumn(dj, MCAttribute.MKMPrice, true);
                    }

                    stockGridView.DataSource = dj;

                    buttonExport.Enabled = true;
                }
                catch (Exception eError)
                {
                    MKMHelpers.LogError("listing stock in Stock View", eError.Message, true);
                }
            }
        }