Beispiel #1
0
 public ActionResult Themmoibanh(BANH banh, HttpPostedFileBase fileUpload)
 {
     ViewBag.MaLB  = new SelectList(db.LOAIBANHs.ToList().OrderBy(n => n.TenLoaiBanh), "MaLB", "Tenloaibanh");
     ViewBag.MaNSX = new SelectList(db.NHASANXUATs.ToList().OrderBy(n => n.TenNSX), "MaNSX", "TenNSX");
     if (fileUpload == null)
     {
         ViewBag.Thongbao = "Vui lòng chọn ảnh bìa";
         return(View());
     }
     else
     {
         if (ModelState.IsValid)
         {
             var fileName = System.IO.Path.GetFileName(fileUpload.FileName);
             var path     = System.IO.Path.Combine(Server.MapPath("~/Hinhsanpham"), fileName);
             if (System.IO.File.Exists(path))
             {
                 ViewBag.Thongbao = "Hình ảnh đã tồn tại";
             }
             else
             {
                 fileUpload.SaveAs(path);
             }
             banh.Anhbia = fileName;
             db.BANHs.InsertOnSubmit(banh);
             db.SubmitChanges();
         }
         return(RedirectToAction("Banh"));
     }
 }
Beispiel #2
0
        public Giohang(int Mabanh)
        {
            iMabanh = Mabanh;
            BANH banh = data.BANHs.Single(n => n.Mabanh == iMabanh);

            lbTenbanh = banh.Tenbanh;
            lbAnhbia  = banh.Anhbia;
            dDongia   = double.Parse(banh.Giaban.ToString());
            iSoluong  = 1;
        }
Beispiel #3
0
        public ActionResult Xoabanh(int id)
        {
            BANH banh = db.BANHs.SingleOrDefault(n => n.Mabanh == id);

            ViewBag.Mabanh = banh.Mabanh;
            if (banh == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            return(View(banh));
        }
Beispiel #4
0
        public ActionResult Xacnhanxoa(int id)
        {
            BANH banh = db.BANHs.SingleOrDefault(n => n.Mabanh == id);

            ViewBag.Mabanh = banh.Mabanh;
            if (banh == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            db.BANHs.DeleteOnSubmit(banh);
            db.SubmitChanges();
            return(RedirectToAction("Banh"));
        }
Beispiel #5
0
        private void Add_Button(object sender, RoutedEventArgs e)
        {
            double money  = 0; // Lưu giá tiền
            int    amount = 0; // Lưu số lượng bánh

            int.TryParse(count.Text.Trim(), out amount);
            double.TryParse(price.Text.Trim(), out money);
            if (temp == null)
            {
                MessageBox.Show("Chưa chọn loại bánh", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (name.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa nhập tên bánh", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (ingredients.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa nhập thông tin cho bánh", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (amount == 0 && amount.GetType() == typeof(int))
            {
                MessageBox.Show("Sai định dạng số lượng bánh", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (money == 0 && money < 1000 && money.GetType() == typeof(double))
            {
                MessageBox.Show("Sai định dạng số tiền", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (unit.Text.Trim().Length == 0)
            {
                MessageBox.Show("Chưa nhập đơn vị tính", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else if (pathImage == "")
            {
                MessageBox.Show("Chưa thêm hình ảnh cho bánh", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                var    info       = new FileInfo(pathImage);
                string baseFolder = AppDomain.CurrentDomain.BaseDirectory;
                baseFolder += $"Image\\{temp.TENLOAI.Replace(" ", "")}\\";
                string nameImage = Guid.NewGuid().ToString();
                File.Copy(pathImage, baseFolder + nameImage + info.Extension);

                var newCake = new BANH
                {
                    ID       = DataProvider.Ins.DB.BANHs.Count() + 1,
                    MABANH   = $"BA{createID(DataProvider.Ins.DB.BANHs.Count() + 1)}",
                    TENBANH  = name.Text.Trim(),
                    SL_TON   = amount,
                    DONGIA   = money,
                    DVT      = unit.Text.Trim(),
                    HA_BANH  = $"{temp.TENLOAI.Replace(" ", "")}\\{nameImage + info.Extension}",
                    LOAIBANH = temp.MALOAI,
                    THONGTIN = ingredients.Text.Trim()
                };
                DataProvider.Ins.DB.BANHs.Add(newCake);
                DataProvider.Ins.DB.SaveChanges();
                resetTextBox();
                MessageBox.Show($"Thêm thành công món {newCake.TENBANH}", "Thành công", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Beispiel #6
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     DataContext = cake;
     temp        = DataProvider.Ins.DB.BANHs.ToList().Find(x => x.MABANH.Equals(cake.MABANH));
 }
Beispiel #7
0
        //public UpdateCake()
        //{
        //    InitializeComponent();
        //}

        public UpdateCake(BANH _cake)
        {
            cake = _cake;

            InitializeComponent();
        }