Ejemplo n.º 1
0
        /// <summary>
        /// hàm thực hiện việc xác nhận thông tin 
        /// </summary>
        /// <param name="objPhieuNhap"></param>
        /// <returns></returns>
        public ActionResult HuyXacNhanPhieuNhapKho(TPhieuNhapxuatthuoc objPhieuNhap, ref string errMsg)
        {
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();

                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {

                            ActionResult _Kiemtrathuochuyxacnhan = Kiemtrathuochuyxacnhan(objPhieuNhap, objPhieuNhapCt);
                            if (_Kiemtrathuochuyxacnhan != ActionResult.Success) return _Kiemtrathuochuyxacnhan;
                            //Xóa toàn bộ chi tiết trong TBiendongThuoc
                            new Delete().From(TBiendongThuoc.Schema)
                                .Where(TBiendongThuoc.IdPhieuColumn).IsEqualTo(objPhieuNhap.IdPhieu)
                                .And(TBiendongThuoc.IdPhieuChitietColumn).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet)
                                   .And(TBiendongThuoc.MaLoaiphieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();

                            new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(-1)
                                .Set(TPhieuNhapxuatthuocChitiet.Columns.NgayNhap).EqualTo(null)
                               .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();

                            StoredProcedure sp = SPs.ThuocXuatkho(objPhieuNhap.IdKhonhap,objPhieuNhapCt.IdThuoc, objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                       Utility.DecimaltoDbnull(objPhieuNhap.Vat), objPhieuNhapCt.SoLuong,objPhieuNhapCt.IdThuockho,objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo,
                                                                       0, errMsg);

                            sp.Execute();
                        }

                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(-1)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(0)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi hủy xác nhận nhập kho", ex);
                return ActionResult.Error;

            }
        }
Ejemplo n.º 2
0
        public ActionResult HuyXacNhanPhieuHuy_thanhly_Thuoc(TPhieuNhapxuatthuoc objPhieuNhap, ref string errMsg)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();

                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            long idthuockho = -1;
                            //Nhập lại kho thanh lý
                            StoredProcedure sp = SPs.ThuocNhapkhoOutput(objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                      objPhieuNhapCt.SoLuong, Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                                      objPhieuNhapCt.IdThuoc, objPhieuNhap.IdKhoxuat, objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo,
                                                                      objPhieuNhapCt.SoDky, objPhieuNhapCt.SoQdinhthau, idthuockho, idthuockho, objPhieuNhapCt.NgayNhap, objPhieuNhapCt.GiaBhyt, objPhieuNhapCt.GiaPhuthuDungtuyen, objPhieuNhapCt.GiaPhuthuTraituyen, objPhieuNhapCt.KieuThuocvattu);
                            sp.Execute();
                            idthuockho = Utility.Int64Dbnull(sp.OutputValues[0], -1);
                            if (idthuockho != objPhieuNhapCt.IdThuockho)//Nếu ai đó xóa bằng tay trong bảng thuốc kho thì cần update lại
                                new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(idthuockho)
                                    .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                        }
                        //Xóa toàn bộ chi tiết trong TBiendongThuoc
                        new Delete().From(TBiendongThuoc.Schema)
                            .Where(TBiendongThuoc.IdPhieuColumn).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TBiendongThuoc.MaLoaiphieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(0)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TPhieuNhapxuatthuoc.LoaiPhieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi hủy xác nhận phiếu ",ex);
                return ActionResult.Error;
            }
        }
 /// <summary>
 ///     hàm thực hiện việc hiển thị thông tin
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdDungChuyenCLS_Click(object sender, EventArgs e)
 {
     try
     {
         Utility.EnableButton(cmdDungChuyenCLS, false);
         Utility.WaitNow(this);
         SqlQuery sqlQuery = new Select().From(KcbChidinhclsChitiet.Schema)
             .Where(KcbChidinhclsChitiet.Columns.IdChidinh).In(
                 new Select(KcbChidinhcl.Columns.IdChidinh).From(KcbChidinhcl.Schema).Where(
                     KcbChidinhcl.Columns.MaLuotkham)
                     .IsEqualTo(txtPatient_Code.Text)
                     .And(KcbChidinhcl.Columns.IdBenhnhan)
                     .IsEqualTo(Utility.Int32Dbnull(txtPatient_ID.Text)))
             .And(KcbChidinhclsChitiet.Columns.TrangThai).IsEqualTo(0)
             .And(KcbChidinhclsChitiet.Columns.TrangthaiChuyencls).IsEqualTo(1);
         if (sqlQuery.GetRecordCount() <= 0)
         {
             Utility.ShowMsg(
                 "Các chỉ định CLS đã được phòng Xét nghiệm nhận về nên bạn không thể hủy chuyển. Đề nghị liên hệ với phòng XN",
                 "Thông báo", MessageBoxIcon.Error);
             return;
         }
         var assignDetailCollection = sqlQuery.ExecuteAsCollection<KcbChidinhclsChitietCollection>();
         foreach (KcbChidinhclsChitiet assignDetail in assignDetailCollection)
         {
             assignDetail.TrangthaiChuyencls = (byte?)TrangThaiCLS.KhongChuyenCLS;
             assignDetail.NguoiSua = globalVariables.UserName;
             assignDetail.NgaySua = globalVariables.SysDate;
             //assignDetail.IpMacSua = globalVariables.IpMacAddress;
             //assignDetail.IpMaySua = globalVariables.IpAddress;
             new Update(KcbChidinhclsChitiet.Schema)
                 .Set(KcbChidinhclsChitiet.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                 .Set(KcbChidinhclsChitiet.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                 .Set(KcbChidinhclsChitiet.Columns.TrangthaiChuyencls).EqualTo(assignDetail.TrangthaiChuyencls)
                 .Where(KcbChidinhclsChitiet.Columns.IdChitietchidinh).IsEqualTo(assignDetail.IdChitietchidinh).Execute();
         }
         // assignDetailCollection.SaveAll();
         cmdChuyenCLS.Enabled = true;
         cmdDungChuyenCLS.Enabled = false;
     }
     catch (Exception exception)
     {
     }
     finally
     {
         Utility.EnableButton(cmdDungChuyenCLS, true);
         Utility.DefaultNow(this);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// hàm thực hiện việc xác nhận thông tin 
        /// </summary>
        /// <param name="objPhieuNhap"></param>
        /// <returns></returns>
        public ActionResult XacNhanPhieuXuatKho(TPhieuNhapxuatthuoc objPhieuNhap,DateTime ngayxacnhan, ref string errMsg)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();
                        objPhieuNhap.NgayXacnhan = ngayxacnhan;
                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            //Kiểm tra đề phòng Kho A-->Xuất kho B. Kho B xác nhận-->Xuất kho C. Kho B hủy xác nhận. Kho C xác nhận dẫn tới việc kho B chưa có thuốc để trừ kho

                            ActionResult _Kiemtrathuocxacnhan = Kiemtrathuocxacnhan(objPhieuNhap, objPhieuNhapCt, ref errMsg);
                            if (_Kiemtrathuocxacnhan != ActionResult.Success) return _Kiemtrathuocxacnhan;

                            long idthuockho = -1;
                            StoredProcedure sp = SPs.ThuocNhapkhoOutput(objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                      objPhieuNhapCt.SoLuong, Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                                      objPhieuNhapCt.IdThuoc, objPhieuNhap.IdKhonhap,
                                                                      objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo,
                                                                      objPhieuNhapCt.SoDky, objPhieuNhapCt.SoQdinhthau, -1, idthuockho, ngayxacnhan, objPhieuNhapCt.GiaBhyt, objPhieuNhapCt.GiaPhuthuDungtuyen, objPhieuNhapCt.GiaPhuthuTraituyen, objPhieuNhapCt.KieuThuocvattu);
                            sp.Execute();
                            idthuockho = Utility.Int64Dbnull(sp.OutputValues[0], -1);
                            sp = SPs.ThuocXuatkho(objPhieuNhap.IdKhoxuat, objPhieuNhapCt.IdThuoc,
                                                          objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                          Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                          Utility.Int32Dbnull(objPhieuNhapCt.SoLuong), objPhieuNhapCt.IdChuyen,
                                                          objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo,
                                                          objHisDuocProperties.XoaDulieuKhiThuocDaHet ? 1 : 0, errorMessage);

                            sp.Execute();
                            new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(idthuockho)
                               .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                            objPhieuNhapCt.IdThuockho = idthuockho;
                            //Insert dòng kho nhập
                            TBiendongThuoc objXuatNhap = new TBiendongThuoc();
                            objXuatNhap.IdPhieu = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieu);
                            objXuatNhap.IdPhieuChitiet = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieuchitiet);
                            objXuatNhap.MaPhieu = Utility.sDbnull(objPhieuNhap.MaPhieu);
                            objXuatNhap.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.DonGia);
                            objXuatNhap.GiaBan = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan);
                            objXuatNhap.IdChuyen = objPhieuNhapCt.IdChuyen;
                            objXuatNhap.NgayNhap = objPhieuNhapCt.NgayNhap;
                            objXuatNhap.GiaNhap = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaNhap);
                            objXuatNhap.SoHoadon = Utility.sDbnull(objPhieuNhap.SoHoadon);
                            objXuatNhap.SoChungtuKemtheo = objPhieuNhap.SoChungtuKemtheo;
                            objXuatNhap.GiaBhyt = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt);
                            objXuatNhap.GiaBhytCu = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhytCu);
                            objXuatNhap.GiaPhuthuDungtuyen = objPhieuNhapCt.GiaPhuthuDungtuyen;
                            objXuatNhap.GiaPhuthuTraituyen = objPhieuNhapCt.GiaPhuthuTraituyen;
                            objXuatNhap.Noitru = objPhieuNhap.NoiTru;
                            objXuatNhap.QuayThuoc = 0;
                            objXuatNhap.ThuocVay = 0;
                            objXuatNhap.PhuThu = 0;
                            objXuatNhap.DuTru = objPhieuNhap.DuTru;
                            objXuatNhap.SoLuong = Utility.Int32Dbnull(objPhieuNhapCt.SoLuong);
                            objXuatNhap.NgayTao = globalVariables.SysDate;
                            objXuatNhap.NguoiTao = globalVariables.UserName;
                            objXuatNhap.ThanhTien = Utility.DecimaltoDbnull(objPhieuNhapCt.ThanhTien);
                            objXuatNhap.IdThuoc = Utility.Int32Dbnull(objPhieuNhapCt.IdThuoc);
                            objXuatNhap.IdThuockho = Utility.Int32Dbnull(objPhieuNhapCt.IdThuockho);
                            objXuatNhap.Vat = Utility.Int32Dbnull(objPhieuNhap.Vat);
                            objXuatNhap.IdNhanvien = Utility.Int16Dbnull(objPhieuNhap.IdNhanvien);
                            objXuatNhap.IdKho = Utility.Int16Dbnull(objPhieuNhap.IdKhonhap);
                            objXuatNhap.NgayHethan = objPhieuNhapCt.NgayHethan.Date;
                            objXuatNhap.MaNhacungcap = objPhieuNhapCt.MaNhacungcap;
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.SoLo = objPhieuNhapCt.SoLo;

                            objXuatNhap.MaLoaiphieu = (byte)LoaiPhieu.PhieuNhapKho;
                            objXuatNhap.TenLoaiphieu = Utility.TenLoaiPhieu(LoaiPhieu.PhieuNhapKho);
                            objXuatNhap.NgayBiendong = objPhieuNhap.NgayXacnhan;
                            objXuatNhap.NgayHoadon = objPhieuNhap.NgayHoadon;
                            objXuatNhap.KieuThuocvattu = objPhieuNhapCt.KieuThuocvattu;
                            objXuatNhap.IsNew = true;
                            objXuatNhap.Save();
                            //Insert dòng của kho xuất
                            objXuatNhap = new TBiendongThuoc();
                            objXuatNhap.IdPhieu = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieu);
                            objXuatNhap.IdPhieuChitiet = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieuchitiet);
                            objXuatNhap.MaPhieu = Utility.sDbnull(objPhieuNhap.MaPhieu);
                            objXuatNhap.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.DonGia);
                            objXuatNhap.NgayNhap = objPhieuNhapCt.NgayNhap;
                            objXuatNhap.GiaBan = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan);
                            objXuatNhap.GiaNhap = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaNhap);
                            objXuatNhap.GiaBhyt = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt);
                            objXuatNhap.GiaBhytCu = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhytCu);
                            objXuatNhap.GiaPhuthuDungtuyen = objPhieuNhapCt.GiaPhuthuDungtuyen;
                            objXuatNhap.GiaPhuthuTraituyen = objPhieuNhapCt.GiaPhuthuTraituyen;
                            objXuatNhap.Noitru = objPhieuNhap.NoiTru;
                            objXuatNhap.QuayThuoc = 0;
                            objXuatNhap.ThuocVay = 0;
                            objXuatNhap.SoHoadon = Utility.sDbnull(objPhieuNhap.SoHoadon);
                            objXuatNhap.PhuThu = 0;
                            objXuatNhap.IdChuyen = -1;
                            objXuatNhap.DuTru = objPhieuNhap.DuTru;
                            objXuatNhap.SoLuong = Utility.Int32Dbnull(objPhieuNhapCt.SoLuong);
                            objXuatNhap.NgayTao = globalVariables.SysDate;
                            objXuatNhap.NguoiTao = globalVariables.UserName;
                            objXuatNhap.IdThuockho = Utility.Int32Dbnull(objPhieuNhapCt.IdChuyen);
                            objXuatNhap.ThanhTien = Utility.DecimaltoDbnull(objPhieuNhapCt.ThanhTien);
                            objXuatNhap.IdThuoc = Utility.Int32Dbnull(objPhieuNhapCt.IdThuoc);
                            objXuatNhap.Vat = Utility.Int32Dbnull(objPhieuNhap.Vat);
                            objXuatNhap.IdNhanvien = Utility.Int16Dbnull(objPhieuNhap.IdNhanvien);
                            objXuatNhap.IdKho = Utility.Int16Dbnull(objPhieuNhap.IdKhoxuat);
                            objXuatNhap.NgayHethan = objPhieuNhapCt.NgayHethan.Date;
                            objXuatNhap.MaNhacungcap = objPhieuNhapCt.MaNhacungcap;
                            objXuatNhap.SoChungtuKemtheo = objPhieuNhap.SoChungtuKemtheo;
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.SoLo = objPhieuNhapCt.SoLo;
                            objXuatNhap.MaLoaiphieu = (byte)LoaiPhieu.PhieuXuatKhoBenhNhan;
                            objXuatNhap.TenLoaiphieu = Utility.TenLoaiPhieu(LoaiPhieu.PhieuXuatKhoBenhNhan);
                            objXuatNhap.NgayBiendong = objPhieuNhap.NgayXacnhan;
                            objXuatNhap.NgayHoadon = objPhieuNhap.NgayHoadon;
                            objXuatNhap.KieuThuocvattu = objPhieuNhapCt.KieuThuocvattu;
                            objXuatNhap.IsNew = true;
                            objXuatNhap.Save();

                        }
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(globalVariables.gv_intIDNhanvien)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(globalVariables.UserName)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(ngayxacnhan)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(1)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TPhieuNhapxuatthuoc.LoaiPhieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi xác nhận phiếu xuất kho", ex);
                return ActionResult.Error;
            }
        }
Ejemplo n.º 5
0
        public ActionResult HuyXacNhanPhieuTrathuocTutrucKhoaVeKho(TPhieuNhapxuatthuoc objPhieuNhap, ref string errMsg)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();

                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            //Kiểm tra ở kho nhập xem thuốc đã sử dụng chưa
                            ActionResult _Kiemtrathuochuyxacnhan = Kiemtrathuochuyxacnhan(objPhieuNhap, objPhieuNhapCt, ref errMsg);
                            if (_Kiemtrathuochuyxacnhan != ActionResult.Success) return _Kiemtrathuochuyxacnhan;
                            //Xóa biến động kho nhập
                            new Delete().From(TBiendongThuoc.Schema)
                                .Where(TBiendongThuoc.IdPhieuColumn).IsEqualTo(objPhieuNhap.IdPhieu)
                                .And(TBiendongThuoc.IdPhieuChitietColumn).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet)
                                .And(TBiendongThuoc.MaLoaiphieuColumn).IsEqualTo((byte)LoaiPhieu.PhieuNhapTraKhoLe).Execute();
                            //Xóa biến động kho xuất
                            new Delete().From(TBiendongThuoc.Schema)
                               .Where(TBiendongThuoc.IdPhieuColumn).IsEqualTo(objPhieuNhap.IdPhieu)
                               .And(TBiendongThuoc.IdPhieuChitietColumn).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet)
                               .And(TBiendongThuoc.MaLoaiphieuColumn).IsEqualTo((byte)LoaiPhieu.PhieuNhapTraKhoLe).Execute();

                            //Cộng trả lại kho xuất
                            long idthuockho = -1;
                            //Nhập theo tủ trực theo số lượng chia
                            int SluongChia = Utility.Int32Dbnull(objPhieuNhapCt.SluongChia, 1);
                            if (SluongChia <= 0) SluongChia = 1;//Nếu lỗi do người dùng sửa tay thì tự động đặt=1
                            //Chú ý khi lập phiếu xuất thuốc tủ trực thì
                            //objPhieuNhapCt.SoLuong= số lượng đã chia-->Cần trừ số lượng trong kho xuất theo số lượng nguyên gốc. Tức là phải lấy số lượng này / số lượng chia
                            int Sluong = objPhieuNhapCt.SoLuong * SluongChia;//Số lượng thực sự bị mất khỏi kho xuất(khi xuất thuốc sang tủ trực)
                            StoredProcedure sp = SPs.ThuocNhapkhoOutput(objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                      Sluong, Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                                      objPhieuNhapCt.IdThuoc, objPhieuNhap.IdKhoxuat, objPhieuNhapCt.MaNhacungcap,
                                                                      objPhieuNhapCt.SoLo, objPhieuNhapCt.SoDky, objPhieuNhapCt.SoQdinhthau, -1, idthuockho, objPhieuNhapCt.NgayNhap, objPhieuNhapCt.GiaBhyt,
                                                                      objPhieuNhapCt.GiaPhuthuDungtuyen, objPhieuNhapCt.GiaPhuthuTraituyen, objPhieuNhapCt.KieuThuocvattu);
                            sp.Execute();
                            idthuockho = Utility.Int64Dbnull(sp.OutputValues[0], -1);
                           //Xuất thứ nguyên từ kho nhận
                            sp = SPs.ThuocXuatkho(objPhieuNhap.IdKhonhap, objPhieuNhapCt.IdThuoc,
                                                          objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                          Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                          objPhieuNhapCt.SoLuong, objPhieuNhapCt.IdThuockho, objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo, objHisDuocProperties.XoaDulieuKhiThuocDaHet ? 1 : 0, errorMessage);
                            sp.Execute();
                            //Cạp nhật lại id_thuockho =-1(giá trị này được update khi xác nhận phiếu). Giá trị id_chuyen cho biết chuyển từ id_thuockho của kho nội trú.
                            new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(-1)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                        }
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(0)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TPhieuNhapxuatthuoc.LoaiPhieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi hủy xác nhận phiếu trả thuốc từ tủ trực về kho lẻ nội trú",ex);
                return ActionResult.Error;
            }
        }
