예제 #1
0
 private void Search()
 {
     ItensTemp = Itens.ToList();
     Itens.Clear();
     foreach (var item in ItensTemp.Where(x => x.english_name.StartsWith(char.ToUpper(SearchField[0]) + SearchField.Substring(1))))
     {
         Itens.Add(item);
     }
 }
 public void Limpar()
 {
     Itens.Clear();
 }
예제 #3
0
        private void Eventos()
        {
            KeyDown   += KeyDowns;
            KeyPreview = true;
            Masks.SetToUpper(this);

            Shown += (s, e) =>
            {
                txtQtdItens.Text = @"0";
                txtValor.Text    = @"R$ 00,00";

                SetHeadersTableItens(GridLista);
                SetHeadersTableSelecionados(GridListaSelecionados);
                LoadItens();
            };

            txtDinheiro.KeyPress += (s, e) => Masks.MaskDouble(s, e);

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

                var troco = Validation.ConvertToDouble(txtDinheiro.Text) -
                            Validation.ConvertToDouble(txtValor.Text.Replace("R$ ", ""));
                label6.Text = Validation.FormatPrice(troco, true);
            };

            btnContinuar.Click += (s, e) =>
            {
                Itens.Clear();

                if (GridLista.Rows.Count > 0)
                {
                    foreach (DataGridViewRow row in GridLista.Rows)
                    {
                        Itens.Add(new
                        {
                            Id         = row.Cells[0].Value,
                            CProd      = row.Cells[1].Value,
                            xProd      = row.Cells[2].Value,
                            Quantidade = row.Cells[3].Value,
                            Total      = Validation.ConvertToDouble(row.Cells[4].Value.ToString().Replace("R$ ", ""))
                        });
                    }
                }

                DialogResult = DialogResult.OK;
                Close();
            };

            #region Table Itens

            GridLista.CellClick += (s, e) =>
            {
                if (GridLista.Columns[e.ColumnIndex].Name == "Dividir")
                {
                    ModalDividirValor.Valor = Validation.ConvertToDouble(GridLista.SelectedRows[0].Cells["Valor"].Value
                                                                         .ToString().Replace("R$ ", ""));
                    var form = new ModalDividirValor {
                        TopMost = true
                    };
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        GridListaSelecionados.Rows.Add(
                            GridLista.SelectedRows[0].Cells["ID"].Value,
                            GridLista.SelectedRows[0].Cells["Referência"].Value,
                            GridLista.SelectedRows[0].Cells["Item"].Value,
                            GridLista.SelectedRows[0].Cells["Qtd."].Value,
                            Validation.FormatPrice(ModalDividirValor.ValorDivido, true),
                            Resources.error20x
                            );

                        RefreshTotal();

                        if (ModalDividirValor.ValorRestante <= 0)
                        {
                            GridLista.Rows.RemoveAt(e.RowIndex);
                        }
                        else
                        {
                            GridLista.Rows[e.RowIndex].Cells[4].Value =
                                Validation.FormatPrice(ModalDividirValor.ValorRestante, true);
                        }

                        Alert.Message("Pronto", "Item adicionado.", Alert.AlertType.success);
                    }
                }

                if (GridLista.Columns[e.ColumnIndex].Name == "Adicionar")
                {
                    GridListaSelecionados.Rows.Add(
                        GridLista.SelectedRows[0].Cells["ID"].Value,
                        GridLista.SelectedRows[0].Cells["Referência"].Value,
                        GridLista.SelectedRows[0].Cells["Item"].Value,
                        GridLista.SelectedRows[0].Cells["Qtd."].Value,
                        GridLista.SelectedRows[0].Cells["Valor"].Value,
                        Resources.error20x
                        );

                    RefreshTotal();

                    GridLista.Rows.RemoveAt(e.RowIndex);

                    Alert.Message("Pronto", "Item adicionado.", Alert.AlertType.success);
                }
            };

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

                var dataGridView = s as DataGridView;
                if (GridLista.Columns[e.ColumnIndex].Name == "Adicionar" ||
                    GridLista.Columns[e.ColumnIndex].Name == "Dividir")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

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

                var dataGridView = s as DataGridView;
                if (GridLista.Columns[e.ColumnIndex].Name == "Adicionar" ||
                    GridLista.Columns[e.ColumnIndex].Name == "Dividir")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };

            #endregion

            #region Itens Selecionados

            GridListaSelecionados.CellClick += (s, e) =>
            {
                if (GridListaSelecionados.Columns[e.ColumnIndex].Name == "Remover")
                {
                    var notFound = true;
                    foreach (DataGridViewRow row in GridLista.Rows)
                    {
                        if (row.Cells[0].Value.ToString() ==
                            GridListaSelecionados.Rows[e.RowIndex].Cells[0].Value.ToString())
                        {
                            var valor    = Validation.ConvertToDouble(row.Cells[4].Value.ToString().Replace("R$ ", ""));
                            var addValor = Validation.ConvertToDouble(GridListaSelecionados.Rows[e.RowIndex].Cells[4]
                                                                      .Value.ToString().Replace("R$ ", ""));
                            row.Cells[4].Value = Validation.FormatPrice(valor + addValor, true);
                            notFound           = false;
                            break;
                        }
                    }

                    if (notFound)
                    {
                        GridLista.Rows.Add(
                            GridListaSelecionados.SelectedRows[0].Cells["ID"].Value,
                            GridListaSelecionados.SelectedRows[0].Cells["Referência"].Value,
                            GridListaSelecionados.SelectedRows[0].Cells["Item"].Value,
                            GridListaSelecionados.SelectedRows[0].Cells["Qtd."].Value,
                            GridListaSelecionados.SelectedRows[0].Cells["Valor"].Value,
                            Resources.divide20x,
                            Resources.plus20x
                            );
                    }

                    GridListaSelecionados.Rows.RemoveAt(e.RowIndex);

                    RefreshTotal();
                }
            };

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

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

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

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

            #endregion
        }