Exemple #1
0
        private void button_CompleteSale_Click(object sender, EventArgs e)
        {
            var idQuery   = "SELECT CardIDs FROM Carts WHERE ID = '" + ID + "'";
            var idResults = DatabaseManager.RunQuery(idQuery).Rows;
            var idArray   = idResults[0][0].ToString().Split('|');

            var cardPrices = "";

            for (int i = 0; i < dataGridView_Items.Rows.Count - 1; i++)
            {
                var row = dataGridView_Items.Rows[i];

                if (i != 0)
                {
                    cardPrices += "|";
                }
                cardPrices += row.Cells["Price"].Value.ToString();

                var id = idArray[i + 1];
                if (String.IsNullOrWhiteSpace(id))
                {
                    continue;
                }

                int multiverseID;
                var updateQuery = "";
                if (int.TryParse(id, out multiverseID))
                {
                    if (row.Cells["CardName"].Value.ToString().Contains("*F*"))
                    {
                        updateQuery = "UPDATE Mtg SET foilInventory = (foilInventory - " + row.Cells["Amount"].Value.ToString() + ") WHERE multiverseID = '" + multiverseID + "'";
                    }
                    else
                    {
                        updateQuery = "UPDATE Mtg SET inventory = (inventory - " + row.Cells["Amount"].Value.ToString() + ") WHERE multiverseID = '" + multiverseID + "'";
                    }
                }
                else
                {
                    updateQuery = "UPDATE Non_Mtg SET inventory = (inventory - " + row.Cells["Amount"].Value.ToString() + ") WHERE MD5Hash = '" + id + "'";
                }

                DatabaseManager.RunQuery(updateQuery);
            }

            var query = "UPDATE Carts SET " +
                        "CardPrices = '" + cardPrices + "', " +
                        "Subtotal = '" + textBox_PriceSubtotal.Text + "', " +
                        "Taxes = '" + textBox_PriceTaxes.Text + "', " +
                        "Total = '" + textBox_PriceTotal.Text + "', " +
                        "Status = 'Sale Complete' " +
                        "WHERE ID = '" + ID + "'";

            DatabaseManager.RunQuery(query);

            SaveCustomerData();
            CartManager.StatusChanged();
            Close();
        }