Ejemplo n.º 6
0
        public ActionResult XacNhanPhieuTrathuocThuatukhoanoitruveKhoLeNoitru(TPhieuNhapxuatthuoc objPhieuNhap, DateTime ngayxacnhan, ref string errMsg)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();
                        objPhieuNhap.NgayXacnhan = ngayxacnhan;
                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            ActionResult _Kiemtrathuocxacnhan = ActionResult.Success;
                            if (_Kiemtrathuocxacnhan != ActionResult.Success) return _Kiemtrathuocxacnhan;
                            long idthuockho = -1;
                            //Nhập vào kho nhận
                            StoredProcedure sp = SPs.ThuocNhapkhoOutput(objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                      objPhieuNhapCt.SoLuong, Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                                      objPhieuNhapCt.IdThuoc, objPhieuNhap.IdKhonhap,
                                                                      objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo, objPhieuNhapCt.SoDky, objPhieuNhapCt.SoQdinhthau,
                                                                      -1, idthuockho, ngayxacnhan, objPhieuNhapCt.GiaBhyt, objPhieuNhapCt.GiaPhuthuDungtuyen, objPhieuNhapCt.GiaPhuthuTraituyen, objPhieuNhapCt.KieuThuocvattu);
                            sp.Execute();
                            //Lấy về Id_thuockho tương ứng trong tủ trực
                            idthuockho = Utility.Int64Dbnull(sp.OutputValues[0], -1);

                            if (idthuockho > 0)
                                new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(idthuockho)
                                   .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                            else
                                idthuockho = Utility.Int64Dbnull(objPhieuNhapCt.IdThuockho, -1);
                            objPhieuNhapCt.IdThuockho = idthuockho;
                            //Insert dòng kho nhập
                            TBiendongThuoc objXuatNhap = new TBiendongThuoc();
                            objXuatNhap.IdPhieu = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieu);
                            objXuatNhap.IdPhieuChitiet = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieuchitiet);
                            objXuatNhap.MaPhieu = Utility.sDbnull(objPhieuNhap.MaPhieu);
                            objXuatNhap.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.DonGia);
                            objXuatNhap.GiaBan = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan);

                            objXuatNhap.GiaPhuthuDungtuyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuDungtuyen);
                            objXuatNhap.GiaPhuthuTraituyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuTraituyen);
                            objXuatNhap.GiaBhyt = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt);
                            objXuatNhap.GiaBhytCu = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhytCu);

                            objXuatNhap.IdChuyen = objPhieuNhapCt.IdChuyen;
                            objXuatNhap.NgayNhap = objPhieuNhapCt.NgayNhap;
                            objXuatNhap.GiaNhap = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaNhap);
                            objXuatNhap.SoHoadon = Utility.sDbnull(objPhieuNhap.SoHoadon);
                            objXuatNhap.SoChungtuKemtheo = objPhieuNhap.SoChungtuKemtheo;
                            objXuatNhap.PhuThu = 0;
                            objXuatNhap.DuTru = objPhieuNhap.DuTru;
                            objXuatNhap.Noitru = 0;
                            objXuatNhap.QuayThuoc = 0;
                            objXuatNhap.SoLuong = Utility.Int32Dbnull(objPhieuNhapCt.SoLuong);
                            objXuatNhap.SluongChia = Utility.Int32Dbnull(objPhieuNhapCt.SluongChia, 1);
                            objXuatNhap.NgayTao = globalVariables.SysDate;
                            objXuatNhap.NguoiTao = globalVariables.UserName;
                            objXuatNhap.ThanhTien = Utility.DecimaltoDbnull(objPhieuNhapCt.ThanhTien);
                            objXuatNhap.IdThuoc = Utility.Int32Dbnull(objPhieuNhapCt.IdThuoc);
                            objXuatNhap.IdThuockho = Utility.Int32Dbnull(objPhieuNhapCt.IdThuockho);
                            objXuatNhap.Vat = Utility.Int32Dbnull(objPhieuNhap.Vat);
                            objXuatNhap.IdNhanvien = Utility.Int16Dbnull(objPhieuNhap.IdNhanvien);
                            objXuatNhap.IdKho = Utility.Int16Dbnull(objPhieuNhap.IdKhonhap);
                            objXuatNhap.NgayHethan = objPhieuNhapCt.NgayHethan.Date;
                            objXuatNhap.MaNhacungcap = objPhieuNhapCt.MaNhacungcap;
                            objXuatNhap.SoLo = objPhieuNhapCt.SoLo;
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.IdKhoaLinh = objPhieuNhap.IdKhoalinh;//Chính là khoa trả

                            objXuatNhap.MaLoaiphieu = (byte)LoaiPhieu.Phieutrathuocthua;
                            objXuatNhap.TenLoaiphieu = Utility.TenLoaiPhieu(LoaiPhieu.Phieutrathuocthua);
                            objXuatNhap.NgayBiendong = objPhieuNhap.NgayXacnhan;
                            objXuatNhap.NgayHoadon = objPhieuNhap.NgayHoadon;
                            objXuatNhap.KieuThuocvattu = objPhieuNhapCt.KieuThuocvattu;
                            objXuatNhap.IsNew = true;
                            objXuatNhap.Save();
                        }
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(globalVariables.gv_intIDNhanvien)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(globalVariables.UserName)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(ngayxacnhan)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(1)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TPhieuNhapxuatthuoc.LoaiPhieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi xác nhận phiếu trả thuốc từ tủ trực khoa nội trú về kho lẻ", ex);
                return ActionResult.Error;
            }
        }
Ejemplo n.º 7
0
        public ActionResult PerformActionPaymentChoose(KcbThanhtoan objPayment, KcbLuotkham objLuotkham, KcbThanhtoanChitiet[] objArrPaymentDetail, ref int Payment_Id)
        {
            decimal PtramBHYT = 0;
            ///tổng tiền hiện tại truyền vào của lần payment đang thực hiện
            decimal v_TotalOrginPrice = 0;
            ///tổng tiền đã thanh toán
            decimal v_TotalPaymentDetail = 0;
            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var dbscope = new SharedDbConnectionScope())
                    {
                        ///lấy tổng số Payment của mang truyền vào của pay ment hiện tại
                        v_TotalOrginPrice = SumOfPaymentDetail_NGOAITRU(objArrPaymentDetail);

                        KcbThanhtoanCollection paymentCollection =
                            new KcbThanhtoanController().FetchByQuery(
                                KcbThanhtoan.CreateQuery().AddWhere(KcbThanhtoan.Columns.MaLuotkham, Comparison.Equals,
                                                                objLuotkham.MaLuotkham).AND(
                                                                    KcbThanhtoan.Columns.IdBenhnhan, Comparison.Equals,
                                                                    objLuotkham.IdBenhnhan).
                                    AND(KcbThanhtoan.Columns.KieuThanhtoan, Comparison.Equals, 0).AND(
                                        KcbThanhtoan.Columns.TrangThai, Comparison.Equals, 0));

                        foreach (KcbThanhtoan Payment in paymentCollection)
                        {
                            KcbThanhtoanChitietCollection paymentDetailCollection = new Select().From(KcbThanhtoanChitiet.Schema)
                                .Where(KcbThanhtoanChitiet.Columns.IdThanhtoan).IsEqualTo(Payment.IdThanhtoan)
                                .And(KcbThanhtoanChitiet.Columns.TrangthaiHuy).IsEqualTo(0).ExecuteAsCollection
                                <KcbThanhtoanChitietCollection>();

                            foreach (KcbThanhtoanChitiet paymentDetail in paymentDetailCollection)
                            {
                                if (paymentDetail.TuTuc == 0)
                                    v_TotalPaymentDetail += Utility.Int32Dbnull(paymentDetail.SoLuong) *
                                                            Utility.DecimaltoDbnull(paymentDetail.DonGia);

                            }
                        }
                        ///lấy thông tin chiết khấu xem đã thực hiện chưa
                        LayThongPtramBHYT(v_TotalOrginPrice + v_TotalPaymentDetail, objLuotkham, ref PtramBHYT);
                        ///hàm thực hiện việc xử lý lại thông tin
                        XuLyChiKhauDacBietBHYT(objLuotkham, PtramBHYT);

                        objPayment.TrangthaiIn = 0;
                        objPayment.KieuThanhtoan = 0;
                        objPayment.NguoiIn = string.Empty;
                        //objPayment.TrongGoi = 0;
                        //objPayment.IpMacTao = THU_VIEN_CHUNG.GetMACAddress();
                        //objPayment.IpMayTao = THU_VIEN_CHUNG.GetIP4Address();
                        objPayment.MaThanhtoan = THU_VIEN_CHUNG.TaoMathanhtoan(Convert.ToDateTime(objPayment.NgayThanhtoan));
                        objPayment.IsNew = true;
                        objPayment.MaKhoaThuchien = globalVariables.MA_KHOA_THIEN;
                        objPayment.Save();
                        //StoredProcedure sp = SPs.KcbThanhtoanThemmoi(objPayment.IdThanhtoan, objPayment.MaLuotkham, objPayment.IdBenhnhan,
                        //                  objPayment.NgayThanhtoan, objPayment.StaffId, objPayment.TrangThai,
                        //                  objPayment.NguoiTao, objPayment.CreatedDate, objPayment.NgaySua,
                        //                  objPayment.NguoiSua, objPayment.PaymentCode, objPayment.KieuThanhtoan,
                        //                  objPayment.DaIn, objPayment.NgayIn, objPayment.NgayTHop, objPayment.NguoiIn,
                        //                  objPayment.NguoiTHop, Utility.Int32Dbnull(objPayment.TrongGoi), objPayment.IpMayTao, objPayment.IpMacTao, globalVariables.MA_KHOA_THIEN);
                        //sp.Execute();
                        //objPayment.IdThanhtoan = Utility.Int32Dbnull(sp.OutputValues[0], -1);
                        //objPayment.IdThanhtoan = Utility.Int32Dbnull(_QueryPayment.GetMax(KcbThanhtoan.Columns.IdThanhtoan), -1);
                        log.Info("Lay ma thanh toan cua phan thanh toan Payment_ID={0}", objPayment.IdThanhtoan);
                        ///hàm thực hiện việc mảng thao tác mảng của chi tiết thanh toán

                        switch (LayChiKhauChiTiet())
                        {
                            case "KHONG":
                                objArrPaymentDetail =THU_VIEN_CHUNG.TinhPhamTramBHYT(objLuotkham, objArrPaymentDetail, PtramBHYT);
                                break;
                            case "CO":
                                objArrPaymentDetail = THU_VIEN_CHUNG.TinhPhamTramBHYT(objArrPaymentDetail, objLuotkham, PtramBHYT);
                                break;
                            default:
                                objArrPaymentDetail = THU_VIEN_CHUNG.TinhPhamTramBHYT(objLuotkham, objArrPaymentDetail, PtramBHYT);
                                break;
                        }
                        decimal BN_CT = 0m;
                        foreach (KcbThanhtoanChitiet objPaymentDetail in objArrPaymentDetail)
                        {

                            ///thanh toán phần thuốc);
                            if (THU_VIEN_CHUNG.LayMaDviLamViec() == "DETMAY")
                            {
                                if (objPaymentDetail.IdLoaithanhtoan == 3)
                                {
                                    new Update(KcbDonthuoc.Schema)
                                        .Set(KcbDonthuoc.Columns.TrangthaiThanhtoan).EqualTo(1)
                                        .Set(KcbDonthuoc.Columns.TrangThai).EqualTo(2)///nếu =2 đối với đơn thuốc ngoại trú
                                        .Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objPaymentDetail.IdPhieu).Execute();

                                }
                            }

                            switch (THU_VIEN_CHUNG.GetThanhToan_TraiTuyen())
                            {
                                case "PHUTHU":
                                    if (objPaymentDetail.IdLoaithanhtoan == 1)
                                    {
                                        objPaymentDetail.PhuThu = 0;
                                    }
                                    break;

                            }
                            objPaymentDetail.NguoiTao = globalVariables.UserName;
                            objPaymentDetail.NoiTru = 0;
                            //objPaymentDetail.TrongGoi = 0;
                            //objPaymentDetail.IpMacTao = THU_VIEN_CHUNG.GetMACAddress();
                            //objPaymentDetail.IpMayTao = THU_VIEN_CHUNG.GetIP4Address();
                            objPaymentDetail.IdThanhtoan = Utility.Int32Dbnull(objPayment.IdThanhtoan, -1);
                            objPaymentDetail.BnhanChitra = Utility.DecimaltoDbnull(objPaymentDetail.BnhanChitra);
                            BN_CT+=objPaymentDetail.BnhanChitra;
                            objPaymentDetail.TenLoaithanhtoan = THU_VIEN_CHUNG.MaKieuThanhToan(Utility.Int32Dbnull(objPaymentDetail.IdLoaithanhtoan));
                            StoredProcedure spPaymentDetail = SPs.KcbThanhtoanThemchitiet(
                                objPaymentDetail.IdChitiet, objPaymentDetail.IdThanhtoan,
                                objPaymentDetail.SoLuong, objPaymentDetail.DonGia,
                                objPaymentDetail.BhytChitra, objPaymentDetail.BnhanChitra,
                                Utility.DecimaltoDbnull(objPaymentDetail.BnhanChitra),
                                objPaymentDetail.PhuThu, objPaymentDetail.IdPhieu,
                                objPaymentDetail.IdPhieuChitiet, objPaymentDetail.IdDichvu,
                                objPaymentDetail.IdChitietdichvu, objPaymentDetail.IdLoaithanhtoan,
                                objPaymentDetail.TrangthaiHuy, objPaymentDetail.TuTuc,
                                objPaymentDetail.NguoiHuy, objPaymentDetail.NgayHuy,
                                objPaymentDetail.IdPhongkham, objPaymentDetail.IdBacsiChidinh,
                                objPaymentDetail.SttIn, objPaymentDetail.DonviTinh,
                                objPaymentDetail.MaDoituongKcb, objPaymentDetail.PtramBhyt,
                                objPaymentDetail.TenChitietdichvu, Utility.sDbnull(objPaymentDetail.TenChitietdichvu),
                                objPaymentDetail.TenLoaithanhtoan, 0, -1, -1,
                                objPaymentDetail.NoiTru, objPaymentDetail.NguoiTao, "", "");

                            spPaymentDetail.Execute();
                            objPaymentDetail.IdChitiet = Utility.Int32Dbnull(spPaymentDetail.OutputValues[0], -1);
                            UpdateTrangThaiBangChucNang(objPayment, objPaymentDetail);

                        }
                        new Update(KcbThanhtoan.Schema).Set(KcbThanhtoan.TongTienColumn).EqualTo(BN_CT).Where(KcbThanhtoan.IdThanhtoanColumn).IsEqualTo(objPayment.IdThanhtoan).Execute();
                        if (objLuotkham.MaDoituongKcb == "BHYT")
                        {
                            if (globalVariables.gv_strTuyenBHYT == "TW")
                            {
                                SqlQuery sqlQuery = new Select().From(KcbThanhtoanChitiet.Schema)
                                    .Where(KcbThanhtoanChitiet.Columns.IdThanhtoan).In(
                                        new Select(KcbThanhtoan.Columns.IdThanhtoan).From(KcbThanhtoan.Schema).Where(
                                            KcbThanhtoan.Columns.MaLuotkham).IsEqualTo(
                                                objLuotkham.MaLuotkham).And(KcbThanhtoan.Columns.IdBenhnhan).IsEqualTo(
                                                    objLuotkham.IdBenhnhan).And(KcbThanhtoan.Columns.KieuThanhtoan).
                                            IsEqualTo(0).
                                            And(KcbThanhtoan.Columns.TrangThai).IsEqualTo(0))
                                    .And(KcbThanhtoanChitiet.Columns.TrangthaiHuy).IsEqualTo(0)
                                    .And(KcbThanhtoanChitiet.Columns.TuTuc).IsEqualTo(0);

                                KcbThanhtoanChitietCollection objPaymentDetailCollection =
                                    sqlQuery.ExecuteAsCollection<KcbThanhtoanChitietCollection>();
                                decimal TongTien =
                                    Utility.DecimaltoDbnull(objPaymentDetailCollection.Sum(c => c.SoLuong * c.DonGia));
                                LayThongPtramBHYT(TongTien, objLuotkham, ref PtramBHYT);
                                foreach (KcbThanhtoanChitiet objPaymentDetail in objPaymentDetailCollection)
                                {
                                    decimal BHCT = Utility.DecimaltoDbnull(objPaymentDetail.DonGia * PtramBHYT / 100);
                                    decimal BNCT = Utility.DecimaltoDbnull(objPaymentDetail.DonGia - BHCT);
                                    objPaymentDetail.BhytChitra = BHCT;
                                    objPaymentDetail.PtramBhyt = PtramBHYT;
                                    objPaymentDetail.BnhanChitra = BNCT;

                                    //new Update(KcbThanhtoanChitiet.Schema)
                                    //    .Set(KcbThanhtoanChitiet.Columns.PtramBhyt).EqualTo(PtramBHYT)
                                    //    .Set(KcbThanhtoanChitiet.Columns.DiscountRate).EqualTo(BHCT)
                                    //    .Set(KcbThanhtoanChitiet.Columns.DiscountPrice).EqualTo(BNCT)
                                    //    .Where(KcbThanhtoanChitiet.Columns.IdChitiet).IsEqualTo(objPaymentDetail.IdChitiet).Execute();
                                    //new Update(KydongKcbThanhtoanChitiet.Schema)
                                    //    .Set(KydongKcbThanhtoanChitiet.Columns.PtramBhyt).EqualTo(PtramBHYT)
                                    //    .Set(KydongKcbThanhtoanChitiet.Columns.DiscountRate).EqualTo(BHCT)
                                    //    .Set(KydongKcbThanhtoanChitiet.Columns.DiscountPrice).EqualTo(BNCT)
                                    //    .Where(KydongKcbThanhtoanChitiet.Columns.IdChiTietTToan).IsEqualTo(objPaymentDetail.IdChitiet)
                                    //    .And(KydongKcbThanhtoanChitiet.Columns.PaymentDetailType).IsEqualTo(0)
                                    //    .Execute();
                                }
                                objPaymentDetailCollection.SaveAll();
                            }

                        }

                    }
                    scope.Complete();
                    Payment_Id = Utility.Int32Dbnull(objPayment.IdThanhtoan, -1);
                    log.Info("Thuc hien thanh cong viec thanh toan");
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                log.Error("Loi thuc hien thanh toan:" + ex.ToString());
                return ActionResult.Error;
            }
        }
