Pesquisar este blog

11 maio 2011

Código C#

Este código uso para carregar o form Entrega do meu projeto.

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 System.Data.SqlClient;

namespace AGE_2._9._1
{
public partial class Entrega : Form
{
SqlConnection con = null;
private DataTable dt = new DataTable("dbo.TbRecebimento");
private DataTable dt1 = new DataTable("dbo.TbProdutos");
private DataTable dt2 = new DataTable("dbo.TbEntrega");
private DataTable dt3 = new DataTable("dbo.TbRecebimento");
private DataTable dt4 = new DataTable("dbo.TbRecebimento");
String nome,codigo,chama;
int posicao;

public Entrega()
{
InitializeComponent();
}

private void Entrega_Load(object sender, EventArgs e)
{
con = Conect.getConect();
carregar_cliente();
carregar_codprod();
carregar_nomeprod();
carregar_nomeprod1();
carregar_nomeprod2();
carregar_nomeprod3();
carregar_nomeprod4();
carregar_nomeprod5();
carregar_nomeprod6();
carregar_nomeprod7();
carregar_nomeprod8();
carregar_nomeprod9();
carregar_nomeprod10();
carregar_total();
carregar_total1();
carregar_total2();
carregar_total3();
carregar_total4();
carregar_total5();
carregar_total6();
carregar_total7();
carregar_total8();
carregar_total9();
carregar_total10();
atualizaGrid();
dataGridView1.Columns[0].HeaderText = "Data da Entrega";
dataGridView1.Columns[1].HeaderText = "Nome do Cliente";
dataGridView1.Columns[2].HeaderText = "Código do Produto";
dataGridView1.Columns[3].HeaderText = "Código do Produto";
dataGridView1.Columns[4].HeaderText = "Código do Produto";
dataGridView1.Columns[5].HeaderText = "Código do Produto";
dataGridView1.Columns[6].HeaderText = "Código do Produto";
dataGridView1.Columns[7].HeaderText = "Código do Produto";
dataGridView1.Columns[8].HeaderText = "Código do Produto";
dataGridView1.Columns[9].HeaderText = "Código do Produto";
dataGridView1.Columns[10].HeaderText = "Código do Produto";
dataGridView1.Columns[11].HeaderText = "Código do Produto";
dataGridView1.Columns[12].HeaderText = "Código do Produto";
dataGridView1.Columns[13].HeaderText = "Nome do Produto";
dataGridView1.Columns[14].HeaderText = "Nome do Produto";
dataGridView1.Columns[15].HeaderText = "Nome do Produto";
dataGridView1.Columns[16].HeaderText = "Nome do Produto";
dataGridView1.Columns[17].HeaderText = "Nome do Produto";
dataGridView1.Columns[18].HeaderText = "Nome do Produto";
dataGridView1.Columns[19].HeaderText = "Nome do Produto";
dataGridView1.Columns[20].HeaderText = "Nome do Produto";
dataGridView1.Columns[21].HeaderText = "Nome do Produto";
dataGridView1.Columns[22].HeaderText = "Nome do Produto";
dataGridView1.Columns[23].HeaderText = "Nome do Produto";
dataGridView1.Columns[24].HeaderText = "Total de Produtos";
dataGridView1.Columns[25].HeaderText = "Total de Produtos";
dataGridView1.Columns[26].HeaderText = "Total de Produtos";
dataGridView1.Columns[27].HeaderText = "Total de Produtos";
dataGridView1.Columns[28].HeaderText = "Total de Produtos";
dataGridView1.Columns[29].HeaderText = "Total de Produtos";
dataGridView1.Columns[30].HeaderText = "Total de Produtos";
dataGridView1.Columns[31].HeaderText = "Total de Produtos";
dataGridView1.Columns[32].HeaderText = "Total de Produtos";
dataGridView1.Columns[33].HeaderText = "Total de Produtos";
dataGridView1.Columns[34].HeaderText = "Total de Produtos";
}

private void atualizaGrid()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from dbo.TbEntrega";
cmd.CommandTimeout = 10;

SqlDataReader dr;
dr = cmd.ExecuteReader();

dt2.Clear();
dt2.Load(dr);
dataGridView1.DataSource = dt2;
dr.Close();
}

private void escreve()
{
if (dt2.Rows.Count != 0)
{
cB1.Text = dt2.Rows[posicao]["nome_fan"].ToString();
cB2.Text = dt2.Rows[posicao]["cod_prod"].ToString();
cB3.Text = dt2.Rows[posicao]["cod_prod1"].ToString();
cB4.Text = dt2.Rows[posicao]["cod_prod2"].ToString();
cB5.Text = dt2.Rows[posicao]["cod_prod3"].ToString();
cB6.Text = dt2.Rows[posicao]["cod_prod4"].ToString();
cB7.Text = dt2.Rows[posicao]["cod_prod5"].ToString();
cB8.Text = dt2.Rows[posicao]["cod_prod6"].ToString();
cB9.Text = dt2.Rows[posicao]["cod_prod7"].ToString();
cB10.Text = dt2.Rows[posicao]["cod_prod8"].ToString();
cB11.Text = dt2.Rows[posicao]["cod_prod9"].ToString();
cB12.Text = dt2.Rows[posicao]["cod_prod10"].ToString();
label1.Text = dt2.Rows[posicao]["nome_prod"].ToString();
label2.Text = dt2.Rows[posicao]["nome_prod1"].ToString();
label3.Text = dt2.Rows[posicao]["nome_prod2"].ToString();
label4.Text = dt2.Rows[posicao]["nome_prod3"].ToString();
label5.Text = dt2.Rows[posicao]["nome_prod4"].ToString();
label6.Text = dt2.Rows[posicao]["nome_prod5"].ToString();
label7.Text = dt2.Rows[posicao]["nome_prod6"].ToString();
label8.Text = dt2.Rows[posicao]["nome_prod7"].ToString();
label9.Text = dt2.Rows[posicao]["nome_prod8"].ToString();
label10.Text = dt2.Rows[posicao]["nome_prod9"].ToString();
label11.Text = dt2.Rows[posicao]["nome_prod10"].ToString();
tB1.Text = dt2.Rows[posicao]["dataent"].ToString();
label12.Text = dt2.Rows[posicao]["total"].ToString();
label13.Text = dt2.Rows[posicao]["total1"].ToString();
label14.Text = dt2.Rows[posicao]["total2"].ToString();
label15.Text = dt2.Rows[posicao]["total3"].ToString();
label16.Text = dt2.Rows[posicao]["total4"].ToString();
label17.Text = dt2.Rows[posicao]["total5"].ToString();
label18.Text = dt2.Rows[posicao]["total6"].ToString();
label19.Text = dt2.Rows[posicao]["total7"].ToString();
label20.Text = dt2.Rows[posicao]["total8"].ToString();
label21.Text = dt2.Rows[posicao]["total9"].ToString();
label22.Text = dt2.Rows[posicao]["total10"].ToString();
}
else
{
cB1.Text = "";
cB2.Text = "";
cB3.Text = "";
cB4.Text = "";
cB5.Text = "";
cB6.Text = "";
cB7.Text = "";
cB8.Text = "";
cB9.Text = "";
cB10.Text = "";
cB11.Text = "";
cB12.Text = "";
label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
label5.Text = "";
label6.Text = "";
label7.Text = "";
label8.Text = "";
label9.Text = "";
label10.Text = "";
label11.Text = "";
tB1.Text = "";
label12.Text = "";
label13.Text = "";
label14.Text = "";
label15.Text = "";
label16.Text = "";
label17.Text = "";
label18.Text = "";
label19.Text = "";
label20.Text = "";
label21.Text = "";
label22.Text = "";
}
}

private void movePrimeiro()
{
posicao = 0;
escreve();
}

private void moveUltimo()
{
posicao = dt2.Rows.Count - 1;
escreve();
}

private void moveAnterior()
{
if (posicao > 0)
{
posicao = posicao - 1;
}
else
{
posicao = 0;
}
escreve();
}

private void moveProximo()
{
if (posicao < dt2.Rows.Count - 1)
{
posicao = posicao + 1;
}
else
{
posicao = dt2.Rows.Count - 1;
}
escreve();
}

private void carregar_cliente()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_fan from dbo.TbRecebimento";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt.Clear();
dt.Load(dr);

for (int i = 0; i < dt.Rows.Count; i++)
{
cB1.Items.Add(dt.Rows[i]["nome_fan"].ToString());
}
}

