public string addTransaction(Transaction_single transaction)
            {
                string writeBack =STRING_EMPTY;
                if (Type == "register")
                {
                    if (transaction.Process == "C")
                    {
                        Register_AllTransactions.Clear();
                        curtotal = 0;
                        subtotal = 0;
                        discount = 0;
                        MemberID = STRING_EMPTY;
                    }
                    else if (transaction.Process == "Z")
                    {
                        Transaction_single tempTrans = barcodeAlreadyPresent(transaction.Barcode);
                        string price, total;

                        if (tempTrans == null)
                        {
                            curtotal = getSubtotalPriceForProduct(transaction.Barcode,
                                Convert.ToDecimal(transaction.Quantity));
                            subtotal += curtotal;
                            transaction.Total = curtotal.ToString();

                            Register_AllTransactions.Push(transaction);

                            price = (decimal.Round((Convert.ToDecimal(transaction.Price)), 0)).ToString();
                            total = (decimal.Round((Convert.ToDecimal(transaction.Total)), 0)).ToString();
                        }
                        else
                        {
                            curtotal = getSubtotalPriceForProduct(transaction.Barcode,
                                Convert.ToDecimal(transaction.Quantity)+
                                Convert.ToDecimal(tempTrans.Quantity));
                            subtotal += curtotal - Convert.ToDecimal(tempTrans.Total);
                            tempTrans.Total = curtotal.ToString();

                            price = (decimal.Round((Convert.ToDecimal(tempTrans.Price)), 0)).ToString();
                            total = (decimal.Round((Convert.ToDecimal(tempTrans.Total)), 0)).ToString();
                        }
                        if (price.Length >= 6)
                        {
                            price = price.Substring(0, 6);
                        }
                        else
                        {
                            string temp = STRING_EMPTY;
                            for (int i = price.Length; i < 6; i++)
                                temp += "0";

                            price = temp + price;
                        }
                        if (total.Length > 6)
                        {
                            total = total.Substring(0, 6);
                        }
                        else
                        {
                            string temp = STRING_EMPTY;
                            for (int i = total.Length; i < 6; i++)
                                temp += "0";

                            total = temp + total;
                        }

                        //SerialPortWrite.DiscardOutBuffer();
                        //SerialPortWrite.DiscardInBuffer();
                        writeBack =
                            this.getRegisterId() + "SH" + total + price + "Z;";
                        //SerialPortWrite.Write(writeBack);
                    }
                    else if (transaction.Process == "S")
                    {
                        string sTotal = Convert.ToInt32(subtotal).ToString();
                        if (sTotal.Length >= 6)
                        {
                            sTotal = sTotal.Substring(0, 6);
                        }
                        else
                        {
                            string temp = STRING_EMPTY;
                            for (int i = sTotal.Length; i < 6; i++)
                                temp += "0";
                            sTotal = temp + sTotal;
                        }

                        writeBack = this.getRegisterId() + "SH" + sTotal + "000000S;";
                    }
                    else if (transaction.Process == "T")
                    {
                        if (!CashierID.Equals("1") && Register_AllTransactions.Count > 0)
                        {
                            string command = _transactionForm.getInsertTransString(CashierID);
                            long transID = _singletonConnection.insertToDB(command);

                            while (Register_AllTransactions.Count != 0)
                            {
                                //update database
                                Register_AllTransactions.Pop().processTransaction(
                                    transID, discount);
                            }

                            string oTotal = (decimal.Round((Convert.
                                ToDecimal(subtotal) * (1 - discount)),
                                0)).ToString();
                            if (oTotal.Length >= 6)
                            {
                                oTotal = oTotal.Substring(0, 6);
                            }
                            else
                            {
                                string temp = STRING_EMPTY;
                                for (int i = oTotal.Length; i < 6; i++)
                                    temp += "0";
                                oTotal = temp + oTotal;
                            }

                            writeBack = this.getRegisterId() + "SH" + oTotal + "000000T;";

                            curtotal = 0;
                            subtotal = 0;
                            MemberID = STRING_EMPTY;
                        }
                        else
                        {
                            writeBack = this.getRegisterId() + "SH000000000000T;";
                        }
                    }
                    else if (transaction.Process == "M")
                    {
                        MemberID = transaction.Barcode.Substring(0, 6);
                        string query = _memberAccess.getDiscountQuery(
                            (Convert.ToInt32(MemberID)).ToString());

                        MySqlDataReader queryOutcome =
                            _singletonConnection.queryResult(query);
                        discount = 0;
                        writeBack = this.getRegisterId() + "SH";
                        if (queryOutcome != null && queryOutcome.Read())
                        {
                            discount = Convert.ToDecimal(queryOutcome[0]);
                            writeBack += "111111111111M;";
                        }
                        else
                        {
                            writeBack += "000000000000M;";
                        }
                    }
                    else if (transaction.Process == "K")
                    {
                        CashierID = transaction.Barcode.Substring(0, 4);
                        string query = "SELECT id FROM Cashier WHERE id = " + CashierID;
                        MySqlDataReader queryOutcome =
                            _singletonConnection.queryResult(query);

                        if (queryOutcome != null && queryOutcome.Read())
                        {
                            writeBack = this.getRegisterId() + "SH" + "111111111111K;";
                        }
                        else
                        {
                            CashierID = "1";
                            writeBack = this.getRegisterId() + "SH" + "000000000000F;";
                        }
                    }
                }

                return writeBack;
            }
        private string ReceiveMessage()
        {
            string response = STRING_EMPTY;

            string ID = "";
            string barcode = "";
            string quantity = "";
            string process = "";

            //records which cash register ID to record the transaction and send back
            int convID = 0;
            for (int i = 2; i < 4; i++)
            {
                convID = convID * 256;
                convID += (int)RxString[i];
            }
            ID = convID.ToString();

            //writes barcode of item
            barcode = RxString.Substring(4, 8);
            quantity = RxString.Substring(12, 4);
            process = RxString[16].ToString();

            string price = STRING_NULL;//placeholder
            decimal converted = 0;
            //Check database
            if (process == "Z")
            {
                string query = "SELECT sellingPrice FROM Product WHERE barcode = "
                    + barcode + " AND Product.currentStock >= " + quantity
                    + " AND 0 < " + quantity;
                MySqlDataReader queryResult = _singletonConnection.queryResult(query);
                try
                {
                    if (queryResult != null && queryResult.Read())
                    {
                        price = queryResult[0].ToString();
                        converted =
                            (Convert.ToDecimal(price) * 100);
                        converted.ToString();
                    }
                    else
                    {
                        return RxString.Substring(2,2) + "SH" + "000000000000E;";
                    }
                }
                catch (Exception e)
                {
                    Console.Write(e);
                    return RxString.Substring(2, 2) + "SH" + "000000000000E;";
                }
            }

            //add transaction detail to transaction holder buffer,updates database within addTransaction
            for (int i = 0; i < AllRegister_AllTransactions.Count; i++)
            {
                if (AllRegister_AllTransactions[i].ID.Equals(ID))
                {
                    Transaction_single newtransaction = new Transaction_single(ID, barcode, converted.ToString(), quantity, process);
                    response = AllRegister_AllTransactions[i].addTransaction(newtransaction);
                }
            }

            return response;
        }