Ejemplo n.º 8
0
        private void GetData()
        {
            string ReasonBy = "";

               string sAccountName = THU_VIEN_CHUNG.LayMaDviLamViec();
               LayThongTinPaymentDetail(sAccountName);
            //grdPaymentDetail.DataSource = m_dtPaymentDetail;

            SqlQuery sqlQuery = new Select().From(TPhieuthu.Schema)
                .Where(TPhieuthu.Columns.PaymentId).IsEqualTo(Utility.Int32Dbnull(txtPayment_ID.Text)).And(
                    TPhieuthu.Columns.LoaiPhieu).IsEqualTo(status);

            if (sqlQuery.GetRecordCount() <= 0)
            {
                TPayment objPayment = TPayment.FetchByID(Utility.Int32Dbnull(txtPayment_ID.Text, -1));
                if (objPayment != null)
                {
                    dtCreateDate.Value = Convert.ToDateTime(objPayment.PaymentDate);
                    txtPayment_ID.Text = Utility.sDbnull(objPayment.PaymentId, "-1");
                    txtMA_PTHU.Text = THU_VIEN_CHUNG.GetMaPhieuThu(dtCreateDate.Value,0);
                    Janus.Windows.GridEX.GridEXColumn gridExColumn = grdPaymentDetail.RootTable.Columns["TONG"];
                    txtSO_TIEN.Text = Utility.sDbnull(grdPaymentDetail.GetTotal(gridExColumn, Janus.Windows.GridEX.AggregateFunction.Sum));
                    txtSLUONG_CTU_GOC.Text = "1";
                    TPatientInfo objPatientInfo = TPatientInfo.FetchByID(objPayment.PatientId);
                    if (objPatientInfo != null)
                    {
                        txtNGUOI_NOP.Text = objPatientInfo.PatientName;
                        label9.Text = "Người nhận";
                    }
                    var query = (from loz in grdPaymentDetail.GetDataRows().AsEnumerable()
                                 let x=Utility.sDbnull(loz.Cells[TPaymentDetail.Columns.ServiceDetailName].Value)
                                 let y=loz.RowType
                                 where(x!="")  &&(y==Janus.Windows.GridEX.RowType.Record)
                                 select x).ToArray();
                    txtLDO_NOP.Text = string.Join(";", query);

                }
            }
            else
            {
                var objPhieuthu = sqlQuery.ExecuteSingle<TPhieuthu>();
                if (objPhieuthu != null)
                {
                    txtSLUONG_CTU_GOC.Text = Utility.sDbnull(objPhieuthu.SluongCtuGoc, 1);
                    txtMA_PTHU.Text = Utility.sDbnull(objPhieuthu.MaPthu, "");
                    txtNGUOI_NOP.Text = Utility.sDbnull(objPhieuthu.NguoiNop);
                    txtSO_TIEN.Text = Utility.sDbnull(objPhieuthu.SoTien);
                    txtTKHOAN_CO.Text = Utility.sDbnull(objPhieuthu.TkhoanCo, "");
                    txtTKHOAN_NO.Text = Utility.sDbnull(objPhieuthu.TkhoanNo, "");
                    txtLDO_NOP.Text = Utility.sDbnull(objPhieuthu.LdoNop);
                    dtCreateDate.Value = Convert.ToDateTime(objPhieuthu.NgayThien);
                }
            }
            sqlQuery = new Select().From(TPaymentDetail.Schema)
              .Where(TPaymentDetail.Columns.PaymentId).IsEqualTo(Utility.Int32Dbnull(txtPayment_ID.Text))
              .And(TPaymentDetail.Columns.IsCancel).IsEqualTo(0);
            TPaymentDetailCollection objPaymentDetailCollection = sqlQuery.ExecuteAsCollection<TPaymentDetailCollection>();
            txtSoTienGoc.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.Quantity * c.OriginPrice));
            txtTienBHCT.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.Quantity * c.DiscountRate));
            txtTienBNCT.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.Quantity * c.DiscountPrice));
            txtTienPhuThu.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.Quantity * c.SurchargePrice));
            txtTienBNPhaiTra.Text =
                Utility.sDbnull(Utility.DecimaltoDbnull(txtTienPhuThu.Text) + Utility.DecimaltoDbnull(txtTienBNCT.Text));
            Utility.SetMessage(lblMoneyLetter, new MoneyByLetter().sMoneyToLetter(txtTienBNPhaiTra.Text), true);
        }
Ejemplo n.º 9
0
 public ActionResult HuyThongTinLanThanhToan(KcbThanhtoan objThanhtoan, KcbLuotkham objLuotkham, string lydohuy, int IdHdonLog, bool HuyBienlai)
 {
     try
     {
         decimal v_TotalPaymentDetail = 0;
         decimal v_DiscountRate = 0;
         using (var scope = new TransactionScope())
         {
             using (var dbscope = new SharedDbConnectionScope())
             {
                 if (Utility.Byte2Bool(objLuotkham.TrangthaiNoitru) && Utility.Byte2Bool(objThanhtoan.NoiTru))
                 {
                     if (THU_VIEN_CHUNG.Laygiatrithamsohethong("NOITRU_TUDONGHOANUNG_KHITHANHTOANNOITRU", "0", false) == "1")
                     SPs.NoitruHuyhoanung(objLuotkham.MaLuotkham, objLuotkham.IdBenhnhan,(byte)1).Execute();
                 }
                 else
                 {
                     if (THU_VIEN_CHUNG.Laygiatrithamsohethong("KCB_THANHTOAN_KICHHOAT_TAMUNG_NGOAITRU", "0", false) == "1")
                         if (THU_VIEN_CHUNG.Laygiatrithamsohethong("NGOAITRU_TUDONGHOANUNG_KHITHANHTOANNGOAITRU", "0", false) == "1")
                             SPs.NoitruHuyhoanung(objLuotkham.MaLuotkham, objLuotkham.IdBenhnhan, (byte)0).Execute();
                 }
                 if (IdHdonLog > 0)
                     if (HuyBienlai)
                         new Update(HoadonLog.Schema).Set(HoadonLog.Columns.TrangThai).EqualTo(1)
                             .Where(HoadonLog.Columns.IdHdonLog).IsEqualTo(IdHdonLog).Execute();
                     else
                         new Delete().From(HoadonLog.Schema)
                             .Where(HoadonLog.Columns.IdHdonLog).IsEqualTo(IdHdonLog).Execute();
                 SqlQuery sqlQuery =
                     new Select().From(KcbThanhtoanChitiet.Schema).Where(KcbThanhtoanChitiet.Columns.IdThanhtoan).IsEqualTo(
                         objThanhtoan.IdThanhtoan);
                 KcbThanhtoanChitietCollection arrPaymentDetails = sqlQuery.ExecuteAsCollection<KcbThanhtoanChitietCollection>();
                 KcbLoghuy objKcbLoghuy = new KcbLoghuy();
                 objKcbLoghuy.IdBenhnhan = objThanhtoan.IdBenhnhan;
                 objKcbLoghuy.MaLuotkham = objThanhtoan.MaLuotkham;
                 objKcbLoghuy.IdNhanvien = globalVariables.gv_intIDNhanvien;
                 objKcbLoghuy.SotienHuy = objThanhtoan.TongTien;
                 objKcbLoghuy.LydoHuy = lydohuy;
                 objKcbLoghuy.NgayHuy = DateTime.Now;
                 objKcbLoghuy.NgayTao = DateTime.Now;
                 objKcbLoghuy.NguoiTao = globalVariables.UserName;
                 objKcbLoghuy.IsNew = true;
                 objKcbLoghuy.LoaiphieuHuy = Utility.ByteDbnull(objThanhtoan.KieuThanhtoan, 0);
                 objKcbLoghuy.Save();
                 if (objThanhtoan != null)
                     HUYTHONGTIN_THANHTOAN(arrPaymentDetails, objThanhtoan);
                 new Delete().From(KcbPhieuDct.Schema)
                     .Where(KcbPhieuDct.Columns.MaLuotkham).IsEqualTo(objThanhtoan.MaLuotkham)
                     .And(KcbPhieuDct.Columns.IdBenhnhan).IsEqualTo(objThanhtoan.IdBenhnhan)
                     .And(KcbPhieuDct.Columns.LoaiThanhtoan).IsEqualTo(objThanhtoan.KieuThanhtoan).Execute();
                 if (objLuotkham != null)
                 {
                     byte locked = (byte)(objLuotkham.MaDoituongKcb == "DV" ? objLuotkham.Locked : 0);
                     new Update(KcbLuotkham.Schema)
                         .Set(KcbLuotkham.Columns.NgayKetthuc).EqualTo(null)
                         .Set(KcbLuotkham.Columns.NguoiKetthuc).EqualTo(string.Empty)
                         .Set(KcbLuotkham.Columns.Locked).EqualTo(locked)
                         .Set(KcbLuotkham.Columns.TrangthaiNgoaitru).EqualTo(locked)
                         .Set(KcbLuotkham.Columns.TthaiThanhtoannoitru).EqualTo(0)
                         .Set(KcbLuotkham.Columns.LydoKetthuc).EqualTo("")
                         .Where(KcbLuotkham.Columns.MaLuotkham).IsEqualTo(objLuotkham.MaLuotkham)
                         .And(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(objLuotkham.IdBenhnhan).Execute();
                 }
                 KcbThanhtoan.Delete(objThanhtoan.IdThanhtoan);
                 new Delete().From(KcbThanhtoanPhanbotheoPTTT.Schema).Where(KcbThanhtoanPhanbotheoPTTT.Columns.IdThanhtoan).IsEqualTo(objThanhtoan.IdThanhtoan).Execute();
                 if (objLuotkham != null) log.Info(string.Format("Phiếu thanh toán ID: {0} của bệnh nhân: {1} - ID Bệnh nhân: {2} đã được hủy bởi :{3} với lý do hủy :{4}", objThanhtoan.IdThanhtoan.ToString(), objLuotkham.MaLuotkham, objLuotkham.IdBenhnhan, globalVariables.UserName, lydohuy));
             }
             scope.Complete();
             return ActionResult.Success;
         }
     }
     catch (Exception exception)
     {
         log.Error("Loi trong qua trinh huy thong tin {0}", exception.ToString());
         return ActionResult.Error;
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// hàm thưc hiện việc load thông tin của kiểm tra thông tin của bảo hiểm y tế khi laod form heienj tại
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frm_KiemTra_BHYT_Load(object sender, EventArgs e)
        {
            txtTieuDe.Text = Utility.sDbnull(tieude);
            if(objLuotkham!=null)
            {
                LayThongTinPaymentDetail();
                SqlQuery sqlQuery = new Select().From(KcbThanhtoanChitiet.Schema)
                    .Where(KcbThanhtoanChitiet.Columns.IdThanhtoan)
                    .In(
                        new Select(KcbThanhtoan.Columns.IdThanhtoan).From(KcbThanhtoan.Schema).Where(KcbThanhtoan.Columns.MaLuotkham).
                            IsEqualTo(
                                objLuotkham.MaLuotkham).And(KcbThanhtoan.Columns.IdBenhnhan).IsEqualTo(
                                    Utility.Int32Dbnull(objLuotkham.IdBenhnhan)).And(KcbThanhtoan.Columns.KieuThanhtoan).IsEqualTo(0))
                    .And(KcbThanhtoanChitiet.Columns.TrangthaiHuy).IsEqualTo(0)
                    .And(KcbThanhtoanChitiet.Columns.TuTuc).IsEqualTo(0);

                KcbThanhtoanChitietCollection objPaymentDetailCollection = sqlQuery.ExecuteAsCollection<KcbThanhtoanChitietCollection>();
                if (objPaymentDetailCollection.Count() > 0)
                {
                    txtSoTienGoc.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.SoLuong * c.DonGia));
                    txtTienBHCT.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.SoLuong * c.BhytChitra));
                    txtTienBNCT.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.SoLuong * c.BnhanChitra));
                    txtTienPhuThu.Text = Utility.sDbnull(objPaymentDetailCollection.Sum(c => c.SoLuong * c.PhuThu));
                    txtTienBNPhaiTra.Text =
                        Utility.sDbnull(Utility.DecimaltoDbnull(txtTienPhuThu.Text) + Utility.DecimaltoDbnull(txtTienBNCT.Text));
                    Utility.SetMsg(lblMoneyLetter, new MoneyByLetter().sMoneyToLetter(txtTienBNPhaiTra.Text), true);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// hàm thực hiện việc xác nhận thông tin 
        /// </summary>
        /// <param name="objPhieuNhap"></param>
        /// <returns></returns>
        public ActionResult XacNhanPhieuNhapKho(TPhieuNhapxuatthuoc objPhieuNhap,DateTime ngayxacnhan)
        {
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        //Sẽ hướng đơn vị theo kiểu bốc thuốc trong bảng t_thuockho+Cho nhập giá BHYT,giá DV ngay tại chức năng nhập thuốc từ nhà cung cấp
                        bool BHYT_LUACHON_APDUNG = Utility.Int32Dbnull(THU_VIEN_CHUNG.Laygiatrithamsohethong("BHYT_LUACHON_APDUNG", "0", false), 0) == 1;
                        bool TUDONG_CAPNHAT_GIADICHVU = Utility.Int32Dbnull(THU_VIEN_CHUNG.Laygiatrithamsohethong("TUDONG_CAPNHAT_GIADICHVU", "0", false), 0) == 1;
                        bool BHYT_CHOPHEPNHAPGIAPHUTHU = Utility.Int32Dbnull(THU_VIEN_CHUNG.Laygiatrithamsohethong("BHYT_CHOPHEPNHAPGIAPHUTHU", "0", false), 0) == 1;

                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();
                        objPhieuNhap.NgayXacnhan = ngayxacnhan;
                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {

                            long idthuockho=-1;
                            StoredProcedure sp = SPs.ThuocNhapkhoOutput(objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                      objPhieuNhapCt.SoLuong, Utility.DecimaltoDbnull(objPhieuNhap.Vat),
                                                                      objPhieuNhapCt.IdThuoc, objPhieuNhap.IdKhonhap, objPhieuNhapCt.MaNhacungcap,
                                                                      objPhieuNhapCt.SoLo, objPhieuNhapCt.SoDky, objPhieuNhapCt.SoQdinhthau,
                                                                      -1, idthuockho, ngayxacnhan, objPhieuNhapCt.GiaBhyt, objPhieuNhapCt.GiaPhuthuDungtuyen, objPhieuNhapCt.GiaPhuthuTraituyen, objPhieuNhapCt.KieuThuocvattu);

                            sp.Execute();
                            idthuockho=Utility.Int64Dbnull(sp.OutputValues[0],-1);
                            new Update(TPhieuNhapxuatthuocChitiet.Schema)
                                .Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(idthuockho)
                                .Set(TPhieuNhapxuatthuocChitiet.Columns.NgayNhap).EqualTo(ngayxacnhan.Date)
                                .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                            TBiendongThuoc objXuatNhap = new TBiendongThuoc();
                            objXuatNhap.IdPhieu = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieu);
                            objXuatNhap.IdPhieuChitiet = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieuchitiet);
                            objXuatNhap.MaPhieu = Utility.sDbnull(objPhieuNhap.MaPhieu);
                            objXuatNhap.NgayNhap = ngayxacnhan.Date;
                            objXuatNhap.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.DonGia);
                            objXuatNhap.GiaBan = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan);
                            objXuatNhap.ThuocVay = objPhieuNhap.PhieuVay;
                            objXuatNhap.GiaNhap = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaNhap);
                            objXuatNhap.SoHoadon = Utility.sDbnull(objPhieuNhap.SoHoadon);
                            objXuatNhap.SoChungtuKemtheo = objPhieuNhap.SoChungtuKemtheo;
                            objXuatNhap.PhuThu = 0;
                            objXuatNhap.SoLuong = Utility.Int32Dbnull(objPhieuNhapCt.SoLuong);
                            objXuatNhap.NgayTao = globalVariables.SysDate;
                            objXuatNhap.NguoiTao = globalVariables.UserName;
                            objXuatNhap.ThanhTien = Utility.DecimaltoDbnull(objPhieuNhapCt.ThanhTien);
                            objXuatNhap.IdThuoc = Utility.Int32Dbnull(objPhieuNhapCt.IdThuoc);
                            objXuatNhap.Vat = Utility.Int32Dbnull(objPhieuNhap.Vat);
                            objXuatNhap.IdNhanvien = Utility.Int16Dbnull(objPhieuNhap.IdNhanvien);
                            objXuatNhap.IdKho = Utility.Int16Dbnull(objPhieuNhap.IdKhonhap);
                            objXuatNhap.NgayHethan = objPhieuNhapCt.NgayHethan.Date;
                            //objXuatNhap.IdNhaCcap = Utility.Int32Dbnull(objPhieuNhap.IdNhaCcap);
                            objXuatNhap.MaNhacungcap = objPhieuNhapCt.MaNhacungcap;
                            objXuatNhap.SoLo = objPhieuNhapCt.SoLo;
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.MaLoaiphieu = Utility.ByteDbnull(objPhieuNhap.LoaiPhieu);
                            objXuatNhap.TenLoaiphieu = Utility.sDbnull(objPhieuNhap.TenLoaiphieu);
                            objXuatNhap.NgayBiendong = objPhieuNhap.NgayXacnhan;
                            objXuatNhap.NgayHoadon = objPhieuNhap.NgayHoadon;
                            objXuatNhap.IdThuockho = idthuockho;

                            objXuatNhap.GiaBhyt = objPhieuNhapCt.GiaBhyt;
                            objXuatNhap.GiaBhytCu =objPhieuNhapCt.GiaBhytCu;
                            objXuatNhap.GiaPhuthuDungtuyen = objPhieuNhapCt.GiaPhuthuDungtuyen;
                            objXuatNhap.GiaPhuthuTraituyen = objPhieuNhapCt.GiaPhuthuTraituyen;
                            objXuatNhap.Noitru = 0;
                            objXuatNhap.QuayThuoc = 0;
                            objXuatNhap.DuTru = 0;
                            objXuatNhap.KieuThuocvattu = objPhieuNhap.KieuThuocvattu;
                            objXuatNhap.IsNew = true;
                            objXuatNhap.Save();

                            new Update(DmucThuoc.Schema)
                                       .Set(DmucThuoc.Columns.DonGia).EqualTo(objPhieuNhapCt.DonGia)
                                       .Set(DmucThuoc.Columns.GiaDv).EqualTo(objPhieuNhapCt.GiaBan)
                                       .Set(DmucThuoc.Columns.GiaBhyt).EqualTo(objPhieuNhapCt.GiaBhyt)
                                       .Set(DmucThuoc.Columns.PhuthuDungtuyen).EqualTo(objPhieuNhapCt.GiaPhuthuDungtuyen)
                                       .Set(DmucThuoc.Columns.PhuthuTraituyen).EqualTo(objPhieuNhapCt.GiaPhuthuTraituyen)
                                       .Where(DmucThuoc.Columns.IdThuoc).IsEqualTo(objPhieuNhapCt.IdThuoc).Execute();

                            if ((Utility.ByteDbnull(objPhieuNhapCt.CoBhyt, 0) == 1 && BHYT_LUACHON_APDUNG) || TUDONG_CAPNHAT_GIADICHVU)
                            {
                                DmucDoituongkcbCollection _lstdoituong = new Select().From(DmucDoituongkcb.Schema).ExecuteAsCollection<DmucDoituongkcbCollection>();
                                //DmucDoituongkcbCollection _kcb = new Select().From(DmucDoituongkcb.Schema).Where(DmucDoituongkcb.Columns.IdLoaidoituongKcb).IsEqualTo(0).ExecuteAsCollection<DmucDoituongkcbCollection>();
                                DmucThuoc _objThuoc = new Select().From(DmucThuoc.Schema).Where(DmucThuoc.Columns.IdThuoc).IsEqualTo(objPhieuNhapCt.IdThuoc).ExecuteSingle<DmucThuoc>();
                                if (_lstdoituong != null && _objThuoc != null )
                                {

                                    foreach (DmucDoituongkcb _kcb in _lstdoituong)
                                    {
                                        if ((Utility.ByteDbnull(objPhieuNhapCt.CoBhyt, 0) == 1 && BHYT_LUACHON_APDUNG && _kcb.IdLoaidoituongKcb == 0) || (TUDONG_CAPNHAT_GIADICHVU && _kcb.IdLoaidoituongKcb == 1))
                                        {
                                            decimal DonGia = 0m;
                                            decimal PhuthuDungtuyen = 0m;
                                            decimal PhuthuTraituyen = 0m;
                                            bool allowupdate = false;
                                            QheDoituongThuoc objQhe = new Select().From(QheDoituongThuoc.Schema)
                                                .Where(QheDoituongThuoc.Columns.IdThuoc).IsEqualTo(objPhieuNhapCt.IdThuoc)
                                          .And(QheDoituongThuoc.Columns.IdLoaidoituongKcb).IsEqualTo(_kcb.IdLoaidoituongKcb).ExecuteSingle<QheDoituongThuoc>();
                                            if (objQhe!=null)//Đã có quan hệ-->Cập nhật lại
                                            {
                                                if (_kcb.IdLoaidoituongKcb == 0)
                                                {
                                                    if (Utility.ByteDbnull(objPhieuNhapCt.CoBhyt, 0) == 1 && BHYT_LUACHON_APDUNG)
                                                    {
                                                        allowupdate = true;
                                                        DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt, 0);
                                                        PhuthuDungtuyen = BHYT_CHOPHEPNHAPGIAPHUTHU ? Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuDungtuyen, 0) : objQhe.PhuthuDungtuyen.Value;
                                                        PhuthuTraituyen = BHYT_CHOPHEPNHAPGIAPHUTHU ? Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuTraituyen, 0) : objQhe.PhuthuTraituyen.Value;
                                                    }
                                                }
                                                else
                                                {
                                                    if (TUDONG_CAPNHAT_GIADICHVU)
                                                    {
                                                        allowupdate = true;
                                                        DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan, 0);
                                                        PhuthuDungtuyen =  objQhe.PhuthuDungtuyen.Value;
                                                        PhuthuTraituyen = objQhe.PhuthuTraituyen.Value;
                                                    }
                                                }
                                                if (allowupdate)
                                                    new Update(QheDoituongThuoc.Schema)
                                                        .Set(QheDoituongThuoc.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                                                        .Set(QheDoituongThuoc.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                                                        .Set(QheDoituongThuoc.Columns.DonGia).EqualTo(DonGia)
                                                        .Set(QheDoituongThuoc.Columns.PhuthuDungtuyen).EqualTo(PhuthuDungtuyen)
                                                        .Set(QheDoituongThuoc.Columns.PhuthuTraituyen).EqualTo(PhuthuTraituyen)
                                                        .Where(QheDoituongThuoc.Columns.IdLoaidoituongKcb).IsEqualTo(_kcb.IdLoaidoituongKcb)
                                                        .And(QheDoituongThuoc.Columns.IdThuoc).IsEqualTo(objPhieuNhapCt.IdThuoc)
                                                            .Execute();
                                            }
                                            else
                                            {
                                                 if (_kcb.IdLoaidoituongKcb == 0)
                                                {
                                                    if (Utility.ByteDbnull(objPhieuNhapCt.CoBhyt, 0) == 1 && BHYT_LUACHON_APDUNG)
                                                    {
                                                        allowupdate = true;
                                                        DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt, 0);
                                                        PhuthuDungtuyen = BHYT_CHOPHEPNHAPGIAPHUTHU ? Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuDungtuyen, 0) : 0m;
                                                        PhuthuTraituyen = BHYT_CHOPHEPNHAPGIAPHUTHU ? Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuTraituyen, 0) : 0m;
                                                    }
                                                }
                                                else
                                                {
                                                    if (TUDONG_CAPNHAT_GIADICHVU)
                                                    {
                                                        allowupdate = true;
                                                        DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan, 0);
                                                        PhuthuDungtuyen = 0m;
                                                        PhuthuTraituyen = 0m;
                                                    }
                                                }
                                                 if (allowupdate)
                                                 {
                                                     QheDoituongThuoc _newItems = new QheDoituongThuoc();
                                                     _newItems.IdDoituongKcb = _kcb.IdDoituongKcb;
                                                     _newItems.IdLoaithuoc = _objThuoc.IdLoaithuoc;
                                                     _newItems.IdThuoc = objPhieuNhapCt.IdThuoc;
                                                     _newItems.TyleGiamgia = 0;
                                                     _newItems.KieuGiamgia = "%";
                                                     _newItems.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt, 0);
                                                     _newItems.PhuthuDungtuyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuDungtuyen, 0);
                                                     _newItems.PhuthuTraituyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuTraituyen, 0);
                                                     _newItems.IdLoaidoituongKcb = _kcb.IdLoaidoituongKcb;
                                                     _newItems.MaDoituongKcb = _kcb.MaDoituongKcb;

                                                     _newItems.NguoiTao = globalVariables.UserName;
                                                     _newItems.NgayTao = globalVariables.SysDate;
                                                     _newItems.MaKhoaThuchien = "ALL";
                                                     _newItems.IsNew = true;
                                                     _newItems.Save();
                                                 }

                                            }
                                        }
                                    }
                                }
                            }
                        }
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(globalVariables.gv_intIDNhanvien)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(globalVariables.UserName)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(ngayxacnhan)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(1)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception exception)
            {
                log.Error("Loi trong qua trinh xac nhan don thuoc :{0}", exception);
                return ActionResult.Error;

            }
        }
