public ActionResult DeleteConfirmed(int id)
        {
            HoaDonThuoc hoaDonThuoc = db.HoaDonThuocs.Find(id);

            db.HoaDonThuocs.Remove(hoaDonThuoc);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "id,NgayThu,DonVi,SoLuong,DonGia,ThanhTien,Thuoc_id,BenhNhan_id")] HoaDonThuoc hoaDonThuoc)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hoaDonThuoc).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BenhNhan_id = new SelectList(db.BenhNhans, "id", "TenBN", hoaDonThuoc.BenhNhan_id);
     ViewBag.Thuoc_id    = new SelectList(db.Thuocs, "id", "TenThuoc", hoaDonThuoc.Thuoc_id);
     return(View(hoaDonThuoc));
 }
        // GET: Admin/HoaDonThuocs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HoaDonThuoc hoaDonThuoc = db.HoaDonThuocs.Find(id);

            if (hoaDonThuoc == null)
            {
                return(HttpNotFound());
            }
            return(View(hoaDonThuoc));
        }
        // GET: Admin/HoaDonThuocs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HoaDonThuoc hoaDonThuoc = db.HoaDonThuocs.Find(id);

            if (hoaDonThuoc == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BenhNhan_id = new SelectList(db.BenhNhans, "id", "TenBN", hoaDonThuoc.BenhNhan_id);
            ViewBag.Thuoc_id    = new SelectList(db.Thuocs, "id", "TenThuoc", hoaDonThuoc.Thuoc_id);
            return(View(hoaDonThuoc));
        }
Пример #5
0
        public static Result GetNgayXuatHoaDon(string soHoaDon)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                HoaDonThuoc hdt = (from i in db.HoaDonThuocs
                                   where i.SoHoaDon == soHoaDon &&
                                   i.Status == (byte)Status.Deactived &&
                                   i.NgayXuatHoaDon >= Global.NgayThayDoiSoHoaDonSauCung
                                   orderby i.NgayXuatHoaDon descending
                                   select i).FirstOrDefault();

                if (hdt != null)
                {
                    result.QueryResult = hdt.NgayXuatHoaDon.Value;
                }
            }
            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);
        }
Пример #6
0
        public static Result UpdateDaThuTienInvoice(string hoaDonThuocGUID, bool daThuTien)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    HoaDonThuoc invoice = db.HoaDonThuocs.SingleOrDefault <HoaDonThuoc>(i => i.HoaDonThuocGUID.ToString() == hoaDonThuocGUID);
                    if (invoice != null)
                    {
                        invoice.UpdatedDate = DateTime.Now;
                        invoice.UpdatedBy   = Guid.Parse(Global.UserGUID);
                        invoice.ChuaThuTien = !daThuTien;

                        string htttStr = Utility.ParseHinhThucThanhToanToStr((PaymentType)invoice.HinhThucThanhToan);

                        desc += string.Format("- Hóa đơn thuốc: GUID: '{0}', Mã hóa đơn: '{1}', Ngày xuất HĐ: '{2}', Người mua hàng: '{3}', Tên đơn vị: '{4}', Địa chỉ: '{5}', STK: '{6}', Hình thức thanh toán: '{7}', Ghi chú: '{8}', Đã thu tiền: '{9}'\n",
                                              invoice.HoaDonThuocGUID.ToString(), invoice.SoHoaDon, invoice.NgayXuatHoaDon.Value.ToString("dd/MM/yyyy HH:mm:ss"),
                                              invoice.TenNguoiMuaHang, invoice.TenDonVi, invoice.DiaChi, invoice.SoTaiKhoan, htttStr, invoice.Notes, !invoice.ChuaThuTien);

                        //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       = "Cập nhật thông tin hóa đơn thuốc";
                        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);
        }
Пример #7
0
        public static Result InsertHoaDonThuoc(HoaDonThuoc hdt, List <ChiTietHoaDonThuoc> addedDetails)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    hdt.HoaDonThuocGUID = Guid.NewGuid();
                    db.HoaDonThuocs.InsertOnSubmit(hdt);
                    db.SubmitChanges();

                    string htttStr = Utility.ParseHinhThucThanhToanToStr((PaymentType)hdt.HinhThucThanhToan);

                    desc += string.Format("- Hóa đơn thuốc: GUID: '{0}', Mã hóa đơn: '{1}', Ngày xuất HĐ: '{2}', Người mua hàng: '{3}', Tên đơn vị: '{4}', Địa chỉ: '{5}', STK: '{6}', Hình thức thanh toán: '{7}', Ghi chú: '{8}', Đã thu tiền: '{9}'\n",
                                          hdt.HoaDonThuocGUID.ToString(), hdt.SoHoaDon, hdt.NgayXuatHoaDon.Value.ToString("dd/MM/yyyy HH:mm:ss"),
                                          hdt.TenNguoiMuaHang, hdt.TenDonVi, hdt.DiaChi, hdt.SoTaiKhoan, htttStr, hdt.Notes, !hdt.ChuaThuTien);

                    if (addedDetails != null && addedDetails.Count > 0)
                    {
                        desc += "- Chi tiết hóa đơn:\n";

                        foreach (ChiTietHoaDonThuoc detail in addedDetails)
                        {
                            detail.ChiTietHoaDonThuocGUID = Guid.NewGuid();
                            detail.HoaDonThuocGUID        = hdt.HoaDonThuocGUID;
                            db.ChiTietHoaDonThuocs.InsertOnSubmit(detail);

                            desc += string.Format("  + GUID: '{0}', Dịch vụ: '{1}', ĐVT: '{2}', Số lượng: '{3}', Đơn giá: '{4}', Thành tiền: '{5}', Loai: '{6}'\n",
                                                  detail.ChiTietHoaDonThuocGUID.ToString(), detail.TenThuoc, detail.DonViTinh, detail.SoLuong, detail.DonGia, detail.ThanhTien, detail.Loai);
                        }

                        db.SubmitChanges();
                    }

                    //Update Exported Invoice
                    if (hdt.PhieuThuThuocGUIDList != null && hdt.PhieuThuThuocGUIDList.Trim() != string.Empty)
                    {
                        string[] pttkeys = hdt.PhieuThuThuocGUIDList.Split(',');
                        foreach (string pttKey in pttkeys)
                        {
                            PhieuThuThuoc ptt = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(r => r.PhieuThuThuocGUID.ToString() == pttKey);
                            if (ptt != null)
                            {
                                ptt.IsExported = true;
                            }
                        }
                    }

                    int            soHoaDon = Convert.ToInt32(hdt.SoHoaDon);
                    QuanLySoHoaDon qlshd    = db.QuanLySoHoaDons.SingleOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon &&
                                                                                                  q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonSauCung);
                    if (qlshd != null)
                    {
                        qlshd.DaXuat = true;
                    }
                    else
                    {
                        qlshd = new QuanLySoHoaDon();
                        qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                        qlshd.SoHoaDon           = soHoaDon;
                        qlshd.DaXuat             = true;
                        qlshd.XuatTruoc          = false;
                        qlshd.NgayBatDau         = Global.NgayThayDoiSoHoaDonSauCung;
                        db.QuanLySoHoaDons.InsertOnSubmit(qlshd);
                    }

                    //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 hóa đơn thuốc";
                    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);
        }
Пример #8
0
        public static Result DeleteHoaDonThuoc(List <string> keys, List <string> noteList)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    string desc  = string.Empty;
                    int    index = 0;
                    foreach (string key in keys)
                    {
                        HoaDonThuoc hdt = db.HoaDonThuocs.SingleOrDefault <HoaDonThuoc>(i => i.HoaDonThuocGUID.ToString() == key);
                        if (hdt != null)
                        {
                            hdt.DeletedDate = DateTime.Now;
                            hdt.DeletedBy   = Guid.Parse(Global.UserGUID);
                            hdt.Status      = (byte)Status.Deactived;
                            if (hdt.Notes == null || hdt.Notes.Trim() == string.Empty)
                            {
                                hdt.Notes = noteList[index];
                            }
                            else
                            {
                                hdt.Notes += string.Format(" - {0}", noteList[index]);
                            }

                            //Update Exported Invoice
                            if (hdt.PhieuThuThuocGUIDList != null && hdt.PhieuThuThuocGUIDList.Trim() != string.Empty)
                            {
                                string[] pttkeys = hdt.PhieuThuThuocGUIDList.Split(',');
                                foreach (string pttKey in pttkeys)
                                {
                                    PhieuThuThuoc ptt = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(r => r.PhieuThuThuocGUID.ToString() == pttKey);
                                    if (ptt != null)
                                    {
                                        ptt.IsExported = false;
                                    }
                                }
                            }

                            int soHoaDon = Convert.ToInt32(hdt.SoHoaDon);

                            DateTime fromDate    = Global.MinDateTime;
                            DateTime toDate      = Global.MaxDateTime;
                            var      ngayThayDoi = (from n in db.NgayBatDauLamMoiSoHoaDons
                                                    where n.KiHieu.ToLower() == hdt.KiHieu &&
                                                    n.MauSo.ToLower() == hdt.MauSo.ToLower()
                                                    select n).FirstOrDefault();

                            if (ngayThayDoi != null)
                            {
                                fromDate = ngayThayDoi.NgayBatDau;

                                var nextThayDoi = (from n in db.NgayBatDauLamMoiSoHoaDons
                                                   where n.NgayBatDau > ngayThayDoi.NgayBatDau
                                                   orderby n.NgayBatDau ascending
                                                   select n).FirstOrDefault();

                                if (nextThayDoi != null)
                                {
                                    toDate = nextThayDoi.NgayBatDau;
                                }

                                QuanLySoHoaDon qlshd = db.QuanLySoHoaDons.SingleOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon &&
                                                                                                           q.NgayBatDau.Value >= fromDate && q.NgayBatDau < toDate);
                                if (qlshd != null)
                                {
                                    qlshd.DaXuat = false;
                                }
                                else
                                {
                                    qlshd = new QuanLySoHoaDon();
                                    qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                                    qlshd.SoHoaDon           = soHoaDon;
                                    qlshd.DaXuat             = false;
                                    qlshd.XuatTruoc          = false;
                                    qlshd.NgayBatDau         = fromDate;
                                    db.QuanLySoHoaDons.InsertOnSubmit(qlshd);
                                }
                            }

                            string htttStr = Utility.ParseHinhThucThanhToanToStr((PaymentType)hdt.HinhThucThanhToan);

                            desc += string.Format("- GUID: '{0}', Mã hóa đơn: '{1}', Ngày xuất HĐ: '{2}', Người mua hàng: '{3}', Tên đơn vị: '{4}', Địa chỉ: '{5}', STK: '{6}', Hình thức thanh toán: '{7}', Ghi chú: '{8}', Đã thu tiền: '{9}'\n",
                                                  hdt.HoaDonThuocGUID.ToString(), hdt.SoHoaDon, hdt.NgayXuatHoaDon.Value.ToString("dd/MM/yyyy HH:mm:ss"),
                                                  hdt.TenNguoiMuaHang, hdt.TenDonVi, hdt.DiaChi, hdt.SoTaiKhoan, htttStr, noteList[index], !hdt.ChuaThuTien);
                        }

                        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 hóa đơn thuốc";
                    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);
        }