private void cB1_SelectedIndexChanged(object sender, EventArgs e)
{
nome = cB1.SelectedItem.ToString();
carregar_cliente();

foreach (DataRow row in dt.Rows)
{
nome = (("nome_fan").ToString());
}
}

private void carregar_codprod()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select cod_prod from dbo.TbProdutos";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt1.Clear();
dt1.Load(dr);

for (int i = 0; i < dt1.Rows.Count; i++)
{
cB2.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB3.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB4.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB5.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB6.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB7.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB8.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB9.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB10.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB11.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
cB12.Items.Add(dt1.Rows[i]["cod_prod"].ToString());
}
}

private void carregar_nomeprod()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod from TbRecebimento where cod_prod like " + "'%" + cB2.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total from TbRecebimento where cod_prod like " + "'%" + cB2.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB2_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB2.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod();
carregar_total();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod").ToString());
}

label1.Text = dt3.Rows[0]["nome_prod"].ToString();
label12.Text = dt4.Rows[0]["total"].ToString();
}

private void carregar_nomeprod1()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod1 from TbRecebimento where cod_prod1 like " + "'%" + cB3.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total1()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total1 from TbRecebimento where cod_prod1 like " + "'%" + cB3.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB3_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB3.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod1();
carregar_total1();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod1").ToString());
}

