예제 #1
0
        public ActionResult Create(CayThuoc caythuoc)   //FormCollection collection
        {
            DbCayThuoc db = new DbCayThuoc();

            //if (new System.IO.FileInfo("AnhMinhHoa").Length != 0)

            try
            {
                HttpPostedFileBase File    = Request.Files["AnhMinhHoa"];
                string             path    = Server.MapPath("~/images/" + File.FileName);
                string             img_url = "images/" + File.FileName;
                File.SaveAs(path);
                caythuoc.AnhMinhHoa = img_url;

                if (db.add(caythuoc))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.Caythuoc_add_message = "Không thể thêm dữ liệu 10";
                    return(View());
                }
            }
            catch
            {
                ViewBag.Caythuoc_add_message = "Không thể thêm dữ liệu";
                return(View());
            }
        }
예제 #2
0
        // GET: Caythuoc/Details/5
        public ActionResult Details(int id)
        {
            DbCayThuoc db   = new DbCayThuoc();
            var        data = db.detail(id);

            return(View(data));
        }
예제 #3
0
        public ActionResult Danhsach()
        {
            DbCayThuoc db   = new DbCayThuoc();
            var        data = db.getList();

            return(View(data));
        }
예제 #4
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            DbCayThuoc db   = new DbCayThuoc();
            var        data = db.detail(id);

            try
            {
                // TODO: Add delete logic here

                if (db.delete(id))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.Delete_Message = "Không thể xóa dữ liệu";
                    return(View(data));
                }
            }
            catch
            {
                ViewBag.Delete_Message = "Không thể xóa dữ liệu";
                return(View(data));
            }
        }
        // GET: Baithuoc/Details/5
        public ActionResult Details(int id)
        {
            DBBaithuoc db   = new DBBaithuoc();
            var        data = db.detail(id);

            //
            DbCaythuocBaithuoc cay_bai     = new DbCaythuocBaithuoc();
            DbCayThuoc         caythuoc_db = new DbCayThuoc();
            var        lis_cay             = cay_bai.cay_thuoc_theo_bai_thuoc(id);
            List <int> id_cay = new List <int>();

            foreach (var cay in lis_cay)
            {
                id_cay.Add(cay.ID_CayThuoc);
            }

            List <string> ten_cay = new List <string>();

            foreach (var id_cay_thuoc in id_cay)
            {
                var cay_thuoc = caythuoc_db.detail(id_cay_thuoc);
                ten_cay.Add(cay_thuoc.TenCayThuoc);
            }
            ViewBag.DsTenCay = ten_cay;


            //
            ViewBag.List_Cay = lis_cay;

            return(View(data));
        }
예제 #6
0
        // GET: Caythuoc/Edit/5
        public ActionResult Edit(int id)
        {
            DbCayThuoc db   = new DbCayThuoc();
            var        data = db.detail(id);

            if (data != null)
            {
                return(View(data));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
예제 #7
0
        public ActionResult Edit(CayThuoc caythuoc)
        {
            DbCayThuoc db       = new DbCayThuoc();
            var        old_data = db.detail(caythuoc.ID);

            //if (new System.IO.FileInfo("AnhMinhHoa").Length != 0)

            try
            {
                if (Request.Files["AnhMinhHoa"] != null)
                {
                    HttpPostedFileBase File    = Request.Files["AnhMinhHoa"];
                    string             path    = Server.MapPath("~/images/" + File.FileName);
                    string             img_url = "images/" + File.FileName;
                    File.SaveAs(path);
                    caythuoc.AnhMinhHoa = img_url;
                }
                else
                {
                    caythuoc.AnhMinhHoa = old_data.AnhMinhHoa;
                }


                if (db.edit(caythuoc))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.Caythuoc_add_message = "Không thể sửa dữ liệu 10";
                    return(View());
                }
            }
            catch
            {
                ViewBag.Caythuoc_add_message = "Không thể sửa dữ liệu";
                return(View());
            }
        }