Escolar Documentos
Profissional Documentos
Cultura Documentos
SOUZA
ETEC DE FRANCISCO MORATO
FRANCISCO MORATO
2011
FRANCISCO MORATO
2011
Banca examinadora:
__________________________________________________
__________________________________________________
__________________________________________________
DEDICATRIA
Dedicamos este trabalho primeiramente a Deus porque sem Ele no
somos ningum. Dedicamos tambm a nossas famlias, amigos, namorados
(as) e entes queridos que tiveram pacincia para entender o perodo de pouco
tempo a ser dedicado a eles e que alm de tudo, nos apoiaram nos momentos
em que pensamos em desistir.
Enfim, este trabalho dedicado a todos os amantes da informtica.
AGRADECIMENTOS
Direcionamos nossos agradecimentos a todo corpo docente da ETEC de
Francisco Morato, em especial ao professores orientadores Adil Aparecido
Soares e Juliana Pereira de Souza, que se empenharam em corrigir nossos
trabalhos, ao professor Anderson Spera, pois sua ajuda foi imprescindvel para
a concluso deste trabalho, ao professor Rafael Barreto que disponibilizou seu
tempo de aula para nos orientar e a professora Angela Roslia da Silva que foi
nossa orientadora no segundo semestre de curso.
Agradecemos tambm aos nossos colegas e amigos de classe que
estiveram conosco durante todo o processo de aprendizagem em especial ao
grande Erasmo Gonalves que nos auxiliou muito com a troca de informaes.
E por fim, agradecemos a famlia.
EPGRAFE
RESUMO
Empresas de segmento alimentcio buscam cada vez mais a fidelizao
de seus clientes e visando esse objetivo investem em comodidade e agilidade
na prestao de servios.
O servio delivery, atualmente, vem garantindo seu espao e no
municpio de Francisco Morato no diferente, pois principalmente as pizzarias
da regio j utilizam deste benefcio para seus clientes. Porm as falhas no
controle de entregas podem afastar por completo o comprador, causando
assim grandes transtornos administrativos.
Partindo desta falha, buscou-se desenvolver um software aplicativo que
gerencie o armazenamento dos dados e para melhor desenvolvimento de
pesquisas, direcionou-se o projeto Pizzaria e Esfiharia Davilla.
Esta empresa apresentou, como muitas, grandes falhas no mtodo de
gerenciamento de informaes gerando a perda de dados importantes, alm de
outros problemas de gerenciamento de departamentos. Assim o software
Gerenciamento de Sistemas FKs, foi desenvolvido para amenizar as falhas
apontadas e assim proporcionar melhoria nas atividades do dia-a-dia da
empresa.
Ferramentas utilizadas para o desenvolvimento do projeto: Visual Studio
2008 e Microsoft SQL Server 2008 R2 Express.
Palavras chaves: Pizzarias, Departamentos, Software, Gerenciamento.
ABSTRACT
Food industry companies are increasingly seeking the loyalty of their
clients and just for that purpose invest in convenience and flexibility in service
delivery.
Service delivery, currently, has ensured its place and the municipality of
Francisco Morato is no different, as especially pizza parlors in the region
already use this perk to their customers. But the failure to control deliveries can
provide convenience rather than the buyer away completely, thus causing great
inconvenience administrative.
From this failure, we sought to develop a software application that
manages data storage and improved development of research, directed to the
project and the Pizzaria Esfiharia Davilla.
This company had as many, large gaps in information management
method entailing the loss of important data, and other management issues
department. So the software Systems Management FK's, was developed to
alleviate the shortcomings pointed out and thus provide an improvement in dayto-day business.
Tools used for the development of the project: Visual Studio 2008 and
Microsoft SQL Server 2008 R2 Express.
LISTA DE FIGURAS
Figura 1: Definio de ramo de negcio .......................................................... 26
Figura 2: Verificando a opinio sobre formas de trabalho mais eficiente ......... 27
Figura 3: Identificao dos principais problemas ............................................. 27
Figura 4: Verificando possibilidades de investimentos. ................................... 28
Figura 5: Questo para verificar a experincia da empresa na utilizao de
tecnologia. .................................................................................... 28
Figura 6: Analisando possibilidades de ao de um software. ........................ 29
Figura 7: Organizao dos dados da empresa. ............................................... 29
Figura 8: Definio da importncia dada aos dados dos clientes. ................... 30
Figura 9 EAP (Estrutura Analtica do Projeto) para a empresa Davilla. ........ 33
Figura 10: Algumas das atribuies do administrador no sistema. .................. 41
Figura 11: Funes de um funcionrio comum e do administrador do sistema..
..................................................................................................... 42
Figura 12: A partir do desenvolvimento de classes possvel relacion-las. .. 43
Figura 13: Classes relacionadas. .................................................................... 44
Figura 14: Demonstrao de um diagrama de atividades. .............................. 46
Figura 15: Atividade ao acessar no sistema.. .................................................. 47
Figura 16: Gesto de Clientes.. ....................................................................... 47
Figura 17: Gesto de Funcionrios.. ............................................................... 48
Figura 18: Gesto de Pedidos.. ....................................................................... 48
Figura 19: Gesto de fornecedores.. ............................................................... 49
Figura 20: Gesto de estoque.. ....................................................................... 49
Figura 21: Gesto de Cargos.. ........................................................................ 50
Figura 22: Gesto de Pizzas.. ......................................................................... 50
Figura 23: Gesto de Esfihas.. ........................................................................ 51
Figura 24: Gesto de Bebidas.. ....................................................................... 51
LISTA DE TABELAS
Tabela 1: DER (Diagrama de Entidade - Relacionamento)............................132
Tabela 2: DER (Diagrama Relacionamento - Atributos).................................133
ABREVIATURAS E SIGLAS
UML (Unified Modeling Language) ou Linguagem Unificada de
Modelagem.
SGBD - Sistema de Gerenciamento de Banco de Dados.
DER - Diagrama Entidade - Relacionamento.
MER - Modelo Entidade - Relacionamento.
IEEE (Institute of Electrical and Electronics Engineers) ou Instituto de
Engenheiros Eletricistas e Eletrnicos.
ERP - (Enterprise Resources Planning) ou Empresa de Planejamento de
Recursos.
FK (Foreign Key) ou Chave Estrangeira.
EAP Estrutura Analtica de Projeto.
SQL (Structured Query Language) ou Linguagem de Consulta
Estruturada.
SUMRIO
INTRODUO ................................................................................................ 19
1.1 A Histria da Pizza ................................................................................ 21
1.2 Pizzarias e o delivery ............................................................................ 22
1.3 Ramo de Pizzarias delivery na cidade de Francisco Morato ................. 23
1.4 Histria da empresa Pizzaria e Esfiharia Davilla ................................... 24
2. LEVANTAMENTO DE DADOS ................................................................... 25
2.1 Pesquisa Bibliogrfica: .......................................................................... 25
2.2 Pesquisa de Campo: ............................................................................. 25
2.3 Anlise das Questes ........................................................................... 26
2.4 Concluso da Pesquisa de Campo ....................................................... 30
2.5 Entrevista com o gerente da empresa Pizzaria e Esfiharia Davilla ........ 31
3. ANLISE E REQUISITOS DO SOFTWARE ............................................... 32
3.1 Engenharia de Software ........................................................................ 32
3.2 Implantao .......................................................................................... 32
3.3 Ciclo de Vida ......................................................................................... 32
3.4 Estrutura Analtica do Projeto (EAP) ..................................................... 33
3.5 Cronograma de Gantt ........................................................................... 34
3.6 Requisitos Funcionais ........................................................................... 34
3.7 Requisitos No Funcionais ................................................................... 35
3.8 Segurana ............................................................................................ 37
4. ANLISE E MODELAGEM DO SISTEMA ORIENTADA A OBJETOS ........ 39
4.1 Linguagem de Modelagem Unificada (UML) ......................................... 40
4.2 Diagramas ............................................................................................ 40
4.2.1 Diagrama de Caso de Uso .................................................... 40
4.2.2 Diagrama de Classes ........................................................... 43
4.2.3 Diagrama de Atividades ........................................................ 45
19
INTRODUO
Atualmente, muitas pessoas precisam controlar o seu tempo e aproveitlo de maneira efetiva, para o alcance de suas metas. A refeio fora de casa
deixou de ser uma opo de lazer para muitas famlias, dentro do que se pode
chamar de terceirizao dos servios familiares.
Diante do crescimento gradativo do consumo de alimentos fora de casa,
surge a ideia de entrega desses alimentos. Muitas pessoas do menor ateno
refeio e maior ateno ao trabalho, e as mesmas necessitam ter a sua
disposio servios a serem executados de maneira rpida e segura.
Pedidos realizados por telefone e internet crescem e fazem empresas
investirem cada vez mais no atendimento ao cliente. Com o gerenciamento dos
dados armazenados, controle dos pedidos e entregas de produtos, observouse a necessidade de obter um cadastro simples e eficiente o bastante para
que, ao realizar um pedido, tanto do produto principal como afins, possa obter
resultados positivos alm de agilidade.
A implantao do software que gerenciar cadastros, controle de vendas
e de fornecedores, prope agilizar e informatizar com o objetivo de otimizar o
atendimento ao pblico, que o maior beneficiado com as melhorias que sero
implantadas.
O presente trabalho consiste em 06 captulos.
O primeiro captulo abrange o detalhamento do modelo de negcio de
gerenciamento, trazendo suas vantagens e dificuldades.
O segundo captulo apresenta as pesquisas elaboradas para apontar a
viabilidade do projeto, onde os resultados sero demonstrados por meio de
grficos.
O terceiro captulo demonstra o inicio do desenvolvimento do projeto, de
acordo com a engenharia do software, onde so detalhadas as etapas de
viabilidade e anlise de requisitos.
20
No quarto captulo consta a modelagem do sistema, onde foram
adotados os Diagramas da UML (Unified Modeling Language) Linguagem
Unificada de Modelagem. Demonstrando os diagramas de Caso de Uso,
Classe, Atividade e Sequncia.
O quinto captulo apresenta a Modelagem Entidade Relacionamento
(MER) e o Diagrama Entidade e Relacionamento (DER) que compem a
Modelagem Conceitual do Banco de Dados. Tambm outras Modelagens como
a Lgica e Fsica.
O sexto captulo a apresentao do projeto em si, sendo demonstrado
o seu design e todas as suas funes juntamente com o manual, que consiste
em apontar as possveis resolues para os problemas e as necessidades.
Finalizando o projeto consta a concluso, onde so abordados os
conhecimentos adquiridos e dificuldades encontradas para desenvolvimento
deste Trabalho de Concluso de Curso.
21
22
um padeiro de Npoles a servio do rei Umberto I e da rainha Margherita, a
quem ele homenageia ao confeccionar uma pizza imitando as cores da
bandeira italiana, branco, vermelho e verde, utilizando para isso mussarela,
tomate e manjerico, produtos que lhe permitiam obter as coloraes
desejadas. A rainha apreciou tanto este prato que dom Raffaele decidiu batizla de Margherita.
A nova receita da pizza, em seu formato redondo, alcanou tamanha
fama mundial que propiciou o nascimento da primeira pizzaria conhecida, a
PortAlba, point onde artistas clebres, como o escritor Alexandre Dumas, se
encontravam neste perodo.
A pizza desembarcou no Brasil trazida por imigrantes italianos,
celebrizando o bairro paulista do Brs, onde se concentrou grande parte deles
na cidade de So Paulo. At 1950 este prato se restringia mais aos crculos
italianos, mas a partir deste momento ela se disseminou por todo o pas,
tornando-se logo um elemento cultural brasileiro. O dia da pizza comeou a ser
comemorado em 1985, sendo reservado para este fim o dia 10 de julho.
23
trabalho de deslocamento. Segundo especialistas, delivery essencialmente
um elo entre o consumidor final e o varejista.
Esta atividade , para muitos empresrios, uma tima opo de lucros.
Isto se deve ao fato de o servio proporcionar tanta comodidade que os
clientes preferem receber o produto em casa a se dirigir at o estabelecimento.
Os restaurantes voltam suas preocupaes para a dificuldade da fidelizao de
clientes, j que um bom atendimento pode ser um diferencial mesmo fora do
estabelecimento comercial.
24
25
2. LEVANTAMENTO DE DADOS
Realizou-se
um
levantamento
de
dados
sobre
empresas
que
problemas e a viabilidade do
Ela
explica
um
problema
fundamentando-se
apenas
nas
26
27
Questo 2: Voc acha que um sistema que organize e controle
cadastros e pedidos de clientes tornaria seu trabalho mais eficiente?
enfrentados
pelas
empresas,
para
que
Sistema
de
28
Gerenciamento FKs procure ameniz-los. Por se tratar de um servio
prestado por telefone, o maior problema apresentado foram os trotes.
Questo 4: Disponibilizaria verba para investir na tecnologia da
informao para sua empresa?
questionado
se
realmente
disponibilizariam
verba
para
tal
29
Mesmo a prestao de servios delivery demonstrando crescimento na
regio, grande parte das empresas entrevistadas ainda utilizam de mtodos
bsicos para manter seu controle, ou seja, poucos realizam controle utilizando
de softwares especficos .
Questo 6: Voc gostaria de ter um software que disponibilize o
pedido e preo dos produtos?
30
Algumas empresas entrevistadas j buscaram se aperfeioar no
atendimento para manter e fidelizar seus clientes, deste modo, possuem uma
melhor estrutura de gerenciamento de dados mantendo-os organizados.
Questo 8: Como costuma fazer o controle de clientes, endereos
de entrega, pedidos e satisfao de servios prestados?
31
Com esses conceitos direcionou-se o projeto para o gerenciamento da
empresa: Pizzaria e Esfiharia Davilla que atua na cidade de Francisco Morato
localizada na regio da Grande So Paulo. Atravs dela buscar-se- a soluo
dos problemas citados e tambm particularidades do cliente.
32
3.2 Implantao
Para a implantao do software ser imprescindvel o uso de um
microcomputador com padro atual e que utilize plataforma Windows 7.
33
problema, definio da arquitetura do software, projeto, implementao, testes
com validao e manuteno. Esse enfoque reconhece o fato de que os
requisitos de um sistema so dinmicos, sendo passveis de mudanas
contnuas.
Ser seguido o modelo de ciclo de vida incremental para o
desenvolvimento do software, possibilitando estruturar e ordenar as etapas do
projeto, sendo possvel identificar antecipadamente falhas no desenvolvimento.
A escolha desse ciclo deve- se pelo fato de ser uma variante do modelo
cascata, que por sua vez, realiza uma etapa do projeto aps a outra, j o
modelo de ciclo de vida incremental, alm dessa maneira sequencial de
concluir as etapas, ainda possibilita a diviso do projeto lgico e fsico
trabalhando em paralelo.
34
Controle de Trotes;
35
durante
um
perodo
de
tempo
estabelecido.
As
36
usados,
sob
condies
estabelecidas.
subdiviso
das
caractersticas de eficincia :
se
cliente
desejar
alguma
mudana
nos
requisitos.
37
Testabilidade:
atributos
esforo
3.8 Segurana
Segurana de acesso: atributos do software que evidenciam sua
capacidade de evitar o acesso no autorizado, acidental ou deliberado, a
programas e dados.
Para a segurana do software ser necessrio utilizao de senhas
para manter a integridade do sistema referente s funes de funcionrios
comuns e funcionrios administradores.
No sistema haver a tela inicial onde ser requerido login e senha para
determinar o tipo de usurio, pois o usurio administrador tem acesso total s
38
funcionalidades do software e um usurio comum tem acesso restrito, como
por exemplo, cadastros de funcionrios.
39
40
4.2 Diagramas
Neste projeto foram utilizados os diagramas de caso de uso, classe,
sequncia e atividade. Eles demonstraram de forma grfica e abstrata o
funcionamento do sistema de gerenciamento de pizzaria Davilla.
4.2.1 Diagrama de Caso de Uso
De Acordo com Rezende (2005), um modelo de caso de uso descrito
pela UML por meio de um diagrama de caso de uso, e pode ser dividido em
diversos diagramas. Um diagrama e os casos de uso contm elementos
modelados para um sistema: os atores e os casos de uso, e mostra os
diferentes relacionamentos como tambm generalizaes, associaes e
dependncias entre estes elementos.
O ator algum ou alguma coisa que interage com o sistema, envia ou
recebe mensagem, troca informaes. Uma pessoa pode ser diferentes atores
em um sistema, por exemplo: Usurio que pode ser administrador ou usurio
comum do sistema.
O ator possui um nome, e este nome reflete o papel do ator no sistema,
o nome no deve refletir uma instncia especifica do ator e nem a
funcionalidade.
41
Demonstrao de um ator no diagrama de caso de uso.
42
43
4.2.2 Diagrama de Classes
Segundo Jnior (2001) diagrama de classes so os diagramas mais
utilizados em sistemas de modelagem a objetos. O diagrama de classes
composto basicamente por um conjunto de classes relacionadas entre si.
Dizemos que um diagrama de classes modela os aspectos estticos de
um sistema pelo fato de sua estrutura ser sempre vlida em qualquer ponto do
ciclo de vida do sistema.
Um dos propsitos do diagrama de classes, ainda de acordo com Jnior
(2001) a utilizao do diagrama para fazer a modelagem orientada a objetos
do esquema lgico de um banco de dados fsico que pode ser orientado a
objetos, relacional ou hbrido.
Exemplo de diagrama de classes de uma loja de convenincias
44
Diagrama de Classe
45
4.2.3 Diagrama de Atividades
Ainda de acordo com Jnior (2001), o diagrama de atividades
responsvel pela modelagem do fluxo de controle entre as atividades de um
sistema, ou seja, ele modela o fluxo sequencial das atividades geradas por
uma operao do sistema ou por um agente externo.
O diagrama de atividades composto por estados de atividades,
estados de aes e transies.
Estados de ao so computaes atmicas executveis, ou seja,
computaes que no podem ser interrompidas ou decompostas e que
representam um estado do sistema sob a execuo de uma ao. Os estados
de atividades, por sua vez, so no atmicos, ou seja, podem ser interrompidos
e decompostos para serem representados mais detalhadamente por outro
diagrama de atividades. Em suma, um estado de ao um estado de
atividade que no pode mais ser decomposto [...].
As transies em um diagrama de atividades podem ser de dois tipos:
1- Sequncias simples
uma linha simples com uma direo, que liga dois estados, e
representa o fluxo de controle entre eles.
2- Ramificaes
A ramificao representada por um losango que indica caminhos
alternativos a tomar em um diagrama mediante alguma expresso. A
ramificao poder ter uma transio de entrada e duas ou mais de sada,
sendo que apenas uma transio de sada pode ser tomada por vez,
obedecendo expresso relacionada ramificao correspondente.
Dessa forma, as transies so utilizadas para modelar o fluxo de
controle de um estado de ao ou de atividade, para outro estado de ao ou
de atividade, assim que o primeiro estiver concludo, sendo que a partir da
concluso deste, o fluxo de controle poder passar imediatamente para outro
estado obedecendo ou no a determinada condio. Porm, quando se fizer
46
necessrio modelar fluxos de controle concorrentes, o diagrama de atividades
dever utilizar barras de sincronizao.
As barras de sincronizao so representadas por linhas horizontais ou
verticais no diagrama e indicam a unio ou a bifurcao de fluxos de controles
[...].
O diagrama de atividades uma variao do diagrama de grfico de
estados, sendo que o diagrama de atividades no necessita especificar qual
evento causou a mudana de um estado para outro no sistema. Outra
caracterstica peculiar do diagrama de atividades o fato deste ser modelado
como um fluxograma, detalhando uma determinada operao de um sistema.
Exemplo de diagrama de atividades de um sistema de vendas
47
consultar diferentes dados, tornando o sistema mais flexvel. Abaixo, os
diagramas de atividades do sistema de gerenciamento de pizzaria Davilla que
demonstram de maneira grfica o que acontece quando algum interage com o
sistema.
Diagrama de Atividade (Login)
48
Diagrama de Atividade (Funcionrio)
49
Diagrama de Atividade (Fornecedor)
50
Diagrama de Atividade (Cargo)
51
Diagrama de Atividade (Esfiha)
52
Diagrama de Atividade (Self-Service)
53
4.2.4 Diagrama de Sequncia
Conforme Jnior (2001), o diagrama de sequncia um diagrama de
interao responsvel pela modelagem dos aspectos dinmicos de um sistema
e que da nfase ordenao temporal das mensagens trocadas entre objetos
deste sistema.
Desta forma, para proporcionar a melhor visualizao do fluxo de
controle ao longo do tempo, o diagrama de sequncias organizado
colocando-se os objetos correspondentes na parte superior do diagrama, ao
longo do eixo horizontal; e suas respectivas mensagens so colocadas ao
longo do eixo vertical, em uma ordem cronolgica, de cima para baixo. As
mensagens so representadas por setas horizontais, onde a ponta da seta
identifica o objetivo alvo.
Tambm existem no diagrama de sequncia as linhas de vida dos
objetos que so as linhas verticais tracejadas que representam o tempo de
existncia de um objeto. Outro item o foco de controle, um retngulo alto e
estreito, que mostra o perodo durante o qual um objeto est desempenhando
uma determinada ao.
Um diagrama de sequncias faz a modelagem dinmica de um sistema
sob diferentes contextos. Para modelar o comportamento do sistema sob
diferentes nveis de abstrao, o diagrama de sistemas criado com um
contexto especfico para interao, que pode ser um sistema como um todo,
um subsistema, uma operao ou uma classe.
Desta forma, um diagrama de sequncias ao ser criado, deve ser
associado a um diagrama de casos de uso ou a um diagrama de classes ou
objetos.
54
Exemplo de diagrama de sequncias de uma livraria
55
Diagrama de Sequncia (Administrador)
56
Diagrama de Sequncia (Usurio)
57
58
59
5.1.1 MER- Modelo Entidade-Relacionamento
Definido por Peter Chen em 1976, baseado na teoria de E.F.Codd
(1970); A viso da realidade baseia-se no relacionamento entre entidades que
retratam fatos que governam a realidade.
Cada entidade ou relacionamento possui atributos.
Objetivo da modelagem de dados: Transmitir e apresentar uma
representao
nica
resumida.
Veja
abaixo
Modelo
Entidade-
60
61
Referncia (Varchar Max), Telefone (Varchar Max), Celular (Varchar Max),
ListaNegra (Varchar Max). A chave primria da tabela CodCliente (int).
Um cliente pode fazer um ou mais pedidos.
Tabela Funcionrio
O funcionrio contratado pela empresa cadastrado por Nome (Varchar
Max), Rua (Varchar Max), Nmero (Varchar Max), Bairro (Varchar Max),
Cidade (Varchar Max), Estado (Varchar Max), CPF (Varchar Max, Chave
Candidata), Telefone (Varchar Max), AdicionalSalario (Numeric 18,2). A chave
primria da tabela CodFuncionario (int). Recebe a Chave Estrangeira
CodCargo.
Um Funcionrio pode pagar um ou mais fornecedores, pode vender um
ou mais pedidos, deve ter um e somente um cargo e deve possuir um e
somente um login de acesso.
Tabela Pedido
O pedido feito por clientes e um conjunto de itens pedidos.
Cadastrado por Tipo de Pedido (Varchar Max), Data (Varchar Max), Hora
(Varchar Max), Valor a Pagar (Varchar Max), Forma de Pagamento (Varchar
Max), Numero Mesa (Int) e Status Pedido (Varchar Max). Recebe as Chaves
Estrangeiras CodCliente e CodFuncionario.
Um pedido deve ser feito por um e somente um cliente, deve ser vendido
por um e somente um funcionrio e deve conter um ou mais itens pedidos.
Tabela Fornecedor
O Fornecedor distribui empresa os produtos necessrios. Cadastrado
por Nome Empresa (Varchar Max), CNPJ (Varchar Max), Nome Representante
(Varchar Max), Tel. Empresa (Varchar Max), Tel. Representante (Varchar Max).
A chave Primria CodFornecedor (Int).
Um Fornecedor pode ser pago por um ou mais Funcionrio e pode
fornecer uma ou mais ProdutoEstoque.
62
Tabelas Pizza, Esfiha e Bebida
A Pizza e a Esfiha e so produtos vendidos na empresa. Cadastrados
por Nome Pizza (Varchar Max), Nome Esfiha (Varchar Max), Descricao
(Varchar Max) e Valor (Varchar Max). Chaves Primrias de cada tabela
CodPizza (int), CodEsfiha (int).
Uma Pizza ou uma Esfiha podem estar em um ou mais Pedidos.
Tabela Bebida
A bebida vendida na empresa. Cadastrada por Descricao (Varchar
Max), TipoUnidade (Varchar Max) e Valor (Numeric 18,2). A chave primria
CodBebida (int).
Uma bebida pode estar em um ou mais pedidos.
Tabela Self Service
No local o Self Service tambm servido aos clientes. Cadastrado por
TipoSelfService (Varchar Max), Valor numeric (18,2). A chave primria
CodSelfService (int)
O Self Service pode estar em um ou mais pedidos.
Tabela Marmitex
O Marmitex tambm um produto vendido na empresa, cadastrado por
Descrio (Varchar Max), Dia Semana (Varchar Max) e Valor (Numeric 18,2).
Chave Primria CodMarmitex (Int).
Um Marmitex pode estar em um ou mais Pedidos.
Tabela Cargo
O Cargo especifica a funo dos Funcionrios. So cadastrados por
Nome Cargo (Varchar Max) e Salrio (Numeric 18,2). Chave Primria
CodCargo (Int).
Um Cargo pode ter um ou mais Funcionrios.
63
Tabela Login
O Login o meio de acesso ao sistema e tambm tem a finalidade de
proteo do sistema diferenciando o Administrador de funcionrios comuns.
cadastrado por NomeUsuario (Varchar Max) e Senha (Varchar Max).
Recebe a Chave Estrangeira CodFuncionario
Um Login pertence a um e somente um Funcionario.
64
5.2.2 Tabelas geradas pelo Relacionamento N:N
Tabela Itens Pedidos
O Item Pedido necessrio para detalhar o pedido final. Sua tabela
composta por Quantidade (Int) e Valor Unitrio (Numeric 18,2), ValorParcial
(Numeric 18,2) Observaoes (varchar Max). Chave primria CodItemPedido
(int).
Recebe
as
chaves
Estrangeiras:
CodPedido(int),
CodPizza(int),
Aviso
(Varchar
Max),
Descricao
(varchar
Max),
StatusConta
65
66
6.2 Principal
a partir do formulrio Principal que se tm acesso a todas as
funcionalidades do software. Apresenta a barra de menus, os botes de acesso
rpido e no rodap os dados do funcionrio que est ativo.
Formulrio Principal
Barra de Menus
67
1- Log Off: Reinicia o sistema com a possibilidade de troca de usurio.
2- Sair: Fecha a aplicao.
Gerenciar
68
6- Pedidos: Abre o Formulrio de Consulta dos Pedidos tanto os realizados no
balco, mesa e para entrega.
7- Estoque: Abre o Formulrio de Cadastrar Produto no Estoque.
8- Lembretes/Validade: Abre o Formulrio de consulta de produtos prximos da
data de vencimento e tambm que estejam acabando no estoque.
9- Lembretes/Conta: Abre o Formulrio de Verificao de contas prximas da
data de pagamento.
10- Checar Telefone: Abre o Formulrio de identificao de clientes.
11- Cliente: Abre o Formulrio de Cadastro de Clientes no corpo do formulrio
principal.
Administrao
69
70
Barra de acesso Rpido: Barra Fixa no layout.
71
6.4 Funcionrio
Utilizado para o cadastro de Novos Funcionrios, tambm para o controle de
atualizaes e Excluso de funcionrios cadastrados. Alm da aba de consulta
de funcionrios onde encontrar uma tabela com os dados pessoais de todos
os funcionrios.
72
Formulrio de Gerenciamento de Funcionrios
73
Aba de Consulta
Pode-se escolher um dado especifico para a consulta, seja por Cdigo,
Telefone, CPF ou Nome.
Aba Consultar Funcionrio
74
.
Figura 46: Opes de Consulta
75
Boto Consultar Todos- Quando o campo de busca Buscar por
estiver vazio, o boto traz todas as contas cadastradas, quando estiver
preenchido, o boto buscar resultados filtrando pelo campo preenchido de
acordo com o tipo de consulta do campo Consultar por.
Boto Somar Contas Pendentes: Soma todas as contas pendentes.
Boto Somar Contas Quitadas: Soma todas as contas quitadas.
Boto Contas Cadastradas por Funcionrios: Abre opes de soma
de contas cadastradas por funcionrios diferentes.
Boto Excluir Todas as Contas: Exclui todas as contas cadastradas.
6.5.1 Lembrete de Contas
A tela de lembrete de contas aparecer automaticamente ao se logar no
sistema somente quando uma conta estiver vencendo na mesma data do login
ou quando a data de aviso de contas que foi previamente cadastrada na tela de
gerenciamento de contas (ver pgina 69) tambm for igual data do login. As
contas aparecero em lista como na figura abaixo:
76
Campo de Detalhes de contas
77
para que seja digitado o nmero da comanda (caso o estabelecimento trabalhe
com comandas). Para continuar o pedido, basta digitar o nmero da comanda e
clicar no boto Continuar, como mostra a figura:
Tela para nmero da Comanda
78
adicionados ao pedido e a seleo de cliente para pedidos do tipo entrega. Ver
figura abaixo:
Escolher os Itens do pedido:
79
Quando o item for adicionado ao pedido com sucesso, aparecer
a informao de que o pedido foi adicionado como na imagem abaixo:
Visualizando Detalhes e Finalizando Pedidos
Ao fechar a tela de itens do pedido, aparecer uma tela com os detalhes
gerais do pedido. Veja a figura abaixo:
Detalhes do Pedido:
Visualizando o pedido:
80
Boto Ir para a Finalizao do Pedido: Ativa as opes de finalizao
do pedido.
Opes extras para pagamento:
81
82
83
Pedidos Entrega:
Pedidos Balco:
84
85
Consultar Telefone:
86
Consultar Telefone:
87
88
As consultas podem ser realizadas basicamente de dois modos:
na tabela de consulta.
3-
4-
89
na tabela de consulta.
2-
3-
4-
90
6.7.2 Cadastro de Esfihas
91
2 - Clicando na seta a direita do campo de consulta onde ser mostrada uma
lista com todos os nomes j cadastrados.
Boto Consultar Todas: O boto Consultar Todas preenche a tabela
com todos os dados cadastrados.
Boto Alterar: O boto Alterar modifica registros j cadastrados no
banco de dados.
Procedimento para alterao de dados:
1-
na tabela de consulta.
2-
3-
4-
de consulta.
Procedimento de excluso:
1-
na tabela de consulta.
2-
3-
4-
92
6.7.3 Cadastro de Bebidas
93
2- Clicando na seta a direita do campo de consulta onde ser mostrada uma
lista com todos os nomes j cadastrados.
Ver Todas as Bebidas: - O boto Ver Todas as Bebidas preenche a
tabela com todos os dados cadastrados.
Boto Alterar: O boto Alterar modifica registros j cadastrados no
banco de dados.
Procedimento para alterao de dados:
1-
3-
4-
de consulta.
Procedimento para excluso:
1-
na tabela de consulta.
2-
3-
4-
No da janela de dialogo.
94
6.7.4 Self Service
95
2-
3-
4-
96
Campos de Cadastros:
97
na tabela de consulta.
2-
3-
4-
de consulta.
Procedimento de excluso:
1-
na tabela de consulta.
2-
3-
4-
No da janela de dilogo.
98
6.8 Relatrios:
99
Boto Salrios: Pressionando esse boto visualizar o relatrio de
Salrios com suas respectivas informaes sobre os Salrios de seus
funcionrios como, por exemplo, nome, salrio, adicional.
Pressionando esse boto visualizar primeiramente o ms para gerar o
relatrio de Contas com suas respectivas informaes sobre Contas a serem
pagas como, por exemplo, descrio da conta, data de vencimento de acordo
com o ms de sua escolha. Como mostrado a esquerda.
100
Pressionando esse boto visualizar o relatrio de Estoque com suas
respectivas informaes sobre os Produtos como, por exemplo, nome do
produto, data de vencimento.
101
Como indicado no campo abaixo o usurio poder efetuar buscas
filtrando por:
102
6.10 Estoque
O formulrio de estoque tem a finalidade de cadastrar, alterar, pesquisar
e excluir Produtos.
Para abrir o formulrio de estoque, deve-se clicar no boto de estoque
da tela principal, apertar F8 ou pelo menu superior Gerenciar >> Estoque.
103
104
Boto Novo: Ao clicar pergunta se deseja limpar os campos para
cadastrar um novo produto, pois se pode ter clicado no boto acidentalmente.
105
106
Respondendo Sim o programa exclui o produto e se No ele mantm o
produto armazenado.
Boto Excluir Todos os Produtos: Como esperado, ao clicar ele apaga todos
os registros do sistema, porm segue tambm a mesma regra do boto excluir
perguntando se realmente deseja executar a ao. Se a resposta for Sim todos
os registros sero apagados do sistema.
Tabela de Visualizao dos dados Cadastrados.
107
Boto Limpar: Por fim o boto limpar, limpa a caixa de filtro e volta a
tabela com todos os dados j cadastrados no sistema.
6.11 Fornecedor
O formulrio de fornecedor tem a finalidade de cadastrar, alterar,
pesquisar e excluir Fornecedores.
Para abrir o formulrio de fornecedor, deve-se clicar menu superior
Administrao >> Fornecedores.
Foi dividido em duas partes por meio de abas, Gerenciar Fornecedores e
Consultar Fornecedores.
108
Na aba Gerenciar Fornecedores encontra-se os seguintes elementos.
Campo Nome Empresa: Digitar o nome do fornecedor que se deseja
cadastrar. Campo obrigatrio.
Campo CNPJ:- Cadastrar o CNPJ do fornecedor, digitar somente
nmeros. Campo obrigatrio.
Campo Telefone: Digitar o telefone do fornecedor, assim como CNPJ
somente nmeros. Campo obrigatrio.
Campo Representante: Digitar o nome do representante do fornecedor.
Campo opcional.
Campo Telefone Representante: Digitar o telefone do representante do
fornecedor. Campo opcional.
Boto Novo: Ao clicar, pergunta se deseja limpar os campos para
cadastrar
um
novo
fornecedor,
pois
pode-se
ter
clicado
no
boto
acidentalmente.
109
Boto Cadastrar: Depois do preenchimento dos campos obrigatrios,
clica-se no boto cadastrar para armazenar os dados, se faltar algum campo
obrigatrio
programa
avisa
com
seguinte
mensagem,
110
111
Tabela de Visualizao de fornecedores cadastrados.
112
Por fim o Boto Consultar Todos.
Boto Consultar Todos: Como o nome j diz, caso haja uma busca
filtrada ele limpa os filtros e mostra a tabela completa dos fornecedores
cadastrados.
superior
mostra
produtos
prximos
ao
vencimento.
113
Detalhando o aviso superior temos.
Tabela
de
visualizao
de
produtos
prximos
ao
vencimento
114
Abrir sem Filtro:
de
visualizao
de
produtos
com
estoque
mnimo
115
Boto Gerenciar Data Vencimento: Com o campo Quantidade Atual
preenchido, filtrado o formulrio de estoque com todos os produtos que esto
com a quantidade igual ou menor ao estoque mnimo definido pelo usurio, se
no estiver preenchida, o sistema pergunta se realmente deseja abrir o estoque
sem filtrar pela quantidade de produtos
Abrir sem Filtro:
116
Fechamento de Caixa:
117
Boto Ir para Relatrios: Direciona o sistema para o formulrio de Relatrios.
Para uma viso mais detalhada dos itens que esto sendo calculados,
estes so demonstrados nos campos de detalhes, como na figura abaixo:
Detalhes:
6.14 Cargo
A aba Cadastro/Alterao/Excluso de Cargos utilizada para o
cadastro de novos cargos, atualizao e excluso de cargos j cadastrados.
118
Tela Cargos:
119
Tela Cargos:
6.15 Cliente
Na aba Cadastrar/Alterar/Excluir Cliente utilizada para o
cadastro de novos clientes, atualizao e excluso de clientes j cadastrados.
Tela Clientes:
120
Boto Novo: Limpa os todos os registro para fazer um novo registro.
Boto Cadastrar: Cadastra um novo cliente.
Boto Alterar: Altera dados de registros j cadastrados anteriormente.
necessrio selecionar o registro que deseja alterar.
Boto Excluir: Exclui um registro criado anteriormente. necessrio
selecionar o registro que deseja excluir.
A figura a seguir, mostra o campo onde possvel escolher um cliente
para excluir o registro ou alterar os dados:
Seleo de Clientes:
121
CONCLUSO
Levando em considerao conceitos administrativos que buscam a
excelncia no atendimento, uma das maneiras de conquistar clientes o
delivery, servio muito utilizado por empresas do ramo alimentcio tal como
pizzarias. Porm a deficincia no armazenamento de dados para tal servio e
outros, pode trazer grandes problemas estrutura administrativa.
Aps a realizao de pesquisas e analisando a problemtica da empresa
em questo atravs de entrevistas, constatou se que as principais
deficincias de gerenciamento da Pizzaria e Esfiharia Davilla ocorrem devido a
mtodos manuais e anotaes para todo o funcionamento da empresa,
proporcionando assim um sistema administrativo vulnervel a erros simples tais
como perca de dados.
Assim dirigiu-se o projeto para o desenvolvimento de um software que
realize o controle de dados de maneira eficiente. possvel perceber que
mtodos informatizados podem amenizar e melhorar o atendimento na
empresa citada, variando os benefcios adquiridos por um atendimento rpido e
eficiente por meio do software. Os benefcios que a empresa obter com a
utilizao do software vo desde cadastros geis e consultas com filtros at
relatrios dos dados mais importantes para o gerenciamento, podendo assim
proporcionar um atendimento mais agradvel aos clientes.
Para a criao do software, foi de grande valia o conhecimento
especfico na rea de programao, banco de dados, documentos e
modelagem de software. Tais conhecimentos adquiridos em aula e tambm
pesquisas fora do mbito escolar.
O verdadeiro desenvolvimento aconteceu da juno de administrao de
tempo para as etapas do projeto e conhecimento nas diversas reas que
englobam a concluso efetiva do software, alm de um trabalho de equipe
preciso e determinado.
Em resumo, o desenvolvimento do software nos proporcionou um vasto
conhecimento prtico e uma viso clara do que nos espera no mercado de
122
trabalho, nos propiciou o prazer de criar algo que em outros dias nos parecia
impossvel e uma experincia de grande valia para a nossa formao pessoal
nos habilitando a ser capazes de escrever o futuro.
123
BIBLIOGRAFIA
BOOCH, Grady; RUMBAUGH, James; JACOBSON, Ivair. UML Guia do
Usurio. Rio de Janeiro: Campus, 2000.
ELMASRI, Ramez: Sistemas de Banco de Dados. So Paulo: Pearson
Addison Wesley, 2005. Disponvel em:
http://amigosdospi.ucoz.com/_ld/0/89_Sistema_de_banc.pdf Acesso em: 12
Out. 2011 as 22:23:28.
ESTEVES, Keli Cristine Menezes. Site: www.foodservicenews.com.br/
materia.php?id=35. Acesso no dia 30/07/2011.
JNIOR, Rodolfo Moacir Seabra. Anlise e Projeto Orientado a Objetos
Usando UML e o Processo Unificado. UFPA 2001. Disponvel em:
<http://www.ufpa.br/cdesouza/teaching/cedai/APOOUMLP.pdf>. Acesso em: 09
out. 2011. 22:50:33.
LOPES, Arthur Vargas. 1999. Estrutura de Dados Para a Construo de
Softwares. 1 ed. Ulbra.
MARTINS, Elaine. Site: http://www.tecmundo.com.br/826-excel-criandograficos-de-gantt.htm Acesso em 14/08/2011
OLIVEIRA, Silvio Luiz, 2009. Metodologia Cientfica Aplicada ao Direito.
Editora: Thomson.
RAMOS, Ricardo Argenton. Treinamento Prtico em UML. So
Paulo:Digerati Books, 2006.
REIS, Linda G. 2008. Produo de monografia: da teoria prtica. 2,ed.
Braslia: Senac-DF, 2008.
RIBEIRO, Juliano: Projeto de Banco de Dados. Instituto de Informtica
da UFRGS. Disponvel em:
http://ww.julianoribeiro.com.br/troca/banco_de_dados/material_der.pdf. Acesso
em 10 Out. 2011. 19:45:12.
124
SANTANA, Ana Lucia. Site: www.infoescola.com/historia/pizza/. Acesso
no dia 30/07/2011.
SOUZA, Cleidson. Orientao a Objetos. [2007?] Disponvel em:
<http://cultura.ufpa.br/cdesouza/teaching/labes/OO-basic-concepts.pdf>.
Acesso em: 28 set. 2011 21:01.
125
126
5.
controle?
Os dados dos fornecedores so armazenados nas prprias notas fiscais
que ao surgir necessidade so consultadas, alm dos telefones de contato que
so anotados em caderno.
7.
8.
9.
de
brindes,
composio
de
pizzas
especiais.
127
128
129
NomeEsfiha varchar(MAX) not null,
Descricao varchar(MAX) not null,
Valor numeric(18,2) not null
)
create table Estoque(
CodProdutoEstoque int identity constraint PK_CodProdutoEstoque Primary
Key,
CodFornecedor int not null,
Descricao varchar(MAX) not null,
TipoUnidade varchar(MAX) not null,
Quantidade numeric(18,1) not null,
EstoqueMin numeric(18,1),
Validade date not null,
DataAviso date,
Observacoes varchar(MAX)
)
create table Fornecedor(
CodFornecedor int identity constraint PK_CodFornecedor Primary Key,
NomeEmpresa varchar(MAX) not null,
CNPJ varchar(MAX),
TelEmpresa varchar(MAX),
NomeRepresentante varchar(MAX),
TelRepresentante varchar(MAX),
)
create table ItemPedido(
CodItemPedido int identity constraint PK_CodItemPedido Primary Key,
CodPedido int not null,
Quantidade int not null,
ValorUnitario numeric (18,2) not null,
ValorParcial numeric (18,2),
Observacoes varchar(MAX),
CodPizza int,
CodMarmitex int,
CodEsfiha int,
CodBebida int,
CodSelfService int
)
create table Login(
NomeUsuario varchar(MAX) not null,
Senha varchar(MAX) not null,
CodFuncionario int not null
)
create table Marmitex(
CodMarmitex int identity constraint PK_CodMarmitex Primary Key,
Descricao varchar(MAX) not null,
DiaSemana varchar(MAX) not null,
Valor numeric (18,2) not null
)
create table Pedido(
CodPedido int identity constraint PK_CodPedido Primary Key,
CodCliente int,
CodFuncionario int not null,
Entregador varchar(MAX),
TipoPedido varchar(MAX) not null,
130
NumeroMesa int,
NumeroComanda int,
Data date not null,
Hora time not null,
ValorTotal numeric(18,2) not null,
FormaPagamento varchar(MAX) not null,
StatusPedido varchar(MAX) not null,
Observacoes varchar(MAX)
)
create table Pizza(
CodPizza int identity constraint PK_CodPizza Primary Key,
NomePizza varchar(MAX) not null,
Descricao varchar(MAX) not null,
Valor numeric(18,2) not null
)
create table SelfService(
CodSelfService int identity constraint PK_CodSelfService Primary Key,
TipoSelfService varchar(MAX) not null,
Valor numeric(18,2)
)
-- comandos para iniciar os campos COD a partir do indice n
DBCC CHECKIDENT ('Pizza', RESEED, 101)
DBCC CHECKIDENT ('Esfiha', RESEED, 201)
DBCC CHECKIDENT ('Bebida', RESEED, 301)
DBCC CHECKIDENT ('Marmitex', RESEED, 401)
-- Adicionando Chave Estrangeira na Tabela ContasApagar
alter table ContasApagar add constraint FK_CodFornecedor foreign key
(CodFornecedor) references Fornecedor (CodFornecedor)
alter table ContasApagar add constraint FK_Funcionario_ContasApagar
foreign key (CodFuncionario) references Funcionario (CodFuncionario)
-- Adicionando Chave Estrangeira na Tabela Estoque
alter table Estoque add constraint FK_CodFornecedor_Estoque foreign
key (CodFornecedor) references Fornecedor (CodFornecedor)
-- Adicionando Chave Estrangeira na Tabela Funcionario
alter table Funcionario add constraint FK_CodCargo_Funcionario foreign
key (CodCargo) references Cargo (CodCargo)
-- Adicionando Chave Estrangeira na Tabela ItemPedido
alter table ItemPedido add constraint FK_CodPedido foreign key
(CodPedido) references Pedido (CodPedido)
alter table ItemPedido add constraint FK_CodPizza foreign key
(CodPizza) references Pizza (CodPizza)
alter table ItemPedido add constraint FK_CodMarmitex foreign key
(CodMarmitex) references Marmitex (CodMarmitex)
alter table ItemPedido add constraint FK_CodEsfiha foreign key
(CodEsfiha) references Esfiha (CodEsfiha)
alter table ItemPedido add constraint FK_CodBebida foreign key
(CodBebida) references Bebida (CodBebida)
alter table ItemPedido add constraint FK_CodSelfService foreign key
(CodSelfService) references SelfService (CodSelfService)
-- Adicionando Chave Estrangeira na Tabela Login
alter table Login add constraint FK_CodFuncionario_Login foreign key
(CodFuncionario) references Funcionario (CodFuncionario)
131
132
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassConexao
{
public SqlConnection CON()
{
SqlConnection conn = new SqlConnection(@"Integrated
Security=SSPI;Persist Security Info=False;Initial
Catalog=BancoDavilla;Data Source=(local)");
try
{
conn.Open();
return conn;
}
catch
{
conn.Close();
return conn;
}
}
}
}
ClassBebida
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassBebida
{
ClassConexao Conecta = new ClassConexao();
//criar todos os get/sets com todos os campos do banco
private int codCadBebida;
public int CodCadBebida
{
get { return codCadBebida; }
133
set { codCadBebida = value; }
}
134
try
{
cmd.Parameters.AddWithValue("@CodBebida",
CodCadBebida);
cmd.Parameters.AddWithValue("@Descricao", Descricao);
cmd.Parameters.AddWithValue("@TipoUnidade",
TipoUnidade);
cmd.Parameters.AddWithValue("@Valor", Valor);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiBebida()
{
//metodo para excluir do banco
SqlCommand cmd = new SqlCommand("Delete from Bebida where
CodBebida = @CodBebida", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodBebida",
CodCadBebida);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassCargo
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassCargo
{
ClassConexao Conecta = new ClassConexao();
private int codCargo;
public int CodCargo
135
{
get { return codCargo; }
set { codCargo = value; }
}
private string nomeCargo;
public string NomeCargo
{
get { return nomeCargo; }
set { nomeCargo = value; }
}
private double salario;
public double Salario
{
get { return salario; }
set { salario = value; }
}
136
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiCargo()
{
SqlCommand cmd = new SqlCommand("Delete from Cargo where
CodCargo = @CodCargo", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodCargo", CodCargo);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassCliente
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
System.Data;
namespace IniciandoDavilla
{
class ClassCliente
{
ClassConexao Conecta = new ClassConexao();
private int codCliente;
public int CodCliente
{
get { return codCliente; }
set { codCliente = value; }
}
private string nome;
public string Nome
{
137
get { return nome; }
set { nome = value; }
}
private string rua;
public string Rua
{
get { return rua; }
set { rua = value; }
}
private string numero;
public string Numero
{
get { return numero; }
set { numero = value; }
}
private string bairro;
public string Bairro
{
get { return bairro; }
set { bairro = value; }
}
private string cidade;
public string Cidade
{
get { return cidade; }
set { cidade = value; }
}
private string estado;
public string Estado
{
get { return estado; }
set { estado = value; }
}
private string telefone;
public string Telefone
{
get { return telefone; }
set { telefone = value; }
}
private string celular;
public string Celular
{
get { return celular; }
set { celular = value; }
}
private string pontoRef;
138
139
{
cmd.Parameters.AddWithValue("@CodCliente",
CodCliente);
cmd.Parameters.AddWithValue("@NomeCliente", Nome);
cmd.Parameters.AddWithValue("@Rua", Rua);
cmd.Parameters.AddWithValue("@Numero", Numero);
cmd.Parameters.AddWithValue("@Bairro", Bairro);
cmd.Parameters.AddWithValue("@Cidade", Cidade);
cmd.Parameters.AddWithValue("@Estado", Estado);
cmd.Parameters.AddWithValue("@Telefone", Telefone);
cmd.Parameters.AddWithValue("@Celular", Celular);
cmd.Parameters.AddWithValue("@PontoReferencia",
PontoRef);
cmd.Parameters.AddWithValue("@ListaNegra",
ListaNegra);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiCliente()
{
SqlCommand cmd = new SqlCommand("Delete from Cliente where
CodCliente = @CodCliente", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodCliente",
CodCliente);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public DataTable TrazTodosClientes()
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
Cliente Order By NomeCliente",Conecta.CON());
DataTable dt = new DataTable();
try
{
da.Fill(dt);
dt.DisplayExpression = "NomeCliente";
return dt;
}
catch {
140
finally
{
Conecta.CON().Close();
}
return dt;
}
}
}
ClassContasApagar
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
System.Data;
namespace IniciandoDavilla
{
class ClassContasPagar
{
// VARIAVEIS GET SET -----------------------------------------------------------------------------------------------------------private string nomeFuncionario; // usada para capturar o
cdigo do fornecedor
public string NomeFuncionario
{
get { return nomeFuncionario; }
set { nomeFuncionario = value; }
}
private string nomeFornecedor; // usada para capturar o cdigo
do funcionario pagante
public string NomeFornecedor
{
get { return nomeFornecedor; }
set { nomeFornecedor = value; }
}
141
public string CodFornecedor
{
get { return codFornecedor; }
set { codFornecedor = value; }
}
private double valoraPagar;
public double ValoraPagar
{
get { return valoraPagar; }
set { valoraPagar = value; }
}
private DateTime dataVencimento;
public DateTime DataVencimento
{
get { return dataVencimento; }
set { dataVencimento = value; }
}
private DateTime dataAviso;
public DateTime DataAviso
{
get { return dataAviso; }
set { dataAviso = value; }
}
private string codConta;
public string CodConta
{
get { return codConta; }
set { codConta = value; }
}
private string statusConta;
public string StatusConta
{
get { return statusConta; }
set { statusConta = value; }
}
private string descricao;
public string Descricao
{
get { return descricao; }
set { descricao = value; }
}
private DateTime dataQuitacao;
public DateTime DataQuitacao
{
get { return dataQuitacao; }
142
set { dataQuitacao = value; }
}
// VARIAVEIS COMUNS ----------------------------------------------------------------------------------------------------------
143
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand CapturaUltimoCodConta()
{
SqlCommand cmd = new SqlCommand("Select MAX (CodConta) as
UltimoCodCad from ContasApagar", Conecta.CON());
try
{
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
CodConta = dr["UltimoCodCad"].ToString();
}
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand CadDataAviso()
{
//CapturaUltimoCodConta();
SqlCommand cmd = new SqlCommand("Update ContasApagar Set
DataAviso = @DataAviso where CodConta = @CodConta", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodConta",CodConta);
cmd.Parameters.AddWithValue("@DataAviso", DataAviso);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand CadDescricao()
{
//CapturaUltimoCodConta();
SqlCommand cmd = new SqlCommand("Update ContasApagar Set
Descricao = @Descricao where CodConta = @CodConta", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodConta", CodConta);
cmd.Parameters.AddWithValue("@Descricao", Descricao);
144
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraConta()
{
SqlCommand cmd = new SqlCommand("Update ContasApagar Set
CodFuncionario=@CodFuncionario, CodFornecedor=@CodFornecedor,
ValorApagar=@ValorApagar, DataVencimento=@DataVencimento,
StatusConta=@StatusConta where CodConta=@CodConta", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodConta", CodConta);
cmd.Parameters.AddWithValue("@CodFuncionario",
CodFuncionario);
cmd.Parameters.AddWithValue("@CodFornecedor",
CodFornecedor);
cmd.Parameters.AddWithValue("@ValorApagar",
ValoraPagar);
cmd.Parameters.AddWithValue("@DataVencimento",
DataVencimento);
cmd.Parameters.AddWithValue("@StatusConta",
StatusConta);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiConta()
{
SqlCommand cmd = new SqlCommand("Delete ContasApagar where
CodConta=@CodConta", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodConta", CodConta);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
145
return cmd;
}
public SqlCommand ExcluiTodasContas()
{
SqlCommand cmd = new SqlCommand("Delete ContasApagar ",
Conecta.CON());
try
{
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaDataQuitacao()
{
SqlCommand cmd = new SqlCommand("Update ContasApagar Set
DataQuitacao = @DataQuitacao where CodConta = @CodConta",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodConta", CodConta);
cmd.Parameters.AddWithValue("@DataQuitacao",
DataQuitacao);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiDataAviso()
{
SqlCommand cmd = new SqlCommand("Update ContasApagar Set
DataAviso = null where CodConta = @CodConta", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodConta", CodConta);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
146
}
}
ClassEsfiha
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassEsfiha
{
ClassConexao Conecta = new ClassConexao();
private int codCadEsfiha;
public int CodCadEsfiha
{
get { return codCadEsfiha; }
set { codCadEsfiha = value; }
}
private string nomeEsfiha;
public string NomeEsfiha
{
get { return nomeEsfiha; }
set { nomeEsfiha = value; }
}
private string descricao;
public string Descricao
{
get { return descricao; }
set { descricao = value; }
}
private double valor;
public double Valor
{
get { return valor; }
set { valor = value; }
}
//
________________________________________________________________
147
148
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassFornecedor
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassFornecedor
{
private int codFornecedor;
public int CodFornecedor
{
get { return codFornecedor; }
set { codFornecedor = value; }
}
private string nomeEmpresa;
public string NomeEmpresa
{
get { return nomeEmpresa; }
set { nomeEmpresa = value; }
}
private string cnpj;
public string Cnpj
{
get { return cnpj; }
set { cnpj = value; }
}
private string nomeRepresentante;
public string NomeRepresentante
{
get { return nomeRepresentante; }
set { nomeRepresentante = value; }
}
private string telEmpresa;
public string TelEmpresa
{
get { return telEmpresa; }
set { telEmpresa = value; }
}
149
150
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraForn()
{
SqlCommand cmd = new SqlCommand("Update Fornecedor set
NomeEmpresa = @NomeEmpresa, NomeRepresentante = @NomeRepresentante,
CNPJ = @CNPJ, TelEmpresa = @TelEmpresa, TelRepresentante =
@TelRepresentante where CodFornecedor = @CodFornecedor",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodFornecedor",
CodFornecedor);
cmd.Parameters.AddWithValue("@NomeEmpresa",
NomeEmpresa);
cmd.Parameters.AddWithValue("@NomeRepresentante",
NomeRepresentante);
cmd.Parameters.AddWithValue("@CNPJ", Cnpj);
cmd.Parameters.AddWithValue("@TelRepresentante",
TelRepresentante);
cmd.Parameters.AddWithValue("@TelEmpresa",
TelEmpresa);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraFornSemTelRepre()
{
SqlCommand cmd = new SqlCommand("Update Fornecedor set
NomeEmpresa = @NomeEmpresa, NomeRepresentante = @NomeRepresentante,
CNPJ = @CNPJ, TelEmpresa = @TelEmpresa where CodFornecedor =
@CodFornecedor", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodFornecedor",
CodFornecedor);
cmd.Parameters.AddWithValue("@NomeEmpresa",
NomeEmpresa);
cmd.Parameters.AddWithValue("@NomeRepresentante",
NomeRepresentante);
cmd.Parameters.AddWithValue("@CNPJ", Cnpj);
cmd.Parameters.AddWithValue("@TelEmpresa",
TelEmpresa);
cmd.ExecuteNonQuery();
151
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiForn()
{
SqlCommand cmd = new SqlCommand("Delete from Fornecedor
where CodFornecedor = @CodFornecedor", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodFornecedor",
CodFornecedor);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassFuncionario
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
System.Data;
namespace IniciandoDavilla
{
class ClassFuncionario
{
private int codFuncionario;
public int CodFuncionario
{
get { return codFuncionario; }
set { codFuncionario = value; }
}
private string nome;
public string Nome
{
get { return nome; }
set { nome = value; }
}
152
153
get { return codCargo; }
set { codCargo = value; }
}
private double adicionalSalario;
public double AdicionalSalario
{
get { return adicionalSalario; }
set { adicionalSalario = value; }
}
ClassConexao Conecta = new ClassConexao();
public SqlCommand TrocaNomeCargoPorCodigo(string
BuscaNomeCargo)
{
NomeCargo
}
public SqlCommand CadFun()
{
SqlCommand cmd = new SqlCommand("insert into
Funcionario(NomeFuncionario, Rua, Numero, Bairro, Cidade, Estado, CPF,
Telefone, CodCargo, AdicionalSalario) values (@NomeFuncionario, @Rua,
@Numero, @Bairro, @Cidade, @Estado, @CPF, @Telefone, @CodCargo,
@AdicionalSalario)", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@NomeFuncionario", Nome);
cmd.Parameters.AddWithValue("@Rua", Rua);
cmd.Parameters.AddWithValue("@Numero", Numero);
cmd.Parameters.AddWithValue("@Bairro", Bairro);
cmd.Parameters.AddWithValue("@Cidade", Cidade);
cmd.Parameters.AddWithValue("@Estado", Estado);
cmd.Parameters.AddWithValue("@CPF", Cpf);
cmd.Parameters.AddWithValue("@Telefone", Telefone);
cmd.Parameters.AddWithValue("@CodCargo", CodCargo);
154
cmd.Parameters.AddWithValue("@AdicionalSalario",
AdicionalSalario);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraFun()
{
SqlCommand cmd = new SqlCommand("Update Funcionario set
NomeFuncionario = @NomeFuncionario, Rua = @Rua, Numero = @Numero,
BAirro = @Bairro, Cidade = @Cidade, Estado = @Estado, CPF = @CPF,
Telefone = @Telefone, CodCargo = @CodCargo, AdicionalSalario =
@AdicionalSalario where CodFuncionario = @CodFuncionario",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodFuncionario",
CodFuncionario);
cmd.Parameters.AddWithValue("@NomeFuncionario", Nome);
cmd.Parameters.AddWithValue("@Rua", Rua);
cmd.Parameters.AddWithValue("@Numero", Numero);
cmd.Parameters.AddWithValue("@Bairro", Bairro);
cmd.Parameters.AddWithValue("@Cidade", Cidade);
cmd.Parameters.AddWithValue("@Estado", Estado);
cmd.Parameters.AddWithValue("@CPF", Cpf);
cmd.Parameters.AddWithValue("@Telefone", Telefone);
cmd.Parameters.AddWithValue("@CodCargo", CodCargo);
cmd.Parameters.AddWithValue("@AdicionalSalario",
AdicionalSalario);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiFun()
{
SqlCommand cmdL = new SqlCommand("Delete from login where
CodFuncionario = @CodFuncionario",Conecta.CON());
try
{
cmdL.Parameters.AddWithValue("@CodFuncionario",
CodFuncionario);
cmdL.ExecuteNonQuery();
}
catch { }
155
finally
{
Conecta.CON().Close();
}
SqlCommand cmd = new SqlCommand("Delete from Funcionario
where CodFuncionario = @CodFuncionario", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodFuncionario",
CodFuncionario);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassItemPedido
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassItemPedido
{
ClassConexao Conecta = new ClassConexao();
// ------------------------------------- Variaveis Get Set
private int codPedido;
public int CodPedido
{
get { return codPedido; }
set { codPedido = value; }
}
private int quantidade;
public int Quantidade
{
get { return quantidade; }
set { quantidade = value; }
}
private double valorUnitario;
public double ValorUnitario
156
{
get { return valorUnitario; }
set { valorUnitario = value; }
}
private int codPizza;
public int CodPizza
{
get { return codPizza; }
set { codPizza = value; }
}
private int codEsfiha;
public int CodEsfiha
{
get { return codEsfiha; }
set { codEsfiha = value; }
}
private int codBebida;
public int CodBebida
{
get { return codBebida; }
set { codBebida = value; }
}
private int codMarmitex;
public int CodMarmitex
{
get { return codMarmitex; }
set { codMarmitex = value; }
}
private int codSelf;
public int CodSelf
{
get { return codSelf; }
set { codSelf = value; }
}
private string obs;
public string Obs
{
get { return obs; }
set { obs = value; }
}
// ---------------------------------------------------------//
157
SqlCommand cmd = new SqlCommand("Insert Into ItemPedido
(CodPedido, Quantidade, ValorUnitario, CodPizza, Observacoes) values
(@CodPedido, @Quantidade, @ValorUnitario, @CodPizza, @Observacoes)",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@Quantidade",
Quantidade);
cmd.Parameters.AddWithValue("@ValorUnitario",
ValorUnitario);
cmd.Parameters.AddWithValue("@CodPizza", CodPizza);
//cmd.Parameters.AddWithValue("@CodEsfiha",CodEsfiha);
//cmd.Parameters.AddWithValue("@CodBebida",CodBebida);
//cmd.Parameters.AddWithValue("@CodMarmitex",CodMarmitex);
cmd.Parameters.AddWithValue("@Observacoes", Obs);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AdicionaItemPedidoBebida()
{
SqlCommand cmd = new SqlCommand("Insert Into ItemPedido
(CodPedido, Quantidade, ValorUnitario, CodBebida,Observacoes) values
(@CodPedido, @Quantidade, @ValorUnitario, @CodBebida, @Observacoes)",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@Quantidade",
Quantidade);
cmd.Parameters.AddWithValue("@ValorUnitario",
ValorUnitario);
//cmd.Parameters.AddWithValue("@CodPizza", CodPizza);
//cmd.Parameters.AddWithValue("@CodEsfiha",CodEsfiha);
cmd.Parameters.AddWithValue("@CodBebida", CodBebida);
//cmd.Parameters.AddWithValue("@CodMarmitex",CodMarmitex);
cmd.Parameters.AddWithValue("@Observacoes", Obs);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
158
}
public SqlCommand AdicionaItemPedidoEsfiha()
{
SqlCommand cmd = new SqlCommand("Insert Into ItemPedido
(CodPedido, Quantidade, ValorUnitario, CodEsfiha, Observacoes) values
(@CodPedido, @Quantidade, @ValorUnitario, @CodEsfiha, @Observacoes)",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@Quantidade",
Quantidade);
cmd.Parameters.AddWithValue("@ValorUnitario",
ValorUnitario);
//cmd.Parameters.AddWithValue("@CodPizza", CodPizza);
cmd.Parameters.AddWithValue("@CodEsfiha", CodEsfiha);
//cmd.Parameters.AddWithValue("@CodBebida",CodBebida);
//cmd.Parameters.AddWithValue("@CodMarmitex",CodMarmitex);
cmd.Parameters.AddWithValue("@Observacoes", Obs);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AdicionaItemPedidoMarmitex()
{
SqlCommand cmd = new SqlCommand("Insert Into ItemPedido
(CodPedido, Quantidade, ValorUnitario, CodMarmitex, Observacoes)
values (@CodPedido, @Quantidade, @ValorUnitario, @CodMarmitex,
@Observacoes)", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@Quantidade",
Quantidade);
cmd.Parameters.AddWithValue("@ValorUnitario",
ValorUnitario);
//cmd.Parameters.AddWithValue("@CodPizza", CodPizza);
//cmd.Parameters.AddWithValue("@CodEsfiha",CodEsfiha);
//cmd.Parameters.AddWithValue("@CodBebida",CodBebida);
cmd.Parameters.AddWithValue("@CodMarmitex",
CodMarmitex);
cmd.Parameters.AddWithValue("@Observacoes", Obs);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
159
}
return cmd;
}
public SqlCommand AdicionaItemPedidoSelf()
{
SqlCommand cmd = new SqlCommand("Insert Into ItemPedido
(CodPedido, Quantidade, ValorUnitario, CodSelfService) values
(@CodPedido, @Quantidade, @ValorUnitario, @CodSelfService)",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@Quantidade",
Quantidade);
cmd.Parameters.AddWithValue("@ValorUnitario",
ValorUnitario);
cmd.Parameters.AddWithValue("@CodSelfService",
CodSelf);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassLogin
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassLogin
{
ClassConexao Conecta = new ClassConexao();
private string nomeUsuario;
160
public string NomeUsuario
{
get { return nomeUsuario; }
set { nomeUsuario = value; }
}
private string senha;
public string Senha
{
get { return senha; }
set { senha = value; }
}
private int codFunc;
public int CodFunc
{
get { return codFunc; }
set { codFunc = value; }
}
161
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand Excluir()
{
SqlCommand cmd = new SqlCommand("Delete from Login where
CodFuncionario = @CodFuncionario", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodFuncionario",
CodFunc);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassMarmitex
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassMarmitex
{
ClassConexao Conecta = new ClassConexao();
private int codMarmitex;
public int CodMarmitex
{
get { return codMarmitex; }
set { codMarmitex = value; }
}
private string descricao;
public string Descricao
{
162
get { return descricao; }
set { descricao = value; }
}
private string diaSemana;
public string DiaSemana
{
get { return diaSemana; }
set { diaSemana = value; }
}
private double valor;
public double Valor
{
get { return valor; }
set { valor = value; }
}
//_________________________________________________Mtodos
agora____________________________________________
public SqlCommand CadMarmitex()
{
SqlCommand cmd = new SqlCommand("Insert Into Marmitex
(Descricao, DiaSemana, Valor) values (@Descricao, @DiaSemana,
@Valor)", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@Descricao", Descricao);
cmd.Parameters.AddWithValue("@DiaSemana", DiaSemana);
cmd.Parameters.AddWithValue("Valor", Valor);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlterMarmitex()
{
SqlCommand cmd = new SqlCommand("Update Marmitex set
Descricao = @Descricao, DiaSemana = @DiaSemana, Valor = @Valor where
CodMarmitex = @CodMarmitex",Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodMarmitex",
CodMarmitex);
cmd.Parameters.AddWithValue("@Descricao", Descricao);
cmd.Parameters.AddWithValue("@DiaSemana", DiaSemana);
cmd.Parameters.AddWithValue("Valor", Valor);
cmd.ExecuteNonQuery();
163
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiMarmitex()
{
SqlCommand cmd = new SqlCommand("Delete from Marmitex
where CodMarmitex = @CodMarmitex", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodMarmitex",
CodMarmitex);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassPedido
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassPedido
{
ClassConexao Conecta = new ClassConexao();
private int codPedido;
public int CodPedido
{
get { return codPedido; }
set { codPedido = value; }
}
private int codCliente;
public int CodCliente
{
get { return codCliente; }
set { codCliente = value; }
}
164
165
166
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaCodCliente()
{
SqlCommand cmd = new SqlCommand("Update Pedido set
CodCliente = @CodCliente where CodPedido = @CodPedido",Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@CodCliente",
CodCliente);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand FecharPedido()
{
SqlCommand cmd = new SqlCommand("Update Pedido Set
ValorTotal = @ValorTotal, FormaPagamento = @FormaPagamento,
StatusPedido = @StatusPedido, Observacoes = @Observacoes,
CodFuncionario = @CodFuncionario, Hora = @Hora, Data = @Data where
CodPedido = @CodPedido", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@ValorTotal",
ValorTotal);
cmd.Parameters.AddWithValue("@FormaPagamento",
FormaPagamento);
cmd.Parameters.AddWithValue("@StatusPedido",
StatusPedido);
cmd.Parameters.AddWithValue("@Observacoes", Obs);
cmd.Parameters.AddWithValue("@CodFuncionario",
CodFuncionario);
cmd.Parameters.AddWithValue("@Hora", Hora);
cmd.Parameters.AddWithValue("@Data", Data);
cmd.ExecuteNonQuery();
}
167
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaTotal()
{
SqlCommand cmd = new SqlCommand("Update Pedido Set
ValorTotal = @ValorTotal where CodPedido = @CodPedido",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@ValorTotal",
ValorTotal);
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraPedido()
{
SqlCommand cmd = new SqlCommand("Update Pedido Set
CodFuncionario = @CodFuncionario, TipoPedido = @TipoPedido, Data =
@Data, Hora = @Hora, ValorTotal = @ValorTotal, FormaPagamento =
@FormaPagamento, NumeroMesa = @NumeroMesa, StatusPedido =
@StatusPedido where CodPedido = @CodPedido", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@CodFuncionario",
CodFuncionario);
cmd.Parameters.AddWithValue("@TipoPedido",
TipoPedido);
cmd.Parameters.AddWithValue("@Data", Data);
cmd.Parameters.AddWithValue("@Hora", Hora);
cmd.Parameters.AddWithValue("@ValorTotal",
ValorTotal);
cmd.Parameters.AddWithValue("@FormaPagamento",
FormaPagamento);
cmd.Parameters.AddWithValue("@NumeroMesa",
NumeroMesa);
cmd.Parameters.AddWithValue("@StatusPedido",
StatusPedido);
//cmd.Parameters.AddWithValue("@NumeroComanda",NumeroComanda);
168
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand DeletaCodCliente()
{
SqlCommand cmd = new SqlCommand("Update Pedido Set
CodCliente = null where CodPedido = @CodPedido", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand DeletaTodosPedidos()
{
SqlCommand cmd = new SqlCommand("Delete from ItemPedido",
Conecta.CON());
try
{
SqlCommand cmd2 = new SqlCommand("Delete from Pedido",
Conecta.CON());
cmd.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand DeleteUmPedido()
{
SqlCommand cmd = new SqlCommand("Delete from ItemPedido
where CodPedido = " + CodPedido, Conecta.CON());
try
169
{
cmd.ExecuteNonQuery();
SqlCommand cmd2 = new SqlCommand("Delete from Pedido
where CodPedido = " + CodPedido, Conecta.CON());
cmd2.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraNumeroComanda()
{
SqlCommand cmd = new SqlCommand("Update Pedido Set
NumeroComanda=@NumeroComanda where CodPedido = @CodPedido",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@NumeroComanda",
NumeroComanda);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand DeletaNumeroComanda()
{
SqlCommand cmd = new SqlCommand("Update Pedido Set
NumeroComanda = null where CodPedido = @CodPedido", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraEntragador()
{
SqlCommand cmd = new SqlCommand("Update Pedido Set
Entregador=@Entregador where CodPedido = @CodPedido", Conecta.CON());
try
170
{
cmd.Parameters.AddWithValue("@CodPedido", CodPedido);
cmd.Parameters.AddWithValue("@Entregador",
Entregador);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassPizza
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassPizza
{
ClassConexao Conecta = new ClassConexao();
private int codPizza;
public int CodPizza
{
get { return codPizza; }
set { codPizza = value; }
}
private string nomePizza;
public string NomePizza
{
get { return nomePizza; }
set { nomePizza = value; }
}
171
private double valor;
public double Valor
{
get { return valor; }
set { valor = value; }
}
linha
SqlCommand cmd = new SqlCommand("Update Pizza set
NomePizza = @NomePizza, Descricao = @Descricao, Valor = @Valor where
CodPizza = @CodPizza", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodPizza", CodPizza);
cmd.Parameters.AddWithValue("@NomePizza", NomePizza);
cmd.Parameters.AddWithValue("@Descricao", Descricao);
cmd.Parameters.AddWithValue("@Valor", Valor);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiPizza()
{
SqlCommand cmd = new SqlCommand("delete from Pizza where
CodPizza = @CodPizza", Conecta.CON());
try
172
{
cmd.Parameters.AddWithValue("@CodPizza", CodPizza);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClasseProdutoEstoque
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassProdutoEstoque
{
private int codProdutoEstoque;
public int CodProdutoEstoque
{
get { return codProdutoEstoque; }
set { codProdutoEstoque = value; }
}
private string codFornecedor;
public string CodFornecedor
{
get { return codFornecedor; }
set { codFornecedor = value; }
}
private string descricao;
public string Descricao
{
get { return descricao; }
set { descricao = value; }
}
private string tipoUnidade;
public string TipoUnidade
{
get { return tipoUnidade; }
set { tipoUnidade = value; }
}
173
174
175
{
cmd.Parameters.AddWithValue("@CodFornecedor",
CodFornecedor);
cmd.Parameters.AddWithValue("@Descricao", Descricao);
cmd.Parameters.AddWithValue("@TipoUnidade",
TipoUnidade);
cmd.Parameters.AddWithValue("@Quantidade",
Quantidade);
cmd.Parameters.AddWithValue("@Validade", Validade);
cmd.Parameters.AddWithValue("@Observacoes",
Observacoes);
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand CadDataAviso()
{
SqlCommand cmd = new SqlCommand("Update Estoque SET
DataAviso = @DataAviso where CodProdutoEstoque = @CodProdutoEstoque",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodProdutoEstoque",
CodProd);
cmd.Parameters.AddWithValue("@DataAviso", DataAviso);
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand CadEstoqueMinimo()
{
SqlCommand cmd = new SqlCommand("UPDATE Estoque SET
EstoqueMin = @EstoqueMin where CodProdutoEstoque =
@CodProdutoEstoque", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodProdutoEstoque",
CodProd);
176
cmd.Parameters.AddWithValue("@EstoqueMin",
EstoqueMin);
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraEstoque()
{
SqlCommand cmd = new SqlCommand("UPDATE Estoque SET
CodFornecedor = @CodFornecedor, Descricao = @Descricao, TipoUnidade =
@TipoUnidade, Quantidade = @Quantidade, Validade = @Validade,
Observacoes = @Observacoes where CodProdutoEstoque =
@CodProdutoEstoque", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodProdutoEstoque",
CodProd);
cmd.Parameters.AddWithValue("@CodFornecedor",
CodFornecedor);
cmd.Parameters.AddWithValue("@Descricao", Descricao);
cmd.Parameters.AddWithValue("@TipoUnidade",
TipoUnidade);
cmd.Parameters.AddWithValue("@Quantidade",
Quantidade);
cmd.Parameters.AddWithValue("@Validade", Validade);
cmd.Parameters.AddWithValue("@Observacoes",
Observacoes);
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiEstoque()
{
SqlCommand cmd = new SqlCommand("DELETE FROM Estoque where
CodProdutoEstoque = @CodProdutoEstoque", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodProdutoEstoque",
CodProdutoEstoque);
177
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiDataAviso()
{
SqlCommand cmd = new SqlCommand("UPDATE Estoque SET
DataAviso = null where CodProdutoEstoque = @CodProdutoEstoque",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodProdutoEstoque",
CodProd);
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiEstoqueMinimo()
{
SqlCommand cmd = new SqlCommand("UPDATE Estoque SET
EstoqueMin = null where CodProdutoEstoque = @CodProdutoEstoque",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodProdutoEstoque",
CodProd);
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand ExcluiTodoEstoque()
{
178
SqlCommand cmd = new SqlCommand("DELETE Estoque",
Conecta.CON());
try
{
cmd.ExecuteNonQuery();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
ClassSelfService
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Data;
System.Data.SqlClient;
namespace IniciandoDavilla
{
class ClassSelfService
{
private string codSelf;
public string CodSelf
{
get { return codSelf; }
set { codSelf = value; }
}
private string tipoSelf;
public string TipoSelf
{
get { return tipoSelf; }
set { tipoSelf = value; }
}
private double valor;
public double Valor
{
get { return valor; }
set { valor = value; }
}
ClassConexao Conecta = new ClassConexao();
public SqlCommand Cadastrar()
179
{
SqlCommand cmd = new SqlCommand("Insert into SelfService
(TipoSelfService) values (@TipoSelfService)",Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@TipoSelfService",
TipoSelf);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand Alterar()
{
SqlCommand cmd = new SqlCommand("Update SelfService set
TipoSelfService = @TipoSelfService, Valor = @Valor where
CodSelfService = @CodSelfService", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodSelfService",
CodSelf);
cmd.Parameters.AddWithValue("@TipoSelfService",
TipoSelf);
cmd.Parameters.AddWithValue("@Valor", Valor);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand Excluir()
{
SqlCommand cmd = new SqlCommand("Delete SelfService where
CodSelfService = @CodSelfService", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodSelfService",
CodSelf);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AlteraSelfValor()
180
{
SqlCommand cmd = new SqlCommand("Update SelfService set
Valor = @Valor where CodSelfService = @CodSelfService",
Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodSelfService",
CodSelf);
cmd.Parameters.AddWithValue("@Valor", Valor);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand DeletaPrecoQuilo()
{
SqlCommand cmd = new SqlCommand("Update SelfService set
Valor = null where CodSelfService = @CodSelfService", Conecta.CON());
try
{
cmd.Parameters.AddWithValue("@CodSelfService",
CodSelf);
cmd.ExecuteNonQuery();
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
}
}
frmCadBebida
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadBebida : Form
{
public frmCadBebida()
{
InitializeComponent();
}
181
182
}
catch
{
}
finally
{
con.CON().Close();
}
}
private void btnNovaBebida_Click(object sender, EventArgs e)
{
if (txtDescricao.Text != "" || txtPreco.Text != "" ||
txtTipo.Text != "" )
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
LimparCampos();
txtDescricao.Focus();
}
}
else
{
LimparCampos();
txtDescricao.Focus();
}
}
private void btnAlterarBebida_Click(object sender, EventArgs
e)
{
if (codBebida == "" || txtDescricao.Text == "" ||
txtTipo.Text == "" || txtPreco.Text == "")
{
MessageBox.Show("Selecione uma Bebida para alterar",
"Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
//altera no banco e atualiza a combo e o datagrid
bebida.CodCadBebida = int.Parse(codBebida);
bebida.Descricao = txtDescricao.Text;
bebida.TipoUnidade = txtTipo.Text;
bebida.Valor = double.Parse(txtPreco.Text);
bebida.AlterBebida();
MessageBox.Show("Dados Alterados", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Atualizar();
BuscaBebida();
LimparCampos();
txtDescricao.Focus();
183
}
catch
{
}
finally
{
con.CON().Close();
}
}
}
private void btnExcluirBebida_Click(object sender, EventArgs
e)
{
//exclui do banco e atualiza a combo e o datagrid
if (codBebida == "")
{
MessageBox.Show("Selecione uma bebida para excluir",
"ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
DialogResult dr = MessageBox.Show("Tem certeza de
que deseja Excluir?", "Excluir Bebidas", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
bebida.CodCadBebida = int.Parse(codBebida);
bebida.ExcluiBebida();
MessageBox.Show("Dados Excluidos", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
LimparCampos();
Atualizar();
BuscaBebida();
}
}
catch
{
MessageBox.Show("Impossvel excluir esse
registro\nPode haver pedidos com este item", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.CON().Close();
}
}
}
private void btnLimpar_Click(object sender, EventArgs e)
{
cmbConsulta.Text = "";
cmbConsulta.Focus();
Atualizar();
}
184
185
txtPreco.Text =
dataGridView1.SelectedCells[3].Value.ToString();
}
private void cmbConsulta_TextChanged(object sender, EventArgs
e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from
Bebida where Descricao like '%" + cmbConsulta.Text + "%'", con.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
con.CON().Close();
}
}
private void cmbConsulta_SelectedIndexChanged(object sender,
EventArgs e)
{
if (cmbConsulta.Text == "")
{ }
else
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select *
from Bebida where Descricao like '%" + cmbConsulta.Text + "%'",
con.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch { }
finally
{
con.CON().Close();
}
}
}
private void txtPreco_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadBebida_Click(sender, e);
break;
}
}
private void txtPreco_KeyPress(object sender,
KeyPressEventArgs e)
186
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
}
}
frmCadCargo
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadCargo : Form
{
public frmCadCargo()
{
InitializeComponent();
}
ClassCargo ClasseCargo = new ClassCargo();
ClassConexao Conecta = new ClassConexao();
string CodCargo;
public void BuscaTodosCargos()
{
SqlDataAdapter da = new SqlDataAdapter("select * from
Cargo order by NomeCargo", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
public void Limpar()
{
CodCargo = "";
txtNomeCargo.Clear();
txtSalario.Clear();
cmbBuscaNomeCargo.SelectedIndex = -1;
}
187
188
if (txtBusca.Text == "")
{
BuscaTodosCargos();
}
else
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Cargo where NomeCargo like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
catch
{
MessageBox.Show("Erro text changed txtBusca");
}
}
private void frmCadCargo_Load(object sender, EventArgs e)
{
BuscaTodosCargos();
CodCargo = "";
}
private void cmbBuscaNomeCargo_Click(object sender, EventArgs
e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from
Cargo order by NomeCargo", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
cmbBuscaNomeCargo.DataSource = ds.Tables[0];
cmbBuscaNomeCargo.DisplayMember = "NomeCargo";
cmbBuscaNomeCargo.SelectedIndex = -1;
}
catch
{
MessageBox.Show("Erro click cmb buscaNomeCargo");
}
}
private void cmbBuscaNomeCargo_SelectedIndexChanged(object
sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("Select * from Cargo
where NomeCargo = '"+ cmbBuscaNomeCargo.Text +"'",Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
CodCargo = dr["CodCargo"].ToString();
txtNomeCargo.Text = dr["NomeCargo"].ToString();
txtSalario.Text = dr["Salario"].ToString();
}
}
private void btnAlterar_Click(object sender, EventArgs e)
{
189
try
{
if (txtNomeCargo.Text == "ADMINISTRADOR")
{
ClasseCargo.CodCargo = int.Parse(CodCargo);
ClasseCargo.NomeCargo = "Administrador";
ClasseCargo.Salario =
double.Parse(txtSalario.Text);
ClasseCargo.AlteraCargo();
}
else
{
ClasseCargo.CodCargo = int.Parse(CodCargo);
ClasseCargo.NomeCargo = txtNomeCargo.Text;
ClasseCargo.Salario =
double.Parse(txtSalario.Text);
ClasseCargo.AlteraCargo();
}
MessageBox.Show("Dados do Cargo Alterados!",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
BuscaTodosCargos();
}
catch
{
MessageBox.Show("Erro btn Alterar cargo");
}
finally
{
Conecta.CON().Close();
}
}
private void btnNovo_Click(object sender, EventArgs e)
{
if (txtNomeCargo.Text != "" || txtSalario.Text != "" )
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
Limpar();
}
}
else
{
Limpar();
}
}
private void btnExcluir_Click(object sender, EventArgs e)
{
try
{
if (CodCargo == "1" || CodCargo == "2")
{
190
MessageBox.Show("Impossvel excluir esse
registro", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
DialogResult dr = MessageBox.Show("Tem certeza que
deseja excluir esse cargo?", "Excluir", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
ClasseCargo.CodCargo = int.Parse(CodCargo);
ClasseCargo.ExcluiCargo();
MessageBox.Show("Cargo Excludo", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Limpar();
BuscaTodosCargos();
}
}
catch
{
MessageBox.Show("Impossvel excluir esse
registro\nPode haver funcionrios com este cargo", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Conecta.CON().Close();
}
}
private void dataGridView1_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
CodCargo =
dataGridView1.SelectedCells[0].Value.ToString();
txtNomeCargo.Text =
dataGridView1.SelectedCells[1].Value.ToString();
txtSalario.Text =
dataGridView1.SelectedCells[2].Value.ToString();
tabControl.SelectedTab = tabControl.TabPages[0];
}
191
string valor =
dgv.Rows[e.RowIndex].Cells[2].Value.ToString();
if (valor == "0,00")
{
/* Alterando cor do Fundo */
//dgv.CurrentRow.DefaultCellStyle.BackColor =
Color.Blue;
/* Alterando cor da fonte */
dgv.Rows[e.RowIndex].DefaultCellStyle.ForeColor =
Color.Red;
}
}
private void txtSalario_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadastrar_Click(sender, e);
break;
}
}
private void txtNomeCargo_TextChanged(object sender, EventArgs
e)
{
if (txtNomeCargo.Text == "ADMINISTRADOR")
{
txtNomeCargo.Enabled = false;
}
else
{
txtNomeCargo.Enabled = true;
}
}
private void txtSalario_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
}
}
frmCadCliente
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
192
namespace IniciandoDavilla
{
public partial class frmCadCliente : Form
{
public frmCadCliente()
{
InitializeComponent();
}
string VerificaTelDuplicado;
string CodCli = "";
private string lista;
public string Lista
{
get { return lista; }
set { lista = value; }
}
private string telListaNegra;
public string TelListaNegra
{
get { return telListaNegra; }
set { telListaNegra = value; }
}
ClassConexao Conecta = new ClassConexao();
ClassCliente classeCliente = new ClassCliente();
private void btnSair_Click(object sender, EventArgs e)
{
this.Close();
}
193
{
Conecta.CON().Close();
}
return cmd;
}
public void BuscaTodosClientes()
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
Cliente", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON();
}
}
194
classeCliente.Estado = txtEstado.Text;
classeCliente.PontoRef = txtPtoRef.Text;
if (checkListaNegra.Checked)
{
classeCliente.ListaNegra = "Sim";
}
else
{
classeCliente.ListaNegra = "No";
}
classeCliente.CadCliente();
MessageBox.Show("Cliente Cadastrado com Sucesso",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
LimparCampos();
BuscaTodosClientes();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnConsultar_Click(object sender, EventArgs e)
{
BuscaTodosClientes();
}
private void txtBusca_TextChanged(object sender, EventArgs e)
{
try
{
if (checkConsultaListaNegra.Checked)
{
if (cmbConsultarPor.Text == "Nome")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Cliente where ListaNegra = 'Sim' and NomeCliente Like '%" +
txtBusca.Text + "%' ", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "Cdigo")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Cliente where ListaNegra = 'Sim' and CodCliente like '%" +
txtBusca.Text + "%'", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
195
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text ==
"Telefone/Celular")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Cliente where ListaNegra = 'Sim' and Telefone like '%" +
txtBusca.Text + "%' or Celular like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
else
{
if (cmbConsultarPor.Text == "Nome")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Cliente where NomeCliente Like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "Cdigo")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Cliente where CodCliente like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text ==
"Telefone/Celular")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Cliente where Telefone like '%" + txtBusca.Text + "%' or
Celular like '%" + txtBusca.Text + "%'", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void cmbConsultarPor_SelectedIndexChanged(object
sender, EventArgs e)
{
BuscaTodosClientes();
196
txtBusca.Text = "";
}
private void cmbConsultarPor_TextChanged(object sender,
EventArgs e)
{
if (cmbConsultarPor.Text == "Telefone/Celular")
{
txtBusca.Mask = "(00) 0000-0000";
}
else
{
txtBusca.Mask = "";
}
}
197
catch
{
MessageBox.Show("Erro selected index Changed combo
busca nome fun");
}
finally
{
Conecta.CON().Close();
}
}
}
public void LimparCampos()
{
txtNome.Clear();
txtCel.Clear();
txtTelefone.Clear();
txtRua.Clear();
txtNumero.Clear();
txtBairro.Clear();
txtCidade.Clear();
txtEstado.Clear();
txtPtoRef.Clear();
cmbBuscaNomeCli.SelectedIndex = -1;
checkListaNegra.Checked = false;
}
private void btnNovo_Click(object sender, EventArgs e)
{
if (txtNome.Text != "" || txtBairro.Text != "" ||
txtCidade.Text != "" || txtTelefone.Text != "( )
-" ||
txtCel.Text != "( )
-" || txtEstado.Text != "" || txtPtoRef.Text
!= "" || txtRua.Text != "" || txtNumero.Text != "" )
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para cadastrar um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
LimparCampos();
}
}
else
{
LimparCampos();
}
}
private void btnAlterar_Click(object sender, EventArgs e)
{
if (txtBairro.Text == "" || txtCidade.Text == "" ||
txtCel.Text == "" || txtEstado.Text == "" || txtNome.Text == "" ||
txtNumero.Text == "" || txtRua.Text == "" || txtTelefone.Text == "")
{
198
MessageBox.Show("Preencha todos os campos para
completar o cadastro!", "ERRO", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
try
{
classeCliente.CodCliente = int.Parse(CodCli);
classeCliente.Nome = txtNome.Text;
classeCliente.Telefone = txtTelefone.Text;
classeCliente.Celular = txtCel.Text;
classeCliente.Rua = txtRua.Text;
classeCliente.Numero =
int.Parse(txtNumero.Text).ToString();
classeCliente.Bairro = txtBairro.Text;
classeCliente.Cidade = txtCidade.Text;
classeCliente.Estado = txtEstado.Text;
classeCliente.PontoRef = txtPtoRef.Text;
if (checkListaNegra.Checked)
{
classeCliente.ListaNegra = "Sim";
}
else
{
classeCliente.ListaNegra = "No";
}
classeCliente.AlteraCliente();
MessageBox.Show("Dados Alterados com Sucesso",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
LimparCampos();
BuscaTodosClientes();
}
catch
{
MessageBox.Show("Erro ao Alterar");
}
finally
{
Conecta.CON().Close();
}
}
}
private void btnExclui_Click(object sender, EventArgs e)
{
try
{
if (CodCli == "")
{
MessageBox.Show("Selecione um cliente para
excluir", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
199
DialogResult dr = MessageBox.Show("Tem certeza de
que deseja Excluir este Cliente?", "Excluir Cliente",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
classeCliente.CodCliente = int.Parse(CodCli);
classeCliente.ExcluiCliente();
MessageBox.Show("Cliente excludo do sistema",
"SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
LimparCampos();
BuscaTodosClientes();
}
}
}
catch
{
MessageBox.Show("Impossvel excluir esse
registro\nPode haver pedidos para este cliente", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Conecta.CON(). Close();
}
}
private void frmCadCliente_Load(object sender, EventArgs e)
{
BuscaTodosClientes();
LimparCampos();
if (Lista == "Sim")
{
cmbConsultarPor.SelectedIndex = 2;
txtBusca.Text = TelListaNegra;
tabControl.SelectedTab = tabControl.TabPages[1];
}
else if (Lista == "Novo")
{
txtTelefone.Text = TelListaNegra;
}
else { }
}
private void cmbBuscaNomeCli_Click(object sender, EventArgs e)
{
try
{
cmbBuscaNomeCli.DataSource =
classeCliente.TrazTodosClientes();
200
cmbBuscaNomeCli.DisplayMember =
classeCliente.TrazTodosClientes().ToString();
cmbBuscaNomeCli.DisplayMember = "NomeCliente";
cmbBuscaNomeCli.SelectedIndex = -1;
}
catch { }
finally
{
Conecta.CON().Close();
}
}
private void txtNumero_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 )
{
e.Handled = true;
}
}
private void txtPtoRef_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadastrar_Click(sender, e);
break;
}
}
private void dataGridView1_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
CodCli =
dataGridView1.SelectedCells[0].Value.ToString();
SqlCommand cmd = new SqlCommand("Select * from
Cliente where CodCliente = " + CodCli, Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtNome.Text =
dataGridView1.SelectedCells[1].Value.ToString();
txtRua.Text =
dataGridView1.SelectedCells[2].Value.ToString();
txtNumero.Text =
dataGridView1.SelectedCells[3].Value.ToString();
txtBairro.Text =
dataGridView1.SelectedCells[4].Value.ToString();
txtCidade.Text =
dataGridView1.SelectedCells[5].Value.ToString();
txtEstado.Text =
dataGridView1.SelectedCells[6].Value.ToString();
txtPtoRef.Text =
dataGridView1.SelectedCells[7].Value.ToString();
201
txtTelefone.Text =
dataGridView1.SelectedCells[8].Value.ToString();
txtCel.Text =
dataGridView1.SelectedCells[9].Value.ToString();
string lista =
dr["ListaNegra"].ToString();
if (lista == "Sim")
{
checkListaNegra.Checked = true;
}
else
{
checkListaNegra.Checked = false;
}
tabControl.SelectedTab =
tabControl.TabPages[0];
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmCadEsfiha
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadEsfiha : Form
{
public frmCadEsfiha()
{
InitializeComponent();
}
string codEsfiha = "";
private string cargo;
public string Cargo
{
get { return cargo; }
set { cargo = value; }
}
202
203
if (codEsfiha == "" || txtDescricao.Text == "" ||
txtNome.Text == "" || txtValor.Text == "")
{
MessageBox.Show("Erro ao alterar Esfiha \n
Verifique se todos os campos esto preenchidos", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
esfiha.CodCadEsfiha = int.Parse(codEsfiha);
esfiha.NomeEsfiha = txtNome.Text;
esfiha.Descricao = txtDescricao.Text;
esfiha.Valor = double.Parse(txtValor.Text);
esfiha.AlterEsfiha();
MessageBox.Show("Dados Alterados", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Atualizar();
BuscaEsfiha();
LimparCampos();
txtNome.Focus();
}
}
catch
{
}
finally
{
con.CON().Close();
}
}
private void btnExcluirEsfiha_Click(object sender, EventArgs
e)
{
try
{
if (codEsfiha == "")
{
MessageBox.Show("Selecione uma Esfiha para
excluir", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
DialogResult dr = MessageBox.Show("Tem certeza de
que deseja Excluir?", "Excluir Esfiha", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
esfiha.CodCadEsfiha = int.Parse(codEsfiha);
esfiha.ExcluiEsfiha();
MessageBox.Show("Dados Excluidos", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
LimparCampos();
Atualizar();
BuscaEsfiha();
204
}
}
}
catch
{
MessageBox.Show("Impossvel excluir esse
registro\nPode haver pedidos com este item", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
con.CON().Close();
}
}
private void btnCadEsfiha_Click(object sender, EventArgs e)
{
try
{
if (txtDescricao.Text == "" || txtNome.Text == "" ||
txtValor.Text == "")
{
MessageBox.Show("Erro ao Cadastrar Esfiha \n
Verifique se todos os campos esto preenchidos", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
esfiha.NomeEsfiha = txtNome.Text;
esfiha.Descricao = txtDescricao.Text;
esfiha.Valor = double.Parse(txtValor.Text);
esfiha.CadEsfiha();
MessageBox.Show("Dados Cadastrados", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Atualizar();
BuscaEsfiha();
LimparCampos();
txtNome.Focus();
}
}
catch
{
}
finally
{
con.CON().Close();
}
}
private void frmCadEsfiha_Load(object sender, EventArgs e)
{
if (Cargo == "Administrador")
gbEsfiha.Enabled = true;
else
gbEsfiha.Enabled = false;
205
BuscaEsfiha();
Atualizar();
}
private void btnLimpar_Click(object sender, EventArgs e)
{
cmbConsulta.Text = "";
cmbConsulta.Focus();
Atualizar();
}
private void cmbConsulta_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from
Esfiha where NomeEsfiha like '%" + cmbConsulta.Text + "%'",
con.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgvEsfiha.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
con.CON().Close();
}
}
private void cmbConsulta_TextChanged(object sender, EventArgs
e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from
Esfiha where NomeEsfiha like '%" + cmbConsulta.Text + "%'",
con.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgvEsfiha.DataSource = ds.Tables[0];
}
catch { }
finally
{
con.CON().Close();
}
}
private void dgvEsfiha_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
codEsfiha = dgvEsfiha.SelectedCells[0].Value.ToString();
txtNome.Text =
dgvEsfiha.SelectedCells[1].Value.ToString();
txtDescricao.Text =
dgvEsfiha.SelectedCells[2].Value.ToString();
206
txtValor.Text =
dgvEsfiha.SelectedCells[3].Value.ToString();
}
private void txtValor_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadEsfiha_Click(sender, e);
break;
}
}
private void txtValor_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
}
}
frmCadFornecedor
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadFornecedor : Form
{
public frmCadFornecedor()
{
InitializeComponent();
}
string CodForn;
string VerificaCNPJduplicado;
ClassFornecedor ClasseForn = new ClassFornecedor();
ClassConexao Conecta = new ClassConexao();
public void Limpar()
{
txtNome.Clear();
txtCNPJ.Clear();
207
txtRepresentante.Clear();
txtTelefone.Clear();
txtTelRepre.Clear();
cmbBuscaNomeForn.SelectedIndex = -1;
CodForn = "";
}
public void BuscaTodosFornecedores()
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
Fornecedor", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
public SqlCommand VerificaDuplicacaoFornecedor()
{
SqlCommand cmd = new SqlCommand("Select * from Fornecedor
where CNPJ = '" + txtCNPJ.Text + "'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
VerificaCNPJduplicado = dr["CNPJ"].ToString();
}
return cmd;
}
public SqlDataAdapter PopulaCombo()
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Fornecedor order by NomeEmpresa", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbBuscaNomeForn.DataSource = dt;
cmbBuscaNomeForn.DisplayMember = "NomeEmpresa";
cmbBuscaNomeForn.SelectedIndex = -1;
return cmd;
}
private void cmbBuscaNomeForn_SelectedIndexChanged(object
sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("Select * from
Fornecedor where NomeEmpresa = '" + cmbBuscaNomeForn.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
CodForn = dr["CodFornecedor"].ToString();
txtNome.Text = dr["NomeEmpresa"].ToString();
txtCNPJ.Text = dr["CNPJ"].ToString();
txtTelefone.Text = dr["TelEmpresa"].ToString();
txtRepresentante.Text =
dr["NomeRepresentante"].ToString();
208
txtTelRepre.Text =
dr["TelRepresentante"].ToString();
}
}
catch
{
}
}
private void btnNovo_Click(object sender, EventArgs e)
{
if (txtNome.Text != "" || txtCNPJ.Text != " ,
,
/
-" || txtRepresentante.Text != "" || txtTelefone.Text != "( )
-"
|| txtTelRepre.Text != "( )
-")
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
Limpar();
}
}
else
{
Limpar();
}
}
private void btnCadastrar_Click(object sender, EventArgs e)
{
try
{
VerificaDuplicacaoFornecedor();
if (txtNome.Text == "")
{
MessageBox.Show("Preencha pelo menos o campo:
'Nome da Empresa' para completar o cadastro!", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (VerificaCNPJduplicado == txtCNPJ.Text)
{
MessageBox.Show("Este Fornecedor j consta no
sistema!", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (txtTelRepre.Text != " / /")
{
ClasseForn.NomeEmpresa = txtNome.Text;
ClasseForn.Cnpj = txtCNPJ.Text;
ClasseForn.NomeRepresentante =
txtRepresentante.Text;
ClasseForn.TelEmpresa = txtTelefone.Text;
ClasseForn.TelRepresentante =
txtTelRepre.Text;
209
ClasseForn.CadFor();
}
else
{
ClasseForn.NomeEmpresa = txtNome.Text;
ClasseForn.Cnpj = txtCNPJ.Text;
ClasseForn.NomeRepresentante =
txtRepresentante.Text;
ClasseForn.TelEmpresa = txtTelefone.Text;
ClasseForn.CadForSemTelRepre();
}
MessageBox.Show("Dados Cadastrados", "SUCESSO",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
BuscaTodosFornecedores();
}
}
catch
{
MessageBox.Show("Erro ao Cadastrar", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Conecta.CON().Close();
}
}
private void btnAlterarFunc_Click(object sender, EventArgs e)
{
try
{
if (txtNome.Text == "" )
{
MessageBox.Show("Preencha pelo menos o campo:
\n'Nome da Empresa' para completar a alterao dos dados!", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (VerificaCNPJduplicado == txtCNPJ.Text)
{
MessageBox.Show("Este Fornecedor j consta no
sistema!", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (txtTelRepre.Text != " / /" ||
txtRepresentante.Text != "")
{
ClasseForn.CodFornecedor = int.Parse(CodForn);
ClasseForn.NomeEmpresa = txtNome.Text;
210
ClasseForn.Cnpj = txtCNPJ.Text;
ClasseForn.NomeRepresentante =
txtRepresentante.Text;
ClasseForn.TelEmpresa = txtTelefone.Text;
ClasseForn.TelRepresentante =
txtTelRepre.Text;
ClasseForn.AlteraForn();
}
else
{
ClasseForn.CodFornecedor = int.Parse(CodForn);
ClasseForn.NomeEmpresa = txtNome.Text;
ClasseForn.Cnpj = txtCNPJ.Text;
ClasseForn.NomeRepresentante =
txtRepresentante.Text;
ClasseForn.TelEmpresa = txtTelefone.Text;
ClasseForn.AlteraFornSemTelRepre();
}
MessageBox.Show("Dados Alterados", "SUCESSO",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
BuscaTodosFornecedores();
}
}
catch
{
MessageBox.Show("Erro ao alterar", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Conecta.CON().Close();
}
}
private void btnExcluiForn_Click(object sender, EventArgs e)
{
try
{
ClasseForn.CodFornecedor = int.Parse(CodForn);
if (CodForn == "")
{
MessageBox.Show("Selecione um Fornecedor para
excluir", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
SqlCommand cmd = new SqlCommand("Select * from
Estoque where CodFornecedor = "+ CodForn,Conecta.CON());
SqlCommand cmd3 = new SqlCommand("Select * from
ContasApagar where CodFornecedor = " + CodForn, Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
211
SqlDataReader dr3 = cmd3.ExecuteReader();
if (dr.Read() || dr3.Read())
{
DialogResult dres = MessageBox.Show("Existem
produtos fornecidos por esta empresa \nque ainda esto cadastrados no
estoque\nou contas a serem pagas para esta empresa em Contas a Pagar.
\nAo excluir este fornecedor, ser excludo tambm o produto fornecido
\npor ele e as contas referentes a este fornecedor.\nDeseja continuar?
", "Excluir Fornecedor", MessageBoxButtons.YesNo,
MessageBoxIcon.Stop);
if (dres == DialogResult.Yes)
{
SqlCommand cmd2 = new SqlCommand("Delete
from Estoque where CodFornecedor = " + CodForn, Conecta.CON());
cmd2.ExecuteNonQuery();
SqlCommand cmd4 = new SqlCommand("Delete
from ContasApagar where CodFornecedor = " + CodForn, Conecta.CON());
cmd4.ExecuteNonQuery();
ClasseForn.ExcluiForn();
MessageBox.Show("Fornecedor excludo do
sistema", "SUCESSO", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Limpar();
BuscaTodosFornecedores();
}
}
else
{
DialogResult dre = MessageBox.Show("Tem
certeza de que deseja Excluir este Fornecedor?", "Excluir Fornecedor",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dre == DialogResult.Yes)
{
ClasseForn.CodFornecedor =
int.Parse(CodForn);
ClasseForn.ExcluiForn();
MessageBox.Show("Fornecedor excludo do
sistema", "SUCESSO", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Limpar();
BuscaTodosFornecedores();
}
}
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnSair_Click(object sender, EventArgs e)
212
{
}
private void btnConsultar_Click(object sender, EventArgs e)
{
BuscaTodosFornecedores();
cmbConsultarPor.SelectedIndex = -1;
txtBusca.Text = "";
}
private void txtBusca_TextChanged(object sender, EventArgs e)
{
if (cmbConsultarPor.Text == "")
{
MessageBox.Show("Selecione um tipo de Pesquisa",
"Erro", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
if (cmbConsultarPor.Text == "Nome")
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Fornecedor where NomeEmpresa like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "Cdigo")
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Fornecedor where CodFornecedor like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "CNPJ")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Fornecedor where CNPJ like '" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
}
private void frmCadFornecedor_Load(object sender, EventArgs e)
{
CodForn = "";
BuscaTodosFornecedores();
}
213
frmCadFuncionario
using
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
System.Data.Sql;
namespace IniciandoDavilla
{
public partial class frmCadFuncionario : Form
{
public frmCadFuncionario()
{
InitializeComponent();
}
string CodFun;
string VerificaCPFduplicado;
214
ClassFuncionario ClasseFunc = new ClassFuncionario();
ClassConexao Conecta = new ClassConexao();
public void LimparCampos()
{
CodFun = "";
txtNome.Clear();
txtCPF.Clear();
txtTelefone.Clear();
txtRua.Clear();
txtNumero.Clear();
txtBairro.Clear();
txtCidade.Clear();
txtEstado.Clear();
txtAdicionalSalario.Text = "0";
cmbCargo.SelectedIndex = -1;
cmbBuscaNomeFun.SelectedIndex = -1;
}
public SqlDataAdapter PopulaCombo()
{
// POPULANDO A COMBOBOX CARGO COM DADOS DA DA PROPRIA
TABELA DO BANCO
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Cargo order by NomeCargo", Conecta.CON());
try
{
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbCargo.DataSource = dt;
cmbCargo.DisplayMember = "NomeCargo";
cmbCargo.SelectedIndex = -1;
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
// --------------------------------------------------------}
public void BuscaTodosFuncionarios()
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
Funcionario", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch { }
finally
{
Conecta.CON().Close();
}
215
}
public SqlCommand VerificaDuplicacaoFuncionario()
{
SqlCommand cmd = new SqlCommand("Select * from Funcionario
where CPF = '"+ txtCPF.Text +"'",Conecta.CON());
try
{
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
VerificaCPFduplicado = dr["CPF"].ToString();
}
}
catch { }
finally
{
Conecta.CON().Close();
}
return cmd;
}
private void frmCadFuncionario_Load(object sender, EventArgs
e)
{
CodFun = "";
PopulaCombo();
BuscaTodosFuncionarios();
}
private void btnCadastrar_Click(object sender, EventArgs e)
{
try
{
VerificaDuplicacaoFuncionario();
if (txtBairro.Text == "" || txtCidade.Text == "" ||
txtCPF.Text == "" || txtEstado.Text == "" || txtNome.Text == "" ||
txtNumero.Text == "" || txtRua.Text == "" || txtTelefone.Text == "" ||
cmbCargo.Text == "")
{
MessageBox.Show("Preencha todos os campos para
completar o cadastro!", "ERRO", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else if (VerificaCPFduplicado == txtCPF.Text)
{
MessageBox.Show("Este Funcionrio j consta no
sistema!", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
// ATRIBUINDO AS TEXTBOX NAS VARIAVEIS DA CLASSE
FUNCIONARIO
ClasseFunc.Nome = txtNome.Text;
ClasseFunc.Rua = txtRua.Text;
ClasseFunc.Numero = txtNumero.Text;
ClasseFunc.Bairro = txtBairro.Text;
ClasseFunc.Cidade = txtCidade.Text;
216
ClasseFunc.Estado = txtEstado.Text;
ClasseFunc.Cpf = txtCPF.Text;
ClasseFunc.Telefone = txtTelefone.Text;
ClasseFunc.AdicionalSalario =
double.Parse(txtAdicionalSalario.Text);
// --------------------------------------------------------ClasseFunc.TrocaNomeCargoPorCodigo(cmbCargo.Text);
ClasseFunc.CadFun();
MessageBox.Show("Dados Cadastrados", "SUCESSO",
MessageBoxButtons.OK, MessageBoxIcon.Information);
LimparCampos();
if ((MessageBox.Show("Deseja Cadastrar o Login e
Senha desse Usurio agora?", "Cadastrar Login",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
DialogResult.Yes))
{
frmCadLogin CadLogin = new frmCadLogin();
CadLogin.Show();
}
else
{
if ((MessageBox.Show("Deseja cadastrar outro
Funcionrio agora?", "Cadastrar Funcionrio", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes))
{
LimparCampos();
}
else
this.Close();
}
LimparCampos();
BuscaTodosFuncionarios();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnSair_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnNovoCargo_Click(object sender, EventArgs e)
{
frmCadCargo cargo = new frmCadCargo();
cargo.Show();
}
217
private void cmbCargo_Click(object sender, EventArgs e)
{
PopulaCombo();
}
private void cmbConsultarPor_TextChanged(object sender,
EventArgs e)
{
if (cmbConsultarPor.Text == "CPF")
{
txtBusca.Mask = "000.000.000-00";
}
else if (cmbConsultarPor.Text == "Telefone")
{
txtBusca.Mask = "(00) 0000-0000";
}
else
{
txtBusca.Mask = "";
}
}
218
SqlDataAdapter da = new SqlDataAdapter("Select *
from Funcionario where Telefone like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "CPF")
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Funcionario where CPF like '%" + txtBusca.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
catch
{
MessageBox.Show("Erro text Changed txtBusca");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbBuscaNomeFun_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
Funcionario order by NomeFuncionario", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
cmbBuscaNomeFun.DataSource = ds.Tables[0];
cmbBuscaNomeFun.DisplayMember = "NomeFuncionario";
cmbBuscaNomeFun.SelectedIndex = -1;
}
catch
{
MessageBox.Show("Erro evento click cmb busca nome
fun");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbBuscaNomeFun_SelectedIndexChanged(object
sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("Select * from
Funcionario where NomeFuncionario = '" + cmbBuscaNomeFun.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
219
if (dr.Read())
{
CodFun = dr["CodFuncionario"].ToString();
txtNome.Text = dr["NomeFuncionario"].ToString();
txtCPF.Text = dr["CPF"].ToString();
txtTelefone.Text = dr["Telefone"].ToString();
txtRua.Text = dr["Rua"].ToString();
txtNumero.Text = dr["Numero"].ToString();
txtBairro.Text = dr["Bairro"].ToString();
txtCidade.Text = dr["Cidade"].ToString();
txtEstado.Text = dr["Estado"].ToString();
txtAdicionalSalario.Text =
dr["AdicionalSalario"].ToString();
SqlCommand cmd2 = new SqlCommand("SELECT
Cargo.NomeCargo AS NomeCargo, Funcionario.* FROM Funcionario INNER
JOIN Cargo ON Cargo.CodCargo = Funcionario.CodFuncionario where
CodFuncionario = " + CodFun, Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
cmbCargo.Text = dr2["NomeCargo"].ToString();
}
}
}
catch
{
MessageBox.Show("Erro selected index Changed combo
busca nome fun");
}
finally
{
Conecta.CON().Close();
}
}
private void btnNovo_Click(object sender, EventArgs e)
{
if (txtNome.Text != "" || txtBairro.Text != "" ||
txtCidade.Text != "" || txtTelefone.Text != "( )
-" ||
txtCPF.Text != "
,
,
-" || txtEstado.Text != "" || txtRua.Text
!= "" || txtNumero.Text != "" || cmbCargo.Text != "" ||
txtAdicionalSalario.Text != "0")
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para cadastrar um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
LimparCampos();
}
}
else
{
LimparCampos();
}
}
220
private void btnAlterarFunc_Click(object sender, EventArgs e)
{
try
{
if (txtBairro.Text == "" || txtCidade.Text == "" ||
txtCPF.Text == "" || txtEstado.Text == "" || txtNome.Text == "" ||
txtNumero.Text == "" || txtRua.Text == "" || txtTelefone.Text == "" ||
cmbCargo.Text == "")
{
MessageBox.Show("Preencha todos os campos para
completar a alterao!", "ERRO", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
// ATRIBUINDO AS TEXTBOX NAS VARIAVEIS DA CLASSE
FUNCIONARIO
ClasseFunc.CodFuncionario = int.Parse(CodFun);
ClasseFunc.Nome = txtNome.Text;
ClasseFunc.Rua = txtRua.Text;
ClasseFunc.Numero = txtNumero.Text;
ClasseFunc.Bairro = txtBairro.Text;
ClasseFunc.Cidade = txtCidade.Text;
ClasseFunc.Estado = txtEstado.Text;
ClasseFunc.Cpf = txtCPF.Text;
ClasseFunc.Telefone = txtTelefone.Text;
ClasseFunc.AdicionalSalario =
double.Parse(txtAdicionalSalario.Text);
// --------------------------------------------------------ClasseFunc.TrocaNomeCargoPorCodigo(cmbCargo.Text);
ClasseFunc.AlteraFun();
MessageBox.Show("Dados Alterados com Sucesso!",
"SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
LimparCampos();
BuscaTodosFuncionarios();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnExcluiFunc_Click(object sender, EventArgs e)
{
try
{
if (CodFun == "")
{
MessageBox.Show("Selecione um Funcionrio para
excluir", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
221
DialogResult dr = MessageBox.Show("Tem certeza de
que deseja Excluir este Funcionrio?", "Excluir Funcionrio",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
ClasseFunc.CodFuncionario = int.Parse(CodFun);
ClasseFunc.ExcluiFun();
MessageBox.Show("Funcionrio excludo do
sistema", "SUCESSO", MessageBoxButtons.OK,
MessageBoxIcon.Information);
LimparCampos();
BuscaTodosFuncionarios();
}
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void txtAdicionalSalario_Validated(object sender,
EventArgs e)
{
if (txtAdicionalSalario.Text == "")
{
txtAdicionalSalario.Text = "0";
}
}
private void txtAdicionalSalario_Click(object sender,
EventArgs e)
{
txtAdicionalSalario.Text = "";
}
private void txtAdicionalSalario_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void cmbCargo_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadastrar_Click(sender, e);
break;
}
222
}
private void txtNumero_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 )
{
e.Handled = true;
}
}
private void cmbCargo_Enter(object sender, EventArgs e)
{
}
private void cmbCargo_KeyPress(object sender,
KeyPressEventArgs e)
{
}
}
}
frmCadLogin
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadLogin : Form
{
public frmCadLogin()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
ClassLogin ClasseLogin = new ClassLogin();
public void BuscaTodosFun()
{
SqlDataAdapter da = new SqlDataAdapter("Select
CodFuncionario, NomeFuncionario from Funcionario order by
NomeFuncionario", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgConsultaCod.DataSource = ds.Tables[0];
}
public void Limpar()
223
{
txtSenha.Clear();
txtNomeUsuario.Clear();
txtCodFunc.Clear();
}
private void txtNomeFunc_KeyPress(object sender,
KeyPressEventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("Select
CodFuncionario, NomeFuncionario from Funcionario where NomeFuncionario
like '" + txtNomeFunc.Text + "%'", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgConsultaCod.DataSource = ds.Tables[0];
}
224
}
else
{
ClasseLogin.NomeUsuario =
txtNomeUsuario.Text;
ClasseLogin.Senha = txtSenha.Text;
ClasseLogin.CodFunc =
int.Parse(txtCodFunc.Text);
ClasseLogin.Cadastrar();
MessageBox.Show("Login e Senha
Cadastrados", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Limpar();
if ((MessageBox.Show("Deseja Cadastrar
outro Login e Senha agora?", "Cadastrar Login",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
DialogResult.Yes))
{
txtNomeUsuario.Clear();
txtCodFunc.Clear();
txtSenha.Clear();
txtCodFunc.Focus();
}
else
{
Close();
}
}
}
catch
{
MessageBox.Show("Erro btnCadastrar login");
}
finally
{
Conecta.CON().Close();
}
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void dgConsultaCod_CellClick(object sender,
DataGridViewCellEventArgs e)
{
txtCodFunc.Text =
dgConsultaCod.SelectedCells[0].Value.ToString();
}
225
private void frmCadLogin_TextChanged(object sender, EventArgs
e)
{
}
private void frmCadLogin_Load(object sender, EventArgs e)
{
BuscaTodosFun();
}
private void txtCodFunc_TextChanged(object sender, EventArgs
e)
{
if (txtCodFunc.Text == "")
{
txtSenha.Clear();
txtNomeUsuario.Clear();
}
else
{
try
{
SqlCommand cmd = new SqlCommand("Select * from
Login where CodFuncionario =" + txtCodFunc.Text, Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtNomeUsuario.Text =
dr["NomeUsuario"].ToString();
txtSenha.Text = dr["Senha"].ToString();
}
}
catch
{
//MessageBox.Show("Erro text changed CodFun");
}
finally
{
Conecta.CON().Close();
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (txtCodFunc.Text != "" || txtSenha.Text != "" ||
txtNomeUsuario.Text != "")
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
Limpar();
txtCodFunc.Focus();
}
}
else
{
226
Limpar();
txtCodFunc.Focus();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (txtCodFunc.Text == "" || txtNomeUsuario.Text == ""
|| txtSenha.Text == "")
{
MessageBox.Show("Informe o cdigo do funcionrio
que j tenha um login cadastrado", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}
else
{
ClasseLogin.NomeUsuario = txtNomeUsuario.Text;
ClasseLogin.Senha = txtSenha.Text;
ClasseLogin.CodFunc = int.Parse(txtCodFunc.Text);
ClasseLogin.Alterar();
MessageBox.Show("Dados Alterados", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
}
}
catch
{
MessageBox.Show("Erro btnAlterar login");
}
}
private void btnExcluir_Click(object sender, EventArgs e)
{
try
{
if (txtCodFunc.Text == "" || txtNomeUsuario.Text == ""
|| txtSenha.Text == "")
{
MessageBox.Show("Este funcionrio ainda no possui
um login, selecione um Funcionario para excluir seu login!", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
DialogResult dr = MessageBox.Show("Tem certeza
de que deseja Excluir este Login?", "Excluir Login",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
ClasseLogin.CodFunc =
int.Parse(txtCodFunc.Text);
ClasseLogin.Excluir();
MessageBox.Show("Login excludo do
sistema", "SUCESSO", MessageBoxButtons.OK,
MessageBoxIcon.Information);
227
BuscaTodosFun();
Limpar();
}
}
catch
{
MessageBox.Show("Erro boto Excluir, Selecione
um Funcionrio para excluir seu login");
}
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
Limpar();
}
private void txtCodFunc_KeyPress(object sender,
KeyPressEventArgs e)
{
}
private void txtSenha_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadastrar_Click(sender, e);
break;
}
}
}
}
frmCadPedido
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadPedido : Form
228
{
ClassConexao Conecta = new ClassConexao();
string preco;
private string codpedido;
public string Codpedido
{
get { return codpedido; }
set { codpedido = value; }
}
public frmCadPedido()
{
InitializeComponent();
}
private string operador;
public string Operador
{
get { return operador; }
set { operador = value; }
}
private string tipoPedido;
public string TipoPedido
{
get { return tipoPedido; }
set { tipoPedido = value; }
}
private string numeroMesa;
public string NumeroMesa
{
get { return numeroMesa; }
set { numeroMesa = value; }
}
string codCliente;
public string CodCliente
{
get { return codCliente; }
set { codCliente = value; }
}
private string verificaClienteComPedidoAberto;
public string VerificaClienteComPedidoAberto
{
get { return verificaClienteComPedidoAberto; }
set { verificaClienteComPedidoAberto = value; }
}
string DiaSemana = "";
string DiaSemanaMarmitex = "";
229
// -------------------------------------------------------------------------------------------------------
230
DiaSemana = DateTime.Now.ToString("ddd");
if (DiaSemana == "seg")
{
DiaSemanaMarmitex = "Segunda";
}
else if (DiaSemana == "ter")
{
DiaSemanaMarmitex = "Tera";
}
else if (DiaSemana == "qua")
{
DiaSemanaMarmitex = "Quarta";
}
else if (DiaSemana == "qui")
{
DiaSemanaMarmitex = "Quinta";
}
else if (DiaSemana == "sex")
{
DiaSemanaMarmitex = "Sexta";
}
else if (DiaSemana == "sb")
{
DiaSemanaMarmitex = "Sbado";
}
else if (DiaSemana == "dom")
{
DiaSemanaMarmitex = "Domingo";
}
if (TipoPedido == "Entrega")
{
pnSelfService.Enabled = false;
}
else
{
pnSelfService.Enabled = true;
}
preco = "";
rbDiaSemana.Checked = true;
}
private void btnAdicPedido_Click(object sender, EventArgs e)
{
try
{
if (cmbCodPizza.Text == "" || cmbNomePizza.Text == ""
|| cmbQuantPizza.Text == "")
{
MessageBox.Show("Selecione a pizza e a
quantidade!", "ERRO", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
231
else
{
if (tsTipoPedido.Text == "Mesa")
{
SqlCommand cmd = new SqlCommand("Select * from
Pizza where NomePizza = '" + cmbNomePizza.Text + "'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantPizza.Text);
itempedido.CodPedido = int.Parse(Codpedido);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodPizza =
int.Parse(cmbCodPizza.Text);
itempedido.AdicionaItemPedidoPizza();
MessageBox.Show("Item adicionado ao pedido",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (tsTipoPedido.Text == "Balco")
{
SqlCommand cmd = new SqlCommand("Select * from
Pizza where NomePizza = '" + cmbNomePizza.Text + "'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantPizza.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodPizza =
int.Parse(cmbCodPizza.Text);
itempedido.AdicionaItemPedidoPizza();
232
MessageBox.Show("Item adicionado ao pedido",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (tsTipoPedido.Text == "Entrega")
{
if (txtCodCli.Text == "")
{
MessageBox.Show("Selecione um Cliente",
"Selecionar Cliente");
}
else
{
SqlCommand cmd = new SqlCommand("Select *
from Pedido where StatusPedido = 'EM ABERTO' and TipoPedido =
'Entrega' and CodPedido not in ('" + Codpedido + "') and CodCliente =
" + txtCodCli.Text, Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("J existe um pedido
em aberto para este cliente", "ERRO");
SqlCommand cmdBuscaCodPedido = new
SqlCommand("Select * from Pedido where CodCliente is NULL and
TipoPedido = 'Entrega' and CodPedido = " + tsCodPedido.Text,
Conecta.CON());
SqlDataReader drBuscaCodPedido =
cmdBuscaCodPedido.ExecuteReader();
if (drBuscaCodPedido.Read())
{
Codpedido =
drBuscaCodPedido["CodPedido"].ToString();
SqlCommand cmddelete = new
SqlCommand("Delete from Pedido where CodPedido = " + Codpedido,
Conecta.CON());
cmddelete.ExecuteNonQuery();
}
}
else
{
if (txtCodCli.Text != "")
{
SqlCommand cmd0 = new
SqlCommand("Select * from Pizza where NomePizza = '" +
cmbNomePizza.Text + "'", Conecta.CON());
SqlDataReader dr0 =
cmd0.ExecuteReader();
if (dr0.Read())
{
preco =
dr0["Valor"].ToString();
}
233
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantPizza.Text);
itempedido.CodPedido =
int.Parse(Codpedido);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodPizza =
int.Parse(cmbCodPizza.Text);
itempedido.AdicionaItemPedidoPizza();
ClassPedido classePedido = new
ClassPedido();
classePedido.CodPedido =
int.Parse(Codpedido);
classePedido.CodCliente =
int.Parse(txtCodCli.Text);
classePedido.AtualizaCodCliente();
MessageBox.Show("Item adicionado
ao pedido", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
}
}
}
catch
{
MessageBox.Show("Erro no boto adicionaPedido da
Pizza");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbConsultaCliente_Click(object sender, EventArgs
e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select * from
Cliente where NomeCliente not in ('MESA') and NomeCliente not in
('Balco') order by NomeCliente", Conecta.CON());
DataTable dt = new DataTable();
da.Fill(dt);
cmbConsultaCliente.DataSource = dt;
cmbConsultaCliente.DisplayMember = "NomeCliente";
}
catch
234
{
MessageBox.Show("Erro no evento Click da combo Nome
Cliente");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbConsultaCliente_TextChanged(object sender,
EventArgs e)
{
try
{
if (cmbConsultaCliente.Text == "")
{
txtCodCli.Clear();
txtNome.Clear();
txtRua.Clear();
txtNumero.Clear();
txtBairro.Clear();
txtCidade.Clear();
txtEstado.Clear();
txtTelefone.Clear();
txtCel.Clear();
txtPtoRef.Clear();
}
else
{
SqlCommand cmd = new SqlCommand("Select * from
Cliente where NomeCliente like '" + cmbConsultaCliente.Text + "%'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtCodCli.Text = dr["CodCliente"].ToString();
txtNome.Text = dr["NomeCliente"].ToString();
txtRua.Text = dr["Rua"].ToString();
txtNumero.Text = dr["Numero"].ToString();
txtBairro.Text = dr["Bairro"].ToString();
txtCidade.Text = dr["Cidade"].ToString();
txtEstado.Text = dr["Estado"].ToString();
txtTelefone.Text = dr["Telefone"].ToString();
txtCel.Text = dr["Celular"].ToString();
txtPtoRef.Text =
dr["PontoReferencia"].ToString();
}
}
}
catch
{
MessageBox.Show("Erro no evento textChanged da Combo
Nome Cliente");
235
}
finally
{
Conecta.CON().Close();
}
}
236
catch
{
MessageBox.Show("Erro textchanged txt consulta
tel");
}
finally
{
Conecta.CON().Close();
}
}
}
237
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodBebida_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Bebida", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbCodBebida.DataSource = dt;
cmbCodBebida.DisplayMember = "CodBebida";
cmbCodBebida.SelectedIndex = -1;
cmbNomeBebida.SelectedIndex = -1;
}
catch
{
MessageBox.Show("Click cmb cod bebida");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbNomeEsfiha_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Esfiha", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbNomeEsfiha.DataSource = dt;
cmbNomeEsfiha.DisplayMember = "NomeEsfiha";
cmbNomeEsfiha.SelectedIndex = -1;
cmbCodEsfiha.SelectedIndex = -1;
}
catch
{
MessageBox.Show("click cmb nome esfiha");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodEsfiha_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Esfiha", Conecta.CON());
238
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbCodEsfiha.DataSource = dt;
cmbCodEsfiha.DisplayMember = "CodEsfiha";
cmbCodEsfiha.SelectedIndex = -1;
cmbNomeEsfiha.SelectedIndex = -1;
}
catch
{
MessageBox.Show("click cmb cod esfiha");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodMarmitex_Click(object sender, EventArgs e)
{
try
{
if (rbDiaSemana.Checked == true)
{
SqlDataAdapter cmd = new SqlDataAdapter("select *
from Marmitex where DiaSemana = '" + DiaSemanaMarmitex + "'",
Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbCodMarmitex.DataSource = dt;
cmbCodMarmitex.DisplayMember = "CodMarmitex";
cmbCodMarmitex.SelectedIndex = -1;
cmbDescricaoMarmitex.SelectedIndex = -1;
}
else if (rbTodasMarmitex.Checked == true)
{
SqlDataAdapter cmd2 = new SqlDataAdapter("select *
from Marmitex", Conecta.CON());
DataTable dt2 = new DataTable();
cmd2.Fill(dt2);
cmbCodMarmitex.DataSource = dt2;
cmbCodMarmitex.DisplayMember = "CodMarmitex";
cmbCodMarmitex.SelectedIndex = -1;
cmbDescricaoMarmitex.SelectedIndex = -1;
}
}
catch
{
MessageBox.Show("click cmb cod marmitex");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbDescricaoMarmitex_Click(object sender,
EventArgs e)
{
try
{
239
if (rbDiaSemana.Checked)
{
SqlDataAdapter cmd = new SqlDataAdapter("select *
from Marmitex where DiaSemana = '" + DiaSemanaMarmitex + "'",
Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbDescricaoMarmitex.DataSource = dt;
cmbDescricaoMarmitex.DisplayMember = "Descricao";
cmbDescricaoMarmitex.SelectedIndex = -1;
cmbCodMarmitex.SelectedIndex = -1;
}
else if (rbTodasMarmitex.Checked)
{
SqlDataAdapter cmd = new SqlDataAdapter("select *
from Marmitex", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbDescricaoMarmitex.DataSource = dt;
cmbDescricaoMarmitex.DisplayMember = "Descricao";
cmbDescricaoMarmitex.SelectedIndex = -1;
cmbCodMarmitex.SelectedIndex = -1;
}
}
catch
{
MessageBox.Show("click cmb descricao marmitex");
}
finally
{
Conecta.CON().Close();
}
}
240
else
{
try
{
SqlCommand cmd = new SqlCommand("Select * from
Cliente where Telefone like '%" + txtConsultaTel.Text + "%'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
CodCliente = dr["CodCliente"].ToString();
txtCodCli.Text = dr["CodCliente"].ToString();
txtNome.Text = dr["NomeCliente"].ToString();
txtRua.Text = dr["Rua"].ToString();
txtNumero.Text = dr["Numero"].ToString();
txtBairro.Text = dr["Bairro"].ToString();
txtCidade.Text = dr["Cidade"].ToString();
txtEstado.Text = dr["Estado"].ToString();
txtTelefone.Text = dr["Telefone"].ToString();
txtCel.Text = dr["Celular"].ToString();
txtPtoRef.Text =
dr["PontoReferencia"].ToString();
}
}
catch
{
MessageBox.Show("Evento text changed do txt
consulta tel");
}
finally
{
Conecta.CON().Close();
}
}
}
private void frmCadPedido_FormClosing(object sender,
FormClosingEventArgs e)
{
try
{
if (tsTipoPedido.Text == "Entrega")
{
SqlCommand cmd2 = new SqlCommand("Select * from
ItemPedido where CodPedido = " + tsCodPedido.Text, Conecta.CON());
SqlDataReader dr = cmd2.ExecuteReader();
if (dr.Read())
{
}
else
{
DialogResult dre = MessageBox.Show("Para
continuar este pedido voc deve adicionar ao menos um item ao pedido!
241
Deseja continuar o Pedido?", "Continuar Pedido",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dre == DialogResult.No)
{
try
{
SqlCommand cmd = new
SqlCommand("Delete from Pedido where TipoPedido = 'Entrega' and
CodCliente is Null and StatusPedido = 'EM ABERTO'", Conecta.CON());
cmd.ExecuteNonQuery();
MessageBox.Show("Existem Pedido no
foram concludos e por isso no sero armazenados!", "Falha ao validar
Pedido", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch { }
}
else
{
e.Cancel = true;
}
}
}
if (tsTipoPedido.Text == "Balco")
{
SqlCommand cmd2 = new SqlCommand("Select * from
ItemPedido where CodPedido = " + tsCodPedido.Text, Conecta.CON());
SqlDataReader dr = cmd2.ExecuteReader();
if (dr.Read())
{
}
else
{
DialogResult drt2 = MessageBox.Show("Para
continuar este pedido voc deve adicionar ao menos um item ao pedido!
Deseja continuar o Pedido?", "Continuar Pedido",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (drt2 == DialogResult.No)
{
SqlCommand cmd = new SqlCommand("Delete
from Pedido where TipoPedido = 'Balco' and CodPedido = " +
tsCodPedido.Text, Conecta.CON());
cmd.ExecuteNonQuery();
MessageBox.Show("Existem Pedido no foram
concludos e por isso no sero armazenados!", "Falha ao validar
Pedido", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
e.Cancel = true;
242
}
}
}
}
catch
{
MessageBox.Show("erro evento form closing do form cad
pedido");
}
finally
{
Conecta.CON().Close();
}
Codpedido = "";
}
private void cmbCodPizza_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Pizza where CodPizza = '" + cmbCodPizza.Text + "'", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbNomePizza.DataSource = dt;
cmbNomePizza.DisplayMember = "NomePizza";
}
catch
{
//MessageBox.Show("Text changed combo Cod Pizza");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbNomePizza_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd2 = new SqlDataAdapter("select *
from Pizza where NomePizza = '" + cmbNomePizza.Text + "'",
Conecta.CON());
DataTable dt2 = new DataTable();
cmd2.Fill(dt2);
cmbCodPizza.DataSource = dt2;
cmbCodPizza.DisplayMember = "CodPizza";
}
catch
{
//MessageBox.Show("Erro text changed Combo Nome
Pizza");
243
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodBebida_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Bebida where CodBebida = '" + cmbCodBebida.Text + "'", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbNomeBebida.DataSource = dt;
cmbNomeBebida.DisplayMember = "Descricao";
}
catch
{
//MessageBox.Show("text changed cmb cod bebida");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbNomeBebida_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd2 = new SqlDataAdapter("select *
from Bebida where Descricao = '" + cmbNomeBebida.Text + "'",
Conecta.CON());
DataTable dt2 = new DataTable();
cmd2.Fill(dt2);
cmbCodBebida.DataSource = dt2;
cmbCodBebida.DisplayMember = "CodBebida";
}
catch
{
//MessageBox.Show("text changed cmb Nome Bebida");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodEsfiha_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Esfiha where CodEsfiha = '" + cmbCodEsfiha.Text + "'", Conecta.CON());
244
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbNomeEsfiha.DataSource = dt;
cmbNomeEsfiha.DisplayMember = "NomeEsfiha";
}
catch
{
//MessageBox.Show("text changed cmb cod esfiha");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbNomeEsfiha_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd2 = new SqlDataAdapter("select *
from Esfiha where NomeEsfiha = '" + cmbNomeEsfiha.Text + "'",
Conecta.CON());
DataTable dt2 = new DataTable();
cmd2.Fill(dt2);
cmbCodEsfiha.DataSource = dt2;
cmbCodEsfiha.DisplayMember = "CodEsfiha";
}
catch
{
//MessageBox.Show("text changed cmb Nome Esfiha");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodMarmitex_SelectedIndexChanged(object
sender, EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Marmitex where CodMarmitex = '" + cmbCodMarmitex.Text + "'",
Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbDescricaoMarmitex.DataSource = dt;
cmbDescricaoMarmitex.DisplayMember = "Descricao";
}
catch
{
// MessageBox.Show("text changed cmb cod
marmitex");????
}
finally
{
Conecta.CON().Close();
245
}
}
private void cmbDescricaoMarmitex_SelectedIndexChanged(object
sender, EventArgs e)
{
try
{
SqlDataAdapter cmd2 = new SqlDataAdapter("select *
from Marmitex where Descricao = '" + cmbDescricaoMarmitex.Text + "'",
Conecta.CON());
DataTable dt2 = new DataTable();
cmd2.Fill(dt2);
cmbCodMarmitex.DataSource = dt2;
cmbCodMarmitex.DisplayMember = "CodMarmitex";
}
catch
{
//MessageBox.Show("text changed cmb descricao
marmitex");
}
finally
{
Conecta.CON().Close();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void btnNovoCliente_Click(object sender, EventArgs e)
{
frmCadCliente cli = new frmCadCliente();
cli.Width = 1168;
cli.Height = 567;
cli.Show();
}
private void btnAdicionarSelecionados_Click(object sender,
EventArgs e)
{
try
{
if (cmbCodPizza.Text == "" && cmbQuantPizza.Text ==
"" && cmbCodBebida.Text == "" && cmbQuantBebida.Text == "" &&
cmbCodEsfiha.Text == "" && cmbQuantEsfiha.Text == "" &&
cmbCodMarmitex.Text == "" && cmbQuantMarmitex.Text == "" &&
cmbCodSelf.Text == "" && cmbQuantSelf.Text == "")
{
MessageBox.Show("Selecione ao menos um Item para
adicionar ao pedido", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
246
else if (cmbQuantPizza.Text == "" &&
cmbQuantBebida.Text == "" && cmbQuantEsfiha.Text == "" &&
cmbQuantMarmitex.Text == "" && cmbQuantSelf.Text == "")
{
MessageBox.Show("Informe a Quantidade de cada item
a ser adicionado ao pedido", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
if (tsTipoPedido.Text == "Mesa")
{
SqlCommand cmd = new SqlCommand("Select *
from Pizza where NomePizza = '" + cmbNomePizza.Text + "'",
Conecta.CON());
247
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantPizza.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodPizza =
int.Parse(cmbCodPizza.Text);
itempedido.Obs = txtObsPizza.Text;
itempedido.AdicionaItemPedidoPizza();
cmbQuantPizza.Text = "";
cmbNomePizza.Text = "";
cmbCodPizza.Text = "";
lblinfoPizza.Visible = true;
}
else if (tsTipoPedido.Text == "Balco")
{
SqlCommand cmd = new SqlCommand("Select *
from Pizza where NomePizza = '" + cmbNomePizza.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantPizza.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodPizza =
int.Parse(cmbCodPizza.Text);
itempedido.Obs = txtObsPizza.Text;
itempedido.AdicionaItemPedidoPizza();
cmbQuantPizza.Text = "";
cmbNomePizza.Text = "";
248
cmbCodPizza.Text = "";
lblinfoPizza.Visible = true;
}
else if (tsTipoPedido.Text == "Entrega")
{
if (txtCodCli.Text == "" ||
txtEntregador.Text == "")
{
MessageBox.Show("Selecione um Cliente
e o entregador", "Selecionar Cliente e Entregador");
}
else
{
SqlCommand cmd = new
SqlCommand("Select * from Pedido where StatusPedido = 'EM ABERTO' and
TipoPedido = 'Entrega' and CodPedido not in ('" + Codpedido + "') and
CodCliente = " + txtCodCli.Text, Conecta.CON());
SqlDataReader dr =
cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("J existe um
pedido em aberto para este cliente", "ERRO");
SqlCommand cmdBuscaCodPedido = new
SqlCommand("Select * from Pedido where CodCliente is NULL and
TipoPedido = 'Entrega' and CodPedido = " + tsCodPedido.Text,
Conecta.CON());
SqlDataReader drBuscaCodPedido =
cmdBuscaCodPedido.ExecuteReader();
if (drBuscaCodPedido.Read())
{
Codpedido =
drBuscaCodPedido["CodPedido"].ToString();
SqlCommand cmddelete = new
SqlCommand("Delete from Pedido where CodPedido = " + Codpedido,
Conecta.CON());
cmddelete.ExecuteNonQuery();
}
}
else
{
if (txtCodCli.Text != "")
{
SqlCommand cmd0 = new
SqlCommand("Select * from Pizza where NomePizza = '" +
cmbNomePizza.Text + "'", Conecta.CON());
SqlDataReader dr0 =
cmd0.ExecuteReader();
if (dr0.Read())
{
249
preco =
dr0["Valor"].ToString();
}
ClassItemPedido itempedido =
new ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantPizza.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodPizza =
int.Parse(cmbCodPizza.Text);
itempedido.Obs =
txtObsPizza.Text;
itempedido.AdicionaItemPedidoPizza();
ClassPedido classePedido = new
ClassPedido();
classePedido.CodPedido =
int.Parse(tsCodPedido.Text);
classePedido.CodCliente =
int.Parse(txtCodCli.Text);
classePedido.Entregador =
txtEntregador.Text;
classePedido.AlteraEntragador();
classePedido.AtualizaCodCliente();
//MessageBox.Show("Itens
adicionados ao pedido", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
cmbQuantPizza.Text = "";
cmbNomePizza.Text = "";
cmbCodPizza.Text = "";
lblinfoPizza.Visible = true;
}
}
}
}
}
// BEBIDA
250
{
if (tsTipoPedido.Text == "Mesa")
{
SqlCommand cmd = new SqlCommand("Select *
from Bebida where Descricao = '" + cmbNomeBebida.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
}
else if (tsTipoPedido.Text == "Balco")
{
SqlCommand cmd = new SqlCommand("Select *
from Bebida where Descricao = '" + cmbNomeBebida.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantBebida.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
251
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodBebida =
int.Parse(cmbCodBebida.Text);
itempedido.Obs = txtObsBebida.Text;
itempedido.AdicionaItemPedidoBebida();
cmbQuantBebida.Text = "";
cmbNomeBebida.Text = "";
cmbCodBebida.Text = "";
lblinfoBebida.Visible = true;
}
else if (tsTipoPedido.Text == "Entrega")
{
if (txtCodCli.Text == "" ||
txtEntregador.Text == "")
{
MessageBox.Show("Selecione um Cliente
e o entregador", "Selecionar Cliente e Entregador");
}
else
{
SqlCommand cmd = new
SqlCommand("Select * from Pedido where StatusPedido = 'EM ABERTO' and
TipoPedido = 'Entrega' and CodPedido not in ('" + Codpedido + "') and
CodCliente = " + txtCodCli.Text, Conecta.CON());
SqlDataReader dr =
cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("J existe um
pedido em aberto para este cliente", "ERRO");
SqlCommand cmdBuscaCodPedido = new
SqlCommand("Select * from Pedido where CodCliente is NULL and
TipoPedido = 'Entrega'", Conecta.CON());
SqlDataReader drBuscaCodPedido =
cmdBuscaCodPedido.ExecuteReader();
if (drBuscaCodPedido.Read())
{
Codpedido =
drBuscaCodPedido["CodPedido"].ToString();
SqlCommand cmddelete = new
SqlCommand("Delete from Pedido where CodPedido = " + Codpedido,
Conecta.CON());
cmddelete.ExecuteNonQuery();
}
}
else
{
if (txtCodCli.Text != "")
{
SqlCommand cmdb = new
SqlCommand("Select * from Bebida where Descricao = '" +
cmbNomeBebida.Text + "'", Conecta.CON());
252
SqlDataReader drb =
cmdb.ExecuteReader();
if (drb.Read())
{
preco =
drb["Valor"].ToString();
}
ClassItemPedido itempedido =
new ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantBebida.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodBebida =
int.Parse(cmbCodBebida.Text);
itempedido.Obs =
txtObsBebida.Text;
itempedido.AdicionaItemPedidoBebida();
ClassPedido classePedido = new
ClassPedido();
classePedido.CodPedido =
int.Parse(tsCodPedido.Text);
classePedido.CodCliente =
int.Parse(txtCodCli.Text);
classePedido.AtualizaCodCliente();
classePedido.Entregador =
txtEntregador.Text;
classePedido.AlteraEntragador();
//MessageBox.Show("Itens
adicionados ao pedido", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
cmbQuantBebida.Text = "";
cmbNomeBebida.Text = "";
cmbCodBebida.Text = "";
lblinfoBebida.Visible = true;
}
}
}
}
}
//ESFIHA
253
}
else if (tsTipoPedido.Text == "Balco")
{
SqlCommand cmd = new SqlCommand("Select *
from Esfiha where NomeEsfiha = '" + cmbNomeEsfiha.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
254
itempedido.Quantidade =
int.Parse(cmbQuantEsfiha.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodEsfiha =
int.Parse(cmbCodEsfiha.Text);
itempedido.Obs = txtObsEsfiha.Text;
itempedido.AdicionaItemPedidoEsfiha();
cmbQuantEsfiha.Text = "";
cmbNomeEsfiha.Text = "";
cmbCodEsfiha.Text = "";
lblinfoEsfiha.Visible = true;
}
else if (tsTipoPedido.Text == "Entrega")
{
if (txtCodCli.Text == "" ||
txtEntregador.Text == "")
{
MessageBox.Show("Selecione um Cliente
e entregador", "Selecionar Cliente e Entregador");
}
else
{
SqlCommand cmd = new
SqlCommand("Select * from Pedido where StatusPedido = 'EM ABERTO' and
TipoPedido = 'Entrega' and CodPedido not in ('" + Codpedido + "') and
CodCliente = " + txtCodCli.Text, Conecta.CON());
SqlDataReader dr =
cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("J existe um
pedido em aberto para este cliente", "ERRO");
SqlCommand cmdBuscaCodPedido = new
SqlCommand("Select * from Pedido where CodCliente is NULL and
TipoPedido = 'Entrega'", Conecta.CON());
SqlDataReader drBuscaCodPedido =
cmdBuscaCodPedido.ExecuteReader();
if (drBuscaCodPedido.Read())
{
Codpedido =
drBuscaCodPedido["CodPedido"].ToString();
SqlCommand cmddelete = new
SqlCommand("Delete from Pedido where CodPedido = " + Codpedido,
Conecta.CON());
cmddelete.ExecuteNonQuery();
}
}
else
{
if (txtCodCli.Text != "")
{
255
SqlCommand cmde = new
SqlCommand("Select * from Esfiha where NomeEsfiha = '" +
cmbNomeEsfiha.Text + "'", Conecta.CON());
SqlDataReader dre =
cmde.ExecuteReader();
if (dre.Read())
{
preco =
dre["Valor"].ToString();
}
ClassItemPedido itempedido =
new ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantEsfiha.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodEsfiha =
int.Parse(cmbCodEsfiha.Text);
itempedido.Obs =
txtObsEsfiha.Text;
itempedido.AdicionaItemPedidoEsfiha();
ClassPedido classePedido = new
ClassPedido();
classePedido.CodPedido =
int.Parse(tsCodPedido.Text);
classePedido.CodCliente =
int.Parse(txtCodCli.Text);
classePedido.AtualizaCodCliente();
classePedido.Entregador =
txtEntregador.Text;
classePedido.AlteraEntragador();
//MessageBox.Show("Itens
adicionados ao pedido", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
cmbQuantEsfiha.Text = "";
cmbNomeEsfiha.Text = "";
cmbCodEsfiha.Text = "";
lblinfoEsfiha.Visible = true;
}
}
}
}
}
// MARMITEX
256
if (cmbCodMarmitex.Text != "" ||
cmbQuantMarmitex.Text != "")
{
if (tsTipoPedido.Text == "Mesa")
{
SqlCommand cmd = new SqlCommand("Select *
from Marmitex where Descricao = '" + cmbDescricaoMarmitex.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
SqlCommand cmd2 = new SqlCommand("select *
from Pedido where TipoPedido = 'MESA' and StatusPedido = 'EM ABERTO'
and NumeroMesa = '" + NumeroMesa + "'", Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
Codpedido =
dr2["CodPedido"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantMarmitex.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodMarmitex =
int.Parse(cmbCodMarmitex.Text);
itempedido.Obs = txtObsMarmitex.Text;
itempedido.AdicionaItemPedidoMarmitex();
cmbQuantMarmitex.Text = "";
cmbDescricaoMarmitex.Text = "";
cmbCodMarmitex.Text = "";
lblinfoMarmitex.Visible = true;
}
else if (tsTipoPedido.Text == "Balco")
{
SqlCommand cmd = new SqlCommand("Select *
from Marmitex where Descricao = '" + cmbDescricaoMarmitex.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
257
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantMarmitex.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodMarmitex =
int.Parse(cmbCodMarmitex.Text);
itempedido.Obs = txtObsMarmitex.Text;
itempedido.AdicionaItemPedidoMarmitex();
cmbQuantMarmitex.Text = "";
cmbDescricaoMarmitex.Text = "";
cmbCodMarmitex.Text = "";
lblinfoMarmitex.Visible = true;
}
else if (tsTipoPedido.Text == "Entrega")
{
if (txtCodCli.Text == "" ||
txtEntregador.Text == "")
{
MessageBox.Show("Selecione um Cliente
e o Entregador", "Selecionar Cliente e Entregadr");
}
else
{
SqlCommand cmd = new
SqlCommand("Select * from Pedido where StatusPedido = 'EM ABERTO' and
TipoPedido = 'Entrega' and CodPedido not in ('" + Codpedido + "') and
CodCliente = " + txtCodCli.Text, Conecta.CON());
SqlDataReader dr =
cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("J existe um
pedido em aberto para este cliente", "ERRO");
SqlCommand cmdBuscaCodPedido = new
SqlCommand("Select * from Pedido where CodCliente is NULL and
TipoPedido = 'Entrega'", Conecta.CON());
SqlDataReader drBuscaCodPedido =
cmdBuscaCodPedido.ExecuteReader();
if (drBuscaCodPedido.Read())
{
Codpedido =
drBuscaCodPedido["CodPedido"].ToString();
258
SqlCommand cmddelete = new
SqlCommand("Delete from Pedido where CodPedido = " + Codpedido,
Conecta.CON());
cmddelete.ExecuteNonQuery();
}
}
else
{
if (txtCodCli.Text != "")
{
SqlCommand cmde = new
SqlCommand("Select * from Marmitex where Descricao = '" +
cmbDescricaoMarmitex.Text + "'", Conecta.CON());
SqlDataReader dre =
cmde.ExecuteReader();
if (dre.Read())
{
preco =
dre["Valor"].ToString();
}
ClassItemPedido itempedido =
new ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantMarmitex.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodMarmitex =
int.Parse(cmbCodMarmitex.Text);
itempedido.Obs =
txtObsMarmitex.Text;
itempedido.AdicionaItemPedidoMarmitex();
ClassPedido classePedido = new
ClassPedido();
classePedido.CodPedido =
int.Parse(tsCodPedido.Text);
classePedido.CodCliente =
int.Parse(txtCodCli.Text);
classePedido.AtualizaCodCliente();
classePedido.Entregador =
txtEntregador.Text;
classePedido.AlteraEntragador();
//MessageBox.Show("Itens
adicionados ao pedido", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
cmbQuantMarmitex.Text = "";
cmbDescricaoMarmitex.Text =
"";
259
cmbCodMarmitex.Text = "";
lblinfoMarmitex.Visible =
true;
}
}
}
}
}
// SELF SERVICE
if (cmbCodSelf.Text != "" || cmbQuantSelf.Text !=
"" || txtValorSelfQuilo.Text != "")
{
if (tsTipoPedido.Text == "Mesa" ||
tsTipoPedido.Text == "Balco")
{
if (cmbCodSelf.Text == "1")
{
SqlCommand cmd = new
SqlCommand("Select * from SelfService where CodSelfService = '" +
cmbCodSelf.Text + "'", Conecta.CON());
SqlDataReader dr =
cmd.ExecuteReader();
if (dr.Read())
{
preco = dr["Valor"].ToString();
}
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantSelf.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(preco);
itempedido.CodSelf =
int.Parse(cmbCodSelf.Text);
itempedido.AdicionaItemPedidoSelf();
cmbQuantSelf.Text = "";
cmbTipoSelf.Text = "";
cmbCodSelf.Text = "";
txtValorSelfQuilo.Text = "";
lblPrato.Visible = true;
}
else
{
if (txtValorSelfQuilo.Text == "")
{
MessageBox.Show("Informe o valor
total/Quilo do prato de self service", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
260
}
else
{
ClassItemPedido itempedido = new
ClassItemPedido();
itempedido.Quantidade =
int.Parse(cmbQuantSelf.Text);
itempedido.CodPedido =
int.Parse(tsCodPedido.Text);
itempedido.ValorUnitario =
double.Parse(txtValorSelfQuilo.Text);
itempedido.CodSelf =
int.Parse(cmbCodSelf.Text);
itempedido.AdicionaItemPedidoSelf();
cmbQuantSelf.Text = "";
cmbTipoSelf.Text = "";
cmbCodSelf.Text = "";
txtValorSelfQuilo.Text = "";
lblPrato.Visible = true;
}
}
}
}
}
}
catch (Exception erro)
{
MessageBox.Show("Boto adicionar ao pedido tela cad
pedido " + erro);
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodBebida_TextChanged(object sender, EventArgs
e)
{
lblinfoBebida.Visible = false;
}
private void cmbCodEsfiha_TextChanged(object sender, EventArgs
e)
261
{
lblinfoEsfiha.Visible = false;
}
private void cmbCodMarmitex_TextChanged(object sender,
EventArgs e)
{
lblinfoMarmitex.Visible = false;
}
private void cmbCodSelf_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
SelfService", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbCodSelf.DataSource = dt;
cmbCodSelf.DisplayMember = "CodSelfService";
cmbCodSelf.SelectedIndex = -1;
cmbTipoSelf.SelectedIndex = -1;
}
catch
{
MessageBox.Show("click cmb cod self");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodSelf_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
SelfService where CodSelfService = '" + cmbCodSelf.Text + "'",
Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbTipoSelf.DataSource = dt;
cmbTipoSelf.DisplayMember = "TipoSelfService";
if (cmbCodSelf.Text == "2")
{
txtValorSelfQuilo.Enabled = true;
txtValorSelfQuilo.BackColor = Color.Aqua;
}
else
{
txtValorSelfQuilo.Enabled = false;
}
}
catch
{
// MessageBox.Show("text changed cmb cod marmitex");
}
finally
262
{
Conecta.CON().Close();
}
}
private void cmbTipoSelf_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
SelfService", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbTipoSelf.DataSource = dt;
cmbTipoSelf.DisplayMember = "TipoSelfService";
cmbTipoSelf.SelectedIndex = -1;
cmbTipoSelf.SelectedIndex = -1;
}
catch
{
MessageBox.Show("click cmb tipo Self");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbTipoSelf_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
SqlDataAdapter cmd2 = new SqlDataAdapter("select *
from SelfService where TipoSelfService = '" + cmbTipoSelf.Text + "'",
Conecta.CON());
DataTable dt2 = new DataTable();
cmd2.Fill(dt2);
cmbCodSelf.DataSource = dt2;
cmbCodSelf.DisplayMember = "CodSelfService";
}
catch
{
//MessageBox.Show("text changed cmb descricao
marmitex");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbCodSelf_TextChanged(object sender, EventArgs
e)
{
if (cmbCodSelf.Text == "2")
{
cmbQuantSelf.Text = "1";
cmbQuantSelf.Enabled = false;
txtValorSelfQuilo.BackColor = Color.Aqua;
263
}
else
{
cmbQuantSelf.Enabled = true;
txtValorSelfQuilo.BackColor = Color.White;
}
lblPrato.Visible = false;
}
private void txtValorSelfQuilo_TextChanged(object sender,
EventArgs e)
{
txtValorSelfQuilo.BackColor = Color.White;
}
264
MessageBox.Show("Evento text changed do txt
consulta tel");
}
finally
{
Conecta.CON().Close();
}
}
}
private void cmbNomeBebida_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter cmd = new SqlDataAdapter("select * from
Bebida", Conecta.CON());
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbNomeBebida.DataSource = dt;
cmbNomeBebida.DisplayMember = "Descricao";
cmbNomeBebida.SelectedIndex = -1;
cmbCodBebida.SelectedIndex = -1;
}
catch
{
MessageBox.Show("click cmb nome bebida");
}
finally
{
Conecta.CON().Close();
}
}
private void txtConsultaCod_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 )
{
e.Handled = true;
}
}
private void cmbCodPizza_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 )
{
e.Handled = true;
}
}
private void cmbCodBebida_KeyPress(object sender,
KeyPressEventArgs e)
265
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8
{
e.Handled = true;
}
}
private void txtValorSelfQuilo_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
}
}
frmCadPizza
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadPizza : Form
{
public frmCadPizza()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
ClassPizza ClassePizza = new ClassPizza();
string CodPizza = "";
private string cargo;
public string Cargo
{
get { return cargo; }
set { cargo = value; }
}
public void Limpar()
266
{
CodPizza = "";
txtNomePizza.Text = "";
txtDesc.Text = "";
txtValor.Text = "";
txtNomePizza.Focus();
}
public void Consultar()
{
SqlDataAdapter todasPizzas = new SqlDataAdapter("select *
from Pizza ", Conecta.CON());
DataSet ds = new DataSet();
todasPizzas.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
267
MessageBox.Show("Para Excluir um registro voc
precisa escolher uma pizza", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
DialogResult dr = MessageBox.Show("Excluir
cadastro de Pizza", "Excluir Pizza", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
ClassePizza.CodPizza = int.Parse(CodPizza);
ClassePizza.ExcluiPizza();
MessageBox.Show("Pizza Excluida com Sucesso",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
Consultar();
Limpar();
}
}
}
catch
{
MessageBox.Show("Impossvel excluir esse
registro\nPode haver pedidos com este item", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Conecta.CON().Close();
}
}
268
ClassePizza.Descricao = txtDesc.Text;
ClassePizza.Valor = double.Parse(txtValor.Text);
ClassePizza.AlterPizza();
MessageBox.Show("Dados da Pizza alterados com
sucesso!", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Limpar();
Consultar();
}
catch
{
MessageBox.Show("Erro ao Alterar dados da Pizza!\n
Verifique se os campos esto preenchidos corretamente \n e tente
novamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtNomePizza.Focus();
}
finally
{
Conecta.CON().Close();
}
}
private void frmCadPizza_Load(object sender, EventArgs e)
{
if (Cargo == "Administrador")
{
gbDadosPizza.Enabled = true;
}
else
{
gbDadosPizza.Enabled = false;
}
Consultar();
}
private void btnNovo_Click(object sender, EventArgs e)
{
if (txtNomePizza.Text != "" || txtValor.Text != "" ||
txtDesc.Text != "")
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
Limpar();
txtNomePizza.Focus();
}
}
else
{
Limpar();
txtNomePizza.Focus();
}
}
private void dataGridView1_DoubleClick(object sender,
EventArgs e)
269
{
CodPizza =
dataGridView1.SelectedCells[0].Value.ToString();
txtNomePizza.Text =
dataGridView1.SelectedCells[1].Value.ToString();
txtDesc.Text =
dataGridView1.SelectedCells[2].Value.ToString();
txtValor.Text =
dataGridView1.SelectedCells[3].Value.ToString();
}
private void cmbDescPizza_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
if (cmbNomePizza.Text == "")
{
Consultar();
}
else
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Pizza where NomePizza = '" + cmbNomePizza.Text + "'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
270
SqlDataAdapter da = new SqlDataAdapter("Select *
from Pizza where NomePizza like '%" + cmbNomePizza.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void txtNomePizza_MouseClick(object sender,
MouseEventArgs e)
{
}
private void txtNomePizza_Validated(object sender, EventArgs
e)
{
}
private void txtValor_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void txtValor_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadastrar_Click(sender, e);
break;
}
}
}
}
271
frmCadSelfService
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmCadSelfService : Form
{
public frmCadSelfService()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
ClassSelfService self = new ClassSelfService();
string CodSelf = "";
private string cargo;
public string Cargo
{
get { return cargo; }
set { cargo = value; }
}
public void Consultar()
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
SelfService", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch { }
finally
{
Conecta.CON().Close();
}
}
public void Limpar()
{
CodSelf = "";
txtTipoSelf.Clear();
txtValor.Clear();
}
private void frmSelfService_Load(object sender, EventArgs e)
{
if (Cargo == "Administrador")
272
{
gbSelf.Enabled = true;
}
else
{
gbSelf.Enabled = false;
}
Consultar();
}
private void dataGridView1_DoubleClick(object sender,
EventArgs e)
{
try
{
CodSelf =
dataGridView1.SelectedCells[0].Value.ToString();
txtTipoSelf.Text =
dataGridView1.SelectedCells[1].Value.ToString();
txtValor.Text =
dataGridView1.SelectedCells[2].Value.ToString();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnAlterar_Click(object sender, EventArgs e)
{
try
{
if (CodSelf == "")
{
MessageBox.Show("Selecione um registro para
alterar", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txtTipoSelf.Text == "")
{
MessageBox.Show("Verifique se o campo Tipo Self
Service foi preenchido corretamente", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else if (txtValor.Text == "")
{
self.CodSelf = CodSelf;
self.TipoSelf = txtTipoSelf.Text;
self.Alterar();
self.DeletaPrecoQuilo();
MessageBox.Show("Dados Alterados", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Consultar();
Limpar();
273
}
else
{
self.CodSelf = CodSelf;
self.TipoSelf = txtTipoSelf.Text;
self.Valor = double.Parse(txtValor.Text);
self.Alterar();
MessageBox.Show("Dados Alterados", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Consultar();
Limpar();
}
}
catch
{
MessageBox.Show("Verifique se todos os campos foram
preenchidos corretamente");
}
finally
{
Conecta.CON().Close();
}
}
private void btnExcluir_Click(object sender, EventArgs e)
{
try
{
if (CodSelf == "")
{
MessageBox.Show("Selecione um registro para
Excluir", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (CodSelf == "1" || CodSelf == "2")
{
MessageBox.Show("Impossvel Excluir esse
registro", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
DialogResult dr = MessageBox.Show("Tem certeza de
que deseja excluir este registro?", "Excluir",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
self.CodSelf = CodSelf;
self.Excluir();
MessageBox.Show("Dados Excludos", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Consultar();
Limpar();
}
}
}
catch
{
MessageBox.Show("Impossvel excluir esse
registro\nPode haver pedidos com este item", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
274
finally
{
Conecta.CON().Close();
}
}
frmContasApagar
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
275
namespace IniciandoDavilla
{
public partial class frmContasPagar : Form
{
public frmContasPagar()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
ClassContasPagar ClasseConta = new ClassContasPagar();
frmMostraPedidos principal = new frmMostraPedidos();
private string codFun;
public string CodFun
{
get { return codFun; }
set { codFun = value; }
}
private string busca;
public string Busca
{
get { return busca; }
set { busca = value; }
}
string CodConta;
public void BuscaTodasContas()
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Fornecedor.NomeEmpresa AS Fornecedor, ContasApagar.* FROM ContasApagar
INNER JOIN Fornecedor ON ContasApagar.CodFornecedor =
Fornecedor.CodFornecedor ", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
public void Limpar()
{
cmbNomeForncecedor.Text = "";
txtValorApagar.Clear();
txtDataVencimento.Text="";
txtDataAviso.Clear();
txtDataQuitacao.Clear();
CodConta = "";
cmbStatusConta.Text = "";
txtDescricao.Clear();
cmbNomeForncecedor.SelectedIndex = -1;
cmbStatusConta.SelectedIndex = -1;
}
private void frmContasPagar_Load(object sender, EventArgs e)
{
if (Busca == "
276
{
BuscaTodasContas();
PopulaComboFornecedor();
Limpar();
}
else
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Fornecedor.NomeEmpresa AS Fornecedor, ContasApagar.* FROM ContasApagar
INNER JOIN Fornecedor ON ContasApagar.CodFornecedor =
Fornecedor.CodFornecedor where CONVERT(nvarchar(10), DataVencimento,
103) like '" + Busca + "%' and StatusConta = 'Pendente' ",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
PopulaComboFornecedor();
}
}
public void PopulaComboFornecedor()
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
Fornecedor order by NomeEmpresa", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
cmbNomeForncecedor.DataSource = ds.Tables[0];
cmbNomeForncecedor.DisplayMember = "NomeEmpresa";
cmbNomeForncecedor.SelectedIndex = -1;
}
catch
{
MessageBox.Show("Erro evento click cmb busca nome
fun");
}
}
private void cmbNomeForncecedor_Click(object sender, EventArgs
e)
{
PopulaComboFornecedor();
}
private void btnCadastrar_Click(object sender, EventArgs e)
{
if (cmbNomeForncecedor.Text == "" ||
txtDataVencimento.Text == "" || txtValorApagar.Text == "" ||
cmbStatusConta.Text == "")
{
MessageBox.Show("Preencha o campo Fornecedor,
DataVencimento Valor Pagar e o Status da Conta", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (cmbStatusConta.Text == "Quitada" &&
txtDataQuitacao.Text == " / /")
{
MessageBox.Show("Para contas QUITADAS, informe a data
da Quitao", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
277
}
else
{
try
{
ClasseConta.CodConta = CodConta;
ClasseConta.NomeFornecedor =
cmbNomeForncecedor.Text;
ClasseConta.CodFuncionario = int.Parse(CodFun);
ClasseConta.ValoraPagar =
double.Parse(txtValorApagar.Text);
ClasseConta.DataVencimento =
Convert.ToDateTime(txtDataVencimento.Text);
ClasseConta.StatusConta = cmbStatusConta.Text;
ClasseConta.TrocaNomeFornecedorPorCod();
ClasseConta.CadConta();
if (txtDataAviso.Text != " / /")
{
ClasseConta.DataAviso =
Convert.ToDateTime(txtDataAviso.Text);
//ClasseConta.CadConta();
ClasseConta.CapturaUltimoCodConta();
ClasseConta.CadDataAviso();
}
if (txtDescricao.Text != "")
{
ClasseConta.Descricao = txtDescricao.Text;
//ClasseConta.CadConta();
ClasseConta.CapturaUltimoCodConta();
ClasseConta.CadDescricao();
}
if (txtDataQuitacao.Text != " / /")
{
ClasseConta.DataQuitacao =
Convert.ToDateTime(txtDataQuitacao.Text);
////ClasseConta.CadConta();
ClasseConta.CapturaUltimoCodConta();
ClasseConta.AtualizaDataQuitacao();
}
if (txtDataAviso.Text == " / /" &&
txtDescricao.Text == "" && txtDataQuitacao.Text == " / /")
{
ClasseConta.CadConta();
}
MessageBox.Show("Conta Cadastrada com Sucesso",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
BuscaTodasContas();
}
catch
{
MessageBox.Show("Erro no boto cadastrar");
}
finally
{
278
Conecta.CON().Close();
}
}
}
private void txtDataAvisa_Validated(object sender, EventArgs
e)
{
}
private void txtDataAvisa_Click(object sender, EventArgs e)
{
}
private void btnConsultar_Click(object sender, EventArgs e)
{
try
{
if (cmbConsultarPor.Text == "" || txtBusca.Text ==""
|| txtBusca.Text == " / /")
{
BuscaTodasContas();
}
else
{
if (cmbConsultarPor.Text == "Empresa")
{
string CodFun = ClasseConta.CodFornecedor;
SqlDataAdapter da = new SqlDataAdapter("SELECT
Fornecedor.NomeEmpresa AS Fornecedor, ContasApagar.* FROM ContasApagar
INNER JOIN Fornecedor ON ContasApagar.CodFornecedor =
Fornecedor.CodFornecedor where Fornecedor.NomeEmpresa like '%" +
txtBusca.Text + "%'", Conecta.CON());
SqlDataAdapter da2 = new
SqlDataAdapter("SELECT Fornecedor.NomeEmpresa AS Fornecedor,
ContasApagar.* FROM ContasApagar INNER JOIN Fornecedor ON
ContasApagar.CodFornecedor = Fornecedor.CodFornecedor where
Fornecedor.NomeEmpresa like '%" + txtBusca.Text + "%' and StatusConta
= 'Pendente'", Conecta.CON());
ClasseConta.NomeFornecedor = txtBusca.Text;
ClasseConta.TrocaNomeFornecedorPorCod();
DataSet ds = new DataSet();
if (chekSomentePendentes.Checked == true)
{
da2.Fill(ds);
}
else
{
da.Fill(ds);
}
dataGridView1.DataSource = ds.Tables[0];
279
}
else if (cmbConsultarPor.Text == "Cdigo do
Funcionrio")
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Fornecedor.NomeEmpresa AS Fornecedor, ContasApagar.* FROM ContasApagar
INNER JOIN Fornecedor ON ContasApagar.CodFornecedor =
Fornecedor.CodFornecedor where CodFuncionario = "+ txtBusca.Text,
Conecta.CON());
SqlDataAdapter da2 = new
SqlDataAdapter("SELECT Fornecedor.NomeEmpresa AS Fornecedor,
ContasApagar.* FROM ContasApagar INNER JOIN Fornecedor ON
ContasApagar.CodFornecedor = Fornecedor.CodFornecedor where
CodFuncionario = "+ txtBusca.Text + " and StatusConta = 'Pendente'",
Conecta.CON());
DataSet ds = new DataSet();
if (chekSomentePendentes.Checked == true)
{
da2.Fill(ds);
}
else
{
da.Fill(ds);
}
dataGridView1.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "Data de
Vencimento")
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Fornecedor.NomeEmpresa AS Fornecedor, ContasApagar.* FROM ContasApagar
INNER JOIN Fornecedor ON ContasApagar.CodFornecedor =
Fornecedor.CodFornecedor where CONVERT(nvarchar(10), DataVencimento,
103) like '%" + txtBusca.Text + "%'", Conecta.CON());
SqlDataAdapter da2 = new
SqlDataAdapter("SELECT Fornecedor.NomeEmpresa AS Fornecedor,
ContasApagar.* FROM ContasApagar INNER JOIN Fornecedor ON
ContasApagar.CodFornecedor = Fornecedor.CodFornecedor where
CONVERT(nvarchar(10), DataVencimento, 103) like '%" + txtBusca.Text +
"%' and StatusConta = 'Pendente'", Conecta.CON());
DataSet ds = new DataSet();
if (chekSomentePendentes.Checked == true)
{
da2.Fill(ds);
}
else
{
da.Fill(ds);
}
dataGridView1.DataSource = ds.Tables[0];
}
}
}
280
catch
{
MessageBox.Show("Erro botao consulta");
}
finally
{
Conecta.CON().Close();
}
}
private void dataGridView1_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
cmbNomeForncecedor.Text =
dataGridView1.SelectedCells[0].Value.ToString();
CodConta =
dataGridView1.SelectedCells[1].Value.ToString();
txtDescricao.Text =
dataGridView1.SelectedCells[3].Value.ToString();
txtValorApagar.Text =
dataGridView1.SelectedCells[5].Value.ToString();
txtDataVencimento.Text =
dataGridView1.SelectedCells[6].Value.ToString();
txtDataAviso.Text =
dataGridView1.SelectedCells[7].Value.ToString();
cmbStatusConta.Text =
dataGridView1.SelectedCells[8].Value.ToString();
txtDataQuitacao.Text =
dataGridView1.SelectedCells[9].Value.ToString();
}
catch { }
}
private void tabPage2_Click(object sender, EventArgs e)
{
}
private void txtValorApagar_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void txtBusca_TextChanged(object sender, EventArgs e)
{
}
private void cmbConsultarPor_TextChanged(object sender,
EventArgs e)
{
if (cmbConsultarPor.Text == "Data de Vencimento")
281
{
txtBusca.Mask = "00/00/0000";
}
else
{
txtBusca.Mask = "";
}
}
private void btnAlterar_Click(object sender, EventArgs e)
{
if (cmbNomeForncecedor.Text == "" ||
txtDataVencimento.Text == "" || txtValorApagar.Text == "" ||
cmbStatusConta.Text == "")
{
MessageBox.Show("Preencha o campo Fornecedor,
DataVencimento Valor Pagar e o Status da Conta", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (cmbStatusConta.Text == "Quitada" &&
txtDataQuitacao.Text == " / /")
{
MessageBox.Show("Para contas QUITADAS, informe a data
da Quitao", "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
ClasseConta.CodConta = CodConta;
ClasseConta.NomeFornecedor =
cmbNomeForncecedor.Text;
ClasseConta.CodFuncionario = int.Parse(CodFun);
ClasseConta.ValoraPagar =
double.Parse(txtValorApagar.Text);
ClasseConta.DataVencimento =
Convert.ToDateTime(txtDataVencimento.Text);
ClasseConta.StatusConta = cmbStatusConta.Text;
ClasseConta.TrocaNomeFornecedorPorCod();
if (txtDataAviso.Text != " / /")
{
ClasseConta.DataAviso =
Convert.ToDateTime(txtDataAviso.Text);
ClasseConta.AlteraConta();
ClasseConta.CadDataAviso();
}
if (txtDescricao.Text != "")
{
ClasseConta.Descricao = txtDescricao.Text;
ClasseConta.AlteraConta();
ClasseConta.CadDescricao();
}
if (txtDataQuitacao.Text != " / /")
{
ClasseConta.DataQuitacao =
Convert.ToDateTime(txtDataQuitacao.Text);
282
ClasseConta.AlteraConta();
ClasseConta.AtualizaDataQuitacao();
}
if (txtDataAviso.Text == "
{
/")
ClasseConta.AlteraConta();
ClasseConta.ExcluiDataAviso();
}
if (txtDataAviso.Text == " / /" &&
txtDescricao.Text == "" && txtDataQuitacao.Text != " / /")
{
ClasseConta.AlteraConta();
}
MessageBox.Show("Conta Alterada com Sucesso",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
BuscaTodasContas();
CodConta = "";
}
catch
{
MessageBox.Show("Erro no boto cadastrar");
}
finally
{
Conecta.CON().Close();
}
}
}
private void btnNovo_Click(object sender, EventArgs e)
{
if (txtDescricao.Text != "" || txtDataAviso.Text != " /
/" || txtDataQuitacao.Text != " / /" || txtDataVencimento.Text != "
/ /" || cmbNomeForncecedor.Text != "" || cmbStatusConta.Text != "" ||
txtValorApagar.Text != "")
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
Limpar();
}
}
else
{
Limpar();
}
}
private void btnExcluir_Click(object sender, EventArgs e)
{
283
if (CodConta == "")
{
MessageBox.Show("Selecione uma conta para excluir",
"ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
DialogResult dr = MessageBox.Show("Tem certeza de que
deseja Excluir esta Conta?", "Excluir Conta", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
ClasseConta.CodConta = (CodConta);
ClasseConta.ExcluiConta();
MessageBox.Show("Conta Excluda do sistema",
"SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
BuscaTodasContas();
}
}
}
private void chekSomentePendentes_CheckedChanged(object
sender, EventArgs e)
{
}
private void btnSomarContasPendentes_Click(object sender,
EventArgs e)
{
pnContasQuitadas.Visible = false;
pnQuitPenPorFun.Visible = false;
pnSomarContasPendentes.Visible = true;
try
{
SqlCommand cmd = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where StatusConta =
'Pendente'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblTotalContasPendentes.Text =
dr["Soma"].ToString();
}
}
catch
{
MessageBox.Show("Erro boto Somar contas pendentes");
}
finally
{
Conecta.CON().Close();
}
}
private void txtBuscaTotalContaPorDia_TextChanged(object
sender, EventArgs e)
{
try
284
{
SqlCommand cmd = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where CONVERT(nvarchar(10),
DataVencimento, 103) = '" + txtBuscaTotalContaPorDia.Text + "' and
StatusConta = 'Pendente'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblTotalContasDiaPend.Text =
dr["Soma"].ToString();
}
}
catch
{
MessageBox.Show("text changed dataBuscaContaTotal");
}
finally
{
Conecta.CON().Close();
}
}
private void btnSomarContasQuitadas_Click(object sender,
EventArgs e)
{
pnSomarContasPendentes.Visible = false;
pnQuitPenPorFun.Visible = false;
pnContasQuitadas.Visible = true;
try
{
SqlCommand cmd = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where StatusConta =
'Quitada'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblTotalQuitadas.Text = dr["Soma"].ToString();
}
}
catch
{
MessageBox.Show("Erro boto Somar contas pendentes");
}
finally
{
Conecta.CON().Close();
}
}
private void txtDataQuitadaDia_TextChanged(object sender,
EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where CONVERT(nvarchar(10),
DataVencimento, 103) = '" + txtDataQuitadaDia.Text + "' and
StatusConta = 'Quitada'", Conecta.CON());
285
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblTotalQuitadasDia.Text = dr["Soma"].ToString();
}
}
catch
{
MessageBox.Show("text changed dataBuscaContaTotal");
}
finally
{
Conecta.CON().Close();
}
}
private void btnBuscar_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd1 = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where CodFuncionario = " +
txtCodFun.Text, Conecta.CON());
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where CodFuncionario = '" +
txtCodFun.Text + "' and StatusConta = 'Pendente'", Conecta.CON());
SqlCommand cmd3 = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where CodFuncionario = '" +
txtCodFun.Text + "' and StatusConta = 'Quitada'", Conecta.CON());
if (rbTotas.Checked == true)
{
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
lblTotalContasCli.Text =
dr["Soma"].ToString();
}
}
else if (rbPendentes.Checked == true)
{
SqlDataReader dr = cmd2.ExecuteReader();
if (dr.Read())
{
lblTotalContasCli.Text =
dr["Soma"].ToString();
}
}
else if (rbQuitadas.Checked == true)
{
SqlDataReader dr = cmd3.ExecuteReader();
if (dr.Read())
{
lblTotalContasCli.Text =
dr["Soma"].ToString();
}
}
else
{
286
MessageBox.Show("Selecione um tipo de Busca e
digite o Cdigo do Cliente", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnContasPorFuncionario_Click(object sender,
EventArgs e)
{
pnContasQuitadas.Visible = false;
pnQuitPenPorFun.Visible = true;
pnSomarContasPendentes.Visible = false;
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void btnExcluirTodasContas_Click(object sender,
EventArgs e)
{
try
{
DialogResult dr = MessageBox.Show("Tem certeza de que
deseja Excluir Todas as Contas?", "Excluir Conta",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
ClasseConta.ExcluiTodasContas();
MessageBox.Show("Todas as Contas foram Excludas",
"SUCESSO", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
BuscaTodasContas();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnNovoFornecedor_Click(object sender, EventArgs
e)
{
287
}
}
frmEstoque
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
288
using System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmEstoque : Form
{
public frmEstoque()
{
InitializeComponent();
}
private string buscaValidade;
public string BuscaValidade
{
get { return buscaValidade; }
set { buscaValidade = value; }
}
private string buscaEstoqueMinimo;
public string BuscaEstoqueMinimo
{
get { return buscaEstoqueMinimo; }
set { buscaEstoqueMinimo = value; }
}
string CodProd;
string verificaProdutoDuplicado;
ClassProdutoEstoque ClassProdEstoque = new
ClassProdutoEstoque();
ClassConexao Conecta = new ClassConexao();
public void LimparCampos()
{
cmbBuscaNomeProduto.SelectedIndex = -1;
cmbFornecedorEstoque.SelectedIndex = -1;
txtDescricao.Clear();
txtTipoUnidade.Clear();
txtQtde.Clear();
txtDataValidade.Clear();
txtDataAviso.Clear();
txtEstoqueMin.Clear();
txtObservacoes.Clear();
CodProd = "";
}
public SqlDataAdapter PopulacomboFornecedor()
{
SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM
Fornecedor order by NomeEmpresa", Conecta.CON());
try
{
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbFornecedorEstoque.DataSource = dt;
cmbFornecedorEstoque.DisplayMember = "NomeEmpresa";
289
cmbFornecedorEstoque.SelectedIndex = -1;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlDataAdapter PopulacomboConsulta()
{
SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM
Estoque order by Descricao", Conecta.CON());
try
{
DataTable dt = new DataTable();
cmd.Fill(dt);
cmbBuscaNomeProduto.DataSource = dt;
cmbBuscaNomeProduto.DisplayMember = "Descricao";
cmbBuscaNomeProduto.SelectedIndex = -1;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public void BuscaEstoque()
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Fornecedor.NomeEmpresa AS Fornecedor, Estoque.* FROM Estoque INNER
JOIN Fornecedor ON Estoque.CodFornecedor = Fornecedor.CodFornecedor",
Conecta.CON());
try
{
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
290
public SqlCommand VerificaDuplicacaoProduto()
{
SqlCommand cmd = new SqlCommand("SELECT * FROM Estoque
WHERE Descricao = '" + txtDescricao.Text + "'", Conecta.CON());
try
{
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
verificaProdutoDuplicado =
dr["Descricao"].ToString();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
291
JOIN Fornecedor ON Estoque.CodFornecedor = Fornecedor.CodFornecedor
where Quantidade <= EstoqueMin", Conecta.CON());
DataSet ds2 = new DataSet();
da2.Fill(ds2);
dataGridView1.DataSource = ds2.Tables[0];
PopulacomboFornecedor();
}
else
{
BuscaEstoque();
PopulacomboFornecedor();
LimparCampos();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnNovoProduto_Click(object sender, EventArgs e)
{
if (txtDescricao.Text != "" || txtDataAviso.Text != " /
/" || txtEstoqueMin.Text != " / /" || txtDataValidade.Text != " /
/" || cmbFornecedorEstoque.Text != "" || txtObservacoes.Text != "" ||
txtTipoUnidade.Text != "" || txtQtde.Text != "")
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
LimparCampos();
}
}
else
{
LimparCampos();
}
}
private void btnCadastrarProduto_Click(object sender,
EventArgs e)
{
VerificaDuplicacaoProduto();
if (verificaProdutoDuplicado == txtDescricao.Text)
{
MessageBox.Show("Produto ja existe, verifique a
Descrio", "ERRO");
}
292
else if (cmbFornecedorEstoque.Text == "" ||
txtDescricao.Text == "" || txtTipoUnidade.Text == "" || txtQtde.Text
== "" || txtDataValidade.Text == " / /")
{
MessageBox.Show("Campos Obrigatrios \n\nFornecedor
\nDescrio \nTipoUnidade \nQuantidade \nData Validade", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
ClassProdEstoque.CodProd = CodProd;
ClassProdEstoque.Descricao = txtDescricao.Text;
ClassProdEstoque.TipoUnidade =
txtTipoUnidade.Text;
ClassProdEstoque.Quantidade =
double.Parse(txtQtde.Text);
ClassProdEstoque.Validade = txtDataValidade.Text;
ClassProdEstoque.Observacoes =
txtObservacoes.Text;
ClassProdEstoque.TrocarNomeFornecedorPorCodigo(cmbFornecedorEstoque.Te
xt);
ClassProdEstoque.CadProdutoEstoque();
if (txtDataAviso.Text != " / /")
{
ClassProdEstoque.DataAviso =
txtDataAviso.Text;
ClassProdEstoque.CapturaUltimoCodProduto();
ClassProdEstoque.CadDataAviso();
}
if (txtEstoqueMin.Text != "")
{
ClassProdEstoque.EstoqueMin =
double.Parse(txtEstoqueMin.Text);
ClassProdEstoque.CapturaUltimoCodProduto();
ClassProdEstoque.CadEstoqueMinimo();
}
293
}
}
private void cmbFornecedorEstoque_Click(object sender,
EventArgs e)
{
PopulacomboFornecedor();
}
private void cmbBuscaNomeProduto_Click(object sender,
EventArgs e)
{
PopulacomboConsulta();
}
private void btnAlterarProduto_Click(object sender, EventArgs
e)
{
if (cmbFornecedorEstoque.Text == "" ||
txtDescricao.Text == "" || txtTipoUnidade.Text == "" || txtQtde.Text
== "" || txtDataValidade.Text == " / /")
{
MessageBox.Show("Campos Obrigatrios \n\nFornecedor
\nDescrio \nTipoUnidade \nQuantidade \nData Validade", "ERRO",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
ClassProdEstoque.CodProd = CodProd;
ClassProdEstoque.Descricao = txtDescricao.Text;
ClassProdEstoque.TipoUnidade =
txtTipoUnidade.Text;
ClassProdEstoque.Quantidade =
double.Parse(txtQtde.Text);
ClassProdEstoque.Validade = txtDataValidade.Text;
ClassProdEstoque.Observacoes =
txtObservacoes.Text;
ClassProdEstoque.TrocarNomeFornecedorPorCodigo(cmbFornecedorEstoque.Te
xt);
if (txtDataAviso.Text != " / /")
{
ClassProdEstoque.DataAviso =
txtDataAviso.Text;
ClassProdEstoque.AlteraEstoque();
ClassProdEstoque.CadDataAviso();
}
if (txtDataAviso.Text == " / /")
{
ClassProdEstoque.AlteraEstoque();
ClassProdEstoque.ExcluiDataAviso();
}
if (txtEstoqueMin.Text != "")
{
294
ClassProdEstoque.EstoqueMin =
double.Parse(txtEstoqueMin.Text);
ClassProdEstoque.AlteraEstoque();
ClassProdEstoque.CadEstoqueMinimo();
}
if (txtEstoqueMin.Text == "")
{
ClassProdEstoque.AlteraEstoque();
ClassProdEstoque.ExcluiEstoqueMinimo();
}
MessageBox.Show("Produto alterado com sucesso",
"Sucesso");
LimparCampos();
BuscaEstoque();
}
catch
{
MessageBox.Show("Erro ao Alterar", "Erro");
}
finally
{
Conecta.CON().Close();
}
}
}
private void btnExcluiProduto_Click(object sender, EventArgs
e)
{
if (CodProd == "")
{
MessageBox.Show("Selecione um Produto para excluir",
"ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
try
{
DialogResult dr = MessageBox.Show("Tem certeza que
deseja excluir este Produto?", "Excluir Produto",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
ClassProdEstoque.CodProdutoEstoque =
int.Parse(CodProd);
ClassProdEstoque.ExcluiEstoque();
MessageBox.Show("Produto Excludo com
sucesso", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
LimparCampos();
BuscaEstoque();
}
}
catch
{
}
}
295
}
private void btnPesquisar_Click(object sender, EventArgs e)
{
cmbBuscaNomeProduto.Text = "";
cmbBuscaNomeProduto.Focus();
}
private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
string CodFornecedor;
try
{
cmbFornecedorEstoque.Text =
dataGridView1.SelectedCells[0].Value.ToString();
CodProd =
dataGridView1.SelectedCells[1].Value.ToString();
CodFornecedor =
dataGridView1.SelectedCells[2].Value.ToString();
txtDescricao.Text =
dataGridView1.SelectedCells[3].Value.ToString();
txtTipoUnidade.Text =
dataGridView1.SelectedCells[4].Value.ToString();
txtQtde.Text =
dataGridView1.SelectedCells[5].Value.ToString();
txtEstoqueMin.Text =
dataGridView1.SelectedCells[6].Value.ToString();
txtDataValidade.Text =
dataGridView1.SelectedCells[7].Value.ToString();
txtDataAviso.Text =
dataGridView1.SelectedCells[8].Value.ToString();
txtObservacoes.Text =
dataGridView1.SelectedCells[9].Value.ToString();
}
catch
{
MessageBox.Show("Erro!!!");
}
finally
{
Conecta.CON().Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
DialogResult dr = MessageBox.Show("Tem certeza que
deseja excluir todos os Produto do estoque???", "Excluir Estoque",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
ClassProdEstoque.ExcluiTodoEstoque();
296
MessageBox.Show("Todos os Produtos Excludos com
sucesso", "Sucesso", MessageBoxButtons.OK,
MessageBoxIcon.Information);
BuscaEstoque();
}
}
catch
{
DialogResult res = MessageBox.Show("Erro ao excluir
registros!", "Alerta", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
private void cmbBuscaNomeProduto_TextChanged(object sender,
EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Fornecedor.NomeEmpresa AS Fornecedor, Estoque.* FROM Estoque INNER
JOIN Fornecedor ON Estoque.CodFornecedor = Fornecedor.CodFornecedor
where Descricao like '%" + cmbBuscaNomeProduto.Text + "%'",
Conecta.CON());
try
{
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void txtQtde_KeyPress(object sender, KeyPressEventArgs
e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void txtEstoqueMin_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
297
}
private void txtObservacoes_KeyPress(object sender,
KeyPressEventArgs e)
{
}
private void txtObservacoes_KeyUp(object sender, KeyEventArgs
e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadastrarProduto_Click(sender, e);
break;
}
}
}
}
frmFechamentoCaixa
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmFechamentoCaixa : Form
{
public frmFechamentoCaixa()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
string ValorTotalPedidos = "";
string ValorTotalContas = "";
string ValorTotalSalario = "";
string Adicional = "";
string Salario = "";
private string cargo;
public string Cargo
{
get { return cargo; }
set { cargo = value; }
}
private void cklsFechacx_SelectedIndexChanged(object sender,
EventArgs e)
{
298
}
private void btnFechaMes_Click(object sender, EventArgs e)
{
try
{
if (cmbMes.Text == "")
{
MessageBox.Show("Selecione o Ms", "Ms",
MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
else
{
try
{
SqlCommand cmd = new SqlCommand("Select
SUM(ValorTotal)as Soma from Pedido where CONVERT(nvarchar(10), Data,
110) like '" + cmbMes.Text + "%' and StatusPedido = 'FECHADO' ",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
ValorTotalPedidos = dr["Soma"].ToString();
}
}
catch { }
finally
{
Conecta.CON().Close();
}
try
{
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where CONVERT(nvarchar(10),
DataQuitacao, 110) like '" + cmbMes.Text + "%' ", Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
ValorTotalContas = dr2["Soma"].ToString();
}
}
catch
{ }
finally
{
Conecta.CON().Close();
}
try
{
SqlCommand cmd3 = new SqlCommand("Select
SUM(AdicionalSalario) As Adicional from Funcionario", Conecta.CON());
SqlDataReader dr3 = cmd3.ExecuteReader();
if (dr3.Read())
{
Adicional = dr3["Adicional"].ToString();
}
}
catch { }
299
finally
{
Conecta.CON().Close();
}
try
{
SqlCommand cmd4 = new SqlCommand("Select
SUM(Salario) as Salario FROM Cargo INNER JOIN Funcionario ON
Funcionario.CodCargo = Cargo.CodCargo ", Conecta.CON());
SqlDataReader dr4 = cmd4.ExecuteReader();
if (dr4.Read())
{
Salario = dr4["Salario"].ToString();
}
}
catch { }
finally
{
Conecta.CON().Close();
}
if (ValorTotalContas == "")
{
ValorTotalContas = "0";
}
if (ValorTotalPedidos == "")
{
ValorTotalPedidos = "0";
}
if (Adicional == "")
{
Adicional = "0";
}
if (Salario == "")
{
Salario = "0";
}
if (ValorTotalSalario == "")
{
ValorTotalSalario = "0";
}
ValorTotalSalario = (double.Parse(Adicional) +
double.Parse(Salario)).ToString();
lblFechamento.Text =
(double.Parse(ValorTotalPedidos) - double.Parse(ValorTotalContas) double.Parse(ValorTotalSalario) double.Parse(ValorTotalSalario)).ToString("C");
lblEntradaTotalVendas.Text = "R$ " +
ValorTotalPedidos;
lblContasQuitadas.Text = "R$ " + ValorTotalContas;
lblSalario.Text = (double.Parse(Adicional) +
double.Parse(Salario)).ToString("C");
300
try
{
SqlDataAdapter da = new SqlDataAdapter("Select
* From Pedido where CONVERT(nvarchar(10), Data, 110) like '" +
cmbMes.Text + "%' and StatusPedido = 'FECHADO' ", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgVendas.DataSource = ds.Tables[0];
}
catch { }
finally
{
Conecta.CON().Close();
}
try
{
SqlDataAdapter da2 = new
SqlDataAdapter("Select * from ContasApagar where CONVERT(nvarchar(10),
DataQuitacao, 110) like '" + cmbMes.Text + "%' ", Conecta.CON());
DataSet ds2 = new DataSet();
da2.Fill(ds2);
dgContas.DataSource = ds2.Tables[0];
}
catch { }
finally
{
Conecta.CON().Close();
}
try
{
SqlDataAdapter da3 = new
SqlDataAdapter("SELECT Funcionario.NomeFuncionario,
Funcionario.AdicionalSalario AS Adicional, Cargo.NomeCargo,
Cargo.Salario FROM Cargo INNER JOIN Funcionario ON
Funcionario.CodCargo = Cargo.CodCargo ", Conecta.CON());
DataSet ds3 = new DataSet();
da3.Fill(ds3);
dgSalario.DataSource = ds3.Tables[0];
}
catch { }
finally
{
Conecta.CON().Close();
}
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnFechaDia_Click(object sender, EventArgs e)
{
301
ValorTotalSalario = "0";
try
{
try
{
SqlCommand cmd = new SqlCommand("Select
SUM(ValorTotal) as Soma From Pedido where StatusPedido = 'FECHADO' and
CONVERT(nvarchar(10), Data, 103) = '" + txtFechaDia.Text + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
ValorTotalPedidos = dr["Soma"].ToString();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
try
{
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where StatusConta =
'Quitada' and CONVERT(nvarchar(10), DataQuitacao, 103) like '" +
txtFechaDia.Text + "%' ", Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
ValorTotalContas = dr2["Soma"].ToString();
}
if (ValorTotalContas == "")
{
ValorTotalContas = "0";
}
if (ValorTotalPedidos == "")
{
ValorTotalPedidos = "0";
}
if (ValorTotalSalario == "")
{
ValorTotalSalario = "0";
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
302
lblFechamento.Text = (double.Parse(ValorTotalPedidos)
- double.Parse(ValorTotalContas) double.Parse(ValorTotalSalario)).ToString("C");
lblEntradaTotalVendas.Text = "R$ " +
ValorTotalPedidos;
lblContasQuitadas.Text = "R$ " + ValorTotalContas;
lblSalario.Text = "R$ " + ValorTotalSalario;
try
{
SqlDataAdapter da = new SqlDataAdapter("Select *
From Pedido where StatusPedido = 'FECHADO' and CONVERT(nvarchar(10),
Data, 103) = '" + txtFechaDia.Text + "' ", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgVendas.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
SqlDataAdapter da2 = new SqlDataAdapter("Select * from
ContasApagar where StatusConta = 'Quitada' and CONVERT(nvarchar(10),
DataQuitacao, 103) like '" + txtFechaDia.Text + "%' ", Conecta.CON());
DataSet ds2 = new DataSet();
da2.Fill(ds2);
dgContas.DataSource = ds2.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void btnGerenciarVendas_Click(object sender, EventArgs
e)
{
303
//quando um formulrio chamado por um boto dentro de
outro form no pode ser mdip
frmTodosPedidos TodosPed = new frmTodosPedidos();
TodosPed.CargoFun = Cargo;
TodosPed.Show();
}
private void btnGerenciarContas_Click(object sender, EventArgs
e)
{
//quando um formulrio chamado por um boto dentro de
outro form no pode ser mdip
frmContasPagar contas = new frmContasPagar();
contas.MdiParent = this;
contas.Show();
}
private void btnGerenciarAdicional_Click(object sender,
EventArgs e)
{
//quando um formulrio chamado por um boto dentro de
outro form no pode ser mdip
frmCadFuncionario func = new frmCadFuncionario();
func.Show();
}
private void btnGerenciarSalario_Click(object sender,
EventArgs e)
{
//quando um formulrio chamado por um boto dentro de
outro form no pode ser mdip
frmCadCargo cargo = new frmCadCargo();
cargo.Show();
}
private void frmFechamentoCaixa_Load(object sender, EventArgs
e)
{
}
private void btnRelatorioDiario_Click(object sender, EventArgs
e)
{
}
private void btnRelatorioMensal_Click(object sender, EventArgs
e)
{
frmSelecionaRelatorios relatorios = new
frmSelecionaRelatorios();
relatorios.Show();
}
}
}
frmLembreteConta
304
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmLembreteConta : Form
{
public frmLembreteConta()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
ClassContasPagar classeContas = new ClassContasPagar();
private string data;
public string Data
{
get { return data; }
set { data = value; }
}
private string codFun;
public string CodFun
{
get { return codFun; }
set { codFun = value; }
}
private string cargo;
public string Cargo
{
get { return cargo; }
set { cargo = value; }
}
private void frmLembreteConta_Load(object sender, EventArgs e)
{
// --------------------- Data Aviso
try
{
SqlDataAdapter da = new SqlDataAdapter("Select * From
ContasApagar where StatusConta = 'Pendente' and CONVERT(nvarchar(10),
DataAviso, 103) = '" + Data + "' or CONVERT(nvarchar(10),
DataVencimento, 103) = '" + Data + "' and StatusConta = 'Pendente'",
Conecta.CON());
305
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
//dataGridView1.DataSource =
classeContas.BuscaContasPendentesPorDia(Data);
try
{
SqlCommand cmd = new SqlCommand("Select
SUM(ValorApagar)as Soma from ContasApagar where CONVERT(nvarchar(10),
DataAviso, 103) = '" + Data + "' or CONVERT(nvarchar(10),
DataVencimento, 103) = '" + Data + "' and StatusConta = 'Pendente'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblTotalContasPendentes.Text =
dr["Soma"].ToString();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
if (Cargo == "Administrador")
{
button1.Enabled = true;
}
else
{
button1.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
frmContasPagar contas = new frmContasPagar();
//contas.CodFun = CodFun;
306
contas.Busca = txtVencimento.Text;
contas.CodFun = CodFun;
//contas.MdiParent = this;
contas.Show();
}
private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
string CodFornec = txtDescricao.Text =
dataGridView1.SelectedCells[1].Value.ToString();
SqlCommand cmd = new SqlCommand("Select * from
Fornecedor where CodFornecedor = " + CodFornec, Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtEmpresa.Text = dr["NomeEmpresa"].ToString();
}
txtDescricao.Text =
dataGridView1.SelectedCells[2].Value.ToString();
txtValorTotal.Text =
dataGridView1.SelectedCells[4].Value.ToString();
txtVencimento.Text =
dataGridView1.SelectedCells[5].Value.ToString();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmLembreteValidade
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmLembreteValidade : Form
{
public frmLembreteValidade()
{
307
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
ClassProdutoEstoque classeEstoque = new ClassProdutoEstoque();
private string dataAviso;
public string DataAviso
{
get { return dataAviso; }
set { dataAviso = value; }
}
private string estoqueAviso;
public string EstoqueAviso
{
get { return estoqueAviso; }
set { estoqueAviso = value; }
}
308
if (txtQtdeAtual.Text == "")
{
DialogResult dr = MessageBox.Show("Deseja abrir o
estoque sem filtrar pela quantidade de produtos?","Abrir sem
filtro",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
if(dr==DialogResult.Yes)
{
frmEstoque FEstoque = new frmEstoque();
FEstoque.Show();
}
}
else
{
frmEstoque FrmEstoque = new frmEstoque();
FrmEstoque.BuscaEstoqueMinimo = txtQtdeAtual.Text;
FrmEstoque.Show();
}
}
catch
{
}
}
private void dataGridView1_CellClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
string CodFornecedor;
CodFornecedor =
dataGridView1.SelectedCells[1].Value.ToString();
SqlCommand cmd = new SqlCommand("SELECT * FROM
Fornecedor WHERE CodFornecedor = '" + CodFornecedor + "'",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtFornecedorValidade.Text =
dr["NomeEmpresa"].ToString();
txtDescricaoValidade.Text =
dataGridView1.SelectedCells[2].Value.ToString();
txtTipoUnidadeValidade.Text =
dataGridView1.SelectedCells[3].Value.ToString();
txtQtde.Text =
dataGridView1.SelectedCells[4].Value.ToString();
txtVencimento.Text =
dataGridView1.SelectedCells[6].Value.ToString();
}
}
catch
309
{
}
finally
{
Conecta.CON().Close();
}
}
private void frmLembreteValidade_Load(object sender, EventArgs
e)
{
DataAviso = DateTime.Now.ToString("d");
SqlDataAdapter da = new SqlDataAdapter("Select * From
Estoque where CONVERT(nvarchar(10), DataAviso, 103) = '" + DataAviso +
"' or CONVERT(nvarchar(10), Validade, 103) = '" + DataAviso + "'",
Conecta.CON());
try
{
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
SqlDataAdapter da2 = new SqlDataAdapter("Select * FROM
Estoque where Quantidade <= EstoqueMin", Conecta.CON());
try
{
DataSet ds2 = new DataSet();
da2.Fill(ds2);
dataGridView2.DataSource = ds2.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void dataGridView2_CellClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
310
string CodFornecedor;
CodFornecedor =
dataGridView2.SelectedCells[1].Value.ToString();
SqlCommand cmd2 = new SqlCommand("SELECT * FROM
Fornecedor WHERE CodFornecedor = '" + CodFornecedor + "'",
Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
txtFornecedorEstMinimo.Text =
dr2["NomeEmpresa"].ToString();
txtDescricaoEstMinimo.Text =
dataGridView2.SelectedCells[2].Value.ToString();
txtTipoUnidadeEstMinimo.Text =
dataGridView2.SelectedCells[3].Value.ToString();
txtQtdeAtual.Text =
dataGridView2.SelectedCells[4].Value.ToString();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnIrFornecedor_Click(object sender, EventArgs e)
{
frmCadFornecedor fornece = new frmCadFornecedor();
fornece.Width = 1168;
fornece.Height = 567;
fornece.Show();
}
}
}
frmLogin
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private string fechar;
311
312
frmMarmitex
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
313
namespace IniciandoDavilla
{
public partial class frmMarmitex : Form
{
public frmMarmitex()
{
InitializeComponent();
}
private string cargo;
public string Cargo
{
get { return cargo; }
set { cargo = value; }
}
ClassMarmitex marmitex = new ClassMarmitex();
ClassConexao Conecta = new ClassConexao();
string CodMarmitex = "";
public void Consultar()
{
SqlDataAdapter da = new SqlDataAdapter("select * from
Marmitex", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
public void Limpar()
{
txtDesc.Text = "";
cmbDiaSemana.SelectedIndex = -1;
txtValor.Text = "";
txtDesc.Focus();
CodMarmitex = "";
}
private void btnCadastrar_Click(object sender, EventArgs e)
{
try
{
marmitex.Descricao = txtDesc.Text;
marmitex.DiaSemana = cmbDiaSemana.Text;
marmitex.Valor = double.Parse(txtValor.Text);
marmitex.CadMarmitex();
MessageBox.Show("Marmitex cadastrada com
sucesso","Sucesso",MessageBoxButtons.OK,MessageBoxIcon.Information);
Limpar();
Consultar();
}
catch
{
314
MessageBox.Show("Erro ao cadastrar. \n Verifique todos
os Campos e tente novamente", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
Conecta.CON().Close();
}
}
private void frmMarmitex_Load(object sender, EventArgs e)
{
if (Cargo == "Administrador")
{
gbDadosMarmitex.Enabled = true;
}
else
{
gbDadosMarmitex.Enabled = false;
}
Consultar();
}
private void dataGridView1_DoubleClick(object sender,
EventArgs e)
{
try
{
CodMarmitex =
dataGridView1.SelectedCells[0].Value.ToString();
txtDesc.Text =
dataGridView1.SelectedCells[1].Value.ToString();
cmbDiaSemana.Text =
dataGridView1.SelectedCells[2].Value.ToString();
txtValor.Text =
dataGridView1.SelectedCells[3].Value.ToString();
}
catch
{
}
}
private void btnConsultarTodas_Click(object sender, EventArgs
e)
{
Consultar();
}
private void btnNovo_Click(object sender, EventArgs e)
{
if (txtDesc.Text != "" || txtValor.Text != " / /" ||
cmbDiaSemana.Text != "" )
{
DialogResult dr = MessageBox.Show("Deseja limpar todos
os campos para um novo registro?", "Limpar Campos",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
315
{
Limpar();
}
}
else
{
Limpar();
}
}
private void btnAlterar_Click(object sender, EventArgs e)
{
try
{
marmitex.CodMarmitex = int.Parse(CodMarmitex);
marmitex.Descricao = txtDesc.Text;
marmitex.DiaSemana = cmbDiaSemana.Text;
marmitex.Valor = double.Parse(txtValor.Text);
marmitex.AlterMarmitex();
MessageBox.Show("Marmitex Alterada com sucesso",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
Consultar();
}
catch
{
MessageBox.Show("Erro na alterao. \n Verifique todos
os Campos e tente novamente", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void btnExcluir_Click(object sender, EventArgs e)
{
try
{
DialogResult dr = MessageBox.Show("Tem certeza de que
deseja excluir este registro?", "Excluir", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
marmitex.CodMarmitex = int.Parse(CodMarmitex);
marmitex.ExcluiMarmitex();
MessageBox.Show("Marmitex Excluda com sucesso",
"Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
Limpar();
Consultar();
}
}
catch
{
MessageBox.Show("Erro na alterao. \n Verifique todos
os Campos e tente novamente", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
316
private void btnConsultar_Click(object sender, EventArgs e)
{
}
private void txtConsulta_TextChanged(object sender, EventArgs
e)
{
try
{
if (rbConsultaDesc.Checked == false &&
rbConsultaDia.Checked == false)
{
MessageBox.Show("Selecione se deseja pesquisar
pela descrio ou pelo dia da semana", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else if (rbConsultaDesc.Checked)
{
SqlDataAdapter da = new SqlDataAdapter("select *
from Marmitex where Descricao like '" + txtConsulta.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else if (rbConsultaDia.Checked)
{
SqlDataAdapter da = new SqlDataAdapter("select *
from Marmitex where DiaSemana like '" + txtConsulta.Text + "%'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void txtValor_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
btnCadastrar_Click(sender, e);
break;
}
}
private void txtValor_KeyPress(object sender,
KeyPressEventArgs e)
{
317
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
}
}
frmMostraPedidos
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmMostraPedidos : Form
{
ClassPedido classePedido = new ClassPedido();//ok
ClassFuncionario classeFun = new ClassFuncionario();
ClassConexao Conecta = new ClassConexao();
318
public string CodfunParapedido
{
get { return codfunParapedido; }
set { codfunParapedido = value; }
}
public frmMostraPedidos()
{
InitializeComponent();
}
string CodPedidoMesa1;
string CodPedidoMesa2;
string CodPedidoMesa3;
string CodPedidoMesa4;
string CodPedidoMesa5;
string CodPedidoMesa6;
public SqlCommand AtualizaMesa1()
{
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = " + 1 + " and StatusPedido = 'EM ABERTO'",
Conecta.CON());
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorParcial)as Soma from ItemPedido where CodPedido = " +
CodPedidoMesa1, Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
CodPedidoMesa1 = dr["CodPedido"].ToString();
SqlDataReader dr2;
dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
lblTotalMesa1.Text = dr2["Soma"].ToString();
lblTotalMesa1.ForeColor = Color.Red;
}
return cmd2;
}
else
{
lblTotalMesa1.Text = "0,00";
lblTotalMesa1.ForeColor = Color.Black;
}
return cmd;
}
catch
{
}
finally
{
Conecta.CON().Close();
319
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaMesa2()
{
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = " + 2 + " and StatusPedido = 'EM ABERTO'",
Conecta.CON());
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorParcial)as Soma from ItemPedido where CodPedido = " +
CodPedidoMesa2, Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
CodPedidoMesa2 = dr["CodPedido"].ToString();
SqlDataReader dr2;
dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
lblTotalMesa2.Text = dr2["Soma"].ToString();
lblTotalMesa2.ForeColor = Color.Red;
}
return cmd2;
}
else
{
lblTotalMesa2.Text = "0,00";
lblTotalMesa2.ForeColor = Color.Black;
}
return cmd;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaMesa3()
{
320
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = " + 3 + " and StatusPedido = 'EM ABERTO'",
Conecta.CON());
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorParcial)as Soma from ItemPedido where CodPedido = " +
CodPedidoMesa3, Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
CodPedidoMesa3 = dr["CodPedido"].ToString();
SqlDataReader dr2;
dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
lblTotalMesa3.Text = dr2["Soma"].ToString();
lblTotalMesa3.ForeColor = Color.Red;
}
return cmd2;
}
else
{
lblTotalMesa3.Text = "0,00";
lblTotalMesa3.ForeColor = Color.Black;
}
return cmd;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaMesa4()
{
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = " + 4 + " and StatusPedido = 'EM ABERTO'",
Conecta.CON());
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorParcial)as Soma from ItemPedido where CodPedido = " +
CodPedidoMesa4, Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
321
CodPedidoMesa4 = dr["CodPedido"].ToString();
SqlDataReader dr2;
dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
lblTotalMesa4.Text = dr2["Soma"].ToString();
lblTotalMesa4.ForeColor = Color.Red;
}
return cmd2;
}
else
{
lblTotalMesa4.Text = "0,00";
lblTotalMesa4.ForeColor = Color.Black;
}
return cmd;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaMesa5()
{
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = " + 5 + " and StatusPedido = 'EM ABERTO'",
Conecta.CON());
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorParcial)as Soma from ItemPedido where CodPedido = " +
CodPedidoMesa5, Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
CodPedidoMesa5 = dr["CodPedido"].ToString();
SqlDataReader dr2;
dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
lblTotalMesa5.Text = dr2["Soma"].ToString();
lblTotalMesa5.ForeColor = Color.Red;
}
return cmd2;
322
}
else
{
lblTotalMesa5.Text = "0,00";
lblTotalMesa5.ForeColor = Color.Black;
}
return cmd;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand AtualizaMesa6()
{
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = " + 6 + " and StatusPedido = 'EM ABERTO'",
Conecta.CON());
SqlCommand cmd2 = new SqlCommand("Select
SUM(ValorParcial)as Soma from ItemPedido where CodPedido = " +
CodPedidoMesa6, Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
CodPedidoMesa6 = dr["CodPedido"].ToString();
SqlDataReader dr2;
dr2 = cmd2.ExecuteReader();
if (dr2.Read())
{
lblTotalMesa6.Text = dr2["Soma"].ToString();
lblTotalMesa6.ForeColor = Color.Red;
}
return cmd2;
}
else
{
lblTotalMesa6.Text = "0,00";
lblTotalMesa6.ForeColor = Color.Black;
}
return cmd;
}
catch
{
}
finally
323
{
Conecta.CON().Close();
}
return cmd;
}
public void AtualizaMesas()
{
frmPedidosAbertos pedAbert = new frmPedidosAbertos();
if (pnMesa1.Enabled == true || pnMesa1.Enabled == false)
{
pedAbert.Mesa = "1";
AtualizaMesa1();
AtivaMesas();
}
if (pnMesa2.Enabled == true || pnMesa2.Enabled == false)
{
pedAbert.Mesa = "2";
AtualizaMesa2();
AtivaMesas();
}
if (pnMesa3.Enabled == true || pnMesa3.Enabled == false)
{
pedAbert.Mesa = "3";
AtualizaMesa3();
AtivaMesas();
}
if (pnMesa4.Enabled == true || pnMesa4.Enabled == false)
{
pedAbert.Mesa = "4";
AtualizaMesa4();
AtivaMesas();
}
if (pnMesa5.Enabled == true || pnMesa5.Enabled == false)
{
pedAbert.Mesa = "5";
AtualizaMesa5();
AtivaMesas();
}
if (pnMesa6.Enabled == true || pnMesa6.Enabled == false)
{
pedAbert.Mesa = "6";
AtualizaMesa6();
AtivaMesas();
}
}
public void AtivaMesas()
{
if (lblTotalMesa1.Text != "0,00")
{
pnMesa1.Enabled = true;
}
else
{
pnMesa1.Enabled = false;
}
if (lblTotalMesa2.Text != "0,00")
{
324
pnMesa2.Enabled = true;
}
else
{
pnMesa2.Enabled = false;
}
if (lblTotalMesa3.Text != "0,00")
{
pnMesa3.Enabled = true;
}
else
{
pnMesa3.Enabled = false;
}
if (lblTotalMesa4.Text != "0,00")
{
pnMesa4.Enabled = true;
}
else
{
pnMesa4.Enabled = false;
}
if (lblTotalMesa5.Text != "0,00")
{
pnMesa5.Enabled = true;
}
else
{
pnMesa5.Enabled = false;
}
if (lblTotalMesa6.Text != "0,00")
{
pnMesa6.Enabled = true;
}
else
{
pnMesa6.Enabled = false;
}
}
public void AtualizaListaPedidosEntrega()
{
try
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Cliente.NomeCliente AS NomeCliente, Pedido.* FROM Pedido INNER JOIN
Cliente ON Pedido.CodCliente = Cliente.CodCliente where
Pedido.StatusPedido = 'EM ABERTO' and Pedido.TipoPedido = 'Entrega'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgEntrega.DataSource = ds.Tables[0];
}
catch { }
finally
{
Conecta.CON().Close();
325
}
}
public void AtualizaListaPedidosBalcao()
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Select * from
Pedido where TipoPedido = 'Balco' and StatusPedido = 'EM ABERTO'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgBalcao.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
326
}
private void btnDetalhesPedidoMesa4_Click(object sender,
EventArgs e)
{
frmPedidosAbertos pedidoAbert = new frmPedidosAbertos();
pedidoAbert.Mesa = "4";
pedidoAbert.TipoPedido = "Mesa";
pedidoAbert.NomeFuncionario = tsFunc.Text;
pedidoAbert.CodFuncionario = tsCodFun.Text;
pedidoAbert.Show();
}
private void btnDetalhesPedidoMesa5_Click(object sender,
EventArgs e)
{
frmPedidosAbertos pedidoAbert = new frmPedidosAbertos();
pedidoAbert.Mesa = "5";
pedidoAbert.TipoPedido = "Mesa";
pedidoAbert.NomeFuncionario = tsFunc.Text;
pedidoAbert.CodFuncionario = tsCodFun.Text;
pedidoAbert.Show();
}
private void btnDetalhesPedidoMesa6_Click(object sender,
EventArgs e)
{
frmPedidosAbertos pedidoAbert = new frmPedidosAbertos();
pedidoAbert.Mesa = "6";
pedidoAbert.TipoPedido = "Mesa";
pedidoAbert.NomeFuncionario = tsFunc.Text;
pedidoAbert.CodFuncionario = tsCodFun.Text;
pedidoAbert.Show();
}
private void btnDetalhesPedidoEntrega_Click(object sender,
EventArgs e)
{
try
{
if (lblCodEntrega.Text != "")
{
frmPedidosAbertos pedidoAbert = new
frmPedidosAbertos();
pedidoAbert.NomeFuncionario = tsFunc.Text;
pedidoAbert.CodPedido = "";
pedidoAbert.CodPedido = lblCodEntrega.Text;
pedidoAbert.TipoPedido = "Entrega";
pedidoAbert.CodFuncionario = tsCodFun.Text;
pedidoAbert.Show();
lblCodEntrega.Text = "";
}
else
{
MessageBox.Show("Selecione um Pedido",
"Selecione", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
327
catch
{
}
}
private void dgEntrega_CellClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
lblCodEntrega.Text =
dgEntrega.SelectedCells[1].Value.ToString();
}
catch
{
}
}
private void dgBalcao_CellClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
lblCodBalcao.Text =
dgBalcao.SelectedCells[0].Value.ToString();
}
catch
{
}
}
private void btnDetalhesPedidoBalcao_Click(object sender,
EventArgs e)
{
if (lblCodBalcao.Text != "")
{
frmPedidosAbertos pedidosAbert = new
frmPedidosAbertos();
pedidosAbert.NomeFuncionario = tsFunc.Text;
pedidosAbert.CodPedido = "";
pedidosAbert.CodPedido = lblCodBalcao.Text;
pedidosAbert.TipoPedido = "Balco";
pedidosAbert.CodFuncionario = tsCodFun.Text;
pedidosAbert.Show();
lblCodBalcao.Text = "";
}
else
{
MessageBox.Show("Selecione um Pedido", "Selecione",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void lblTotalMesa2_TextChanged(object sender,
EventArgs e)
{
if (lblTotalMesa2.Text == "")
{
328
lblTotalMesa2.Text = "Sem Itens";
}
}
private void lblTotalMesa1_TextChanged(object sender,
EventArgs e)
{
if (lblTotalMesa1.Text == "")
{
lblTotalMesa1.Text = "Sem Itens";
}
}
private void lblTotalMesa3_TextChanged(object sender,
EventArgs e)
{
if (lblTotalMesa3.Text == "")
{
lblTotalMesa3.Text = "Sem Itens";
}
}
private void lblTotalMesa4_TextChanged(object sender,
EventArgs e)
{
if (lblTotalMesa4.Text == "")
{
lblTotalMesa4.Text = "Sem Itens";
}
}
private void lblTotalMesa5_TextChanged(object sender,
EventArgs e)
{
if (lblTotalMesa5.Text == "")
{
lblTotalMesa5.Text = "Sem Itens";
}
}
private void lblTotalMesa6_TextChanged(object sender,
EventArgs e)
{
if (lblTotalMesa6.Text == "")
{
lblTotalMesa6.Text = "Sem Itens";
}
}
private void
gerenciarLoginsESenhasToolStripMenuItem_Click(object sender, EventArgs
e)
{
frmCadLogin cadLogin = new frmCadLogin();
cadLogin.ShowDialog();
}
329
}
}
frmPedidosAbertos
using System;
using System.Collections.Generic;
using System.ComponentModel;
330
using
using
using
using
using
using
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmPedidosAbertos : Form
{
ClassConexao Conecta = new ClassConexao();
public frmPedidosAbertos()
{
InitializeComponent();
}
private string mesa;
public string Mesa
{
get { return mesa; }
set { mesa = value; }
}
private string codPedido;
public string CodPedido
{
get { return codPedido; }
set { codPedido = value; }
}
private string nomeFuncionario;
public string NomeFuncionario
{
get { return nomeFuncionario; }
set { nomeFuncionario = value; }
}
private string tipoPedido;
public string TipoPedido
{
get { return tipoPedido; }
set { tipoPedido = value; }
}
private string codFuncionario;
public string CodFuncionario
{
get { return codFuncionario; }
set { codFuncionario = value; }
}
private string hora;
public string Hora
{
331
get { return hora; }
set { hora = value; }
}
string CodItemPedido;
double totalapagar;
double troco;
string ValidaExtra;
public SqlCommand SelecionaMesaparaLista()
{
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = '" + Mesa + "' and StatusPedido = 'EM ABERTO'",
Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
CodPedido = dr["CodPedido"].ToString();
}
return cmd;
}
catch
{
MessageBox.Show("Erro no metodo Seleciona Mesa para
Lista");
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public void PopulaListaPedidos()
{
CodPedido = lblCodPedido.Text;
try
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Pizza.NomePizza AS ItemPedido, ItemPedido.* FROM ItemPedido INNER JOIN
Pizza ON ItemPedido.CodPizza = Pizza.CodPizza where
ItemPedido.CodPedido = " + CodPedido + " UNION SELECT Esfiha.Descricao
As ItemPedido, ItemPedido.* FROM ItemPedido INNER JOIN Esfiha ON
ItemPedido.CodEsfiha = Esfiha.CodEsfiha where ItemPedido.CodPedido = "
+ CodPedido + " UNION SELECT Bebida.Descricao As ItemPedido,
ItemPedido.* FROM ItemPedido INNER JOIN Bebida ON ItemPedido.CodBebida
= Bebida.CodBebida where ItemPedido.CodPedido = " + CodPedido + "
UNION SELECT Marmitex.Descricao As ItemPedido, ItemPedido.* FROM
ItemPedido INNER JOIN Marmitex ON ItemPedido.CodMarmitex =
Marmitex.CodMarmitex where ItemPedido.CodPedido = " + CodPedido + "
332
UNION SELECT SelfService.TipoSelfService As ItemPedido, ItemPedido.*
FROM ItemPedido INNER JOIN SelfService ON ItemPedido.CodSelfService =
SelfService.CodSelfService where ItemPedido.CodPedido = " + CodPedido,
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgListaItemPedido.DataSource = ds.Tables[0];
}
catch
{
MessageBox.Show("Erro no metodo Popula Lista Pedidos
do Form Pedidos Abertos");
}
finally
{
Conecta.CON().Close();
}
}
public SqlCommand AtualizaValorParcialItem()
{
SqlCommand cmd = new SqlCommand("Update ItemPedido Set
ValorParcial = (ValorUnitario * Quantidade)", Conecta.CON());
try
{
cmd.ExecuteNonQuery();
return cmd;
}
catch
{
//MessageBox.Show("Erro no metodo
AtualizaVAlorParcialItem");
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
public SqlCommand BuscaValorTotal()
{
CodPedido = lblCodPedido.Text;
SqlCommand cmd = new SqlCommand("Select
SUM(ValorParcial)as Soma from ItemPedido where CodPedido = " +
CodPedido, Conecta.CON());
try
{
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
txtSubTotal.Text = dr["Soma"].ToString();
}
else
{
txtSubTotal.Text = "0,00";
}
333
}
catch
{
MessageBox.Show("Erro no metodo Busca Valor Total do
form Pedidos Abertos");
}
finally
{
Conecta.CON().Close();
}
return cmd;
}
334
DialogResult dr2 = MessageBox.Show("Fechar
Pedido?", "Encerrar Pedido", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (dr2 == DialogResult.Yes)
{
frmMostraPedidos principal = new
frmMostraPedidos();
ClassPedido classePedido = new
ClassPedido();
classePedido.CodPedido =
int.Parse(CodPedido);
classePedido.ValorTotal =
double.Parse(txtSubTotal.Text);
classePedido.FormaPagamento =
cmbFormaPagamento.Text;
classePedido.StatusPedido = "FECHADO";
classePedido.CodFuncionario =
int.Parse(lblCodFun.Text);
Hora = DateTime.Now.ToString("T");
string Data =
DateTime.Now.ToString("d");
classePedido.Hora =
Convert.ToDateTime(Hora);
classePedido.Data =
Convert.ToDateTime(Data);
classePedido.Obs = "Desconto de " +
txtDesconto.Text + " sobre o valor Total + Taxa de Servio/Entrega de
" + txtTaxaServio.Text + " + Produtos Diversos com Valor de " +
txtDiversos.Text ;
classePedido.FecharPedido();
MessageBox.Show("Pedido Fechado!",
"Pedido Terminado", MessageBoxButtons.OK, MessageBoxIcon.Information);
classePedido.CodPedido =
int.Parse(CodPedido);
classePedido.ValorTotal =
double.Parse(txtSubTotal.Text);
classePedido.AtualizaTotal();
this.Close();
}
}
}
else
{
MessageBox.Show("No existe nada cadastrado
neste pedido e por isso ser descartado", "Erro",
MessageBoxButtons.OK, MessageBoxIcon.Error);
DialogResult dre = MessageBox.Show("Deseja
adicionar algo ao pedido?", "Adicionar Item ao Pedido",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dre == DialogResult.Yes)
{
AdicionarAoPedido();
}
335
else
{
SqlCommand cmd2 = new SqlCommand("Delete
from Pedido where CodPedido = " + lblCodPedido.Text, Conecta.CON());
cmd2.ExecuteNonQuery();
Close();
}
}
}
else
{
if (cmbFormaPagamento.Text == "")
{
MessageBox.Show("Escolha a forma de
pagamento", "Informe os dados corretos", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
else
{
DialogResult dr = MessageBox.Show("Fechar
Pedido?", "Encerrar Pedido", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
frmMostraPedidos principal = new
frmMostraPedidos();
ClassPedido classePedido = new
ClassPedido();
classePedido.CodPedido =
int.Parse(CodPedido);
classePedido.ValorTotal =
double.Parse(txtSubTotal.Text);
classePedido.FormaPagamento =
cmbFormaPagamento.Text;
classePedido.StatusPedido = "FECHADO";
classePedido.CodFuncionario =
int.Parse(lblCodFun.Text);
Hora = DateTime.Now.ToString("T");
string Data = DateTime.Now.ToString("d");
classePedido.Hora =
Convert.ToDateTime(Hora);
classePedido.Data =
Convert.ToDateTime(Data);
classePedido.Obs = "Desconto de " +
txtDesconto.Text + " sobre o valor Total + Taxa de Servio/Entrega de
" + txtTaxaServio.Text + " + Produtos Diversos com Valor de " +
txtDiversos.Text;
classePedido.FecharPedido();
MessageBox.Show("Pedido Fechado!", "Pedido
Terminado", MessageBoxButtons.OK, MessageBoxIcon.Information);
336
classePedido.CodPedido =
int.Parse(CodPedido);
classePedido.ValorTotal =
double.Parse(txtSubTotal.Text);
classePedido.AtualizaTotal();
this.Close();
}
}
}
}
catch
{
MessageBox.Show("Erro no boto fechar pedido");
}
finally
{
Conecta.CON().Close();
}
}
public void AdicionarAoPedido()
{
try
{
if (Mesa == "1" || Mesa == "2" || Mesa == "3" || Mesa
== "4" || Mesa == "5" || Mesa == "6")
{
SqlCommand cmd = new SqlCommand("Select * from
Pedido where NumeroMesa = " + Mesa + " and StatusPedido = 'EM
ABERTO'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
frmCadPedido pedido = new frmCadPedido();
pedido.Codpedido = dr["CodPedido"].ToString();
pedido.TipoPedido = "Mesa";
pedido.NumeroMesa = lblNumMesa.Text;
pedido.Operador = NomeFuncionario;
CodPedido = lblCodPedido.Text;
//pedido.MdiParent = this; esse mtodo
necessrio para o principal
pedido.ShowDialog();
AtualizaPedidos();
AtualizaValorParcialItem();
}
}
if (TipoPedido == "Entrega")
{
SqlCommand cmd2 = new SqlCommand("Select * from
Pedido where CodPedido = " + CodPedido + "and StatusPedido = 'EM
ABERTO' and TipoPedido = 'Entrega'", Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
337
if (dr2.Read())
{
frmCadPedido pedido = new frmCadPedido();
pedido.CodCliente =
dr2["CodCliente"].ToString();
pedido.Codpedido = CodPedido;
pedido.TipoPedido = "Entrega";
pedido.Operador = NomeFuncionario;
//pedido.MdiParent=this;
pedido.ShowDialog();
AtualizaPedidos();
AtualizaValorParcialItem();
}
}
if (lblTipoPedido.Text == "Balco")
{
SqlCommand cmd = new SqlCommand("Select * from
Pedido where CodPedido = " + CodPedido + "and StatusPedido = 'EM
ABERTO' and TipoPedido = 'Balco'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
frmCadPedido pedido = new frmCadPedido();
pedido.Codpedido = lblCodPedido.Text;
pedido.TipoPedido = "Balco";
pedido.Operador = NomeFuncionario;
pedido.ShowDialog();
AtualizaPedidos();
AtualizaValorParcialItem();
}
}
}
catch
{
MessageBox.Show("Erro no mtodo Adiconar ao pedido");
}
finally
{
Conecta.CON().Close();
}
}
private void btnAdicionarAoPedido_Click(object sender,
EventArgs e)
{
AdicionarAoPedido();
}
private void frmPedidosAbertos_Load(object sender, EventArgs
e)
{
338
lblCodFun.Text = CodFuncionario;
try
{
lblCodPedido.Text = CodPedido;
lblTipoPedido.Text = TipoPedido;
lblNumMesa.Text = Mesa;
lblCodFun.Text = CodFuncionario;
if (lblTipoPedido.Text == "Mesa")
{
SelecionaMesaparaLista();
}
AtualizaPedidos();
AtualizaValorParcialItem();
}
catch
{
MessageBox.Show("Erro load de Pedidos Abertos");
}
}
private void dgListaItemPedido_CellClick(object sender,
DataGridViewCellEventArgs e)
{
try
{
CodItemPedido =
dgListaItemPedido.SelectedCells[1].Value.ToString();
}
catch
{
MessageBox.Show("Clicou fora da rea de seleo");
}
}
private void btnRemoverDoPedido_Click(object sender, EventArgs
e)
{
try
{
SqlCommand cmd = new SqlCommand("Delete from
ItemPedido where CodItemPedido = " + CodItemPedido, Conecta.CON());
if (CodItemPedido == "")
{
MessageBox.Show("Selecione o Item a ser
excludo!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
DialogResult dr = MessageBox.Show("Excluir este
item do Pedido?", "EXCLUIR", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
cmd.ExecuteNonQuery();
339
CodItemPedido = "";
AtualizaPedidos();
}
}
}
catch
{
MessageBox.Show("Selecione novamente o Item a ser
excludo!", "Erro ao tentar excluir", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
finally
{
Conecta.CON().Close();
}
}
private void txtValorReceb_Click(object sender, EventArgs e)
{
txtValorReceb.Text = "";
}
private void txtValorReceb_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void txtDesconto_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void txtTaxaServio_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void txtSubTotal_KeyPress(object sender,
KeyPressEventArgs e)
{
340
if (!char.IsDigit(e.KeyChar) )
{
e.Handled = true;
}
}
private void txtTotalPagar_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
private void txtTotalPagar_TextChanged(object sender,
EventArgs e)
{
if (txtTotalPagar.Text == "")
txtTotalPagar.Text = "0,00";
}
private void txtSubTotal_TextChanged(object sender, EventArgs
e)
{
if (txtSubTotal.Text == "")
txtSubTotal.Text = "0,00";
double LevaValorTotalParaRS =
double.Parse(txtSubTotal.Text);
txtTotalPagar.Text = LevaValorTotalParaRS.ToString("C");
}
private void txtValorReceb_Validated(object sender, EventArgs
e)
{
if (txtValorReceb.Text == "")
{
txtValorReceb.Text = "0,00";
}
else if (double.Parse(txtValorReceb.Text) >
double.Parse(txtSubTotal.Text))
{
troco = (double.Parse(txtValorReceb.Text) double.Parse(txtSubTotal.Text));
txtTroco.Text = troco.ToString("C");
}
else
{
txtValorReceb.Text = "0,00";
}
}
private void txtDesconto_Validated(object sender, EventArgs e)
{
if (txtDesconto.Text == "")
{
341
txtDesconto.Text = "0,00";
}
}
private void txtTaxaServio_Validating(object sender,
CancelEventArgs e)
{
if (txtTaxaServio.Text == "")
{
txtTaxaServio.Text = "0,00";
}
}
private void txtDesconto_Click(object sender, EventArgs e)
{
txtDesconto.Text = "";
}
private void txtTaxaServio_Click(object sender, EventArgs e)
{
txtTaxaServio.Text = "";
}
private void btnValidaExtra_Click(object sender, EventArgs e)
{
if (ValidaExtra == "Ja Validado")
{
btnValidaExtra.Enabled = false;
}
else
{
if (txtDesconto.Text == "")
{
txtValorReceb.Text = "0,00";
}
else
{
totalapagar = (double.Parse(txtSubTotal.Text) double.Parse(txtDesconto.Text));
txtSubTotal.Text = totalapagar.ToString();
}
if (txtValorReceb.Text == "")
{
txtValorReceb.Text = "0,00";
}
else
{
totalapagar = (double.Parse(txtSubTotal.Text) +
double.Parse(txtTaxaServio.Text));
txtSubTotal.Text = totalapagar.ToString();
}
if (txtDiversos.Text == "")
{
txtValorReceb.Text = "0,00";
}
else
342
{
totalapagar = (double.Parse(txtSubTotal.Text) +
double.Parse(txtDiversos.Text));
txtSubTotal.Text = totalapagar.ToString();
}
ValidaExtra = "Ja Validado";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (ValidaExtra == "Ja Validado")
{
btnValidaExtra.Enabled = false;
}
else
{
btnValidaExtra.Enabled = true;
}
Hora = DateTime.Now.ToString("T");
}
private void btnFinaliza_Click(object sender, EventArgs e)
{
btnAdicionarAoPedido.Enabled = false;
btnRemoverDoPedido.Enabled = false;
btnFinaliza.Enabled = false;
pnFinalizaPedido.Enabled = true;
}
private void btnContinuaPedido_Click(object sender, EventArgs
e)
{
btnAdicionarAoPedido.Enabled = true;
btnRemoverDoPedido.Enabled = true;
btnFinaliza.Enabled = true;
pnFinalizaPedido.Enabled = false;
}
private void frmPedidosAbertos_FormClosing(object sender,
FormClosingEventArgs e)
{
try
{
ClassPedido classePedido = new ClassPedido();
classePedido.CodPedido = int.Parse(CodPedido);
classePedido.ValorTotal =
double.Parse(txtSubTotal.Text);
classePedido.AtualizaTotal();
}
catch
343
{
MessageBox.Show("Erro no evento Closing de Pedidos
Abertos");
}
}
private void txtDiversos_Click(object sender, EventArgs e)
{
txtDiversos.Text = "";
}
private void txtDiversos_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
private void txtDiversos_Validating(object sender,
CancelEventArgs e)
{
if (txtDiversos.Text == "")
{
txtDiversos.Text = "0,00";
}
}
}
}
frmRelatCardapio
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatCardapio : Form
{
344
public frmRelatCardapio()
{
InitializeComponent();
}
private void frmRelatProdutosVendas_Load(object sender,
EventArgs e)
{
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select * from Pizza",
Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
SqlCommand cmd2 = new SqlCommand("Select * from
Esfiha", Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
SqlCommand cmd3 = new SqlCommand("Select * from
Bebida", Conecta.CON());
SqlDataReader dr3 = cmd3.ExecuteReader();
SqlCommand cmd4 = new SqlCommand("Select * from
Marmitex", Conecta.CON());
SqlDataReader dr4 = cmd4.ExecuteReader();
if (dr.Read() || dr2.Read() || dr3.Read() ||
dr4.Read())
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Pizza", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioPizzas relc = new RelatorioPizzas();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
SqlDataAdapter da2 = new SqlDataAdapter("Select *
from Esfiha", Conecta.CON());
DataSet ds2 = new DataSet();
da2.Fill(ds2);
RelatorioEsfihas relc2 = new RelatorioEsfihas();
relc2.SetDataSource(ds2.Tables[0]);
crystalReportViewer2.ReportSource = relc2;
SqlDataAdapter da3 = new SqlDataAdapter("Select *
from Bebida", Conecta.CON());
DataSet ds3 = new DataSet();
da3.Fill(ds3);
RelatorioBebida relc3 = new RelatorioBebida();
relc3.SetDataSource(ds3.Tables[0]);
crystalReportViewer3.ReportSource = relc3;
SqlDataAdapter da4 = new SqlDataAdapter("Select *
from Marmitex", Conecta.CON());
DataSet ds4 = new DataSet();
da4.Fill(ds4);
RelatorioMarmitex relc4 = new RelatorioMarmitex();
345
relc4.SetDataSource(ds4.Tables[0]);
crystalReportViewer4.ReportSource = relc4;
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio","Sem
registros",MessageBoxButtons.OK,MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmRelatCliente
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatClientes : Form
{
public frmRelatClientes()
{
InitializeComponent();
}
private void frmRelatClientes_Load(object sender, EventArgs e)
{
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select * from
Cliente", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Cliente", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioClientes relc = new RelatorioClientes();
relc.SetDataSource(ds.Tables[0]);
346
crystalReportViewer1.ReportSource = relc;
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio", "Sem registros", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmRelatContas
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatContas : Form
{
public frmRelatContas()
{
InitializeComponent();
}
private string mes;
public string Mes
{
get { return mes; }
set { mes = value; }
}
ClassConexao Conecta = new ClassConexao();
private void frmRelatContas_Load(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("Select * from
ContasApagar", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (Mes == null || Mes == "")
347
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from ContasApagar where CONVERT(nvarchar(2), DataQuitacao, 110) =
CONVERT(nvarchar(2), MONTH(GETDATE())) and StatusConta = 'Quitada'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioContas relc = new RelatorioContas();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
}
else
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from ContasApagar where CONVERT(nvarchar(2), DataQuitacao, 110) = '"
+ Mes + "' and StatusConta = 'Quitada'", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioContas relc = new RelatorioContas();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
}
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio", "Sem registros",MessageBoxButtons.OK,
MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmRelatEstoque
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatEstoque : Form
{
public frmRelatEstoque()
{
348
InitializeComponent();
}
private void frmRelatEstoque_Load(object sender, EventArgs e)
{
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select * from
Estoque", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Estoque", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioEstoque relc = new RelatorioEstoque();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio", "Sem registros", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmRelatFornecedores
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatFornecedores : Form
{
public frmRelatFornecedores()
349
{
InitializeComponent();
}
private void frmRelatFornecedores_Load(object sender,
EventArgs e)
{
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select * from
Fornecedor", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Fornecedor", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioFornecedores relc = new
RelatorioFornecedores();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio", "Sem registros", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmRelatFuncionarios
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatFuncionarios : Form
{
350
public frmRelatFuncionarios()
{
InitializeComponent();
}
private void frmRelatFuncionarios_Load(object sender,
EventArgs e)
{
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select * from
Funcionario", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
SqlDataAdapter da = new SqlDataAdapter("Select *
from Funcionario", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioFuncionarios relc = new
RelatorioFuncionarios();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio", "Sem registros", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmRelatSalarios
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatSalarios : Form
{
351
public frmRelatSalarios()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
private void frmRelatFechaCaixa_Load(object sender, EventArgs
e)
{
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select * from
Funcionario", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio", "Sem registros", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
}
}
frmRelatVendas
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmRelatVendas : Form
{
public frmRelatVendas()
{
InitializeComponent();
}
private string mes;
352
public string Mes
{
get { return mes; }
set { mes = value; }
}
private void frmRelatVendas_Load(object sender, EventArgs e)
{
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select * from
Pedido", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (Mes == null || Mes == "")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Pedido where CONVERT(nvarchar(2), Data, 110) =
CONVERT(nvarchar(2), MONTH(GETDATE())) and StatusPedido = 'FECHADO'",
Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioVendas relc = new RelatorioVendas();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
}
else
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Pedido where CONVERT(nvarchar(2), Data, 110) = '" + Mes + "'
and StatusPedido = 'FECHADO'", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
RelatorioVendas relc = new RelatorioVendas();
relc.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource = relc;
}
}
else
{
MessageBox.Show("No h nenhum registro para gerar
relatrio", "Sem registros", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
353
}
}
}
frmSelecionaNumeroComanda
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmSelecionaNumeroComanda : Form
{
public frmSelecionaNumeroComanda()
{
InitializeComponent();
}
private string codPedido;
public string CodPedido
{
get { return codPedido; }
set { codPedido = value; }
}
private string nomeFuncionario;
public string NomeFuncionario
{
get { return nomeFuncionario; }
set { nomeFuncionario = value; }
}
private string tipoPedido;
public string TipoPedido1
{
get { return tipoPedido; }
set { tipoPedido = value; }
}
public string TipoPedido
{
get { return tipoPedido; }
set { tipoPedido = value; }
}
private string data;
public string Data
{
get { return data; }
354
set { data = value; }
}
private string hora;
public string Hora
{
get { return hora; }
set { hora = value; }
}
private string codFuncionario;
public string CodFuncionario
{
get { return codFuncionario; }
set { codFuncionario = value; }
}
private void btnContinuar_Click(object sender, EventArgs e)
{
ClassPedido classePedido = new ClassPedido();
frmCadPedido pedidos = new frmCadPedido();
frmPedidosAbertos pedAberto = new frmPedidosAbertos();
ClassConexao Conecta = new ClassConexao();
try
{
SqlCommand cmd = new SqlCommand("Select MAX
(CodPedido) as Cod from Pedido", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
pedidos.Codpedido = dr["Cod"].ToString();
pedAberto.CodPedido = dr["Cod"].ToString();
string CodPedido = dr["Cod"].ToString();
classePedido.CodPedido = int.Parse(CodPedido);
classePedido.NumeroComanda =
int.Parse(txtNumeroComanda.Text);
classePedido.AlteraNumeroComanda();
}
pedAberto.NomeFuncionario = NomeFuncionario;
pedAberto.TipoPedido = "Balco";
pedAberto.Hora = Hora;
pedAberto.CodFuncionario = CodFuncionario;
pedAberto.Show();
pedAberto.AdicionarAoPedido();
Close();
}
catch
{
MessageBox.Show("Erro ao capturar o cod pedido boto
novo balcao");
}
finally
{
Conecta.CON().Close();
355
}
}
frmSelecionaRelatorios
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
namespace IniciandoDavilla
{
public partial class frmSelecionaRelatorios : Form
{
public frmSelecionaRelatorios()
{
InitializeComponent();
}
private void btnSalarios_Click(object sender, EventArgs e)
{
}
private void btnFornecedores_Click(object sender, EventArgs e)
{
this.Close();
}
356
private void btnClientes_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnFuncionrios_Click(object sender, EventArgs e)
{
this.Close();
}
357
this.Close();
}
private void btnRelatFun_Click(object sender, EventArgs e)
{
frmRelatFuncionarios fun = new frmRelatFuncionarios();
fun.Show();
}
private void btnRelatCli_Click(object sender, EventArgs e)
{
frmRelatClientes cli = new frmRelatClientes();
cli.Show();
}
private void btnRelatFornec_Click(object sender, EventArgs e)
{
frmRelatFornecedores fornec = new frmRelatFornecedores();
fornec.Show();
}
private void btnRelatCadapio_Click(object sender, EventArgs e)
{
frmRelatCardapio pv = new frmRelatCardapio();
pv.Show();
}
private void btnRelatSalario_Click(object sender, EventArgs e)
{
frmRelatSalarios sal = new frmRelatSalarios();
sal.Show();
}
private void btnRelatContas_Click(object sender, EventArgs e)
{
pnContas.Visible = true;
pnVendas.Visible = false;
}
private void btnRelatVendas_Click(object sender, EventArgs e)
{
pnVendas.Visible = true;
pnContas.Visible = false;
}
private void btnRelatEstoque_Click(object sender, EventArgs e)
{
frmRelatEstoque est = new frmRelatEstoque();
est.Show();
}
private void btnContasMesCont_Click_1(object sender, EventArgs
e)
{
frmRelatContas cont = new frmRelatContas();
cont.Mes = cmbContasMes.Text;
cont.Show();
}
private void btnVendasMesCont_Click_1(object sender, EventArgs
e)
358
{
frmRelatVendas ven = new frmRelatVendas();
ven.Mes = cmbMesVendas.Text;
ven.Show();
}
}
}
frmSelecionarMesa
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmSelecionarMesa : Form
{
public frmSelecionarMesa()
{
InitializeComponent();
}
string nomefun;
private string passaOperador;
public string PassaOperador
{
get { return passaOperador; }
set { passaOperador = value; }
}
private string passaTipoPedido;
public string PassaTipoPedido
{
get { return passaTipoPedido; }
set { passaTipoPedido = value; }
}
private string passaCodFun;
public string PassaCodFun
{
get { return passaCodFun; }
set { passaCodFun = value; }
}
private DateTime data;
public DateTime Data
{
359
get { return data; }
set { data = value; }
}
private DateTime hora;
public DateTime Hora
{
get { return hora; }
set { hora = value; }
}
ClassConexao Conecta = new ClassConexao();
frmCadPedido pedidos = new frmCadPedido();
ClassPedido classePedido = new ClassPedido();
frmMostraPedidos principal = new frmMostraPedidos();
frmPedidosAbertos pedAbertos = new frmPedidosAbertos();
private void btnContinuar_Click(object sender, EventArgs e)
{
try
{
pedidos.NumeroMesa = cmbNumMesa.Text; // Escolhe os
itens do pedido
pedAbertos.Mesa = cmbNumMesa.Text; // central do
pedido
pedidos.Operador = PassaOperador;
// Escolhe os itens
do pedido
pedAbertos.NomeFuncionario = PassaOperador; // central
do pedido
pedidos.TipoPedido = PassaTipoPedido; // Escolhe os
itens do pedido
pedAbertos.TipoPedido = PassaTipoPedido;
// central
do pedido
pedAbertos.CodFuncionario = PassaCodFun;
pedAbertos.Hora = Convert.ToString(Hora);
SqlCommand cmd = new SqlCommand("Select * from Pedido
where NumeroMesa = " + cmbNumMesa.Text + " and StatusPedido = 'EM
ABERTO'", Conecta.CON());
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("J Existe um pedido aberto para
esta mesa!", "Mesa Ocupada", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}
else
{
360
SqlCommand sql = new SqlCommand("select * from
Funcionario where NomeFuncionario = '" + PassaOperador + "'",
Conecta.CON());
SqlDataReader dr2;
dr2 = sql.ExecuteReader();
if (dr2.Read())
{
nomefun = dr2["CodFuncionario"].ToString();
}
this.Close();
}
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void frmSelecionarMesa_Load(object sender, EventArgs
e)
{
}
}
}
361
frmTodosPedidos
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmTodosPedidos : Form
{
public frmTodosPedidos()
{
InitializeComponent();
}
string CodPedido;
private string cargoFun;
public string CargoFun
{
get { return cargoFun; }
set { cargoFun = value; }
}
ClassConexao Conecta = new ClassConexao();
ClassPedido classePedido = new ClassPedido();
public void PopulaLista()
{
try
{
SqlDataAdapter da = new SqlDataAdapter("SELECT
Funcionario.NomeFuncionario As NomeFunc, Pedido.* FROM Pedido INNER
JOIN Funcionario ON Pedido.CodFuncionario = Funcionario.CodFuncionario
order by Pedido.CodPedido Desc", Conecta.CON());
DataSet ds = new DataSet();
da.Fill(ds);
dgHistorico.DataSource = ds.Tables[0];
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
public void Limpar()
{
362
txtCodCli.Clear();
txtCodFun.Clear();
txtCodPedido.Clear();
txtData.Clear();
txtFormaPgto.Clear();
txtHora.Clear();
txtNumMesa.Clear();
txtObs.Clear();
txtStatusPedido.Clear();
txtTipoPedido.Clear();
txtValorTotal.Clear();
txtNumeroComanda.Clear();
txtEntregador.Clear();
}
363
txtTipoPedido.Text =
dgHistorico.SelectedCells[5].Value.ToString();
txtNumMesa.Text =
dgHistorico.SelectedCells[6].Value.ToString();
txtNumeroComanda.Text =
dgHistorico.SelectedCells[7].Value.ToString();
txtData.Text =
dgHistorico.SelectedCells[8].Value.ToString();
txtHora.Text =
dgHistorico.SelectedCells[9].Value.ToString();
txtValorTotal.Text =
dgHistorico.SelectedCells[10].Value.ToString();
txtFormaPgto.Text =
dgHistorico.SelectedCells[11].Value.ToString();
txtStatusPedido.Text =
dgHistorico.SelectedCells[12].Value.ToString();
txtObs.Text =
dgHistorico.SelectedCells[13].Value.ToString();
}
catch
{
}
finally
{
Conecta.CON().Close();
}
}
private void btnAlterarPedido_Click(object sender, EventArgs
e)
{
try
{
if (txtNumeroComanda.Text != "")
{
classePedido.CodPedido =
int.Parse(txtCodPedido.Text);
classePedido.NumeroComanda =
int.Parse(txtNumeroComanda.Text);
classePedido.AlteraNumeroComanda();
}
else if (txtNumeroComanda.Text == "")
{
classePedido.CodPedido =
int.Parse(txtCodPedido.Text);
classePedido.DeletaNumeroComanda();
}
if (txtCodCli.Text != "")
{
classePedido.CodPedido =
int.Parse(txtCodPedido.Text);
classePedido.CodCliente =
int.Parse(txtCodCli.Text);
classePedido.AtualizaCodCliente();
txtCodCli.Clear();
}
364
else if (txtCodCli.Text == "")
{
classePedido.CodPedido =
int.Parse(txtCodPedido.Text);
classePedido.DeletaCodCliente();
}
if (txtEntregador.Text != "")
{
classePedido.CodPedido =
int.Parse(txtCodPedido.Text);
classePedido.Entregador = txtEntregador.Text;
classePedido.AlteraEntragador();
}
else
{
}
classePedido.CodPedido = int.Parse(txtCodPedido.Text);
classePedido.CodFuncionario =
int.Parse(txtCodFun.Text);
classePedido.TipoPedido = txtTipoPedido.Text;
classePedido.NumeroMesa = int.Parse(txtNumMesa.Text);
classePedido.Data = Convert.ToDateTime(txtData.Text);
classePedido.Hora = Convert.ToDateTime(txtHora.Text);
classePedido.ValorTotal =
double.Parse(txtValorTotal.Text);
classePedido.FormaPagamento = txtFormaPgto.Text;
classePedido.StatusPedido = txtStatusPedido.Text;
classePedido.Obs = txtObs.Text;
classePedido.AlteraPedido();
365
try
{
DialogResult dr = MessageBox.Show("REALMENTE DESEJA
EXCLUIR TODOS OS PEDIDOS?", "Excluir?", MessageBoxButtons.YesNo,
MessageBoxIcon.Stop);
if (dr == DialogResult.Yes)
{
classePedido.DeletaTodosPedidos();
MessageBox.Show("Todos os pedidos foram excludos
do sistema com xito!", "SUCESSO", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Limpar();
PopulaLista();
}
}
catch { }
finally
{
Conecta.CON().Close();
}
}
private void btnOpcoesAvancadas_Click(object sender, EventArgs
e)
{
gbDetalhes.Visible = true;
}
private void frmTodosPedidos_Load(object sender, EventArgs e)
{
PopulaLista();
if (CargoFun == "Administrador")
{
btnOpcoesAvancadas.Enabled = true;
}
}
private void btnConsultar_Click(object sender, EventArgs e)
{
try
{
if (cmbConsultarPor.Text == "" || txtBusca.Text == ""
|| txtBusca.Text == " / /")
{
MessageBox.Show("Selecione o tipo de consulta e
digite sua busca", "Erro", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
if (cmbConsultarPor.Text == "Cdigo do Pedido")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Pedido where CodPedido = " + txtBusca.Text, Conecta.CON());
366
367
da3.Fill(ds);
}
else
{
da.Fill(ds);
}
dgHistorico.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "Cdigo do
Cliente")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Pedido where CodCliente = " + txtBusca.Text, Conecta.CON());
SqlDataAdapter da2 = new
SqlDataAdapter("Select * from Pedido where CodCliente = " +
txtBusca.Text + " and StatusPedido = 'EM ABERTO'", Conecta.CON());
SqlDataAdapter da3 = new
SqlDataAdapter("Select * from Pedido where CodCliente = " +
txtBusca.Text + " and StatusPedido = 'FECHADO'", Conecta.CON());
DataSet ds = new DataSet();
if (rbSomenteEmAberto.Checked == true)
{
da2.Fill(ds);
}
else if (rbSomenteFechados.Checked == true)
{
da3.Fill(ds);
}
else
{
da.Fill(ds);
}
dgHistorico.DataSource = ds.Tables[0];
}
else if (cmbConsultarPor.Text == "Valor Total")
{
SqlDataAdapter da = new SqlDataAdapter("Select
* from Pedido where ValorTotal = " + txtBusca.Text, Conecta.CON());
SqlDataAdapter da2 = new
SqlDataAdapter("Select * from Pedido where ValorTotal = " +
txtBusca.Text + " and StatusPedido = 'EM ABERTO'", Conecta.CON());
SqlDataAdapter da3 = new
SqlDataAdapter("Select * from Pedido where ValorTotal = " +
txtBusca.Text + " and StatusPedido = 'FECHADO'", Conecta.CON());
DataSet ds = new DataSet();
if (rbSomenteEmAberto.Checked == true)
{
da2.Fill(ds);
}
else if (rbSomenteFechados.Checked == true)
{
da3.Fill(ds);
}
else
{
da.Fill(ds);
}
368
dgHistorico.DataSource = ds.Tables[0];
}
}
}
catch
{
MessageBox.Show("Erro botao consulta");
}
finally
{
Conecta.CON().Close();
}
}
private void cmbConsultarPor_SelectedIndexChanged(object
sender, EventArgs e)
{
if (cmbConsultarPor.Text == "Data")
{
txtBusca.Mask = "00/00/0000";
}
}
private void txtCodPedido_TextChanged(object sender, EventArgs
e)
{
if (txtCodPedido.Text == "")
{
btnAlterarPedido.Enabled
btnExcluirPedido.Enabled
}
else
{
btnAlterarPedido.Enabled
btnExcluirPedido.Enabled
}
= false;
= false;
= true;
= true;
}
private void btnConsultarTodos_Click(object sender, EventArgs
e)
{
PopulaLista();
}
private void gbDetalhes_Enter(object sender, EventArgs e)
{
}
private void btnFechaCaixa_Click(object sender, EventArgs e)
{
frmFechamentoCaixa fecha = new frmFechamentoCaixa();
fecha.Show();
}
private void txtCodPedido_KeyPress(object sender,
KeyPressEventArgs e)
{
369
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 )
{
e.Handled = true;
}
}
private void txtValorTotal_KeyPress(object sender,
KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 &&
e.KeyChar != ',')
{
e.Handled = true;
}
}
}
}
frmVerificaListaNegra
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmVerificaListaNegra : Form
{
public frmVerificaListaNegra()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
private void frmVerificaListaNegra_KeyUp(object sender,
KeyEventArgs e)
{
}
private void txtLista_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
try
{
370
SqlCommand cmd = new SqlCommand("Select * from
Cliente where ListaNegra = 'Sim' and Telefone like '" + txtLista.Text
+ "%' or Celular like '" + txtLista.Text + "%'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
SqlCommand cmd2 = new SqlCommand("Select *
from Cliente where ListaNegra = 'No' and Telefone like '" +
txtLista.Text + "%' or Celular like '" + txtLista.Text + "%'",
Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr.Read())
{
lblLista.Text = "Nmero ENCONTRADO na
Lista Negra!";
lblLista.ForeColor = Color.Red;
}
else if (dr2.Read())
{
lblLista.Text = "Nmero NO PERTENCE
Lista Negra\nCliente Efetivo!";
lblLista.ForeColor = Color.Blue;
}
else
{
DialogResult dre = MessageBox.Show("Parece
ser um novo Cliente!\nDeseja realizar um novo cadastro?", "Novo
Cliente", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dre == DialogResult.Yes)
{
frmCadCliente cli = new
frmCadCliente();
cli.WindowState =
FormWindowState.Normal;
cli.StartPosition =
FormStartPosition.CenterScreen;
cli.Lista = "Novo";
cli.TelListaNegra = txtLista.Text;
cli.Show();
}
}
btnVerificaCliente.Enabled = true;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
break;
}
}
private void btnVerificaCliente_Click(object sender, EventArgs
e)
371
{
frmCadCliente cli = new frmCadCliente();
cli.Lista = "Sim";
cli.TelListaNegra = txtLista.Text;
cli.Width = 1168;
cli.Height = 567;
cli.Show();
}
private void txtLista_TextChanged(object sender, EventArgs e)
{
if (txtLista.Text == "( )
-")
{
lblLista.Visible = false;
}
else
{
lblLista.Visible = true;
lblLista.Text = "";
btnVerificaCliente.Enabled = false;
}
}
}
}
MDIPrincipal
using
using
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
System.Data.SqlClient;
namespace IniciandoDavilla
{
public partial class frmVerificaListaNegra : Form
{
public frmVerificaListaNegra()
{
InitializeComponent();
}
ClassConexao Conecta = new ClassConexao();
private void frmVerificaListaNegra_KeyUp(object sender,
KeyEventArgs e)
{
}
private void txtLista_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
try
372
{
SqlCommand cmd = new SqlCommand("Select * from
Cliente where ListaNegra = 'Sim' and Telefone like '" + txtLista.Text
+ "%' or Celular like '" + txtLista.Text + "%'", Conecta.CON());
SqlDataReader dr = cmd.ExecuteReader();
SqlCommand cmd2 = new SqlCommand("Select *
from Cliente where ListaNegra = 'No' and Telefone like '" +
txtLista.Text + "%' or Celular like '" + txtLista.Text + "%'",
Conecta.CON());
SqlDataReader dr2 = cmd2.ExecuteReader();
if (dr.Read())
{
lblLista.Text = "Nmero ENCONTRADO na
Lista Negra!";
lblLista.ForeColor = Color.Red;
}
else if (dr2.Read())
{
lblLista.Text = "Nmero NO PERTENCE
Lista Negra\nCliente Efetivo!";
lblLista.ForeColor = Color.Blue;
}
else
{
DialogResult dre = MessageBox.Show("Parece
ser um novo Cliente!\nDeseja realizar um novo cadastro?", "Novo
Cliente", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dre == DialogResult.Yes)
{
frmCadCliente cli = new
frmCadCliente();
cli.WindowState =
FormWindowState.Normal;
cli.StartPosition =
FormStartPosition.CenterScreen;
cli.Lista = "Novo";
cli.TelListaNegra = txtLista.Text;
cli.Show();
}
}
btnVerificaCliente.Enabled = true;
}
catch
{
}
finally
{
Conecta.CON().Close();
}
break;
}
}
373
private void btnVerificaCliente_Click(object sender, EventArgs
e)
{
frmCadCliente cli = new frmCadCliente();
cli.Lista = "Sim";
cli.TelListaNegra = txtLista.Text;
cli.Width = 1168;
cli.Height = 567;
cli.Show();
}
private void txtLista_TextChanged(object sender, EventArgs e)
{
if (txtLista.Text == "( )
-")
{
lblLista.Visible = false;
}
else
{
lblLista.Visible = true;
lblLista.Text = "";
btnVerificaCliente.Enabled = false;
}
}
}
}