Beispiel #1
0
        /// <summary>
        /// Decrements the stock record of the specified ID by the specified quantity. Assumed the
        /// connection has already been set up. Current has unhandled exceptions for timed out connections.
        /// Timeout currently set at 10000ms.
        /// </summary>
        /// <param name="stockID">The stock ID to request.</param>
        public bool DecrementStock(StockRecord record)
        {
            int rows = 0;

            try
            {
                //Send a request to update stock, expecting a confirmation. Also writes the number of rows updated to rows.
                if ((rows = _connection.SendReceiveObject<StockRecord, int>("DecrementStockRecord", "ReturnDecrementStockRecord", 10000, record)) != 0)
                {
                    View.SuccessNotify("Successfully decremented " + rows + " rows.", "Decrement successful");
                    return true;
                }
                //The server has failed to insert the stock in the database.
                else
                {
                    View.ErrorNotify("Data could not be updated in the database.\n Check the server for further details.",
                        "Database Error");
                }
            }
            catch (ExpectedReturnTimeoutException exception)
            {
                View.ErrorNotify("No confirmation recieved from server.\n Likly a connection issue, check the server status.",
                    "Connection Error");
            }

            return false;
        }
Beispiel #2
0
        public void TestEditReceipt()
        {
            ClientConnectionManager p = new ClientConnectionManager("127.0.0.1", 25565);

            Assert.IsTrue(p.ConnectToServer());

            p.InsertStock("Apple", 0.5, 1, 100);
            p.InsertStock("Orange", 0.7, 1.5, 100);
            p.InsertStock("Banana", 0.65, 1.2, 100);

            int lenReceipt = p.RequestStockInfo(-1).Count - 1;

            StockRecord aRecord = p.RequestStockInfo(-1)[lenReceipt];
            StockRecord bRecord = p.RequestStockInfo(-1)[lenReceipt - 1];
            StockRecord cRecord = p.RequestStockInfo(-1)[lenReceipt - 2];

            ItemSaleRecord a = new ItemSaleRecord(0, aRecord.StockID, 1, 1);
            ItemSaleRecord b = new ItemSaleRecord(0, bRecord.StockID, 1.5, 2);
            ItemSaleRecord c = new ItemSaleRecord(0, cRecord.StockID, 1.2, 1);


            List <ItemSaleRecord> s = new List <ItemSaleRecord>();

            s.Add(a);
            s.Add(b);
            s.Add(c);

            Assert.IsTrue(p.InsertReceipt(s));

            int lenReceiptNew = p.RequestReceiptInfo(-1).Count - 1;

            ReceiptRecord aReceipt = (ReceiptRecord)p.RequestReceiptInfo(-1)[lenReceiptNew];

            Assert.IsTrue(p.UpdateReceipt(aReceipt.SaleID));
        }
Beispiel #3
0
        public void TestDeleteStockItem()
        {
            ClientConnectionManager p = new ClientConnectionManager("127.0.0.1", 25565);

            Assert.IsTrue(p.ConnectToServer());

            p.InsertStock("Apple", 0.5, 1, 100);
            StockRecord lid = p.RequestStockInfo(-1)[0];

            Assert.IsTrue(p.DeleteStock(lid.StockID));
        }
Beispiel #4
0
        public void TestAddReceipt()
        {
            ClientConnectionManager p = new ClientConnectionManager("127.0.0.1", 25565);

            Assert.IsTrue(p.ConnectToServer());

            p.DeleteReceipt(-1);
            p.DeleteStock(-1);

            p.InsertStock("Apple", 0.5, 1, 100);
            p.InsertStock("Orange", 0.7, 1.5, 100);
            p.InsertStock("Banana", 0.65, 1.2, 100);

            int lenStock = p.RequestStockInfo(-1).Count - 1;

            List <StockRecord> records = p.RequestStockInfo(-1);
            StockRecord        aRecord = records[lenStock];
            StockRecord        bRecord = records[lenStock - 1];
            StockRecord        cRecord = records[lenStock - 2];

            ItemSaleRecord a = new ItemSaleRecord(0, aRecord.StockID, 1, 1);
            ItemSaleRecord b = new ItemSaleRecord(0, bRecord.StockID, 1.5, 2);
            ItemSaleRecord c = new ItemSaleRecord(0, cRecord.StockID, 1.2, 1);


            List <ItemSaleRecord> s = new List <ItemSaleRecord>();

            s.Add(a);
            s.Add(b);
            s.Add(c);

            Assert.IsTrue(p.InsertReceipt(s));


            int lenReceiptNew = p.RequestReceiptInfo(-1).Count - 1;

            //ReceiptRecord lastReceipt = (ReceiptRecord)p.RequestReceiptInfo(-1)[lenReceiptNew];
            Assert.IsTrue(p.RequestReceiptInfo(-1).Count == 1);
        }