Ejemplo n.º 12
0
        public ActionResult HuyXacNhanDonThuocBN_Tutruc(KcbDonthuoc objDonthuoc, KcbDonthuocChitiet[] arrDetails)
        {
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        HisDuocProperties objHisDuocProperties = new HisDuocProperties();
                        // if(objHisDuocProperties.KieuDuyetDonThuoc=="DONTHUOC")id_kho=Utility.Int32Dbnull(objDonthuoc.IdKho)
                        objHisDuocProperties = PropertyLib._HisDuocProperties;
                        int id_thuockho = -1;
                        foreach (KcbDonthuocChitiet objDetail in arrDetails)
                        {
                            SqlQuery sqlQuery = new Select().From(TPhieuXuatthuocBenhnhanChitiet.Schema)
                                .Where(TPhieuXuatthuocBenhnhanChitiet.Columns.IdPhieuChitiet).IsEqualTo(objDetail.IdChitietdonthuoc);
                            TPhieuXuatthuocBenhnhanChitietCollection objXuatBnhanCtCollection =
                                sqlQuery.ExecuteAsCollection<TPhieuXuatthuocBenhnhanChitietCollection>();
                            foreach (TPhieuXuatthuocBenhnhanChitiet PhieuXuatBnhanCt in objXuatBnhanCtCollection)
                            {
                                StoredProcedure sp = SPs.ThuocNhapkhoOutput(PhieuXuatBnhanCt.NgayHethan, PhieuXuatBnhanCt.DonGia, PhieuXuatBnhanCt.GiaBan,
                                                                 PhieuXuatBnhanCt.SoLuong, Utility.DecimaltoDbnull(PhieuXuatBnhanCt.Vat),
                                                                 PhieuXuatBnhanCt.IdThuoc, PhieuXuatBnhanCt.IdKho, PhieuXuatBnhanCt.MaNhacungcap,
                                                                 PhieuXuatBnhanCt.SoLo, PhieuXuatBnhanCt.SoDky, PhieuXuatBnhanCt.SoQdinhthau, -1, id_thuockho,
                                                                 objDonthuoc.NgayXacnhan, PhieuXuatBnhanCt.GiaBhyt,
                                                                 PhieuXuatBnhanCt.PhuthuDungtuyen, PhieuXuatBnhanCt.PhuthuTraituyen, objDonthuoc.KieuThuocvattu);

                                sp.Execute();
                                ///xóa thông tin bảng chi tiết
                                new Delete().From(TPhieuXuatthuocBenhnhanChitiet.Schema)
                                    .Where(TPhieuXuatthuocBenhnhanChitiet.Columns.IdPhieuChitiet).IsEqualTo(Utility.Int32Dbnull(PhieuXuatBnhanCt.IdPhieuChitiet))
                                    .Execute();

                                new Delete().From(TBiendongThuoc.Schema)
                                    .Where(TBiendongThuoc.Columns.IdPhieuChitiet).IsEqualTo(Utility.Int32Dbnull(PhieuXuatBnhanCt.IdPhieuChitiet))
                                    .And(TBiendongThuoc.Columns.MaLoaiphieu).IsEqualTo(3).Execute();

                                sqlQuery = new Select().From(TPhieuXuatthuocBenhnhanChitiet.Schema)
                                    .Where(TPhieuXuatthuocBenhnhanChitiet.Columns.IdPhieu).IsEqualTo(
                                        PhieuXuatBnhanCt.IdPhieu);
                                if (sqlQuery.GetRecordCount() <= 0)
                                {
                                    TPhieuXuatthuocBenhnhan.Delete(PhieuXuatBnhanCt.IdPhieu);
                                }
                            }
                            new Delete().From(TXuatthuocTheodon.Schema)
                                .Where(TXuatthuocTheodon.Columns.IdChitietdonthuoc).IsEqualTo(objDetail.IdChitietdonthuoc).Execute();
                            new Update(KcbDonthuocChitiet.Schema)
                                .Set(KcbDonthuocChitiet.Columns.TrangThai).EqualTo(0)
                                .Where(KcbDonthuocChitiet.Columns.IdChitietdonthuoc).IsEqualTo(objDetail.IdChitietdonthuoc).
                                Execute();

                        }
                        SqlQuery sqlQuery1 = new Select().From(KcbDonthuocChitiet.Schema)
                              .Where(KcbDonthuocChitiet.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc)
                              .And(KcbDonthuocChitiet.Columns.TrangThai).IsEqualTo(0);
                        int status = sqlQuery1.GetRecordCount() <= 0 ? 1 : 0;
                        new Update(KcbDonthuoc.Schema)
                                  .Set(KcbDonthuoc.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                                  .Set(KcbDonthuoc.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                                  .Set(KcbDonthuoc.Columns.TrangThai).EqualTo(status)
                                  .Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc).Execute();

                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception exception)
            {
                log.Error("Loi trong qua trinh xac nhan don thuoc :{0}", exception);
                return ActionResult.Error;

            }
        }
Ejemplo n.º 13
0
 private TThuockhoCollection GetObjThuocKhoCollection(KcbDonthuocChitiet objDetail)
 {
     SqlQuery sqlQuery;
     sqlQuery = new Select().From(TThuockho.Schema)
         .Where(TThuockho.Columns.IdKho).IsEqualTo(objDetail.IdKho)
         .And(TThuockho.Columns.NgayHethan).IsGreaterThanOrEqualTo( globalVariables.SysDate.Date)
         .And(TThuockho.Columns.IdThuoc).IsEqualTo(objDetail.IdThuoc)
         .And(TThuockho.Columns.SoLuong).IsGreaterThan(0)
         .OrderAsc(TThuockho.Columns.NgayHethan)
         .OrderAsc(TThuockho.Columns.GiaNhap);
     return sqlQuery.ExecuteAsCollection<TThuockhoCollection>();
 }
