public bool ValidarAtualizarCompraGado(CompraGado Compra) { bool retorno = false; if (!ValidarDataEntrega(Compra)) { throw new System.ArgumentException("Uma compra de gado tem que ter obrigatoriamente uma data de entrega.", "ValidarCompra"); } else if (!ValidarPecuarista(Compra)) { throw new System.ArgumentException("Uma compra de gado tem que ter obrigatoriamente um pecuarista.", "ValidarCompra"); } else if (!ValidarItens(Compra.CompraDadoItem)) { throw new System.ArgumentException("Um compra de gado precisa ter no minimo um item.", "ValidarCompra"); } else if (!ValidarSeExisteDoisItensMesmoAnimal(Compra.CompraDadoItem)) { throw new System.ArgumentException("Um compra de gado não pode ter dois itens com o mesmo animal.", "ValidarCompra"); } else if (!ValidarQuantidadeItem(Compra.CompraDadoItem)) { throw new System.ArgumentException("Um item não pode ter quantidade menor do que zero.", "ValidarCompra"); } else { retorno = true; } return(retorno); }
public async Task <ActionResult <CompraGado> > PostCompraGado(CompraGado compraGado) { _context.CompraGados.Add(compraGado); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCompraGado", new { id = compraGado.CompraGadoId }, compraGado)); }
public void ValidarCompraGado() { CompraGadoValidar CompraGadoItemRep = new CompraGadoValidar(new CompraGadoRepository(new SistemaCompraGadoDGContexto())); CompraGado _CompraGado = new CompraGado(); List <CompraGadoItem> _Itens = new List <CompraGadoItem>(); SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository PecuaristaRep = new SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository(new SistemaCompraGadoDGContexto()); Pecuarista LstPecuarista = (Pecuarista)PecuaristaRep.GetAll().First(); AnimalRepository AnimalRep = new AnimalRepository(new SistemaCompraGadoDGContexto()); Animal LstAnimal = (Animal)AnimalRep.GetAll().First(); _CompraGado.ID = 205; _Itens.Add(new CompraGadoItem { AnimalID = LstAnimal.ID, CompraGadoID = _CompraGado.ID, Quantidade = "1.000" }); // _Itens.Add(new CompraGadoItem { AnimalID = LstAnimal.ID, CompraGadoID = _CompraGado.ID, Quantidade = "1.000" }); _CompraGado.DataEntrega = DateTime.Now; _CompraGado.PecuaristaID = LstPecuarista.ID; _CompraGado.CompraDadoItem = _Itens; CompraGadoItemRep.ValidarCompraGado(_CompraGado); }
public async Task <IActionResult> Edit(int id, [Bind("CompraGadoId,DataEntrega,PecuaristaId")] CompraGado compraGado) { if (id != compraGado.CompraGadoId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(compraGado); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompraGadoExists(compraGado.CompraGadoId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["PecuaristaId"] = new SelectList(_context.Pecuaristas, "PecuaristaId", "Nome", compraGado.PecuaristaId); return(View(compraGado)); }
public async Task <IHttpActionResult> PutCompraGado(int id, CompraGado compraGado) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != compraGado.Id) { return(BadRequest()); } db.Entry(compraGado).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompraGadoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> PutCompraGado(int id, CompraGado compraGado) { if (id != compraGado.Id) { return(BadRequest()); } _context.Entry(compraGado).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CompraGadoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private new async void Update() { URL = ConfigurationManager.AppSettings["Marfrig"]; URL += "/CompraGado"; CompraGado compraGado = new CompraGado(); compraGado.Pecuarista = new Pecuarista(); compraGado.Id = int.Parse(lblCompraGadoID.Text); compraGado.DataEntrega = dtpDataEntrega.Value; compraGado.Pecuarista.Id = idPecuarista; compraGado.Pecuarista.Nome = txtPecuarista.Text; using (var client = new HttpClient()) { HttpResponseMessage responseMessage = await client.PutAsJsonAsync(URL + "/" + compraGado.Id, compraGado); if (responseMessage.IsSuccessStatusCode) { MessageBox.Show("Produto atualizado"); frmCompra frm = new frmCompra(); frm.GetAllPecuaristas(); } else { MessageBox.Show("Falha ao atualizar o produto : " + responseMessage.StatusCode); } } }
public void InserirCompraGadoData() { CompraGadoRepository CompraGadoRep = new CompraGadoRepository(new SistemaCompraGadoDGContexto()); CompraGado _CompraGado = new CompraGado(); _CompraGado.ID = 203; _CompraGado.DataEntrega = DateTime.Now; _CompraGado.PecuaristaID = 1; CompraGadoRep.Add(_CompraGado); }
public void AtualizaCompraGadoData() { CompraGadoRepository CompraGadoRep = new CompraGadoRepository(new SistemaCompraGadoDGContexto()); CompraGado _CompraGado = new CompraGado(); CompraGado LstCompraGado = (CompraGado)CompraGadoRep.GetAll().First(); _CompraGado.DataEntrega = DateTime.Now; _CompraGado.PecuaristaID = 1; CompraGadoRep.Update(_CompraGado); }
public async Task <IHttpActionResult> GetCompraGado(int id) { CompraGado compraGado = await db.CompraGados.Where(c => c.Id == id).Include(c => c.Pecuarista).Include(c => c.CompraGadoItems).SingleAsync(); if (compraGado == null) { return(NotFound()); } return(Ok(compraGado)); }
public async Task <IHttpActionResult> PostCompraGado(CompraGado compraGado) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CompraGados.Add(compraGado); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = compraGado.Id }, compraGado)); }
public async Task <IActionResult> Create([Bind("CompraGadoId,DataEntrega,PecuaristaId")] CompraGado compraGado) { if (ModelState.IsValid) { _context.Add(compraGado); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PecuaristaId"] = new SelectList(_context.Pecuaristas, "PecuaristaId", "Nome", compraGado.PecuaristaId); return(View(compraGado)); }
public async Task <IHttpActionResult> DeleteCompraGado(int id) { CompraGado compraGado = await db.CompraGados.FindAsync(id); if (compraGado == null) { return(NotFound()); } db.CompraGados.Remove(compraGado); await db.SaveChangesAsync(); return(Ok(compraGado)); }
private void Pesquisar() { bool validaPesquisa = false; CompraGado compragado = new CompraGado(); if (txtDataEntregaDe.Checked) { compragado.DataEntrega = Convert.ToDateTime(txtDataEntregaDe.Value); validaPesquisa = true; } if (txtDataEntregaAte.Checked) { compragado.DataEntregaAte = Convert.ToDateTime(txtDataEntregaAte.Value); validaPesquisa = true; } if (Convert.ToInt32(cmbPecuarista.SelectedValue) > 0) { compragado.PecuaristaId = Convert.ToInt32(cmbPecuarista.SelectedValue); validaPesquisa = true; } if (txtId.Text != "") { compragado.Id = Convert.ToInt32(txtId.Text); validaPesquisa = true; } if (validaPesquisa != true) { MetroFramework.MetroMessageBox.Show(this, "Por favor, digite um item para pesquisa.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { compraGadoConsultaBindingSource.DataSource = wbclient.GetConsultaCompraGado(compragado); CompraGado oCompragado = compraGadoConsultaBindingSource.Current as CompraGado; } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public bool Update(CompraGado oGado) { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoSqlServer"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } int resultado = db.Execute("sp_Atualizar_CompraGado", new { Id = oGado.Id, DataEntrega = oGado.DataEntrega }, commandType: CommandType.StoredProcedure); return(resultado != 0); } }
private void btnNovo_Click(object sender, EventArgs e) { if (btnNovo.Text == "Novo") { btnNovoAnimal.Enabled = true; txtDataEntrega.Enabled = true; //txtDataEntrega.Checked = false; cmbPecuarista.Enabled = true; txtId.Text = "NOVO"; btnNovo.Enabled = false; } else { if (MetroFramework.MetroMessageBox.Show(this, "Tem certeza que deseja salvar as alterações", "Salvar ?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } WebServiceMarfrigSoapClient wbClinet = null; CompraGado classCompragado = null; try { wbClinet = new WebServiceMarfrigSoapClient(); classCompragado = new WebServiceMarfrig.CompraGado(); if (txtDataEntrega.Checked) { classCompragado.DataEntrega = Convert.ToDateTime(txtDataEntrega.Text); } classCompragado.Id = Convert.ToInt32(txtId.Text); classCompragado.PecuaristaId = Convert.ToInt32(cmbPecuarista.SelectedValue); wbClinet.UpdateCompraGado(classCompragado); this.Close(); } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public int Inserir(CompraGado oGado) { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoSqlServer"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } DynamicParameters p = new DynamicParameters(); p.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output); p.AddDynamicParams(new { DataEntrega = oGado.DataEntrega, PecuaristaId = oGado.PecuaristaId }); int resultado = db.Execute("sp_Inserir_CompraGado", p, commandType: CommandType.StoredProcedure); if (resultado != 0) { return(p.Get <int>("@Id")); } return(0); } }
public async Task <IActionResult> Post(CompraGado model) { try { var compraGado = _mapper.Map <CompraGado>(model); _repository.Add(compraGado); if (await _repository.SaveChangesAsync()) { return(Created($"/api/marfrig/{model.Id}", _mapper.Map <CompraGadoDto>(compraGado))); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Banco de dados falhou {ex.Message}")); } return(BadRequest()); }
private void frmRelatorio_Load(object sender, EventArgs e) { rpRelatorio.Width = this.Width - 10; rpRelatorio.Height = this.Height - 10; try { WebServiceMarfrigSoapClient webclient = new WebServiceMarfrigSoapClient(); compraGadoConsultaBindingSource.DataSource = webclient.GetRelatorioCompraGado(compraGado); CompraGado oCompragado = compraGadoConsultaBindingSource.Current as CompraGado; } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.rpRelatorio.AutoSize = true; this.rpRelatorio.RefreshReport(); this.rpRelatorio.RefreshReport(); }
public void ValidarCompraGadoAppService() { CompraGadoAppService CompraService = new CompraGadoAppService(new CompraGadoService(new CompraGadoRepository(new SistemaCompraGadoDGContexto()), new CompraGadoValidar(new CompraGadoRepository(new SistemaCompraGadoDGContexto())), new CompraGadoItemRepository((new SistemaCompraGadoDGContexto())), new PecuaristaRepository((new SistemaCompraGadoDGContexto())), new AnimalRepository(new SistemaCompraGadoDGContexto()))); CompraGado Compra = new CompraGado(); SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository PecuaristaRep = new SistemaCompraGado.Infra.Data.Repositories.PecuaristaRepository(new SistemaCompraGadoDGContexto()); Pecuarista LstPecuarista = (Pecuarista)PecuaristaRep.GetAll().First(); List <CompraGadoItem> _Itens = new List <CompraGadoItem>(); AnimalRepository AnimalRep = new AnimalRepository(new SistemaCompraGadoDGContexto()); Animal LstAnimal = (Animal)AnimalRep.GetAll().First(); Compra.ID = 545; Compra.DataEntrega = DateTime.Now; Compra.PecuaristaID = LstPecuarista.ID; _Itens.Add(new CompraGadoItem { AnimalID = LstAnimal.ID, CompraGadoID = 544, Quantidade = "1.000" }); Compra.CompraDadoItem = _Itens; CompraService.AdicionarCompra(Compra); }
public CompraGadoWebAPI ConsultarById(string IDCompraGado) { if (long.TryParse(IDCompraGado, out long n)) { CompraGado _CompraGado = _CompraGadoAppService.ConsultarById(long.Parse(IDCompraGado)); List <CompraGadoItemWebAPI> _CompraGadoItemWebAPI = new List <CompraGadoItemWebAPI>(); foreach (CompraGadoItem _CompraGadoItem in _CompraGado.CompraDadoItem) { _CompraGadoItemWebAPI.Add(new CompraGadoItemWebAPI { AnimalID = _CompraGadoItem.AnimalID, CompraGadoID = _CompraGadoItem.CompraGadoID, Quantidade = _CompraGadoItem.Quantidade }); } return(new CompraGadoWebAPI { ID = _CompraGado.ID, CompraDadoItem = _CompraGadoItemWebAPI, DataEntrega = _CompraGado.DataEntrega, PecuaristaID = _CompraGado.PecuaristaID }); } else { return(null); } }
private bool ValidarPecuarista(CompraGado Compra) { return(Compra.PecuaristaID.GetHashCode() != 0); }
private bool ValidarDataEntrega(CompraGado Compra) { return(Compra.DataEntrega.GetHashCode() != 0); }
public List <CompraGadoConsulta> GetConsultaCompraGado(CompraGado compraGado) { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexaoSql"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } DynamicParameters p = new DynamicParameters(); if (compraGado.Id != null) { p.AddDynamicParams(new { Id = compraGado.Id }); } if (compraGado.PecuaristaId != null) { p.AddDynamicParams(new { PecuaristaId = compraGado.PecuaristaId }); } if (compraGado.DataEntrega != null) { p.AddDynamicParams(new { DataEntrega = compraGado.DataEntrega }); } if (compraGado.DataEntregaAte != null) { p.AddDynamicParams(new { DataEntregaAte = compraGado.DataEntregaAte }); } string select = null; if (compraGado.Id == null) { select = select + "DECLARE @id int = null "; } if (compraGado.PecuaristaId == null) { select = select + "DECLARE @PecuaristaId int = null "; } if (compraGado.DataEntrega == null) { select = select + "DECLARE @DataEntrega datetime = null "; } if (compraGado.DataEntregaAte == null) { select = select + "DECLARE @DataEntregaAte datetime = null "; } select = select + "SELECT cg.id, cg.PecuaristaId, p.Nome, cg.DataEntrega, COUNT(a.Id) QuantidadeItem, "; select = select + "SUM(cgi.Quantidade * a.Preco) AS ValorTotal, CASE WHEN cg.Impresso = 0 THEN 'Não' ELSE 'SIM' END AS Impresso "; select = select + "FROM CompraGado cg "; select = select + " INNER JOIN Pecuarista p ON p.id = cg.PecuaristaId "; select = select + " LEFT JOIN CompraGadoItem cgi ON cgi.CompraGadoId = cg.Id "; select = select + " LEFT JOIN Animal a ON a.id = cgi.AnimalId "; select = select + " WHERE "; select = select + " (@id IS NULL OR cg.id = @id) AND "; select = select + " (@PecuaristaId IS NULL OR cg.PecuaristaId = @PecuaristaId) AND "; select = select + " (@DataEntrega IS NULL OR cg.DataEntrega >= @DataEntrega) AND "; select = select + " (@DataEntregaAte IS NULL OR cg.DataEntrega <= @DataEntregaAte) "; select = select + " GROUP BY cg.id, cg.PecuaristaId, p.Nome, cg.DataEntrega, cg.Impresso"; return(db.Query <CompraGadoConsulta>(select, p, commandType: CommandType.Text).ToList()); } }
private bool ValidarID(CompraGado Compra) { return(_CompraGadoRepository.GetById(Compra.ID).DataEntrega.GetHashCode() == 0); }
private void btnInserir_Click(object sender, EventArgs e) { WebServiceMarfrigSoapClient wbClient = null; CompraGado classCompragado = null; try { wbClient = new WebServiceMarfrigSoapClient(); classCompragado = new WebServiceMarfrig.CompraGado(); if (txtId.Text == "NOVO") { classCompragado.Id = 1; } else { classCompragado.Id = Convert.ToInt32(txtId.Text); } if (txtDataEntrega.Checked) { classCompragado.DataEntrega = Convert.ToDateTime(txtDataEntrega.Text); } else { MetroFramework.MetroMessageBox.Show(this, "Por favor, selecionar uma data de entrega.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cmbPecuarista.SelectedValue == null) { MetroFramework.MetroMessageBox.Show(this, "Por favor, selecionar um pecuarista", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } classCompragado.PecuaristaId = Convert.ToInt32(cmbPecuarista.SelectedValue); int Id; if (txtId.Text == "NOVO") { Id = wbClient.InserirCompraGado(classCompragado); txtId.Text = Id.ToString(); } else { wbClient.UpdateCompraGado(classCompragado); } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } frmCompraGadoItem frmcompragadoitem = new frmCompraGadoItem(Convert.ToInt32(txtId.Text)); frmcompragadoitem.ShowDialog(); //Atualiza o grid getAllCompraGadoItem(Convert.ToInt32(txtId.Text)); btnExcluirAnimal.Enabled = true; }