Exemple #1
0
        private void Eventos()
        {
            BuscarProduto.Select();

            KeyDown                   += KeyDowns;
            ModoRapido.KeyDown        += KeyDowns;
            BuscarProduto.KeyDown     += KeyDowns;
            GridListaProdutos.KeyDown += KeyDowns;
            Quantidade.KeyDown        += KeyDowns;
            Masks.SetToUpper(this);

            Shown += (s, e) =>
            {
                // Autocomplete de produtos
                collection = _mItem.AutoComplete("Produtos");
                BuscarProduto.AutoCompleteCustomSource = collection;

                Medidas.DataSource = Support.GetMedidas();

                SetHeadersTable(GridListaProdutos);
                GetDataTableItens(GridListaProdutos, _mNota.id_pedido);
                LoadTotais();
                ClearForms();
                BuscarProduto.Select();

                if (_mNota.Status != "Pendente")
                {
                    progress5.Visible   = false;
                    pictureBox1.Visible = false;
                    label9.Visible      = false;
                }
            };

            ModoRapido.Click += (s, e) => AlterarModo();

            Next.Click += (s, e) => OpenForm.Show <TelaFrete>(this);

            Back.Click += (s, e) => Close();

            addProduto.Click += (s, e) => LoadItens();

            BuscarProduto.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (ModoRapAva == 1)
                    {
                        if (!string.IsNullOrEmpty(nomeProduto()[0]))
                        {
                            var item = _mItem.FindById(collection.Lookup(nomeProduto()[0])).FirstOrDefault <Model.Item>();
                            if (item != null)
                            {
                                Preco.Text           = Validation.FormatPrice(item.ValorVenda);
                                Medidas.SelectedItem = item.Medida;
                            }

                            Quantidade.Focus();
                            return;
                        }
                    }

                    if (string.IsNullOrEmpty(nomeProduto()[0]))
                    {
                        ModalItens();
                    }
                    else
                    {
                        LoadItens();
                    }
                }
            };

            GridListaProdutos.DoubleClick += (s, e) =>
            {
                if (GridListaProdutos.SelectedRows.Count > 0)
                {
                    EditProduct.idPdt  = Validation.ConvertToInt32(GridListaProdutos.SelectedRows[0].Cells["ID"].Value);
                    EditProduct.nrItem = Validation.ConvertToInt32(GridListaProdutos.SelectedRows[0].Cells["#"].Value);
                    EditProduct f = new EditProduct();
                    f.TopMost = true;
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        GetDataTableItens(GridListaProdutos, _mNota.id_pedido);
                        LoadTotais();
                    }
                }
            };

            Preco.TextChanged += (s, e) =>
            {
                TextBox txt = (TextBox)s;
                Masks.MaskPrice(ref txt);
            };

            Preco.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    LoadItens();
                }
            };

            Quantidade.KeyPress += (s, e) => Masks.MaskDouble(s, e);
            Quantidade.KeyDown  += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (String.IsNullOrEmpty(nomeProduto()[0]))
                    {
                        BuscarProduto.Focus();
                    }
                    else if (ModoRapAva == 1 && !String.IsNullOrEmpty(nomeProduto()[0]))
                    {
                        Preco.Focus();
                    }
                    else
                    {
                        LoadItens();
                    }
                }
            };

            DescontoPorcentagem.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    LoadItens();
                }
            };
            DescontoReais.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    LoadItens();
                }
            };

            AlterarImposto.Click += (s, e) =>
            {
                if (GridListaProdutos.SelectedRows.Count > 0)
                {
                    AlterarImposto f = new AlterarImposto();
                    f.TopMost = true;
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        if (idImposto > 0)
                        {
                            foreach (DataGridViewRow item in GridListaProdutos.Rows)
                            {
                                if ((bool)item.Cells["Selecione"].Value == true)
                                {
                                    new Controller.Imposto().SetImposto(Validation.ConvertToInt32(item.Cells["ID"].Value), idImposto, "NFe", NCM);
                                }
                            }
                        }

                        GetDataTableItens(GridListaProdutos, _mNota.id_pedido);
                    }

                    NCM       = "";
                    idImposto = 0;
                }

                BuscarProduto.Select();
            };

            btnMarcarCheckBox.Click += (s, e) =>
            {
                foreach (DataGridViewRow item in GridListaProdutos.Rows)
                {
                    if (btnMarcarCheckBox.Text == "Marcar Todos")
                    {
                        if ((bool)item.Cells["Selecione"].Value == false)
                        {
                            item.Cells["Selecione"].Value = true;
                            AlterarImposto.Visible        = true;
                        }
                    }
                    else
                    {
                        item.Cells["Selecione"].Value = false;
                        AlterarImposto.Visible        = false;
                    }
                }

                if (btnMarcarCheckBox.Text == "Marcar Todos")
                {
                    btnMarcarCheckBox.Text = "Desmarcar Todos";
                }
                else
                {
                    btnMarcarCheckBox.Text = "Marcar Todos";
                }
            };

            GridListaProdutos.CellClick += (s, e) =>
            {
                if (GridListaProdutos.Columns[e.ColumnIndex].Name == "Selecione")
                {
                    if ((bool)GridListaProdutos.SelectedRows[0].Cells["Selecione"].Value == false)
                    {
                        GridListaProdutos.SelectedRows[0].Cells["Selecione"].Value = true;
                        AlterarImposto.Visible = true;
                    }
                    else
                    {
                        GridListaProdutos.SelectedRows[0].Cells["Selecione"].Value = false;

                        bool hideBtns = false;
                        foreach (DataGridViewRow item in GridListaProdutos.Rows)
                        {
                            if ((bool)item.Cells["Selecione"].Value == true)
                            {
                                hideBtns = true;
                            }
                        }

                        AlterarImposto.Visible = hideBtns;
                    }
                }
            };

            GridListaProdutos.CellMouseEnter += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = (s as DataGridView);
                if (GridListaProdutos.Columns[e.ColumnIndex].Name == "Selecione")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

            GridListaProdutos.CellMouseLeave += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = (s as DataGridView);
                if (GridListaProdutos.Columns[e.ColumnIndex].Name == "Selecione")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };
        }