Пример #1
0
        /// <summary>
        /// Updates a single stock item. Record specifies the details.
        /// </summary>
        /// <param name="table">The table to update from.</param>
        /// <param name="record">Stock record. StockID indicates stock to change; Quantity indicates decrement amount.</param>
        /// <returns>Number of rows updated. 0 if failed.</returns>
        public int Decrement(DatabaseTable table, StockRecord record)
        {
            int stockID = record.StockID;
            int qty     = record.Quantity;

            string query = "UPDATE " + table + " SET StockQty=StockQty-" + qty + " WHERE StockID=" + stockID + " AND StockQty > " + (qty - 1);

            return(RunNonQueryCommand(query));
        }
Пример #2
0
        /// <summary>
        /// Updates a single stock item. Record specifies the details.
        /// </summary>
        /// <param name="table">The table to update from.</param>
        /// <param name="record">Stock record. StockID indicates stock to change; Quantity indicates new amount.</param>
        /// <returns>Number of rows updated. 0 if failed.</returns>
        public int Update(DatabaseTable table, StockRecord record)
        {
            int stockID = record.StockID;
            int qty     = record.Quantity;

            string query = "UPDATE " + table + " SET StockQty=" + qty + " WHERE StockID=" + stockID;

            return(RunNonQueryCommand(query));
        }
Пример #3
0
        /// <summary>
        /// Inserts a stock record into the database.
        /// </summary>
        /// <param name="header">The packet header associated with the incoming message</param>
        /// <param name="connection">The connection used by the incoming message</param>
        /// <param name="record">The record to insert</param>
        private static void InsertStock(PacketHeader header, Connection connection, StockRecord record)
        {
            Console.WriteLine("\nInserting: " + record.StockName + record.Purchase + record.CurrentSell + record.Quantity + " for connection: " + connection.ToString() + "'.");
            DatabaseAccess dbconnect = new DatabaseAccess();

            if (dbconnect.Insert(record.StockName, record.Purchase, record.CurrentSell, record.Quantity) != 0)
            {
                Console.WriteLine("Success.");
                connection.SendObject("ReturnInsertStockRecord", true);
            }
            else
            {
                Console.WriteLine("Failed.");
                connection.SendObject("ReturnInsertStockRecord", false);
            }
            Console.WriteLine("Done");
        }
Пример #4
0
        /// <summary>
        /// Updates the stock quantity for the specified items of the specified amounts.
        /// </summary>
        /// <param name="header">The packet header associated with the incoming message</param>
        /// <param name="connection">The connection used by the incoming message</param>
        /// <param name="record">Stock record. StockID indicates stock to change; Quantity indicates new amount.</param>
        private static void UpdateStock(PacketHeader header, Connection connection, StockRecord record)
        {
            int rows = 0;

            Console.WriteLine("\nUpdating: " + record.StockID + " to " + record.Quantity + " for connection: " + connection.ToString() + "'.");
            DatabaseAccess dbconnect = new DatabaseAccess();

            if ((rows = dbconnect.Update(DatabaseTable.Stock, record)) != 0)
            {
                Console.WriteLine("Success.");
            }
            else
            {
                Console.WriteLine("Failed.");
            }

            connection.SendObject("ReturnUpdateStockRecord", rows);
            Console.WriteLine("Done");
        }