public static int CancelaItemVenda(int pItem) { try { int Resultado = -1; using (ISession Session = NHibernateHelper.GetSessionFactory().OpenSession()) { NHibernateDAL <NfeDetalheDTO> DALDetalhe = new NHibernateDAL <NfeDetalheDTO>(Session); NfeDetalheDTO Detalhe = DALDetalhe.SelectObjeto <NfeDetalheDTO>( new NfeDetalheDTO { NumeroItem = pItem, IdNfeCabecalho = Sessao.Instance.VendaAtual.Id } ); if (Detalhe != null) { // Se o item existe na base, exclui o imposto e o item NfeDetalheImpostoIcmsDTO Icms = new NfeDetalheImpostoIcmsDTO(); Icms.IdNfeDetalhe = Detalhe.Id; NHibernateDAL <NfeDetalheImpostoIcmsDTO> DALIcms = new NHibernateDAL <NfeDetalheImpostoIcmsDTO>(Session); DALIcms.Delete(Icms); DALDetalhe.Delete(Detalhe); Session.Flush(); Resultado = 0; } } return(Resultado); } catch (Exception ex) { throw new Exception(ex.Message + (ex.InnerException != null ? " " + ex.InnerException.Message : "")); } }