Beispiel #1
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtMaMon.Text))
     {
         lb_MaMon.ForeColor = Color.Red;
     }
     else
     {
         lb_MaMon.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(txtTenMon.Text))
     {
         lb_TenMon.ForeColor = Color.Red;
     }
     else
     {
         lb_TenMon.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(txtMoTa.Text))
     {
         lb_MoTa.ForeColor = Color.Red;
     }
     else
     {
         lb_MoTa.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(txtGiaTien.Text))
     {
         lb_GiaTien.ForeColor = Color.Red;
     }
     else
     {
         lb_GiaTien.ForeColor = Color.Black;
     }
     if (string.IsNullOrEmpty(cbb_DanhMuc.Text))
     {
         lb_DanhMuc.ForeColor = Color.Red;
     }
     else
     {
         lb_DanhMuc.ForeColor = Color.Black;
     }
     if (lb_MaMon.ForeColor == Color.Black && lb_DanhMuc.ForeColor == Color.Black && lb_MoTa.ForeColor == Color.Black && lb_GiaTien.ForeColor == Color.Black && lb_TenMon.ForeColor == Color.Black)
     {
         DTO_Food addfood = new DTO_Food();
         addfood.MaMon   = txtMaMon.Text;
         addfood.TenMon  = txtTenMon.Text;
         addfood.DanhMuc = cbb_DanhMuc.Text;
         addfood.MoTa    = txtMoTa.Text;
         addfood.GiaTien = (int)double.Parse(txtGiaTien.Text);
         //xử lí hình ảnh
         Image        img    = Image.FromFile(file);
         MemoryStream stream = new MemoryStream();
         img.Save(stream, ImageFormat.Jpeg);
         stream.Seek(0, SeekOrigin.Begin);
         byte[] imgByte = System.IO.File.ReadAllBytes(file);
         int    sizeImg = imgByte.Length;
         stream.Read(imgByte, 0, sizeImg);
         addfood.HinhAnh = imgByte;
         SQLAction add = new SQLAction();
         if (add.AddFood(addfood) != -1)
         {
             MessageBox.Show("Thêm món thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("Thất Bại, vui lòng thử lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show("Điền thiếu thông tin, vui lòng kiểm tra lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }