protected internal override void DeleteChungTuInstance() { if (IsEditMode) { CheckInvalidLock(); if (((BusinessProviderBase)BusinessProvider).GetChungTuRefBySoChungTu <T>(ChungTuInfo.SoChungTu) != null) { throw new Exception("Chứng từ này đã được sử dụng trong hệ thống, không thể xóa được."); } if (!((BusinessProviderBase)BusinessProvider).ChiTietHangHoaExists(ChungTuInfo.SoChungTu)) { SaveChiTietChungTu(ListChiTietChungTu, new List <TK>()); if (BusinessKeToanKhoProvider != null) { BusinessKeToanKhoProvider.DeleteChungTu(ChungTuInfo.IdChungTu); } else { BusinessProvider.UpdateChungTu(ChungTu); } } else { throw new Exception("Chứng từ này đã được bắn mã vạch, không thể xóa được."); } } }
protected internal override void CancelChungTuInstance() { if (IsEditMode) { CheckInvalidLock(); if (!ChungTuInfo.IsOrigin) { BusinessProvider.UpdateChungTu(ChungTu); } ChungTuChiTietBaseInfo chungTuChiTietInfo; foreach (TK originInfo in ListChiTietChungTu) { chungTuChiTietInfo = ToBaseInfo(originInfo); TinhTonKho(ChungTuInfo.IdKho, chungTuChiTietInfo.IdSanPham, -chungTuChiTietInfo.SoLuong, chungTuChiTietInfo.SoLuong); } if (ChungTuInfo.IdKho == 0) { return; } ((BusinessProviderBase)BusinessProvider).ChungTuSyncPushORC(this); } }
/// <summary> /// Kiểm tra có cập nhật thì mới lưu. /// </summary> protected internal override void SaveChungTuInstance() { TK[] arrBackupChiTietChungTu = new TK[ListChiTietChungTu.Count]; ListChiTietChungTu.CopyTo(arrBackupChiTietChungTu); int backupChungTu = ChungTuInfo.IdChungTu; try { if (ListChiTietChungTu.Count == 0) { throw new ManagedException("Không có line chi tiết!"); } if (!IsOnTheSameAccountBook) { throw new ManagedException("Không được ghi nhận trong cùng bộ sổ."); } if (IsEditMode) { if (!ChungTuInfo.IsOrigin) { if ((ChungTuOriginInfo as ChungTuBaseInfo).IdKho != ChungTuInfo.IdKho) { throw new ManagedException("Chứng từ đã được tạo, không thể thay đổi thông tin kho!"); } if ((ChungTuOriginInfo as ChungTuBaseInfo).SoChungTu != ChungTuInfo.SoChungTu) { throw new ManagedException("Chứng từ đã được tạo, không thể thay đổi số chứng từ!"); } CheckInvalidLock(); BusinessProvider.UpdateChungTu(ChungTu); } } else { ChungTuInfo.IdChungTu = BusinessProvider.InsertChungTu(ChungTu); } //if ((((BusinessProviderBase)BusinessProvider).GetChungTuBySoChungTu<T>(ChungTuInfo.SoChungTu) as ChungTuBaseInfo).TrangThai == TrangThaiHuy) //{ // throw new ManagedException("Chứng từ này đã bị hủy!"); //} //check so chung tu bi lap if (BusinessProvider is BusinessProviderBase) { if (((BusinessProviderBase)BusinessProvider). DuplicateSoChungTu(ChungTuInfo.SoChungTu, ChungTuInfo.IdChungTu)) { throw new ManagedException("Số chứng từ này đã được sử dụng!"); } } List <TK> listOrigin = BusinessProvider.GetListChiTietChungTuByIdChungTu(ChungTuInfo.IdChungTu); if (!IsKeToan && listOrigin.Count == 0) { throw new Exception("Nghiệp vụ này không làm phát sinh nội dung chứng từ"); } ListChiTietChungTu.Sort( delegate(TK cthh1, TK cthh2) { return(ToBaseInfo(cthh1).IdSanPham.CompareTo(ToBaseInfo(cthh2).IdSanPham)); }); SaveChiTietChungTu(listOrigin, ListChiTietChungTu); if (ChungTuInfo.IdKho == 0) { return; } ((BusinessProviderBase)BusinessProvider).ChungTuSyncPushORC(this); } catch (Exception ex) { ChungTuInfo.IdChungTu = backupChungTu; ListChiTietChungTu.Clear(); ListChiTietChungTu.AddRange(arrBackupChiTietChungTu); var description = String.Empty; ListChiTietChungTu.ForEach(delegate(TK ctct) { description += ToBaseInfo(ctct).IdSanPham + " " + ToBaseInfo(ctct).SoLuong + "\r\n"; }); description += ex.ToString(); EventLogProvider.Instance.WriteOfflineLog(String.Format("{0}\r\n{1}", ChungTuInfo.SoChungTu, description), "Loi luu chung tu"); throw; } }