GALERA, QUANDO ESTOU CADASTRANDO O PRODUTO E VOU CLICAR NA CATEGORIA
EX: DESCRICAO DO PRODUTO/CAMISA REGATA VALOR/20,00 CATEGORIA/ QUANDO VOU ESCOLHER ESSA OPÇÃO, MEUS CAMPOS DE CATEGORIA FICAM DUPLICADOS
VEJAM SE HÁ ALGO DE ERRADO NOS CODIGOS!
namespace Sistema
{
public partial class frm_produtos : Form
{
public frm_produtos()
{
InitializeComponent();
}
private void frm_produtos_Load(object sender, EventArgs e)
{
this.produtoBindingSource.DataSource = DataContextFactory.DataContext.Produto;
this.categoriaBindingSource.DataSource = DataContextFactory.DataContext.Categoria;
}
private void btn_novo_Click(object sender, EventArgs e)
{
this.produtoBindingSource.AddNew();
}
private void btn_cadastrar_Click(object sender, EventArgs e)
{
if (this.valida() && validvalor() && validcat())
{
this.produtoBindingSource.EndEdit();
DataContextFactory.DataContext.SubmitChanges();
dataGridView1.Refresh();
MessageBox.Show("Produto inserido com sucesso!");
}
}
private bool valida()
{
if (txt_descricao.Text.Trim() == string.Empty)
{
MessageBox.Show("O campo de desrição é obrigatório!");
txt_descricao.Focus();
return false;
}
return true;
}
private bool validvalor()
{
if (txt_valor.Text.Trim() == string.Empty)
{
MessageBox.Show("O campo de valor é obrigatório!");
txt_valor.Focus();
return false;
}
return true;
}
private bool validcat()
{
if (cb_categoria.Text.Trim() == string.Empty)
{
MessageBox.Show("O campo de categoria é obrigatório!");
cb_categoria.Focus();
return false;
}
return true;
}
private void btn_excluir_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Deseja realmente excluir este campo?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
{
this.produtoBindingSource.RemoveCurrent();
DataContextFactory.DataContext.SubmitChanges();
MessageBox.Show("Produto exlcuído com sucesso");
}
}
}
private void btn_cancelar_Click(object sender, EventArgs e)
{
this.produtoBindingSource.CancelEdit();
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
{
if (e.Value != null && e.ColumnIndex == 3)
e.Value = ((Categoria)e.Value).Descricao;
}
}
}
}