Beispiel #1
0
        /*Precondition:
         Postcondition: Adds the stock send in into the newOrderedStock list, also add it to the datagrid to be viewed */
        public void addStock(Stock newStock)
        {
            OrderedStock os = new OrderedStock(currOrder.orderID, newStock.stockID, 1, newStock.author, newStock.title, newStock.price, newStock.bookID, 0.00);
            newOrderedStock.Add(os);

            dataGridView1.Rows.Add(1, newStock.author, newStock.title, "$" + String.Format("{0:0.00}", newStock.price), newStock.bookID, "$0.00");
        }
Beispiel #2
0
        /*Precondition:
        Postcondition: Updates the passed in orderedStock details, new details already added onto the orderedStock, use the ID to update*/
        public void updateOrderedStock(OrderedStock orderedStock)
        {
            if (checkForTable("OrderedStock"))
            {
                int orderID = orderedStock.orderID;
                int stockID = orderedStock.stockID;
                int quantity = orderedStock.quantity;
                string author = SyntaxHelper.escapeSingleQuotes(orderedStock.author);
                string title = SyntaxHelper.escapeSingleQuotes(orderedStock.title);
                double price = orderedStock.price;
                string bookID = SyntaxHelper.escapeSingleQuotes(orderedStock.bookID);
                double discount = orderedStock.discount;
                int orderedStockID = orderedStock.orderedStockID;

                //Apostrophies cause program to crash
                string updateQuery = "UPDATE OrderedStock SET orderID =" + orderID + ", stockID = " + stockID + ", quantity = " + quantity + ", author = '" + author + "', title = '" + title +
                    "', price = '" + price + "', bookID = '" + bookID + "', discount = '" + discount + "' WHERE orderedStockID = " + orderedStockID;

                dbConnection.Open();
                SQLiteCommand updateCommand = new SQLiteCommand(updateQuery, dbConnection);
                updateCommand.ExecuteNonQuery();
                dbConnection.Close();
            }
        }
Beispiel #3
0
        /*Precondition:
         Postcondition: Returns a list of all the ordered stock */
        public List<OrderedStock> getAllOrderedStock()
        {
            List<OrderedStock> foundOrderedStock = new List<OrderedStock>();

            //Check to make sure orderedstock table exists
            if (checkForTable("OrderedStock"))
            {
                dbConnection.Open();

                //Execute SQL query
                string sql = "SELECT * FROM OrderedStock";
                SQLiteCommand command = new SQLiteCommand(sql, dbConnection);
                SQLiteDataReader reader = command.ExecuteReader();

                //Loop over and store results
                while (reader.Read())
                {
                    OrderedStock newOrderedStock = new OrderedStock(Convert.ToInt32(reader[0]), Convert.ToInt32(reader[1]), Convert.ToInt32(reader[2]), Convert.ToInt32(reader[3]), reader[4].ToString(),
                        reader[5].ToString(), Convert.ToDouble(reader[6]), reader[7].ToString(), Convert.ToDouble(reader[8]));

                    foundOrderedStock.Add(newOrderedStock);
                }

                dbConnection.Close();
            }

            //Return results
            return foundOrderedStock;
        }
Beispiel #4
0
        /*Precondition:
         Postcondition: Returns a list of orderedStock from the orderedBooks and data in datagrid */
        private List<OrderedStock> createOrderedStock(Order order)
        {
            List<OrderedStock> newOrderedStock = new List<OrderedStock>();

            //Get invoice/orderID for current order
            int nextOrderIDAndInvoiceNo = dbManager.getNextOrderID();

            int currRowIndex = 0;

            //Loop over all the books selected and create orderedStock from them
            foreach (Stock s in orderedBooks)
            {
                //Get quantity, price and discount from the datagrid
                int quantity = Convert.ToInt32(dataGridView1.Rows[currRowIndex].Cells[0].Value.ToString());
                string author = dataGridView1.Rows[currRowIndex].Cells[1].Value.ToString();
                string title = dataGridView1.Rows[currRowIndex].Cells[2].Value.ToString();
                string priceString = dataGridView1.Rows[currRowIndex].Cells[3].Value.ToString();
                double price = 0.00;
                if (priceString != "")
                {
                    if(priceString[0] == '$')
                        price = Convert.ToDouble(priceString.Substring(1));
                    else
                        price = Convert.ToDouble(priceString);
                }
                string bookID = dataGridView1.Rows[currRowIndex].Cells[4].Value.ToString();
                string discountString = dataGridView1.Rows[currRowIndex].Cells[5].Value.ToString();
                double discount = 0.00;
                if (discountString != "")
                {
                    if(discountString[0] == '$')
                        discount = Convert.ToDouble(discountString.Substring(1));
                    else
                        discount = Convert.ToDouble(discountString);
                }

                //Create the orderedStock and store
                OrderedStock o = new OrderedStock(nextOrderIDAndInvoiceNo, s.stockID, quantity, author, title, price, bookID, discount);
                newOrderedStock.Add(o);

                currRowIndex++;
            }

            return newOrderedStock;
        }