label2.Text = dt3.Rows[0]["nome_prod1"].ToString();
label13.Text = dt4.Rows[0]["total1"].ToString();
}

private void carregar_nomeprod2()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod2 from TbRecebimento where cod_prod2 like " + "'%" + cB4.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total2()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total2 from TbRecebimento where cod_prod2 like " + "'%" + cB4.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB4_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB4.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod2();
carregar_total2();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod2").ToString());
}

label3.Text = dt3.Rows[0]["nome_prod2"].ToString();
label14.Text = dt4.Rows[0]["total2"].ToString();
}

private void carregar_nomeprod3()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod3 from TbRecebimento where cod_prod3 like " + "'%" + cB5.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total3()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total3 from TbRecebimento where cod_prod3 like " + "'%" + cB5.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB5_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB5.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod3();
carregar_total3();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod3").ToString());
}

label4.Text = dt3.Rows[0]["nome_prod3"].ToString();
label15.Text = dt4.Rows[0]["total3"].ToString();
}

private void carregar_nomeprod4()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod4 from TbRecebimento where cod_prod4 like " + "'%" + cB6.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total4()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total4 from TbRecebimento where cod_prod4 like " + "'%" + cB6.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB6_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB6.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod4();
carregar_total4();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod4").ToString());
}

label5.Text = dt3.Rows[0]["nome_prod4"].ToString();
label16.Text = dt4.Rows[0]["total4"].ToString();
}

private void carregar_nomeprod5()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod5 from TbRecebimento where cod_prod5 like " + "'%" + cB7.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total5()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total5 from TbRecebimento where cod_prod5 like " + "'%" + cB7.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB7_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB7.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod5();
carregar_total5();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod5").ToString());
}

label6.Text = dt3.Rows[0]["nome_prod5"].ToString();
label17.Text = dt4.Rows[0]["total5"].ToString();
}