Ejemplo n.º 14
0
        /// <summary>
        /// HÀM THỰC HIỆN VIECJ CHO PHÉP CẬP NHẬP ĐƠN THUỐC
        /// </summary>
        /// <returns></returns>
        public ActionResult Linhthuocnoitru(KcbDonthuoc objDonthuoc, TPhieuXuatthuocBenhnhan objXuatBnhan, int ID_KHO_XUAT, DateTime ngaythuchien)
        {
            try
            {
                using (var scope = new TransactionScope())
                {
                    string THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC = THU_VIEN_CHUNG.Laygiatrithamsohethong("THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC", "0", false);
                    HisDuocProperties hisDuocProperties = new HisDuocProperties();
                    objXuatBnhan.IdBenhnhan = objDonthuoc.IdBenhnhan;
                    objXuatBnhan.MaLuotkham = objDonthuoc.MaLuotkham;
                    objXuatBnhan.MaPhieu = THU_VIEN_CHUNG.MaPhieuXuatBN();
                    objXuatBnhan.Noitru = Utility.ByteDbnull(objDonthuoc.Noitru);
                    objXuatBnhan.TenKhongdau = Utility.UnSignedCharacter(objXuatBnhan.TenBenhnhan);
                    objXuatBnhan.IdDonthuoc = Utility.Int32Dbnull(objDonthuoc.IdDonthuoc);
                    objXuatBnhan.IsNew = true;
                    objXuatBnhan.Save();
                    Int32 PtramBHYT = 0;
                    SqlQuery sqlQuery = new Select().From(KcbLuotkham.Schema).Where(
                        KcbLuotkham.Columns.MaLuotkham).IsEqualTo(objDonthuoc.MaLuotkham)
                        .And(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(objDonthuoc.IdBenhnhan);
                    KcbLuotkham objLuotkham = sqlQuery.ExecuteSingle<KcbLuotkham>();
                    if (objLuotkham != null)
                    {
                        PtramBHYT = Utility.Int32Dbnull(objLuotkham.PtramBhyt);
                    }
                    sqlQuery = new Select().From(TPhieuCapphatChitiet.Schema)
                        .Where(TPhieuCapphatChitiet.Columns.IdCapphat).IsEqualTo(objXuatBnhan.IdCapphat)
                        .And(TPhieuCapphatChitiet.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc);

                    TPhieuCapphatChitietCollection objDPhieuCapphatCtCollection =
                        sqlQuery.ExecuteAsCollection<TPhieuCapphatChitietCollection>();
                    foreach (TPhieuCapphatChitiet objCapphatDetail in objDPhieuCapphatCtCollection)
                    {
                        KcbDonthuocChitiet objDetail = new Select().From(KcbDonthuocChitiet.Schema)
                            .Where(KcbDonthuocChitiet.Columns.IdChitietdonthuoc).IsEqualTo(objCapphatDetail.IdChitietdonthuoc)
                            .ExecuteSingle<KcbDonthuocChitiet>();
                        if (objDetail == null) return ActionResult.Exceed;
                        objDetail.SetColumnValue("id_kho", ID_KHO_XUAT);
                        ActionResult actionResult = TruThuocTrongKho_Noitru(objDonthuoc,objCapphatDetail, objDetail, objXuatBnhan, ID_KHO_XUAT, ngaythuchien);
                        switch (actionResult)
                        {
                            case ActionResult.NotEnoughDrugInStock:
                                return actionResult;
                        }

                        TXuatthuocTheodon objThuocCt = new TXuatthuocTheodon();
                        objThuocCt.IdPhieuXuat = Utility.Int32Dbnull(objXuatBnhan.IdPhieu);
                        objThuocCt.IdThuoc = Utility.Int32Dbnull(objCapphatDetail.IdThuoc);
                        objThuocCt.NgayTao = globalVariables.SysDate;
                        objThuocCt.SoLuong = objCapphatDetail.SoLuong;
                        objThuocCt.NguoiTao = globalVariables.UserName;
                        objThuocCt.PhuThu = Utility.DecimaltoDbnull(objDetail.PhuThu);
                        objThuocCt.DonGia = Utility.DecimaltoDbnull(objDetail.DonGia);
                        objThuocCt.BnhanChitra = Utility.DecimaltoDbnull(objDetail.BnhanChitra);
                        objThuocCt.BhytChitra = Utility.DecimaltoDbnull(objDetail.BhytChitra);
                        objThuocCt.ChiDan = Utility.sDbnull(objDetail.MotaThem);
                        objThuocCt.ChidanThem = Utility.sDbnull(objDetail.ChidanThem);
                        objThuocCt.SolanDung = Utility.sDbnull(objDetail.SolanDung);
                        objThuocCt.SoluongDung = Utility.sDbnull(objDetail.SoluongDung);
                        objThuocCt.CachDung = Utility.sDbnull(objDetail.CachDung);
                        objThuocCt.PtramBhyt = PtramBHYT;
                        objThuocCt.IdChitietdonthuoc = Utility.Int32Dbnull(objCapphatDetail.IdChitietdonthuoc);
                        objThuocCt.IdDonthuoc = Utility.Int32Dbnull(objCapphatDetail.IdThuoc);
                        objThuocCt.IsNew = true;
                        objThuocCt.Save();
                        if (THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC == "1")
                        {
                            objCapphatDetail.ThucLinh = objCapphatDetail.SoLuong;
                            objCapphatDetail.IsNew = false;
                            objCapphatDetail.MarkOld();
                            objCapphatDetail.Save();
                        }
                    }
                    byte DA_LINH = (byte)(THUOC_NOITRU_XACNHANDALINH_KHIXACNHANDONTHUOC == "1" ? 1 : 0);

                    new Update(TPhieuCapphatChitiet.Schema)
                        .Set(TPhieuCapphatChitiet.Columns.DaLinh).EqualTo(DA_LINH)

                        .Set(TPhieuCapphatChitiet.Columns.IdPhieuxuatthuocBenhnhan).EqualTo(objXuatBnhan.IdPhieu)
                        .Where(TPhieuCapphatChitiet.Columns.IdCapphat).IsEqualTo(objXuatBnhan.IdCapphat).Execute();
                    sqlQuery = new Select().From(KcbDonthuocChitiet.Schema)
                                .Where(KcbDonthuocChitiet.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc)
                                .And(KcbDonthuocChitiet.Columns.TrangThai).IsEqualTo(0);
                    int status = sqlQuery.GetRecordCount() <= 0 ? 1 : 0;
                    new Update(KcbDonthuoc.Schema)
                              .Set(KcbDonthuoc.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                              .Set(KcbDonthuoc.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                              .Set(KcbDonthuoc.Columns.TrangThai).EqualTo(status)
                              .Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(objDonthuoc.IdDonthuoc).Execute();
                    scope.Complete();
                }

                return ActionResult.Success;
            }
            catch (Exception exception)
            {
                log.Error("loi trong qua trinh cap don thuoc {0}", exception);
                return ActionResult.Error;

            }
        }
Ejemplo n.º 15
0
 public ActionResult HuyThongTinLanThanhToan_Donthuoctaiquay(int id_thanhtoan, KcbLuotkham objLuotkham, string lydohuy, int IdHdonLog, bool HuyBienlai)
 {
     try
     {
         decimal v_TotalPaymentDetail = 0;
         decimal v_DiscountRate = 0;
         using (var scope = new TransactionScope())
         {
             using (var dbscope = new SharedDbConnectionScope())
             {
                 if (IdHdonLog > 0)
                     if (HuyBienlai)
                         new Update(HoadonLog.Schema).Set(HoadonLog.Columns.TrangThai).EqualTo(1)
                             .Where(HoadonLog.Columns.IdHdonLog).IsEqualTo(IdHdonLog).Execute();
                     else
                         new Delete().From(HoadonLog.Schema)
                             .Where(HoadonLog.Columns.IdHdonLog).IsEqualTo(IdHdonLog).Execute();
                 SqlQuery sqlQuery =
                     new Select().From(KcbThanhtoanChitiet.Schema).Where(KcbThanhtoanChitiet.Columns.IdThanhtoan).IsEqualTo(
                         id_thanhtoan);
                 KcbThanhtoanChitietCollection arrPaymentDetails = sqlQuery.ExecuteAsCollection<KcbThanhtoanChitietCollection>();
                 KcbThanhtoan objThanhtoan = KcbThanhtoan.FetchByID(id_thanhtoan);
                 int id_donthuoc = -1;
                 if (arrPaymentDetails.Count > 0) id_donthuoc = arrPaymentDetails[0].IdPhieu;
                 if (objThanhtoan != null)
                     HUYTHONGTIN_THANHTOAN(arrPaymentDetails, objThanhtoan);
                 KcbDonthuoc objDonthuoc = KcbDonthuoc.FetchByID(id_donthuoc);
                 KcbDonthuocChitietCollection lstChitiet = new Select().From(KcbDonthuoc.Schema).Where(KcbDonthuoc.Columns.IdDonthuoc).IsEqualTo(id_donthuoc).ExecuteAsCollection<KcbDonthuocChitietCollection>();
                 ActionResult actionResult = ActionResult.Success;
                 if (objDonthuoc != null && lstChitiet.Count > 0)
                 {
                    actionResult= new XuatThuoc().HuyXacNhanDonThuocBN(id_donthuoc, Utility.Int16Dbnull(lstChitiet[0].IdKho, 0),DateTime.Now,lydohuy);
                     switch (actionResult)
                     {
                         case ActionResult.Success:
                             break;
                         case ActionResult.Error:
                             return actionResult;
                     }
                 }
                 KcbThanhtoan.Delete(id_thanhtoan);
             }
             scope.Complete();
             return ActionResult.Success;
         }
     }
     catch (Exception exception)
     {
         log.Error("Loi trong qua trinh huy thong tin {0}", exception.ToString());
         return ActionResult.Error;
     }
 }
Ejemplo n.º 16
0
        private void IN_PHIEU_KHAM_VAO_VIEN()
        {
            DataTable dsTable =
               new noitru_nhapvien().NoitruLaythongtinInphieunhapvien(objLuotkham.MaLuotkham, Utility.Int32Dbnull(objLuotkham.IdBenhnhan));
            if (dsTable.Rows.Count <= 0)
            {
                Utility.ShowMsg("Không tìm thấy bản ghi nào\n Mời bạn xem lại", "Thông báo",MessageBoxIcon.Error);
                return;
            }

            SqlQuery sqlQuery = new Select().From(KcbChandoanKetluan.Schema)
                .Where(KcbChandoanKetluan.Columns.MaLuotkham).IsEqualTo(objLuotkham.MaLuotkham)
                .And(KcbChandoanKetluan.Columns.IdBenhnhan).IsEqualTo(objLuotkham.IdBenhnhan).OrderAsc(
                    KcbChandoanKetluan.Columns.NgayChandoan);
            var objInfoCollection = sqlQuery.ExecuteAsCollection<KcbChandoanKetluanCollection>();
            string chandoan = "";
            string mabenh = "";
            string phongkhamvaovien = "";
            string khoanoitru = "";
            foreach (KcbChandoanKetluan objDiagInfo in objInfoCollection)
            {
                string ICD_Name = "";
                string ICD_Code = "";
                GetChanDoan(Utility.sDbnull(objDiagInfo.MabenhChinh, ""),
                            Utility.sDbnull(objDiagInfo.MabenhPhu, ""), ref ICD_Name, ref ICD_Code);
                chandoan += string.IsNullOrEmpty(objDiagInfo.Chandoan)
                                ? ICD_Name
                                : Utility.sDbnull(objDiagInfo.Chandoan);
                mabenh += ICD_Code;
            }

            //txtkbMa.Text = Utility.sDbnull(mabenh);

            DataSet ds = new noitru_nhapvien().KcbLaythongtinthuocKetquaCls(objLuotkham.MaLuotkham, Utility.Int32Dbnull(objLuotkham.IdBenhnhan));
            DataTable dtThuoc = ds.Tables[0];
            DataTable dtketqua = ds.Tables[1];

            string[] query = (from thuoc in dtThuoc.AsEnumerable()
                              let y = Utility.sDbnull(thuoc["ten_thuoc"])
                              select y).ToArray();
            string donthuoc = string.Join(";", query);
            string[] querykq = (from kq in dtketqua.AsEnumerable()
                                let y = Utility.sDbnull(kq["ketqua"])
                                select y).ToArray();
            string ketquaCLS = string.Join("; ", querykq);

            //foreach (DataRow dr in dsTable.Rows)
            //{
            DataRow dr = dsTable.Rows[0];
            if (dr != null)
            {
                dr["thuockedon"] = donthuoc;
                dr["CHANDOAN_VAOVIEN"] = chandoan;
                dr["KETQUA_CLS"] = ketquaCLS;
            }

            dsTable.AcceptChanges();
            VNS.HIS.UI.Baocao.noitru_baocao.Inphieunhapvien(dsTable, "PHIẾU NHẬP VIỆN", globalVariables.SysDate);
        }
        /// <summary>
        ///     hàm thực hiện việc hiển thị thông tin
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdDungChuyenCLS_Click(object sender, EventArgs e)
        {
            bool hasFound = false;
            try
            {
                Utility.EnableButton(cmdDungChuyenCLS, false);
                Utility.WaitNow(this);
                SqlQuery sqlQuery = new Select().From(KcbChidinhclsChitiet.Schema)
                    .Where(KcbChidinhclsChitiet.Columns.IdChidinh).In(
                        new Select(KcbChidinhcl.Columns.IdChidinh).From(KcbChidinhcl.Schema).Where(
                            KcbChidinhcl.Columns.MaLuotkham)
                            .IsEqualTo(txtPatient_Code.Text)
                            .And(KcbChidinhcl.Columns.IdBenhnhan)
                            .IsEqualTo(Utility.Int32Dbnull(txtPatient_ID.Text)))
                    .And(KcbChidinhclsChitiet.Columns.TrangThai).IsEqualTo(1);
                hasFound = sqlQuery.GetRecordCount() > 0;
                if (sqlQuery.GetRecordCount() <= 0)
                {
                    Utility.SetMsg(lblMsg, string.Format("Không có chỉ định CLS có thể hủy chuyển"), false);
                    return;
                }
                var assignDetailCollection = sqlQuery.ExecuteAsCollection<KcbChidinhclsChitietCollection>();
                foreach (KcbChidinhclsChitiet assignDetail in assignDetailCollection)
                {
                    assignDetail.TrangThai = (byte?)TrangThaiCLS.KhongChuyenCLS;
                    assignDetail.NguoiSua = globalVariables.UserName;
                    assignDetail.NgaySua = globalVariables.SysDate;
                    new Update(KcbChidinhclsChitiet.Schema)
                        .Set(KcbChidinhclsChitiet.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                        .Set(KcbChidinhclsChitiet.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                        .Set(KcbChidinhclsChitiet.Columns.TrangThai).EqualTo(assignDetail.TrangThai)
                        .Where(KcbChidinhclsChitiet.Columns.IdChitietchidinh).IsEqualTo(assignDetail.IdChitietchidinh).Execute();
                }
                Utility.SetMsg(lblMsg, string.Format("Bạn vừa hủy chuyển CLS {0} chỉ định", sqlQuery.GetRecordCount().ToString()), false);

            }
            catch (Exception exception)
            {
            }
            finally
            {
                TuybiennutchuyenCLS();
                Utility.DefaultNow(this);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// hàm thực hiện việc update thông tin xác nhận gói
        /// </summary>
        /// <param name="objThongtinGoiDvuBnhan"></param>
        /// <returns></returns>
        public ActionResult UpdateExamInfo(KcbChandoanKetluan objDiagInfo, KcbDangkyKcb objRegExam,
                                           KcbLuotkham objPatientExam)
        {
            try
            {
                using (var scope = new TransactionScope())
                {
                    using (var sh = new SharedDbConnectionScope())
                    {

                        if (objDiagInfo.IsNew)
                        {
                            objDiagInfo.Save();
                        }
                        else
                        {
                            objDiagInfo.MarkOld();
                            objDiagInfo.Save();
                        }

                        SqlQuery sqlQuery = new Select().From(
                                                     KcbChandoanKetluan.Schema)
                               .Where(KcbChandoanKetluan.Columns.MaLuotkham).IsEqualTo(objPatientExam.MaLuotkham)
                               .And(KcbChandoanKetluan.Columns.IdBenhnhan).IsEqualTo(objPatientExam.IdBenhnhan).OrderAsc(
                                   KcbChandoanKetluan.Columns.NgayChandoan);
                        KcbChandoanKetluanCollection objInfoCollection = sqlQuery.ExecuteAsCollection<KcbChandoanKetluanCollection>();
                        var query = (from chandoan in objInfoCollection.AsEnumerable()
                                     let y = Utility.sDbnull(chandoan.Chandoan)
                                     where (y != "")
                                     select y).ToArray();
                        string cdchinh = string.Join(";", query);
                        //KcbChandoanKetluanCollection objInfoCollection = sqlQuery.ExecuteAsCollection<KcbChandoanKetluanCollection>();
                        var querychandoanphu = (from chandoan in objInfoCollection.AsEnumerable()
                                                let y = Utility.sDbnull(chandoan.ChandoanKemtheo)
                                                where (y != "")
                                                select y).ToArray();
                        string cdphu = string.Join(";", querychandoanphu);
                        var querybenhchinh = (from benhchinh in objInfoCollection.AsEnumerable()
                                              let y = Utility.sDbnull(benhchinh.MabenhChinh)
                                              where (y != "")
                                              select y).ToArray();
                        string mabenhchinh = string.Join(";", querybenhchinh);

                        var querybenhphu = (from benhphu in objInfoCollection.AsEnumerable()
                                            let y = Utility.sDbnull(benhphu.MabenhPhu)
                                            where (y != "")
                                            select y).ToArray();
                        string mabenhphu = string.Join(";", querybenhphu);
                        new Update(KcbLuotkham.Schema)
                            .Set(KcbLuotkham.Columns.MabenhChinh).EqualTo(mabenhchinh)
                            .Set(KcbLuotkham.Columns.MabenhPhu).EqualTo(mabenhphu)
                            .Set(KcbLuotkham.Columns.ChanDoan).EqualTo(cdchinh)
                            .Set(KcbLuotkham.Columns.ChandoanKemtheo).EqualTo(cdphu)
                            .Set(KcbLuotkham.Columns.TrieuChung).EqualTo(objPatientExam.TrieuChung)
                            .Set(KcbLuotkham.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                            .Set(KcbLuotkham.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                            .Set(KcbLuotkham.Columns.Locked).EqualTo(objPatientExam.Locked)
                            .Set(KcbLuotkham.Columns.NguoiKetthuc).EqualTo(objPatientExam.NguoiKetthuc)
                            .Set(KcbLuotkham.Columns.NgayKetthuc).EqualTo(objPatientExam.NgayKetthuc)
                            .Where(KcbLuotkham.Columns.MaLuotkham).IsEqualTo(objPatientExam.MaLuotkham)
                            .And(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(objPatientExam.IdBenhnhan).Execute();
                        //Tạm bỏ tránh việc bị cập nhật sai bác sĩ chỉ định nếu bác sĩ đó chỉ lưu thông tin kết luận
                        //SPs.KcbThamkhamCappnhatBsyKham(Utility.Int32Dbnull(objRegExam.IdKham, -1), objPatientExam.MaLuotkham,
                        //                            Utility.Int32Dbnull(objPatientExam.IdBenhnhan, -1),
                        //                            Utility.Int32Dbnull(objDiagInfo.DoctorId, -1)).Execute();

                        if (objRegExam != null)
                        {
                            new Update(KcbDangkyKcb.Schema)
                                .Set(KcbDangkyKcb.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                                .Set(KcbDangkyKcb.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                                .Set(KcbDangkyKcb.Columns.IpMaysua).EqualTo(globalVariables.gv_strIPAddress)
                                .Set(KcbDangkyKcb.Columns.TenMaysua).EqualTo(globalVariables.gv_strComputerName)
                                .Set(KcbDangkyKcb.Columns.IdBacsikham).EqualTo(objDiagInfo.IdBacsikham)
                                .Set(KcbDangkyKcb.Columns.TrangThai).EqualTo(objRegExam.TrangThai)
                                .Where(KcbDangkyKcb.Columns.IdKham).IsEqualTo(Utility.Int32Dbnull(objRegExam.IdKham, -1)).
                                Execute();
                        }

                    }

                    scope.Complete();
                    //  Reg_ID = Utility.Int32Dbnull(objRegExam.IdKham, -1);
                    return ActionResult.Success;
                }
            }
            catch (Exception exception)
            {
                log.Error("Loi trong qua trinh chuyen vien khoi noi tru {0}", exception);
                return ActionResult.Error;
            }
        }
Ejemplo n.º 19
0
        public ActionResult CapnhatChandoan(KcbChandoanKetluan objKcbChandoanKetluan)
        {
            try
             {
                 if (objKcbChandoanKetluan == null) return ActionResult.Cancel;
                 using (TransactionScope scope = new TransactionScope())
                 {
                     using (SharedDbConnectionScope sh = new SharedDbConnectionScope())
                     {
                         if (objKcbChandoanKetluan.IsNew )
                         {
                             objKcbChandoanKetluan.Save();
                         }
                         else
                         {
                             objKcbChandoanKetluan.MarkOld();
                             objKcbChandoanKetluan.Save();
                         }

                         SqlQuery sqlQuery = new Select().From( KcbChandoanKetluan.Schema)
                                .Where(KcbChandoanKetluan.Columns.MaLuotkham).IsEqualTo(objKcbChandoanKetluan.MaLuotkham)
                                .And(KcbChandoanKetluan.Columns.IdBenhnhan).IsEqualTo(objKcbChandoanKetluan.IdBenhnhan).OrderAsc(
                                    KcbChandoanKetluan.Columns.NgayChandoan);
                         KcbChandoanKetluanCollection objInfoCollection = sqlQuery.ExecuteAsCollection<KcbChandoanKetluanCollection>();
                         var query = (from chandoan in objInfoCollection.AsEnumerable()
                                      let y = Utility.sDbnull(chandoan.Chandoan)
                                      where (y != "")
                                      select y).ToArray();
                         string cdchinh = string.Join(";", query);
                         var querychandoanphu = (from chandoan in objInfoCollection.AsEnumerable()
                                                 let y = Utility.sDbnull(chandoan.ChandoanKemtheo)
                                                 where (y != "")
                                                 select y).ToArray();
                         string cdphu = string.Join(";", querychandoanphu);
                         var querybenhchinh = (from benhchinh in objInfoCollection.AsEnumerable()
                                               let y = Utility.sDbnull(benhchinh.MabenhChinh)
                                               where (y != "")
                                               select y).ToArray();
                         string mabenhchinh = string.Join(";", querybenhchinh);

                         var querybenhphu = (from benhphu in objInfoCollection.AsEnumerable()
                                             let y = Utility.sDbnull(benhphu.MabenhPhu)
                                             where (y != "")
                                             select y).ToArray();
                         string mabenhphu = string.Join(";", querybenhphu);
                         new Update(KcbLuotkham.Schema)
                             .Set(KcbLuotkham.Columns.MabenhChinh).EqualTo(mabenhchinh)
                             .Set(KcbLuotkham.Columns.MabenhPhu).EqualTo(mabenhphu)
                             .Set(KcbLuotkham.Columns.ChanDoan).EqualTo(cdchinh)
                             .Set(KcbLuotkham.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                             .Set(KcbLuotkham.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                             .Where(KcbLuotkham.Columns.MaLuotkham).IsEqualTo(objKcbChandoanKetluan.MaLuotkham)
                             .And(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(objKcbChandoanKetluan.IdBenhnhan).Execute();

                     }

                     scope.Complete();
                     //  Reg_ID = Utility.Int32Dbnull(objRegExam.IdKham, -1);
                     return ActionResult.Success;
                 }
             }
             catch (Exception exception)
             {
                 log.Error("Loi trong qua trinh chuyen vien khoi noi tru {0}", exception);
                 return ActionResult.Error;
             }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Lấy toàn bộ dữ liệu CLS giống phần chỉ định CLS sau đó tính giá dựa trên dữ liệu lấy được đó. Thay vì select lại từ các bảng quan hệ
        /// </summary>
        /// <param name="objLuotkham"></param>
        /// <returns></returns>
        private static ActionResult CapnhatChiphiCLS(KcbLuotkham objLuotkham)
        {
            using (var Scope = new TransactionScope())
            {
                DataTable m_dtServiceDetail = new KCB_CHIDINH_CANLAMSANG().LaydanhsachCLS_chidinh(objLuotkham.MaDoituongKcb, objLuotkham.TrangthaiNoitru, Utility.ByteDbnull(objLuotkham.GiayBhyt, 0), -1, Utility.Int32Dbnull(objLuotkham.DungTuyen.Value, 0), objLuotkham.MaKhoaThuchien, "-GOI,-TIEN");//Ko lấy dữ liệu liên quan đến gói dịch vụ+tiền phí phụ thêm
                SqlQuery sqlQuery = new Select().From(KcbChidinhclsChitiet.Schema)
                    .Where(KcbChidinhclsChitiet.Columns.IdChidinh).In(
                        new Select(KcbChidinhcl.Columns.IdChidinh).From(KcbChidinhcl.Schema)
                        .Where(KcbChidinhcl.Columns.MaLuotkham).IsEqualTo(objLuotkham.MaLuotkham)
                        .And(KcbChidinhcl.Columns.IdBenhnhan).IsEqualTo(objLuotkham.IdBenhnhan)
                        );
                var objAssignDetailCollection =
                    sqlQuery.ExecuteAsCollection<KcbChidinhclsChitietCollection>();
                foreach (KcbChidinhclsChitiet objAssignDetail in objAssignDetailCollection)
                {

                    if (objAssignDetail.TrangthaiThanhtoan == 0)//Chưa thanh toán
                    {
                         DataRow[] arrDr = m_dtServiceDetail.Select(KcbChidinhclsChitiet.Columns.IdChitietdichvu + "=" + Utility.Int32Dbnull(objAssignDetail.IdChitietdichvu, -1));
                         if (arrDr.Length > 0)
                         {
                             objAssignDetail.IdDoituongKcb = objLuotkham.IdDoituongKcb;
                             objAssignDetail.PtramBhyt = objLuotkham.PtramBhyt;
                             objAssignDetail.DonGia =Utility.DecimaltoDbnull(arrDr[0][KcbChidinhclsChitiet.Columns.DonGia], 0);
                             objAssignDetail.GiaDanhmuc = Utility.DecimaltoDbnull(arrDr[0][KcbChidinhclsChitiet.Columns.DonGia], 0);
                             objAssignDetail.TuTuc = Utility.ByteDbnull(arrDr[0][KcbChidinhclsChitiet.Columns.TuTuc],0);
                             objAssignDetail.PhuThu = Utility.DecimaltoDbnull(arrDr[0][KcbChidinhclsChitiet.Columns.PhuThu], 0);
                             objAssignDetail.NguoiSua = globalVariables.UserName;
                             objAssignDetail.NgaySua = DateTime.Now;
                             TinhCLS.GB_TinhPhtramBHYT(objAssignDetail, objLuotkham, Utility.DecimaltoDbnull(objLuotkham.PtramBhyt));

                         }
                         else//Rất khó nhảy vào nhánh này trừ phi lỗi dữ liệu đặc biệt nào đó
                         {
                             CLS_GIATHEO_KHOAKCB = THU_VIEN_CHUNG.Laygiatrithamsohethong("CLS_GIATHEO_KHOAKCB", "0", true) == "1";
                             QheDoituongDichvucl _Items = THU_VIEN_CHUNG.LayQheDoituongCLS(objLuotkham.MaDoituongKcb, objAssignDetail.IdChitietdichvu, objLuotkham.MaKhoaThuchien, CLS_GIATHEO_KHOAKCB);
                             if (_Items != null)
                             {

                                 objAssignDetail.DonGia = Utility.DecimaltoDbnull(_Items.DonGia);
                                 objAssignDetail.PhuThu = (Utility.isTrue(objLuotkham.DungTuyen) ? Utility.DecimaltoDbnull(_Items.PhuthuDungtuyen) : Utility.DecimaltoDbnull(_Items.PhuthuTraituyen));
                                 objAssignDetail.TuTuc = 0;
                                 objAssignDetail.IdDoituongKcb = objLuotkham.IdDoituongKcb;
                                 objAssignDetail.PtramBhyt = objLuotkham.PtramBhyt;
                             }
                             else
                             {
                                 _Items = THU_VIEN_CHUNG.LayQheDoituongCLS("DV", objAssignDetail.IdChitietdichvu, objLuotkham.MaKhoaThuchien, CLS_GIATHEO_KHOAKCB);
                                 if (_Items != null)
                                 {
                                     objAssignDetail.DonGia = Utility.DecimaltoDbnull(_Items.DonGia);
                                     objAssignDetail.PhuThu = (Utility.isTrue(objLuotkham.DungTuyen) ? Utility.DecimaltoDbnull(_Items.PhuthuDungtuyen) : Utility.DecimaltoDbnull(_Items.PhuthuTraituyen));
                                     objAssignDetail.TuTuc = 1;
                                     objAssignDetail.IdDoituongKcb = objLuotkham.IdDoituongKcb;
                                     objAssignDetail.PtramBhyt = 0;
                                 }
                             }
                             DmucDichvuclsChitiet _DmucDichvuclsChitiet = DmucDichvuclsChitiet.FetchByID(objAssignDetail.IdChitietdichvu);
                             if (_DmucDichvuclsChitiet != null && Utility.Int32Dbnull(_DmucDichvuclsChitiet.TuTuc, 0) == 1)
                                 objAssignDetail.TuTuc = 1;//Ke ca co trong bang quan he
                             if (objLuotkham.IdLoaidoituongKcb == 1)//Đối tượng dịch vụ-->ko cần phải đánh dấu tự túc
                                 objAssignDetail.TuTuc = 0;

                             objAssignDetail.NguoiSua = globalVariables.UserName;
                             objAssignDetail.NgaySua = DateTime.Now;
                             decimal PtramBHYT = Utility.DecimaltoDbnull(objLuotkham.PtramBhyt);
                             TinhCLS.GB_TinhPhtramBHYT(objAssignDetail, objLuotkham, PtramBHYT);
                         }

                    }
                    else//Đã thanh toán-->Ko đổi
                    {
                        return ActionResult.Cancel;
                    }
                }
                objAssignDetailCollection.SaveAll();
                Scope.Complete();
                return ActionResult.Success;
            }
        }
Ejemplo n.º 21
0
       public static DLoaiDvuCollection LayThongTinKieuDichVu()
       {
         

           SqlQuery sqlQuery = new Select().From(DLoaiDvu.Schema)
               .OrderAsc(DLoaiDvu.Columns.SttHthi);

          
           return sqlQuery.ExecuteAsCollection<DLoaiDvuCollection>();
       }
Ejemplo n.º 22
0
        private static ActionResult CapnhatChiphiCLS_old(KcbLuotkham objLuotkham)
        {
            using (var Scope = new TransactionScope())
            {
                CLS_GIATHEO_KHOAKCB = THU_VIEN_CHUNG.Laygiatrithamsohethong("CLS_GIATHEO_KHOAKCB","0", true) == "1";
                SqlQuery sqlQuery = new Select().From(KcbChidinhclsChitiet.Schema)
                    .Where(KcbChidinhclsChitiet.Columns.IdChidinh).In(
                        new Select(KcbChidinhcl.Columns.IdChidinh).From(KcbChidinhcl.Schema)
                        .Where(KcbChidinhcl.Columns.MaLuotkham).IsEqualTo(objLuotkham.MaLuotkham)
                        .And(KcbChidinhcl.Columns.IdBenhnhan).IsEqualTo(objLuotkham.IdBenhnhan)
                        );
                var objAssignDetailCollection =
                    sqlQuery.ExecuteAsCollection<KcbChidinhclsChitietCollection>();
                foreach (KcbChidinhclsChitiet objAssignDetail in objAssignDetailCollection)
                {
                    if (objAssignDetail.TrangthaiThanhtoan == 0)
                    {
                        QheDoituongDichvucl _Items = THU_VIEN_CHUNG.LayQheDoituongCLS(objLuotkham.MaDoituongKcb, objAssignDetail.IdChitietdichvu, objLuotkham.MaKhoaThuchien, CLS_GIATHEO_KHOAKCB);
                        if (_Items != null)
                        {

                            objAssignDetail.DonGia = Utility.DecimaltoDbnull(_Items.DonGia);
                            objAssignDetail.PhuThu = (Utility.isTrue(objLuotkham.DungTuyen) ? Utility.DecimaltoDbnull(_Items.PhuthuDungtuyen) : Utility.DecimaltoDbnull(_Items.PhuthuTraituyen));
                            objAssignDetail.TuTuc = 0;
                            objAssignDetail.IdDoituongKcb = objLuotkham.IdDoituongKcb;
                            objAssignDetail.PtramBhyt = objLuotkham.PtramBhyt;
                        }
                        else
                        {
                            _Items = THU_VIEN_CHUNG.LayQheDoituongCLS("DV", objAssignDetail.IdChitietdichvu, objLuotkham.MaKhoaThuchien, CLS_GIATHEO_KHOAKCB);
                            if (_Items != null)
                            {
                                objAssignDetail.DonGia = Utility.DecimaltoDbnull(_Items.DonGia);
                                objAssignDetail.PhuThu = (Utility.isTrue(objLuotkham.DungTuyen) ? Utility.DecimaltoDbnull(_Items.PhuthuDungtuyen) : Utility.DecimaltoDbnull(_Items.PhuthuTraituyen));
                                objAssignDetail.TuTuc = 1;
                                objAssignDetail.IdDoituongKcb = objLuotkham.IdDoituongKcb;
                                objAssignDetail.PtramBhyt = 0;
                            }
                        }
                        DmucDichvuclsChitiet _DmucDichvuclsChitiet = DmucDichvuclsChitiet.FetchByID(objAssignDetail.IdChitietdichvu);
                        if (_DmucDichvuclsChitiet != null && Utility.Int32Dbnull(_DmucDichvuclsChitiet.TuTuc, 0) == 1)
                            objAssignDetail.TuTuc = 1;//Ke ca co trong bang quan he
                        if (objLuotkham.IdLoaidoituongKcb == 1)//Đối tượng dịch vụ-->ko cần phải đánh dấu tự túc
                            objAssignDetail.TuTuc = 0;

                        objAssignDetail.NguoiSua = globalVariables.UserName;
                        objAssignDetail.NgaySua = DateTime.Now;
                        decimal PtramBHYT = Utility.DecimaltoDbnull(objLuotkham.PtramBhyt);
                        TinhCLS.GB_TinhPhtramBHYT(objAssignDetail, objLuotkham, PtramBHYT);
                    }
                    else
                    {
                        return ActionResult.Cancel;
                    }
                }
                objAssignDetailCollection.SaveAll();
                Scope.Complete();
                return ActionResult.Success;
            }
        }
Ejemplo n.º 23
0
        public ActionResult HuyXacNhanPhieuTrathuocThuatuKhoanoitruVeKhoLeNoitru(TPhieuNhapxuatthuoc objPhieuNhap, ref string errMsg)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();

                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            //Kiểm tra ở kho nhập xem thuốc đã sử dụng chưa
                            ActionResult _Kiemtrathuochuyxacnhan = Kiemtrathuochuyxacnhan(objPhieuNhap, objPhieuNhapCt, ref errMsg);
                            if (_Kiemtrathuochuyxacnhan != ActionResult.Success) return _Kiemtrathuochuyxacnhan;
                            //Xóa biến động kho nhập
                            new Delete().From(TBiendongThuoc.Schema)
                                .Where(TBiendongThuoc.IdPhieuColumn).IsEqualTo(objPhieuNhap.IdPhieu)
                                .And(TBiendongThuoc.IdPhieuChitietColumn).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet)
                                .And(TBiendongThuoc.MaLoaiphieuColumn).IsEqualTo((byte)LoaiPhieu.Phieutrathuocthua).Execute();
                            //Trừ từ kho xuất
                            StoredProcedure sp = SPs.ThuocXuatkho(objPhieuNhap.IdKhonhap, objPhieuNhapCt.IdThuoc,
                                                          objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                          Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                          objPhieuNhapCt.SoLuong, objPhieuNhapCt.IdThuockho, objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo, objHisDuocProperties.XoaDulieuKhiThuocDaHet ? 1 : 0, errorMessage);
                            sp.Execute();
                            //Cạp nhật lại id_thuockho =-1(giá trị này được update khi xác nhận phiếu). Giá trị id_chuyen cho biết chuyển từ id_thuockho của kho nội trú.
                            new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(-1)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                        }
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(0)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TPhieuNhapxuatthuoc.LoaiPhieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi hủy xác nhận phiếu trả thuốc thừa từ khoa nội trú về kho lẻ nội trú", ex);
                return ActionResult.Error;
            }
        }
Ejemplo n.º 24
0
        private static ActionResult CapnhatChiphiThuoc(KcbLuotkham objLuotkham)
        {
            using (var Scope = new TransactionScope())
            {
                decimal BHYT_PTRAM_TRAITUYENNOITRU =Utility.DecimaltoDbnull( THU_VIEN_CHUNG.Laygiatrithamsohethong("BHYT_PTRAM_TRAITUYENNOITRU", "0", false),0m);
                THUOC_GIATHEO_KHOAKCB = THU_VIEN_CHUNG.Laygiatrithamsohethong("THUOC_GIATHEO_KHOAKCB", "0", true) == "1";
                SqlQuery sqlQuery;
                sqlQuery = new Select().From(KcbDonthuocChitiet.Schema)
                    .Where(KcbDonthuocChitiet.Columns.IdDonthuoc).In(
                        new Select(KcbDonthuoc.Columns.IdDonthuoc).From(KcbDonthuoc.Schema).Where(
                            KcbDonthuoc.Columns.MaLuotkham).
                            IsEqualTo(objLuotkham.MaLuotkham).And(KcbDonthuoc.Columns.IdBenhnhan).
                            IsEqualTo(objLuotkham.IdBenhnhan));
                var objChitietDonthuocCollection =
                    sqlQuery.ExecuteAsCollection<KcbDonthuocChitietCollection>();

                bool ApdunggiathuocDoituong = THU_VIEN_CHUNG.Laygiatrithamsohethong("APDUNG_GIATHUOC_DOITUONG", "0", true) == "1";

                DmucDoituongkcb _DmucDoituongkcb = new Select().From(DmucDoituongkcb.Schema).Where(DmucDoituongkcb.Columns.MaDoituongKcb).IsEqualTo(objLuotkham.MaDoituongKcb).ExecuteSingle<DmucDoituongkcb>();
                if (_DmucDoituongkcb == null) return ActionResult.Success;
                decimal PtramBHYT = Utility.DecimaltoDbnull(objLuotkham.PtramBhyt);
                if (Utility.ByteDbnull(objLuotkham.TrangthaiNoitru, 0) > 0)
                    PtramBHYT = Utility.DecimaltoDbnull(objLuotkham.PtramBhytGoc);

                foreach (KcbDonthuocChitiet objChitietDonthuoc in objChitietDonthuocCollection)
                {
                    if (Utility.Int16Dbnull(objChitietDonthuoc.TrangthaiThanhtoan, 0) == 0)
                    {
                        DmucThuoc _DmucThuoc = DmucThuoc.FetchByID(objChitietDonthuoc.IdThuoc);
                        if (ApdunggiathuocDoituong || Utility.Byte2Bool( _DmucDoituongkcb.GiathuocQuanhe.Value))// globalVariables.gv_GiathuoctheoGiatrongKho)
                        {
                            //Giá theo quan he-->
                            QheDoituongThuoc _item = THU_VIEN_CHUNG.LayQheDoituongThuoc(objLuotkham.MaDoituongKcb,
                                                                      objChitietDonthuoc.IdThuoc,
                                                                      objLuotkham.MaKhoaThuchien, CLS_GIATHEO_KHOAKCB);
                            if (_item != null)
                            {
                                objChitietDonthuoc.DonGia = Utility.DecimaltoDbnull(_item.DonGia);
                                objChitietDonthuoc.PhuThu = (Utility.isTrue(objLuotkham.DungTuyen.Value) ? Utility.DecimaltoDbnull(_item.PhuthuDungtuyen) : Utility.DecimaltoDbnull(_item.PhuthuTraituyen));
                                objChitietDonthuoc.TuTuc = 0;
                                objChitietDonthuoc.PtramBhyt = Utility.DecimaltoDbnull(PtramBHYT);
                            }
                            else
                            {
                                _item = THU_VIEN_CHUNG.LayQheDoituongThuoc("DV",
                                                                       objChitietDonthuoc.IdThuoc,
                                                                       objLuotkham.MaKhoaThuchien, THUOC_GIATHEO_KHOAKCB);
                                if (_item != null)
                                {
                                    objChitietDonthuoc.DonGia = Utility.DecimaltoDbnull(_item.DonGia);
                                    objChitietDonthuoc.PhuThu = (Utility.isTrue(objLuotkham.DungTuyen.Value) ? Utility.DecimaltoDbnull(_item.PhuthuDungtuyen) : Utility.DecimaltoDbnull(_item.PhuthuTraituyen));
                                    objChitietDonthuoc.TuTuc = 1;
                                    objChitietDonthuoc.PtramBhyt = 0;
                                }
                            }

                        }
                        else //Giá theo kho-->
                        {

                            TThuockho objTK = TThuockho.FetchByID(objChitietDonthuoc.IdThuockho);
                            if (objTK != null)
                            {
                                objChitietDonthuoc.DonGia = objLuotkham.IdLoaidoituongKcb == 0 ? Utility.DecimaltoDbnull(objTK.GiaBhyt.Value, objChitietDonthuoc.DonGia) : objTK.GiaBan;
                            }
                            if (objLuotkham.IdLoaidoituongKcb == 1)//Đối tượng dịch vụ-->ko cần phải đánh dấu tự túc
                                objChitietDonthuoc.TuTuc = 0;
                            if (Utility.Int32Dbnull(objChitietDonthuoc.TuTuc, 0) == 1)
                            {
                                objChitietDonthuoc.BhytChitra = 0;
                                objChitietDonthuoc.BnhanChitra = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia, 0);
                                objChitietDonthuoc.PtramBhyt = 0;
                            }
                            else
                            {
                                objChitietDonthuoc.BhytChitra = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia) *
                                                            Utility.DecimaltoDbnull(PtramBHYT) / 100;

                                objChitietDonthuoc.BnhanChitra = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia, 0) -
                                                          Utility.DecimaltoDbnull(objChitietDonthuoc.BhytChitra, 0);
                                objChitietDonthuoc.PtramBhyt = Utility.DecimaltoDbnull(PtramBHYT);
                            }
                        }
                        //Tính lại các mục tự túc, BHYT chi trả, BN chi trả
                        if (_DmucThuoc!=null && Utility.Int32Dbnull(_DmucThuoc.TuTuc, 0) == 1)
                            objChitietDonthuoc.TuTuc = 1;//Ke ca co trong bang quan he

                        if (objLuotkham.IdLoaidoituongKcb == 1)//Đối tượng dịch vụ-->ko cần phải đánh dấu tự túc
                            objChitietDonthuoc.TuTuc = 0;
                        if (Utility.Int32Dbnull(objChitietDonthuoc.TuTuc, 0) == 0)
                        {
                            decimal BHCT = 0m;
                            if (objLuotkham.DungTuyen == 1)
                            {
                                BHCT = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia, 0) * (Utility.DecimaltoDbnull(objLuotkham.PtramBhyt, 0) / 100);
                            }
                            else
                            {
                                if (objLuotkham.TrangthaiNoitru <= 0)
                                    BHCT = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia, 0) * (Utility.DecimaltoDbnull(objLuotkham.PtramBhyt, 0) / 100);
                                else//Nội trú cần tính=đơn giá * % đầu thẻ * % tuyến
                                    BHCT = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia, 0) * (Utility.DecimaltoDbnull(objLuotkham.PtramBhytGoc, 0) / 100) * (BHYT_PTRAM_TRAITUYENNOITRU / 100);
                            }
                            // decimal num2 = (Utility.DecimaltoDbnull(row[KcbDonthuocChitiet.Columns.DonGia], 0) * Utility.DecimaltoDbnull(this.objLuotkham.PtramBhyt, 0)) / 100M;
                            decimal num3 = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia, 0) - BHCT;
                            objChitietDonthuoc.BhytChitra = BHCT;
                            objChitietDonthuoc.BnhanChitra = num3;
                        }
                        else
                        {
                            objChitietDonthuoc.PtramBhyt = 0;
                            objChitietDonthuoc.BhytChitra = 0;
                            objChitietDonthuoc.BnhanChitra = Utility.DecimaltoDbnull(objChitietDonthuoc.DonGia, 0);
                        }
                    }
                    else
                    {
                        return ActionResult.Cancel;
                    }
                }
                objChitietDonthuocCollection.SaveAll();
                Scope.Complete();
                return ActionResult.Success;
            }
        }
Ejemplo n.º 25
0
        public ActionResult XacNhanPhieuCapphatThuoc(TPhieuNhapxuatthuoc objPhieuNhap, DateTime ngayxacnhan, ref string errMsg)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();
                        objPhieuNhap.NgayXacnhan = ngayxacnhan;
                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            //Kiểm tra đề phòng Kho A-->Xuất kho B. Kho B xác nhận-->Xuất kho C. Kho B hủy xác nhận. Kho C xác nhận dẫn tới việc kho B chưa có thuốc để trừ kho

                            ActionResult _Kiemtrathuocxacnhan = Kiemtrathuocxacnhan(objPhieuNhap, objPhieuNhapCt, ref errMsg);
                            if (_Kiemtrathuocxacnhan != ActionResult.Success) return _Kiemtrathuocxacnhan;

                            long idthuockho = -1;

                            int SluongChia = Utility.Int32Dbnull(objPhieuNhapCt.SluongChia, 1);
                            if (SluongChia <= 0) SluongChia = 1;//Nếu lỗi do người dùng sửa tay thì tự động đặt=1
                            //Chú ý khi lập phiếu xuất thuốc tủ trực thì
                            //objPhieuNhapCt.SoLuong= số lượng đã chia-->Cần trừ số lượng trong kho xuất theo số lượng nguyên gốc. Tức là phải lấy số lượng này / số lượng chia
                            int _SoLuong = objPhieuNhapCt.SoLuong * SluongChia;//Số lượng thực sự bị mất khỏi kho xuất(khi xuất thuốc sang tủ trực)
                            StoredProcedure sp = SPs.ThuocNhapkhoOutput(objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                      _SoLuong, Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                                      objPhieuNhapCt.IdThuoc, objPhieuNhap.IdKhonhap,
                                                                      objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo, objPhieuNhapCt.SoDky, objPhieuNhapCt.SoQdinhthau, -1, idthuockho, ngayxacnhan, objPhieuNhapCt.GiaBhyt, objPhieuNhapCt.GiaPhuthuDungtuyen, objPhieuNhapCt.GiaPhuthuTraituyen, objPhieuNhapCt.KieuThuocvattu);
                            sp.Execute();
                            idthuockho = Utility.Int64Dbnull(sp.OutputValues[0], -1);

                            sp = SPs.ThuocXuatkho(objPhieuNhap.IdKhoxuat, objPhieuNhapCt.IdThuoc,
                                                          objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                          Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                          Utility.Int32Dbnull(objPhieuNhapCt.SoLuong), objPhieuNhapCt.IdChuyen,
                                                          objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo,
                                                          objHisDuocProperties.XoaDulieuKhiThuocDaHet ? 1 : 0, errorMessage);

                            sp.Execute();
                            errorMessage = Utility.sDbnull(sp.OutputValues[0], "");
                            if (Utility.DoTrim(errorMessage)!= "")
                            {
                                Utility.ShowMsg(errorMessage);
                                return ActionResult.Error;
                            }
                            if (idthuockho > 0)
                                new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(idthuockho)
                                   .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                            else
                                idthuockho =Utility.Int64Dbnull( objPhieuNhapCt.IdThuockho,-1);
                            objPhieuNhapCt.IdThuockho = idthuockho;
                            //Insert dòng kho nhập
                            TBiendongThuoc objXuatNhap = new TBiendongThuoc();
                            objXuatNhap.IdPhieu = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieu);
                            objXuatNhap.IdPhieuChitiet = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieuchitiet);
                            objXuatNhap.MaPhieu = Utility.sDbnull(objPhieuNhap.MaPhieu);
                            objXuatNhap.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.DonGia);
                            objXuatNhap.GiaBan = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan);

                            objXuatNhap.GiaPhuthuDungtuyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuDungtuyen);
                            objXuatNhap.GiaPhuthuTraituyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuTraituyen);
                            objXuatNhap.GiaBhyt = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt);

                            objXuatNhap.IdChuyen = objPhieuNhapCt.IdChuyen;
                            objXuatNhap.NgayNhap = objPhieuNhapCt.NgayNhap;
                            objXuatNhap.GiaNhap = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaNhap);
                            objXuatNhap.SoHoadon = Utility.sDbnull(objPhieuNhap.SoHoadon);
                            objXuatNhap.SoChungtuKemtheo = objPhieuNhap.SoChungtuKemtheo;
                            objXuatNhap.PhuThu = 0;
                            objXuatNhap.DuTru = objPhieuNhap.DuTru;
                            objXuatNhap.SoLuong = Utility.Int32Dbnull(objPhieuNhapCt.SoLuong);
                            objXuatNhap.SluongChia = Utility.Int32Dbnull(objPhieuNhapCt.SluongChia,1);
                            objXuatNhap.NgayTao = globalVariables.SysDate;
                            objXuatNhap.NguoiTao = globalVariables.UserName;
                            objXuatNhap.ThanhTien = Utility.DecimaltoDbnull(objPhieuNhapCt.ThanhTien);
                            objXuatNhap.IdThuoc = Utility.Int32Dbnull(objPhieuNhapCt.IdThuoc);
                            objXuatNhap.IdThuockho = Utility.Int32Dbnull(objPhieuNhapCt.IdThuockho);
                            objXuatNhap.Vat = Utility.Int32Dbnull(objPhieuNhap.Vat);
                            objXuatNhap.IdNhanvien = Utility.Int16Dbnull(objPhieuNhap.IdNhanvien);
                            objXuatNhap.IdKho = Utility.Int16Dbnull(objPhieuNhap.IdKhonhap);
                            objXuatNhap.NgayHethan = objPhieuNhapCt.NgayHethan.Date;
                            objXuatNhap.MaNhacungcap = objPhieuNhapCt.MaNhacungcap;
                            objXuatNhap.SoLo = objPhieuNhapCt.SoLo;
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.IdKhoaLinh = objPhieuNhap.IdKhoalinh;

                            objXuatNhap.MaLoaiphieu = (byte)LoaiPhieu.PhieuNhapKho;
                            objXuatNhap.TenLoaiphieu = Utility.TenLoaiPhieu(LoaiPhieu.PhieuNhapKho);
                            objXuatNhap.NgayBiendong = objPhieuNhap.NgayXacnhan;
                            objXuatNhap.NgayHoadon = objPhieuNhap.NgayHoadon;
                            objXuatNhap.KieuThuocvattu = objPhieuNhapCt.KieuThuocvattu;
                            objXuatNhap.IsNew = true;
                            objXuatNhap.Save();
                            //Insert dòng của kho xuất
                            objXuatNhap = new TBiendongThuoc();
                            objXuatNhap.IdPhieu = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieu);
                            objXuatNhap.IdPhieuChitiet = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieuchitiet);
                            objXuatNhap.MaPhieu = Utility.sDbnull(objPhieuNhap.MaPhieu);
                            objXuatNhap.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.DonGia);
                            objXuatNhap.NgayNhap = objPhieuNhapCt.NgayNhap;
                            objXuatNhap.GiaBan = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan);
                            objXuatNhap.GiaNhap = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaNhap);

                            objXuatNhap.GiaPhuthuDungtuyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuDungtuyen);
                            objXuatNhap.GiaPhuthuTraituyen = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaPhuthuTraituyen);
                            objXuatNhap.GiaBhyt = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBhyt);

                            objXuatNhap.SoHoadon = Utility.sDbnull(objPhieuNhap.SoHoadon);
                            objXuatNhap.PhuThu = 0;
                            objXuatNhap.IdChuyen = -1;
                            objXuatNhap.DuTru = objPhieuNhap.DuTru;
                            objXuatNhap.SoLuong = Utility.Int32Dbnull(objPhieuNhapCt.SoLuong);
                            objXuatNhap.SluongChia = Utility.Int32Dbnull(objPhieuNhapCt.SluongChia, 1);
                            objXuatNhap.NgayTao = globalVariables.SysDate;
                            objXuatNhap.NguoiTao = globalVariables.UserName;
                            objXuatNhap.IdThuockho = Utility.Int32Dbnull(objPhieuNhapCt.IdChuyen);
                            objXuatNhap.ThanhTien = Utility.DecimaltoDbnull(objPhieuNhapCt.ThanhTien);
                            objXuatNhap.IdThuoc = Utility.Int32Dbnull(objPhieuNhapCt.IdThuoc);
                            objXuatNhap.Vat = Utility.Int32Dbnull(objPhieuNhap.Vat);
                            objXuatNhap.IdNhanvien = Utility.Int16Dbnull(objPhieuNhap.IdNhanvien);
                            objXuatNhap.IdKho = Utility.Int16Dbnull(objPhieuNhap.IdKhoxuat);
                            objXuatNhap.NgayHethan = objPhieuNhapCt.NgayHethan.Date;
                            objXuatNhap.MaNhacungcap = objPhieuNhapCt.MaNhacungcap;
                            objXuatNhap.SoChungtuKemtheo = objPhieuNhap.SoChungtuKemtheo;
                            objXuatNhap.SoLo = objPhieuNhapCt.SoLo;
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.MaLoaiphieu = (byte)LoaiPhieu.PhieuXuatKhoa;
                            objXuatNhap.TenLoaiphieu = Utility.TenLoaiPhieu(LoaiPhieu.PhieuXuatKhoa);
                            objXuatNhap.NgayBiendong = objPhieuNhap.NgayXacnhan;
                            objXuatNhap.NgayHoadon = objPhieuNhap.NgayHoadon;
                            objXuatNhap.KieuThuocvattu = objPhieuNhapCt.KieuThuocvattu;
                            objXuatNhap.IdKhoaLinh = objPhieuNhap.IdKhoalinh;
                            objXuatNhap.IsNew = true;
                            objXuatNhap.Save();

                        }
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(globalVariables.gv_intIDNhanvien)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(globalVariables.UserName)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(ngayxacnhan)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(1)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TPhieuNhapxuatthuoc.LoaiPhieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi xác nhận phiếu cấp phát thuốc-khoa", ex);
                return ActionResult.Error;
            }
        }
