private void btnAlterar_Click(object sender, EventArgs e) { //try //{ Model.Entities.tb_suprimento supri = cboProduto.SelectedItem as Model.Entities.tb_suprimento; Model.Entities.tb_fornecedor forn = cboFornecedor.SelectedItem as Model.Entities.tb_fornecedor; supri.id_fornecedor = forn.id_fornecedor; supri.nm_produto = txtProduto.Text; supri.qt_produtos = Convert.ToInt32(nudQtdProduto.Value); supri.vl_preco = nudPreco.Value; Business.SuprimentosBusiness bussupri = new Business.SuprimentosBusiness(); bussupri.Alterar(supri); MessageBox.Show("Alteração efetuada com sucesso", "Fast Care", MessageBoxButtons.OK, MessageBoxIcon.Information); //} //catch (ArgumentException ex) //{ // MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //} //catch (Exception) //{ // MessageBox.Show("Ocorreu um erro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //} }
public void Remover(int id) { Model.Entities.tb_fornecedor remove = db.tb_fornecedor.FirstOrDefault(t => t.id_fornecedor == id); db.tb_fornecedor.Remove(remove); db.SaveChanges(); }
private void btnRemover_Click(object sender, EventArgs e) { try { Model.Entities.tb_fornecedor forn = cboCnpj.SelectedItem as Model.Entities.tb_fornecedor; Business.FonecedorBusiness busf = new Business.FonecedorBusiness(); busf.Remover(forn.id_fornecedor); MessageBox.Show("Remoção efetuada com sucesso", "Fast Care", MessageBoxButtons.OK, MessageBoxIcon.Information); ConsultarCnpjs(); txtFornecedor.Clear(); txtCel.Clear(); txtCep.Clear(); txtCnpj.Clear(); txtEmail.Clear(); txtEnd.Clear(); txtInscrEstadual.Clear(); txtNCasa.Clear(); cboUF.Text = string.Empty; } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception) { MessageBox.Show("Ocorreu um erro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnCadastrar_Click(object sender, EventArgs e) { try { Model.Entities.tb_suprimento supri = new Model.Entities.tb_suprimento(); Model.Entities.tb_fornecedor forn = cboFornecedor.SelectedItem as Model.Entities.tb_fornecedor; supri.id_fornecedor = forn.id_fornecedor; supri.nm_produto = txtProduto.Text.Trim(); supri.qt_produtos = Convert.ToInt32(nudQtdProduto.Value); supri.vl_preco = nudPreco.Value; supri.dt_compra = dtpCompra.Value; Business.SuprimentosBusiness bussupri = new Business.SuprimentosBusiness(); bussupri.Inserir(supri); MessageBox.Show("Cadastro efetuado com sucesso", "Fast Care", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception) { MessageBox.Show("Ocorreu um erro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnCadastrar_Click(object sender, EventArgs e) { try { Model.Entities.tb_fornecedor forn = new Model.Entities.tb_fornecedor(); forn.ds_cel = txtCel.Text; forn.ds_cep = txtCep.Text; forn.ds_cnpj = txtCnpj.Text; forn.ds_email = txtEmail.Text.Trim(); forn.ds_tel = txtTel.Text; forn.end_forn = txtEnd.Text; forn.insc_estadual = txtInscrEstadual.Text.Trim(); forn.nm_forn = txtFornecedor.Text.Trim(); forn.nu_forn = txtNCasa.Text.Trim(); forn.uf_estado = cboUF.Text; Business.FonecedorBusiness busforn = new Business.FonecedorBusiness(); busforn.Inserir(forn); MessageBox.Show("Cadastro efetuado com sucesso", "Fast Care", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception) { MessageBox.Show("Ocorreu um erro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Alterar(Model.Entities.tb_fornecedor forn) { Model.Entities.tb_fornecedor verificado = db.VerificarCnpj(forn.ds_cnpj); if (verificado != null) { throw new ArgumentException("O CNPJ já existe"); } ValidarFornecedor(forn); db.Alterar(forn); }
private void cboCnpj_SelectedIndexChanged_1(object sender, EventArgs e) { Model.Entities.tb_fornecedor f = cboCnpj.SelectedItem as Model.Entities.tb_fornecedor; txtFornecedor.Text = f.nm_forn; txtCel.Text = f.ds_cel; txtCep.Text = f.ds_cep; txtCnpj.Text = f.ds_cnpj; txtEmail.Text = f.ds_email; txtEnd.Text = f.end_forn; txtInscrEstadual.Text = f.insc_estadual; txtNCasa.Text = f.nu_forn; txtTel.Text = f.ds_tel; cboUF.Text = f.uf_estado; }
public void Alterar(Model.Entities.tb_fornecedor forn) { Model.Entities.tb_fornecedor antigo = db.tb_fornecedor.FirstOrDefault(t => t.ds_cnpj == forn.ds_cnpj); antigo.ds_cel = forn.ds_cel; antigo.ds_cep = forn.ds_cep; antigo.ds_cnpj = forn.ds_cnpj; antigo.ds_email = forn.ds_email; antigo.ds_tel = forn.ds_tel; antigo.end_forn = forn.end_forn; antigo.insc_estadual = forn.insc_estadual; antigo.nm_forn = forn.nm_forn; antigo.nu_forn = forn.nu_forn; antigo.uf_estado = forn.uf_estado; antigo.insc_estadual = forn.insc_estadual; db.SaveChanges(); }
private void ValidarFornecedor(Model.Entities.tb_fornecedor forn) { if (!Utils.Validacao.ValidarRequerido(forn.nm_forn)) { throw new ArgumentException("O campo Fornecedor é obrigatório"); } if (!Utils.Validacao.ValidarCnpj(forn.ds_cnpj)) { throw new ArgumentException("O campo CNPJ é obrigatório"); } if (!Utils.Validacao.ValidarRequerido(forn.uf_estado)) { throw new ArgumentException("O campo UF é obrigatório"); } if (!Utils.Validacao.ValidarRequerido(forn.insc_estadual)) { throw new ArgumentException("O campo Inscrição Estadual é obrigatório"); } if (!Utils.Validacao.ValidarCep(forn.ds_cep)) { throw new ArgumentException("O campo Cep deve ser preenchido"); } if (forn.end_forn == " - - " || !Utils.Validacao.ValidarRequerido(forn.end_forn)) { throw new ArgumentException("Cep inválido"); } if (!Utils.Validacao.ValidarRequerido(forn.nu_forn)) { throw new ArgumentException("O campo Nº Estabelecimento é obrigatório"); } if (!Utils.Validacao.ValidarEmail(forn.ds_email)) { throw new ArgumentException("O Email é inválido"); } if (!Utils.Validacao.ValidarCelOuTel(forn.ds_cel)) { throw new ArgumentException("O Celular é inválido"); } if (!Utils.Validacao.ValidarCelOuTel(forn.ds_tel)) { throw new ArgumentException("O Telefone inválido"); } }
private void btnCadastrar_Click(object sender, EventArgs e) { try { Model.Entities.tb_fornecedor f = new Model.Entities.tb_fornecedor(); f.nm_forn = txtFornecedor.Text; f.ds_cel = txtCel.Text; f.ds_cep = txtCep.Text; f.ds_cnpj = txtCnpj.Text; f.ds_email = txtEmail.Text; f.end_forn = txtEnd.Text; f.insc_estadual = txtInscrEstadual.Text; f.nu_forn = txtNCasa.Text; f.ds_tel = txtTel.Text; f.uf_estado = cboUF.Text; Business.FonecedorBusiness busf = new Business.FonecedorBusiness(); if (f.ds_cnpj != Model.Entities.Fornecedor.cnpjantigo) { busf.Alterar(f); } else { busf.AlterarCnpjIgual(f); } MessageBox.Show("Alteração efetuada com sucesso", "Fast Care", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception) { MessageBox.Show("Ocorreu um erro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public Model.Entities.tb_fornecedor VerificarCnpj(string cnpj) { Model.Entities.tb_fornecedor model = db.tb_fornecedor.FirstOrDefault(t => t.ds_cnpj == cnpj); return(model); }
public void Inserir(Model.Entities.tb_fornecedor forn) { db.tb_fornecedor.Add(forn); db.SaveChanges(); }
public void AlterarCnpjIgual(Model.Entities.tb_fornecedor forn) { ValidarFornecedor(forn); db.Alterar(forn); }