Ejemplo n.º 1
0
        public ActionResult Product(string id)
        {
            THUOC model = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44366/api/");
                //HTTP GET
                var responseTask = client.GetAsync("thuoc/getthuoc/" + id);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <THUOC>();
                    readTask.Wait();

                    model = readTask.Result;
                }
                else //web api sent error response
                {
                    //log response status here..

                    model = null;

                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }
            }
            return(View(model));
            //ViewBag.maThuoc = id;
            //return View();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(THUOC businessObject, IDataReader dataReader)
        {
            businessObject.ID = dataReader.GetInt32(dataReader.GetOrdinal(THUOC.THUOCFields.ID.ToString()));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(THUOC.THUOCFields.TEN.ToString())))
            {
                businessObject.TEN = dataReader.GetString(dataReader.GetOrdinal(THUOC.THUOCFields.TEN.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(THUOC.THUOCFields.HAMLUONG.ToString())))
            {
                businessObject.HAMLUONG = dataReader.GetString(dataReader.GetOrdinal(THUOC.THUOCFields.HAMLUONG.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(THUOC.THUOCFields.CACHSUDUNG.ToString())))
            {
                businessObject.CACHSUDUNG = dataReader.GetString(dataReader.GetOrdinal(THUOC.THUOCFields.CACHSUDUNG.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(THUOC.THUOCFields.SOLUONG.ToString())))
            {
                businessObject.SOLUONG = dataReader.GetInt32(dataReader.GetOrdinal(THUOC.THUOCFields.SOLUONG.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(THUOC.THUOCFields.HANSUDUNG.ToString())))
            {
                businessObject.HANSUDUNG = dataReader.GetInt32(dataReader.GetOrdinal(THUOC.THUOCFields.HANSUDUNG.ToString()));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal(THUOC.THUOCFields.GHICHU.ToString())))
            {
                businessObject.GHICHU = dataReader.GetString(dataReader.GetOrdinal(THUOC.THUOCFields.GHICHU.ToString()));
            }
        }
Ejemplo n.º 3
0
        public void Update_TestCase4()
        {
            // Khởi tạo dao
            ThuocDAO dao = new ThuocDAO();
            // Insert một thuốc mới
            THUOC thuoc = new THUOC
            {
                MaThuoc  = TestCommon.LEN_10,
                TenThuoc = "TEST UT"
            };

            dao.Save(db, thuoc);
            // Update thuốc
            THUOC thuocUpdate = new THUOC
            {
                MaThuoc  = TestCommon.LEN_10,
                TenThuoc = "TEST UT UPDATE"
            };
            // Tạo biến lưu thông tin thuốc update
            string actual = dao.Save(db, thuocUpdate);
            // Biến kết quả
            string expected = "0000";

            // Test
            Assert.Equals(expected, actual);
        }
Ejemplo n.º 4
0
        private bool Check()
        {
            int soluong;

            try
            {
                soluong = Int32.Parse(txtSoLuong.Text);
            }
            catch
            {
                MessageBox.Show("Số lượng phải là số nguyên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            // kiểm tra kho
            THUOC thuoc = THUOCService.GetAllEntities().Where(p => p.ID == (int)cbxThuoc.EditValue).FirstOrDefault();

            if (soluong > thuoc.SOLUONG)
            {
                MessageBox.Show("Số lượng thuốc " + thuoc.TEN + " còn lại không đủ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        // sua thuoc
        private void button1_Click(object sender, EventArgs e)
        {
            // khoi tao doi tuong DTO
            THUOC bnDTO = new THUOC();

            if (txb_TenThuoc.Text == null || txb_TenThuoc.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txb_Gia.Text == null || txb_Gia.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            bnDTO.TenThuoc1 = txb_TenThuoc.Text;

            bnDTO.Gia1 = float.Parse(txb_Gia.Text);

            bnDTO.DonViTinh1 = cbb_DVT.SelectedItem.ToString();
            // goi lop nghiep vu BENHNHAN_BUS
            if (THUOC_BUS.SuaTHUOC(bnDTO) == true)
            {
                TaiDuLieuVaoDataGirdView();

                MessageBox.Show("Sửa thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }
            MessageBox.Show(" Sửa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Ejemplo n.º 6
0
        public ActionResult Add_SanPham(HttpPostedFileBase file, THUOC model)
        {
            try
            {
                if (file != null && file.ContentLength > 0)
                {
                    // lấy tên tệp tin
                    var fileName = Path.GetFileName(file.FileName);
                    // lưu trữ tệp tin vào folder ~/App_Data/uploads
                    var path = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
                    file.SaveAs(path);
                    context.THUOCs.Add(model);
                    context.SaveChanges();

                    var obj = context.THUOCs.Where(x => x.MaThuoc == model.MaThuoc).FirstOrDefault();
                    obj.URLAnh = fileName;
                    context.SaveChanges();
                    return(RedirectToAction("SanPham"));
                }
                else
                {
                    return(View("Add_SanPham"));
                }
            }
            catch
            {
                return(View("Add_SanPham"));
            }
        }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            THUOC tHUOC = db.THUOCs.Find(id);

            db.THUOCs.Remove(tHUOC);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
 private void CapNhat(ref THUOC cu, THUOC moi)
 {
     cu.TEN        = moi.TEN;
     cu.HAMLUONG   = moi.HAMLUONG;
     cu.CACHSUDUNG = moi.CACHSUDUNG;
     cu.HANSUDUNG  = moi.HANSUDUNG;
     cu.SOLUONG    = moi.SOLUONG;
     cu.GHICHU     = moi.GHICHU;
 }
Ejemplo n.º 9
0
 public View_ThemSuaThuoc_ViewModel()
 {
     PickedThuoc = new THUOC();
     Thuoc       = new CT_DONTHUOC();
     DS_Thuoc    = new ObservableCollection <THUOC>();
     DS_CachDung = new ObservableCollection <CACHDUNG>();
     ViewSource  = (CollectionView)CollectionViewSource.GetDefaultView(DS_Thuoc);
     LoadLists();
 }
Ejemplo n.º 10
0
        // PUT: api/TestAPI/5
        public void Put(string id, THUOC sp)
        {
            var obj = context.THUOCs.Find(id);

            obj.TenThuoc = sp.TenThuoc;


            context.SaveChanges();
        }
        public ActionResult ChiTiet(string maSP)
        {
            THUOC sp = data.THUOCs.SingleOrDefault(item => item.TENTHUOC == maSP);

            ////tạo biến kiểu dữ liệu sách cùng chủ đề
            //List<sanpham> dsSach_DM = data.sanphams.Where(s => s.loaisp == sp.loaisp).Take(5).ToList();
            //ViewBag.dm = dsSach_DM;
            return(View(sp));
        }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "MATHUOC,TENTHUOC,XUATXU,NSX,HSD,DONVITINH,DONGIATHUOC")] THUOC tHUOC)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tHUOC).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tHUOC));
 }
Ejemplo n.º 13
0
        public void Insert_TestCase2()
        {
            THUOC thuoc = new THUOC {
                MaThuoc = TestCommon.LEN_10
            };
            ThuocDAO dao      = new ThuocDAO();
            string   actual   = dao.Save(db, thuoc);
            string   expected = "1111";

            Assert.Equals(expected, actual);
        }
Ejemplo n.º 14
0
        public ActionResult Create([Bind(Include = "MATHUOC,TENTHUOC,XUATXU,NSX,HSD,DONVITINH,DONGIATHUOC")] THUOC tHUOC)
        {
            if (ModelState.IsValid)
            {
                db.THUOCs.Add(tHUOC);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tHUOC));
        }
Ejemplo n.º 15
0
 bool KiemTraTonTai(THUOC thuoc)
 {
     if (THUOC_BUS.KiemTraTonTai(thuoc) == true)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 16
0
        public void Delete_TestCase7()
        {
            ThuocDAO dao   = new ThuocDAO();
            THUOC    thuoc = new THUOC
            {
                MaThuoc  = TestCommon.LEN_10,
                TenThuoc = TestCommon.LEN_50
            };
            string actual = dao.Save(db, thuoc);

            Assert.Equals(null, actual);
        }
Ejemplo n.º 17
0
 bool KiemTraTonTai(THUOC thuoc)
 {
     if (THUOC_BUS.KiemTraTonTai(thuoc) == true)
     {
         return(true);
     }
     else
     {
         return(false);
     }
     //return QuanLyThongTinBacSi_BUS.KiemTraTonTai(bn);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of THUOC</returns>
        internal List <THUOC> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List <THUOC> list = new List <THUOC>();

            while (dataReader.Read())
            {
                THUOC businessObject = new THUOC();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return(list);
        }
Ejemplo n.º 19
0
        private THUOC getTHUOCByForm()
        {
            THUOC ans = new THUOC();

            ans.TEN        = txtTen.Text;
            ans.HAMLUONG   = txtHamLuong.Text;
            ans.CACHSUDUNG = txtCachSuDung.Text;
            ans.HANSUDUNG  = Int32.Parse(txtHanSuDung.Text);
            ans.SOLUONG    = Int32.Parse(txtSoLuong.Text);
            ans.GHICHU     = txtDonViTinh.Text;

            return(ans);
        }
Ejemplo n.º 20
0
 public ActionResult SanPhamAdd(THUOC model)
 {
     try
     {
         context.THUOCs.Add(model);
         context.SaveChanges();
         return(RedirectToAction("SanPham"));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 21
0
        public void HienThiChiTiet()
        {
            THUOC  thuoc        = QuanLyThuoc.LayThongTin1Thuoc(ma);
            string tenLoaiThuoc = QuanLyThuoc.LayTenLoaiThuoc(thuoc.MaLoai);

            txtMaThuoc.Text            = thuoc.MaThuoc;
            txtTenThuoc.Text           = thuoc.TenThuoc;
            txtCongDung.Text           = thuoc.CongDung;
            txtTacDungPhu.Text         = thuoc.TacDungPhu;
            txtDangThuoc.Text          = thuoc.DangThuoc;
            txtSoLuong.Text            = thuoc.SoLuong;
            cbbLoaiThuoc.SelectedIndex = cbbLoaiThuoc.FindStringExact(tenLoaiThuoc);
        }
Ejemplo n.º 22
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (!CheckLuaChon())
            {
                return;
            }

            if (btnSua.Text == "Sửa")
            {
                btnSua.Text     = "Lưu";
                btnXoa.Text     = "Hủy";
                btnThem.Enabled = false;

                UnlockControl();

                return;
            }

            if (btnSua.Text == "Lưu")
            {
                if (Check())
                {
                    btnSua.Text = "Sửa";
                    btnXoa.Text = "Xóa";

                    LockControl();

                    THUOC cu  = getTHUOCByID();
                    THUOC moi = getTHUOCByForm();
                    CapNhat(ref cu, moi);

                    if (THUOCService.Update(cu))
                    {
                        MessageBox.Show("Sửa thông tin thuốc thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Sửa thông tin thuốc thất bại\n",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvTHUOC();
                }

                return;
            }
        }
Ejemplo n.º 23
0
        // GET: THUOCs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            THUOC tHUOC = db.THUOCs.Find(id);

            if (tHUOC == null)
            {
                return(HttpNotFound());
            }
            return(View(tHUOC));
        }
Ejemplo n.º 24
0
 public bool ThemThuoc(THUOC thuoc)
 {
     try
     {
         MyDBContext context = new MyDBContext();
         context.THUOCs.Add(thuoc);
         context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 25
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (btnXoa.Text == "Xóa")
            {
                if (!CheckLuaChon())
                {
                    return;
                }

                THUOC        cu = getTHUOCByID();
                DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa thuốc " + cu.TEN + "?",
                                                  "Thông báo",
                                                  MessageBoxButtons.OKCancel,
                                                  MessageBoxIcon.Warning);

                if (rs == DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    THUOCService.Delete(new THUOCKeys(cu.ID));
                    MessageBox.Show("Xóa thông tin thuốc thành công",
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Xóa thông tin thuốc thất bại\n" + ex.Message,
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                LoadDgvTHUOC();

                return;
            }
            if (btnXoa.Text == "Hủy")
            {
                btnSua.Text  = "Sửa";
                btnThem.Text = "Thêm";
                btnXoa.Text  = "Xóa";

                LockControl();
                UpdateDetail();
                return;
            }
        }
Ejemplo n.º 26
0
        private bool CheckLuaChon()
        {
            THUOC tg = getTHUOCByID();

            if (tg.ID == 0)
            {
                MessageBox.Show("Chưa có thuốc nào được chọn",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 27
0
        private void button2_Click(object sender, EventArgs e)
        {
            THUOC bnDTO = new THUOC();

            bnDTO.TenThuoc1 = txb_TenThuoc.Text;
            if (THUOC_BUS.XoaTHUOC(bnDTO) == true)
            {
                TaiDuLieuVaoDataGirdView();

                MessageBox.Show("Xóa thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }
            MessageBox.Show(" Xóa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Ejemplo n.º 28
0
        public void Insert_TestCase3()
        {
            THUOC thuoc = new THUOC
            {
                MaThuoc      = TestCommon.LEN_10,
                TenThuoc     = TestCommon.LEN_50 + "11",
                ChiDinh      = TestCommon.LEN_250 + "11",
                ChongChiDinh = TestCommon.LEN_250 + "11"
            };
            ThuocDAO dao      = new ThuocDAO();
            string   actual   = dao.Save(db, thuoc);
            string   expected = "1111";

            Assert.Equals(expected, actual);
        }
Ejemplo n.º 29
0
 private THUOC getTHUOCByID()
 {
     try
     {
         int   id  = (int)dgvTHUOC.GetFocusedRowCellValue("ID");
         THUOC ans = THUOCService.GetAllBy(THUOC.THUOCFields.ID, id).FirstOrDefault();
         if (ans == null)
         {
             return(new THUOC());
         }
         return(ans);
     }
     catch
     {
         return(new THUOC());
     }
 }
Ejemplo n.º 30
0
 void ThemDonThuoc()
 {
     if (Regex.Replace(txtSoLan.Text, " ", "") == "" || Regex.Replace(txtSoNgay.Text, " ", "") == "" || Regex.Replace(txtSovien1L.Text, " ", "") == "")
     {
         MessageBox.Show("Không được để trống thông tin", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         int soluongLay;
         int solan  = Convert.ToInt32(txtSoLan.Text);
         int moilan = Convert.ToInt32(txtSovien1L.Text);
         int songay = Convert.ToInt32(txtSoNgay.Text);
         soluongLay = songay * solan * moilan;
         string     cachDung = "Mỗi ngày " + solan + " lần, một lần " + moilan + " " + lbDVT.Text;
         DonVaThuoc Don      = new DonVaThuoc
         {
             MaDon     = maDT,
             MaThuoc   = maTH,
             SoLuong   = soluongLay.ToString(),
             DonViTinh = lbDVT.Text,
             CachDung  = cachDung,
         };
         THUOC thuoc_hientai = QuanLyThuoc.LayThongTin1Thuoc(maTH);
         int   soluongKho    = Convert.ToInt32(thuoc_hientai.SoLuong);
         int   soluongConLai = soluongKho - soluongLay;
         if (soluongConLai < 0)
         {
             MessageBox.Show("Không đủ số lượng thuốc cấp", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         THUOC thuoc_capnhat = new THUOC
         {
             MaThuoc    = thuoc_hientai.MaThuoc,
             TenThuoc   = thuoc_hientai.TenThuoc,
             CongDung   = thuoc_hientai.CongDung,
             TacDungPhu = thuoc_hientai.TacDungPhu,
             DangThuoc  = thuoc_hientai.DangThuoc,
             SoLuong    = soluongConLai.ToString(),
             MaLoai     = thuoc_hientai.MaLoai,
         };
         DvT.ThemDonVaThuoc(Don);                  // them don
         QuanLyThuoc.ChinhSuaThuoc(thuoc_capnhat); // cap nhat so luong thuoc
         this.Close();
     }
 }