Пример #9
0
        public static Result GetSoHoaDon()
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                while (true)
                {
                    string query = string.Format("SELECT Min(SoHoaDon) as SoHoaDon FROM QuanLySoHoaDon WITH(NOLOCK) WHERE XuatTruoc = 'False' AND DaXuat = 'False' AND NgayBatDau >= '{0}'",
                                                 Global.NgayThayDoiSoHoaDonSauCung.ToString("yyyy-MM-dd HH:mm:ss"));
                    result = ExcuteQuery(query);
                    if (!result.IsOK)
                    {
                        return(result);
                    }
                    DataTable dt = result.QueryResult as DataTable;
                    if (dt != null && dt.Rows.Count > 0 && dt.Rows[0][0] != null && dt.Rows[0][0] != DBNull.Value)
                    {
                        result.QueryResult = dt.Rows[0][0];
                    }
                    else
                    {
                        query = string.Format("SELECT MAX(SoHoaDon) as SoHoaDon FROM QuanLySoHoaDon WITH(NOLOCK) WHERE NgayBatDau >= '{0}'",
                                              Global.NgayThayDoiSoHoaDonSauCung.ToString("yyyy-MM-dd HH:mm:ss"));
                        result = ExcuteQuery(query);
                        if (!result.IsOK)
                        {
                            return(result);
                        }

                        dt = result.QueryResult as DataTable;
                        if (dt != null && dt.Rows.Count > 0 && dt.Rows[0][0] != null && dt.Rows[0][0] != DBNull.Value)
                        {
                            result.QueryResult = Convert.ToInt32(dt.Rows[0][0]) + 1;
                        }
                        else
                        {
                            result.QueryResult = Global.SoHoaDonBatDau;
                        }
                    }

                    db = new MMOverride();
                    int  soHoaDon = Convert.ToInt32(result.QueryResult);
                    bool isExist  = false;

                    //Hoa don dich vu
                    Invoice hdhd = db.Invoices.FirstOrDefault <Invoice>(h => Convert.ToInt32(h.InvoiceCode) == soHoaDon &&
                                                                        h.Status == (byte)Status.Actived && h.InvoiceDate >= Global.NgayThayDoiSoHoaDonSauCung);
                    if (hdhd != null)
                    {
                        QuanLySoHoaDon qlshd = db.QuanLySoHoaDons.FirstOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon &&
                                                                                                  q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonSauCung);
                        if (qlshd == null)
                        {
                            qlshd = new QuanLySoHoaDon();
                            qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                            qlshd.SoHoaDon           = soHoaDon;
                            qlshd.DaXuat             = true;
                            qlshd.XuatTruoc          = false;
                            qlshd.NgayBatDau         = Global.NgayThayDoiSoHoaDonSauCung;
                            db.QuanLySoHoaDons.InsertOnSubmit(qlshd);
                        }
                        else
                        {
                            qlshd.DaXuat = true;
                        }

                        db.SubmitChanges();
                        isExist = true;
                    }

                    //Hoa don thuoc
                    if (!isExist)
                    {
                        HoaDonThuoc hdt = db.HoaDonThuocs.FirstOrDefault <HoaDonThuoc>(h => Convert.ToInt32(h.SoHoaDon) == soHoaDon &&
                                                                                       h.Status == (byte)Status.Actived && h.NgayXuatHoaDon >= Global.NgayThayDoiSoHoaDonSauCung);
                        if (hdt != null)
                        {
                            QuanLySoHoaDon qlshd = db.QuanLySoHoaDons.FirstOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon &&
                                                                                                      q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonSauCung);
                            if (qlshd == null)
                            {
                                qlshd = new QuanLySoHoaDon();
                                qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                                qlshd.SoHoaDon           = soHoaDon;
                                qlshd.DaXuat             = true;
                                qlshd.XuatTruoc          = false;
                                qlshd.NgayBatDau         = Global.NgayThayDoiSoHoaDonSauCung;
                                db.QuanLySoHoaDons.InsertOnSubmit(qlshd);
                            }
                            else
                            {
                                qlshd.DaXuat = true;
                            }

                            db.SubmitChanges();
                            isExist = true;
                        }
                    }


                    //Hoa don xuat truoc
                    if (!isExist)
                    {
                        HoaDonXuatTruoc hdxt = db.HoaDonXuatTruocs.FirstOrDefault <HoaDonXuatTruoc>(h => Convert.ToInt32(h.SoHoaDon) == soHoaDon &&
                                                                                                    h.Status == (byte)Status.Actived && h.NgayXuatHoaDon >= Global.NgayThayDoiSoHoaDonSauCung);
                        if (hdxt != null)
                        {
                            QuanLySoHoaDon qlshd = db.QuanLySoHoaDons.FirstOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon &&
                                                                                                      q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonSauCung);
                            if (qlshd == null)
                            {
                                qlshd = new QuanLySoHoaDon();
                                qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                                qlshd.SoHoaDon           = soHoaDon;
                                qlshd.DaXuat             = true;
                                qlshd.XuatTruoc          = true;
                                qlshd.NgayBatDau         = Global.NgayThayDoiSoHoaDonSauCung;
                                db.QuanLySoHoaDons.InsertOnSubmit(qlshd);
                            }
                            else
                            {
                                qlshd.DaXuat = true;
                            }

                            db.SubmitChanges();
                            isExist = true;
                        }
                    }

                    //Hoa don hop dong
                    if (!isExist)
                    {
                        HoaDonHopDong hd = db.HoaDonHopDongs.FirstOrDefault <HoaDonHopDong>(h => Convert.ToInt32(h.SoHoaDon) == soHoaDon &&
                                                                                            h.Status == (byte)Status.Actived && h.NgayXuatHoaDon >= Global.NgayThayDoiSoHoaDonSauCung);
                        if (hd != null)
                        {
                            QuanLySoHoaDon qlshd = db.QuanLySoHoaDons.FirstOrDefault <QuanLySoHoaDon>(q => q.SoHoaDon == soHoaDon &&
                                                                                                      q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonSauCung);
                            if (qlshd == null)
                            {
                                qlshd = new QuanLySoHoaDon();
                                qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                                qlshd.SoHoaDon           = soHoaDon;
                                qlshd.DaXuat             = true;
                                qlshd.XuatTruoc          = false;
                                qlshd.NgayBatDau         = Global.NgayThayDoiSoHoaDonSauCung;
                                db.QuanLySoHoaDons.InsertOnSubmit(qlshd);
                            }
                            else
                            {
                                qlshd.DaXuat = true;
                            }

                            db.SubmitChanges();
                            isExist = true;
                        }
                    }

                    if (!isExist)
                    {
                        break;
                    }
                }
            }
            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);
        }