private void carregar_nomeprod6()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod6 from TbRecebimento where cod_prod6 like " + "'%" + cB8.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total6()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total6 from TbRecebimento where cod_prod6 like " + "'%" + cB8.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB8_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB8.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod6();
carregar_total6();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod6").ToString());
}

label7.Text = dt3.Rows[0]["nome_prod6"].ToString();
label18.Text = dt4.Rows[0]["total6"].ToString();
}

private void carregar_nomeprod7()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod7 from TbRecebimento where cod_prod7 like " + "'%" + cB9.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total7()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total7 from TbRecebimento where cod_prod7 like " + "'%" + cB9.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB9_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB9.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod7();
carregar_total7();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod7").ToString());
}

label8.Text = dt3.Rows[0]["nome_prod7"].ToString();
label19.Text = dt4.Rows[0]["total7"].ToString();
}

private void carregar_nomeprod8()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod8 from TbRecebimento where cod_prod8 like " + "'%" + cB10.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total8()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total8 from TbRecebimento where cod_prod8 like " + "'%" + cB10.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB10_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB10.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod8();
carregar_total8();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod8").ToString());
}

label9.Text = dt3.Rows[0]["nome_prod8"].ToString();
label20.Text = dt4.Rows[0]["total8"].ToString();
}

private void carregar_nomeprod9()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod9 from TbRecebimento where cod_prod9 like " + "'%" + cB11.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total9()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total9 from TbRecebimento where cod_prod9 like " + "'%" + cB11.Text + "%' and nome_fan like " + "'%" + cB1.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB11_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB11.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod9();
carregar_total9();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod9").ToString());
}

label10.Text = dt3.Rows[0]["nome_prod9"].ToString();
label21.Text = dt4.Rows[0]["total9"].ToString();
}

private void carregar_nomeprod10()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select nome_prod10 from TbRecebimento where cod_prod10 like " + "'%" + cB12.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt3.Clear();
dt3.Load(dr);
}
private void carregar_total10()
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select total10 from TbRecebimento where cod_prod10 like " + "'%" + cB12.Text + "%'";
cmd.CommandTimeout = 10;

SqlDataReader dr = cmd.ExecuteReader();
dt4.Clear();
dt4.Load(dr);
}
private void cB12_SelectedIndexChanged(object sender, EventArgs e)
{
codigo = cB12.SelectedItem.ToString();
carregar_codprod();
carregar_nomeprod10();
carregar_total10();

foreach (DataRow row in dt3.Rows)
{
codigo = (("cod_prod10").ToString());
}

label11.Text = dt3.Rows[0]["nome_prod10"].ToString();
label22.Text = dt4.Rows[0]["total10"].ToString();
}

private void salvar_cliente(String dataent, String nome_fan, String cod_prod, String cod_prod1, String cod_prod2, String cod_prod3, String cod_prod4, String cod_prod5, String cod_prod6, String cod_prod7, String cod_prod8, String cod_prod9, String cod_prod10, String nome_prod, String nome_prod1, String nome_prod2, String nome_prod3, String nome_prod4, String nome_prod5, String nome_prod6, String nome_prod7, String nome_prod8, String nome_prod9, String nome_prod10, String total, String total1, String total2, String total3, String total4, String total5, String total6, String total7, String total8, String total9, String total10)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;

