public void InsertT(Thuoc t) { db.Thuocs.Add(t); db.SaveChanges(); }
public void UpdateDS(Thuoc t) { Thuoc capnhat = this.db.Thuocs.Single(s => s.MaThuoc == t.MaThuoc); capnhat.MaThuoc = t.MaThuoc; capnhat.TenThuoc = t.TenThuoc; capnhat.MaNhaCungCap = t.MaNhaCungCap; capnhat.LoaiThuoc = t.LoaiThuoc; capnhat.GiaNhap = t.GiaNhap; capnhat.GiaBan = t.GiaBan; capnhat.HanSuDung = t.HanSuDung; capnhat.MaNhaSanXuat = t.MaNhaSanXuat; db.SaveChanges(); }
private void btnXoa_Click(object sender, EventArgs e) { if (thuocBindingSource.Current == null) { return; } if (MessageBox.Show("Xác nhận xóa thuốc.", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Thuoc t = new Thuoc(); t = thuocBindingSource.Current as Thuoc; thuocServices.Delete(t); thuocBindingSource.DataSource = thuocServices.GetAll(); } }
public ActionResult ChinhSua(Thuoc thuoc) { if (ModelState.IsValid) { //Thực hiện cập nhận trong model db.Entry(thuoc).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } //Đưa dữ liệu vào dropdownlist ViewBag.MaDM = new SelectList(db.DanhMucs.ToList().OrderBy(n => n.TenDM), "MaDM", "TenDM", thuoc.MaDM); ViewBag.MaTH = new SelectList(db.ThuongHieux.ToList().OrderBy(n => n.TenTH), "MaTH", "TenTH", thuoc.MaTH); return(RedirectToAction("Index")); }
private void CommandBinding_CanExecute_Xoa(object sender, CanExecuteRoutedEventArgs e) { if (dg == null) { return; } Thuoc a = (Thuoc)dg.SelectedItem; if (dg.SelectedItem != null ) { e.CanExecute = true; } }
// GET: Thuocs/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Thuoc thuoc = db.Thuocs.Find(id); if (thuoc == null) { return(HttpNotFound()); } return(View(thuoc)); }
public static Result CheckThuocExistCode(string thuocGUID, string code) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); Thuoc th = null; if (thuocGUID == null || thuocGUID == string.Empty) { th = db.Thuocs.SingleOrDefault <Thuoc>(t => t.MaThuoc.ToLower() == code.ToLower()); } else { th = db.Thuocs.SingleOrDefault <Thuoc>(t => t.MaThuoc.ToLower() == code.ToLower() && t.ThuocGUID.ToString() != thuocGUID); } if (th == null) { result.Error.Code = ErrorCode.NOT_EXIST; } else { result.Error.Code = ErrorCode.EXIST; } } catch (System.Data.SqlClient.SqlException se) { result.Error.Code = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT; result.Error.Description = se.ToString(); } catch (Exception e) { result.Error.Code = ErrorCode.UNKNOWN_ERROR; result.Error.Description = e.ToString(); } finally { if (db != null) { db.Dispose(); db = null; } } return(result); }
public int UpdateData(Thuoc T) { SqlParameter[] para = { new SqlParameter("MaThuoc", T.MaThuoc), new SqlParameter("TenThuoc", T.TenThuoc), new SqlParameter("MaLoaiThuoc", T.MaLoaiThuoc), new SqlParameter("MaDVSX", T.MaDVSX), new SqlParameter("CongDung", T.CongDung), new SqlParameter("HSD", T.HSD), new SqlParameter("NuocSX", T.NuocSX), new SqlParameter("TTT", T.TTT) }; return(conn.ExcuteSQL("Sua_Thuoc", para)); }
// GET: Thuoc/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()); } ViewBag.ID_DonVi = new SelectList(db.DonVis, "ID_DonVi", "TenDonVi", thuoc.ID_DonVi); return(View(thuoc)); }
// 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()); } ViewBag.Benh_id = new SelectList(db.Benhs, "id", "TenBenh", thuoc.Benh_id); return(View(thuoc)); }
private void CommandBinding_CanExecute_Sua(object sender, CanExecuteRoutedEventArgs e) { if (dg == null) { return; } Thuoc a = (Thuoc)dg.SelectedItem; decimal x; if (a != null && decimal.TryParse(txtDonGia.Text, out x) && a.MaThuoc == txtMaThuoc.Text) { e.CanExecute = true; } }
public void Sua(Thuoc a) { Thuoc b = tim(a.MaThuoc); if (b != null) { b.MaThuoc = a.MaThuoc; b.TenThuoc = a.TenThuoc; b.DonViTinh = a.DonViTinh; b.DuongDung = a.DuongDung; b.DonGiaThuoc = a.DonGiaThuoc; //b.KhoaKhamID = a.KhoaKham.ID; //b.KhoaKhamID = int.Parse(b.KhoaKhamID.Value.ToString()); tc.capnhat(); } }
private void btnXoa_Click(object sender, EventArgs e) { Thuoc th = getDataThuoc(); if (MessageBox.Show("Bạn có chắc muốn xóa thuốc này?", "Xác Nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { if (thbo.XoaThuoc(th)) { MessageBox.Show("Xóa thành công"); } else { MessageBox.Show("Không thể xóa"); } } bindData(); }
public eThuoc getThuocbyID(int id) { Thuoc item = db.thuocs.Where(x => x.idThuoc == id).FirstOrDefault(); if (item == null) { return(null); } eThuoc temp = new eThuoc(); temp.idThuoc = item.idThuoc; temp.tenThuoc = item.tenThuoc; temp.donGia = item.donGia; temp.moTa = item.moTa; temp.donVi = item.donVi; return(temp); }
public ActionResult ChinhSua(int MaThuoc) { if (Session["Admin"] == null || Session["Admin"].ToString() == "") { return(RedirectToAction("Login", "Admin")); } Thuoc thuoc = db.Thuocs.SingleOrDefault(n => n.MaThuoc == MaThuoc); if (thuoc == null) { Response.StatusCode = 404; return(null); } ViewBag.MaDM = new SelectList(db.DanhMucs.ToList().OrderBy(n => n.TenDM), "MaDM", "TenDM"); ViewBag.MaTH = new SelectList(db.ThuongHieux.ToList().OrderBy(n => n.TenTH), "MaTH", "TenTH"); return(View(thuoc)); }
public ActionResult Xoa(int MaThuoc) { if (Session["Admin"] == null || Session["Admin"].ToString() == "") { return(RedirectToAction("Login", "Admin")); } //Lấy ra đối tượng sách theo mã Thuoc thuoc = db.Thuocs.SingleOrDefault(n => n.MaThuoc == MaThuoc); if (thuoc == null) { Response.StatusCode = 404; return(null); } return(View(thuoc)); }
public bool Update(Thuoc thuoc) { try { var th = db.Thuoc.Find(thuoc.MaThuoc); th.TenThuoc = thuoc.TenThuoc; th.CachDung = thuoc.CachDung; th.DonViTinh = thuoc.DonViTinh; th.DonGia = thuoc.DonGia; th.SoLuongMacDinh = thuoc.SoLuongMacDinh; db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public ActionResult EditThuoc(ThuocJson nv) { try { Thuoc temp = db.Thuoc.Where(n => n.MaThuoc == nv.MaThuoc).SingleOrDefault(); temp.TenThuoc = nv.TenThuoc; temp.MaLoaiThuoc = nv.MaLoaiThuoc; temp.MaNCC = nv.MaNCC; temp.CongDung = nv.CongDung; temp.HanSuDung = Convert.ToDateTime(nv.HanSuDung); temp.Donvitinh = nv.Donvitinh; temp.SoLuong = nv.SoLuong; temp.DonGiaNhap = Convert.ToDecimal(nv.DonGiaNhap); db.Entry(temp).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Sửa thành công" }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new { success = false, message = "Sửa không thành công, lỗi: " + e.Message }, JsonRequestBehavior.AllowGet)); } }
public bool edtiThuoc(String pmathuoc, String ptenthuoc, String pmanhom, String pcongdung, String pThanhPhan, String pdonvitinh, String pxuatsu, int pgiaban, int pSL) { if (!ktrThuoc(pmathuoc)) { Thuoc thuoc = data.Thuocs.Where(t => t.ma_thuoc == pmathuoc).Single(); thuoc.ma_thuoc = pmathuoc; thuoc.ten_thuoc = ptenthuoc; thuoc.ma_nhom = pmanhom; thuoc.cong_dung = pcongdung; thuoc.thanh_phan = pThanhPhan; thuoc.dvt = pdonvitinh; thuoc.xuat_xu = pxuatsu; thuoc.gia_ban = pgiaban; thuoc.so_luong = pSL; return(true); } return(false); }
// cập nhật giỏ hàng public ActionResult CapNhatGioHang(int MaSP, FormCollection f) { // Kiểm tra mã sp Thuoc thuoc = db.Thuocs.SingleOrDefault(n => n.MaThuoc == MaSP); if (thuoc == null) { Response.StatusCode = 404; return(null); } List <GioHang> listGioHang = LayGioHang(); GioHang sanpham = listGioHang.SingleOrDefault(n => n.MaSP == MaSP); if (sanpham != null) { sanpham.SoLuong = int.Parse(f["txtSoLuong"].ToString()); } return(RedirectToAction("GioHang")); }
private void button1_Click(object sender, EventArgs e) { DialogResult dialog = MessageBox.Show("Bạn muốn thanh toán?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dialog == DialogResult.OK) { if (listView1.Items.Count != 0) { Global.lstItemBuy.Clear(); foreach (ListViewItem it in listView1.Items) { Thuoc sp = APIs.GetThuocByID(int.Parse(it.Text))[0]; sp.Soluong = int.Parse(it.SubItems[2].Text); Global.lstItemBuy.Add(sp); } if (checkBox1.Checked) { Global.khachhangID = APIs.GetKhachhangByName(comboKhachhang.Text).KhachhangID; Global.Tenkhachhang = comboKhachhang.Text; Global.Diachi = APIs.GetKhachhangByName(comboKhachhang.Text).Diachi; } else { if (textBoxKhachhang.Text == "" || textBoxDiachi.Text == "") { MessageBox.Show("Bạn chưa nhập thông tin khách hàng!"); return; } Global.khachhangID = 1; Global.Tenkhachhang = textBoxKhachhang.Text; Global.Diachi = textBoxDiachi.Text; } Hoadon hd = new Hoadon(); hd.passData = PassData; hd.ShowDialog(); } else { MessageBox.Show("Bạn chưa chọn món hàng nào!"); } } }
public bool Create(ThuocDTO thuocDto) { try { var item = CheckExistsTenThuoc(thuocDto.TenThuoc); if (item) { return(false); } var thuoc = new Thuoc { MaThuoc = Guid.NewGuid(), TenThuoc = thuocDto.TenThuoc, CongDung = thuocDto.CongDung, CachDung = thuocDto.CachDung, HinhAnh = thuocDto.HinhAnh, LuuY = thuocDto.LuuY, LieuDung = thuocDto.LieuDung }; _thuocRepository.Insert(thuoc); _unitOfWork.Commit(); if (thuocDto.MaBenhs != null) { foreach (var mabenh in thuocDto.MaBenhs) { var thuocdieutri = new ThuocDieuTri { MaThuoc = thuoc.MaThuoc, MaBenh = new Guid(mabenh) }; _thuocdieutriRepository.Insert(thuocdieutri); } _unitOfWork.Commit(); } return(true); } catch (Exception e) { return(false); } }
public int CreateTemp(string name) { using (var scope = new TransactionScope()) { //Mapper.CreateMap<ThuocEntities, Thuoc>(); //var o = Mapper.Map<ThuocEntities, Thuoc>(name); Thuoc o = new Thuoc(); o.donGia = 0; o.loaiThuoc = -1; o.soLuongTon = 0; o.tenThuoc = name; o.GhiChu = "Thuốc không nằm trong kho"; o.IsDelete = false; o.Date_Created = DateTime.Now; _unitOfWork.ThuocRepository.Insert(o); _unitOfWork.Save(); scope.Complete(); return(o.ID_Thuoc); } }
private void txtMathuoc_EditValueChanged(object sender, EventArgs e) { GiaThuoc g = new GiaThuoc(); if (txtMathuoc.Text != "") { g = gt.GetLast(txtMathuoc.Text, "GiaThuocMaThuoc"); } if (g != null) { Thuoc t = th.SelectByID(int.Parse(txtMathuoc.Text))[0]; txtMagiathuoc.Text = g.MaGiaThuoc.ToString(); txtMathuoc.Text = g.MaThuoc.ToString(); txtGianhap.Text = g.GiaNhap.ToString(); txtGiaxuat.Text = g.GiaXuat.ToString(); dtNgaycapnhat.Text = g.NgayCapNhat.ToShortDateString(); txtTenthuoc.Text = t.TenThuoc; } LoadGiaThuoc(); }
public ActionResult Contact([Bind(Include = "Id,ThanhPhan,NhomThuoc,DangThuoc,SanXuat,DangKy,ImagesCover")] Thuoc thuoc) { var thuocs = new List <Thuoc>(); thuocs.Add(new Thuoc(1, "Thuốc đau dạ dày", "Nhóm A", "Vỉ x 12 Viên", "Việt Nam", "19/2/2020", "/Content/Images/ThuocDauDaDay.jpg")); thuocs.Add(new Thuoc(1, "Thuốc đau đầu", "Nhóm B", "Vỉ x 12 Viên", "Việt Nam", "19/2/2020", "/Content/Images/ThuocDauDau.jpg")); thuocs.Add(new Thuoc(1, "Thuốc mát gan", "Nhóm C", "Vỉ x 12 Viên", "Việt Nam", "19/2/2020", "/Content/Images/ThuocMatGan.png")); try { if (ModelState.IsValid) { thuocs.Add(thuoc); } } catch (RetryLimitExceededException) { ModelState.AddModelError("", "Error Save Data"); } return(View("ListThuocModel", thuocs)); }
public ActionResult EditCTHDN(CTHDNJson ct) { try { ChiTietHDN temp = db.ChiTietHDN.Where(n => (n.MaHDN == ct.MaHDN) && (n.MaThuoc == ct.MaThuoc)).SingleOrDefault(); var soLuongCu = temp.SoluongNhap; temp.DonGiaNhap = Convert.ToDecimal(ct.DonGiaNhap); temp.SoluongNhap = Convert.ToInt32(ct.SoluongNhap); db.Entry(temp).State = EntityState.Modified; var soLuongMoi = temp.SoluongNhap - soLuongCu; Thuoc data = db.Thuoc.Where(n => n.MaThuoc == temp.MaThuoc).SingleOrDefault(); data.SoLuong = data.SoLuong + soLuongMoi; db.Entry(data).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Sửa chi tiết hóa đơn nhập thành công" }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { success = false, mesage = "Sửa không thành công" }, JsonRequestBehavior.AllowGet)); } }
//Get Thuoc/EditThuoc/Id public ActionResult EditThuoc(int id) { var thuocs = new List <Thuoc>(); thuocs.Add(new Thuoc(1, "Thuốc đau dạ dày", "Nhóm A", "Vỉ x 12 Viên", "Việt Nam", "19/2/2020", "/Content/Images/ThuocDauDaDay.jpg")); thuocs.Add(new Thuoc(1, "Thuốc đau đầu", "Nhóm B", "Vỉ x 12 Viên", "Việt Nam", "19/2/2020", "/Content/Images/ThuocDauDau.jpg")); thuocs.Add(new Thuoc(1, "Thuốc mát gan", "Nhóm C", "Vỉ x 12 Viên", "Việt Nam", "19/2/2020", "/Content/Images/ThuocMatGan.png")); //Check if not exit Thuoc thuoc = new Thuoc(); foreach (Thuoc b in thuocs) { thuoc = b; break; } if (thuoc == null) { return(HttpNotFound()); } return(View(thuoc)); }
private void CommandBinding_Executed_Sua(object sender, ExecutedRoutedEventArgs e) { Thuoc a = new Thuoc(); a.MaThuoc = txtMaThuoc.Text; a.TenThuoc = txtTenThuoc.Text; a.DonViTinh = txtDonViTinh.Text; a.DuongDung = txtDuongDung.Text; a.DonGiaThuoc = decimal.Parse(txtDonGia.Text); var message = validate(a); if (message != string.Empty) { MessageBox.Show(message, "Thông báo", MessageBoxButton.OK, MessageBoxImage.Warning); return; } xl.Sua(a); getDS(); }
public static Thuoc ShowThuocFromDB(String mahh) { // Lấy connection ThuocRepository getstring = new ThuocRepository(); string connectstring = getstring.GetConnectString(); // Câu truy vấn chọn hết dữ liệu từ Database var query = "SELECT * FROM current.dmthuoc WHERE mahh=@mahh"; // Tạo List chứa dữ liệu Thuoc list = new Thuoc(); //Tạo kết nối NpgsqlConnection conn = new NpgsqlConnection(connectstring); // Lấy dữ liệu try { conn.Open(); NpgsqlCommand cmd = new NpgsqlCommand(query, conn); cmd.Parameters.Add("@mahh", NpgsqlDbType.Varchar).Value = mahh; NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // Thêm vào list list = new Thuoc(reader.GetString(0), reader.GetString(1), reader.GetString(2)); } conn.Close(); Console.WriteLine("Thành công"); return(list); } catch (Exception e) { conn.Close(); Console.WriteLine(e.Message); return(list); } }
private void btnCapNhat_Click(object sender, EventArgs e) { try { Thuoc_BLL _thuoc = new Thuoc_BLL(); Thuoc th = new Thuoc(); th.MaThuoc = txtMaThuoc.Text.ToString().Trim(); th.TenThuoc = txtTenThuoc.Text.ToString().Trim(); th.DonGia = Convert.ToInt32(txtDonGia.Text.Trim()); th.DuongDung = cbxCachDung.SelectedItem.ToString(); th.DVT = cbxDonViTinh.SelectedItem.ToString(); _thuoc.Update(th); MessageBox.Show("Cập nhật thông tin thuốc thành công.", "Thông báo", MessageBoxButtons.OK); loadData2DataGridView(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK); } }
private void btnThem_Click(object sender, EventArgs e) { var tb = new HideNotifications(); try { if (txtTenThuoc.Text.Trim() != "") { string TenThuoc = txtTenThuoc.Text; string DonVi = cbxDonVi.Text; int DonGia = (int)numDonGia.Value; if (Thuoc.TimThuoc(TenThuoc, DonGia) == 0) { Thuoc.ThemThuoc(TenThuoc, DonVi, DonGia); LoadData(); lblThongBao.ForeColor = Color.Green; lblThongBao.Text = "Thêm mới thành công!"; tb.stt(lblThongBao); } else { XoaTextbox(); } } else { lblThongBao.Text = "Bạn chưa nhập tên thuốc"; tb.stt(lblThongBao); txtTenThuoc.Focus(); } } catch { lblThongBao.Text = "Thêm bị lỗi"; tb.stt(lblThongBao); } }
private void btnThemMoi_Click(object sender, EventArgs e) { Thuoc_BLL _thuoc = new Thuoc_BLL(); Thuoc th = new Thuoc(); th.MaThuoc = txtMaThuoc.Text.ToString(); th.TenThuoc = txtTenThuoc.Text.ToString(); th.DonGia = Convert.ToInt32(txtDonGia.Text); th.DuongDung = cbxCachDung.SelectedItem.ToString(); th.DVT = cbxDonViTinh.SelectedItem.ToString(); if (_thuoc.CheckMaThuoc(th) == false) { MessageBox.Show("Mã thuốc đã tồn tại.", "Thông báo", MessageBoxButtons.OK); txtMaThuoc.Focus(); } else { _thuoc.Add(th); MessageBox.Show("Thêm mới thuốc thành công.", "Thông báo", MessageBoxButtons.OK); loadData2DataGridView(); } }