Beispiel #1
0
        public static Result GetPhieuThuCapCuu(string phieuThuCapCuuGUID)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                PhieuThuCapCuu ptcc = db.PhieuThuCapCuus.SingleOrDefault <PhieuThuCapCuu>(p => p.PhieuThuCapCuuGUID.ToString() == phieuThuCapCuuGUID);
                result.QueryResult = ptcc;
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Beispiel #2
0
        public static Result CheckPhieuThuCapCuuExistCode(string phieuThuCapCuuGUID, string code)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                PhieuThuCapCuu ptcc = null;
                if (phieuThuCapCuuGUID == null || phieuThuCapCuuGUID == string.Empty)
                {
                    ptcc = db.PhieuThuCapCuus.SingleOrDefault <PhieuThuCapCuu>(p => p.MaPhieuThuCapCuu.ToLower() == code.ToLower());
                }
                else
                {
                    ptcc = db.PhieuThuCapCuus.SingleOrDefault <PhieuThuCapCuu>(p => p.MaPhieuThuCapCuu.ToLower() == code.ToLower() &&
                                                                               p.PhieuThuCapCuuGUID.ToString() != phieuThuCapCuuGUID);
                }

                if (ptcc == null)
                {
                    result.Error.Code = ErrorCode.NOT_EXIST;
                }
                else
                {
                    result.Error.Code = ErrorCode.EXIST;
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Beispiel #3
0
        public static Result InsertGhiNhanTraNo(GhiNhanTraNo ghiNhanTraNo, bool isDataTraDu, string phieuThuGUID, LoaiPT loaiPT)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (ghiNhanTraNo.GhiNhanTraNoGUID == null || ghiNhanTraNo.GhiNhanTraNoGUID == Guid.Empty)
                    {
                        ghiNhanTraNo.GhiNhanTraNoGUID = Guid.NewGuid();
                        db.GhiNhanTraNos.InsertOnSubmit(ghiNhanTraNo);
                        db.SubmitChanges();

                        //Tracking
                        desc += string.Format("- GUID: '{0}', Phiếu thu GUID: '{1}', Ngày trả: '{2}', Số tiền: '{3}', Ghi chú: '{4}'",
                                              ghiNhanTraNo.GhiNhanTraNoGUID.ToString(), ghiNhanTraNo.MaPhieuThuGUID.ToString(),
                                              ghiNhanTraNo.NgayTra.ToString("dd/MM/yyyy HH:mm:ss"), ghiNhanTraNo.SoTien, ghiNhanTraNo.GhiChu);

                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin ghi nhận trả nợ";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.None;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }
                    else //Update
                    {
                        GhiNhanTraNo tn = db.GhiNhanTraNos.SingleOrDefault <GhiNhanTraNo>(s => s.GhiNhanTraNoGUID.ToString() == ghiNhanTraNo.GhiNhanTraNoGUID.ToString());
                        if (tn != null)
                        {
                            tn.MaPhieuThuGUID = ghiNhanTraNo.MaPhieuThuGUID;
                            tn.NgayTra        = ghiNhanTraNo.NgayTra;
                            tn.SoTien         = ghiNhanTraNo.SoTien;
                            tn.GhiChu         = ghiNhanTraNo.GhiChu;
                            tn.LoaiPT         = ghiNhanTraNo.LoaiPT;
                            tn.CreatedDate    = ghiNhanTraNo.CreatedDate;
                            tn.CreatedBy      = ghiNhanTraNo.CreatedBy;
                            tn.UpdatedDate    = ghiNhanTraNo.UpdatedDate;
                            tn.UpdatedBy      = ghiNhanTraNo.UpdatedBy;
                            tn.DeletedDate    = ghiNhanTraNo.DeletedDate;
                            tn.DeletedBy      = ghiNhanTraNo.DeletedBy;
                            tn.Status         = ghiNhanTraNo.Status;

                            //Tracking
                            desc += string.Format("- GUID: '{0}', Phiếu thu GUID: '{1}', Ngày trả: '{2}', Số tiền: '{3}', Ghi chú: '{4}'",
                                                  tn.GhiNhanTraNoGUID.ToString(), tn.MaPhieuThuGUID.ToString(),
                                                  tn.NgayTra.ToString("dd/MM/yyyy HH:mm:ss"), tn.SoTien, tn.GhiChu);

                            Tracking tk = new Tracking();
                            tk.TrackingGUID = Guid.NewGuid();
                            tk.TrackingDate = DateTime.Now;
                            tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                            tk.ActionType   = (byte)ActionType.Edit;
                            tk.Action       = "Sửa thông tin ghi nhận trả nợ";
                            tk.Description  = desc;
                            tk.TrackingType = (byte)TrackingType.None;
                            tk.ComputerName = Utility.GetDNSHostName();
                            db.Trackings.InsertOnSubmit(tk);

                            db.SubmitChanges();
                        }
                    }

                    switch (loaiPT)
                    {
                    case LoaiPT.DichVu:
                        Receipt ptdv = db.Receipts.Where(p => p.ReceiptGUID.ToString() == phieuThuGUID).FirstOrDefault();
                        ptdv.ChuaThuTien = !isDataTraDu;
                        break;

                    case LoaiPT.Thuoc:
                        PhieuThuThuoc ptt = db.PhieuThuThuocs.Where(p => p.PhieuThuThuocGUID.ToString() == phieuThuGUID).FirstOrDefault();
                        ptt.ChuaThuTien = !isDataTraDu;
                        break;

                    case LoaiPT.HopDong:
                        PhieuThuHopDong pthd = db.PhieuThuHopDongs.Where(p => p.PhieuThuHopDongGUID.ToString() == phieuThuGUID).FirstOrDefault();
                        pthd.ChuaThuTien = !isDataTraDu;
                        break;

                    case LoaiPT.CapCuu:
                        PhieuThuCapCuu ptcc = db.PhieuThuCapCuus.Where(p => p.PhieuThuCapCuuGUID.ToString() == phieuThuGUID).FirstOrDefault();
                        ptcc.ChuaThuTien = !isDataTraDu;
                        break;
                    }

                    db.SubmitChanges();

                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Beispiel #4
0
        public static Result DeleteGhiNhanTraNo(List <string> keys, string phieuThuGUID, LoaiPT loaiPT)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    bool   isDelete = false;
                    string desc     = string.Empty;
                    foreach (string key in keys)
                    {
                        GhiNhanTraNo tn = db.GhiNhanTraNos.SingleOrDefault <GhiNhanTraNo>(ss => ss.GhiNhanTraNoGUID.ToString() == key);
                        if (tn != null)
                        {
                            tn.DeletedDate = DateTime.Now;
                            tn.DeletedBy   = Guid.Parse(Global.UserGUID);

                            if (tn.Status == (byte)Status.Actived)
                            {
                                isDelete = true;
                            }

                            tn.Status = (byte)Status.Deactived;

                            desc += string.Format("- GUID: '{0}', Phiếu thu GUID: '{1}', Ngày trả: '{2}', Số tiền: '{3}', Ghi chú: '{4}'\n",
                                                  tn.GhiNhanTraNoGUID.ToString(), tn.MaPhieuThuGUID.ToString(), tn.NgayTra.ToString("dd/MM/yyyy HH:mm:ss"), tn.SoTien, tn.GhiChu);
                        }
                    }

                    //Update trạng thái phiếu thu
                    if (isDelete)
                    {
                        switch (loaiPT)
                        {
                        case LoaiPT.DichVu:
                            Receipt ptdv = db.Receipts.Where(p => p.ReceiptGUID.ToString() == phieuThuGUID).FirstOrDefault();
                            ptdv.ChuaThuTien = true;
                            break;

                        case LoaiPT.Thuoc:
                            PhieuThuThuoc ptt = db.PhieuThuThuocs.Where(p => p.PhieuThuThuocGUID.ToString() == phieuThuGUID).FirstOrDefault();
                            ptt.ChuaThuTien = true;
                            break;

                        case LoaiPT.HopDong:
                            PhieuThuHopDong pthd = db.PhieuThuHopDongs.Where(p => p.PhieuThuHopDongGUID.ToString() == phieuThuGUID).FirstOrDefault();
                            pthd.ChuaThuTien = true;
                            break;

                        case LoaiPT.CapCuu:
                            PhieuThuCapCuu ptcc = db.PhieuThuCapCuus.Where(p => p.PhieuThuCapCuuGUID.ToString() == phieuThuGUID).FirstOrDefault();
                            ptcc.ChuaThuTien = true;
                            break;
                        }
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin ghi nhận trả nợ";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.None;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Beispiel #5
0
        public static Result CapNhatTrangThaiPhieuThu(string phieuThuCapCuuGUID, bool daXuatHD, bool daThuTien, byte hinhThucThanhToan, string ghiChu)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();

                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    PhieuThuCapCuu ptcc = db.PhieuThuCapCuus.SingleOrDefault <PhieuThuCapCuu>(p => p.PhieuThuCapCuuGUID.ToString() == phieuThuCapCuuGUID);
                    if (ptcc != null)
                    {
                        ptcc.UpdatedDate       = DateTime.Now;
                        ptcc.UpdatedBy         = Guid.Parse(Global.UserGUID);
                        ptcc.IsExported        = daXuatHD;
                        ptcc.ChuaThuTien       = !daThuTien;
                        ptcc.HinhThucThanhToan = hinhThucThanhToan;
                        ptcc.Notes             = ghiChu;

                        string desc = string.Format("Phiếu thu cấp cứu: GUID: '{0}', Mã phiếu thu: '{1}', Ngày thu: '{2}', Mã bệnh nhân: '{3}', Tên bệnh nhân: '{4}', Địa chỉ: '{5}', Ghi chú: '{6}', Đã thu tiền: '{7}', Đã xuất HĐ: '{8}', Hình thức thanh toán: '{9}'",
                                                    ptcc.PhieuThuCapCuuGUID.ToString(), ptcc.MaPhieuThuCapCuu, ptcc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"),
                                                    ptcc.MaBenhNhan, ptcc.TenBenhNhan, ptcc.DiaChi, ptcc.Notes, !ptcc.ChuaThuTien, ptcc.IsExported, ptcc.HinhThucThanhToan);

                        //Tracking
                        desc = desc.Substring(0, desc.Length - 1);
                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Edit;
                        tk.Action       = "Sửa trạng thái phiếu thu cấp cứu";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.Price;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Beispiel #6
0
        public static Result InsertPhieuThuCapCuu(PhieuThuCapCuu ptcc, List <ChiTietPhieuThuCapCuu> addedList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope tnx = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    //Insert
                    if (ptcc.PhieuThuCapCuuGUID == null || ptcc.PhieuThuCapCuuGUID == Guid.Empty)
                    {
                        ptcc.PhieuThuCapCuuGUID = Guid.NewGuid();
                        db.PhieuThuCapCuus.InsertOnSubmit(ptcc);
                        db.SubmitChanges();

                        desc += string.Format("- Phiếu thu cấp cứu: GUID: '{0}', Mã phiếu thu: '{1}', Ngày thu: '{2}', Mã bệnh nhân: '{3}', Tên bệnh nhân: '{4}', Địa chỉ: '{5}', Ghi chú: '{6}', Đã thu tiền: '{7}', Lý do giảm: '{8}', Toa thuốc GUID: '{9}', Hình thức thanh toán: '{10}'\n",
                                              ptcc.PhieuThuCapCuuGUID.ToString(), ptcc.MaPhieuThuCapCuu, ptcc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"),
                                              ptcc.MaBenhNhan, ptcc.TenBenhNhan, ptcc.DiaChi, ptcc.Notes, !ptcc.ChuaThuTien, ptcc.LyDoGiam, ptcc.ToaCapCuuGUID.ToString(),
                                              ptcc.HinhThucThanhToan);

                        desc += "- Chi tiết phiếu thu cấp cứu được thêm:\n";

                        //Chi tiet phieu thu
                        DateTime dt = DateTime.Now;
                        foreach (ChiTietPhieuThuCapCuu ctptcc in addedList)
                        {
                            ctptcc.PhieuThuCapCuuGUID        = ptcc.PhieuThuCapCuuGUID;
                            ctptcc.ChiTietPhieuThuCapCuuGUID = Guid.NewGuid();

                            int soLuong = Convert.ToInt32(ctptcc.SoLuong);

                            var nhapKhoCapCuuList = from l in db.NhapKhoCapCuus
                                                    where l.Status == (byte)Status.Actived &&
                                                    l.KhoCapCuuGUID == ctptcc.KhoCapCuuGUID &&
                                                    new DateTime(l.NgayHetHan.Value.Year, l.NgayHetHan.Value.Month, l.NgayHetHan.Value.Day) > dt &&
                                                    l.SoLuongNhap * l.SoLuongQuiDoi - l.SoLuongXuat > 0
                                                    orderby new DateTime(l.NgayHetHan.Value.Year, l.NgayHetHan.Value.Month, l.NgayHetHan.Value.Day) ascending,
                                l.NgayNhap ascending
                            select l;

                            double giaNhapTB = 0;
                            if (nhapKhoCapCuuList != null)
                            {
                                double tongGiaNhap = 0;
                                int    count       = 0;
                                foreach (var lt in nhapKhoCapCuuList)
                                {
                                    if (soLuong > 0)
                                    {
                                        int soLuongTon = lt.SoLuongNhap * lt.SoLuongQuiDoi - lt.SoLuongXuat;
                                        if (soLuongTon >= soLuong)
                                        {
                                            lt.SoLuongXuat += soLuong;
                                            tongGiaNhap    += (soLuong * lt.GiaNhapQuiDoi.Value);
                                            count          += soLuong;
                                            soLuong         = 0;
                                            db.SubmitChanges();
                                            break;
                                        }
                                        else
                                        {
                                            lt.SoLuongXuat += soLuongTon;
                                            soLuong        -= soLuongTon;
                                            tongGiaNhap    += (soLuongTon * lt.GiaNhapQuiDoi.Value);
                                            count          += soLuongTon;
                                            db.SubmitChanges();
                                        }
                                    }
                                }

                                giaNhapTB = Math.Round(tongGiaNhap / count, 0);
                            }

                            ctptcc.DonGiaNhap = giaNhapTB;
                            db.ChiTietPhieuThuCapCuus.InsertOnSubmit(ctptcc);
                            db.SubmitChanges();

                            desc += string.Format("  + GUID: '{0}', Tên cấp cứu: '{1}', Đơn giá: '{2}', Số lượng: '{3}', Giảm: '{4}', Thành tiền: '{5}', Đơn giá nhập: '{6}'\n",
                                                  ctptcc.ChiTietPhieuThuCapCuuGUID.ToString(), ctptcc.KhoCapCuu.TenCapCuu, ctptcc.DonGia, ctptcc.SoLuong, ctptcc.Giam, ctptcc.ThanhTien, ctptcc.DonGiaNhap);
                        }

                        //Tracking
                        desc = desc.Substring(0, desc.Length - 1);
                        Tracking tk = new Tracking();
                        tk.TrackingGUID = Guid.NewGuid();
                        tk.TrackingDate = DateTime.Now;
                        tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                        tk.ActionType   = (byte)ActionType.Add;
                        tk.Action       = "Thêm thông tin phiếu thu cấp cứu";
                        tk.Description  = desc;
                        tk.TrackingType = (byte)TrackingType.Price;
                        tk.ComputerName = Utility.GetDNSHostName();
                        db.Trackings.InsertOnSubmit(tk);

                        db.SubmitChanges();
                    }

                    tnx.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }
Beispiel #7
0
        public static Result DeletePhieuThuCapCuu(List <string> keys, List <string> noteList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    DateTime dt    = DateTime.Now;
                    string   desc  = string.Empty;
                    int      index = 0;
                    foreach (string key in keys)
                    {
                        PhieuThuCapCuu ptcc = db.PhieuThuCapCuus.SingleOrDefault <PhieuThuCapCuu>(p => p.PhieuThuCapCuuGUID.ToString() == key);
                        if (ptcc != null)
                        {
                            Status status = (Status)ptcc.Status;
                            ptcc.DeletedDate = DateTime.Now;
                            ptcc.DeletedBy   = Guid.Parse(Global.UserGUID);
                            ptcc.Status      = (byte)Status.Deactived;
                            ptcc.Notes       = noteList[index];

                            if (status == (byte)Status.Actived)
                            {
                                //Update So luong Kho Cap Cuu
                                var ctptts = ptcc.ChiTietPhieuThuCapCuus;
                                foreach (var ct in ctptts)
                                {
                                    int soLuong = Convert.ToInt32(ct.SoLuong);

                                    var nhapKhoCapCuuList = from l in db.NhapKhoCapCuus
                                                            where l.Status == (byte)Status.Actived &&
                                                            l.KhoCapCuuGUID == ct.KhoCapCuuGUID &&
                                                            new DateTime(l.NgayHetHan.Value.Year, l.NgayHetHan.Value.Month, l.NgayHetHan.Value.Day) > dt &&
                                                            l.SoLuongXuat > 0
                                                            orderby new DateTime(l.NgayHetHan.Value.Year, l.NgayHetHan.Value.Month, l.NgayHetHan.Value.Day) ascending,
                                        l.NgayNhap ascending
                                    select l;

                                    if (nhapKhoCapCuuList != null)
                                    {
                                        foreach (var lt in nhapKhoCapCuuList)
                                        {
                                            if (soLuong > 0)
                                            {
                                                if (lt.SoLuongXuat >= soLuong)
                                                {
                                                    lt.SoLuongXuat -= soLuong;
                                                    soLuong         = 0;
                                                    db.SubmitChanges();
                                                    break;
                                                }
                                                else
                                                {
                                                    soLuong       -= lt.SoLuongXuat;
                                                    lt.SoLuongXuat = 0;
                                                    db.SubmitChanges();
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            desc += string.Format("- GUID: '{0}', Mã phiếu thu: '{1}', Ngày thu: '{2}', Mã bệnh nhân: '{3}', Tên bệnh nhân: '{4}', Địa chỉ: '{5}', Ghi chú: '{6}', Đã thu tiền: '{7}', Lý do giảm: '{8}', Toa thuốc GUID: '{9}', Hình thức thanh toán: '{10}'\n",
                                                  ptcc.PhieuThuCapCuuGUID.ToString(), ptcc.MaPhieuThuCapCuu, ptcc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"),
                                                  ptcc.MaBenhNhan, ptcc.TenBenhNhan, ptcc.DiaChi, noteList[index], !ptcc.ChuaThuTien, ptcc.LyDoGiam, ptcc.ToaCapCuuGUID.ToString(),
                                                  ptcc.HinhThucThanhToan);
                        }

                        index++;
                    }

                    //Tracking
                    desc = desc.Substring(0, desc.Length - 1);
                    Tracking tk = new Tracking();
                    tk.TrackingGUID = Guid.NewGuid();
                    tk.TrackingDate = DateTime.Now;
                    tk.DocStaffGUID = Guid.Parse(Global.UserGUID);
                    tk.ActionType   = (byte)ActionType.Delete;
                    tk.Action       = "Xóa thông tin phiếu thu cấp cứu";
                    tk.Description  = desc;
                    tk.TrackingType = (byte)TrackingType.Price;
                    tk.ComputerName = Utility.GetDNSHostName();
                    db.Trackings.InsertOnSubmit(tk);

                    db.SubmitChanges();
                    t.Complete();
                }
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }