public NotaEntrada GetById(long id)
    {
        NotaEntrada    notaEntrada      = new NotaEntrada();
        DAL_Fornecedor dalFornecedor    = new DAL_Fornecedor();
        long           idFornecedorNota = -1;
        var            command          = new SqlCommand("select id, idfornecedor, numero, dataemissao," +
                                                         "dataentrada from NOTASDEENTRADA where id = @id", connection);

        command.Parameters.AddWithValue("@id", id);
        connection.Open();

        using (SqlDataReader reader = command.ExecuteReader())
        {
            while (reader.Read())
            {
                notaEntrada.Id          = reader.GetInt64(0);
                idFornecedorNota        = reader.GetInt64(1);
                notaEntrada.Numero      = reader.GetString(2);
                notaEntrada.DataEmissao = reader.GetDateTime(3);
                notaEntrada.DataEntrada = reader.GetDateTime(4);
            }
        }
        connection.Close();
        if (idFornecedorNota > 0)
        {
            notaEntrada.FornecedorNota = dalFornecedor.GetById(idFornecedorNota);
        }

        return(notaEntrada);
    }
示例#2
0
        public NotaEntrada GetNotaEntradabyId(long?id)
        {
            NotaEntrada          nota = new NotaEntrada();
            FornecedorController fornecedorController = new FornecedorController();
            long?IdFornecedorNota = -1;
            var  command          = new SqlCommand("select Id, IdFornecedor, Numero, DataEmissao, DataEntrada from NotaDeEntrada where id=@id", connection);

            command.Parameters.AddWithValue("@id", id);
            connection.Open();
            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    nota.Id          = reader.GetInt64(0);
                    IdFornecedorNota = reader.GetInt64(1);
                    nota.Numero      = reader.GetString(2);
                    nota.DataEmissao = reader.GetDateTime(3);
                    nota.DataEntrada = reader.GetDateTime(4);
                }
            }
            connection.Close();
            if (IdFornecedorNota > 0)
            {
                nota.FornecedorNota = fornecedorController.GetFornecedorById(IdFornecedorNota);
            }
            return(nota);
        }
        public async Task <IActionResult> PutNotaEntrada([FromRoute] int id, [FromBody] NotaEntrada notaEntrada)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != notaEntrada.CdNotaEntrada)
            {
                return(BadRequest());
            }

            notaEntrada.DtAlteracao = DateTime.Now;

            _context.Entry(notaEntrada).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotaEntradaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(notaEntrada));
        }
        public async Task <IActionResult> PostNotaEntrada([FromBody] NotaEntrada notaEntrada)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            notaEntrada.DtRegistro = DateTime.Now;

            _context.NotaEntrada.Add(notaEntrada);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (NotaEntradaExists(notaEntrada.CdNotaEntrada))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetNotaEntrada", new { id = notaEntrada.CdNotaEntrada }, notaEntrada));
        }
示例#5
0
        public NotaEntrada UpdateNotaEntrada(NotaEntrada notaEntrada)
        {
            string query = "UPDATE Notas SET Numero = @Numero, Fornecedor = @Fornecedor, DataEmissao = @DataEmissao, DataEntrada = @DataEntrada WHERE ID = @ID";

            SqlParameter[] parameters = new SqlParameter[5];
            parameters[0]       = new SqlParameter("@Numero", SqlDbType.VarChar);
            parameters[0].Value = notaEntrada.Numero;

            parameters[1]       = new SqlParameter("@Fornecedor", SqlDbType.Int);
            parameters[1].Value = notaEntrada.FornecedorNota.Id;

            parameters[2]       = new SqlParameter("@DataEmissao", SqlDbType.DateTime);
            parameters[2].Value = notaEntrada.DataEmissao;

            parameters[3]       = new SqlParameter("@DataEntrada", SqlDbType.DateTime);
            parameters[3].Value = notaEntrada.DataEntrada;

            parameters[4]       = new SqlParameter("@ID", SqlDbType.Int);
            parameters[4].Value = notaEntrada.Id;

            conn.ExecuteNonQuery(query, parameters);

            //this.notasEntrada[this.notasEntrada.IndexOf(notaEntrada)] = notaEntrada;

            return(notaEntrada);
        }
