public ActionResult Edit([Bind(Include = "ID_BenhNhan,HoTen,GioiTinh,NamSinh,DiaChi,Deleted")] HoSoBenhNhan hoSoBenhNhan)
        {
            if (ModelState.IsValid)
            {
                db.Entry(hoSoBenhNhan).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            List <SelectListItem> Gender = new List <SelectListItem>()
            {
                new SelectListItem
                {
                    Value = "true",
                    Text  = "Nam"
                },
                new SelectListItem
                {
                    Value = "false",
                    Text  = "Nữ"
                }
            };

            ViewBag.GioiTinh = new SelectList(Gender, "Value", "Text");
            return(View(hoSoBenhNhan));
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "ID_User,Username,Password,Roles")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "ID_CachDung,TenCachDung,Deleted")] CachDung cachDung)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cachDung).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cachDung));
 }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "ID,TypeName")] UserType userType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userType));
 }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "ID_BenhNhan,HoTen,GioiTinh,NamSinh,DiaChi,NgayKham")] HoSoBenhNhan hoSoBenhNhan)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hoSoBenhNhan).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("DanhSachKhamBenh", "HoSoBenhNhan"));
     }
     return(View(hoSoBenhNhan));
 }
 public ActionResult Edit([Bind(Include = "ID_DonVi,TenDonVi,Deleted")] DonVi donVi)
 {
     if (ModelState.IsValid)
     {
         db.Entry(donVi).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(donVi));
 }
Ejemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "ID_ThamSo,GiaTri,GhiChu")] ThamSo thamSo)
 {
     if (ModelState.IsValid)
     {
         db.Entry(thamSo).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(thamSo));
 }
 public ActionResult Edit([Bind(Include = "ID_Benh,TenBenh")] Benh benh)
 {
     if (ModelState.IsValid)
     {
         db.Entry(benh).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(benh));
 }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "ID_Thuoc,ID_DonVi,TenThuoc,SoLuong,DonGia")] Thuoc thuoc)
 {
     if (ModelState.IsValid)
     {
         db.Entry(thuoc).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_DonVi = new SelectList(db.DonVis, "ID_DonVi", "TenDonVi", thuoc.ID_DonVi);
     return(View(thuoc));
 }
Ejemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "ID_HoaDon,ID_PhieuKham,TienKham,TienThuoc,DoanhThu,GhiChu")] HoaDon hoaDon)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hoaDon).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_PhieuKham = new SelectList(db.PhieuKhamBenhs, "ID_PhieuKham", "TrieuChung", hoaDon.ID_PhieuKham);
     return(View(hoaDon));
 }