if (chama == "novo")
{
cmd.CommandText = "insert into dbo.TbEntrega(nome_fan,cod_prod,cod_prod1,cod_prod2,cod_prod3,cod_prod4,cod_prod5,cod_prod6,cod_prod7,cod_prod8,cod_prod9,cod_prod10,nome_prod,nome_prod1,nome_prod2,nome_prod3,nome_prod4,nome_prod5,nome_prod6,nome_prod7,nome_prod8,nome_prod9,nome_prod10,total,total1,total2,total3,total4,total5,total6,total7,total8,total9,total10,dataent) Values (@nome_fan,@cod_prod,@cod_prod1,@cod_prod2,@cod_prod3,@cod_prod4,@cod_prod5,@cod_prod6,@cod_prod7,@cod_prod8,@cod_prod9,@cod_prod10,@nome_prod,@nome_prod1,@nome_prod2,@nome_prod3,@nome_prod4,@nome_prod5,@nome_prod6,@nome_prod7,@nome_prod8,@nome_prod9,@nome_prod10,@total,@total1,@total2,@total3,@total4,@total5,@total6,@total7,@total8,@total9,@total10,@dataent)";
cmd.Parameters.Add("@dataent", SqlDbType.NVarChar).Value = dataent;
cmd.Parameters.Add("@nome_fan", SqlDbType.NVarChar).Value = nome_fan;
cmd.Parameters.Add("@cod_prod", SqlDbType.NVarChar).Value = cod_prod;
cmd.Parameters.Add("@cod_prod1", SqlDbType.NVarChar).Value = cod_prod1;
cmd.Parameters.Add("@cod_prod2", SqlDbType.NVarChar).Value = cod_prod2;
cmd.Parameters.Add("@cod_prod3", SqlDbType.NVarChar).Value = cod_prod3;
cmd.Parameters.Add("@cod_prod4", SqlDbType.NVarChar).Value = cod_prod4;
cmd.Parameters.Add("@cod_prod5", SqlDbType.NVarChar).Value = cod_prod5;
cmd.Parameters.Add("@cod_prod6", SqlDbType.NVarChar).Value = cod_prod6;
cmd.Parameters.Add("@cod_prod7", SqlDbType.NVarChar).Value = cod_prod7;
cmd.Parameters.Add("@cod_prod8", SqlDbType.NVarChar).Value = cod_prod8;
cmd.Parameters.Add("@cod_prod9", SqlDbType.NVarChar).Value = cod_prod9;
cmd.Parameters.Add("@cod_prod10", SqlDbType.NVarChar).Value = cod_prod10;
cmd.Parameters.Add("@nome_prod", SqlDbType.NVarChar).Value = nome_prod;
cmd.Parameters.Add("@nome_prod1", SqlDbType.NVarChar).Value = nome_prod1;
cmd.Parameters.Add("@nome_prod2", SqlDbType.NVarChar).Value = nome_prod2;
cmd.Parameters.Add("@nome_prod3", SqlDbType.NVarChar).Value = nome_prod3;
cmd.Parameters.Add("@nome_prod4", SqlDbType.NVarChar).Value = nome_prod4;
cmd.Parameters.Add("@nome_prod5", SqlDbType.NVarChar).Value = nome_prod5;
cmd.Parameters.Add("@nome_prod6", SqlDbType.NVarChar).Value = nome_prod6;
cmd.Parameters.Add("@nome_prod7", SqlDbType.NVarChar).Value = nome_prod7;
cmd.Parameters.Add("@nome_prod8", SqlDbType.NVarChar).Value = nome_prod8;
cmd.Parameters.Add("@nome_prod9", SqlDbType.NVarChar).Value = nome_prod9;
cmd.Parameters.Add("@nome_prod10", SqlDbType.NVarChar).Value = nome_prod10;
cmd.Parameters.Add("@total", SqlDbType.NVarChar).Value = total;
cmd.Parameters.Add("@total1", SqlDbType.NVarChar).Value = total1;
cmd.Parameters.Add("@total2", SqlDbType.NVarChar).Value = total2;
cmd.Parameters.Add("@total3", SqlDbType.NVarChar).Value = total3;
cmd.Parameters.Add("@total4", SqlDbType.NVarChar).Value = total4;
cmd.Parameters.Add("@total5", SqlDbType.NVarChar).Value = total5;
cmd.Parameters.Add("@total6", SqlDbType.NVarChar).Value = total6;
cmd.Parameters.Add("@total7", SqlDbType.NVarChar).Value = total7;
cmd.Parameters.Add("@total8", SqlDbType.NVarChar).Value = total8;
cmd.Parameters.Add("@total9", SqlDbType.NVarChar).Value = total9;
cmd.Parameters.Add("@total10", SqlDbType.NVarChar).Value = total10;
cmd.ExecuteNonQuery();
atualizaGrid();
}
else if (chama == "alterar")
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "update dbo.TbEntrega set cod_prod = @cod_prod, cod_prod1 = @cod_prod1, cod_prod2 = @cod_prod2, cod_prod3 = @cod_prod3, cod_prod4 = @cod_prod4, cod_prod5 = @cod_prod5, cod_prod6 = @cod_prod6, cod_prod7 = @cod_prod7, cod_prod8 = @cod_prod8, cod_prod9 = @cod_prod9, cod_prod10 = @cod_prod10, nome_prod = @nome_prod, nome_prod1 = @nome_prod1, nome_prod2 = @nome_prod2, nome_prod3 = @nome_prod3, nome_prod4 = @nome_prod4, nome_prod5 = @nome_prod5, nome_prod6 = @nome_prod6, nome_prod7 = @nome_prod7, nome_prod8 = @nome_prod8, nome_prod9 = @nome_prod9, nome_prod10 = @nome_prod10, total = @total, total1 = @total1, total2 = @total2, total3 = @total3, total4 = @total4, total5 = @total5, total6 = @total6, total7 = @total7, total8 = @total8, total9 = @total9, total10 = @total10, dataent = @dataent where nome_fan = @nome_fan";
cmd.Parameters.Add("@dataent", SqlDbType.NVarChar).Value = dataent;
cmd.Parameters.Add("@nome_fan", SqlDbType.NVarChar).Value = nome_fan;
cmd.Parameters.Add("@cod_prod", SqlDbType.NVarChar).Value = cod_prod;
cmd.Parameters.Add("@cod_prod1", SqlDbType.NVarChar).Value = cod_prod1;
cmd.Parameters.Add("@cod_prod2", SqlDbType.NVarChar).Value = cod_prod2;
cmd.Parameters.Add("@cod_prod3", SqlDbType.NVarChar).Value = cod_prod3;
cmd.Parameters.Add("@cod_prod4", SqlDbType.NVarChar).Value = cod_prod4;
cmd.Parameters.Add("@cod_prod5", SqlDbType.NVarChar).Value = cod_prod5;
cmd.Parameters.Add("@cod_prod6", SqlDbType.NVarChar).Value = cod_prod6;
cmd.Parameters.Add("@cod_prod7", SqlDbType.NVarChar).Value = cod_prod7;
cmd.Parameters.Add("@cod_prod8", SqlDbType.NVarChar).Value = cod_prod8;
cmd.Parameters.Add("@cod_prod9", SqlDbType.NVarChar).Value = cod_prod9;
cmd.Parameters.Add("@cod_prod10", SqlDbType.NVarChar).Value = cod_prod10;
cmd.Parameters.Add("@nome_prod", SqlDbType.NVarChar).Value = nome_prod;
cmd.Parameters.Add("@nome_prod1", SqlDbType.NVarChar).Value = nome_prod1;
cmd.Parameters.Add("@nome_prod2", SqlDbType.NVarChar).Value = nome_prod2;
cmd.Parameters.Add("@nome_prod3", SqlDbType.NVarChar).Value = nome_prod3;
cmd.Parameters.Add("@nome_prod4", SqlDbType.NVarChar).Value = nome_prod4;
cmd.Parameters.Add("@nome_prod5", SqlDbType.NVarChar).Value = nome_prod5;
cmd.Parameters.Add("@nome_prod6", SqlDbType.NVarChar).Value = nome_prod6;
cmd.Parameters.Add("@nome_prod7", SqlDbType.NVarChar).Value = nome_prod7;
cmd.Parameters.Add("@nome_prod8", SqlDbType.NVarChar).Value = nome_prod8;
cmd.Parameters.Add("@nome_prod9", SqlDbType.NVarChar).Value = nome_prod9;
cmd.Parameters.Add("@nome_prod10", SqlDbType.NVarChar).Value = nome_prod10;
cmd.Parameters.Add("@total", SqlDbType.NVarChar).Value = total;
cmd.Parameters.Add("@total1", SqlDbType.NVarChar).Value = total1;
cmd.Parameters.Add("@total2", SqlDbType.NVarChar).Value = total2;
cmd.Parameters.Add("@total3", SqlDbType.NVarChar).Value = total3;
cmd.Parameters.Add("@total4", SqlDbType.NVarChar).Value = total4;
cmd.Parameters.Add("@total5", SqlDbType.NVarChar).Value = total5;
cmd.Parameters.Add("@total6", SqlDbType.NVarChar).Value = total6;
cmd.Parameters.Add("@total7", SqlDbType.NVarChar).Value = total7;
cmd.Parameters.Add("@total8", SqlDbType.NVarChar).Value = total8;
cmd.Parameters.Add("@total9", SqlDbType.NVarChar).Value = total9;
cmd.Parameters.Add("@total10", SqlDbType.NVarChar).Value = total10;
cmd.Parameters.Add("@dataent", SqlDbType.NVarChar).Value = dataent;
cmd.ExecuteNonQuery();
atualizaGrid();
}
}