Ejemplo n.º 26
0
 private void LoadMoiQuanHe()
 {
     SqlQuery sql =
         new Select().From(QheDoituongKho.Schema).Where(QheDoituongKho.Columns.IdKho).IsEqualTo(
             Utility.Int32Dbnull(txtIDKHO.Text));
     DataTable m_MQH = sql.ExecuteAsCollection<QheDoituongKhoCollection>().ToDataTable();
     foreach (DataRow dr in m_MQH.Rows)
     {
         foreach (GridEXRow grRow in grdDoiTuong.GetRows())
         {
             if (dr[QheDoituongKho.Columns.MaDoituongKcb].ToString() == grRow.Cells[QheDoituongKho.Columns.MaDoituongKcb].Value.ToString())
             {
                 grRow.BeginEdit();
                 grRow.IsChecked = true;
                 grRow.Cells[QheDoituongKho.Columns.SttHthi].Value = dr[QheDoituongKho.Columns.SttHthi].ToString();
                 grRow.EndEdit();
             }
         }
     }
 }
Ejemplo n.º 27
0
        public ActionResult XacnhanPhieuTrathuocNhacungcap(TPhieuNhapxuatthuoc objPhieuNhap)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();
                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            //Insert dòng hủy vào TBiendongThuoc
                            TBiendongThuoc objXuatNhap = new TBiendongThuoc();
                            objXuatNhap.IdPhieu = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieu);
                            objXuatNhap.IdPhieuChitiet = Utility.Int32Dbnull(objPhieuNhapCt.IdPhieuchitiet);
                            objXuatNhap.MaPhieu = Utility.sDbnull(objPhieuNhap.MaPhieu);
                            objXuatNhap.DonGia = Utility.DecimaltoDbnull(objPhieuNhapCt.DonGia);
                            objXuatNhap.NgayHoadon =objPhieuNhap.NgayHoadon;
                            objXuatNhap.GiaBan = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaBan);
                            objXuatNhap.GiaNhap = Utility.DecimaltoDbnull(objPhieuNhapCt.GiaNhap);
                            objXuatNhap.SoDky = objPhieuNhapCt.SoDky;
                            objXuatNhap.SoQdinhthau = objPhieuNhapCt.SoQdinhthau;
                            objXuatNhap.SoLo = objPhieuNhapCt.SoLo;
                            objXuatNhap.IdThuockho = Utility.Int32Dbnull(objPhieuNhapCt.IdThuockho);
                            objXuatNhap.KieuThuocvattu = Utility.sDbnull(objPhieuNhapCt.KieuThuocvattu);

                            objXuatNhap.SoChungtuKemtheo = "";
                            objXuatNhap.Noitru = 0;
                            objXuatNhap.QuayThuoc = 0;
                            objXuatNhap.GiaBhyt = 0;
                            objXuatNhap.GiaBhytCu = 0;
                            objXuatNhap.GiaPhuthuDungtuyen = 0;
                            objXuatNhap.GiaPhuthuTraituyen = 0;
                            objXuatNhap.DuTru = 0;

                            objXuatNhap.SoHoadon = Utility.sDbnull(objPhieuNhap.SoHoadon);
                            objXuatNhap.PhuThu = 0;
                            objXuatNhap.SoLuong = Utility.Int32Dbnull(objPhieuNhapCt.SoLuong);
                            objXuatNhap.NgayTao =  globalVariables.SysDate;
                            objXuatNhap.NguoiTao = globalVariables.UserName;
                            objXuatNhap.ThanhTien = Utility.DecimaltoDbnull(objPhieuNhapCt.ThanhTien);
                            objXuatNhap.IdThuoc = Utility.Int32Dbnull(objPhieuNhapCt.IdThuoc);
                            objXuatNhap.Vat = Utility.Int32Dbnull(objPhieuNhap.Vat);
                            objXuatNhap.IdNhanvien = Utility.Int16Dbnull(objPhieuNhap.IdNhanvien);
                            objXuatNhap.IdKho = Utility.Int16Dbnull(objPhieuNhap.IdKhoxuat);
                            objXuatNhap.NgayHethan = objPhieuNhapCt.NgayHethan.Date;
                            objXuatNhap.MaNhacungcap = objPhieuNhap.MaNhacungcap;
                            objXuatNhap.MaLoaiphieu = objPhieuNhap.LoaiPhieu;
                            objXuatNhap.TenLoaiphieu = objPhieuNhap.TenLoaiphieu;
                            objXuatNhap.NgayBiendong = objPhieuNhap.NgayHoadon;
                            objXuatNhap.IsNew = true;
                            objXuatNhap.Save();
                            StoredProcedure sp = SPs.ThuocXuatkho(objPhieuNhap.IdKhoxuat, objPhieuNhapCt.IdThuoc,
                                                          objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                          Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                          Utility.Int32Dbnull(objXuatNhap.SoLuong), objPhieuNhapCt.IdThuockho, objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo, objHisDuocProperties.XoaDulieuKhiThuocDaHet ? 1 : 0, errorMessage);

                            sp.Execute();
                        }
                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(globalVariables.gv_intIDNhanvien)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(globalVariables.UserName)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo( globalVariables.SysDate)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(1)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception exception)
            {
                log.Error("Loi ban ra tu sp :{0}", errorMessage);
                log.Error("Loi trong qua trinh xac nhan don thuoc :{0}", exception);
                return ActionResult.Error;
            }
        }
