private void BtnSelecionarCid_Click(object sender, EventArgs e) { try { VendPet = dgvDados.CurrentRow?.DataBoundItem as VendaPET; if (dgvDados.CurrentRow != null) { DialogResult = DialogResult.OK; Close(); } } catch (Exception erro) { MessageBox.Show(erro.Message, "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void gravar(VendaPET venda) { if (venda.Vp_cod == null) { Connection.Execute("insert into vendapet" + "(vp_datavenda,vp_valortotal,cli_cod, user_cod)" + " values(@vp_datavenda, @vp_valortotal, @clienteid, @usuarioid)", venda); venda.Vp_cod = Convert.ToInt32(Connection.ExecuteScalar("select last_insert_id()")); } else { Connection.Execute("update vendapet set vp_datavenda = @vp_datavenda, vp_valortotal=@vp_valortotal, cli_cod=@clienteid, user_cod=@usuarioid where vp_cod = @vp_cod", venda); Connection.Execute("delete from produtovenda where vp_cod = @vp_cod", venda); Connection.Execute("delete from ContasAReceber where vp_cod = @vp_cod", venda); } }
public void Exclui(ProdutoVenda p, VendaPET v) { Connection.Execute("delete from produtovenda where vp_cod = @Vendaid", p); Connection.Execute("delete from vendapet where vp_cod = @vp_cod", v); }
private void BtnVender_Click(object sender, EventArgs e) { int parcelas = 0, dias = 0; VendaPET v = new VendaPET(); bool flag = true; DateTime data = DateTime.Now; if (txtcliente.Text == null) { MessageBox.Show("Selecione um cliente"); } else { if (txtid.Text != "") { v.Vp_cod = Convert.ToInt32(txtid.Text); } if (produtos.Count == 0) { MessageBox.Show("Uma venda precisa ter pelo menos um produto!"); } else { v.Vp_valortotal = Convert.ToDecimal(txtValor.Text); v.Cliente = cliente; v.Vp_datavenda = dtpData.Value; List <ProdutoVenda> lpv = VendaPETRepository.GetPVenda(v.Vp_cod).ToList(); if (rbParcelado.Checked) { flag = false; if (txtParcelas.Text.Replace("R$", "").Replace("-", "").Replace("_", "").Replace(".", ",").Replace(" ", "").Replace(",", "").Length > 0) { string a = txtParcelas.Text.Replace("R$", "").Replace("-", "").Replace("_", "").Replace(".", ",").Replace(" ", ""); parcelas = Convert.ToInt32(a); if (txtDias.Text.Replace("R$", "").Replace("-", "").Replace("_", "").Replace(".", ",").Replace(" ", "").Replace(",", "").Length > 0) { string b = txtParcelas.Text.Replace("R$", "").Replace("-", "").Replace("_", "").Replace(".", ",").Replace(" ", ""); dias = Convert.ToInt32(b); data = dtpVencimentoParcela.Value; flag = true; } else { MessageBox.Show("Dias invalidos"); } } else { MessageBox.Show("Parcelas invalidas"); } } else { if (rbPrazo.Checked) { data = dtpVencimentoPrazo.Value; } } if (flag) { if (txtid.Text != "") { foreach (var a in lpv) { int estoque = a.Produto.Pp_estoque + a.Pv_quantidade; int?c = a.ProdutoID; VendaPETRepository.atualizarproduto((int)c, estoque); } } VendaPETRepository.gravar(v); if (rbParcelado.Checked) { decimal total = v.Vp_valortotal; decimal valorp = v.Vp_valortotal / parcelas; ContasAReceber c; for (int i = 0; i < parcelas; i++) { c = new ContasAReceber(); c.Cr_dataVencimento = data; if (i + 1 != parcelas) { c.Cr_valorAReceber = valorp; } else { c.Cr_valorAReceber = total; } total -= valorp; c.Cr_dataGeracao = DateTime.Now; c.VendaPet = (int)v.Vp_cod; c.UsuarioId = v.Usuarioid; VendaPETRepository.GravarContas(c); data = data.AddDays(dias); } } else { if (rbPrazo.Checked) { ContasAReceber c = new ContasAReceber(); c.Cr_dataVencimento = data; c.Cr_valorAReceber = v.Vp_valortotal; c.VendaPet = (int)v.Vp_cod; c.UsuarioId = v.Usuarioid; VendaPETRepository.GravarContas(c); } } foreach (var item in produtos) { item.Venda = v; item.Vendaid = v.Vp_cod; VendaPETRepository.GravarProds(item); ProdutoPET pp = ProdutoPETRepository.Get(item.ProdutoID); int n = pp.Pp_estoque - item.Pv_quantidade; int? c = item.ProdutoID; VendaPETRepository.atualizarproduto((int)c, n); } produtos.Clear(); limpar(); MessageBox.Show("Gravado com sucesso!"); } } } }