public DBContext(DbContextOptions <DBContext> options) : base(options) { //this.Configuration.LazyLoadingEnabled = false; if (!Categoria.Any()) { Categoria.Add(new Categoria("Banco de Dados", "Perguntas relacionados com banco de dados")); Categoria.Add(new Categoria("Linguagem de programação", "Perguntas sobre as mais diversas linguagens de programação")); Categoria.Add(new Categoria("IoT", "Perguntas sobre sensores, automação e internet")); Categoria.Add(new Categoria("WEB", "Perguntas sobre desenvolvimento WEB")); SaveChanges(); } }
private void Eventos() { workerBackground.DoWork += (s, e) => GridLista.Invoke((MethodInvoker)LoadProdutos); workerBackground.RunWorkerCompleted += (s, e) => { label2.Visible = false; pictureBox2.Visible = false; GridLista.Visible = true; }; Shown += (s, e) => { Refresh(); AutoCompleteItens(); pictureBox2.Visible = true; var cat = new Categoria().FindAll().Where("tipo", "Produtos").WhereFalse("excluir").OrderByDesc("nome").Get(); if (cat.Any()) { Categorias.DataSource = cat; Categorias.DisplayMember = "NOME"; Categorias.ValueMember = "ID"; } Medidas.DataSource = Support.GetMedidas(); if (ImportarNfe.optionSelected == 1) { BuscarProduto.Visible = false; label10.Visible = false; pictureBox4.Visible = false; btnVincular.Visible = false; label9.Text = @"Edite o produto selecionado abaixo"; } pictureBox2.Visible = true; GridLista.Visible = false; workerBackground.RunWorkerAsync(); }; btnVincular.Click += (s, e) => VincularProduto(); GridLista.CellClick += (s, e) => { BuscarProduto.Enabled = true; if (GridLista.Columns[e.ColumnIndex].Name == "Editar") { VincularProduto(true); GridLista.Enabled = false; } if (GridLista.Columns[e.ColumnIndex].Name == "Importar") { GridLista.SelectedRows[0].Cells["Importar"].Value = (bool)GridLista.SelectedRows[0].Cells["Importar"].Value == false; } }; GridLista.CellMouseEnter += (s, e) => { if (e.ColumnIndex < 0 || e.RowIndex < 0) { return; } var dataGridView = s as DataGridView; if (GridLista.Columns[e.ColumnIndex].Name == "Importar" || GridLista.Columns[e.ColumnIndex].Name == "Editar") { 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 == "Importar" || GridLista.Columns[e.ColumnIndex].Name == "Editar") { dataGridView.Cursor = Cursors.Default; } }; btnSalvarVinculacao.Click += (s, e) => { SalvarProduto(); if (ImportarNfe.optionSelected != 1) { label10.Visible = true; pictureBox4.Visible = true; BuscarProduto.Visible = true; btnVincular.Visible = true; label9.Text = @"Vincular a produtos existentes"; panelVinculacao.Location = new Point(34, 517); } panelVinculacao.Visible = false; }; btnImportar.Click += (s, e) => { produtos.Clear(); var i = -1; foreach (DataGridViewRow item in GridLista.Rows) { i++; if ((bool)item.Cells["Importar"].Value) { var id = Validation.ConvertToInt32(item.Cells["IDVINCULO"].Value); double estoque = 0; var codeBarras = item.Cells["Cód. de Barras"].Value.ToString(); var id_sync = 0; if (!string.IsNullOrEmpty(codeBarras)) { var _mItem = new Item(); _mItem = _mItem.Query().Select("*").Where("codebarras", codeBarras).Where("excluir", 0) .FirstOrDefault <Item>(); if (_mItem != null) { id = _mItem.Id; estoque = _mItem.EstoqueAtual; id_sync = _mItem.id_sync; } } //estoque = Validation.ConvertToDouble(item.Cells[6].Value) + estoque; switch (ImportarNfe.optionSelected) { case 1: estoque = 0; break; case 3: //estoque = Validation.ConvertToDouble(item.Cells[6].Value) + estoque; break; } produtos.Add(new { Ordem = i, Id = id, Referencia = item.Cells["Referência"].Value.ToString(), CodeBarras = item.Cells["Cód. de Barras"].Value.ToString(), Nome = item.Cells["Descrição"].Value.ToString(), Medida = item.Cells["Medida"].Value.ToString(), Estoque = estoque, CategoriaId = Validation.ConvertToInt32(item.Cells["CATEGORIAID"].Value), ValorCompra = Validation.ConvertToDouble(item.Cells["Vlr. Compra"].Value), ValorVenda = Validation.ConvertToDouble(item.Cells["Vlr. Venda"].Value), Fornecedor = item.Cells["Fornecedor"].Value.ToString(), NCM = item.Cells["NCM"].Value.ToString(), idSync = id_sync, EstoqueCompra = Validation.ConvertToDouble(item.Cells[6].Value) }); } } if (ImportarNfe.optionSelected == 3) { OpenForm.Show <ImportarPagamentos>(this); } else { OpenForm.Show <ImportarProdutosConcluido>(this); } }; valorcompra.TextChanged += (s, e) => { var txt = (TextBox)s; Masks.MaskPrice(ref txt); }; valorvenda.TextChanged += (s, e) => { var txt = (TextBox)s; Masks.MaskPrice(ref txt); Validation.WarningInput(txt, warning); }; btnMarcarCheckBox.Click += (s, e) => { foreach (DataGridViewRow item in GridLista.Rows) { if (btnMarcarCheckBox.Text == @"Marcar Todos") { if ((bool)item.Cells["Importar"].Value == false) { item.Cells["Importar"].Value = true; } } else { item.Cells["Importar"].Value = false; } } btnMarcarCheckBox.Text = btnMarcarCheckBox.Text == @"Marcar Todos" ? @"Desmarcar Todos" : @"Marcar Todos"; }; BuscarProduto.KeyDown += (s, e) => { if (e.KeyCode != Keys.Enter) { return; } if (!string.IsNullOrEmpty(BuscarProduto.Text)) { var item = _mItem.FindById(collection.Lookup(BuscarProduto.Text)).FirstOrDefault <Item>(); if (item != null) { BuscarProduto.Text = item.Nome; } ModalItens(); return; } if (string.IsNullOrEmpty(BuscarProduto.Text)) { ModalItens(); } else { VincularProduto(); } }; Back.Click += (s, e) => Close(); }