private void FillData()
        {
            lblCapNhat.Text = "Thêm";
            if (MaDM != "")
            {
                txtMaVTYT.Enabled = false;
                lblCapNhat.Text = "Cập nhật";

                clsDM_VTYT obj = new clsDM_VTYT();
                obj.GetByKey(MaDM);
                txtMaVTYT.Text = obj.MaVTYT;
                txtTenVTYT.Text = obj.TenVTYT;
                txtDVT.Text = obj.DonViTinh;
                txtTenHoatChat.Text = obj.TenHoatChat;
                txtQuyCach.Text = obj.QuyCach;
                txtNhaSanXuat.Text = obj.NhaSanXuat;
                txtNuocSanXuat.Text = obj.NuocSanXuat;
                txtSoDK.Text = obj.SoDangKy;

                decDonGiaMua.Value = obj.DonGiaMua??0;
                decDonGiaCSKCB.Value = obj.DonGiaCSKCB??0;
                decDonGiaBHYT.Value = obj.DonGiaThau??0;
                chkVTYT_TT.Checked = obj.VTYTThayThe??false;
                chkKTC.Checked = obj.VTYTDichVuKTC??false;
                chkConDung.Checked = obj.Active??false;
                chkBHYT.Checked = obj.TrongDanhMucBHYT??false;
                txtNhom1.Text = obj.MaNhom1;
                txtNhom2.Text = obj.MaNhom2;

                txtHanSuDung.Text = (obj.HanSuDung != null) ? string.Format("{0:dd/MM/yyyy}", obj.HanSuDung) : "";

                chkKTC.Checked = obj.VTYTDichVuKTC??false;
                txtMaVTYTBYT.Text = obj.MaVTYTBYT;

                txtGhiChu.Text = obj.GhiChu;
                intSTTBYT.Text = obj.STTBYT;
                txtMaVTYTBYT.Text = obj.MaVTYTBYT;
                txtTenVTYTBYT.Text = obj.TenVTYTBYT;
            }
        }
