You are on page 1of 15

Cadastro de Alimentos

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrabalhoILP20
{

public partial class Cadastro_de_Alimentos : Form


{
private SqlConnection conexao;
private SqlCommand comando;
private string strsql, strconex;
public Cadastro_de_Alimentos()
{
InitializeComponent();
}

private void Btcancelar_Click(object sender, EventArgs e)


{
Application.Exit ();
}

private void Btgravar_Click(object sender, EventArgs e)


{
try
{
strconex = "data source=(local);initial
catalog=zoologico;integrated security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();

strsql = "insert into alimentos (alimento,descricao) values ('" +


txtalimento.Text + "','" + txtdescricao.Text + "')";
comando = new SqlCommand(strsql, conexao);
comando.ExecuteNonQuery();
MessageBox.Show("Resgistro gravado com Sucesso.", "Informação",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("Verifique os dados digitados", "Aviso",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

}
}
}

Alterar Alimentos

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrabalhoILP20
{
public partial class Alterar_Alimentos : Form
{
private SqlConnection conexao;
private SqlCommand comando;
private SqlDataAdapter adapter;
private DataTable tblalimentos;
private string strsql, strconex;
public Alterar_Alimentos()
{
InitializeComponent();
}

private void Btgravar_Click(object sender, EventArgs e)


{
try {
strconex = "data source=(local);initial
catalog=zoologico;integrated security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();

strsql = "insert into alimentos (alimento,descricao) values ('" +


txtalimento.Text + "','" + txtdescricao.Text + "')";
comando = new SqlCommand(strsql, conexao);
comando.ExecuteNonQuery();
MessageBox.Show("Resgistro gravado com Sucesso.", "Informação",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("Verifique os dados digitados", "Aviso",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

private void Btcancelar_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void Btpesquisar_Click(object sender, EventArgs e)


{
strconex = "data source=(local);initial catalog=zoologico;integrated
security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();

tblalimentos = new DataTable();

strsql = "select*from alimentos where codalimento='" +


txtcodalimento.Text + "'";

adapter = new SqlDataAdapter(strsql, conexao);

adapter.Fill(tblalimentos);
if (tblalimentos.Rows.Count == 1)
{
grupo1.Enabled = false;
grupo2.Visible = true;
txtalimento.Text = tblalimentos.Rows[0]["alimento"].ToString();
txtdescricao.Text = tblalimentos.Rows[0]["descricao"].ToString();

else
{
MessageBox.Show("Registro não encontrado!", "mensagem",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}
}
}
}

Consultar Animais por país de origem

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TrabalhoILP20
{
public partial class Consultar_Animais_Pais : Form
{

private SqlConnection conexao;


private SqlDataAdapter adapter;
private DataTable tblanimais;
private string strsql, strconex;
private string registro;

private void Cbopais_SelectedIndexChanged(object sender, EventArgs e)


{
registro = cbopais.SelectedValue.ToString();
Preencher();
}

private void Consultar_Animais_Pais_Load(object sender, EventArgs e)


{
strconex = "data source=(local); initial catalog=Zoologico;
integrated security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();
tblanimais = new DataTable();
strsql = "select distinct paisOrigem from animais";
adapter = new SqlDataAdapter(strsql, conexao);
adapter.Fill(tblanimais);
cbopais.DataSource = tblanimais;
cbopais.DisplayMember = "paisOrigem";
cbopais.ValueMember = "paisOrigem";
registro = cbopais.SelectedValue.ToString();
}

public Consultar_Animais_Pais()
{
InitializeComponent();
}

private void Grade_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{

private void Label1_Click(object sender, EventArgs e)


{

private void Preencher()


{
tblanimais = new DataTable();
strsql = "select * from animais where paisOrigem = '" + cbopais.Text
+ "'";
adapter = new SqlDataAdapter(strsql, conexao);
adapter.Fill(tblanimais);
grade.DataSource = tblanimais;
}

Menu

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrabalhoILP20
{
public partial class Menu : Form
{
public int Nivel;
public string Nome;

public Menu()
{
InitializeComponent();
}

private void Menu_Load(object sender, EventArgs e)


{

}
private void CadastroToolStripMenuItem_Click(object sender, EventArgs e)
{
Cadastro_Animais cadanimais = new Cadastro_Animais();
cadanimais.Show();
}

private void CadastroDeAlimentosToolStripMenuItem_Click(object sender,


EventArgs e)
{
Cadastro_de_Alimentos cadalimentos = new Cadastro_de_Alimentos();
cadalimentos.Show();
}

private void AlterarAnimaisToolStripMenuItem_Click(object sender,


EventArgs e)
{
Alterar_Animais altanimais = new Alterar_Animais();
altanimais.Show();
}

private void AlterarAlimentosToolStripMenuItem_Click(object sender,


EventArgs e)
{
Alterar_Alimentos altalimentos = new Alterar_Alimentos();
altalimentos.Show();
}

private void AnimaisToolStripMenuItem_Click(object sender, EventArgs e)


{
Excluir_Animais exclanimais = new Excluir_Animais();
exclanimais.Show();
}

private void AnimaisPaísDeOrigemToolStripMenuItem_Click(object sender,


EventArgs e)
{
Consultar_Animais_Pais consanimais = new Consultar_Animais_Pais();
consanimais.Show();
}

private void AlimentosToolStripMenuItem_Click(object sender, EventArgs e)


{
Consulta_Alimentos consalimentos = new Consulta_Alimentos();
consalimentos.Show();
}
}
}
Alterar Animais

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrabalhoILP20
{
public partial class Alterar_Animais : Form
{
private SqlConnection conexao;
private SqlCommand comando;
private SqlDataAdapter adapter;
private DataTable tblanimais;
private string strsql, strconex;

public Alterar_Animais()
{
InitializeComponent();
}

private void Btgravar_Click(object sender, EventArgs e)


{
try
{
strconex = "data source=(local);initial
catalog=zoologico;integrated security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();
strsql = "insert into animais
(Animal,paisOrigem,Localizacao,codalimento) values ('" + txtanimal.Text + "','" +
txtpaisorigem.Text + "','" + txtlocalizacao.Text + "','" + txtcodalimento.Text +
"')";
comando = new SqlCommand(strsql, conexao);
comando.ExecuteNonQuery();
MessageBox.Show("Resgistro gravado com Sucesso.", "Informação",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("Verifique os dados digitados", "Aviso",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

private void Btcancelar_Click(object sender, EventArgs e)


{
groupBox1.Enabled = true;
groupBox2.Visible = false;
}

private void Btpesquisar_Click(object sender, EventArgs e)


{
strconex = "data source=(local);initial catalog=zoologico;integrated
security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();

tblanimais = new DataTable();

strsql = "select*from animais where codanimal='" +txtcodanimal.Text +


"'";

adapter = new SqlDataAdapter(strsql, conexao);

adapter.Fill(tblanimais);

if (tblanimais.Rows.Count == 1)
{
groupBox1.Enabled = false;
groupBox2.Visible = true;
txtanimal.Text = tblanimais.Rows[0]["animal"].ToString();
txtpaisorigem.Text = tblanimais.Rows[0]["paisorigem"].ToString();
txtlocalizacao.Text = tblanimais.Rows[0]
["localizacao"].ToString();
txtcodalimento.Text = tblanimais.Rows[0]
["codalimento"].ToString();

else
{
MessageBox.Show("Registro não encontrado!", "mensagem",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}
}
}
}
Cadastro Animais

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrabalhoILP20
{
public partial class Cadastro_Animais : Form
{
private SqlConnection conexao;
private SqlCommand comando;
private string strsql, strconex;

public Cadastro_Animais()
{
InitializeComponent();
}

private void Btcancelar_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void Btgravar_Click(object sender, EventArgs e)


{
try
{
strconex = "data source=(local);initial
catalog=zoologico;integrated security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();

strsql = "insert into animais


(Animal,paisOrigem,Localizacao,codalimento) values ('" + txtanimal.Text + "','" +
txtpaisorigem.Text + "','" + txtlocalizacao.Text + "','" + txtcodalimento.Text +
"')";
comando = new SqlCommand(strsql, conexao);
comando.ExecuteNonQuery();
MessageBox.Show("Resgistro gravado com Sucesso.", "Informação",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("Verifique os dados digitados", "Aviso",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}

Consulta de Alimentos

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrabalhoILP20
{
public partial class Consulta_Alimentos : Form
{
private SqlConnection conexao;
private SqlDataAdapter adapter;
private DataTable tblalimentos, tblanimais;
private string strsql, strconex;
private int registro = 0;

public Consulta_Alimentos()
{
InitializeComponent();
}

private void Btpri_Click(object sender, EventArgs e)


{
registro = 0;
Preencher();
}

private void Btant_Click(object sender, EventArgs e)


{
if (registro > 0)
{
registro = registro - 1;
Preencher();
}
else
{
MessageBox.Show("Primeiro registro!", "mensagem",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

private void Btprox_Click(object sender, EventArgs e)


{
if (registro < tblalimentos.Rows.Count - 1)
{
registro = registro + 1;
Preencher();
}
else
{
MessageBox.Show("Último registro!", "mensagem",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}

private void Btult_Click(object sender, EventArgs e)


{
registro = tblalimentos.Rows.Count - 1;
Preencher();
}

private void Consulta_Alimentos_Load(object sender, EventArgs e)


{
strconex = "data source = (local);initial
catalog=zoologico;integrated security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();

tblalimentos = new DataTable();


strsql = "select * from alimentos";
adapter = new SqlDataAdapter(strsql, conexao);
adapter.Fill(tblalimentos);
Preencher();
}
private void Preencher()
{
if (tblalimentos.Rows.Count != 0)
{
txtcodalimento.Text = tblalimentos.Rows[registro]
["codalimento"].ToString();
txtdescricao.Text = tblalimentos.Rows[registro]
["descricao"].ToString();
lblreg.Text = (registro + 1).ToString() + " de " +
tblalimentos.Rows.Count.ToString();
}
else
{
MessageBox.Show("Não há registros cadastrados", "mensagem",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

tblanimais = new DataTable();


strsql = "select * from animais where codanimal='" +
txtcodalimento.Text + "'";
adapter = new SqlDataAdapter(strsql, conexao);
adapter.Fill(tblanimais);
grade.DataSource = tblanimais;
}
}
}

Excluir Animais
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrabalhoILP20
{
public partial class Excluir_Animais : Form
{
private SqlConnection conexao;
private SqlCommand comando;
private SqlDataAdapter adapter;
private DataTable tblanimais;
private string strsql, strconex;

public Excluir_Animais()
{
InitializeComponent();
}

private void Btapagar_Click(object sender, EventArgs e)


{
strsql = "delete from animais where Codanimal='" + txtcodanimal.Text
+ "'";
comando = new SqlCommand(strsql, conexao);
comando.ExecuteNonQuery();

MessageBox.Show("Registro apagado com sucesso!", "mensagem",


MessageBoxButtons.OK, MessageBoxIcon.Information);

groupBox1.Enabled = true;
groupBox2.Visible = false;
}

private void Btcancelar_Click(object sender, EventArgs e)


{
groupBox1.Enabled = true;
groupBox2.Visible = false;
}

private void Btpesquisar_Click(object sender, EventArgs e)


{
strconex = "data source=(local);initial catalog=zoologico;integrated
security=sspi";
conexao = new SqlConnection(strconex);
conexao.Open();

tblanimais = new DataTable();

strsql = "select*from animais where codanimal='" + txtcodanimal.Text


+ "'";

adapter = new SqlDataAdapter(strsql, conexao);

adapter.Fill(tblanimais);
if (tblanimais.Rows.Count == 1)
{
groupBox1.Enabled = false;
groupBox2.Visible = true;
txtanimal.Text = tblanimais.Rows[0]["animal"].ToString();
txtpaisorigem.Text = tblanimais.Rows[0]["paisorigem"].ToString();
txtlocalizacao.Text = tblanimais.Rows[0]
["localizacao"].ToString();
txtcodalimento.Text = tblanimais.Rows[0]
["codalimento"].ToString();

else
{
MessageBox.Show("Registro não encontrado!", "mensagem",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}
}
}
}

You might also like