示例#6
0
        //para NOTA ENTRADA

        public NotaEntrada InsertNotaEntrada(NotaEntrada notaEntrada)
        {
            string query = "INSERT INTO Notas VALUES (@Numero, @Fornecedor, @DataEmissao, @DataEntrada); SELECT SCOPE_IDENTITY();";

            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0]       = new SqlParameter("@Numero", SqlDbType.VarChar);
            parameters[0].Value = notaEntrada.Numero;

            parameters[1]       = new SqlParameter("@Fornecedor", SqlDbType.Int);
            parameters[1].Value = notaEntrada.FornecedorNota.Id;

            parameters[2]       = new SqlParameter("@DataEmissao", SqlDbType.DateTime);
            parameters[2].Value = notaEntrada.DataEmissao;

            parameters[3]       = new SqlParameter("@DataEntrada", SqlDbType.DateTime);
            parameters[3].Value = notaEntrada.DataEntrada;

            int idGerado = conn.ExecuteInsert(query, parameters);

            notaEntrada.Id = idGerado;

            //this.notasEntrada.Add(notaEntrada);

            return(notaEntrada);
        }
示例#7
0
 public FormEntradaNew(NotaEntrada currentNotaEntrada)
 {
     InitializeComponent();
     this.nuevo = false;
     formato    = "{0:n" + nroDecimales + "}";
     cargarFechaSistema();
     this.currentNotaEntrada = currentNotaEntrada;
 }
示例#8
0
 public void Save(NotaEntrada notaEntrada)
 {
     if (notaEntrada.Id != null)
     {
         this.Update(notaEntrada);
     }
     else
     {
         this.Insert(notaEntrada);
     }
 }
示例#9
0
 public void Save(NotaEntrada notaEntrada, ProdutoNotaEntrada produto)
 {
     if (produto.Id != null)
     {
         this.Update(produto);
     }
     else
     {
         this.Insert(notaEntrada, produto);
     }
 }
 public void SaveNotaDeEntrada(NotaEntrada notaEntrada)
 {
     if (notaEntrada.Id == null)
     {
         this.InsertNotaDeEntrada(notaEntrada);
     }
     else
     {
         this.UpdateNotaDeEntrada(notaEntrada);
     }
 }
 public void SaveProduto(NotaEntrada notaEntrada, ProdutoNotaEntrada produto)
 {
     if (produto.Id == null)
     {
         this.InsertProduto(notaEntrada, produto);
     }
     else
     {
         this.UpdateProduto(produto);
     }
 }
示例#12
0
 private void ClearControls()
 {
     txtIdNotaEntrada.Text       = string.Empty;
     cmbFornecedor.SelectedIndex = -1;
     txtNumeroNotaEntrada.Text   = string.Empty;
     dtpDataEmissao.Value        = DateTime.Now;
     dtpDataEntrada.Value        = DateTime.Now;
     dgvNotaEntrada.ClearSelection();
     notaAtual = null;
     ClearControlsProdutoNota();
     dgvProdutoNotaEntrada.DataSource = null;
 }
示例#13
0
        public void RemoveNotaEntrada(NotaEntrada notaEntrada)
        {
            string query = "DELETE FROM Notas WHERE ID = @ID";

            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0]       = new SqlParameter("@ID", SqlDbType.Int);
            parameters[0].Value = notaEntrada.Id;

            conn.ExecuteNonQuery(query, parameters);

            this.notasEntrada.Remove(notaEntrada);
        }
