summaryrefslogtreecommitdiff
path: root/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorParcelaRepository.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorParcelaRepository.cs')
-rw-r--r--Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorParcelaRepository.cs474
1 files changed, 0 insertions, 474 deletions
diff --git a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorParcelaRepository.cs b/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorParcelaRepository.cs
deleted file mode 100644
index e765212..0000000
--- a/Gestor.Infrastructure/Gestor.Infrastructure.Repository.Logic/VendedorParcelaRepository.cs
+++ /dev/null
@@ -1,474 +0,0 @@
-using AutoMapper;
-using Gestor.Infrastructure.Entities.Generic;
-using Gestor.Infrastructure.Entities.Seguros;
-using Gestor.Infrastructure.Helpers;
-using Gestor.Infrastructure.Mappers;
-using Gestor.Infrastructure.Repository.Generic;
-using Gestor.Infrastructure.Repository.Interface;
-using Gestor.Infrastructure.UnitOfWork.Generic;
-using Gestor.Model.Common;
-using Gestor.Model.Domain.Ferramentas;
-using Gestor.Model.Domain.Generic;
-using Gestor.Model.Domain.Relatorios;
-using Gestor.Model.Domain.Seguros;
-using NHibernate;
-using NHibernate.Connection;
-using NHibernate.Impl;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Data.Common;
-using System.Data.SqlClient;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Runtime.CompilerServices;
-
-namespace Gestor.Infrastructure.Repository.Logic
-{
- public class VendedorParcelaRepository : GenericRepository<VendedorParcelaDb>, IVendedorParcelaRepository, IGenericRepository<VendedorParcelaDb>
- {
- private readonly GenericUnitOfWork _unitOfWork;
-
- public VendedorParcelaRepository(GenericUnitOfWork unitOfWork) : base(unitOfWork.Session)
- {
- this._unitOfWork = unitOfWork;
- }
-
- public List<VendedorParcela> AddRange(List<VendedorParcela> repasses)
- {
- List<VendedorParcelaDb> vendedorParcelaDbs = ApplicationMapper.Mapper.Map<List<VendedorParcela>, List<VendedorParcelaDb>>(repasses);
- base.AddRange(vendedorParcelaDbs);
- return ApplicationMapper.Mapper.Map<List<VendedorParcelaDb>, List<VendedorParcela>>(vendedorParcelaDbs);
- }
-
- public Vendedor BuscarVendedorPorControle(long id)
- {
- Vendedor vendedor;
- object connection;
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
- {
- Auxiliar.CriarVendedor(sqlCommand, false);
- sqlCommand.CommandText = string.Format("SELECT TOP 1 idvendedor as id FROM vendedorparcela vp INNER JOIN parcela p on p.idparcela = vp.idparcela INNER JOIN documento d on d.iddocumento = vp.iddocumento WHERE vp.idtipovendedor = 1 AND p.idsubtipo = 1 AND d.idcontrole = {0};", id);
- SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
- if (sqlDataReader.HasRows)
- {
- sqlDataReader.Read();
- long num = (sqlDataReader["id"] == null ? (long)0 : long.Parse(sqlDataReader["id"].ToString()));
- sqlDataReader.Close();
- return Auxiliar.Vendedores.FirstOrDefault<Vendedor>((Vendedor x) => {
- if (x == null)
- {
- return false;
- }
- return x.Id == num;
- });
- }
- else
- {
- vendedor = null;
- }
- }
- }
- return vendedor;
- }
-
- public bool Delete(long id)
- {
- VendedorParcelaDb vendedorParcelaDb = base.FindEntityById(id);
- if (vendedorParcelaDb == null)
- {
- return true;
- }
- base.Delete(vendedorParcelaDb);
- return true;
- }
-
- public void DeleteRange(long id)
- {
- List<VendedorParcelaDb> list = (
- from vp in base.All()
- where vp.Documento.Id == id && (int)vp.Parcela.SubTipo == 1
- select vp).ToList<VendedorParcelaDb>();
- if (list.Count == 0)
- {
- return;
- }
- VendedorParcelaRepository vendedorParcelaRepository = this;
- list.ForEach(new Action<VendedorParcelaDb>(vendedorParcelaRepository.Delete));
- }
-
- public void DeleteRange(List<VendedorParcela> repasses)
- {
- List<long> list = (
- from y in repasses
- select y.Id).ToList<long>();
- List<VendedorParcelaDb> vendedorParcelaDbs = (
- from x in base.All()
- where list.Contains(x.Id)
- select x).ToList<VendedorParcelaDb>();
- if (vendedorParcelaDbs.Count == 0)
- {
- return;
- }
- VendedorParcelaRepository vendedorParcelaRepository = this;
- vendedorParcelaDbs.ForEach(new Action<VendedorParcelaDb>(vendedorParcelaRepository.Delete));
- }
-
- public List<ManutencaoPagamentos> FindByDate(Filtros filtro)
- {
- List<ManutencaoPagamentos> manutencaoPagamentos;
- object connection;
- DataTable dataTable = new DataTable();
- string str = (filtro.Referencia == "DATA PAGAMENTO" ? "CAST(vp.datapgt AS DATE)" : "CAST(vp.dataprepagto AS DATE)");
- List<Condicao> condicaos = new List<Condicao>()
- {
- new Condicao()
- {
- Campo = "vp.datapgt",
- Valores = null,
- Operador = Operador.Diferente,
- Operacao = Operacao.And
- },
- new Condicao()
- {
- Campo = str,
- Valores = filtro.Inicio.CriarValor<DateTime>(),
- Operador = Operador.MaiorEIgual
- },
- new Condicao()
- {
- Campo = str,
- Valores = filtro.Fim.CriarValor<DateTime>(),
- Operador = Operador.MenorEIgual
- }
- };
- if (filtro.Vendedores != null && filtro.Vendedores.Any<long>())
- {
- condicaos.Add(new Condicao()
- {
- Campo = "vp.idvendedor",
- Valores = filtro.Vendedores.CriarValor<long>()
- });
- }
- if (filtro.IdEmpresa > (long)0)
- {
- condicaos.Add(new Condicao()
- {
- Campo = "c.idempresa",
- Valores = filtro.IdEmpresa.CriarValor<long>()
- });
- }
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- if (sqlConnection != null)
- {
- using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
- {
- Auxiliar.CriarAuxiliar(sqlCommand, false);
- string str1 = "SELECT p.idparcela, vp.idvendedorparcela as idvendedorparcela, vp.iddocumento as iddocumento, c.idciaseg as idseguradora, cl.nome as nomecliente, c.idramo, d.contrato as apolice, d.aditamento as endosso, v.nome as nomevendedor, p.parcela as numeroparcela, p.valor as valor, p.datarec as datarecebimento, vp.datapgt as datapagamento, vp.dataprepagto as dataprepagamento, p.idsubtipo, c.idempresa, vp.vlrrep, c.idproduto FROM vendedorparcela vp INNER JOIN documento d on d.iddocumento = vp.iddocumento INNER JOIN controle c on c.idcontrole = d.idcontrole INNER JOIN vendedor v on v.idvendedor = vp.idvendedor INNER JOIN parcela p on p.idparcela = vp.idparcela INNER JOIN cliente cl on cl.idcliente = c.idcliente WHERE ";
- dataTable = sqlCommand.Select(condicaos.CreateParameters(0), str1, "");
- return dataTable.MapManutencao();
- }
- }
- else
- {
- manutencaoPagamentos = null;
- }
- }
- return manutencaoPagamentos;
- }
-
- public List<VendedorParcela> FindByDocumentId(long documentId)
- {
- return this.Select(string.Format(" AND vp.iddocumento = {0}", documentId));
- }
-
- public VendedorParcela FindById(long id)
- {
- VendedorParcelaDb vendedorParcelaDb = base.FindEntityById(id);
- return ApplicationMapper.Mapper.Map<VendedorParcelaDb, VendedorParcela>(vendedorParcelaDb);
- }
-
- public Vendedor FindByMainDocumentId(long id)
- {
- Vendedor vendedor;
- object connection;
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
- {
- Auxiliar.CriarVendedor(sqlCommand, false);
- sqlCommand.CommandText = string.Format("SELECT TOP 1 idvendedor as id FROM vendedorparcela vp INNER JOIN parcela p on p.idparcela = vp.idparcela WHERE vp.idtipovendedor = 1 AND p.idsubtipo = 1 AND vp.iddocumento = {0};", id);
- SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
- if (sqlDataReader.HasRows)
- {
- sqlDataReader.Read();
- long num = (sqlDataReader["id"] == null ? (long)0 : long.Parse(sqlDataReader["id"].ToString()));
- sqlDataReader.Close();
- return Auxiliar.Vendedores.FirstOrDefault<Vendedor>((Vendedor x) => {
- if (x == null)
- {
- return false;
- }
- return x.Id == num;
- });
- }
- else
- {
- vendedor = null;
- }
- }
- }
- return vendedor;
- }
-
- public List<VendedorParcela> FindByParcela(long id)
- {
- return this.Select(string.Format(" AND vp.idparcela = {0}", id));
- }
-
- public List<Vendedor> FindVendedoresByDocumentId(long documentId)
- {
- object connection;
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- DataTable dataTable = new DataTable();
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
- {
- Auxiliar.CriarVendedor(sqlCommand, false);
- sqlCommand.CommandText = string.Format("SELECT DISTINCT idvendedor as id FROM vendedorparcela WHERE iddocumento = {0}", documentId);
- using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
- {
- sqlDataAdapter.SelectCommand = sqlCommand;
- sqlDataAdapter.Fill(dataTable);
- }
- }
- }
- return Auxiliar.Vendedores.Where<Vendedor>((Vendedor x) => {
- List<DataRow> list = dataTable.AsEnumerable().ToList<DataRow>();
- Func<DataRow, long> u003cu003e9_181 = VendedorParcelaRepository.u003cu003ec.u003cu003e9__18_1;
- if (u003cu003e9_181 == null)
- {
- u003cu003e9_181 = (DataRow v) => v.Field<long>("id");
- VendedorParcelaRepository.u003cu003ec.u003cu003e9__18_1 = u003cu003e9_181;
- }
- return list.Select<DataRow, long>(u003cu003e9_181).Contains<long>(x.Id);
- }).ToList<Vendedor>();
- }
-
- public List<Vendedor> FindVinculoByIdCliente(long idcliente)
- {
- object connection;
- SqlCommand sqlCommand;
- List<long> list;
- List<Condicao> condicaos = new List<Condicao>();
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- condicaos.Add(new Condicao()
- {
- Campo = "cl.idcliente",
- Valores = idcliente.CriarValor<long>()
- });
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- if (sqlConnection != null)
- {
- sqlCommand = sqlConnection.CreateCommand();
- }
- else
- {
- sqlCommand = null;
- }
- using (SqlCommand sqlCommand1 = sqlCommand)
- {
- Auxiliar.CriarAuxiliar(sqlCommand1, false);
- string str = "SELECT DISTINCT vp.idvendedor idvendedor FROM vendedorparcela vp LEFT JOIN documento d ON vp.iddocumento = d.iddocumento LEFT JOIN controle c ON c.idcontrole = d.idcontrole LEFT JOIN cliente cl on cl.idcliente = c.idcliente WHERE";
- DataTable dataTable = sqlCommand1.Select(condicaos.CreateParameters(0), str, "");
- list = dataTable.AsEnumerable().Select<DataRow, long>((DataRow column) => column.Field<long>("idvendedor")).ToList<long>();
- }
- }
- return (
- from v in Auxiliar.Vendedores
- where list.Contains(v.Id)
- select v).ToList<Vendedor>();
- }
-
- public bool GerarPagamento(List<long> ids, DateTime data)
- {
- bool flag;
- object connection;
- try
- {
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- if (sqlConnection != null)
- {
- SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
- using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
- {
- sqlCommand.CommandTimeout = 15000;
- sqlCommand.Transaction = sqlTransaction;
- List<long> nums = ids;
- while (nums.Count > 0)
- {
- List<long> list = nums.Take<long>(1000).ToList<long>();
- List<Condicao> condicaos = new List<Condicao>()
- {
- new Condicao()
- {
- Campo = "idvendedorparcela",
- Valores = list.CriarValor<long>()
- },
- new Condicao()
- {
- Campo = "datapgt",
- Valores = null
- }
- };
- List<SqlParameter> sqlParameters = new List<SqlParameter>()
- {
- new SqlParameter()
- {
- ParameterName = "@datapgt",
- SqlDbType = Funcoes.GetDbType(typeof(DateTime)),
- Value = data
- }
- };
- if (sqlCommand.Update(condicaos.CreateParameters(0), "UPDATE vendedorparcela SET datapgt = @datapgt WHERE ", sqlParameters))
- {
- nums = (list.Count < 1000 ? new List<long>() : nums.Except<long>(list).ToList<long>());
- }
- else
- {
- flag = false;
- return flag;
- }
- }
- sqlTransaction.Commit();
- sqlCommand.Dispose();
- }
- }
- else
- {
- flag = false;
- return flag;
- }
- }
- return true;
- }
- catch (Exception exception)
- {
- flag = false;
- }
- return flag;
- }
-
- public VendedorParcela Merge(VendedorParcela vendedorParcela)
- {
- VendedorParcelaDb vendedorParcelaDb = ApplicationMapper.Mapper.Map<VendedorParcela, VendedorParcelaDb>(vendedorParcela);
- base.Merge(vendedorParcelaDb);
- return ApplicationMapper.Mapper.Map<VendedorParcelaDb, VendedorParcela>(vendedorParcelaDb);
- }
-
- public VendedorParcela SaveOrUpdate(VendedorParcela vendedorParcela)
- {
- VendedorParcelaDb vendedorParcelaDb = ApplicationMapper.Mapper.Map<VendedorParcela, VendedorParcelaDb>(vendedorParcela);
- this.SaveOrUpdate(vendedorParcelaDb);
- return ApplicationMapper.Mapper.Map<VendedorParcelaDb, VendedorParcela>(vendedorParcelaDb);
- }
-
- public List<VendedorParcela> Select(string condition)
- {
- object connection;
- SessionFactoryImpl sessionFactory = this._unitOfWork.Session.SessionFactory as SessionFactoryImpl;
- DataTable dataTable = new DataTable();
- if (sessionFactory != null)
- {
- connection = sessionFactory.ConnectionProvider.GetConnection();
- }
- else
- {
- connection = null;
- }
- using (SqlConnection sqlConnection = connection as SqlConnection)
- {
- using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
- {
- Auxiliar.CriarVendedor(sqlCommand, true);
- sqlCommand.CommandText = string.Concat("SELECT DISTINCT * FROM vendedorparcela vp INNER JOIN parcela p on p.idparcela = vp.idparcela WHERE 1=1 ", condition);
- using (SqlDataAdapter sqlDataAdapter = new SqlDataAdapter())
- {
- sqlDataAdapter.SelectCommand = sqlCommand;
- sqlDataAdapter.Fill(dataTable);
- }
- }
- }
- return CustomMap.MapVendedorParcela(dataTable);
- }
-
- public bool TemPagamentoParcela(long id)
- {
- return base.All().Any<VendedorParcelaDb>((VendedorParcelaDb x) => x.Parcela.Id == id && (x.DataPagamento != null) && (int?)x.Repasse.Forma == (int?)FormaRepasse.Recebimento);
- }
-
- public bool TipoVendedorUtilizado(long id)
- {
- return base.All().Any<VendedorParcelaDb>((VendedorParcelaDb x) => x.TipoVendedor.Id == id);
- }
- }
-} \ No newline at end of file