Пример #1
0
        public bool UpdateInfoThuoc(DTO_Thuoc thuoc, string ten, string congDung, double donGia)
        {
            using (var context = new SQLServerDBContext())
            {
                var item = context.Thuoc.Where(t => t.TenThuoc == ten).FirstOrDefault();

                bool check;

                if (item != null)
                {
                    check = item.MaThuoc == thuoc.MaThuoc;
                }
                else
                {
                    check = true;
                }

                if (check)
                {
                    thuoc.TenThuoc = ten;
                    thuoc.CongDung = congDung;
                    thuoc.DonGia   = donGia;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #2
0
 private void btnAddNV_Click(object sender, EventArgs e)
 {
     if (txtIdThuoc.Text != "")
     {
         if (bus_Thuoc.CheckTrung(txtIdThuoc.Text) == true)
         {
             MessageBox.Show("Trung ID");
             txtIdThuoc.Select();
         }
         else
         {
             if (txtDonGia.Text == "")
             {
                 txtDonGia.Text = "0";
             }
             DTO_Thuoc th = new DTO_Thuoc(Convert.ToInt32(txtIdThuoc.Text), txtTenThuoc.Text, txtSoLuong.Text, txtLieuDung.Text, Convert.ToInt32(txtDonGia.Text), txtGhiChu.Text);
             if (bus_Thuoc.ThemThuoc(th))
             {
                 MessageBox.Show("Thêm thành công");
             }
             else
             {
                 MessageBox.Show("Thêm ko thành công");
             }
         }
     }
     else
     {
         MessageBox.Show("Chưa nhập ID");
     }
 }
Пример #3
0
 public bool IsThuocDaTonTai(DTO_Thuoc thuocMoi)
 {
     using (var context = new SQLServerDBContext())
     {
         return(context.Thuoc.Any(t => (t.TenThuoc.Equals(thuocMoi.TenThuoc, StringComparison.OrdinalIgnoreCase)) && (t.DonVi == thuocMoi.DonVi)));
     }
 }
Пример #4
0
        public bool SuaThuoc(DTO_Thuoc th)
        {
            try
            {
                _conn.Open();
                // Create List Sql Parameter
                string cm = "update  DonThuoc set TenThuoc=@tenthuoc,DonViTinh=@donvitinh,LieuDung=@lieudung,DonGia=@dongia,GhiChu=@ghichu where ID=@id";

                SqlCommand cmd;
                cmd = new SqlCommand(cm, _conn);
                cmd.Parameters.AddWithValue("@ID", th.thuoc_id);
                cmd.Parameters.AddWithValue("@tenthuoc", th.thuoc_tenthuoc);
                cmd.Parameters.AddWithValue("@donvitinh", th.thuoc_soLuong);
                cmd.Parameters.AddWithValue("@lieudung", th.thuoc_lieuDung);
                cmd.Parameters.AddWithValue("@dongia", th.thuoc_donGia);
                cmd.Parameters.AddWithValue("@ghichu", th.thuoc_ghiChu);


                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                _conn.Close();
            }
            return(false);
        }
Пример #5
0
        public bool xoaMaHoaDon(string maNCC)
        {
            var lit             = db.Thuocs.Where(x => x.Ma_NCC.Equals(maNCC));
            List <DTO_Thuoc> li = new List <DTO_Thuoc>();

            if (lit != null)
            {
                foreach (Thuoc th in lit)
                {
                    DTO_Thuoc t = new DTO_Thuoc();
                    t.MaThuoc = th.Ma_Thuoc;
                    li.Add(t);
                }
                foreach (DTO_Thuoc th in li)
                {
                    var hdtemp = db.HoaDons.Where(x => x.Ma_Thuoc == th.MaThuoc);
                    if (hdtemp != null)
                    {
                        foreach (HoaDon item in hdtemp)
                        {
                            db.HoaDons.DeleteOnSubmit(item);
                            db.SubmitChanges();
                        }
                    }
                }
                foreach (Thuoc item in lit)
                {
                    db.Thuocs.DeleteOnSubmit(item);
                    db.SubmitChanges();
                }
                return(true);
            }
            return(false);
        }
Пример #6
0
 public async Task <string> AddThuocAsync(DTO_Thuoc thuoc)
 {
     using (var context = new SQLServerDBContext())
     {
         string res = null;
         try
         {
             var donVi    = new SqlParameter("@1", System.Data.SqlDbType.NVarChar);
             var tenThuoc = new SqlParameter("@2", System.Data.SqlDbType.NVarChar);
             var congDung = new SqlParameter("@3", System.Data.SqlDbType.NVarChar);
             donVi.Value    = thuoc.DonVi;
             tenThuoc.Value = thuoc.TenThuoc;
             congDung.Value = thuoc.CongDung;
             res            = await context.Database.SqlQuery <string>("exec proc_Thuoc_insert @1, @2, @3, @4, @5",
                                                                       new SqlParameter[]
             {
                 donVi,
                 tenThuoc,
                 congDung,
                 new SqlParameter("@4", thuoc.DonGia),
                 new SqlParameter("@5", thuoc.SoLuong)
             }).FirstOrDefaultAsync();
         }
         catch (Exception e)
         {
             Debug.WriteLine("[ERROR] " + e.Message);
         }
         return(res);
     }
 }
Пример #7
0
        public bool ThemThuoc(DTO_Thuoc th)
        {
            try
            {
                _conn.Open();
                // Create List Sql Parameter
                string cm = "insert into DonThuoc values(@ID,@TenThuoc,@DonViTinh,@LieuDung,@DonGia,@GhiChu)";

                SqlCommand cmd;
                cmd = new SqlCommand(cm, _conn);
                cmd.Parameters.AddWithValue("@ID", th.thuoc_id);
                cmd.Parameters.AddWithValue("@TenThuoc", th.thuoc_tenthuoc);
                cmd.Parameters.AddWithValue("@DonViTinh", th.thuoc_soLuong);
                cmd.Parameters.AddWithValue("@LieuDung", th.thuoc_lieuDung);
                cmd.Parameters.AddWithValue("@DonGia", th.thuoc_donGia);
                cmd.Parameters.AddWithValue("@GhiChu", th.thuoc_ghiChu);


                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                _conn.Close();
            }
            return(false);
        }
Пример #8
0
 public bool CheckIfThuocNhapTrung(ObservableCollection <DTO_CTHDThuoc> list, DTO_Thuoc thuocSuDung)
 {
     if (list == null)
     {
         return(false);
     }
     return(list.Any(c => c.MaThuoc == thuocSuDung.MaThuoc));
 }
Пример #9
0
        public DTO_Thuoc timTheoMa(string ma) // chỉ lấy một cột trong database
        {
            Thuoc     dst = db.Thuocs.Where(x => x.Ma_Thuoc.Equals(ma)).FirstOrDefault();
            DTO_Thuoc t   = new DTO_Thuoc();

            t.MaNhaCC = dst.Ma_NCC;
            return(t);
        }
        private void tinhTongThu()
        {
            decimal tong = 0;

            List <DTO_HoaDon> dshd = hdBUS.getAllHoaDon();

            foreach (DTO_HoaDon item in dshd)
            {
                DTO_Thuoc t = tBUS.getThuocTheoMa(item.MaThuoc);

                tong += item.SoLuong * (t.DonGia);
            }
            txtTong.Text = tong.ToString();
        }
Пример #11
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtMaThuoc.Text == " " || txtMaThuoc.Text == "" || txtTenThuoc.Text == " " || txtTenThuoc.Text == "" ||
                txtCongDung.Text == " " || txtCongDung.Text == "" || cbbNhaCungCap.Text == "" ||
                txtDonGia.Text == " " || txtDonGia.Text == "" || txtSoLuong.Text == " " ||
                txtSoLuong.Text == "" || txtDVT.Text == " " || txtDVT.Text == "")
            {
                MessageBox.Show("Vui lòng không bỏ trống thông tin", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                KiemTraTrong();
            }
            else if (checkT.checkMaThuoc(txtMaThuoc.Text) == false || checkT.checkTenThuoc(txtTenThuoc.Text) == false ||
                     checkT.checkNhaCC(cbbNhaCungCap.Text) == false || checkT.checkDonGia(txtDonGia.Text) == false ||
                     checkT.checkDonGia(txtSoLuong.Text) == false || checkT.checkCongDung(txtCongDung.Text) == false ||
                     checkT.checkDonViTinh(txtDVT.Text) == false)
            {
                MessageBox.Show("Vui lòng nhập đúng yêu cầu của thông tin", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                KiemTraCheck();
            }
            else
            {
                DTO_Thuoc t = new DTO_Thuoc();
                t.MaThuoc      = txtMaThuoc.Text;
                t.TenThuoc     = txtTenThuoc.Text;
                t.CongDung     = txtCongDung.Text;
                t.DonViTinh    = txtDVT.Text;
                t.DonGia       = int.Parse(txtDonGia.Text);
                t.SoLuongThuoc = int.Parse(txtSoLuong.Text);
                t.NgaySX       = dtpkNSX.Value;
                t.HanSD        = dtpkHSD.Value;
                t.MaNhaCC      = cbbNhaCungCap.Text;


                if (tBUS.addThuoc(t))
                {
                    MessageBox.Show("Thêm thành công!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    LoadData_T();
                    restTxtT();                      //note
                    cbbNhaCungCap.Text   = "(None)"; //note
                    cbbTimLoaiThuoc.Text = "(None)"; //note
                    txtTimTenThuoc.ResetText();      //note
                    LoadData_T();                    //note
                    errorProvider1.Clear();          //note
                }
                else
                {
                    MessageBox.Show("Bị trùng mã", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                }
            }
        }
        private void btnHD_ThanhToan_Click(object sender, EventArgs e)
        {
            DTO_HoaDon    hd = new DTO_HoaDon();
            DTO_Thuoc     t  = new DTO_Thuoc();
            DTO_KhachHang kh = new DTO_KhachHang();

            if (checkEmpty_HD())
            {
                errorProvider1.Clear();
                if (checkBH.checkRegex(txtHD_SoLuong.Text))
                {
                    errorProvider1.Clear();
                    if (checkDate())
                    {
                        errorProvider1.Clear();
                        hd.NgayLap    = dtpkHD_NgayLapHD.Value;
                        hd.LoaiHoaDon = cbbHD_LoaiHD.Text;
                        hd.SoLuong    = int.Parse(txtHD_SoLuong.Text);
                        hd.MaThuoc    = cbbHD_MaThuoc.Text;
                        kh            = khBUS.getKhachHangTheoTen(cbbHD_KhachHang.Text);
                        hd.MaKhach    = kh.MaKhachHang;
                        if (hdBUS.addHoaDon(hd, kh, t))
                        {
                            MessageBox.Show("Thanh Toán Thành Công!", "Thông Tin", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            LoadData_HD();
                            khoaThongTinHD();
                            restTxtHD();
                            btnHD_XuatHD.Text = "Xuất hóa đơn";
                        }
                        else
                        {
                            MessageBox.Show("Thanh Toán Thất bại!", "Thông Tin", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        errorProvider1.SetError(dtpkHD_NgayLapHD, "Ngày Chưa Tới");
                        dtpkHD_NgayLapHD.Focus();
                    }
                }
                else
                {
                    errorProvider1.SetError(txtHD_SoLuong, "Chỉ được nhập số.");
                    txtHD_SoLuong.Focus();
                }
            }
        }
        private void tinhTongThuTheoNgayTheoLoai(DateTime date, string loaihd)
        {
            decimal tong = 0;

            List <DTO_HoaDon> dshd = hdBUS.getAllHoaDon();

            foreach (DTO_HoaDon item in dshd)
            {
                if ((item.NgayLap.Day == date.Day && item.NgayLap.Month == date.Month && item.NgayLap.Year == date.Year) && item.LoaiHoaDon.Equals(loaihd))
                {
                    DTO_Thuoc t = tBUS.getThuocTheoMa(item.MaThuoc);

                    tong += item.SoLuong * t.DonGia;
                }
            }
            txtTong.Text = tong.ToString();
        }
Пример #14
0
        public bool CheckIfSoLuongThuocDu(DTO_Thuoc thuocSuDung, int soLuongSuDung)
        {
            ObservableCollection <DTO_Thuoc> listThuoc = GetListThuoc();

            var kq = listThuoc.Where(c => c.MaThuoc == thuocSuDung.MaThuoc).FirstOrDefault();

            if (kq != null)
            {
                if (kq.SoLuong >= soLuongSuDung)
                {
                    return(true);
                }
                return(false);
            }

            return(false);
        }
Пример #15
0
        public DTO_Thuoc layThuocTheoMa(string mathuoc)
        {
            Thuoc ttemp = db.Thuocs.Where(x => x.Ma_Thuoc.Equals(mathuoc)).FirstOrDefault();

            DTO_Thuoc tt = new DTO_Thuoc();

            tt.MaThuoc      = ttemp.Ma_Thuoc;
            tt.TenThuoc     = ttemp.Ten_Thuoc;
            tt.CongDung     = ttemp.CongDung_Thuoc;
            tt.DonViTinh    = ttemp.DonViTinh_Thuoc;
            tt.DonGia       = ttemp.DonGia_Thuoc;
            tt.NgaySX       = ttemp.NSX_Thuoc;
            tt.HanSD        = ttemp.HSD_Thuoc;
            tt.SoLuongThuoc = ttemp.SoLuongThuoc;

            return(tt);
        }
 private void cbbHD_MaThuoc_SelectedValueChanged(object sender, EventArgs e)
 {
     if (cbbHD_MaThuoc.Text == " ")
     {
         txtHD_TenThuoc.Text = " ";
         txtHD_CongDung.Text = " ";
         txtHD_DonGia.Text   = " ";
         txtHD_DVT.Text      = " ";
     }
     else
     {
         DTO_Thuoc t = tBUS.getThuocTheoMa(cbbHD_MaThuoc.Text);
         txtHD_TenThuoc.Text = t.TenThuoc;
         txtHD_CongDung.Text = t.CongDung;
         txtHD_DonGia.Text   = t.DonGia.ToString();
         txtHD_DVT.Text      = t.DonViTinh;
     }
 }
Пример #17
0
        private void btnDelNV_Click(object sender, EventArgs e)
        {
            var       rowH  = gridView1.FocusedRowHandle;
            var       rowHv = gridView1.GetRowCellValue(rowH, gridView1.Columns["ID"]);
            int       ID    = Convert.ToInt32(rowHv);
            DTO_Thuoc kt    = new DTO_Thuoc();

            kt.thuoc_id = ID;
            if (bus_Thuoc.XoaThuoc(kt))
            {
                MessageBox.Show("Xóa thành công");
                this.donThuocTableAdapter.Fill(this.quanLyPhongKhamDataSet.DonThuoc);
            }
            else
            {
                MessageBox.Show("Xóa ko thành công");
            }
        }
Пример #18
0
        public List <DTO_Thuoc> GetDrugs()
        {
            List <DTO_Thuoc> result = new List <DTO_Thuoc>();
            DataTable        data   = DAO_Thuoc.Instance.GetDrugs();

            foreach (DataRow row in data.Rows)
            {
                DTO_Thuoc tmpObject = new DTO_Thuoc();
                tmpObject.MaThuoc  = row["MATHUOC"].ToString();
                tmpObject.TenThuoc = row["TENTHUOC"].ToString();

                tmpObject.DonGia    = double.Parse(row["DONGIA"].ToString());
                tmpObject.DonViTinh = row["DONVITINH"].ToString();
                tmpObject.LuuY      = row["LUUY"].ToString();
                result.Add(tmpObject);
            }
            return(result);
        }
        private void loadDoanhThu()
        {
            List <DTO_HoaDon> dshd = hdBUS.getAllHoaDon();

            foreach (DTO_HoaDon item in dshd)
            {
                DTO_Thuoc t = tBUS.getThuocTheoMa(item.MaThuoc);
                if (item.LoaiHoaDon.Equals("Theo đơn"))
                {
                    tongTD += item.SoLuong * (t.DonGia);
                }
                else
                {
                    tongKTD += item.SoLuong * (t.DonGia);
                }
            }
            txtQLDT_TongTD.Text  = tongTD.ToString();
            txtQLTD_TongKTD.Text = tongKTD.ToString();
        }
Пример #20
0
        private void btnUpdateNV_Click(object sender, EventArgs e)
        {
            if (txtIdThuoc.Text != "")
            {
                DTO_Thuoc kt = new DTO_Thuoc(Convert.ToInt32(txtIdThuoc.Text), txtTenThuoc.Text, txtSoLuong.Text, txtLieuDung.Text, Convert.ToInt32(txtDonGia.Text), txtGhiChu.Text);

                if (bus_Thuoc.SuaThuoc(kt))
                {
                    MessageBox.Show("Sửa thành công");
                    this.donThuocTableAdapter.Fill(this.quanLyPhongKhamDataSet.DonThuoc);
                }
                else
                {
                    MessageBox.Show("Sửa ko thành công");
                }
            }
            else
            {
                MessageBox.Show("Chọn hàng cần sửa");
            }
        }
Пример #21
0
 public bool LoadNP_CTPhieuNhapThuoc(DTO_Thuoc thuoc)
 {
     try
     {
         using (var context = new SQLServerDBContext())
         {
             context.Thuoc.Attach(thuoc);
             var entry = context.Entry(thuoc);
             if (!entry.Collection(p => p.DS_CTPhieuNhapThuoc).IsLoaded)
             {
                 entry.Collection(p => p.DS_CTPhieuNhapThuoc).Load();
             }
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine($"[ERRROR DAL BENH] {e.Message}");
         return(false);
     }
 }
Пример #22
0
 private void dtgvShow_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         DataGridViewRow row = this.dtgvShow.Rows[e.RowIndex];
         DTO_Thuoc       t   = new DTO_Thuoc();
         t = tBUS.getTimTheoMa(row.Cells[0].Value.ToString());
         txtMaThuoc.Text    = row.Cells[0].Value.ToString();
         cbbNhaCungCap.Text = t.MaNhaCC;
         txtTenThuoc.Text   = row.Cells[2].Value.ToString();
         txtCongDung.Text   = row.Cells[3].Value.ToString();
         txtDVT.Text        = row.Cells[4].Value.ToString();
         txtDonGia.Text     = row.Cells[5].Value.ToString();
         dtpkNSX.Value      = DateTime.Parse(row.Cells[6].Value.ToString());
         dtpkHSD.Value      = DateTime.Parse(row.Cells[7].Value.ToString());
         txtSoLuong.Text    = row.Cells[8].Value.ToString();
     }
     btnSua.Enabled = true;
     btnXoa.Enabled = true;
     hienThongTinT();
 }
Пример #23
0
        public bool suaThuoc(DTO_Thuoc tnew)
        {
            IQueryable <Thuoc> t = db.Thuocs.Where(x => x.Ma_Thuoc.Equals(tnew.MaThuoc));

            if (t.Count() >= 0)
            {
                t.First().Ma_Thuoc        = tnew.MaThuoc;
                t.First().Ma_NCC          = tnew.MaNhaCC;
                t.First().Ten_Thuoc       = tnew.TenThuoc;
                t.First().CongDung_Thuoc  = tnew.CongDung;
                t.First().DonViTinh_Thuoc = tnew.DonViTinh;
                t.First().DonGia_Thuoc    = tnew.DonGia;
                t.First().SoLuongThuoc    = tnew.SoLuongThuoc;
                t.First().NSX_Thuoc       = tnew.NgaySX;
                t.First().HSD_Thuoc       = tnew.HanSD;

                db.SubmitChanges();

                return(true);
            }
            return(false);
        }
Пример #24
0
        public List <DTO_Thuoc> layDanhSachThuoc()
        {
            var dst = db.Thuocs.Select(p => p).OrderBy(p => p.Ma_Thuoc);
            List <DTO_Thuoc> lst = new List <DTO_Thuoc>();

            foreach (Thuoc item in dst)
            {
                DTO_Thuoc t = new DTO_Thuoc();
                t.MaThuoc      = item.Ma_Thuoc;
                t.MaNhaCC      = item.Ma_NCC;
                t.TenThuoc     = item.Ten_Thuoc;
                t.CongDung     = item.CongDung_Thuoc;
                t.DonViTinh    = item.DonViTinh_Thuoc;
                t.DonGia       = item.DonGia_Thuoc;
                t.SoLuongThuoc = item.SoLuongThuoc;
                t.NgaySX       = item.NSX_Thuoc;
                t.HanSD        = item.HSD_Thuoc;

                lst.Add(t);
            }
            return(lst);
        }
Пример #25
0
        public bool themThuoc(DTO_Thuoc tnew)
        {
            if (CheckIfExist(tnew.MaThuoc))
            {
                return(false);
            }

            Thuoc ttemp = new Thuoc();

            ttemp.Ma_Thuoc        = tnew.MaThuoc;
            ttemp.Ma_NCC          = tnew.MaNhaCC;
            ttemp.Ten_Thuoc       = tnew.TenThuoc;
            ttemp.CongDung_Thuoc  = tnew.CongDung;
            ttemp.DonGia_Thuoc    = tnew.DonGia;
            ttemp.DonViTinh_Thuoc = tnew.DonViTinh;
            ttemp.SoLuongThuoc    = tnew.SoLuongThuoc;
            ttemp.NSX_Thuoc       = tnew.NgaySX;
            ttemp.HSD_Thuoc       = tnew.HanSD;

            db.Thuocs.InsertOnSubmit(ttemp);
            db.SubmitChanges();
            return(true);
        }
Пример #26
0
        public bool themHoaDon(DTO_HoaDon hdnew, DTO_KhachHang khnew, DTO_Thuoc tnew)
        {
            if (CheckIfExist(hdnew.MaHoaDon))
            {
                return(false);
            }


            HoaDon hdtemp = new HoaDon();

            hdtemp.Ma_Thuoc     = hdnew.MaThuoc;
            hdtemp.Ma_KhachHang = hdnew.MaKhach;
            DateTime date = Convert.ToDateTime(hdnew.NgayLap);

            hdtemp.NgayLap_HD = date;
            hdtemp.SoLuong_HD = hdnew.SoLuong;
            hdtemp.Loai_HD    = hdnew.LoaiHoaDon;


            db.HoaDons.InsertOnSubmit(hdtemp);
            db.SubmitChanges();
            return(true);
        }
Пример #27
0
        public bool XoaThuoc(DTO_Thuoc th)
        {
            try
            {
                _conn.Open();
                string     cm  = "Delete DonThuoc where ID =@iD";
                SqlCommand cmd = new SqlCommand(cm, _conn);
                cmd.Parameters.AddWithValue("@iD", th.thuoc_id);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                _conn.Close();
            }

            return(false);
        }
Пример #28
0
 public bool addHoaDon(DTO_HoaDon hdnew, DTO_KhachHang khnew, DTO_Thuoc tnew)
 {
     return(hdDAL.themHoaDon(hdnew, khnew, tnew));
 }
Пример #29
0
 public bool CheckIfSoLuongThuocDu(DTO_Thuoc thuocSuDung, int soLuongSuDung)
 {
     return(DALManager.ThuocDAL.CheckIfSoLuongThuocDu(thuocSuDung, soLuongSuDung));
 }
Пример #30
0
 public bool UpdateInfoThuoc(DTO_Thuoc thuoc, string ten, string congDung, double donGia)
 {
     return(DALManager.ThuocDAL.UpdateInfoThuoc(thuoc, ten, congDung, donGia));
 }