//define a method that load the combo box with the existing food types
        private void frmChangeFoodItem_Load(object sender, EventArgs e)
        {
            //load food type combo box with food types and description
            DataSet ds = new DataSet();

            ds = FoodTypes.getAllFoodType(ds);

            for (int i = 0; i < ds.Tables["ss"].Rows.Count; i++)
            {
                cboChangeFoodItemType.Items.Add(ds.Tables[0].Rows[i][0].ToString().PadLeft(0) + " : " + ds.Tables[0].Rows[i][1].ToString());
                cboChangeFoodItemFoodType.Items.Add(ds.Tables[0].Rows[i][0].ToString() + " : " + ds.Tables[0].Rows[i][1].ToString());
            }
        }
Beispiel #2
0
        private void btnFdTypeSubmit_Click(object sender, EventArgs e)
        {
            //input validation

            //foodtype is empty
            if (txtFoodType.Text.Equals(""))
            {
                MessageBox.Show("Food Type must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //foodtype is all char letter
            else if (!txtFoodType.Text.All(Char.IsLetter))
            {
                MessageBox.Show("Food Type must only be alphabetic character", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //foodtype description is empty
            else if (txtFdTypeDesc.Text.Equals(""))
            {
                MessageBox.Show("Food Description must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //foodtype exist in the database
            else if (FoodTypes.isFoodTypeExist(txtFoodType.Text))
            {
                MessageBox.Show("Food Type already existed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //valid input!
            //display confirmation message
            else
            {
                MessageBox.Show("Valid Food Type! Food type has been inputed", "Food Type input success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            //save food type detail in food type files
            txtFoodType.Text.ToUpper();
            FoodTypes foodtype = new FoodTypes(Convert.ToString(txtFoodType.Text[0]), txtFdTypeDesc.Text);

            //insert new foodtype into FoodTypes table in the database;
            foodtype.addNewFoodType();

            //reset user interface
            txtFoodType.Clear();
            txtFdTypeDesc.Clear();
            txtFoodType.Focus();
        }