Ejemplo n.º 28
0
 public ActionResult HuyThongTinLanThanhToan_Ao(int id_thanhtoan, KcbLuotkham objLuotkham, string lydohuy, int IdHdonLog, bool HuyBienlai)
 {
     try
     {
         decimal v_TotalPaymentDetail = 0;
         decimal v_DiscountRate = 0;
         using (var scope = new TransactionScope())
         {
             using (var dbscope = new SharedDbConnectionScope())
             {
                 if (IdHdonLog > 0)
                     if (HuyBienlai)
                         new Update(HoadonLog.Schema).Set(HoadonLog.Columns.TrangThai).EqualTo(1)
                             .Where(HoadonLog.Columns.IdHdonLog).IsEqualTo(IdHdonLog).Execute();
                     else
                         new Delete().From(HoadonLog.Schema)
                             .Where(HoadonLog.Columns.IdHdonLog).IsEqualTo(IdHdonLog).Execute();
                 SqlQuery sqlQuery =
                     new Select().From(KcbThanhtoanChitiet.Schema).Where(KcbThanhtoanChitiet.Columns.IdThanhtoan).IsEqualTo(
                         id_thanhtoan);
                 KcbThanhtoanChitietCollection arrPaymentDetails = sqlQuery.ExecuteAsCollection<KcbThanhtoanChitietCollection>();
                 KcbThanhtoan objThanhtoan = KcbThanhtoan.FetchByID(id_thanhtoan);
                 if (objThanhtoan != null)
                     HUYTHONGTIN_THANHTOAN(arrPaymentDetails, objThanhtoan);
                 new Delete().From(KcbPhieuDct.Schema)
                     .Where(KcbPhieuDct.Columns.MaLuotkham).IsEqualTo(objThanhtoan.MaLuotkham)
                     .And(KcbPhieuDct.Columns.IdBenhnhan).IsEqualTo(objThanhtoan.IdBenhnhan)
                     .And(KcbPhieuDct.Columns.LoaiThanhtoan).IsEqualTo(objThanhtoan.KieuThanhtoan).Execute();
                 if (objLuotkham != null)
                 {
                     byte locked = (byte)(objLuotkham.MaDoituongKcb == "DV" ? objLuotkham.Locked : 0);
                     new Update(KcbLuotkham.Schema)
                         .Set(KcbLuotkham.Columns.NgayKetthuc).EqualTo(null)
                         .Set(KcbLuotkham.Columns.NguoiKetthuc).EqualTo(string.Empty)
                         .Set(KcbLuotkham.Columns.Locked).EqualTo(locked)
                         .Set(KcbLuotkham.Columns.TrangthaiNgoaitru).EqualTo(locked)
                         .Set(KcbLuotkham.Columns.BoVien).EqualTo(0)
                         .Set(KcbLuotkham.Columns.LydoKetthuc).EqualTo("")
                         .Where(KcbLuotkham.Columns.MaLuotkham).IsEqualTo(objLuotkham.MaLuotkham)
                         .And(KcbLuotkham.Columns.IdBenhnhan).IsEqualTo(objLuotkham.IdBenhnhan).Execute();
                 }
                 KcbThanhtoan.Delete(id_thanhtoan);
                 if (objLuotkham != null) log.Info(string.Format("Phiếu thanh toán ID: {0} của bệnh nhân: {1} - ID Bệnh nhân: {2} đã được hủy bởi :{3} với lý do hủy :{4}", id_thanhtoan.ToString(), objLuotkham.MaLuotkham, objLuotkham.IdBenhnhan, globalVariables.UserName, lydohuy));
             }
             scope.Complete();
             return ActionResult.Success;
         }
     }
     catch (Exception exception)
     {
         log.Error("Loi trong qua trinh huy thong tin {0}", exception.ToString());
         return ActionResult.Error;
     }
 }