private void button5_Click(object sender, EventArgs e)
{
tB1.Text = "";
cB1.Text = "";
cB2.Text = "";
cB3.Text = "";
cB4.Text = "";
cB5.Text = "";
cB6.Text = "";
cB7.Text = "";
cB8.Text = "";
cB9.Text = "";
cB10.Text = "";
cB11.Text = "";
cB12.Text = "";
label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
label5.Text = "";
label6.Text = "";
label7.Text = "";
label8.Text = "";
label9.Text = "";
label10.Text = "";
label11.Text = "";
label12.Text = "";
label13.Text = "";
label14.Text = "";
label15.Text = "";
label16.Text = "";
label17.Text = "";
label18.Text = "";
label19.Text = "";
label20.Text = "";
label21.Text = "";
label22.Text = "";
chama = "novo";
}

private void button6_Click(object sender, EventArgs e)
{
chama = "alterar";
}

private void removeCadastro(String nome_fan)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "delete from dbo.TbEntrega where nome_fan = @nome_fan";
cmd.Parameters.Add("@nome_fan", SqlDbType.NChar).Value = nome_fan;
cmd.ExecuteNonQuery();
atualizaGrid();
}

private void button7_Click(object sender, EventArgs e)
{
this.removeCadastro(cB1.Text);
}

private void button8_Click(object sender, EventArgs e)
{
salvar_cliente(tB1.Text, cB1.Text, cB2.Text, cB3.Text, cB4.Text, cB5.Text, cB6.Text, cB7.Text, cB8.Text, cB9.Text, cB10.Text, cB11.Text, cB12.Text, label1.Text, label2.Text, label3.Text, label4.Text, label5.Text, label6.Text, label7.Text, label8.Text, label9.Text, label10.Text, label11.Text, label12.Text, label13.Text, label14.Text, label15.Text, label16.Text, label17.Text, label18.Text, label19.Text, label20.Text, label21.Text, label22.Text);
}

private void button10_Click(object sender, EventArgs e)
{
Close();
}

private void button1_Click(object sender, EventArgs e)
{
movePrimeiro();
}

private void button2_Click(object sender, EventArgs e)
{
moveAnterior();
}

private void button3_Click(object sender, EventArgs e)
{
moveProximo();
}

private void button4_Click(object sender, EventArgs e)
{
moveUltimo();
}
}
}

Nenhum comentário:

Postar um comentário