Ejemplo n.º 1
0
        public static Result CheckHoaDonXetNghiemExistCode(int soHoaDon)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                QuanLySoHoaDonXetNghiemYKhoa qlshd = db.QuanLySoHoaDonXetNghiemYKhoas.SingleOrDefault <QuanLySoHoaDonXetNghiemYKhoa>(q => q.SoHoaDon == soHoaDon &&
                                                                                                                                     (q.DaXuat == true || q.XuatTruoc == true) && q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonXetNghiemSauCung);

                if (qlshd == 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);
        }
        public static Result GetSoHoaDon()
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                while (true)
                {
                    string query = string.Format("SELECT Min(SoHoaDon) as SoHoaDon FROM QuanLySoHoaDonXetNghiemYKhoa WITH(NOLOCK) WHERE XuatTruoc = 'False' AND DaXuat = 'False' AND NgayBatDau >= '{0}'",
                                                 Global.NgayThayDoiSoHoaDonXetNghiemSauCung.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 QuanLySoHoaDonXetNghiemYKhoa WITH(NOLOCK) WHERE NgayBatDau >= '{0}'",
                                              Global.NgayThayDoiSoHoaDonXetNghiemSauCung.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.SoHoaDonXetNghiemBatDau;
                        }
                    }

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

                    //Hoa don xét nghiệm
                    HoaDonXetNghiem hdxn = db.HoaDonXetNghiems.FirstOrDefault <HoaDonXetNghiem>(h => Convert.ToInt32(h.SoHoaDon) == soHoaDon &&
                                                                                                h.Status == (byte)Status.Actived && h.NgayXuatHoaDon >= Global.NgayThayDoiSoHoaDonXetNghiemSauCung);
                    if (hdxn != null)
                    {
                        QuanLySoHoaDonXetNghiemYKhoa qlshd = db.QuanLySoHoaDonXetNghiemYKhoas.FirstOrDefault <QuanLySoHoaDonXetNghiemYKhoa>(q => q.SoHoaDon == soHoaDon &&
                                                                                                                                            q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonXetNghiemSauCung);
                        if (qlshd == null)
                        {
                            qlshd = new QuanLySoHoaDonXetNghiemYKhoa();
                            qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                            qlshd.SoHoaDon           = soHoaDon;
                            qlshd.DaXuat             = true;
                            qlshd.XuatTruoc          = false;
                            qlshd.NgayBatDau         = Global.NgayThayDoiSoHoaDonXetNghiemSauCung;
                            db.QuanLySoHoaDonXetNghiemYKhoas.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);
        }
Ejemplo n.º 3
0
        public static Result InsertHoaDonXetNghiem(HoaDonXetNghiem hdxn, List <ChiTietHoaDonXetNghiem> addedDetails)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                string desc = string.Empty;
                using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    hdxn.HoaDonXetNghiemGUID = Guid.NewGuid();
                    db.HoaDonXetNghiems.InsertOnSubmit(hdxn);
                    db.SubmitChanges();

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

                    desc += string.Format("- Hóa đơn xét nghiệm 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",
                                          hdxn.HoaDonXetNghiemGUID.ToString(), hdxn.SoHoaDon, hdxn.NgayXuatHoaDon.Value.ToString("dd/MM/yyyy HH:mm:ss"),
                                          hdxn.TenNguoiMuaHang, hdxn.TenDonVi, hdxn.DiaChi, hdxn.SoTaiKhoan, htttStr, hdxn.Notes, !hdxn.ChuaThuTien);

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

                        foreach (ChiTietHoaDonXetNghiem detail in addedDetails)
                        {
                            detail.ChiTietHoaDonXetNghiemGUID = Guid.NewGuid();
                            detail.HoaDonXetNghiemGUID        = hdxn.HoaDonXetNghiemGUID;
                            db.ChiTietHoaDonXetNghiems.InsertOnSubmit(detail);

                            desc += string.Format("  + GUID: '{0}', Mặt hàng: '{1}', ĐVT: '{2}', Số lượng: '{3}', Đơn giá: '{4}', Thành tiền: '{5}'\n",
                                                  detail.ChiTietHoaDonXetNghiemGUID.ToString(), detail.TenHangHoa, detail.DonViTinh, detail.SoLuong, detail.DonGia, detail.ThanhTien);
                        }

                        db.SubmitChanges();
                    }

                    int soHoaDon = Convert.ToInt32(hdxn.SoHoaDon);
                    QuanLySoHoaDonXetNghiemYKhoa qlshd = db.QuanLySoHoaDonXetNghiemYKhoas.SingleOrDefault <QuanLySoHoaDonXetNghiemYKhoa>(q => q.SoHoaDon == soHoaDon &&
                                                                                                                                         q.NgayBatDau.Value >= Global.NgayThayDoiSoHoaDonXetNghiemSauCung);
                    if (qlshd != null)
                    {
                        qlshd.DaXuat = true;
                    }
                    else
                    {
                        qlshd = new QuanLySoHoaDonXetNghiemYKhoa();
                        qlshd.QuanLySoHoaDonGUID = Guid.NewGuid();
                        qlshd.SoHoaDon           = soHoaDon;
                        qlshd.DaXuat             = true;
                        qlshd.XuatTruoc          = false;
                        qlshd.NgayBatDau         = Global.NgayThayDoiSoHoaDonXetNghiemSauCung;
                        db.QuanLySoHoaDonXetNghiemYKhoas.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 xét nghiệm";
                    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);
        }
Ejemplo n.º 4
0
        public static Result DeleteHoaDonXetNghiem(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)
                    {
                        HoaDonXetNghiem hdxn = db.HoaDonXetNghiems.SingleOrDefault <HoaDonXetNghiem>(i => i.HoaDonXetNghiemGUID.ToString() == key);
                        if (hdxn != null)
                        {
                            hdxn.DeletedDate = DateTime.Now;
                            hdxn.DeletedBy   = Guid.Parse(Global.UserGUID);
                            hdxn.Status      = (byte)Status.Deactived;
                            if (hdxn.Notes == null || hdxn.Notes.Trim() == string.Empty)
                            {
                                hdxn.Notes = noteList[index];
                            }
                            else
                            {
                                hdxn.Notes += string.Format(" - {0}", noteList[index]);
                            }

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

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

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

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

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

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

                            string htttStr = Utility.ParseHinhThucThanhToanToStr((PaymentType)hdxn.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",
                                                  hdxn.HoaDonXetNghiemGUID.ToString(), hdxn.SoHoaDon, hdxn.NgayXuatHoaDon.Value.ToString("dd/MM/yyyy HH:mm:ss"),
                                                  hdxn.TenNguoiMuaHang, hdxn.TenDonVi, hdxn.DiaChi, hdxn.SoTaiKhoan, htttStr, noteList[index], !hdxn.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 xét nghiệm";
                    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);
        }