Ejemplo n.º 29
0
        /// <summary>
        /// hàm thực hiện việc xác nhận thông tin 
        /// </summary>
        /// <param name="objPhieuNhap"></param>
        /// <returns></returns>
        public ActionResult HuyXacNhanPhieuXuatKho(TPhieuNhapxuatthuoc objPhieuNhap, ref string errMsg)
        {
            HisDuocProperties objHisDuocProperties = PropertyLib._HisDuocProperties;
            string errorMessage = "";
            try
            {
                using (var Scope = new TransactionScope())
                {
                    using (var dbScope = new SharedDbConnectionScope())
                    {
                        SqlQuery sqlQuery = new Select().From(TPhieuNhapxuatthuocChitiet.Schema)
                            .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu);
                        TPhieuNhapxuatthuocChitietCollection objPhieuNhapCtCollection =
                            sqlQuery.ExecuteAsCollection<TPhieuNhapxuatthuocChitietCollection>();

                        foreach (TPhieuNhapxuatthuocChitiet objPhieuNhapCt in objPhieuNhapCtCollection)
                        {
                            //Kiểm tra ở kho nhập xem thuốc đã sử dụng chưa
                            ActionResult _Kiemtrathuochuyxacnhan = Kiemtrathuochuyxacnhan(objPhieuNhap, objPhieuNhapCt, ref errMsg);
                            if (_Kiemtrathuochuyxacnhan != ActionResult.Success) return _Kiemtrathuochuyxacnhan;
                            //Xóa biến động kho nhập
                            new Delete().From(TBiendongThuoc.Schema)
                                .Where(TBiendongThuoc.IdPhieuColumn).IsEqualTo(objPhieuNhap.IdPhieu)
                                .And(TBiendongThuoc.IdPhieuChitietColumn).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet)
                                .And(TBiendongThuoc.MaLoaiphieuColumn).IsEqualTo((byte)LoaiPhieu.PhieuNhapKho).Execute();
                            //Xóa biến động kho xuất
                            new Delete().From(TBiendongThuoc.Schema)
                               .Where(TBiendongThuoc.IdPhieuColumn).IsEqualTo(objPhieuNhap.IdPhieu)
                               .And(TBiendongThuoc.IdPhieuChitietColumn).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet)
                               .And(TBiendongThuoc.MaLoaiphieuColumn).IsEqualTo((byte)LoaiPhieu.PhieuXuatKhoBenhNhan).Execute();
                            long id_Thuockho_new = -1;
                            new Update(TPhieuNhapxuatthuocChitiet.Schema).Set(TPhieuNhapxuatthuocChitiet.Columns.IdThuockho).EqualTo(-1)
                              .Where(TPhieuNhapxuatthuocChitiet.Columns.IdPhieuchitiet).IsEqualTo(objPhieuNhapCt.IdPhieuchitiet).Execute();
                            StoredProcedure sp = SPs.ThuocNhapkhoOutput(objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap, objPhieuNhapCt.GiaBan,
                                                                      objPhieuNhapCt.SoLuong, Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                                      objPhieuNhapCt.IdThuoc, objPhieuNhap.IdKhoxuat, objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo,
                                                                      objPhieuNhapCt.SoDky, objPhieuNhapCt.SoQdinhthau, objPhieuNhapCt.IdThuockho.Value, id_Thuockho_new, objPhieuNhapCt.NgayNhap,
                                                                      objPhieuNhapCt.GiaBhyt, objPhieuNhapCt.GiaPhuthuDungtuyen, objPhieuNhapCt.GiaPhuthuTraituyen, objPhieuNhapCt.KieuThuocvattu);
                            sp.Execute();
                            sp = SPs.ThuocXuatkho(objPhieuNhap.IdKhonhap, objPhieuNhapCt.IdThuoc,
                                                          objPhieuNhapCt.NgayHethan, objPhieuNhapCt.GiaNhap,objPhieuNhapCt.GiaBan,
                                                          Utility.DecimaltoDbnull(objPhieuNhapCt.Vat),
                                                          Utility.Int32Dbnull(objPhieuNhapCt.SoLuong), objPhieuNhapCt.IdThuockho, objPhieuNhapCt.MaNhacungcap, objPhieuNhapCt.SoLo, objHisDuocProperties.XoaDulieuKhiThuocDaHet ? 1 : 0, errorMessage);
                            sp.Execute();
                        }

                        new Update(TPhieuNhapxuatthuoc.Schema)
                            .Set(TPhieuNhapxuatthuoc.Columns.IdNhanvien).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NguoiXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.NgayXacnhan).EqualTo(null)
                            .Set(TPhieuNhapxuatthuoc.Columns.TrangThai).EqualTo(0)
                            .Where(TPhieuNhapxuatthuoc.Columns.IdPhieu).IsEqualTo(objPhieuNhap.IdPhieu)
                            .And(TPhieuNhapxuatthuoc.LoaiPhieuColumn).IsEqualTo(objPhieuNhap.LoaiPhieu).Execute();
                    }
                    Scope.Complete();
                    return ActionResult.Success;
                }
            }
            catch (Exception ex)
            {
                Utility.CatchException("Lỗi khi hủy xác nhận phiếu chuyển kho", ex);
                return ActionResult.Error;
            }
        }
 /// <summary>
 ///     hàm thực hiện việc chuyển cận lâm sàng
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmdChuyenCLS_Click(object sender, EventArgs e)
 {
     try
     {
         Utility.EnableButton(cmdChuyenCLS, false);
         Utility.WaitNow(this);
         if (objLuotkham != null)
         {
             SqlQuery sqlQuery = new Select().From(KcbChidinhclsChitiet.Schema)
                 .Where(KcbChidinhclsChitiet.Columns.IdChidinh).In(
                     new Select(KcbChidinhcl.Columns.IdChidinh).From(KcbChidinhcl.Schema)
                         .Where(KcbChidinhcl.Columns.MaLuotkham)
                         .IsEqualTo(
                             txtPatient_Code.Text).And(KcbChidinhcl.Columns.IdBenhnhan).IsEqualTo(
                                 Utility.Int32Dbnull(txtPatient_ID.Text)))
                 .AndExpression(KcbChidinhclsChitiet.Columns.TrangthaiChuyencls)
                 .IsEqualTo(0)
                 .Or(KcbChidinhclsChitiet.Columns.TrangthaiChuyencls)
                 .IsNull()
                 .CloseExpression()
                 ;
             if (sqlQuery.GetRecordCount() <= 0)
             {
                 Utility.ShowMsg("Không còn dữ liệu để chuyển, Dữ liệu đã chuyển sang cận lâm sàng", "Thông báo",
                     MessageBoxIcon.Error);
                 return;
             }
             var assignDetailCollection =
                 sqlQuery.ExecuteAsCollection<KcbChidinhclsChitietCollection>();
             foreach (KcbChidinhclsChitiet assignDetail in assignDetailCollection)
             {
                 assignDetail.TrangthaiChuyencls =  (byte?)TrangThaiCLS.ChuyenCLS;
                 assignDetail.NguoiSua = globalVariables.UserName;
                 assignDetail.NgaySua = globalVariables.SysDate;
                 //assignDetail.IpMacSua = globalVariables.IpMacAddress;
                 //assignDetail.IpMaySua = globalVariables.IpAddress;
                 new Update(KcbChidinhclsChitiet.Schema)
                     .Set(KcbChidinhclsChitiet.Columns.NgaySua).EqualTo(globalVariables.SysDate)
                     .Set(KcbChidinhclsChitiet.Columns.NguoiSua).EqualTo(globalVariables.UserName)
                     .Set(KcbChidinhclsChitiet.Columns.TrangthaiChuyencls).EqualTo(assignDetail.TrangthaiChuyencls)
                     .Where(KcbChidinhclsChitiet.Columns.IdChitietchidinh)
                     .IsEqualTo(assignDetail.IdChitietchidinh)
                     .Execute();
             }
             //assignDetailCollection.SaveAll();
             cmdChuyenCLS.Enabled = false;
             cmdDungChuyenCLS.Enabled = true;
         }
     }
     catch (Exception ex)
     {
     }
     finally
     {
         Utility.EnableButton(cmdChuyenCLS, true);
         Utility.DefaultNow(this);
     }
 }