示例#14
0
 public async Task <Response> anular(NotaEntrada currentNotaEntrada)
 {
     try
     {
         // localhost:8080/admeli/xcore2/xcore/services.php/nentrada/guardar
         return(await webService.POST <NotaEntrada, Response>("nentrada", "anular", currentNotaEntrada));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#15
0
        private void Insert(NotaEntrada nota)
        {
            var command = new SqlCommand("insert into NotaDeEntrada (Numero, IdFornecedor, DataEmissao, DataEntrada) values (@Numero, @IdFornecedor, @DataEmissao, @DataEntrada)", connection);

            command.Parameters.AddWithValue("@Numero", nota.Numero);
            command.Parameters.AddWithValue("@IdFornecedor", nota.FornecedorNota.Id);
            command.Parameters.AddWithValue("@DataEmissao", nota.DataEmissao);
            command.Parameters.AddWithValue("@DataEntrada", nota.DataEntrada);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
            MessageBox.Show("Nota inserida com sucesso!");
        }
    private void InsertNotaDeEntrada(NotaEntrada notaEntrada)
    {
        var command = new SqlCommand("insert into NOTASDEENTRADA(IdFornecedor, Numero, DataEmissao," +
                                     "DataEntrada) values(@IdFornecedor, @Numero, @DataEmissao, @DataEntrada)", connection);

        command.Parameters.AddWithValue("@IdFornecedor", notaEntrada.FornecedorNota.Id);
        command.Parameters.AddWithValue("@Numero", notaEntrada.Numero);
        command.Parameters.AddWithValue("@DataEmissao", notaEntrada.DataEmissao);
        command.Parameters.AddWithValue("@DataEntrada", notaEntrada.DataEntrada);
        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();
    }
 private void ClearControlsNota()
 {
     txtIDNotaEntrada.Text       = string.Empty;
     txtNumero.Text              = string.Empty;
     cbxFornecedor.SelectedIndex = -1;
     dtpEmissao.Value            = DateTime.Now;
     dtpEntrada.Value            = DateTime.Now;
     dgvNotasEntrada.ClearSelection();
     dgvProdutos.ClearSelection();
     GetAllNotas();
     GetAllProdutos();
     this.notaAtual = null;
 }
 private void dgvNotasEntrada_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex < 0 || e.ColumnIndex < 0)
     {
         return;
     }
     this.notaAtual             = dalNotaEntrada.GetById(Convert.ToInt64(dgvNotasEntrada.Rows[e.RowIndex].Cells[0].Value));
     txtIDNotaEntrada.Text      = notaAtual.Id.ToString();
     txtNumero.Text             = notaAtual.Numero;
     dtpEmissao.Value           = notaAtual.DataEmissao;
     dtpEntrada.Value           = notaAtual.DataEntrada;
     cbxFornecedor.SelectedItem = notaAtual.FornecedorNota;
 }
示例#19
0
        private void Update(NotaEntrada nota)
        {
            var command = new SqlCommand("update NotaDeEntrada set Numero=@Numero, IdFornecedor=@IdFornecedor, DataEmissao=@DataEmissao, DataEntrada=@DataEntrada where Id=@Id", connection);

            command.Parameters.AddWithValue("@Numero", nota.Numero);
            command.Parameters.AddWithValue("@IdFornecedor", nota.FornecedorNota.Id);
            command.Parameters.AddWithValue("@DataEmissao", nota.DataEmissao);
            command.Parameters.AddWithValue("@DataEntrada", nota.DataEntrada);
            command.Parameters.AddWithValue("@Id", nota.Id);
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
            MessageBox.Show("Nota atualizada com sucesso!");
        }
    private void InsertProduto(NotaEntrada ProdutoNotaEntrada, ProdutoNotaEntrada produto)
    {
        //ProdutoNotaEntrada.Produtos.Add(produto);
        var command = new SqlCommand("insert into PRODUTOSNOTASDEENTRADA(IdNotaDeEntrada, IdProduto," +
                                     "PrecoCustoCompra, QuantidadeComprada) " +
                                     "values(@idnotadeentrada, @idproduto, @precocustocompra, @quantidadecomprada)", connection);

        command.Parameters.AddWithValue("@idnotadeentrada", ProdutoNotaEntrada.Id);
        command.Parameters.AddWithValue("@idproduto", produto.ProdutoNota.Id);
        command.Parameters.AddWithValue("@precocustocompra", produto.PrecoCustoCompra);
        command.Parameters.AddWithValue("@quantidadecomprada", produto.QuantidadeComprada);
        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();
    }
示例#21
0
        private void dgvNotaEntrada_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            this.notaAtual             = notaEntradaController.GetNotaEntradabyId(Convert.ToInt64(dgvNotaEntrada.Rows[e.RowIndex].Cells[0].Value));
            txtIdNotaEntrada.Text      = notaAtual.Id.ToString();
            cmbFornecedor.SelectedItem = notaAtual.FornecedorNota;
            txtNumeroNotaEntrada.Text  = notaAtual.Numero;
            dtpDataEmissao.Value       = notaAtual.DataEmissao;
            dtpDataEntrada.Value       = notaAtual.DataEntrada;
            ChangeStatusControlsNovaNotaDeEntrada(true);
            AtualizarProdutoNotaEntradaDataGridView();
        }
