public static Result GetPhieuThuThuoc(string phieuThuThuocGUID) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); PhieuThuThuoc ptthuoc = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(p => p.PhieuThuThuocGUID.ToString() == phieuThuThuocGUID); result.QueryResult = ptthuoc; } 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 CheckPhieuThuThuocExistCode(string phieuThuThuocGUID, string code) { Result result = new Result(); MMOverride db = null; try { db = new MMOverride(); PhieuThuThuoc ptthuoc = null; if (phieuThuThuocGUID == null || phieuThuThuocGUID == string.Empty) { ptthuoc = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(p => p.MaPhieuThuThuoc.ToLower() == code.ToLower()); } else { ptthuoc = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(p => p.MaPhieuThuThuoc.ToLower() == code.ToLower() && p.PhieuThuThuocGUID.ToString() != phieuThuThuocGUID); } if (ptthuoc == 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 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); }
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); }
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); }
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); }
public static Result CapNhatTrangThaiPhieuThu(string phieuThuThuocGUID, 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)) { PhieuThuThuoc ptthuoc = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(p => p.PhieuThuThuocGUID.ToString() == phieuThuThuocGUID); if (ptthuoc != null) { ptthuoc.UpdatedDate = DateTime.Now; ptthuoc.UpdatedBy = Guid.Parse(Global.UserGUID); ptthuoc.IsExported = daXuatHD; ptthuoc.ChuaThuTien = !daThuTien; ptthuoc.HinhThucThanhToan = hinhThucThanhToan; ptthuoc.Notes = ghiChu; string maToaThuoc = string.Empty; if (ptthuoc.ToaThuocGUID.Value != Guid.Empty) { maToaThuoc = db.ToaThuocs.SingleOrDefault <ToaThuoc>(tt => tt.ToaThuocGUID == ptthuoc.ToaThuocGUID.Value).MaToaThuoc; } string desc = string.Format("Phiếu thu thuốc: GUID: '{0}', Mã toa thuốc: '{1}', Mã phiếu thu: '{2}', Ngày thu: '{3}', Mã bệnh nhân: '{4}', Tên bệnh nhân: '{5}', Địa chỉ: '{6}', Ghi chú: '{7}', Đã thu tiền: '{8}', Đã xuất HĐ: '{9}', Hình thức thanh toán: '{10}'", ptthuoc.PhieuThuThuocGUID.ToString(), maToaThuoc, ptthuoc.MaPhieuThuThuoc, ptthuoc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"), ptthuoc.MaBenhNhan, ptthuoc.TenBenhNhan, ptthuoc.DiaChi, ptthuoc.Notes, !ptthuoc.ChuaThuTien, ptthuoc.IsExported, ptthuoc.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 thuốc"; 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); }
public static Result InsertPhieuThuThuoc(PhieuThuThuoc ptthuoc, List <ChiTietPhieuThuThuoc> 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 (ptthuoc.PhieuThuThuocGUID == null || ptthuoc.PhieuThuThuocGUID == Guid.Empty) { ptthuoc.PhieuThuThuocGUID = Guid.NewGuid(); db.PhieuThuThuocs.InsertOnSubmit(ptthuoc); db.SubmitChanges(); string maToaThuoc = string.Empty; if (ptthuoc.ToaThuocGUID.Value != Guid.Empty) { maToaThuoc = db.ToaThuocs.SingleOrDefault <ToaThuoc>(tt => tt.ToaThuocGUID == ptthuoc.ToaThuocGUID.Value).MaToaThuoc; } desc += string.Format("- Phiếu thu thuốc: GUID: '{0}', Mã toa thuốc: '{1}', Mã phiếu thu: '{2}', Ngày thu: '{3}', Mã bệnh nhân: '{4}', Tên bệnh nhân: '{5}', Địa chỉ: '{6}', Ghi chú: '{7}', Đã thu tiền: '{8}', Lý do giảm: '{9}', Hình thức thanh toán: '{10}'\n", ptthuoc.PhieuThuThuocGUID.ToString(), maToaThuoc, ptthuoc.MaPhieuThuThuoc, ptthuoc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"), ptthuoc.MaBenhNhan, ptthuoc.TenBenhNhan, ptthuoc.DiaChi, ptthuoc.Notes, !ptthuoc.ChuaThuTien, ptthuoc.LyDoGiam, ptthuoc.HinhThucThanhToan); desc += "- Chi tiết phiếu thu thuốc được thêm:\n"; //Chi tiet phieu thu DateTime dt = DateTime.Now; foreach (ChiTietPhieuThuThuoc ctptt in addedList) { ctptt.PhieuThuThuocGUID = ptthuoc.PhieuThuThuocGUID; ctptt.ChiTietPhieuThuThuocGUID = Guid.NewGuid(); int soLuong = Convert.ToInt32(ctptt.SoLuong); if (soLuong <= 0) { Utility.WriteToTraceLog(string.Format("Số lượng: '{0}', Mã thuốc: '{1}', Mã phiếu thu: '{2}'", soLuong, ctptt.ThuocGUID.ToString(), ptthuoc.MaPhieuThuThuoc)); } var loThuocList = from l in db.LoThuocs where l.Status == (byte)Status.Actived && l.ThuocGUID == ctptt.ThuocGUID && new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) > dt && l.SoLuongNhap * l.SoLuongQuiDoi - l.SoLuongXuat > 0 orderby new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) ascending, l.CreatedDate ascending select l; double giaNhapTB = 0; if (loThuocList != null) { double tongGiaNhap = 0; int count = 0; foreach (var lt in loThuocList) { if (soLuong > 0) { int soLuongTon = lt.SoLuongNhap * lt.SoLuongQuiDoi - lt.SoLuongXuat; if (soLuongTon >= soLuong) { lt.SoLuongXuat += soLuong; tongGiaNhap += (soLuong * lt.GiaNhapQuiDoi); count += soLuong; soLuong = 0; db.SubmitChanges(); break; } else { lt.SoLuongXuat += soLuongTon; soLuong -= soLuongTon; tongGiaNhap += (soLuongTon * lt.GiaNhapQuiDoi); count += soLuongTon; db.SubmitChanges(); } } } giaNhapTB = Math.Round(tongGiaNhap / count, 0); } else { Utility.WriteToTraceLog(string.Format("Không tồn tại lô thuốc: '{0}', Mã phiếu thu: '{1}'", ctptt.ThuocGUID.ToString(), ptthuoc.MaPhieuThuThuoc)); } ctptt.DonGiaNhap = giaNhapTB; db.ChiTietPhieuThuThuocs.InsertOnSubmit(ctptt); db.SubmitChanges(); desc += string.Format(" + GUID: '{0}', Thuốc: '{1}', Đơn giá: '{2}', Số lượng: '{3}', Giảm: '{4}', Thành tiền: '{5}', Đơn giá nhập: '{6}'\n", ctptt.ChiTietPhieuThuThuocGUID.ToString(), ctptt.Thuoc.TenThuoc, ctptt.DonGia, ctptt.SoLuong, ctptt.Giam, ctptt.ThanhTien, ctptt.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 thuốc"; 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); }
public static Result DeletePhieuThuThuoc(List <string> phieuThuThuocKeys, 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 phieuThuThuocKeys) { PhieuThuThuoc ptthuoc = db.PhieuThuThuocs.SingleOrDefault <PhieuThuThuoc>(p => p.PhieuThuThuocGUID.ToString() == key); if (ptthuoc != null) { Status status = (Status)ptthuoc.Status; ptthuoc.DeletedDate = DateTime.Now; ptthuoc.DeletedBy = Guid.Parse(Global.UserGUID); ptthuoc.Status = (byte)Status.Deactived; ptthuoc.Notes = noteList[index]; if (status == (byte)Status.Actived) { //Update So luong Lo thuoc var ctptts = ptthuoc.ChiTietPhieuThuThuocs; foreach (var ctptt in ctptts) { int soLuong = Convert.ToInt32(ctptt.SoLuong); var loThuocList = from l in db.LoThuocs where l.Status == (byte)Status.Actived && l.ThuocGUID == ctptt.ThuocGUID && new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) > dt && l.SoLuongXuat > 0 orderby new DateTime(l.NgayHetHan.Year, l.NgayHetHan.Month, l.NgayHetHan.Day) ascending, l.CreatedDate ascending select l; if (loThuocList != null) { foreach (var lt in loThuocList) { if (soLuong > 0) { if (lt.SoLuongXuat >= soLuong) { lt.SoLuongXuat -= soLuong; soLuong = 0; db.SubmitChanges(); break; } else { soLuong -= lt.SoLuongXuat; lt.SoLuongXuat = 0; db.SubmitChanges(); } } } } else { Utility.WriteToTraceLog(string.Format("Không tồn tại lô thuốc: '{0}', Mã phiếu thu: '{1}'", ctptt.ThuocGUID.ToString(), ptthuoc.MaPhieuThuThuoc)); } } } string maToaThuoc = string.Empty; if (ptthuoc.ToaThuocGUID.Value != Guid.Empty) { maToaThuoc = db.ToaThuocs.SingleOrDefault <ToaThuoc>(tt => tt.ToaThuocGUID == ptthuoc.ToaThuocGUID.Value).MaToaThuoc; } desc += string.Format("- GUID: '{0}', Mã toa thuốc: '{1}', Mã phiếu thu: '{2}', Ngày thu: '{3}', Mã bệnh nhân: '{4}', Tên bệnh nhân: '{5}', Địa chỉ: '{6}', Ghi chú: '{7}', Đã thu tiền: '{8}', Lý do giảm: '{9}', Hình thức thanh toán: '{10}'\n", ptthuoc.PhieuThuThuocGUID.ToString(), maToaThuoc, ptthuoc.MaPhieuThuThuoc, ptthuoc.NgayThu.ToString("dd/MM/yyyy HH:mm:ss"), ptthuoc.MaBenhNhan, ptthuoc.TenBenhNhan, ptthuoc.DiaChi, noteList[index], !ptthuoc.ChuaThuTien, ptthuoc.LyDoGiam, ptthuoc.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 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); }