Exemplo n.º 2
0
        private void ThemVaCapNhatChiPhi()
        {
            if (txtSoTheBHYT.Text.Replace("-", "").Length < 15)
            {
                MessageBox.Show("Vui lòng nhập số thẻ BHYT trước khi thêm chi phí.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //lblThongBao.Text = "Vui lòng nhập số thẻ BHYT trước khi thêm chi phí!";
                //timerThongBao.Enabled = true;

                txtThuoc.Focus();
                return;
            }
            string MaChiPhi = txtThuoc.SelectedValues["MaChiPhi"].ToString();
            string LoaiChiPhi = txtThuoc.SelectedValues["LoaiChiPhi"].ToString();

            bool isUpdateChiTiet = false;

            isCapNhat = false;

            if (m_MaChiPhi.Trim().Length > 0 && m_LoaiChiPhi.Trim().Length > 0)
            {
                MaChiPhi = m_MaChiPhi;
                LoaiChiPhi = m_LoaiChiPhi;
                isUpdateChiTiet = true;
                isCapNhat = true;
            }

            DataRow[] existsRows = TableChiPhiThuoc.Select("MaChiPhi ='" + MaChiPhi + "'");

            if (LoaiChiPhi == "T")
            {
                clsDM_Thuoc t = new clsDM_Thuoc();
                t.GetByKey(MaChiPhi);

                if (existsRows.Length > 0)
                {
                    if (!isUpdateChiTiet && MessageBox.Show("Mã " + MaChiPhi + " chi phí này tồn tại? Bạn có muốn cập nhật số lượng?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        existsRows[0]["SoLuong"] = (decimal)existsRows[0]["SoLuong"] + txtSoLuongThuoc.Value;

                    }
                    else
                    {
                        existsRows[0]["SoLuong"] = txtSoLuongThuoc.Value;
                    }

                    existsRows[0]["PhanTramDuocHuong"] = txtPhanTramHuong.Text;

                    decimal ThanhTienBHYT = Math.Round((decimal)existsRows[0]["SoLuong"] * t.DonGiaThau.Value);
                    decimal BHYTThanhToan = Math.Round(((decimal)existsRows[0]["SoLuong"] * t.DonGiaThau.Value) * (txtPhanTramHuong.Value / 100) * (t.TyLeThanhToan.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;

                    existsRows[0]["ThanhTienBHYT"] = ThanhTienBHYT;
                    existsRows[0]["BHYTThanhToan"] = BHYTThanhToan;
                    existsRows[0]["NguoiBenhTra"] = NguoiBenhTra; ;
                    existsRows[0]["NguonKhac"] = txtNguonKhacThuoc.Value;
                    existsRows[0]["ChiPhiNgoaiDinhSuat"] = 0;
                    existsRows[0]["TyLeThanhToan"] = t.TyLeThanhToan.Value;
                    TableChiPhiThuoc.AcceptChanges();
                }
                else
                {

                    DataRow dr = TableChiPhiThuoc.NewRow();
                    dr["MaChiPhi"] = t.MaThuoc;
                    //dr["MaPhu"] = t.MaPhu ;
                    dr["TenChiPhi"] = t.TenThuoc;
                    dr["DonViTinh"] = t.DonViTinh;
                    dr["SoLuong"] = txtSoLuongThuoc.Value;
                    dr["DonGiaBHYT"] = t.DonGiaThau;
                    dr["PhanTramDuocHuong"] = txtPhanTramHuong.Text;

                    decimal ThanhTienBHYT = Math.Round(txtSoLuongThuoc.Value * t.DonGiaThau.Value);
                    decimal BHYTThanhToan = Math.Round((txtSoLuongThuoc.Value * t.DonGiaThau.Value) * (txtPhanTramHuong.Value / 100) * (t.TyLeThanhToan.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;

                    dr["ThanhTienBHYT"] = ThanhTienBHYT;
                    dr["BHYTThanhToan"] = BHYTThanhToan;
                    dr["NguoiBenhTra"] = NguoiBenhTra;
                    dr["NguonKhac"] = txtNguonKhacThuoc.Value;
                    dr["ChiPhiNgoaiDinhSuat"] = 0;
                    dr["MaNhom1"] = t.MaNhom1;
                    dr["MaNhom2"] = t.MaNhom2;
                    dr["MaLoaiChiPhi"] = LoaiChiPhi;
                    //dr["VTYTDichVuKTC"] = t.VTYTDichVuKTC ;
                    //dr["DichVuKTC"] = t.DichVuKTC ;
                    dr["GhiChu"] = t.GhiChu;

                    dr["TyLeThanhToan"] = t.TyLeThanhToan.Value;

                    dr["GroupName"] = "Thuốc";

                    TableChiPhiThuoc.Rows.Add(dr);
                }
            }

            else if (LoaiChiPhi == "D")
            {
                clsDM_DichVu dv = new clsDM_DichVu();
                dv.GetByKey(MaChiPhi);

                if (existsRows.Length > 0)
                {
                    if (!isUpdateChiTiet && MessageBox.Show("Mã " + MaChiPhi + " chi phí này tồn tại? Bạn có muốn cập nhật số lượng?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        existsRows[0]["SoLuong"] = (decimal)existsRows[0]["SoLuong"] + txtSoLuongThuoc.Value;
                    }
                    else
                    {
                        existsRows[0]["SoLuong"] = txtSoLuongThuoc.Value;
                    }
                    existsRows[0]["PhanTramDuocHuong"] = txtPhanTramHuong.Text;

                    decimal ThanhTienBHYT = Math.Round((decimal)existsRows[0]["SoLuong"] * dv.DonGiaBHYT.Value);
                    decimal BHYTThanhToan = Math.Round(((decimal)existsRows[0]["SoLuong"] * dv.DonGiaBHYT.Value) * (txtPhanTramHuong.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;

                    existsRows[0]["ThanhTienBHYT"] = ThanhTienBHYT;
                    existsRows[0]["BHYTThanhToan"] = BHYTThanhToan;
                    existsRows[0]["NguoiBenhTra"] = NguoiBenhTra; ;
                    existsRows[0]["NguonKhac"] = txtNguonKhacThuoc.Value;
                    existsRows[0]["ChiPhiNgoaiDinhSuat"] = 0;
                    TableChiPhiThuoc.AcceptChanges();
                }
                else
                {

                    DataRow dr = TableChiPhiThuoc.NewRow();
                    dr["MaChiPhi"] = dv.MaDichVu;
                    dr["MaPhu"] = dv.MaKhac;
                    dr["TenChiPhi"] = dv.TenDichVu;
                    dr["DonViTinh"] = dv.DonViTinh;
                    dr["SoLuong"] = txtSoLuongThuoc.Value;
                    dr["DonGiaBHYT"] = dv.DonGiaBHYT;
                    dr["PhanTramDuocHuong"] = txtPhanTramHuong.Text;

                    decimal ThanhTienBHYT = Math.Round(txtSoLuongThuoc.Value * dv.DonGiaBHYT.Value);
                    decimal BHYTThanhToan = Math.Round((txtSoLuongThuoc.Value * dv.DonGiaBHYT.Value) * (txtPhanTramHuong.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;

                    dr["ThanhTienBHYT"] = ThanhTienBHYT;
                    dr["BHYTThanhToan"] = BHYTThanhToan;
                    dr["NguoiBenhTra"] = NguoiBenhTra;
                    dr["NguonKhac"] = txtNguonKhacThuoc.Value;
                    dr["ChiPhiNgoaiDinhSuat"] = 0;
                    dr["MaNhom1"] = dv.MaNhom1;
                    dr["MaNhom2"] = dv.MaNhom2;
                    dr["MaLoaiChiPhi"] = LoaiChiPhi;
                    //dr["VTYTDichVuKTC"] = t.VTYTDichVuKTC ;
                    dr["DichVuKTC"] = dv.DichVuKTC.Value;
                    dr["GhiChu"] = dv.GhiChu;

                    dr["GroupName"] = "Dịch vụ";

                    TableChiPhiThuoc.Rows.Add(dr);
                }
            }
            else if (LoaiChiPhi == "V")
            {
                clsDM_VTYT vtyt = new clsDM_VTYT();
                vtyt.GetByKey(MaChiPhi);

                if (existsRows.Length > 0)
                {
                    if (!isUpdateChiTiet && MessageBox.Show("Mã " + MaChiPhi + " chi phí này tồn tại? Bạn có muốn cập nhật số lượng?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        existsRows[0]["SoLuong"] = (decimal)existsRows[0]["SoLuong"] + txtSoLuongThuoc.Value;

                    }
                    else
                    {
                        existsRows[0]["SoLuong"] = txtSoLuongThuoc.Value;
                    }
                    existsRows[0]["PhanTramDuocHuong"] = txtPhanTramHuong.Text;
                    decimal ThanhTienBHYT = Math.Round((decimal)existsRows[0]["SoLuong"] * vtyt.DonGiaThau.Value);
                    decimal BHYTThanhToan = Math.Round(((decimal)existsRows[0]["SoLuong"] * vtyt.DonGiaThau.Value) * (txtPhanTramHuong.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;

                    existsRows[0]["ThanhTienBHYT"] = ThanhTienBHYT;
                    existsRows[0]["BHYTThanhToan"] = BHYTThanhToan;
                    existsRows[0]["NguoiBenhTra"] = NguoiBenhTra; ;
                    existsRows[0]["NguonKhac"] = txtNguonKhacThuoc.Value;
                    existsRows[0]["ChiPhiNgoaiDinhSuat"] = 0;
                    TableChiPhiThuoc.AcceptChanges();
                }
                else
                {

                    DataRow dr = TableChiPhiThuoc.NewRow();
                    dr["MaChiPhi"] = vtyt.MaVTYT;
                    // dr["MaPhu"] = vtyt.;
                    dr["TenChiPhi"] = vtyt.TenVTYT;
                    dr["DonViTinh"] = vtyt.DonViTinh;
                    dr["SoLuong"] = txtSoLuongThuoc.Value;
                    dr["DonGiaBHYT"] = vtyt.DonGiaThau;
                    dr["PhanTramDuocHuong"] = txtPhanTramHuong.Text;

                    decimal ThanhTienBHYT = Math.Round(txtSoLuongThuoc.Value * vtyt.DonGiaThau.Value);
                    decimal BHYTThanhToan = Math.Round((txtSoLuongThuoc.Value * vtyt.DonGiaThau.Value) * (txtPhanTramHuong.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;
                    dr["ThanhTienBHYT"] = ThanhTienBHYT;
                    dr["BHYTThanhToan"] = BHYTThanhToan;
                    dr["NguoiBenhTra"] = NguoiBenhTra;
                    dr["NguonKhac"] = txtNguonKhacThuoc.Value;

                    dr["ChiPhiNgoaiDinhSuat"] = 0;
                    dr["MaNhom1"] = vtyt.MaNhom1;
                    dr["MaNhom2"] = vtyt.MaNhom2;
                    dr["MaLoaiChiPhi"] = LoaiChiPhi;
                    dr["VTYTDichVuKTC"] = vtyt.VTYTDichVuKTC.Value;
                    //dr["DichVuKTC"] = t.DichVuKTC ;
                    dr["GhiChu"] = vtyt.GhiChu;
                    dr["GroupName"] = "Vật tư y tế";
                    TableChiPhiThuoc.Rows.Add(dr);
                }
            }
            else if (LoaiChiPhi == "M")
            {
                clsDM_Mau m = new clsDM_Mau();
                m.GetByKey(MaChiPhi);

                if (existsRows.Length > 0)
                {
                    if (MessageBox.Show("Mã " + MaChiPhi + " chi phí này tồn tại? Bạn có muốn cập nhật số lượng?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        existsRows[0]["SoLuong"] = (decimal)existsRows[0]["SoLuong"] + txtSoLuongThuoc.Value;

                    }
                    else
                    {
                        existsRows[0]["SoLuong"] = txtSoLuongThuoc.Value;
                    }
                    existsRows[0]["PhanTramDuocHuong"] = txtPhanTramHuong.Text;

                    decimal ThanhTienBHYT = Math.Round((decimal)existsRows[0]["SoLuong"] * m.DonGiaBHYT.Value);
                    decimal BHYTThanhToan = Math.Round(((decimal)existsRows[0]["SoLuong"] * m.DonGiaBHYT.Value) * (txtPhanTramHuong.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;

                    existsRows[0]["ThanhTienBHYT"] = ThanhTienBHYT;
                    existsRows[0]["BHYTThanhToan"] = BHYTThanhToan;
                    existsRows[0]["NguoiBenhTra"] = NguoiBenhTra; ;
                    existsRows[0]["NguonKhac"] = txtNguonKhacThuoc.Value;

                    existsRows[0]["ChiPhiNgoaiDinhSuat"] = 0;
                    TableChiPhiThuoc.AcceptChanges();
                }
                else
                {

                    DataRow dr = TableChiPhiThuoc.NewRow();
                    dr["MaChiPhi"] = m.MaMauVaChePhamMau;
                    // dr["MaPhu"] = vtyt.;
                    dr["TenChiPhi"] = m.TenMauVaChePhamMau;
                    dr["DonViTinh"] = m.DonViTinh;
                    dr["SoLuong"] = txtSoLuongThuoc.Value;
                    dr["DonGiaBHYT"] = m.DonGiaBHYT;
                    dr["PhanTramDuocHuong"] = txtPhanTramHuong.Text;

                    decimal ThanhTienBHYT = Math.Round(txtSoLuongThuoc.Value * m.DonGiaBHYT.Value);
                    decimal BHYTThanhToan = Math.Round((txtSoLuongThuoc.Value * m.DonGiaBHYT.Value) * (txtPhanTramHuong.Value / 100));
                    decimal NguoiBenhTra = ThanhTienBHYT - txtNguonKhacThuoc.Value - BHYTThanhToan;
                    dr["ThanhTienBHYT"] = ThanhTienBHYT;
                    dr["BHYTThanhToan"] = BHYTThanhToan;
                    dr["NguoiBenhTra"] = NguoiBenhTra;
                    dr["NguonKhac"] = txtNguonKhacThuoc.Value;

                    dr["ChiPhiNgoaiDinhSuat"] = 0;
                    dr["MaNhom1"] = m.MaNhom1;
                    dr["MaNhom2"] = m.MaNhom2;
                    dr["MaLoaiChiPhi"] = LoaiChiPhi;
                    //dr["VTYTDichVuKTC"] = vtyt.VTYTDichVuKTC;
                    //dr["DichVuKTC"] = t.DichVuKTC ;
                    dr["GhiChu"] = m.GhiChu;
                    dr["GroupName"] = "Máu và chế phẩm";
                    TableChiPhiThuoc.Rows.Add(dr);
                }
            }
            m_MaChiPhi = "";
            m_LoaiChiPhi = "";
            txtThuoc.ClearSelection();
            TinhTongGridView();
            txtThuoc.Focus();
        }