示例#22
0
        private void btnGravarNota_Click(object sender, System.EventArgs e)
        {
            var notaEntrada = new NotaEntrada()
            {
                Id             = (txtIDNotaEntrada.Text == string.Empty ? Guid.NewGuid() : new Guid(txtIDNotaEntrada.Text)),
                DataEmissao    = dtpEmissao.Value,
                DataEntrada    = dtpEntrada.Value,
                FornecedorNota = (Fornecedor)cbxFornecedor.SelectedItem,
                Numero         = txtNumero.Text
            };

            notaEntrada = (txtIDNotaEntrada.Text == string.Empty ? this.controller.Insert(notaEntrada) : this.controller.Update(notaEntrada));
            dgvNotasEntrada.DataSource = null;
            dgvNotasEntrada.DataSource = this.controller.GetAll();
            ClearControlsNota();
        }
示例#23
0
        private void BtnGravarProduto_Click(object sender, EventArgs e)
        {
            var produtoNota = new ProdutoNotaEntrada()
            {
                Id = (txtIDProduto.Text == string.Empty ? Guid.NewGuid() : new Guid(txtIDProduto.Text)),
                PrecoCustoCompra   = Convert.ToDouble(txtCusto.Text),
                ProdutoNota        = (Produto)cbxProduto.SelectedItem,
                QuantidadeComprada = Convert.ToDouble(txtQuantidade.Text)
            };

            this.notaAtual.RegistrarProduto(produtoNota);
            this.notaAtual = this.controller.Update(this.notaAtual);
            ChangeStatusOfControls(false);
            UpdateProdutosGrid();
            ClearControlsProduto();
        }
    private void UpdateNotaDeEntrada(NotaEntrada notaEntrada)
    {
        var command = new SqlCommand("update NOTASDEENTRADA set IdFornecedor = @IdFornecedor, Numero = @Numero, DataEmissao = @DataEmissao," +
                                     "DataEntrada = @DataEntrada where(Id = @Id)", connection);

        command.Parameters.AddWithValue("@IdFornecedor", notaEntrada.FornecedorNota.Id);
        command.Parameters.AddWithValue("@Numero", notaEntrada.Numero);
        command.Parameters.AddWithValue("@DataEmissao", notaEntrada.DataEmissao);
        command.Parameters.AddWithValue("@DataEntrada", notaEntrada.DataEntrada);
        command.Parameters.AddWithValue("@Id", notaEntrada.Id);
        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();
        //DeleteAllProdutosFromNotaEntrada(notaEntrada.Id);
        //InsertProdutosNotaDeEntrada(notaEntrada.Id, notaEntrada.Produtos);
    }
