25/05/2026 - Modificando interface do sistema
This commit is contained in:
parent
8251c6e38b
commit
079532bf61
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using DALL;
|
||||
using DAL;
|
||||
using MLL;
|
||||
|
||||
namespace BLL
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using DALL;
|
||||
using DAL;
|
||||
using MLL;
|
||||
|
||||
namespace BLL
|
||||
|
||||
@ -1,39 +1,40 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using DAL;
|
||||
using DALL;
|
||||
using MLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
public class BLLClientes
|
||||
{
|
||||
private DALClientes dal;
|
||||
private readonly DALClientes dal;
|
||||
|
||||
public BLLClientes(string conexao)
|
||||
{
|
||||
dal = new DALClientes(conexao);
|
||||
}
|
||||
|
||||
#region INSERT
|
||||
#region CRUD
|
||||
|
||||
public bool Inserir(ModeloCliente c)
|
||||
{
|
||||
string erro = Validar(c);
|
||||
|
||||
if (!string.IsNullOrEmpty(erro))
|
||||
if (!string.IsNullOrWhiteSpace(erro))
|
||||
throw new Exception(erro);
|
||||
|
||||
// 🔥 evita duplicidade (Documento + Empresa)
|
||||
var existente = CarregarPorDocumento(c.EmpresaId, c.Documento);
|
||||
ModeloCliente? existente =
|
||||
CarregarPorDocumento(c.EmpresaId, c.Documento);
|
||||
|
||||
if (existente != null)
|
||||
throw new Exception("Já existe um cliente com esse documento.");
|
||||
|
||||
return dal.Inserir(c);
|
||||
}//Inserir
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region UPDATE
|
||||
public bool Alterar(ModeloCliente c)
|
||||
{
|
||||
if (c.Id <= 0)
|
||||
@ -41,45 +42,46 @@ namespace BLL
|
||||
|
||||
string erro = Validar(c);
|
||||
|
||||
if (!string.IsNullOrEmpty(erro))
|
||||
if (!string.IsNullOrWhiteSpace(erro))
|
||||
throw new Exception(erro);
|
||||
|
||||
var existente = CarregarPorDocumento(c.EmpresaId, c.Documento);
|
||||
ModeloCliente? existente =
|
||||
CarregarPorDocumento(c.EmpresaId, c.Documento);
|
||||
|
||||
if (existente != null && existente.Id != c.Id)
|
||||
throw new Exception("Já existe outro cliente com esse documento.");
|
||||
|
||||
return dal.Alterar(c);
|
||||
}//Alterar
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region DELETE
|
||||
public bool Excluir(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
throw new Exception("ID inválido.");
|
||||
|
||||
return dal.Excluir(id);
|
||||
}//Excluir
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region SELECT
|
||||
public ModeloCliente Carregar(int id)
|
||||
public ModeloCliente? Carregar(int id)
|
||||
{
|
||||
if (id <= 0)
|
||||
return null;
|
||||
|
||||
return dal.Carregar(id);
|
||||
}//Carregar
|
||||
}
|
||||
|
||||
public List<ModeloCliente> Listar()
|
||||
{
|
||||
return dal.Listar();
|
||||
}//Listar
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BUSCA POR DOCUMENTO
|
||||
public ModeloCliente CarregarPorDocumento(int empresaId, string documento)
|
||||
#region BUSCAS
|
||||
|
||||
public ModeloCliente? CarregarPorDocumento(
|
||||
int empresaId,
|
||||
string documento)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(documento))
|
||||
return null;
|
||||
@ -91,10 +93,163 @@ namespace BLL
|
||||
x.EmpresaId == empresaId &&
|
||||
LimparNumeros(x.Documento) == documento);
|
||||
}
|
||||
|
||||
public List<ModeloCliente> BuscarPorNome(string nome)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(nome))
|
||||
return [];
|
||||
|
||||
return dal.Listar()
|
||||
.Where(x =>
|
||||
x.Nome.Contains(
|
||||
nome,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> BuscarPorCidade(string cidade)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cidade))
|
||||
return [];
|
||||
|
||||
return dal.Listar()
|
||||
.Where(x =>
|
||||
!string.IsNullOrWhiteSpace(x.Cidade) &&
|
||||
x.Cidade.Contains(
|
||||
cidade,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> BuscarPorTelefone(string telefone)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(telefone))
|
||||
return [];
|
||||
|
||||
telefone = LimparNumeros(telefone);
|
||||
|
||||
return dal.Listar()
|
||||
.Where(x =>
|
||||
LimparNumeros(x.Telefone1).Contains(telefone) ||
|
||||
LimparNumeros(x.Telefone2).Contains(telefone) ||
|
||||
LimparNumeros(x.Celular).Contains(telefone) ||
|
||||
LimparNumeros(x.Whatsapp).Contains(telefone))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VIEWS
|
||||
|
||||
public List<ModeloCliente> ListarTodos()
|
||||
{
|
||||
return dal.ListarTodos();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarAtivos()
|
||||
{
|
||||
return dal.ListarAtivos();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarInativos()
|
||||
{
|
||||
return dal.ListarInativos();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarBloqueados()
|
||||
{
|
||||
return dal.ListarBloqueados();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarComLimite()
|
||||
{
|
||||
return dal.ListarComLimite();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarSemLimite()
|
||||
{
|
||||
return dal.ListarSemLimite();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarPF()
|
||||
{
|
||||
return dal.ListarPF();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarPJ()
|
||||
{
|
||||
return dal.ListarPJ();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarWhatsapp()
|
||||
{
|
||||
return dal.ListarWhatsapp();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarEmail()
|
||||
{
|
||||
return dal.ListarEmail();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarEmailNFe()
|
||||
{
|
||||
return dal.ListarEmailNFe();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarCripto()
|
||||
{
|
||||
return dal.ListarCripto();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarUltimaCompra()
|
||||
{
|
||||
return dal.ListarUltimaCompra();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarSemCompra()
|
||||
{
|
||||
return dal.ListarSemCompra();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarRecentes()
|
||||
{
|
||||
return dal.ListarRecentes();
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarCobranca()
|
||||
{
|
||||
return dal.ListarCobranca();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DASHBOARD
|
||||
|
||||
public DataTable ObterClientesPorCidade()
|
||||
{
|
||||
return dal.ObterClientesPorCidade();
|
||||
}
|
||||
|
||||
public DataTable ObterClientesPorGrupo()
|
||||
{
|
||||
return dal.ObterClientesPorGrupo();
|
||||
}
|
||||
|
||||
public DataTable ObterDashboard()
|
||||
{
|
||||
return dal.ObterDashboard();
|
||||
}
|
||||
|
||||
public DataTable ObterClientesCompleto()
|
||||
{
|
||||
return dal.ObterClientesCompleto();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VALIDAÇÃO
|
||||
private string Validar(ModeloCliente c)
|
||||
|
||||
private string? Validar(ModeloCliente c)
|
||||
{
|
||||
if (c == null)
|
||||
return "Objeto cliente inválido.";
|
||||
@ -111,22 +266,27 @@ namespace BLL
|
||||
if (string.IsNullOrWhiteSpace(c.Documento))
|
||||
return "Documento é obrigatório.";
|
||||
|
||||
// 🔥 limpa CPF/CNPJ
|
||||
c.Documento = LimparNumeros(c.Documento);
|
||||
|
||||
if (c.TipoPessoa == "PF" && c.Documento.Length != 11)
|
||||
if (c.TipoPessoa == "PF" &&
|
||||
c.Documento.Length != 11)
|
||||
{
|
||||
return "CPF inválido.";
|
||||
}
|
||||
|
||||
if (c.TipoPessoa == "PJ" && c.Documento.Length != 14)
|
||||
if (c.TipoPessoa == "PJ" &&
|
||||
c.Documento.Length != 14)
|
||||
{
|
||||
return "CNPJ inválido.";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(c.Email))
|
||||
if (!string.IsNullOrWhiteSpace(c.Email))
|
||||
{
|
||||
if (!c.Email.Contains("@"))
|
||||
return "Email inválido.";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(c.UF))
|
||||
if (!string.IsNullOrWhiteSpace(c.UF))
|
||||
{
|
||||
if (c.UF.Length != 2)
|
||||
return "UF inválida.";
|
||||
@ -134,16 +294,20 @@ namespace BLL
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AUX
|
||||
private string LimparNumeros(string texto)
|
||||
#region AUXILIARES
|
||||
|
||||
private string LimparNumeros(string? texto)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(texto))
|
||||
return texto;
|
||||
return string.Empty;
|
||||
|
||||
return new string(texto.Where(char.IsDigit).ToArray());
|
||||
return new string(
|
||||
texto.Where(char.IsDigit).ToArray());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using DALL;
|
||||
using DAL;
|
||||
using MLL;
|
||||
|
||||
namespace BLL
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using DALL;
|
||||
using DAL;
|
||||
using MLL;
|
||||
|
||||
namespace BLL
|
||||
|
||||
17
CCH/AppConectionSystem.cs
Normal file
17
CCH/AppConectionSystem.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CCH
|
||||
{
|
||||
public static class AppConectionSystem
|
||||
{
|
||||
public static string ConnectionStringDB { get; private set; }
|
||||
public static void Inicializar(string connectionString)
|
||||
{
|
||||
ConnectionStringDB = connectionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,7 @@ namespace CCH
|
||||
|
||||
|
||||
|
||||
|
||||
//Public
|
||||
public static string AppFileIconSystem => appFileIconSystem;
|
||||
public static string AppFileDBSystem => appFileDBSystem;
|
||||
|
||||
@ -19,6 +19,7 @@ namespace CCH
|
||||
|
||||
public static string AppKeyMasterCrip => appKeyMasterCrip;
|
||||
|
||||
public static string? conectionString;
|
||||
private static string GerarChaveMaquina()
|
||||
{
|
||||
string baseInfo = Environment.MachineName + Environment.UserName;
|
||||
|
||||
@ -4,7 +4,7 @@ using System.Data.SqlClient;
|
||||
using MLL;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALAgenda
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALBancos
|
||||
{
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALClientes
|
||||
{
|
||||
@ -16,173 +16,440 @@ namespace DALL
|
||||
}
|
||||
|
||||
#region INSERT
|
||||
|
||||
public bool Inserir(ModeloCliente c)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection conn = new SqlConnection(_conexao))
|
||||
{
|
||||
string sql = @"INSERT INTO Clientes
|
||||
(EmpresaId, Nome, NomeFantasia, TipoPessoa, Documento, RG, InscricaoMunicipal,
|
||||
DataNascimento, Contato, Telefone1, Telefone2, Celular, Whatsapp, Email, EmailNFe,
|
||||
Site, Grupo, Cep, Endereco, Numero, Complemento, Bairro, Cidade, UF, Pais,
|
||||
LimiteCredito, Bloqueado, ObservacoesCobranca, VendedorPadraoId, TipoConsumidor,
|
||||
Observacoes, CampoExtra1, CampoExtra2, CampoExtra3,
|
||||
Bitcoin, Ethereum, Litecoin, Ativo, UltimaCompra)
|
||||
VALUES
|
||||
(@EmpresaId, @Nome, @NomeFantasia, @TipoPessoa, @Documento, @RG, @InscricaoMunicipal,
|
||||
@DataNascimento, @Contato, @Telefone1, @Telefone2, @Celular, @Whatsapp, @Email, @EmailNFe,
|
||||
@Site, @Grupo, @Cep, @Endereco, @Numero, @Complemento, @Bairro, @Cidade, @UF, @Pais,
|
||||
@LimiteCredito, @Bloqueado, @ObservacoesCobranca, @VendedorPadraoId, @TipoConsumidor,
|
||||
@Observacoes, @CampoExtra1, @CampoExtra2, @CampoExtra3,
|
||||
@Bitcoin, @Ethereum, @Litecoin, @Ativo, @UltimaCompra)";
|
||||
using SqlConnection conn = new(_conexao);
|
||||
|
||||
string sql = @"
|
||||
INSERT INTO Clientes
|
||||
(
|
||||
EmpresaId,
|
||||
Nome,
|
||||
NomeFantasia,
|
||||
TipoPessoa,
|
||||
Documento,
|
||||
RG,
|
||||
InscricaoMunicipal,
|
||||
DataNascimento,
|
||||
Contato,
|
||||
Telefone1,
|
||||
Telefone2,
|
||||
Celular,
|
||||
Whatsapp,
|
||||
Email,
|
||||
EmailNFe,
|
||||
Site,
|
||||
Grupo,
|
||||
Cep,
|
||||
Endereco,
|
||||
Numero,
|
||||
Complemento,
|
||||
Bairro,
|
||||
Cidade,
|
||||
UF,
|
||||
Pais,
|
||||
LimiteCredito,
|
||||
Bloqueado,
|
||||
ObservacoesCobranca,
|
||||
VendedorPadraoId,
|
||||
TipoConsumidor,
|
||||
Observacoes,
|
||||
CampoExtra1,
|
||||
CampoExtra2,
|
||||
CampoExtra3,
|
||||
Bitcoin,
|
||||
Ethereum,
|
||||
Litecoin,
|
||||
Ativo,
|
||||
UltimaCompra
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@EmpresaId,
|
||||
@Nome,
|
||||
@NomeFantasia,
|
||||
@TipoPessoa,
|
||||
@Documento,
|
||||
@RG,
|
||||
@InscricaoMunicipal,
|
||||
@DataNascimento,
|
||||
@Contato,
|
||||
@Telefone1,
|
||||
@Telefone2,
|
||||
@Celular,
|
||||
@Whatsapp,
|
||||
@Email,
|
||||
@EmailNFe,
|
||||
@Site,
|
||||
@Grupo,
|
||||
@Cep,
|
||||
@Endereco,
|
||||
@Numero,
|
||||
@Complemento,
|
||||
@Bairro,
|
||||
@Cidade,
|
||||
@UF,
|
||||
@Pais,
|
||||
@LimiteCredito,
|
||||
@Bloqueado,
|
||||
@ObservacoesCobranca,
|
||||
@VendedorPadraoId,
|
||||
@TipoConsumidor,
|
||||
@Observacoes,
|
||||
@CampoExtra1,
|
||||
@CampoExtra2,
|
||||
@CampoExtra3,
|
||||
@Bitcoin,
|
||||
@Ethereum,
|
||||
@Litecoin,
|
||||
@Ativo,
|
||||
@UltimaCompra
|
||||
)";
|
||||
|
||||
using SqlCommand cmd = new(sql, conn);
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
PreencherParametros(cmd, c);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}//inserir
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UPDATE
|
||||
|
||||
public bool Alterar(ModeloCliente c)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection conn = new SqlConnection(_conexao))
|
||||
{
|
||||
string sql = @"UPDATE Clientes SET
|
||||
Nome=@Nome, NomeFantasia=@NomeFantasia, TipoPessoa=@TipoPessoa,
|
||||
Documento=@Documento, RG=@RG, InscricaoMunicipal=@InscricaoMunicipal,
|
||||
DataNascimento=@DataNascimento, Contato=@Contato,
|
||||
Telefone1=@Telefone1, Telefone2=@Telefone2, Celular=@Celular,
|
||||
Whatsapp=@Whatsapp, Email=@Email, EmailNFe=@EmailNFe,
|
||||
Site=@Site, Grupo=@Grupo, Cep=@Cep, Endereco=@Endereco,
|
||||
Numero=@Numero, Complemento=@Complemento, Bairro=@Bairro,
|
||||
Cidade=@Cidade, UF=@UF, Pais=@Pais,
|
||||
LimiteCredito=@LimiteCredito, Bloqueado=@Bloqueado,
|
||||
using SqlConnection conn = new(_conexao);
|
||||
|
||||
string sql = @"
|
||||
UPDATE Clientes SET
|
||||
|
||||
EmpresaId = @EmpresaId,
|
||||
Nome = @Nome,
|
||||
NomeFantasia = @NomeFantasia,
|
||||
TipoPessoa = @TipoPessoa,
|
||||
Documento = @Documento,
|
||||
RG = @RG,
|
||||
InscricaoMunicipal = @InscricaoMunicipal,
|
||||
DataNascimento = @DataNascimento,
|
||||
Contato = @Contato,
|
||||
Telefone1 = @Telefone1,
|
||||
Telefone2 = @Telefone2,
|
||||
Celular = @Celular,
|
||||
Whatsapp = @Whatsapp,
|
||||
Email = @Email,
|
||||
EmailNFe = @EmailNFe,
|
||||
Site = @Site,
|
||||
Grupo = @Grupo,
|
||||
Cep = @Cep,
|
||||
Endereco = @Endereco,
|
||||
Numero = @Numero,
|
||||
Complemento = @Complemento,
|
||||
Bairro = @Bairro,
|
||||
Cidade = @Cidade,
|
||||
UF = @UF,
|
||||
Pais = @Pais,
|
||||
LimiteCredito = @LimiteCredito,
|
||||
Bloqueado = @Bloqueado,
|
||||
ObservacoesCobranca = @ObservacoesCobranca,
|
||||
VendedorPadraoId = @VendedorPadraoId,
|
||||
TipoConsumidor = @TipoConsumidor,
|
||||
Observacoes = @Observacoes,
|
||||
CampoExtra1=@CampoExtra1, CampoExtra2=@CampoExtra2, CampoExtra3=@CampoExtra3,
|
||||
Bitcoin=@Bitcoin, Ethereum=@Ethereum, Litecoin=@Litecoin,
|
||||
Ativo=@Ativo, UltimaCompra=@UltimaCompra,
|
||||
CampoExtra1 = @CampoExtra1,
|
||||
CampoExtra2 = @CampoExtra2,
|
||||
CampoExtra3 = @CampoExtra3,
|
||||
Bitcoin = @Bitcoin,
|
||||
Ethereum = @Ethereum,
|
||||
Litecoin = @Litecoin,
|
||||
Ativo = @Ativo,
|
||||
UltimaCompra = @UltimaCompra,
|
||||
AtualizadoEm = GETDATE()
|
||||
|
||||
WHERE Id = @Id";
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
using SqlCommand cmd = new(sql, conn);
|
||||
|
||||
PreencherParametros(cmd, c);
|
||||
|
||||
cmd.Parameters.AddWithValue("@Id", c.Id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}//Alterar
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DELETE
|
||||
|
||||
public bool Excluir(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection conn = new SqlConnection(_conexao))
|
||||
{
|
||||
using SqlConnection conn = new(_conexao);
|
||||
|
||||
string sql = "DELETE FROM Clientes WHERE Id = @Id";
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
using SqlCommand cmd = new(sql, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@Id", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}//Excluir
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SELECT POR ID
|
||||
public ModeloCliente Carregar(int id)
|
||||
{
|
||||
ModeloCliente c = null;
|
||||
#region SELECT
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(_conexao))
|
||||
public ModeloCliente? Carregar(int id)
|
||||
{
|
||||
using SqlConnection conn = new(_conexao);
|
||||
|
||||
string sql = "SELECT * FROM Clientes WHERE Id = @Id";
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
using SqlCommand cmd = new(sql, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@Id", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using (SqlDataReader dr = cmd.ExecuteReader())
|
||||
{
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
if (dr.Read())
|
||||
{
|
||||
c = new ModeloCliente();
|
||||
PreencherModelo(c, dr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return PreencherModelo(dr);
|
||||
}
|
||||
|
||||
return c;
|
||||
}//CarregarModelo
|
||||
#endregion
|
||||
return null;
|
||||
}
|
||||
|
||||
#region LISTAR
|
||||
public List<ModeloCliente> Listar()
|
||||
{
|
||||
var lista = new List<ModeloCliente>();
|
||||
return ExecutarViewLista("SELECT * FROM Clientes ORDER BY Nome");
|
||||
}
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(_conexao))
|
||||
{
|
||||
string sql = "SELECT * FROM Clientes ORDER BY Nome";
|
||||
#endregion
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
#region VIEWS
|
||||
|
||||
public List<ModeloCliente> ListarTodos()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_Clientes");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarAtivos()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesAtivos");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarInativos()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesInativos");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarBloqueados()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesBloqueados");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarComLimite()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesComLimite");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarSemLimite()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesSemLimite");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarPF()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesPF");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarPJ()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesPJ");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarWhatsapp()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesWhatsapp");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarEmail()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesEmail");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarEmailNFe()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesEmailNFe");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarCripto()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesCripto");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarUltimaCompra()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesUltimaCompra");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarSemCompra()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesSemCompra");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarRecentes()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesRecentes");
|
||||
}
|
||||
|
||||
public List<ModeloCliente> ListarCobranca()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ClientesCobranca");
|
||||
}
|
||||
|
||||
public DataTable ObterClientesPorCidade()
|
||||
{
|
||||
return ExecutarViewDataTable("SELECT * FROM VW_ClientesCidade");
|
||||
}
|
||||
|
||||
public DataTable ObterClientesPorGrupo()
|
||||
{
|
||||
return ExecutarViewDataTable("SELECT * FROM VW_ClientesGrupo");
|
||||
}
|
||||
|
||||
public DataTable ObterDashboard()
|
||||
{
|
||||
return ExecutarViewDataTable("SELECT * FROM VW_ClientesDashboard");
|
||||
}
|
||||
|
||||
public DataTable ObterClientesCompleto()
|
||||
{
|
||||
return ExecutarViewDataTable("SELECT * FROM VW_ClientesCompleto");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HELPERS
|
||||
|
||||
private List<ModeloCliente> ExecutarViewLista(string query)
|
||||
{
|
||||
List<ModeloCliente> lista = [];
|
||||
|
||||
using SqlConnection conn = new(_conexao);
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using (SqlDataReader dr = cmd.ExecuteReader())
|
||||
{
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
var c = new ModeloCliente();
|
||||
PreencherModelo(c, dr);
|
||||
lista.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
|
||||
return lista;
|
||||
}//Listar Clientes
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region AUX PARAMETROS
|
||||
private void PreencherParametros(SqlCommand cmd, ModeloCliente c)
|
||||
private DataTable ExecutarViewDataTable(string query)
|
||||
{
|
||||
DataTable dt = new();
|
||||
|
||||
using SqlConnection conn = new(_conexao);
|
||||
|
||||
using SqlDataAdapter da = new(query, conn);
|
||||
|
||||
da.Fill(dt);
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
private static ModeloCliente PreencherModelo(SqlDataReader dr)
|
||||
{
|
||||
return new ModeloCliente
|
||||
{
|
||||
Id = Convert.ToInt32(dr["Id"]),
|
||||
EmpresaId = Convert.ToInt32(dr["EmpresaId"]),
|
||||
|
||||
Nome = Convert.ToString(dr["Nome"]) ?? string.Empty,
|
||||
NomeFantasia = Convert.ToString(dr["NomeFantasia"]) ?? string.Empty,
|
||||
TipoPessoa = Convert.ToString(dr["TipoPessoa"]) ?? string.Empty,
|
||||
Documento = Convert.ToString(dr["Documento"]) ?? string.Empty,
|
||||
RG = Convert.ToString(dr["RG"]) ?? string.Empty,
|
||||
InscricaoMunicipal = Convert.ToString(dr["InscricaoMunicipal"]) ?? string.Empty,
|
||||
Contato = Convert.ToString(dr["Contato"]) ?? string.Empty,
|
||||
Telefone1 = Convert.ToString(dr["Telefone1"]) ?? string.Empty,
|
||||
Telefone2 = Convert.ToString(dr["Telefone2"]) ?? string.Empty,
|
||||
Celular = Convert.ToString(dr["Celular"]) ?? string.Empty,
|
||||
Whatsapp = Convert.ToString(dr["Whatsapp"]) ?? string.Empty,
|
||||
Email = Convert.ToString(dr["Email"]) ?? string.Empty,
|
||||
EmailNFe = Convert.ToString(dr["EmailNFe"]) ?? string.Empty,
|
||||
Site = Convert.ToString(dr["Site"]) ?? string.Empty,
|
||||
Grupo = Convert.ToString(dr["Grupo"]) ?? string.Empty,
|
||||
Cep = Convert.ToString(dr["Cep"]) ?? string.Empty,
|
||||
Endereco = Convert.ToString(dr["Endereco"]) ?? string.Empty,
|
||||
Complemento = Convert.ToString(dr["Complemento"]) ?? string.Empty,
|
||||
Bairro = Convert.ToString(dr["Bairro"]) ?? string.Empty,
|
||||
Cidade = Convert.ToString(dr["Cidade"]) ?? string.Empty,
|
||||
UF = Convert.ToString(dr["UF"]) ?? string.Empty,
|
||||
Pais = Convert.ToString(dr["Pais"]) ?? string.Empty,
|
||||
Observacoes = Convert.ToString(dr["Observacoes"]) ?? string.Empty,
|
||||
TipoConsumidor = Convert.ToString(dr["TipoConsumidor"]) ?? string.Empty,
|
||||
|
||||
Numero = dr["Numero"] == DBNull.Value
|
||||
? (int?)null
|
||||
: Convert.ToInt32(dr["Numero"]),
|
||||
|
||||
DataNascimento = dr["DataNascimento"] == DBNull.Value
|
||||
? (DateTime?)null
|
||||
: Convert.ToDateTime(dr["DataNascimento"]),
|
||||
|
||||
LimiteCredito = dr["LimiteCredito"] == DBNull.Value
|
||||
? 0
|
||||
: Convert.ToDecimal(dr["LimiteCredito"]),
|
||||
|
||||
Bloqueado = dr["Bloqueado"] != DBNull.Value &&
|
||||
Convert.ToBoolean(dr["Bloqueado"]),
|
||||
|
||||
Ativo = dr["Ativo"] != DBNull.Value &&
|
||||
Convert.ToBoolean(dr["Ativo"]),
|
||||
|
||||
UltimaCompra = dr["UltimaCompra"] == DBNull.Value
|
||||
? (DateTime?)null
|
||||
: Convert.ToDateTime(dr["UltimaCompra"])
|
||||
};
|
||||
}
|
||||
|
||||
private static void PreencherParametros(SqlCommand cmd, ModeloCliente c)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@EmpresaId", c.EmpresaId);
|
||||
cmd.Parameters.AddWithValue("@Nome", c.Nome);
|
||||
@ -224,54 +491,7 @@ namespace DALL
|
||||
cmd.Parameters.AddWithValue("@Ativo", c.Ativo);
|
||||
cmd.Parameters.AddWithValue("@UltimaCompra", c.UltimaCompra ?? (object)DBNull.Value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AUX MODEL
|
||||
private void PreencherModelo(ModeloCliente c, SqlDataReader dr)
|
||||
{
|
||||
c.Id = Convert.ToInt32(dr["Id"]);
|
||||
c.EmpresaId = Convert.ToInt32(dr["EmpresaId"]);
|
||||
c.Nome = dr["Nome"].ToString();
|
||||
c.NomeFantasia = dr["NomeFantasia"]?.ToString();
|
||||
c.TipoPessoa = dr["TipoPessoa"].ToString();
|
||||
c.Documento = dr["Documento"].ToString();
|
||||
c.RG = dr["RG"]?.ToString();
|
||||
c.InscricaoMunicipal = dr["InscricaoMunicipal"]?.ToString();
|
||||
c.DataNascimento = dr["DataNascimento"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dr["DataNascimento"]);
|
||||
c.Contato = dr["Contato"]?.ToString();
|
||||
c.Telefone1 = dr["Telefone1"]?.ToString();
|
||||
c.Telefone2 = dr["Telefone2"]?.ToString();
|
||||
c.Celular = dr["Celular"]?.ToString();
|
||||
c.Whatsapp = dr["Whatsapp"]?.ToString();
|
||||
c.Email = dr["Email"]?.ToString();
|
||||
c.EmailNFe = dr["EmailNFe"]?.ToString();
|
||||
c.Site = dr["Site"]?.ToString();
|
||||
c.Grupo = dr["Grupo"]?.ToString();
|
||||
c.Cep = dr["Cep"]?.ToString();
|
||||
c.Endereco = dr["Endereco"]?.ToString();
|
||||
c.Numero = dr["Numero"] == DBNull.Value ? null : (int?)Convert.ToInt32(dr["Numero"]);
|
||||
c.Complemento = dr["Complemento"]?.ToString();
|
||||
c.Bairro = dr["Bairro"]?.ToString();
|
||||
c.Cidade = dr["Cidade"]?.ToString();
|
||||
c.UF = dr["UF"]?.ToString();
|
||||
c.Pais = dr["Pais"]?.ToString();
|
||||
c.LimiteCredito = Convert.ToDecimal(dr["LimiteCredito"]);
|
||||
c.Bloqueado = Convert.ToBoolean(dr["Bloqueado"]);
|
||||
c.ObservacoesCobranca = dr["ObservacoesCobranca"]?.ToString();
|
||||
c.VendedorPadraoId = dr["VendedorPadraoId"] == DBNull.Value ? null : (int?)Convert.ToInt32(dr["VendedorPadraoId"]);
|
||||
c.TipoConsumidor = dr["TipoConsumidor"]?.ToString();
|
||||
c.Observacoes = dr["Observacoes"]?.ToString();
|
||||
c.CampoExtra1 = dr["CampoExtra1"]?.ToString();
|
||||
c.CampoExtra2 = dr["CampoExtra2"]?.ToString();
|
||||
c.CampoExtra3 = dr["CampoExtra3"]?.ToString();
|
||||
c.Bitcoin = dr["Bitcoin"]?.ToString();
|
||||
c.Ethereum = dr["Ethereum"]?.ToString();
|
||||
c.Litecoin = dr["Litecoin"]?.ToString();
|
||||
c.Ativo = Convert.ToBoolean(dr["Ativo"]);
|
||||
c.UltimaCompra = dr["UltimaCompra"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dr["UltimaCompra"]);
|
||||
c.CriadoEm = Convert.ToDateTime(dr["CriadoEm"]);
|
||||
c.AtualizadoEm = Convert.ToDateTime(dr["AtualizadoEm"]);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ using System.Data.SqlClient;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MLL;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALEmpresa
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MLL;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALFuncionarios
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLBackupAutomatico
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLBackupExecucao
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
using System.Data;
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLBackupService
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLBancos
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLBoletos
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLCalibracao
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLCalibracaoEnsaio
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLCalibracaoPadrao
|
||||
{
|
||||
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLCalibracaoPadraoEnsaios
|
||||
{
|
||||
|
||||
298
DAL/DALLCartoes.cs
Normal file
298
DAL/DALLCartoes.cs
Normal file
@ -0,0 +1,298 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLCartoes
|
||||
{
|
||||
private readonly string connectionString;
|
||||
|
||||
public DALLCartoes(string connectionString)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
}
|
||||
|
||||
#region CRUD
|
||||
|
||||
public bool Inserir(ModeloCartoes modelo)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
INSERT INTO Cartoes
|
||||
(
|
||||
BANDEIRA,
|
||||
NUM_CARTAO,
|
||||
NOME,
|
||||
VALIDADE,
|
||||
AUTORIZACAO,
|
||||
PARCELAS,
|
||||
VALOR,
|
||||
COD_CLIENTE,
|
||||
RESUMO,
|
||||
DEBITO,
|
||||
COD_CONTA,
|
||||
DIA,
|
||||
COMPENSADO,
|
||||
OBS_COMP
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@BANDEIRA,
|
||||
@NUM_CARTAO,
|
||||
@NOME,
|
||||
@VALIDADE,
|
||||
@AUTORIZACAO,
|
||||
@PARCELAS,
|
||||
@VALOR,
|
||||
@COD_CLIENTE,
|
||||
@RESUMO,
|
||||
@DEBITO,
|
||||
@COD_CONTA,
|
||||
@DIA,
|
||||
@COMPENSADO,
|
||||
@OBS_COMP
|
||||
)";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
PreencherParametrosInserir(cmd, modelo);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
|
||||
public bool Alterar(ModeloCartoes modelo)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
UPDATE Cartoes
|
||||
SET
|
||||
CODIGO = @CODIGO,
|
||||
BANDEIRA = @BANDEIRA,
|
||||
NUM_CARTAO = @NUM_CARTAO,
|
||||
NOME = @NOME,
|
||||
VALIDADE = @VALIDADE,
|
||||
AUTORIZACAO = @AUTORIZACAO,
|
||||
PARCELAS = @PARCELAS,
|
||||
VALOR = @VALOR,
|
||||
COD_CLIENTE = @COD_CLIENTE,
|
||||
RESUMO = @RESUMO,
|
||||
DEBITO = @DEBITO,
|
||||
COD_CONTA = @COD_CONTA,
|
||||
DIA = @DIA,
|
||||
COMPENSADO = @COMPENSADO,
|
||||
OBS_COMP = @OBS_COMP
|
||||
WHERE ID_COD_CARTAO = @ID_COD_CARTAO";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
PreencherParametrosAlterar(cmd, modelo);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_COD_CARTAO", modelo.ID_COD_CARTAO);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
|
||||
public bool Excluir(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
DELETE FROM Cartoes
|
||||
WHERE ID_COD_CARTAO = @ID_COD_CARTAO";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_COD_CARTAO", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
|
||||
public ModeloCartoes? ObterPorId(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Cartoes
|
||||
WHERE ID_COD_CARTAO = @ID_COD_CARTAO";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_COD_CARTAO", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
if (dr.Read())
|
||||
{
|
||||
return PreencherModelo(dr);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ModeloCartoes> Listar()
|
||||
{
|
||||
List<ModeloCartoes> lista = [];
|
||||
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Cartoes
|
||||
ORDER BY ID_COD_CARTAO DESC";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HELPERS
|
||||
|
||||
private static ModeloCartoes PreencherModelo(SqlDataReader dr)
|
||||
{
|
||||
return new ModeloCartoes
|
||||
{
|
||||
ID_COD_CARTAO = Convert.ToInt32(dr["ID_COD_CARTAO"]),
|
||||
|
||||
CODIGO = Convert.ToString(dr["CODIGO"]) ?? string.Empty,
|
||||
|
||||
BANDEIRA = Convert.ToString(dr["BANDEIRA"]) ?? string.Empty,
|
||||
|
||||
NUM_CARTAO = Convert.ToString(dr["NUM_CARTAO"]) ?? string.Empty,
|
||||
|
||||
NOME = Convert.ToString(dr["NOME"]) ?? string.Empty,
|
||||
|
||||
VALIDADE = Convert.ToString(dr["VALIDADE"]) ?? string.Empty,
|
||||
|
||||
AUTORIZACAO = Convert.ToString(dr["AUTORIZACAO"]) ?? string.Empty,
|
||||
|
||||
PARCELAS = Convert.ToString(dr["PARCELAS"]) ?? string.Empty,
|
||||
|
||||
VALOR = Convert.ToString(dr["VALOR"]) ?? string.Empty,
|
||||
|
||||
COD_CLIENTE = Convert.ToString(dr["COD_CLIENTE"]) ?? string.Empty,
|
||||
|
||||
RESUMO = Convert.ToString(dr["RESUMO"]) ?? string.Empty,
|
||||
|
||||
DEBITO = Convert.ToString(dr["DEBITO"]) ?? string.Empty,
|
||||
|
||||
COD_CONTA = Convert.ToString(dr["COD_CONTA"]) ?? string.Empty,
|
||||
|
||||
DIA = Convert.ToString(dr["DIA"]) ?? string.Empty,
|
||||
|
||||
COMPENSADO = Convert.ToString(dr["COMPENSADO"]) ?? string.Empty,
|
||||
|
||||
OBS_COMP = Convert.ToString(dr["OBS_COMP"]) ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
private static void PreencherParametrosInserir(SqlCommand cmd, ModeloCartoes modelo)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@BANDEIRA",
|
||||
string.IsNullOrWhiteSpace(modelo.BANDEIRA)
|
||||
? DBNull.Value
|
||||
: modelo.BANDEIRA);
|
||||
|
||||
cmd.Parameters.AddWithValue("@NUM_CARTAO",
|
||||
string.IsNullOrWhiteSpace(modelo.NUM_CARTAO)
|
||||
? DBNull.Value
|
||||
: modelo.NUM_CARTAO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@NOME",
|
||||
string.IsNullOrWhiteSpace(modelo.NOME)
|
||||
? DBNull.Value
|
||||
: modelo.NOME);
|
||||
|
||||
cmd.Parameters.AddWithValue("@VALIDADE",
|
||||
string.IsNullOrWhiteSpace(modelo.VALIDADE)
|
||||
? DBNull.Value
|
||||
: modelo.VALIDADE);
|
||||
|
||||
cmd.Parameters.AddWithValue("@AUTORIZACAO",
|
||||
string.IsNullOrWhiteSpace(modelo.AUTORIZACAO)
|
||||
? DBNull.Value
|
||||
: modelo.AUTORIZACAO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@PARCELAS",
|
||||
string.IsNullOrWhiteSpace(modelo.PARCELAS)
|
||||
? DBNull.Value
|
||||
: modelo.PARCELAS);
|
||||
|
||||
cmd.Parameters.AddWithValue("@VALOR",
|
||||
string.IsNullOrWhiteSpace(modelo.VALOR)
|
||||
? DBNull.Value
|
||||
: modelo.VALOR);
|
||||
|
||||
cmd.Parameters.AddWithValue("@COD_CLIENTE",
|
||||
string.IsNullOrWhiteSpace(modelo.COD_CLIENTE)
|
||||
? DBNull.Value
|
||||
: modelo.COD_CLIENTE);
|
||||
|
||||
cmd.Parameters.AddWithValue("@RESUMO",
|
||||
string.IsNullOrWhiteSpace(modelo.RESUMO)
|
||||
? DBNull.Value
|
||||
: modelo.RESUMO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@DEBITO",
|
||||
string.IsNullOrWhiteSpace(modelo.DEBITO)
|
||||
? DBNull.Value
|
||||
: modelo.DEBITO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@COD_CONTA",
|
||||
string.IsNullOrWhiteSpace(modelo.COD_CONTA)
|
||||
? DBNull.Value
|
||||
: modelo.COD_CONTA);
|
||||
|
||||
cmd.Parameters.AddWithValue("@DIA",
|
||||
string.IsNullOrWhiteSpace(modelo.DIA)
|
||||
? DBNull.Value
|
||||
: modelo.DIA);
|
||||
|
||||
cmd.Parameters.AddWithValue("@COMPENSADO",
|
||||
string.IsNullOrWhiteSpace(modelo.COMPENSADO)
|
||||
? DBNull.Value
|
||||
: modelo.COMPENSADO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@OBS_COMP",
|
||||
string.IsNullOrWhiteSpace(modelo.OBS_COMP)
|
||||
? DBNull.Value
|
||||
: modelo.OBS_COMP);
|
||||
}
|
||||
|
||||
private static void PreencherParametrosAlterar(SqlCommand cmd, ModeloCartoes modelo)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@CODIGO",
|
||||
string.IsNullOrWhiteSpace(modelo.CODIGO)
|
||||
? DBNull.Value
|
||||
: modelo.CODIGO);
|
||||
|
||||
PreencherParametrosInserir(cmd, modelo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
606
DAL/DALLChamado.cs
Normal file
606
DAL/DALLChamado.cs
Normal file
@ -0,0 +1,606 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLChamado
|
||||
{
|
||||
private readonly string connectionString;
|
||||
|
||||
public DALLChamado(string connectionString)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
}
|
||||
|
||||
#region CRUD
|
||||
|
||||
public bool Inserir(ModeloChamado modelo)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
INSERT INTO Chamado
|
||||
(
|
||||
TIPO,
|
||||
COD_CLIENTE,
|
||||
NOME_AVULSO,
|
||||
FONES,
|
||||
EMAIL,
|
||||
PARA,
|
||||
PRIORIDADE,
|
||||
REALIZADO,
|
||||
DIA_CHAMADO,
|
||||
OBS,
|
||||
ENDER_CLI
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@TIPO,
|
||||
@COD_CLIENTE,
|
||||
@NOME_AVULSO,
|
||||
@FONES,
|
||||
@EMAIL,
|
||||
@PARA,
|
||||
@PRIORIDADE,
|
||||
@REALIZADO,
|
||||
@DIA_CHAMADO,
|
||||
@OBS,
|
||||
@ENDER_CLI
|
||||
)";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
PreencherParametrosInserir(cmd, modelo);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}//Inserir
|
||||
|
||||
public bool Alterar(ModeloChamado modelo)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
UPDATE Chamado
|
||||
SET
|
||||
CODIGO = @CODIGO,
|
||||
TIPO = @TIPO,
|
||||
COD_CLIENTE = @COD_CLIENTE,
|
||||
NOME_AVULSO = @NOME_AVULSO,
|
||||
FONES = @FONES,
|
||||
EMAIL = @EMAIL,
|
||||
PARA = @PARA,
|
||||
PRIORIDADE = @PRIORIDADE,
|
||||
REALIZADO = @REALIZADO,
|
||||
DIA_CHAMADO = @DIA_CHAMADO,
|
||||
OBS = @OBS,
|
||||
ENDER_CLI = @ENDER_CLI
|
||||
WHERE ID_CHAMADO = @ID_CHAMADO";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
PreencherParametrosAlterar(cmd, modelo);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_CHAMADO", modelo.ID_CHAMADO);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}//Alterar
|
||||
|
||||
public bool Excluir(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
DELETE FROM Chamado
|
||||
WHERE ID_CHAMADO = @ID_CHAMADO";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_CHAMADO", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}//Excluir
|
||||
|
||||
public ModeloChamado? ObterPorId(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE ID_CHAMADO = @ID_CHAMADO";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_CHAMADO", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
if (dr.Read())
|
||||
{
|
||||
return PreencherModelo(dr);
|
||||
}
|
||||
|
||||
return null;
|
||||
}//ObterPorID
|
||||
public ModeloChamado CarregarModeloChamado(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE ID_CHAMADO = @ID_CHAMADO";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_CHAMADO", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
if (dr.Read())
|
||||
{
|
||||
return PreencherModelo(dr);
|
||||
}
|
||||
|
||||
#pragma warning disable CS8603 // Possível retorno de referência nula.
|
||||
return null;
|
||||
#pragma warning restore CS8603 // Possível retorno de referência nula.
|
||||
}//CarregarModeloChamado
|
||||
|
||||
#region LISTAGENS
|
||||
public List<ModeloChamado> Listar()
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
|
||||
return lista;
|
||||
}//listar
|
||||
public List<ModeloChamado> ListarPorCliente(string codCliente)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE COD_CLIENTE = @COD_CLIENTE
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@COD_CLIENTE", codCliente);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorCliente
|
||||
public List<ModeloChamado> ListarPorTipo(string tipo)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE TIPO = @TIPO
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@TIPO", tipo);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorTipo
|
||||
public List<ModeloChamado> ListarPorPrioridade(string prioridade)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE PRIORIDADE = @PRIORIDADE
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@PRIORIDADE", prioridade);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorPrioridade
|
||||
public List<ModeloChamado> ListarPorRealizado(string realizado)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE REALIZADO = @REALIZADO
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@REALIZADO", realizado);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorRealizado
|
||||
public List<ModeloChamado> ListarPorData(string diaChamado)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE DIA_CHAMADO = @DIA_CHAMADO
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@DIA_CHAMADO", diaChamado);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorData
|
||||
public List<ModeloChamado> ListarPorClienteETipo(string codCliente, string tipo)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE COD_CLIENTE = @COD_CLIENTE AND TIPO = @TIPO
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@COD_CLIENTE", codCliente);
|
||||
cmd.Parameters.AddWithValue("@TIPO", tipo);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorClienteETipo
|
||||
public List<ModeloChamado> ListarPorClienteERealizado(string codCliente, string realizado)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE COD_CLIENTE = @COD_CLIENTE AND REALIZADO = @REALIZADO
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@COD_CLIENTE", codCliente);
|
||||
cmd.Parameters.AddWithValue("@REALIZADO", realizado);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorClienteERealizado
|
||||
public List<ModeloChamado> ListarPorTipoERealizado(string tipo, string realizado)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT *
|
||||
FROM Chamado
|
||||
WHERE TIPO = @TIPO AND REALIZADO = @REALIZADO
|
||||
ORDER BY ID_CHAMADO DESC";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@TIPO", tipo);
|
||||
cmd.Parameters.AddWithValue("@REALIZADO", realizado);
|
||||
conn.Open();
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
return lista;
|
||||
}//ListarPorTipoERealizado
|
||||
public bool MarcarComoRealizado(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
UPDATE Chamado
|
||||
SET REALIZADO = 'S'
|
||||
WHERE ID_CHAMADO = @ID_CHAMADO";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@ID_CHAMADO", id);
|
||||
conn.Open();
|
||||
int rowsAffected = cmd.ExecuteNonQuery();
|
||||
return rowsAffected > 0;
|
||||
}//MarcarComoRealizado
|
||||
public bool MarcarComoPendente(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
UPDATE Chamado
|
||||
SET REALIZADO = 'N'
|
||||
WHERE ID_CHAMADO = @ID_CHAMADO";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@ID_CHAMADO", id);
|
||||
conn.Open();
|
||||
int rowsAffected = cmd.ExecuteNonQuery();
|
||||
return rowsAffected > 0;
|
||||
}//MarcarComoPendente
|
||||
public bool VerificarExistencia(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
string query = @"
|
||||
SELECT COUNT(1)
|
||||
FROM Chamado
|
||||
WHERE ID_CHAMADO = @ID_CHAMADO";
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
cmd.Parameters.AddWithValue("@ID_CHAMADO", id);
|
||||
conn.Open();
|
||||
int count = Convert.ToInt32(cmd.ExecuteScalar());
|
||||
return count > 0;
|
||||
}//VerificarExistencia
|
||||
|
||||
#endregion
|
||||
|
||||
#region HELPERS
|
||||
|
||||
private static ModeloChamado PreencherModelo(SqlDataReader dr)
|
||||
{
|
||||
return new ModeloChamado
|
||||
{
|
||||
ID_CHAMADO = Convert.ToInt32(dr["ID_CHAMADO"]),
|
||||
|
||||
CODIGO = Convert.ToString(dr["CODIGO"]) ?? string.Empty,
|
||||
|
||||
TIPO = Convert.ToString(dr["TIPO"]) ?? string.Empty,
|
||||
|
||||
COD_CLIENTE = Convert.ToString(dr["COD_CLIENTE"]) ?? string.Empty,
|
||||
|
||||
NOME_AVULSO = Convert.ToString(dr["NOME_AVULSO"]) ?? string.Empty,
|
||||
|
||||
FONES = Convert.ToString(dr["FONES"]) ?? string.Empty,
|
||||
|
||||
EMAIL = Convert.ToString(dr["EMAIL"]) ?? string.Empty,
|
||||
|
||||
PARA = Convert.ToString(dr["PARA"]) ?? string.Empty,
|
||||
|
||||
PRIORIDADE = Convert.ToString(dr["PRIORIDADE"]) ?? string.Empty,
|
||||
|
||||
REALIZADO = Convert.ToString(dr["REALIZADO"]) ?? string.Empty,
|
||||
|
||||
DIA_CHAMADO = Convert.ToString(dr["DIA_CHAMADO"]) ?? string.Empty,
|
||||
|
||||
OBS = Convert.ToString(dr["OBS"]) ?? string.Empty,
|
||||
|
||||
ENDER_CLI = Convert.ToString(dr["ENDER_CLI"]) ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
private static void PreencherParametrosInserir(SqlCommand cmd, ModeloChamado modelo)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@TIPO",
|
||||
string.IsNullOrWhiteSpace(modelo.TIPO)
|
||||
? DBNull.Value
|
||||
: modelo.TIPO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@COD_CLIENTE",
|
||||
string.IsNullOrWhiteSpace(modelo.COD_CLIENTE)
|
||||
? DBNull.Value
|
||||
: modelo.COD_CLIENTE);
|
||||
|
||||
cmd.Parameters.AddWithValue("@NOME_AVULSO",
|
||||
string.IsNullOrWhiteSpace(modelo.NOME_AVULSO)
|
||||
? DBNull.Value
|
||||
: modelo.NOME_AVULSO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@FONES",
|
||||
string.IsNullOrWhiteSpace(modelo.FONES)
|
||||
? DBNull.Value
|
||||
: modelo.FONES);
|
||||
|
||||
cmd.Parameters.AddWithValue("@EMAIL",
|
||||
string.IsNullOrWhiteSpace(modelo.EMAIL)
|
||||
? DBNull.Value
|
||||
: modelo.EMAIL);
|
||||
|
||||
cmd.Parameters.AddWithValue("@PARA",
|
||||
string.IsNullOrWhiteSpace(modelo.PARA)
|
||||
? DBNull.Value
|
||||
: modelo.PARA);
|
||||
|
||||
cmd.Parameters.AddWithValue("@PRIORIDADE",
|
||||
string.IsNullOrWhiteSpace(modelo.PRIORIDADE)
|
||||
? DBNull.Value
|
||||
: modelo.PRIORIDADE);
|
||||
|
||||
cmd.Parameters.AddWithValue("@REALIZADO",
|
||||
string.IsNullOrWhiteSpace(modelo.REALIZADO)
|
||||
? DBNull.Value
|
||||
: modelo.REALIZADO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@DIA_CHAMADO",
|
||||
string.IsNullOrWhiteSpace(modelo.DIA_CHAMADO)
|
||||
? DBNull.Value
|
||||
: modelo.DIA_CHAMADO);
|
||||
|
||||
cmd.Parameters.AddWithValue("@OBS",
|
||||
string.IsNullOrWhiteSpace(modelo.OBS)
|
||||
? DBNull.Value
|
||||
: modelo.OBS);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ENDER_CLI",
|
||||
string.IsNullOrWhiteSpace(modelo.ENDER_CLI)
|
||||
? DBNull.Value
|
||||
: modelo.ENDER_CLI);
|
||||
}
|
||||
|
||||
private static void PreencherParametrosAlterar(SqlCommand cmd, ModeloChamado modelo)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@CODIGO",
|
||||
string.IsNullOrWhiteSpace(modelo.CODIGO)
|
||||
? DBNull.Value
|
||||
: modelo.CODIGO);
|
||||
|
||||
PreencherParametrosInserir(cmd, modelo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VIEWS
|
||||
|
||||
public List<ModeloChamado> ListarTodos()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_Chamados");
|
||||
}//ListarTodos
|
||||
|
||||
public List<ModeloChamado> ListarPendentes()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosPendentes");
|
||||
}//ListarPendentes
|
||||
|
||||
public List<ModeloChamado> ListarFinalizados()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosFinalizados");
|
||||
}//ListarFinalizados
|
||||
|
||||
public List<ModeloChamado> ListarPrioridadeAlta()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosPrioridadeAlta");
|
||||
}//ListarPrioridadeAlta
|
||||
|
||||
public List<ModeloChamado> ListarPrioridadeMedia()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosPrioridadeMedia");
|
||||
}//ListarPrioridadeMedia
|
||||
|
||||
public List<ModeloChamado> ListarPrioridadeBaixa()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosPrioridadeBaixa");
|
||||
}//ListarPrioridadeBaixa
|
||||
|
||||
public List<ModeloChamado> ListarAvulsos()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosAvulsos");
|
||||
}//ListarAvulsos
|
||||
|
||||
public List<ModeloChamado> ListarClientes()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosClientes");
|
||||
}//ListarClientes
|
||||
|
||||
public List<ModeloChamado> ListarHoje()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosHoje");
|
||||
}//ListarHoje
|
||||
|
||||
public List<ModeloChamado> ListarVisita()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosVisita");
|
||||
}//ListarVisita
|
||||
|
||||
public List<ModeloChamado> ListarRemotos()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosRemotos");
|
||||
}//ListarRemotos
|
||||
|
||||
public List<ModeloChamado> ListarComEmail()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosComEmail");
|
||||
}//ListarComEmail
|
||||
|
||||
public List<ModeloChamado> ListarSemEmail()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_ChamadosSemEmail");
|
||||
}//ListarSemEmail
|
||||
|
||||
#endregion
|
||||
|
||||
#region DASHBOARD
|
||||
|
||||
public DataTable ObterDashboard()
|
||||
{
|
||||
return ExecutarViewDataTable("SELECT * FROM VW_ChamadosDashboard");
|
||||
}//ObterDashboard
|
||||
|
||||
#endregion
|
||||
|
||||
#region HELPERS VIEWS
|
||||
|
||||
private List<ModeloChamado> ExecutarViewLista(string query)
|
||||
{
|
||||
List<ModeloChamado> lista = [];
|
||||
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
|
||||
return lista;
|
||||
}//ExecutarViewLista
|
||||
|
||||
private DataTable ExecutarViewDataTable(string query)
|
||||
{
|
||||
DataTable dt = new();
|
||||
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
using SqlDataAdapter da = new(query, conn);
|
||||
|
||||
da.Fill(dt);
|
||||
|
||||
return dt;
|
||||
}//ExecutarViewDataTable
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
280
DAL/DALLChegues.cs
Normal file
280
DAL/DALLChegues.cs
Normal file
@ -0,0 +1,280 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using MLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
{
|
||||
public class DALLChegues
|
||||
{
|
||||
private readonly string connectionString;
|
||||
|
||||
public DALLChegues(string connectionString)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
}
|
||||
|
||||
#region CRUD
|
||||
|
||||
public bool Inserir(ModeloChegues modelo)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
INSERT INTO Chegues
|
||||
(
|
||||
BANCO,
|
||||
AGENCIA,
|
||||
VALOR,
|
||||
CLIENTE,
|
||||
FORNECEDOR,
|
||||
EMITIDO,
|
||||
COMPENSAR,
|
||||
OK,
|
||||
TIPO,
|
||||
CONTA,
|
||||
NUMERO,
|
||||
OBS,
|
||||
COD_CONTA,
|
||||
EMITENTE
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@BANCO,
|
||||
@AGENCIA,
|
||||
@VALOR,
|
||||
@CLIENTE,
|
||||
@FORNECEDOR,
|
||||
@EMITIDO,
|
||||
@COMPENSAR,
|
||||
@OK,
|
||||
@TIPO,
|
||||
@CONTA,
|
||||
@NUMERO,
|
||||
@OBS,
|
||||
@COD_CONTA,
|
||||
@EMITENTE
|
||||
)";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
PreencherParametrosInserir(cmd, modelo);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
|
||||
public bool Alterar(ModeloChegues modelo)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = @"
|
||||
UPDATE Chegues
|
||||
SET
|
||||
CODIGO = @CODIGO,
|
||||
BANCO = @BANCO,
|
||||
AGENCIA = @AGENCIA,
|
||||
VALOR = @VALOR,
|
||||
CLIENTE = @CLIENTE,
|
||||
FORNECEDOR = @FORNECEDOR,
|
||||
EMITIDO = @EMITIDO,
|
||||
COMPENSAR = @COMPENSAR,
|
||||
OK = @OK,
|
||||
TIPO = @TIPO,
|
||||
CONTA = @CONTA,
|
||||
NUMERO = @NUMERO,
|
||||
OBS = @OBS,
|
||||
COD_CONTA = @COD_CONTA,
|
||||
EMITENTE = @EMITENTE
|
||||
WHERE ID_CHEGUES = @ID_CHEGUES";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
PreencherParametrosAlterar(cmd, modelo);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_CHEGUES", modelo.ID_CHEGUES);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
|
||||
public bool Excluir(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = "DELETE FROM Chegues WHERE ID_CHEGUES = @ID_CHEGUES";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_CHEGUES", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
|
||||
public ModeloChegues? ObterPorId(int id)
|
||||
{
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
string query = "SELECT * FROM Chegues WHERE ID_CHEGUES = @ID_CHEGUES";
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
cmd.Parameters.AddWithValue("@ID_CHEGUES", id);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
if (dr.Read())
|
||||
{
|
||||
return PreencherModelo(dr);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ModeloChegues> Listar()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_Chegues");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VIEWS
|
||||
|
||||
public List<ModeloChegues> ListarCompensados()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_CheguesCompensados");
|
||||
}
|
||||
|
||||
public List<ModeloChegues> ListarPendentes()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_CheguesPendentes");
|
||||
}
|
||||
|
||||
public List<ModeloChegues> ListarClientes()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_CheguesClientes");
|
||||
}
|
||||
|
||||
public List<ModeloChegues> ListarFornecedores()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_CheguesFornecedores");
|
||||
}
|
||||
|
||||
public List<ModeloChegues> ListarReceber()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_CheguesReceber");
|
||||
}
|
||||
|
||||
public List<ModeloChegues> ListarPagar()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_CheguesPagar");
|
||||
}
|
||||
|
||||
public List<ModeloChegues> ListarHoje()
|
||||
{
|
||||
return ExecutarViewLista("SELECT * FROM VW_CheguesHoje");
|
||||
}
|
||||
|
||||
public DataTable ObterDashboard()
|
||||
{
|
||||
return ExecutarViewDataTable("SELECT * FROM VW_CheguesDashboard");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region HELPERS
|
||||
|
||||
private List<ModeloChegues> ExecutarViewLista(string query)
|
||||
{
|
||||
List<ModeloChegues> lista = [];
|
||||
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
using SqlCommand cmd = new(query, conn);
|
||||
|
||||
conn.Open();
|
||||
|
||||
using SqlDataReader dr = cmd.ExecuteReader();
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
lista.Add(PreencherModelo(dr));
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
|
||||
private DataTable ExecutarViewDataTable(string query)
|
||||
{
|
||||
DataTable dt = new();
|
||||
|
||||
using SqlConnection conn = new(connectionString);
|
||||
|
||||
using SqlDataAdapter da = new(query, conn);
|
||||
|
||||
da.Fill(dt);
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
private static ModeloChegues PreencherModelo(SqlDataReader dr)
|
||||
{
|
||||
return new ModeloChegues
|
||||
{
|
||||
ID_CHEGUES = Convert.ToInt32(dr["ID_CHEGUES"]),
|
||||
CODIGO = Convert.ToString(dr["CODIGO"]) ?? string.Empty,
|
||||
BANCO = Convert.ToString(dr["BANCO"]) ?? string.Empty,
|
||||
AGENCIA = Convert.ToString(dr["AGENCIA"]) ?? string.Empty,
|
||||
VALOR = Convert.ToString(dr["VALOR"]) ?? string.Empty,
|
||||
CLIENTE = Convert.ToString(dr["CLIENTE"]) ?? string.Empty,
|
||||
FORNECEDOR = Convert.ToString(dr["FORNECEDOR"]) ?? string.Empty,
|
||||
EMITIDO = Convert.ToString(dr["EMITIDO"]) ?? string.Empty,
|
||||
COMPENSAR = Convert.ToString(dr["COMPENSAR"]) ?? string.Empty,
|
||||
OK = Convert.ToString(dr["OK"]) ?? string.Empty,
|
||||
TIPO = Convert.ToString(dr["TIPO"]) ?? string.Empty,
|
||||
CONTA = Convert.ToString(dr["CONTA"]) ?? string.Empty,
|
||||
NUMERO = Convert.ToString(dr["NUMERO"]) ?? string.Empty,
|
||||
OBS = Convert.ToString(dr["OBS"]) ?? string.Empty,
|
||||
COD_CONTA = Convert.ToString(dr["COD_CONTA"]) ?? string.Empty,
|
||||
EMITENTE = Convert.ToString(dr["EMITENTE"]) ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
private static void PreencherParametrosInserir(SqlCommand cmd, ModeloChegues modelo)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@BANCO", string.IsNullOrWhiteSpace(modelo.BANCO) ? DBNull.Value : modelo.BANCO);
|
||||
cmd.Parameters.AddWithValue("@AGENCIA", string.IsNullOrWhiteSpace(modelo.AGENCIA) ? DBNull.Value : modelo.AGENCIA);
|
||||
cmd.Parameters.AddWithValue("@VALOR", string.IsNullOrWhiteSpace(modelo.VALOR) ? DBNull.Value : modelo.VALOR);
|
||||
cmd.Parameters.AddWithValue("@CLIENTE", string.IsNullOrWhiteSpace(modelo.CLIENTE) ? DBNull.Value : modelo.CLIENTE);
|
||||
cmd.Parameters.AddWithValue("@FORNECEDOR", string.IsNullOrWhiteSpace(modelo.FORNECEDOR) ? DBNull.Value : modelo.FORNECEDOR);
|
||||
cmd.Parameters.AddWithValue("@EMITIDO", string.IsNullOrWhiteSpace(modelo.EMITIDO) ? DBNull.Value : modelo.EMITIDO);
|
||||
cmd.Parameters.AddWithValue("@COMPENSAR", string.IsNullOrWhiteSpace(modelo.COMPENSAR) ? DBNull.Value : modelo.COMPENSAR);
|
||||
cmd.Parameters.AddWithValue("@OK", string.IsNullOrWhiteSpace(modelo.OK) ? DBNull.Value : modelo.OK);
|
||||
cmd.Parameters.AddWithValue("@TIPO", string.IsNullOrWhiteSpace(modelo.TIPO) ? DBNull.Value : modelo.TIPO);
|
||||
cmd.Parameters.AddWithValue("@CONTA", string.IsNullOrWhiteSpace(modelo.CONTA) ? DBNull.Value : modelo.CONTA);
|
||||
cmd.Parameters.AddWithValue("@NUMERO", string.IsNullOrWhiteSpace(modelo.NUMERO) ? DBNull.Value : modelo.NUMERO);
|
||||
cmd.Parameters.AddWithValue("@OBS", string.IsNullOrWhiteSpace(modelo.OBS) ? DBNull.Value : modelo.OBS);
|
||||
cmd.Parameters.AddWithValue("@COD_CONTA", string.IsNullOrWhiteSpace(modelo.COD_CONTA) ? DBNull.Value : modelo.COD_CONTA);
|
||||
cmd.Parameters.AddWithValue("@EMITENTE", string.IsNullOrWhiteSpace(modelo.EMITENTE) ? DBNull.Value : modelo.EMITENTE);
|
||||
}
|
||||
|
||||
private static void PreencherParametrosAlterar(SqlCommand cmd, ModeloChegues modelo)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@CODIGO",
|
||||
string.IsNullOrWhiteSpace(modelo.CODIGO)
|
||||
? DBNull.Value
|
||||
: modelo.CODIGO);
|
||||
|
||||
PreencherParametrosInserir(cmd, modelo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace DALL
|
||||
namespace DAL
|
||||
{
|
||||
public class DALLCloudBackup
|
||||
{
|
||||
|
||||
@ -17,7 +17,7 @@ namespace DAL
|
||||
public static bool Encrypt { get; set; } = true;
|
||||
public static bool TrustServerCertificate { get; set; } = true;
|
||||
|
||||
public static readonly string ObjetoStringConexao = ObterConexao();
|
||||
public static string ObjetoStringConexao;
|
||||
|
||||
// ===== CONEXÃO =====
|
||||
public static string ObterConexao()
|
||||
@ -51,7 +51,9 @@ namespace DAL
|
||||
{
|
||||
using var conn = new SqlConnection(cs);
|
||||
conn.Open();
|
||||
ObjetoStringConexao = cs;
|
||||
return true;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
34
UI/ArquivosAuxiliares/Triggers/Cartao.sql
Normal file
34
UI/ArquivosAuxiliares/Triggers/Cartao.sql
Normal file
@ -0,0 +1,34 @@
|
||||
CREATE OR ALTER TRIGGER TR_Cartoes_GerarCodigo
|
||||
ON Cartoes
|
||||
AFTER INSERT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
DECLARE @UltimoNumero INT;
|
||||
|
||||
SELECT @UltimoNumero =
|
||||
ISNULL(
|
||||
MAX(
|
||||
CAST(
|
||||
REPLACE(CODIGO, 'CT', '')
|
||||
AS INT)
|
||||
),
|
||||
99)
|
||||
FROM Cartoes
|
||||
WHERE CODIGO IS NOT NULL;
|
||||
|
||||
;WITH Numerados AS
|
||||
(
|
||||
SELECT
|
||||
ID_COD_CARTAO,
|
||||
ROW_NUMBER() OVER (ORDER BY ID_COD_CARTAO) AS Linha
|
||||
FROM inserted
|
||||
)
|
||||
UPDATE C
|
||||
SET CODIGO = 'CT' + RIGHT('0000' + CAST(@UltimoNumero + N.Linha AS VARCHAR), 4)
|
||||
FROM Cartoes C
|
||||
INNER JOIN Numerados N
|
||||
ON C.ID_COD_CARTAO = N.ID_COD_CARTAO;
|
||||
END
|
||||
GO
|
||||
34
UI/ArquivosAuxiliares/Triggers/ChamadoTecnico.sql
Normal file
34
UI/ArquivosAuxiliares/Triggers/ChamadoTecnico.sql
Normal file
@ -0,0 +1,34 @@
|
||||
CREATE OR ALTER TRIGGER TR_Chamado_GerarCodigo
|
||||
ON Chamado
|
||||
AFTER INSERT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
DECLARE @UltimoNumero INT;
|
||||
|
||||
SELECT @UltimoNumero =
|
||||
ISNULL(
|
||||
MAX(
|
||||
CAST(
|
||||
REPLACE(CODIGO, 'CH', '')
|
||||
AS INT)
|
||||
),
|
||||
99)
|
||||
FROM Chamado
|
||||
WHERE CODIGO IS NOT NULL;
|
||||
|
||||
;WITH Numerados AS
|
||||
(
|
||||
SELECT
|
||||
ID_CHAMADO,
|
||||
ROW_NUMBER() OVER (ORDER BY ID_CHAMADO) AS Linha
|
||||
FROM inserted
|
||||
)
|
||||
UPDATE C
|
||||
SET CODIGO = 'CH' + RIGHT('0000' + CAST(@UltimoNumero + N.Linha AS VARCHAR), 4)
|
||||
FROM Chamado C
|
||||
INNER JOIN Numerados N
|
||||
ON C.ID_CHAMADO = N.ID_CHAMADO;
|
||||
END
|
||||
GO
|
||||
34
UI/ArquivosAuxiliares/Triggers/Chegues.sql
Normal file
34
UI/ArquivosAuxiliares/Triggers/Chegues.sql
Normal file
@ -0,0 +1,34 @@
|
||||
CREATE OR ALTER TRIGGER TR_Chegues_GerarCodigo
|
||||
ON Chegues
|
||||
AFTER INSERT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
DECLARE @UltimoNumero INT;
|
||||
|
||||
SELECT @UltimoNumero =
|
||||
ISNULL(
|
||||
MAX(
|
||||
CAST(
|
||||
REPLACE(CODIGO, 'CQ', '')
|
||||
AS INT)
|
||||
),
|
||||
99)
|
||||
FROM Chegues
|
||||
WHERE CODIGO IS NOT NULL;
|
||||
|
||||
;WITH Numerados AS
|
||||
(
|
||||
SELECT
|
||||
ID_CHEGUES,
|
||||
ROW_NUMBER() OVER (ORDER BY ID_CHEGUES) AS Linha
|
||||
FROM inserted
|
||||
)
|
||||
UPDATE C
|
||||
SET CODIGO = 'CQ' + RIGHT('0000' + CAST(@UltimoNumero + N.Linha AS VARCHAR), 4)
|
||||
FROM Chegues C
|
||||
INNER JOIN Numerados N
|
||||
ON C.ID_CHEGUES = N.ID_CHEGUES;
|
||||
END
|
||||
GO
|
||||
195
UI/ArquivosAuxiliares/Views/ChamadoTecnico.sql
Normal file
195
UI/ArquivosAuxiliares/Views/ChamadoTecnico.sql
Normal file
@ -0,0 +1,195 @@
|
||||
USE [Levelcode-LevelOS]
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: TODOS OS CHAMADOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_Chamados
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS PENDENTES
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosPendentes
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
REALIZADO IS NULL
|
||||
OR REALIZADO = ''
|
||||
OR REALIZADO = 'NAO'
|
||||
OR REALIZADO = 'NÃO';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS FINALIZADOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosFinalizados
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
REALIZADO = 'SIM';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS PRIORIDADE ALTA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosPrioridadeAlta
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
PRIORIDADE = 'ALTA';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS PRIORIDADE MÉDIA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosPrioridadeMedia
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
PRIORIDADE = 'MEDIA'
|
||||
OR PRIORIDADE = 'MÉDIA';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS PRIORIDADE BAIXA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosPrioridadeBaixa
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
PRIORIDADE = 'BAIXA';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS AVULSOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosAvulsos
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
COD_CLIENTE IS NULL
|
||||
OR COD_CLIENTE = '';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS COM CLIENTE
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosClientes
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
COD_CLIENTE IS NOT NULL
|
||||
AND COD_CLIENTE <> '';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS DO DIA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosHoje
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
DIA_CHAMADO = CONVERT(VARCHAR, GETDATE(), 103);
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: DASHBOARD DE CHAMADOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosDashboard
|
||||
AS
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_CHAMADOS,
|
||||
|
||||
SUM(CASE
|
||||
WHEN REALIZADO = 'SIM'
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS FINALIZADOS,
|
||||
|
||||
SUM(CASE
|
||||
WHEN REALIZADO IS NULL
|
||||
OR REALIZADO = ''
|
||||
OR REALIZADO = 'NAO'
|
||||
OR REALIZADO = 'NÃO'
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS PENDENTES,
|
||||
|
||||
SUM(CASE
|
||||
WHEN PRIORIDADE = 'ALTA'
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS PRIORIDADE_ALTA
|
||||
FROM Chamado;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS PARA VISITA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosVisita
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
PARA = 'VISITA';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS REMOTOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosRemotos
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
PARA = 'REMOTO';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS COM EMAIL
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosComEmail
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
EMAIL IS NOT NULL
|
||||
AND EMAIL <> '';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CHAMADOS SEM EMAIL
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ChamadosSemEmail
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Chamado
|
||||
WHERE
|
||||
EMAIL IS NULL
|
||||
OR EMAIL = '';
|
||||
GO
|
||||
87
UI/ArquivosAuxiliares/Views/CheguesViews.sql
Normal file
87
UI/ArquivosAuxiliares/Views/CheguesViews.sql
Normal file
@ -0,0 +1,87 @@
|
||||
USE [Levelcode-LevelOS]
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_Chegues
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues;
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesCompensados
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues
|
||||
WHERE OK = 'SIM';
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesPendentes
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues
|
||||
WHERE
|
||||
OK IS NULL
|
||||
OR OK = ''
|
||||
OR OK = 'NAO'
|
||||
OR OK = 'NÃO';
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesClientes
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues
|
||||
WHERE
|
||||
CLIENTE IS NOT NULL
|
||||
AND CLIENTE <> '';
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesFornecedores
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues
|
||||
WHERE
|
||||
FORNECEDOR IS NOT NULL
|
||||
AND FORNECEDOR <> '';
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesReceber
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues
|
||||
WHERE TIPO = 'RECEBER';
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesPagar
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues
|
||||
WHERE TIPO = 'PAGAR';
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesHoje
|
||||
AS
|
||||
SELECT *
|
||||
FROM Chegues
|
||||
WHERE COMPENSAR = CONVERT(VARCHAR, GETDATE(), 103);
|
||||
GO
|
||||
|
||||
CREATE OR ALTER VIEW VW_CheguesDashboard
|
||||
AS
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL,
|
||||
|
||||
SUM(CASE
|
||||
WHEN OK = 'SIM'
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS COMPENSADOS,
|
||||
|
||||
SUM(CASE
|
||||
WHEN OK IS NULL
|
||||
OR OK = ''
|
||||
OR OK = 'NAO'
|
||||
OR OK = 'NÃO'
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS PENDENTES
|
||||
FROM Chegues;
|
||||
GO
|
||||
325
UI/ArquivosAuxiliares/Views/ClientesViews.sql
Normal file
325
UI/ArquivosAuxiliares/Views/ClientesViews.sql
Normal file
@ -0,0 +1,325 @@
|
||||
USE [Levelcode-LevelOS]
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: TODOS OS CLIENTES
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_Clientes
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES ATIVOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesAtivos
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE Ativo = 1;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES INATIVOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesInativos
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE Ativo = 0;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES BLOQUEADOS
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesBloqueados
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE Bloqueado = 1;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES COM LIMITE
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesComLimite
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE LimiteCredito > 0;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES SEM LIMITE
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesSemLimite
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE
|
||||
LimiteCredito IS NULL
|
||||
OR LimiteCredito = 0;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES PF
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesPF
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE TipoPessoa = 'PF';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES PJ
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesPJ
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE TipoPessoa = 'PJ';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES COM WHATSAPP
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesWhatsapp
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE
|
||||
Whatsapp IS NOT NULL
|
||||
AND Whatsapp <> '';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES COM EMAIL
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesEmail
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE
|
||||
Email IS NOT NULL
|
||||
AND Email <> '';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES COM EMAIL NFE
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesEmailNFe
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE
|
||||
EmailNFe IS NOT NULL
|
||||
AND EmailNFe <> '';
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES COM CRIPTO
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesCripto
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE
|
||||
Bitcoin IS NOT NULL
|
||||
OR Ethereum IS NOT NULL
|
||||
OR Litecoin IS NOT NULL;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES POR CIDADE
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesCidade
|
||||
AS
|
||||
SELECT
|
||||
Cidade,
|
||||
UF,
|
||||
COUNT(*) AS TOTAL
|
||||
FROM Clientes
|
||||
GROUP BY Cidade, UF;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES POR GRUPO
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesGrupo
|
||||
AS
|
||||
SELECT
|
||||
Grupo,
|
||||
COUNT(*) AS TOTAL
|
||||
FROM Clientes
|
||||
GROUP BY Grupo;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES COM ÚLTIMA COMPRA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesUltimaCompra
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE UltimaCompra IS NOT NULL;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES SEM COMPRA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesSemCompra
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE UltimaCompra IS NULL;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES RECENTES
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesRecentes
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM Clientes
|
||||
WHERE CriadoEm >= DATEADD(DAY, -30, GETDATE());
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES PARA COBRANÇA
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesCobranca
|
||||
AS
|
||||
SELECT
|
||||
Id,
|
||||
Nome,
|
||||
Documento,
|
||||
Telefone1,
|
||||
Celular,
|
||||
Whatsapp,
|
||||
Email,
|
||||
ObservacoesCobranca
|
||||
FROM Clientes
|
||||
WHERE Ativo = 1;
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: DASHBOARD CLIENTES
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesDashboard
|
||||
AS
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_CLIENTES,
|
||||
|
||||
SUM(CASE
|
||||
WHEN Ativo = 1
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS CLIENTES_ATIVOS,
|
||||
|
||||
SUM(CASE
|
||||
WHEN Ativo = 0
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS CLIENTES_INATIVOS,
|
||||
|
||||
SUM(CASE
|
||||
WHEN Bloqueado = 1
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS CLIENTES_BLOQUEADOS,
|
||||
|
||||
SUM(CASE
|
||||
WHEN TipoPessoa = 'PF'
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS TOTAL_PF,
|
||||
|
||||
SUM(CASE
|
||||
WHEN TipoPessoa = 'PJ'
|
||||
THEN 1
|
||||
ELSE 0
|
||||
END) AS TOTAL_PJ
|
||||
FROM Clientes;
|
||||
GO
|
||||
|
||||
USE [Levelcode-LevelOS]
|
||||
GO
|
||||
|
||||
USE [Levelcode-LevelOS]
|
||||
GO
|
||||
|
||||
/* =========================================================
|
||||
VIEW: CLIENTES COMPLETO
|
||||
========================================================= */
|
||||
CREATE OR ALTER VIEW VW_ClientesCompleto
|
||||
AS
|
||||
SELECT
|
||||
-- CLIENTE
|
||||
C.Id,
|
||||
C.EmpresaId,
|
||||
C.Nome,
|
||||
C.NomeFantasia,
|
||||
C.TipoPessoa,
|
||||
C.Documento,
|
||||
C.RG,
|
||||
C.InscricaoMunicipal,
|
||||
C.DataNascimento,
|
||||
C.Contato,
|
||||
C.Telefone1,
|
||||
C.Telefone2,
|
||||
C.Celular,
|
||||
C.Whatsapp,
|
||||
C.Email,
|
||||
C.EmailNFe,
|
||||
C.Site,
|
||||
C.Grupo,
|
||||
C.Cep,
|
||||
C.Endereco,
|
||||
C.Numero,
|
||||
C.Complemento,
|
||||
C.Bairro,
|
||||
C.Cidade,
|
||||
C.UF,
|
||||
C.Pais,
|
||||
C.LimiteCredito,
|
||||
C.Bloqueado,
|
||||
C.ObservacoesCobranca,
|
||||
C.VendedorPadraoId,
|
||||
C.TipoConsumidor,
|
||||
C.Observacoes,
|
||||
C.CampoExtra1,
|
||||
C.CampoExtra2,
|
||||
C.CampoExtra3,
|
||||
C.Bitcoin,
|
||||
C.Ethereum,
|
||||
C.Litecoin,
|
||||
C.Ativo,
|
||||
C.UltimaCompra,
|
||||
C.CriadoEm,
|
||||
C.AtualizadoEm,
|
||||
|
||||
-- EMPRESA
|
||||
E.IdEmpresa,
|
||||
E.Nome AS EmpresaNome
|
||||
|
||||
FROM Clientes C
|
||||
INNER JOIN Empresa E
|
||||
ON C.EmpresaId = E.IdEmpresa;
|
||||
GO
|
||||
@ -1,9 +1,14 @@
|
||||
using BLL;
|
||||
using CCH;
|
||||
using CPT;
|
||||
using DAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
namespace UI
|
||||
{
|
||||
// ═══════════════════════════════════════════════════════════════════════
|
||||
@ -42,7 +47,8 @@ namespace UI
|
||||
|
||||
// ── KPI cards ──────────────────────────────────────────────────────
|
||||
// CORRIGIDO: instanciação posicional explícita (sem parâmetros nomeados)
|
||||
private readonly KpiCard[] _kpis;
|
||||
//private readonly KpiCard[] _kpis;
|
||||
private KpiCard[] _kpis;
|
||||
|
||||
// ── Layout ─────────────────────────────────────────────────────────
|
||||
private const int Pad = 24;
|
||||
@ -81,14 +87,15 @@ namespace UI
|
||||
_fTopTitle = new Font("Segoe UI Semibold", 13f);
|
||||
_fTopSub = new Font("Segoe UI", 9f);
|
||||
|
||||
// CORRIGIDO: KpiCard instanciado com construtor posicional explícito
|
||||
_kpis = new[]
|
||||
{
|
||||
new KpiCard("OS Abertas", "12", "↑ 4 essa semana", true, BlueLight, Blue),
|
||||
new KpiCard("OS Concluídas", "45", "↑ 12% vs mês", true, GreenL, Green),
|
||||
new KpiCard("Faturamento", "22.5k", "↑ R$ 2.100", true, AmberL, Amber),
|
||||
new KpiCard("Pendências", "3", "↓ aguardando", false, RedL, Red),
|
||||
};
|
||||
//// CORRIGIDO: KpiCard instanciado com construtor posicional explícito
|
||||
//_kpis = new[]
|
||||
//{
|
||||
// new KpiCard("OS Abertas", "12", "↑ 4 essa semana", true, BlueLight, Blue),
|
||||
// new KpiCard("OS Concluídas", "45", "↑ 12% vs mês", true, GreenL, Green),
|
||||
// new KpiCard("Faturamento", "22.5k", "↑ R$ 2.100", true, AmberL, Amber),
|
||||
// new KpiCard("Pendências", "3", "↓ aguardando", false, RedL, Red),
|
||||
//};
|
||||
this.CarregarDashboardClientes();
|
||||
|
||||
BackColor = Surface2;
|
||||
DoubleBuffered = true;
|
||||
@ -96,6 +103,85 @@ namespace UI
|
||||
ControlStyles.OptimizedDoubleBuffer |
|
||||
ControlStyles.ResizeRedraw, true);
|
||||
}
|
||||
private void CarregarDashboardClientes()
|
||||
{
|
||||
try
|
||||
{
|
||||
//string caminhoKey = @"C:\Levelcode\LevelOS\Config\config.json";
|
||||
//string conectionString = DatabaseHelperCPT.Carregar(caminhoKey);
|
||||
//string conexao = conectionString;
|
||||
|
||||
BLLClientes bll = new(AppConectionSystem.ConnectionStringDB);
|
||||
|
||||
DataTable dt = bll.ObterDashboard();
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
return;
|
||||
|
||||
DataRow row = dt.Rows[0];
|
||||
|
||||
_kpis = new KpiCard[]
|
||||
{
|
||||
new KpiCard(
|
||||
"Clientes",
|
||||
row["TOTAL_CLIENTES"].ToString() ?? "0",
|
||||
"Total cadastrados",
|
||||
true,
|
||||
BlueLight,
|
||||
Blue),
|
||||
|
||||
new KpiCard(
|
||||
"Ativos",
|
||||
row["CLIENTES_ATIVOS"].ToString() ?? "0",
|
||||
"Clientes ativos",
|
||||
true,
|
||||
GreenL,
|
||||
Green),
|
||||
|
||||
new KpiCard(
|
||||
"Inativos",
|
||||
row["CLIENTES_INATIVOS"].ToString() ?? "0",
|
||||
"Clientes inativos",
|
||||
false,
|
||||
AmberL,
|
||||
Amber),
|
||||
|
||||
new KpiCard(
|
||||
"Bloqueados",
|
||||
row["CLIENTES_BLOQUEADOS"].ToString() ?? "0",
|
||||
"Clientes bloqueados",
|
||||
false,
|
||||
RedL,
|
||||
Red),
|
||||
|
||||
new KpiCard(
|
||||
"Pessoa Física",
|
||||
row["TOTAL_PF"].ToString() ?? "0",
|
||||
"Clientes PF",
|
||||
true,
|
||||
BlueLight,
|
||||
Blue),
|
||||
|
||||
new KpiCard(
|
||||
"Pessoa Jurídica",
|
||||
row["TOTAL_PJ"].ToString() ?? "0",
|
||||
"Clientes PJ",
|
||||
true,
|
||||
OrangeL,
|
||||
Orange)
|
||||
};
|
||||
|
||||
Invalidate();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ex.Message,
|
||||
"Erro Dashboard",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
@ -118,6 +204,10 @@ namespace UI
|
||||
|
||||
DrawTopbar(g);
|
||||
int y = TopbarH + Pad;
|
||||
|
||||
DrawSectionTitle(g, "Resumo de Clientes", y);
|
||||
y += _fHead.Height + 10 + 8; // título + linha + espaço
|
||||
|
||||
DrawKpiRow(g, y);
|
||||
y += KpiH + 20;
|
||||
DrawOsCard(g, y);
|
||||
@ -162,22 +252,76 @@ namespace UI
|
||||
}
|
||||
}
|
||||
|
||||
//private void DrawKpiCard(Graphics g, KpiCard kpi, Rectangle r)
|
||||
//{
|
||||
// FillRoundRect(g, new SolidBrush(Surface), r, CardRad);
|
||||
// DrawRoundBorder(g, r, CardRad, Border);
|
||||
|
||||
// int dotSize = 36;
|
||||
// var dotRect = new Rectangle(r.Right - 16 - dotSize, r.Y + 16, dotSize, dotSize);
|
||||
// FillRoundRect(g, new SolidBrush(kpi.DotBg), dotRect, 8);
|
||||
|
||||
// g.DrawString(kpi.Label, _fLabel, new SolidBrush(TextMuted), r.X + 16, r.Y + 18);
|
||||
// g.DrawString(kpi.Value, _fValue, new SolidBrush(TextPri), r.X + 14, r.Y + 36);
|
||||
|
||||
// var deltaColor = kpi.DeltaUp ? Green : Red;
|
||||
// g.DrawString(kpi.Delta, _fDelta, new SolidBrush(deltaColor), r.X + 16, r.Y + 76);
|
||||
//}
|
||||
private void DrawKpiCard(Graphics g, KpiCard kpi, Rectangle r)
|
||||
{
|
||||
// Fundo + borda
|
||||
FillRoundRect(g, new SolidBrush(Surface), r, CardRad);
|
||||
DrawRoundBorder(g, r, CardRad, Border);
|
||||
|
||||
int dotSize = 36;
|
||||
var dotRect = new Rectangle(r.Right - 16 - dotSize, r.Y + 16, dotSize, dotSize);
|
||||
// Tarja colorida no topo (3px)
|
||||
using var topPath = new GraphicsPath();
|
||||
topPath.AddArc(r.X + 1, r.Y + 1, CardRad * 2, CardRad * 2, 180, 90);
|
||||
topPath.AddArc(r.Right - CardRad * 2 - 1, r.Y + 1, CardRad * 2, CardRad * 2, 270, 90);
|
||||
topPath.AddLine(r.Right - 1, r.Y + 4, r.X + 1, r.Y + 4);
|
||||
topPath.CloseFigure();
|
||||
g.FillPath(new SolidBrush(kpi.DotFg), topPath);
|
||||
|
||||
// Ícone (dot arredondado)
|
||||
int dotSize = 34;
|
||||
var dotRect = new Rectangle(r.Right - 14 - dotSize, r.Y + 14, dotSize, dotSize);
|
||||
FillRoundRect(g, new SolidBrush(kpi.DotBg), dotRect, 8);
|
||||
|
||||
g.DrawString(kpi.Label, _fLabel, new SolidBrush(TextMuted), r.X + 16, r.Y + 18);
|
||||
g.DrawString(kpi.Value, _fValue, new SolidBrush(TextPri), r.X + 14, r.Y + 36);
|
||||
// Ícone no centro do dot
|
||||
string icon = kpi.Label switch
|
||||
{
|
||||
"Clientes" => "",
|
||||
"Ativos" => "",
|
||||
"Inativos" => "",
|
||||
"Bloqueados" => "",
|
||||
"Pessoa Física" => "",
|
||||
"Pessoa Jurídica" => "",
|
||||
_ => "·"
|
||||
};
|
||||
var sfCenter = new StringFormat
|
||||
{
|
||||
Alignment = StringAlignment.Center,
|
||||
LineAlignment = StringAlignment.Center
|
||||
};
|
||||
g.DrawString(icon, new Font("Segoe UI", 10f), new SolidBrush(kpi.DotFg), dotRect, sfCenter);
|
||||
|
||||
// Label uppercase
|
||||
using var fLabelUp = new Font("Segoe UI", 8f);
|
||||
g.DrawString(kpi.Label.ToUpperInvariant(), fLabelUp,
|
||||
new SolidBrush(TextMuted), r.X + 14, r.Y + 16);
|
||||
|
||||
// Valor grande
|
||||
g.DrawString(kpi.Value, _fValue, new SolidBrush(TextPri), r.X + 12, r.Y + 34);
|
||||
|
||||
// Separador
|
||||
int sepY = r.Y + 72;
|
||||
g.DrawLine(new Pen(Border, 0.5f), r.X + 12, sepY, r.Right - 12, sepY);
|
||||
|
||||
// Delta com seta
|
||||
var deltaColor = kpi.DeltaUp ? Green : Red;
|
||||
g.DrawString(kpi.Delta, _fDelta, new SolidBrush(deltaColor), r.X + 16, r.Y + 76);
|
||||
string arrow = kpi.DeltaUp ? "↑ " : "↓ ";
|
||||
g.DrawString(arrow + kpi.Delta, _fDelta,
|
||||
new SolidBrush(deltaColor), r.X + 14, r.Y + 80);
|
||||
}
|
||||
|
||||
// ── OS Card ────────────────────────────────────────────────────────
|
||||
private void DrawOsCard(Graphics g, int y)
|
||||
{
|
||||
@ -240,6 +384,14 @@ namespace UI
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSectionTitle(Graphics g, string title, int y)
|
||||
{
|
||||
g.DrawString(title, _fHead, new SolidBrush(TextPri), Pad, y);
|
||||
|
||||
int lineY = y + _fHead.Height + 4;
|
||||
g.DrawLine(new Pen(Border, 0.5f), Pad, lineY, Width - Pad, lineY);
|
||||
}
|
||||
|
||||
private static int[] GetColWidths(int total, float[] ratios)
|
||||
{
|
||||
var ws = new int[ratios.Length];
|
||||
|
||||
@ -40,6 +40,7 @@ namespace UI
|
||||
if (DadosDaConexao.TestarConexao())
|
||||
{
|
||||
NT_MessageBox.Show("Conexão com o banco de dados concluida com sucesso!", "Teste de conexão");
|
||||
AppConectionSystem.Inicializar(DadosDaConexao.ObjetoStringConexao);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +69,7 @@ namespace UI
|
||||
DadosDaConexao.TrustServerCertificate = false;
|
||||
DatabaseHelperCPT.Salvar(caminhoKey);
|
||||
string conectionString = DatabaseHelperCPT.Carregar(caminhoKey);
|
||||
AppInfoSystem.conectionString = conectionString;
|
||||
NT_MessageBox.Show(conectionString);
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user