public bool HasNewMessages() { try { var query = "SELECT COUNT(*) as quantidade from mensagem_" + Logindto.Usuario + " WHERE lida='0'"; bd.Conectar(); var dr = bd.RetDataReader(query); if (Convert.ToInt32(dr["quantidade"]) > 0) { dto.Quantidade = Convert.ToInt32(dr["quantidade"]); return(true); } else { return(false); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { bd.CloseConection(); } }
public ObservableCollection <EstabelecimentosDTO> LoadEstabelecimentos() { string Procurar = ""; if (dto.FromParent) { Procurar = "WHERE c.id = '" + dto.ParentId + "'"; } var estabelecimentos = new ObservableCollection <EstabelecimentosDTO>(); var dt = new DataTable(); try { var query = "SELECT e.id, e.cnpj, e.endereco, e.descricao, e.inscricao, e.status_id, cid.estado as id_estado, c.id as cliente_id, cid.id as id_cidade, e.CLIENTE_id, e.telefone, c.rsocial, c.fantasia, c.data, cid.uf, cid.cidade FROM estabelecimento e join cliente c on e.CLIENTE_id = c.id join cidades cid on e.CIDADES_id = cid.id " + Procurar + " ORDER BY c.fantasia, cid.uf, cid.cidade ASC"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow dr in dt.Rows) { estabelecimentos.Add(new EstabelecimentosDTO { Id = dr["id"].ToString(), Razao_Social = dr["rsocial"].ToString(), Nome_Fantasia = dr["fantasia"].ToString(), Cnpj = dr["cnpj"].ToString(), Status = Convert.ToInt32(dr["status_id"]), Endereco = dr["endereco"].ToString(), Cidade = dr["cidade"].ToString() + " - " + dr["uf"].ToString(), Cliente_Id = dr["cliente_id"].ToString(), Cidade_Id = dr["id_cidade"].ToString(), Ie = dr["inscricao"].ToString(), Telefone = dr["telefone"].ToString(), UF_Id = dr["id_estado"].ToString(), Descricao = dr["descricao"].ToString() }); } bd.CloseConection(); } return(estabelecimentos); }
public ObservableCollection <ItensDTO> LoadItens() { var itens = new ObservableCollection <ItensDTO>(); var dt = new DataTable(); try { var query = "SELECT i.id, i.descricao, un.descricao as un, i.status_id, s.descricao as status, i.mobra, gi.id as grupo_id, gi.descricao as grupo, i.data, f.nome FROM item i JOIN grupo_item gi ON i.GRUPO_ITEM_id = gi.id JOIN usuario u ON i.USUARIO_id = u.id JOIN funcionario f ON f.id = u.funcionario_id JOIN status s ON s.id = i.status_id JOIN unidade un ON un.id = i.unidade_id"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { foreach (DataRow dr in dt.Rows) { itens.Add(new ItensDTO { Id = Convert.ToInt32(dr["id"]), Descricao = dr["descricao"].ToString(), Grupo_Descricao = dr["grupo"].ToString(), Mobra = Convert.ToInt32(dr["mobra"]), Un = dr["un"].ToString(), Status_Id = Convert.ToInt32(dr["status_id"]), Grupo_Id = Convert.ToInt32(dr["grupo_id"]), Data = Convert.ToDateTime(dr["data"]).ToString("dd/MM/yyyy"), Usuario = dr["nome"].ToString(), Status = dr["status"].ToString() }); } bd.CloseConection(); } return(itens); }
public ObservableCollection <DisciplinaDTO> LoadDisciplinas(CopiarItensOrcamentoDTO dTO) { var disciplinas = new ObservableCollection <DisciplinaDTO>(); var dt = new DataTable(); try { var query = "SELECT DISTINCT d.descricao, d.id FROM atividade a JOIN negocio n ON a.NEGOCIO_id = n.id JOIN desc_atividades da ON a.DESC_ATIVIDADES_id = da.id JOIN disciplina d ON da.DISCIPLINA_id = d.id JOIN versao_atividade va ON a.VERSAO_ATIVIDADE_id = va.id WHERE a.NEGOCIO_id = '" + dTO.Negocio_Id + "' AND va.VERSAO_id = n.versao_valida ORDER BY d.descricao"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { foreach (DataRow dr in dt.Rows) { disciplinas.Add(new DisciplinaDTO { Id = Convert.ToInt32(dr["id"]), Descricao = dr["descricao"].ToString() }); } bd.CloseConection(); } return(disciplinas); }
public ObservableCollection <ClientesDTO> LoadClientes() { var clientes = new ObservableCollection <ClientesDTO>(); var dt = new DataTable(); try { var cliente = dto.Pesquisa; var query = "SELECT c.id, c.status_id, s.descricao as status_descricao, c.rsocial, c.fantasia, c.data, c.CATEGORIA_CLIENTE_id, cat.categoria FROM cliente c JOIN categoria_cliente cat ON c.CATEGORIA_CLIENTE_id = cat.id join status s on s.id = c.status_id ORDER BY c.fantasia"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow dr in dt.Rows) { clientes.Add(new ClientesDTO { Id = dr["id"].ToString(), Razao_Social = dr["rsocial"].ToString(), Nome_Fantasia = dr["fantasia"].ToString(), Categoria = dr["categoria"].ToString(), Status = Convert.ToInt32(dr["status_id"]), Categoria_Id = Convert.ToInt32(dr["categoria_cliente_id"]), Status_descricao = dr["status_descricao"].ToString() }); } bd.CloseConection(); } return(clientes); }
public List <AtividadeDTO> LoadAtividades(ListaOrcamentosDTO NDTO, DisciplinaDTO DTO) { var atividades = new List <AtividadeDTO>(); var dt = new DataTable(); try { var query = "select distinct da.id, da.descricao from atividade a JOIN desc_atividades da ON da.id = a.desc_atividades_id join versao_atividade va ON va.id = a.versao_atividade_id join negocio n ON a.negocio_id = n.id and n.versao_valida = va.versao_id where a.negocio_id = '" + NDTO.Id + "' and a.habilitado = 1 and da.disciplina_id = '" + DTO.Id + "'"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { atividades.Add(new AtividadeDTO { Id = Convert.ToInt32(item["id"]), Descricao = item["descricao"].ToString() }); } bd.CloseConection(); } return(atividades); }
public ObservableCollection <PessoasDTO> LoadPessoas() { string Procurar = ""; if (dto.FromParent) { Procurar = "WHERE c.id = '" + dto.ParentId + "'"; } var pessoas = new ObservableCollection <PessoasDTO>(); var dt = new DataTable(); try { var query = "SELECT cc.id, cc.nome, cc.anotacoes, cc.STATUS_id, cc.email, cc.telefone, cc.celular, cc.data, cc.USUARIO_id, fc.id as id_funcao, fc.descricao as desc_funcao, c.id as cliente_id, c.rsocial, c.fantasia FROM contato_cliente cc join cliente c on cc.CLIENTE_id = c.id join funcoes_contato fc ON cc.funcao_id = fc.id " + Procurar + " ORDER BY cc.nome"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow dr in dt.Rows) { pessoas.Add(new PessoasDTO { Id = dr["id"].ToString(), Status_Id = dr["status_id"].ToString(), Nome = dr["nome"].ToString(), Email = dr["email"].ToString(), Funcao = dr["desc_funcao"].ToString() + " NA " + dr["rsocial"].ToString(), Telefone = dr["telefone"].ToString(), Celular = dr["celular"].ToString(), Cliente_Id = dr["cliente_id"].ToString(), Funcao_Id = dr["id_funcao"].ToString(), Rsocial = dr["rsocial"].ToString(), Anotacoes = dr["anotacoes"].ToString() }); } bd.CloseConection(); } return(pessoas); }
public ObservableCollection <CadastroAtividadesDTO> LoadOrcamento(CadastroAtividadesDTO DTO) { ObservableCollection <CadastroAtividadesDTO> orcamentos = new ObservableCollection <CadastroAtividadesDTO>(); var dt = new DataTable(); try { var query = "SELECT n.id, n.descricao, n.anotacoes, cc.nome as responsavel, c.rsocial, e.cnpj, n.versao_valida, n.prazo, n.valor_fechamento, va.id as versao_atividade_id, va.locked, n.data, v.nome as vendedor, s.descricao as status_descricao, s.id as status_id, e.cnpj, e.endereco, cid.cidade, cid.uf FROM negocio n JOIN vendedor v ON n.VENDEDOR_id = v.id JOIN status_orcamento s ON n.STATUS_ORCAMENTO_id = s.id JOIN estabelecimento e ON n.ESTABELECIMENTO_id = e.id JOIN cidades cid ON e.CIDADES_id = cid.id JOIN contato_cliente cc ON n.contato_cliente_id = cc.id JOIN cliente c ON e.cliente_id = c.id join versao_atividade va ON va.negocio_id = n.id and va.versao_id = n.versao_valida WHERE n.id = '" + DTO.Id + "' ORDER BY n.id"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow dr in dt.Rows) { orcamentos.Add(new CadastroAtividadesDTO { Id = Convert.ToInt32(dr["id"]), Numero = "p" + Convert.ToInt32(dr["id"]).ToString("0000"), Razao_Social = dr["rsocial"].ToString(), Descricao = dr["descricao"].ToString(), Endereco = dr["endereco"].ToString() + " - " + dr["cidade"].ToString() + " - " + dr["uf"].ToString(), Vendedor = dr["vendedor"].ToString(), Status_Descricao = dr["status_descricao"].ToString(), CidadeEstado = dr["cidade"].ToString() + " - " + dr["uf"].ToString(), Cnpj = dr["cnpj"].ToString(), Contato_Nome = dr["responsavel"].ToString(), Versao_Id = Convert.ToInt32(dr["versao_valida"]), Versao_Locked = Convert.ToInt32(dr["locked"]), Versao_Atividade_Id = dr["versao_atividade_id"].ToString() }); } bd.CloseConection(); } return(orcamentos); }
public ObservableCollection <LinkarProdutoNotaFiscalDTO> LoadItens() { var itens = new ObservableCollection <LinkarProdutoNotaFiscalDTO>(); var dt = new DataTable(); try { var query = "SELECT p.id, i.descricao, p.descricao as desc_completa, un.descricao as un, p.partnumber, f.rsocial FROM produto p JOIN item i ON p.DESCRICAO_ITEM_id = i.id JOIN unidade un ON un.id = i.unidade_id JOIN fornecedor f ON p.FORNECEDOR_id = f.id WHERE p.STATUS_id='1' AND i.mobra='0' AND p.id != '1' AND f.status_id ='1' ORDER BY i.descricao"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { itens.Add(new LinkarProdutoNotaFiscalDTO { Id = Convert.ToInt32(item["id"]), Descricao = item["descricao"].ToString(), Anotacoes = item["desc_completa"].ToString(), Unidade = item["un"].ToString(), Partnumber = item["partnumber"].ToString(), Fabricante = item["rsocial"].ToString(), Codigo = Convert.ToInt32(item["id"]).ToString("000000") }); } bd.CloseConection(); } return(itens); }
public List <VersaoDTO> LoadVersao(ListaOrcamentosDTO DTO) { var versoes = new List <VersaoDTO>(); var dt = new DataTable(); try { var query = "SELECT id, versao_id, descricao FROM versao_atividade WHERE negocio_id = '" + DTO.Id + "'"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { versoes.Add(new VersaoDTO { Id = Convert.ToInt32(item["id"]), Descricao = item["descricao"].ToString(), Num_Versao = Convert.ToInt32(item["versao_id"]) }); } bd.CloseConection(); } return(versoes); }
public ObservableCollection <FornecedoresDTO> LoadFornecedores() { var fornecedores = new ObservableCollection <FornecedoresDTO>(); var dt = new DataTable(); try { var query = "SELECT f.id, f.rsocial, f.fantasia, f.grupo_frn_id, f.endereco, cid.estado as id_estado, f.status_id, f.inscricao, f.cnpj, cid.id as id_cidade, cid.cidade, cid.uf, gf.id, gf.descricao, f.tel, f.email FROM fornecedor f JOIN grupo_frn gf ON f.GRUPO_FRN_id = gf.id JOIN cidades cid ON f.cidades_id = cid.id ORDER BY f.rsocial"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { foreach (DataRow dr in dt.Rows) { fornecedores.Add(new FornecedoresDTO { Id = Convert.ToInt32(dr["id"]), Razao_Social = dr["rsocial"].ToString(), Nome_Fantasia = dr["fantasia"].ToString(), Grupo_Forn_id = Convert.ToInt32(dr["grupo_frn_id"]), Endereco = dr["endereco"].ToString(), Cnpj = dr["cnpj"].ToString(), Ie = dr["inscricao"].ToString(), CidadeEstado = dr["cidade"].ToString() + " - " + dr["uf"].ToString(), Email = dr["email"].ToString(), Telefone = dr["tel"].ToString(), Grupo_Forn_Descricao = dr["descricao"].ToString(), Cidade_Id = Convert.ToInt32(dr["id_cidade"]), Estado_Id = Convert.ToInt32(dr["id_estado"]) }); } bd.CloseConection(); } return(fornecedores); }
public List <OrcamentosDTO> LoadTextBoxes(ListaOrcamentosDTO DTO) { var orcamento = new List <OrcamentosDTO>(); var dt = new DataTable(); try { var query = "SELECT DISTINCT n.descricao, c.rsocial, cid.cidade, cid.uf, n.versao_valida, n.STATUS_ORCAMENTO_id FROM negocio n JOIN estabelecimento e ON n.ESTABELECIMENTO_id = e.id JOIN cliente c ON e.CLIENTE_id = c.id JOIN cidades cid ON e.CIDADES_id = cid.id JOIN status_orcamento so ON n.STATUS_ORCAMENTO_id = so.id JOIN atividade a ON a.NEGOCIO_id = n.id JOIN versao_atividade va ON a.VERSAO_ATIVIDADE_id = va.id WHERE n.id = '" + DTO.Id + "' AND va.VERSAO_id = n.versao_valida"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { foreach (DataRow dr in dt.Rows) { orcamento.Add(new OrcamentosDTO { Descricao = dr["descricao"].ToString(), Razao_Social = dr["rsocial"].ToString(), Cidade = dr["cidade"].ToString(), UF = dr["uf"].ToString(), Versao_Valida = dr["versao_valida"].ToString(), Status_Id = dr["STATUS_ORCAMENTO_id"].ToString() }); } bd.CloseConection(); } return(orcamento); }
public List <EstadoDTO> LoadEstados() { var estados = new List <EstadoDTO>(); var dt = new DataTable(); try { var query = "SELECT id, uf FROM estados ORDER BY uf ASC"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { estados.Add(new EstadoDTO { Id = Convert.ToInt32(item["id"]), Uf = item["uf"].ToString() }); } bd.CloseConection(); } return(estados); }
public ObservableCollection <ListaOrcamentosDTO> LoadOrcamento(InformacoesListaOrcamentosDTO DTO) { var orcamento = new ObservableCollection <ListaOrcamentosDTO>(); var dt = new DataTable(); try { var query = "SELECT (@cnt := @cnt + 1) AS Num, t.* FROM (SELECT p.id, i.descricao, lo.descricao_orc as desc_completa, p.partnumber, un.descricao as un, f.rsocial, lo.quantidade, lo.desconto, lo.preco_orc, lo.bdi, lo.quantidade * lo.preco_orc * (1-(desconto/100)) as preco_total, CASE lo.fd WHEN '0' THEN lo.quantidade * lo.preco_orc * (1 + (lo.bdi / 100)) * (1-(desconto/100)) WHEN '1' THEN lo.quantidade * lo.preco_orc * (1-(desconto/100)) * (1 + 10 / 100) END as preco_total_bdi, lo.fd, lo.id as pk FROM lista_orcamento lo JOIN produto p ON lo.PRODUTO_id = p.id JOIN item i ON p.DESCRICAO_ITEM_id = i.id JOIN unidade un ON un.id = i.unidade_id JOIN fornecedor f ON p.FORNECEDOR_id = f.id WHERE lo.NEGOCIO_id = '" + DTO.Id + "' AND lo.ATIVIDADES_id = '" + DTO.Atividade_Id + "') t CROSS JOIN(SELECT @cnt:= 0) AS dummy"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { foreach (DataRow dr in dt.Rows) { orcamento.Add(new ListaOrcamentosDTO { Id = dr["pk"].ToString(), Produto_Id = dr["id"].ToString(), Codigo_Produto = Convert.ToInt32(dr["id"]).ToString("000000"), Descricao = dr["descricao"].ToString(), Partnumber = dr["partnumber"].ToString(), Anotacoes = dr["desc_completa"].ToString(), Un = dr["un"].ToString(), Quantidade = Convert.ToDouble(dr["quantidade"]), Fabricante = dr["rsocial"].ToString(), Custo_Total = Convert.ToDouble(dr["preco_total"]), Bdi = Convert.ToDouble(dr["bdi"]), Preco_Unitario = Convert.ToDouble(dr["preco_orc"]), Preco_Total = Convert.ToDouble(dr["preco_total_bdi"]), Fd = Convert.ToInt32(dr["fd"]) }); } bd.CloseConection(); } return(orcamento); }
public ObservableCollection <FunildeVendasDTO> LoadNegocios() { var negocios = new ObservableCollection <FunildeVendasDTO>(); try { var query = "SELECT n.id, so.descricao as status_orcamento, n.status_orcamento_id, n.descricao, n.prazo, cid.uf, cid.cidade, c.fantasia FROM negocio n JOIN estabelecimento e ON e.id = n.estabelecimento_id JOIN cliente c ON c.id = e.cliente_id JOIN cidades cid ON cid.id = e.cidades_id JOIN status_orcamento so ON so.id = n.status_orcamento_id ORDER BY n.status_orcamento_id, n.id"; bd.Conectar(); var dtt = bd.RetDataTable(query); foreach (DataRow dr in dtt.Rows) { negocios.Add(new FunildeVendasDTO { Id = dr["id"].ToString(), Negocio = "p" + Convert.ToInt32(dr["id"]).ToString("0000"), Descricao = dr["descricao"].ToString(), Prazo = Convert.ToDateTime(dr["prazo"]).ToString("dd/MM/yyyy"), Cidade = dr["cidade"].ToString() + " - " + dr["uf"].ToString(), Fantasia = dr["fantasia"].ToString(), Descricao_Status = dr["status_orcamento"].ToString(), Status_Orcamento = Convert.ToInt32(dr["status_orcamento_id"]) }); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { bd.CloseConection(); } return(negocios); }
public List <ContatoDTO> LoadContatoFromNegocios(NegociosDTO DTO) { var contato = new List <ContatoDTO>(); var dt = new DataTable(); try { var query = "select id, nome from contato_cliente where cliente_id = '" + DTO.Cliente_Id + "' and status_id='1' ORDER BY nome ASC"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { contato.Add(new ContatoDTO { Id = Convert.ToInt32(item["id"]), Nome = item["nome"].ToString() }); } bd.CloseConection(); } return(contato); }
public List <VendedoresDTO> LoadVendedores() { var vendedor = new List <VendedoresDTO>(); var dt = new DataTable(); try { var query = "SELECT id, nome FROM gegetdb.vendedor ORDER BY nome ASC"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { vendedor.Add(new VendedoresDTO { Id = Convert.ToInt32(item["id"]), Nome = item["nome"].ToString() }); } bd.CloseConection(); } return(vendedor); }
public List <CategoriaClienteDTO> LoadCategoriaCliente() { var categorias = new List <CategoriaClienteDTO>(); var dt = new DataTable(); try { var query = "SELECT id, categoria FROM categoria_cliente ORDER BY categoria ASC"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { categorias.Add(new CategoriaClienteDTO { Id = Convert.ToInt32(item["id"]), Descricao = item["categoria"].ToString() }); } bd.CloseConection(); } return(categorias); }
public ObservableCollection <AdicionarItemOrcamentoDTO> LoadItens() { var itens = new ObservableCollection <AdicionarItemOrcamentoDTO>(); var dt = new DataTable(); try { var query = "SELECT p.id, i.descricao, p.descricao as desc_completa, un.descricao as un, p.partnumber, p.custounitario, f.rsocial FROM produto p JOIN item i ON p.DESCRICAO_ITEM_id = i.id JOIN unidade un ON un.id = i.unidade_id JOIN fornecedor f ON p.FORNECEDOR_id = f.id WHERE p.STATUS_id='1' AND f.status_id='1' ORDER BY p.id, i.descricao"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { itens.Add(new AdicionarItemOrcamentoDTO { Id = Convert.ToInt32(item["id"]), Descricao = item["descricao"].ToString(), Descricao_Produto = item["desc_completa"].ToString().Trim('\n', '\r'), Un = item["un"].ToString(), Partnumber = item["partnumber"].ToString(), Custo_Unitario = Convert.ToDouble(item["custounitario"]), Fabricante = item["rsocial"].ToString(), Codigo_Produto = Convert.ToInt32(item["id"]).ToString("000000") }); } bd.CloseConection(); } return(itens); }
public List <CidadesDTO> LoadCidades(EstadoDTO DTO) { var cidades = new List <CidadesDTO>(); var dt = new DataTable(); try { var query = "SELECT id, cidade FROM cidades WHERE estado='" + DTO.Id + "' ORDER BY cidade ASC"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { cidades.Add(new CidadesDTO { Id = Convert.ToInt32(item["id"]), Cidade = item["cidade"].ToString() }); } bd.CloseConection(); } return(cidades); }
public List <PrioridadeDTO> LoadPrioridades() { var cidades = new List <PrioridadeDTO>(); var dt = new DataTable(); try { var query = "SELECT id, descricao FROM prioridade ORDER BY descricao ASC"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { cidades.Add(new PrioridadeDTO { Id = Convert.ToInt32(item["id"]), Descricao = item["descricao"].ToString() }); } bd.CloseConection(); } return(cidades); }
public bool Login(LoginDTO dto) { string usuario = dto.Usuario.Replace("'", "''"); string senha = dto.Senha.Replace("'", "''"); var query = "SELECT SUBSTRING_INDEX(f.nome, ' ', 1) as primeiro_nome, SUBSTRING_INDEX(f.nome, ' ', -1) as ultimo_nome, u.id, f.nome, u.nivel_usuario_id, u.foto FROM usuario u JOIN funcionario f ON f.id = u.funcionario_id WHERE login='******' AND senha='" + senha + "' AND u.STATUS_ID='1'"; try { bd.Conectar(); var rd = bd.RetDataReader(query); if (rd.HasRows) { dto.Id = Convert.ToInt32(rd["id"]); dto.Nome = rd["nome"].ToString(); dto.Nivel = Convert.ToInt32(rd["nivel_usuario_id"]); dto.Primeiro_Nome = rd["primeiro_nome"].ToString(); dto.Ultimo_Sobrenome = rd["ultimo_nome"].ToString(); if (!String.IsNullOrEmpty(rd["foto"].ToString())) { byte[] blob = (byte[])rd["foto"]; MemoryStream stream = new MemoryStream(); stream.Write(blob, 0, blob.Length); stream.Position = 0; System.Drawing.Image img = System.Drawing.Image.FromStream(stream); BitmapImage bi = new BitmapImage(); bi.BeginInit(); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); bi.StreamSource = ms; bi.EndInit(); dto.Foto = bi; } else { Image image = new Image(); Uri uri = new Uri("pack://application:,,,/Resources/Images/User.png"); BitmapImage bi = new BitmapImage(uri); dto.Foto = bi; } return(true); } else { return(false); } } catch (Exception ex) { throw new Exception(ex.ToString()); } finally { bd.CloseConection(); } }
public ObservableCollection <AdicionarItemProjetoDTO> LoadItens() { var itens = new ObservableCollection <AdicionarItemProjetoDTO>(); var dt = new DataTable(); try { var query = "SELECT p.id,i.descricao,p.descricao AS desc_completa,un.descricao AS un,p.partnumber,p.custounitario,coalesce(e.quantidade,0) as estoque,f.rsocial FROM produto p JOIN item i ON p.DESCRICAO_ITEM_id=i.id JOIN unidade un ON un.id=i.unidade_id JOIN fornecedor f ON p.FORNECEDOR_id=f.id LEFT OUTER JOIN estoque e ON e.produto_id=p.id WHERE p.STATUS_id='1' AND i.mobra='0' AND p.id !='1' AND f.status_id='1' ORDER BY i.descricao"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow item in dt.Rows) { itens.Add(new AdicionarItemProjetoDTO { Id = Convert.ToInt32(item["id"]), Descricao = item["descricao"].ToString(), Anotacoes = item["desc_completa"].ToString(), Unidade = item["un"].ToString(), Partnumber = item["partnumber"].ToString(), Custo = Convert.ToDouble(item["custounitario"]), Fabricante = item["rsocial"].ToString(), Codigo = Convert.ToInt32(item["id"]).ToString("000000"), Estoque = Convert.ToDouble(item["estoque"]) }); } bd.CloseConection(); } return(itens); }
public ObservableCollection <NegociosDTO> LoadNegocios(NegociosDTO DTO) { string Procurar = ""; if (dto.FromParent) { Procurar = "WHERE c.id = '" + dto.ParentId + "'"; } else if (dto.FromChildrenParent) { Procurar = "WHERE e.id = '" + dto.ParentId + "'"; } var negocios = new ObservableCollection <NegociosDTO>(); var dt = new DataTable(); try { var query = "SELECT n.id, n.descricao, n.anotacoes, n.prazo, n.valor_fechamento, n.data, v.nome, s.descricao as status_descricao, s.id as status_id, e.cnpj, e.endereco, cid.cidade, e.id as estabelecimento_id, c.id as cliente_id, cid.uf, c.rsocial, c.fantasia, e.descricao as descricao_estabelecimento FROM negocio n JOIN vendedor v ON n.VENDEDOR_id = v.id JOIN status_orcamento s ON n.STATUS_ORCAMENTO_id = s.id JOIN estabelecimento e ON n.ESTABELECIMENTO_id = e.id JOIN cidades cid ON e.CIDADES_id = cid.id JOIN cliente c ON e.CLIENTE_id = c.id " + Procurar + " ORDER BY n.id"; bd.Conectar(); dt = bd.RetDataTable(query); } catch (Exception ex) { throw new Exception(ex.Message); } finally { foreach (DataRow dr in dt.Rows) { negocios.Add(new NegociosDTO { Id = dr["id"].ToString(), Numero = "p" + Convert.ToInt32(dr["id"]).ToString("0000"), Razao_Social = dr["rsocial"].ToString(), Descricao = dr["descricao"].ToString(), Anotacoes = dr["anotacoes"].ToString(), Status = Convert.ToInt32(dr["status_id"]), Endereco = dr["endereco"].ToString() + " - " + dr["cidade"].ToString() + " - " + dr["uf"].ToString(), Vendedor = dr["nome"].ToString(), Status_Descricao = dr["status_descricao"].ToString(), Status_Id = Convert.ToInt32(dr["status_id"]), Cliente_Id = dr["cliente_id"].ToString(), Estabelecimento_Id = dr["estabelecimento_id"].ToString(), CidadeEstado = dr["cidade"].ToString() + " - " + dr["uf"].ToString(), ProgressBarValue = Convert.ToInt32(dr["status_id"]) * 20, Cnpj = dr["cnpj"].ToString(), Descricao_Estabelecimento = dr["descricao_estabelecimento"].ToString(), Prazo = Convert.ToDateTime(dr["prazo"]).ToString("dd/MM/yyyy"), Nome_Fantasia = dr["fantasia"].ToString() }); } bd.CloseConection(); } return(negocios); }