示例#25
0
        private async void executeAnular()
        {
            // Verificando la existencia de datos en el datagridview
            if (dataGridView.Rows.Count == 0)
            {
                MessageBox.Show("No hay un registro seleccionado", "Desactivar o anular", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                DialogResult dialog = MessageBox.Show("¿Desea Eliminar este Nota Salida?", "Nota Salida",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                if (dialog == DialogResult.No)
                {
                    return;
                }
                loadState(true);


                // preguntar antes de anular
                int index = dataGridView.CurrentRow.Index;                                                   // Identificando la fila actual del datagridview
                currentNotaEntrada = new NotaEntrada();                                                      //creando una instancia del objeto correspondiente
                currentNotaEntrada.idNotaEntrada = Convert.ToInt32(dataGridView.Rows[index].Cells[0].Value); // obteniedo el idRegistro del datagridview

                // Comprobando si el registro ya esta desactivado
                if (notaEntradas.Find(x => x.idNotaEntrada == currentNotaEntrada.idNotaEntrada).estado == 0)
                {
                    MessageBox.Show("Este registro ya esta desactivado", "Desactivar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // Procediendo con las desactivacion
                Response response = await notaEntradaModel.anular(currentNotaEntrada);

                MessageBox.Show(response.msj, "Desactivar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cargarRegistros(); // recargando los registros en el datagridview
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                loadState(false);
            }
        }
示例#26
0
 private void dgvNotasEntrada_SelectionChanged(object sender, EventArgs e)
 {
     try
     {
         this.notaAtual             = this.controller.GetNotaEntradaById((Guid)dgvNotasEntrada.CurrentRow.Cells[0].Value);
         txtIDNotaEntrada.Text      = notaAtual.Id.ToString();
         txtNumero.Text             = notaAtual.Numero;
         cbxFornecedor.SelectedItem = notaAtual.FornecedorNota;
         dtpEmissao.Value           = notaAtual.DataEmissao;
         dtpEntrada.Value           = notaAtual.DataEntrada;
         UpdateProdutosGrid();
     }
     catch (Exception)
     {
         this.notaAtual = new NotaEntrada();
     }
 }
示例#27
0
        private void Insert(NotaEntrada notaEntrada, ProdutoNotaEntrada produto)
        {
            notaEntrada.Produtos.Add(produto);

            var command = new SqlCommand("insert into ProdutoNotaDeEntrada (IdNotaDeEntrada, IdProduto, PrecoCustoCompra, QuantidadeComprada) values (@IdNotaDeEntrada, @IdProduto, @PrecoCustoCompra, @QuantidadeComprada)", connection);

            command.Parameters.AddWithValue("@IdNotaDeEntrada", notaEntrada.Id);
            command.Parameters.AddWithValue("@IdProduto", produto.ProdutoNota.Id);
            command.Parameters.AddWithValue("@PrecoCustoCompra", produto.PrecoCustoCompra);
            command.Parameters.AddWithValue("@QuantidadeComprada", produto.QuantidadeComprada);

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();

            double qtdProduto = BuscaEstoqueProduto(produto.ProdutoNota.Id) + produto.QuantidadeComprada;

            UpdateEstoqueProdutos(qtdProduto, produto.ProdutoNota.Id);

            MessageBox.Show("Produto inserido na nota de entrada com sucesso!");
        }
示例#28
0
        private async void executeEliminar()
        {
            // Verificando la existencia de datos en el datagridview
            if (dataGridView.Rows.Count == 0)
            {
                MessageBox.Show("No hay un registro seleccionado", "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Pregunta de seguridad de eliminacion
            DialogResult dialog = MessageBox.Show("¿Está seguro de eliminar este registro?", "Eliminar",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (dialog == DialogResult.No)
            {
                return;
            }


            try
            {
                int index = dataGridView.CurrentRow.Index;                                                   // Identificando la fila actual del datagridview
                currentNotaEntrada = new NotaEntrada();                                                      //creando una instancia del objeto categoria
                currentNotaEntrada.idNotaEntrada = Convert.ToInt32(dataGridView.Rows[index].Cells[0].Value); // obteniedo el idCategoria del datagridview

                loadState(true);                                                                             // cambiando el estado
                Response response = await notaEntradaModel.eliminar(currentNotaEntrada);                     // Eliminando con el webservice correspondiente

                MessageBox.Show(response.msj, "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cargarRegistros(); // recargando el datagridview
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                loadState(false); // cambiando el estado
            }
        }
示例#29
0
        public IList <NotaEntrada> GetAllNotasEntrada()
        {
            notasEntrada.Clear();

            string    query = "SELECT * FROM Notas";
            DataTable dt    = conn.ExecuteSelectQuery(query);

            foreach (DataRow row in dt.Rows)
            {
                int      id           = (int)row["ID"];
                string   nome         = row["Numero"] as string;
                int      idFornecedor = (int)row["Fornecedor"]; //chave estrangeira
                DateTime dataEmissao  = (DateTime)row["DataEmissao"];
                DateTime dataEntrada  = (DateTime)row["DataEntrada"];

                Fornecedor  f    = GetFornecedor(idFornecedor);
                NotaEntrada nota = new NotaEntrada(id, nome, f, dataEmissao, dataEntrada);
                notasEntrada.Add(nota);
            }

            return(this.notasEntrada);
        }
        //botao gravar ou gravar nota
        private void btnGravarNota_Click(object sender, System.EventArgs e)
        {
            var notaEntrada = new NotaEntrada()
            {
                DataEmissao    = dtpEmissao.Value,
                DataEntrada    = dtpEntrada.Value,
                FornecedorNota = (Fornecedor)cbxFornecedor.SelectedItem,
                Numero         = txtNumero.Text
            };

            if (!string.IsNullOrEmpty(this.txtIDNota.Text))
            {
                notaEntrada.Id = Convert.ToInt32(txtIDNota.Text);
                notaEntradaController.Update(notaEntrada);
            }
            else
            {
                notaEntradaController.Insert(notaEntrada);
            }

            dgvNotasEntrada.DataSource = null;
            dgvNotasEntrada.DataSource = this.notaEntradaController.GetAll();
            ClearControlsNota();
        }