コード例 #1
0
        public DataSet GetFoodInfo(DTO_Food food)
        {
            DataSet result = new DataSet();
            string  sql    = "exec LayThongTinMonAn @DanhMuc";

            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@DanhMuc", food.DanhMuc),
            };
            DataAccess data = new DataAccess();

            result = data.GetDataSet(sql, para);
            return(result);
        }
コード例 #2
0
        public int AddFood(DTO_Food food)
        {
            int    result = -1;
            string sql    = "Exec ThemMon @MaMon,@TenMon, @DanhMuc, @GiaTien, @HinhAnh, @MoTa";

            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@MaMon", food.MaMon),
                new SqlParameter("@TenMon", food.TenMon),
                new SqlParameter("@DanhMuc", food.DanhMuc),
                new SqlParameter("@GiaTien", food.GiaTien),
                new SqlParameter("@HinhAnh", food.HinhAnh),
                new SqlParameter("@MoTa", food.MoTa),
            };
            DataAccess data = new DataAccess();

            result = data.Execute(sql, para);
            return(result);
        }
コード例 #3
0
        private void load()
        {
            SQLAction laydanhmuc = new SQLAction();
            DataSet   table      = laydanhmuc.GetCategory();


            if (table.Tables[0].Rows.Count > 0 && table.Tables.Count > 0)
            {
                for (int i = 0; i < table.Tables[0].Rows.Count; i++)
                {
                    Button button = new Button();
                    button.Size = new Size(80, 50);
                    button.Text = table.Tables[0].Rows[i][0].ToString();
                    pl_Chon.Controls.Add(button);
                    string DM = table.Tables[0].Rows[i][0].ToString();

                    button.Click += (sender, args) =>
                    {
                        pl_Menu.Controls.Clear();
                        FlowLayoutPanel pl = new FlowLayoutPanel();
                        pl.Size = new Size(400, 430);

                        DTO_Food food = new DTO_Food();
                        food.DanhMuc = button.Text;
                        SQLAction getfood = new SQLAction();
                        DataSet   result  = new DataSet();
                        result = getfood.GetFoodInfo(food);
                        for (int k = 0; k < result.Tables[0].Rows.Count; k++)
                        {
                            ChooseFood choose = new ChooseFood();
                            choose.TENMON  = result.Tables[0].Rows[k][1].ToString();
                            choose.GIATIEN = int.Parse(result.Tables[0].Rows[k][3].ToString());
                            System.Byte[] arr = (result.Tables[0].Rows[k][4]) as System.Byte[];
                            choose.HINHANH = arr;
                            pl.Controls.Add(choose);
                        }
                        pl_Menu.Controls.Add(pl);
                    };
                }
            }
        }
コード例 #4
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);
     }
 }