Ejemplo n.º 11
0
 public ActionResult Edit([Bind(Include = "IDPhieuTN,ID_BenhNhan,NgayTiepNhan,Deleted")] PhieuTiepNhan phieuTiepNhan)
 {
     if (ModelState.IsValid)
     {
         db.Entry(phieuTiepNhan).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_BenhNhan = new SelectList(db.HoSoBenhNhans.Where(x => x.Deleted == false), "ID_BenhNhan", "HoTen", phieuTiepNhan.ID_BenhNhan);
     return(View(phieuTiepNhan));
 }
 public ActionResult Edit([Bind(Include = "UserName,Password,UserTypeID")] UserDetail userDetail)
 {
     if (ModelState.IsValid)
     {
         userDetail.Password        = Encryptor.MD5Hash(userDetail.Password);
         db.Entry(userDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserTypeID = new SelectList(db.UserTypes, "ID", "TypeName", userDetail.UserTypeID);
     return(View(userDetail));
 }
 public ActionResult Edit([Bind(Include = "ID_PhieuKham,ID_BenhNhan,ID_Benh,TrieuChung")] PhieuKhamBenh phieuKhamBenh)
 {
     if (ModelState.IsValid)
     {
         db.Entry(phieuKhamBenh).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_Benh     = new SelectList(db.Benhs, "ID_Benh", "TenBenh", phieuKhamBenh.ID_Benh);
     ViewBag.ID_BenhNhan = new SelectList(db.HoSoBenhNhans, "ID_BenhNhan", "HoTen", phieuKhamBenh.ID_BenhNhan);
     return(View(phieuKhamBenh));
 }
Ejemplo n.º 14
0
 public ActionResult Edit([Bind(Include = "ID_PhieuKham,ID_Thuoc,ID_CachDung,SoLuongThuocLay")] CT_PhieuKhamBenh cT_PhieuKhamBenh)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cT_PhieuKhamBenh).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_CachDung  = new SelectList(db.CachDungs, "ID_CachDung", "TenCachDung", cT_PhieuKhamBenh.ID_CachDung);
     ViewBag.ID_PhieuKham = new SelectList(db.PhieuKhamBenhs, "ID_PhieuKham", "TrieuChung", cT_PhieuKhamBenh.ID_PhieuKham);
     ViewBag.ID_Thuoc     = new SelectList(db.Thuocs, "ID_Thuoc", "TenThuoc", cT_PhieuKhamBenh.ID_Thuoc);
     return(View(cT_PhieuKhamBenh));
 }
        public ActionResult Save(int?IDPhieu, int idPhieuTN, DateTime date, int IDBenh, string TrieuChung, CT_PhieuKhamBenh[] chitietphieukham)
        {
            string result = "Error! Thêm chi tiết không thể hoàn tất!";

            if (IDPhieu == null && idPhieuTN != 0 && date != null && chitietphieukham != null && IDBenh != 0)
            {
                PhieuKhamBenh phieuKham = new PhieuKhamBenh();

                int tienThuoc = 0;
                phieuKham.IDPhieuTN  = idPhieuTN;
                phieuKham.ID_Benh    = IDBenh;
                phieuKham.NgayKham   = date;
                phieuKham.TrieuChung = TrieuChung;
                db.PhieuKhamBenhs.Add(phieuKham);
                db.SaveChanges();
                int    idPhieuKham = phieuKham.ID_PhieuKham;
                HoaDon hoaDon      = new HoaDon();
                hoaDon.ID_PhieuKham = idPhieuKham;
                int tienKham = Convert.ToInt32(db.ThamSoes.Where(x => x.GhiChu.Contains("Tien kham")).SingleOrDefault().GiaTri);;
                hoaDon.TienKham = tienKham;
                foreach (var ct in chitietphieukham)
                {
                    CT_PhieuKhamBenh C = new CT_PhieuKhamBenh();
                    C.ID_PhieuKham    = idPhieuKham;
                    C.ID_Thuoc        = ct.ID_Thuoc;
                    C.DonGiaBan       = ct.DonGiaBan;
                    C.SoLuongThuocLay = ct.SoLuongThuocLay;
                    C.ThanhTien       = ct.ThanhTien;
                    db.CT_PhieuKhamBenh.Add(C);
                    tienThuoc += ct.ThanhTien;
                }
                hoaDon.TienThuoc = tienThuoc;
                hoaDon.TongTien  = tienKham + tienThuoc;
                db.HoaDons.Add(hoaDon);
                db.SaveChanges();
                Session["ID_PhieuKham"] = idPhieuKham;
                result = "Thành công! Thêm chi tiết hoàn tất!";
            }
            else
            {
                try
                {
                    int tienThuoc = 0;
                    //Trường hợp đã remove 1 hay nhiều ChiTietKhamBenh nào đó ...
                    CT_PhieuKhamBenh[] C = db.CT_PhieuKhamBenh.Where(x => x.ID_PhieuKham == IDPhieu && x.Deleted == false).ToList().ToArray();

                    List <int> listC       = Helper.GhiIDThuocThanhMang(C);
                    List <int> listChiTiet = Helper.GhiIDThuocThanhMang(chitietphieukham);
                    //Tìm phần tử có trong C mà ko có trong chitietphieusua
                    var excepts = listC.Except(listChiTiet).ToArray();
                    if (excepts.Count() != 0)
                    {
                        foreach (var e in excepts)
                        {
                            CT_PhieuKhamBenh chiTietPhieuKham = db.CT_PhieuKhamBenh.Find(IDPhieu, e);
                            chiTietPhieuKham.Deleted = true;
                            //Update lại thành Số lượng tồn
                            Helper.UpdateAfterDeleteChiTietPhieu(chiTietPhieuKham);
                            //Flag
                            db.Entry(chiTietPhieuKham).State = EntityState.Modified;
                        }

                        db.SaveChanges();
                    }
                    foreach (CT_PhieuKhamBenh chiTiet in chitietphieukham)
                    {
                        int idThuoc = chiTiet.ID_Thuoc;

                        //Nếu đã có ChiTietPhieu này thi chỉ thực hiện edit
                        if (db.CT_PhieuKhamBenh.Any(x => x.ID_PhieuKham == IDPhieu && x.ID_Thuoc == idThuoc))
                        {
                            CT_PhieuKhamBenh ct = db.CT_PhieuKhamBenh.Find(IDPhieu, idThuoc);
                            if (ct.Deleted == false) //Chi Edit vs ChiTiet chua xoa
                            {
                                ct.DonGiaBan       = chiTiet.DonGiaBan;
                                ct.SoLuongThuocLay = chiTiet.SoLuongThuocLay;
                                ct.ThanhTien       = chiTiet.ThanhTien;
                                db.Entry(ct).State = EntityState.Modified;
                            }
                            else //Neu xoa roi (Deleted = true) thi xoa hẳn giá trị đó, va them lai => To fire trigger, update Soluongton, ...
                            {
                                //Xóa
                                db.CT_PhieuKhamBenh.Remove(ct);
                                db.SaveChanges();
                                //Gán & Add lại
                                ct.DonGiaBan       = chiTiet.DonGiaBan;
                                ct.SoLuongThuocLay = chiTiet.SoLuongThuocLay;
                                ct.ThanhTien       = chiTiet.ThanhTien;
                                ct.Deleted         = false;
                                db.CT_PhieuKhamBenh.Add(ct);
                                db.SaveChanges();
                            }
                        }
                        else //Nếu không có thì thêm mới
                        {
                            CT_PhieuKhamBenh ChiTiet = new CT_PhieuKhamBenh();
                            ChiTiet.ID_PhieuKham    = (int)IDPhieu;
                            ChiTiet.ID_Thuoc        = chiTiet.ID_Thuoc;
                            ChiTiet.DonGiaBan       = chiTiet.DonGiaBan;
                            ChiTiet.SoLuongThuocLay = chiTiet.SoLuongThuocLay;
                            ChiTiet.ThanhTien       = chiTiet.ThanhTien;
                            db.CT_PhieuKhamBenh.Add(ChiTiet);
                        }
                        db.SaveChanges();
                    }
                    HoaDon phieuThuTien = db.HoaDons.Where(x => x.ID_PhieuKham == IDPhieu).SingleOrDefault();
                    var    chiTietKham  = db.CT_PhieuKhamBenh.Where(x => x.ID_PhieuKham == IDPhieu && x.Deleted == false);
                    foreach (var ele in chiTietKham)
                    {
                        tienThuoc += ele.ThanhTien;
                    }
                    phieuThuTien.TienThuoc = tienThuoc;
                    phieuThuTien.TongTien  = tienThuoc + phieuThuTien.TienKham;
                    db.SaveChanges();
                    Session["ID_PhieuKham"] = IDPhieu;
                    result = "Sửa thành công!!";
                }
                catch (Exception ex)
                {
                    ViewBag.Errors = ex.Message;
                    throw ex;
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }