private void LoadShopItem(ShopItem si)
        {
            Creation creation = ShopItemToCreation(si);

            TablePanel.Controls.Clear();
            TablePanel.ColumnCount = 2;
            TablePanel.RowCount    = creation.Input.Count * 2 + creation.Output.Count * 2 + 2;
            TablePanel.Size        = new Size(254, TablePanel.RowCount * 16);

            if (formType == Creation.CreationFormType.Shop &&
                TablePanel.Controls.Cast <Control>().FirstOrDefault(a => a.Name == "storeName") != null)
            {
                Item item = creation.Input[0];
                item.quantity = si.Cost;
                Label label = new Label
                {
                    Name     = "storeName",
                    Text     = "Store Name: " + ShopList.GetShop(si).Name,
                    AutoSize = true,
                    Tag      = ShopList.GetShop(si)
                };
                label.Click += new EventHandler(TableItemSelected);
                TablePanel.Controls.Add(label);
                TablePanel.SetColumnSpan(label, 2);
            }
            LoadCreation(creation, 1);
        }
 public void ReloadCreation()
 {
     if (!(itemList.SelectedItem == null || TablePanel.Controls == null))
     {
         foreach (Control control in TablePanel.Controls)
         {
             if (control.Name.Contains("BuyPrice"))
             {
                 Item   item = (Item)control.Tag;
                 int    num  = (sortBox.Text == "Insta-buy" || sortBox.Text == "Insta-transaction") ? item.sellPrice : item.BuyPrice;
                 string text = (sortBox.Text == "Insta-buy" || sortBox.Text == "Insta-transaction") ? "Sell Price: " : "Buy Price: ";
                 text        += (num * item.quantity).ToString("N0");
                 text        += ((item.quantity == 1) ? "" : (" (" + num.ToString("N0") + " each)"));
                 control.Text = text;
             }
             else if (control.Name.Contains("SellPrice"))
             {
                 Item   item2 = (Item)control.Tag;
                 int    num2  = (sortBox.Text == "Insta-sell" || sortBox.Text == "Insta-transaction") ? item2.BuyPrice : item2.sellPrice;
                 string text2 = (sortBox.Text == "Insta-buy" || sortBox.Text == "Insta-transaction") ? "Buy Price: " : "Sell Price: ";
                 text2       += (num2 * item2.quantity).ToString("N0");
                 text2       += ((item2.quantity == 1) ? "" : (" (" + num2.ToString("N0") + " each)"));
                 control.Text = text2;
             }
             else if (control.Name.Contains("Margin"))
             {
                 int num3;
                 if (formType == Creation.CreationFormType.Shop)
                 {
                     ShopItem shopItem = (ShopItem)itemList.SelectedItem;
                     num3 = shopItem.margin();
                 }
                 else
                 {
                     Creation creation = (Creation)itemList.SelectedItem;
                     if (sortBox.Text == "Insta-buy")
                     {
                         num3 = creation.instaBuyMargin();
                     }
                     else if (sortBox.Text == "Insta-sell")
                     {
                         num3 = creation.instaSellMargin();
                     }
                     else if (sortBox.Text == "Insta-transaction")
                     {
                         num3 = creation.instaTransactionMargin();
                     }
                     else
                     {
                         num3 = creation.margin();
                     }
                 }
                 control.Text      = "Profit: " + num3.ToString("N0");
                 control.ForeColor = ((num3 >= 0) ? Color.Green : ((num3 == 0) ? SystemColors.Control : Color.Red));
             }
         }
     }
 }
 private Creation GetCreationFromList(Creation oldCreation, ListBox.ObjectCollection list)
 {
     foreach (Creation creation in list)
     {
         if (creation.GenerateID() == oldCreation.GenerateID())
         {
             return(creation);
         }
     }
     return(null);
 }
        public bool ValidityCheck(Creation c)
        {
            foreach (Item current in c.Input)
            {
                if (current.BuyPrice == 0)
                {
                    return(false);
                }
            }
            foreach (Item current2 in c.Output)
            {
                if (current2.sellPrice == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
        public void sortBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <Creation> list  = new List <Creation>();
            List <ShopItem> list2 = new List <ShopItem>();
            string          text  = sortBox.Text;

            if (text == "Insta-transaction")
            {
                list = MasterList.Where(a => ValidityCheck(a) && main.CheckAgainstSettings(a))
                       .OrderByDescending(a => a.instaTransactionMargin()).ToList();
            }
            else if (text == "Insta-sell")
            {
                list = MasterList.Where(a => ValidityCheck(a) && main.CheckAgainstSettings(a))
                       .OrderByDescending(a => a.instaSellMargin()).ToList();
            }
            else if (text == "Insta-buy")
            {
                list = MasterList.Where(a => ValidityCheck(a) && main.CheckAgainstSettings(a))
                       .OrderByDescending(a => a.instaBuyMargin()).ToList();
            }
            else if (text == "Alphabetize")
            {
                if (formType == Creation.CreationFormType.Shop)
                {
                    list2 = ShopItems.Where(a => ValidityCheck(a) && main.CheckAgainstSettings(a))
                            .OrderBy(a => a.Item.name).ToList();
                }
                else
                {
                    list = MasterList.Where(a => ValidityCheck(a) && main.CheckAgainstSettings(a))
                           .OrderBy(a => a.ToString()).ToList();
                }
            }
            else if (text == "Highest Margin")
            {
                if (formType == Creation.CreationFormType.Shop)
                {
                    list2 = ShopItems.Where(a => ValidityCheck(a) && main.CheckAgainstSettings(a))
                            .OrderByDescending(a => a.margin()).ToList();
                }
                else
                {
                    list = MasterList.Where(a => ValidityCheck(a) && main.CheckAgainstSettings(a))
                           .OrderByDescending(a => a.margin()).ToList();
                }
            }

            if (list.Count != 0)
            {
                foreach (Creation current in list)
                {
                    if (!ValidityCheck(current))
                    {
                        list.Remove(current);
                    }
                }

                Creation creation = (Creation)itemList.SelectedItem;
                itemList.BeginUpdate();
                itemList.Items.Clear();
                itemList.Items.AddRange(list.ToArray());

                if (creation != null)
                {
                    itemList.SelectedItem = GetCreationFromList(creation, itemList.Items);
                }
                itemList.EndUpdate();
            }
            else if (list2.Count != 0)
            {
                foreach (ShopItem current2 in list2)
                {
                    if (!ValidityCheck(current2))
                    {
                        list2.Remove(current2);
                    }
                }

                ShopItem shopItem = (ShopItem)itemList.SelectedItem;
                itemList.BeginUpdate();
                itemList.Items.Clear();
                itemList.Items.AddRange(list2.ToArray());

                if (shopItem != null)
                {
                    itemList.SelectedItem = GetShopItemFromList(shopItem, itemList.Items);
                }
                itemList.EndUpdate();
            }
        }
        private void LoadCreation(Creation c, int row = 0)
        {
            if (formType != Creation.CreationFormType.Shop)
            {
                TablePanel.Controls.Clear();
                TablePanel.ColumnCount = 2;
                TablePanel.RowCount    = c.Input.Count * 2 + c.Output.Count * 2 + 1;
                TablePanel.Size        = new Size(254, TablePanel.RowCount * 16);
            }
            foreach (Item current in c.Input)
            {
                string text = "Name: " + current.name;
                text += ((current.quantity == 1) ? "" : (" x" + current.quantity));
                Label label = new Label
                {
                    Text     = text,
                    AutoSize = true,
                    Tag      = current,
                    Name     = "Name" + current.name
                };
                label.Click += new EventHandler(TableItemSelected);
                TablePanel.Controls.Add(label, 0, row);
                PictureBox pictureBox = new PictureBox();
                //pictureBox.Load("http://cdn.rsbuddy.com/items/" + current.id + ".png");
                pictureBox.Click += new EventHandler(TableItemSelected);
                pictureBox.Tag    = current;
                pictureBox.Image  = null;
                TablePanel.Controls.Add(pictureBox, 1, row);
                TablePanel.SetRowSpan(pictureBox, 2);
                int num = row;
                row = num + 1;
                int    num2 = (sortBox.Text == "Insta-buy" || sortBox.Text == "Insta-transaction") ? current.sellPrice : current.BuyPrice;
                string str  = (sortBox.Text == "Insta-buy" || sortBox.Text == "Insta-transaction") ? "Sell Price: " : "Buy Price: ";
                text  = str + (num2 * current.quantity).ToString("N0");
                text += ((current.quantity == 1) ? "" : (" (" + num2.ToString("N0") + " each)"));
                Label label2 = new Label
                {
                    Text     = text,
                    AutoSize = true,
                    Tag      = current,
                    Name     = "BuyPrice" + current.name
                };
                label2.Click += new EventHandler(TableItemSelected);
                TablePanel.Controls.Add(label2, 0, row);
                num = row;
                row = num + 1;
            }
            foreach (Item current2 in c.Output)
            {
                string text2 = "Name: " + current2.name;
                text2 += ((current2.quantity == 1) ? "" : (" x" + current2.quantity));
                Label label3 = new Label
                {
                    Text     = text2,
                    AutoSize = true,
                    Tag      = current2,
                    Name     = "Name" + current2.name
                };
                label3.Click += new EventHandler(TableItemSelected);
                TablePanel.Controls.Add(label3, 0, row);
                PictureBox pictureBox2 = new PictureBox();
                //pictureBox2.Load("http://cdn.rsbuddy.com/items/" + current2.id + ".png");
                pictureBox2.Click += new EventHandler(TableItemSelected);
                TablePanel.Controls.Add(pictureBox2, 1, row);
                pictureBox2.Tag = current2;
                TablePanel.SetRowSpan(pictureBox2, 2);
                int num = row;
                row = num + 1;
                int    num3 = (sortBox.Text == "Insta-sell" || sortBox.Text == "Insta-transaction") ? current2.BuyPrice : current2.sellPrice;
                string str2 = (sortBox.Text == "Insta-buy" || sortBox.Text == "Insta-transaction") ? "Buy Price: " : "Sell Price: ";
                text2  = str2 + (num3 * current2.quantity).ToString("N0");
                text2 += ((current2.quantity == 1) ? "" : (" (" + num3.ToString("N0") + " each)"));
                Label label4 = new Label
                {
                    Text     = text2,
                    AutoSize = true,
                    Tag      = current2,
                    Name     = "SellPrice" + current2.name
                };
                label4.Click += new EventHandler(TableItemSelected);
                TablePanel.Controls.Add(label4, 0, row);
                num = row;
                row = num + 1;
            }
            int num4;

            if (sortBox.Text == "Insta-buy")
            {
                num4 = c.instaBuyMargin();
            }
            else if (sortBox.Text == "Insta-sell")
            {
                num4 = c.instaSellMargin();
            }
            else if (sortBox.Text == "Insta-transaction")
            {
                num4 = c.instaTransactionMargin();
            }
            else
            {
                num4 = c.margin();
            }

            Label control = new Label
            {
                Text      = "Profit: " + num4.ToString("N0"),
                AutoSize  = true,
                Name      = "Margin",
                ForeColor = ((num4 >= 0) ? Color.Green : ((num4 == 0) ? SystemColors.Control : Color.Red))
            };

            TablePanel.Controls.Add(control, 0, row);
        }