Aqui apresento um pequeno aplicativo, voltado para a
área comercial, com o intuito de automatizar trabalhos manuais desnecessários.Será composto pelas seguintes funcionalidades.
- Um menu principal com opção para chamar o cadastro de marcas e o de produtos;
- Um formulário para fazer a inserção, manutenção e consulta de dados de marcas;
- Um formulário para fazer a inserção, manutenção e consulta de dados de produtos;
Para que nossa aplicação seja possível de ser desenvolvida, deve-se fazer o uso de um banco de dados, (sugiro o uso do Firebird como padrão, mas qualquer SGBD pode ser utilizado). Será feito na linguagem C#.
DESENVOLVIMENTO
using System;
using System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
FirebirdSql.Data.FirebirdClient;
namespace
TRABALHO_UNOPAR
{
public partial class CADASTROPRODUTOS : Form
{
public const string StrConn =
"user=SYSDBA;Password=masterkey;Database=c:\\TRABALHOUNOPAR.FDB;Datasource=localhost";
public
CADASTROPRODUTOS()
{
InitializeComponent();
}
private void
textBox1_TextChanged(object sender, EventArgs e)
{
}
private void
label1_Click(object sender, EventArgs e)
{
}
private void
CADASTROPRODUTOS_Load(object sender, EventArgs e)
{
lblDESCRICAOMARCA.Text = "";
}
private void
btnSAIR_Click(object sender, EventArgs e)
{
this.Close();
}
private void
btnINCLUIR_Click(object sender, EventArgs e)
{
FbConnection conexao
= new FbConnection(StrConn);
FbCommand
comando = new FbCommand();
string
instrucaoSQL = "insert
into TBL_PRODUTOS VALUES (@CODIGO,@DESCRICAO,@MARCA,@QTDE,@VALOR)";
comando.Connection = conexao;
comando.CommandType
= CommandType.Text;
comando.CommandText = instrucaoSQL;
comando.Parameters.Add("@CODIGO", edtCODIGO.Text);
comando.Parameters.Add("@DESCRICAO", edtDESCRICAO.Text);
comando.Parameters.Add("@MARCA", edtMARCA.Text);
comando.Parameters.Add("@QTDE", edtQTDE.Text);
comando.Parameters.Add("@VALOR", edtPRECO.Text);
try
{
conexao.Open();
comando.ExecuteNonQuery();
conexao.Close();
}
catch (Exception
excecao)
{
MessageBox.Show("Uma exceção foi gerada, apresentando a seguinte
mensagem:" + Environment.NewLine
+ excecao.Message);
}
finally
{
comando.Dispose();
conexao.Dispose();
}
}
private void
btnCONSULTAR_Click(object sender, EventArgs e)
{
FbConnection
conexao = new FbConnection(StrConn);
FbCommand comando =
new FbCommand("Select
p.id_PRODUTO, p.ds_PRODUTO,p.id_MARCA, m.ds_MARCA, p.qt_ESTOQUE,p.vl_VENDAS
FROM TBL_PRODUTOS p INNER JOIN TBL_MARCAS m ON m.id_MARCA = p.id_MARCA",conexao);
FbDataAdapter
adaptador = new FbDataAdapter(comando);
DataSet ds = new DataSet();
try
{
conexao.Open();
adaptador.Fill(ds, "Produtos");
conexao.Close();
grdPRODUTOS.DataSource = ds;
grdPRODUTOS.DataMember = "Produtos";
}
catch (Exception
excecao)
{
MessageBox.Show(excecao.Message);
}
finally
{
comando.Dispose();
conexao.Dispose();
}
}
private void
btnALTERAR_Click(object sender, EventArgs e)
{
FbConnection
conexao = new FbConnection(StrConn);
FbCommand
comando = new FbCommand();
string instrucaoSQL = "UPDATE
TBL_PRODUTOS SET DS_PRODUTO = @DESCRICAO,ID_MARCA = @MARCA,QT_ESTOQUE =
@QTDE,VL_VENDAS = @VALOR WHERE ID_PRODUTO = @CODIGO";
comando.Connection = conexao;
comando.CommandType = CommandType.Text;
comando.CommandText = instrucaoSQL;
comando.Parameters.Add("@CODIGO", edtCODIGO.Text);
comando.Parameters.Add("@DESCRICAO", edtDESCRICAO.Text);
comando.Parameters.Add("@MARCA", edtMARCA.Text);
comando.Parameters.Add("@QTDE",
edtQTDE.Text);
comando.Parameters.Add("@VALOR", edtPRECO.Text);
try
{
conexao.Open();
comando.ExecuteNonQuery();
conexao.Close();
}
catch (Exception
excecao)
{
MessageBox.Show("Uma exceção foi gerada, apresentando a seguinte
mensagem:" + Environment.NewLine
+ excecao.Message);
}
finally
{
comando.Dispose();
conexao.Dispose();
}
}
private void
btnEXCLUIR_Click(object sender, EventArgs e)
{
FbConnection
conexao = new FbConnection(StrConn);
FbCommand
comando = new FbCommand();
string
instrucaoSQL = "DELETE
FROM TBL_PRODUTOS WHERE ID_PRODUTO =
@CODIGO";
comando.Connection = conexao;
comando.CommandType = CommandType.Text;
comando.CommandText = instrucaoSQL;
comando.Parameters.Add("@CODIGO",
edtCODIGO.Text);
try
{
conexao.Open();
comando.ExecuteNonQuery();
conexao.Close();
}
catch (Exception
excecao)
{
MessageBox.Show("Uma exceção foi gerada, apresentando a seguinte
mensagem:" + Environment.NewLine
+ excecao.Message);
}
finally
{
comando.Dispose();
conexao.Dispose();
}
}
private void
edtCODIGO_TextChanged(object sender, EventArgs e)
{
}
}
}
.
