예제 #1
0
    // Takes a location index and then matches it to one in the productlocation table and updates the menu
    // so that it displays what a particular location has
    void WriteFromDataBaseToMenu(string locIndex, GameObject menu, bool isSelling)
    {
        string[,] arrMenuData = _dataBaseConnector.DataBaseProductLocationSelect("LocationID", locIndex);
        int[] rowChildIndex = FindRowsWithinMenu(menu);

        // Goes through each item in a city or shop and writes them to each row
        for (int i = 0; i < 4; i++)
        {
            GameObject tempRow = menu.transform.GetChild(rowChildIndex[i]).gameObject;
            string[,] getProduct = _dataBaseConnector.DataBaseProductsSelect("ProductID", arrMenuData[i, 0]);
            string[] playerInv  = _dataBaseConnector.DataBasePlayerInventorySelect("ProductID", arrMenuData[i, 0]);
            string   itemString = getProduct[0, 1];
            float    priceFloat = float.Parse(arrMenuData[i, 3]);
            int      stockInt   = 0;

            // If the location is a city then take the stock from the player inventory
            // Otherwise take the stock from the productLocation table
            stockInt = int.Parse(isSelling ? playerInv[2] : arrMenuData[i, 2]);

            WriteRow(tempRow, itemString, priceFloat, stockInt);
        }
    }