private void InitialConditionPage()
        {
            switch (Session.LoggedUser.Usuario.Privilegio.IdPrivilegio)
            {
            default:
                ListInvoice();
                ListFilial();
                ListProviders();
                ListStuff();
                buttonApply   = new EnumApplyAction();
                newCollection = null;
                oldCollection = null;

                //Lists
                dataGridInvoice.Visibility   = Visibility.Visible;
                dataGridAddStuff.ItemsSource = null;

                //Buttons
                btnEdit.IsEnabled   = btnRemove.IsEnabled = btnAddStuff.IsEnabled = btnRemoveStuff.IsEnabled = btnEditStuff.IsEnabled = false;
                btnNew.Visibility   = btnEdit.Visibility = btnRemove.Visibility = Visibility.Visible;
                btnApply.Visibility = btnCancel.Visibility = Visibility.Hidden;

                //Controls
                txtInvoice.Text     = txtStuffQt.Text = string.Empty;
                dpDate.SelectedDate = null;
                lblUn.Content       = string.Empty;
                break;
            }
        }
        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                notaDTO = dataGridInvoice.SelectedItem as NotaDTO;

                if (MessageBox.Show("Realmente deseja excluir a nota " + notaDTO.NumeroNota + "?", "Remover Nota", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
                {
                    oldCollection = notaProdutoBLL.ReadInvoice(notaDTO);
                    notaProdutoBLL.Delete(notaDTO);
                    notaBLL.Delete(notaDTO);

                    foreach (NotaProdutoDTO item in oldCollection)
                    {
                        estoqueDTO            = new EstoqueDTO();
                        estoqueDTO.Produto    = item.Produto;
                        estoqueDTO.Filial     = item.Nota.Filial;
                        estoqueDTO.Quantidade = item.QuantidadeComprada;
                        estoqueBLL.Delete(estoqueDTO);
                    }

                    InitialConditionPage();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                buttonApply = EnumApplyAction.Update;

                //Lists
                dataGridInvoice.Visibility = Visibility.Hidden;

                //Buttons
                btnNew.Visibility   = btnEdit.Visibility = btnRemove.Visibility = Visibility.Hidden;
                btnApply.Visibility = btnCancel.Visibility = Visibility.Visible;

                //Pegando informações das notas apenas
                notaDTO = new NotaDTO();
                notaDTO = dataGridInvoice.SelectedItem as NotaDTO;

                txtInvoice.Text          = notaDTO.NumeroNota.ToString();
                dpDate.SelectedDate      = notaDTO.DataNota;
                cbProvider.SelectedValue = notaDTO.Fornecedor.Pessoa.NomePessoa;
                cbFilial.SelectedValue   = notaDTO.Filial.Pessoa.NomePessoa;

                newCollection = notaProdutoBLL.ReadInvoice(notaDTO);
                oldCollection = notaProdutoBLL.ReadInvoice(notaDTO);

                dataGridAddStuff.ItemsSource = newCollection;
                LiberarRemoveStuff();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Consulta informações de privilegio por nome.
        /// </summary>
        /// <param name="nota">Nome do privilegio que será consultado.</param>
        /// <returns>Informações do privilegio encontrado.</returns>
        public NotaProdutoCollectionDTO ReadInvoice(NotaDTO nota)
        {
            NotaProdutoCollectionDTO notaProdutoCollectionDTO = new NotaProdutoCollectionDTO();

            try
            {
                dataBaseAccess.ClearParameters();
                dataBaseAccess.AddParameters("_idNota", nota.IdNota);

                DataTable dataTable = new DataTable();
                dataTable = dataBaseAccess.Consult(CommandType.StoredProcedure, "sp_nota_produto_nota");

                foreach (DataRow row in dataTable.Rows)
                {
                    NotaProdutoDTO notaProdutoDTO = new NotaProdutoDTO();
                    notaProdutoDTO.Nota               = new NotaDTO();
                    notaProdutoDTO.Nota.IdNota        = Convert.ToInt32(row["IdNota"]);
                    notaProdutoDTO.QuantidadeComprada = float.Parse(row["QuantidadeComprada"].ToString());
                    notaProdutoDTO.ValorUnitario      = Convert.ToDecimal(row["ValorUnitario"]);
                    notaProdutoDTO.ValorTotal         = Convert.ToDecimal(row["ValorTotal"]);

                    notaProdutoDTO.Nota.Filial = new FilialDTO();
                    notaProdutoDTO.Nota.Filial.Pessoa.IdPessoa   = Convert.ToInt32(row["IdPessoaFilial"]);
                    notaProdutoDTO.Nota.Filial.Pessoa.NomePessoa = row["NomeFilial"].ToString();

                    notaProdutoDTO.Nota.Fornecedor = new FornecedorDTO();
                    notaProdutoDTO.Nota.Fornecedor.Pessoa.IdPessoa   = Convert.ToInt32(row["IdPessoaFornecedor"]);
                    notaProdutoDTO.Nota.Fornecedor.Pessoa.NomePessoa = row["NomeFornecedor"].ToString();

                    notaProdutoDTO.Produto                  = new ProdutoDTO();
                    notaProdutoDTO.Produto.IdProduto        = Convert.ToInt32(row["IdProduto"]);
                    notaProdutoDTO.Produto.DescricaoProduto = row["DescricaoProduto"].ToString();

                    notaProdutoDTO.Produto.Unidade              = new UnidadeDTO();
                    notaProdutoDTO.Produto.Unidade.IdUnidade    = Convert.ToInt32(row["IdProduto"]);
                    notaProdutoDTO.Produto.Unidade.SiglaUnidade = row["SiglaUnidade"].ToString();

                    notaProdutoCollectionDTO.Add(notaProdutoDTO);
                }

                return(notaProdutoCollectionDTO);
            }
            catch (Exception ex)
            {
                StringBuilder message = new StringBuilder();
                message.Append("Não foi possível consultar produto por nota:\n\n").Append(ex.Message);
                throw new Exception(message.ToString());
            }
            finally
            {
                dataBaseAccess.ClearParameters();
            }
        }
        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            buttonApply = EnumApplyAction.Create;

            //Lists
            dataGridInvoice.Visibility = Visibility.Hidden;

            //Buttons
            btnNew.Visibility   = btnEdit.Visibility = btnRemove.Visibility = Visibility.Hidden;
            btnApply.Visibility = btnCancel.Visibility = Visibility.Visible;

            notaProdutoDTO = new NotaProdutoDTO();
            newCollection  = new NotaProdutoCollectionDTO();
        }