예제 #1
0
        public static FoodItems getFood(int ItemId)
        {
            FoodItems fooditem = new FoodItems();

            OracleConnection conn = new OracleConnection(DBConnect.oradb);

            conn.Open();
            //connection name conn.open()
            String        strSQL = "SELECT * FROM FoodItems WHERE ItemId = " + ItemId;
            OracleCommand cmd    = new OracleCommand(strSQL, conn);

            //exceute the SQL Query and put result in OracleDataReader object
            OracleDataReader dr = cmd.ExecuteReader();

            //read the first (only) value returned by query
            //If first itemId, assign value 1, otherwise add 1 to MAX value
            dr.Read();
            if (!dr.IsDBNull(0))
            {
                fooditem.setItemId(ItemId);
                fooditem.setItemName(dr.GetString(1));
                fooditem.setDescription(dr.GetString(2));
                fooditem.setFoodType(dr.GetString(3));
                fooditem.setPrice(dr.GetDecimal(4));
                fooditem.setStatus(dr.GetString(5));
            }

            //close db connection
            conn.Close();

            //return next ItemId
            return(fooditem);
        }
예제 #2
0
        //Define a method that will extract the food type and store into the foodtype variable in this class
        private void cboAddFoodItemType_SelectedIndexChange(object sender, EventArgs e)
        {
            //if resetting combo, ignore...
            if (cboAddFoodItemType.SelectedIndex == 1)
            {
                return;
            }

            //find food type details , create a new fooditems and store the food type details into food item
            FoodItems newFoodItem = new FoodItems();

            newFoodItem.setFoodType(cboAddFoodItemType.Text.Substring(0, 1));

            //Validation to prevent the food type is empty
            if (newFoodItem.getFoodType() == "")
            {
                MessageBox.Show("No food type selected", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cboAddFoodItemType.Focus();
                return;
            }
        }