Ejemplo n.º 1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     Data.Cake c = GetCake();
     if (c == null)
     {
         return;
     }
     if (c.Img1 == null)
     {
         MessageBox.Show("Please choo a picture");
         return;
     }
     try { bool result = Cakedao.AddNewCake(c);
           if (result == true)
           {
               MessageBox.Show("Add successfull");
               getCakes();
           }
     }
     catch (Exception ex)
     {
         if (ex.Message.Contains("duplicate"))
         {
             MessageBox.Show("ID is exist");
         }
     }
 }
Ejemplo n.º 2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            Data.Cake c = GetCake();

            if (c.Img1 == null)
            {
                MessageBox.Show("null");
                Cakedao.UpdateCakeNoImg(c);
            }
            else
            {
                Cakedao.UpdateCake(c); MessageBox.Show("nkoull");
            }
            MessageBox.Show("Update Successfull");
            getCakes();
        }
Ejemplo n.º 3
0
        public Data.Cake GetCake()
        {
            string id = txtID.Text;

            if (id.Length == 0)
            {
                MessageBox.Show("Id is not blank");
                return(null);
            }
            string name = txtName.Text;

            if (name.Length == 0)
            {
                MessageBox.Show("Cake Name is not blank");
                return(null);
            }

            string category = txtCategory.SelectedItem.ToString();

            MessageBox.Show("cate" + category);

            string origin = txtOrigin.Text;

            if (origin.Length == 0)
            {
                MessageBox.Show("Cake Origin is not blank");
                return(null);
            }
            float price;

            try
            {
                price = float.Parse(txtPrice.Text);
                if (price <= 0)
                {
                    MessageBox.Show("Price must > 0");
                    return(null);
                }
            }
            catch
            {
                MessageBox.Show("Price is a number");
                return(null);
            }
            int quantity;

            try
            {
                quantity = int.Parse(txtQuantity.Text);
                if (quantity < 0)
                {
                    MessageBox.Show("Quantity must >= 0");
                    return(null);
                }
            }
            catch
            {
                MessageBox.Show("Quantity is a number");
                return(null);
            }


            MessageBox.Show(pBox1.ImageLocation);

            byte[] img1 = null;
            if (pBox1.ImageLocation != null)
            {
                img1 = convertImageToBytes(pBox1.ImageLocation);
            }

            string description = txtDescription.Text;

            Data.Cake c = new Data.Cake(id, name, price, origin, quantity, img1, category, description);
            return(c);
        }