private void CarregarDataGridComFiltros() { String grupos = "", nome_item = ""; long quantidade = 0; bool abaixo_do_minimo; Enumeradores.TipoComparador tipoOP = Enumeradores.TipoComparador.Nenhum; lblBarra.Text = "Aguarde... carregando as informações de estoque."; foreach (var item in lstGrupos.CheckedItems) { GrupoCheckedListBoxItem g = new GrupoCheckedListBoxItem(); g = (GrupoCheckedListBoxItem)item; grupos = grupos + g.Tag.ToString() + ","; } if (grupos.Length > 0) { grupos = grupos.Substring(0, grupos.Length - 1); } nome_item = txtLocalizarItensPorNome.Text; if (!txtQuantidadeEstoque.Text.Equals(String.Empty)) { quantidade = Convert.ToInt64(txtQuantidadeEstoque.Text); } abaixo_do_minimo = chkExibirItensAbaixoMinimo.Checked; if (rdoMaiorIgual.Checked) { tipoOP = Enumeradores.TipoComparador.Maior_que; } else if (rdoMenorIgual.Checked) { tipoOP = Enumeradores.TipoComparador.Menor_que; } else { tipoOP = Enumeradores.TipoComparador.Nenhum; } CarregarDataGrid(grupos, nome_item, tipoOP, quantidade, abaixo_do_minimo); CarregarNomeDaEmpresa(); }
private void CarregarDataGrid(String grupos_selecionados, String nome_item, Enumeradores.TipoComparador tpOP, long quantidade, bool abaixo_do_minimo) { try { DataGridViewImageColumn grdImg = new DataGridViewImageColumn(); //this.grdGerenciamento.RowEnter -= new DataGridViewCellEventHandler(grdGerenciamento_RowEnter); grdGerenciamento.Columns.Clear(); grdGerenciamento.DataSource = _reportDAO.ItensParaGerenciamento(grupos_selecionados, nome_item, tpOP, quantidade, abaixo_do_minimo); grdGerenciamento.SelectionMode = DataGridViewSelectionMode.FullRowSelect; grdGerenciamento.AllowUserToDeleteRows = false; grdGerenciamento.Columns["id"].Visible = false; grdGerenciamento.Columns["estoquebaixo"].Visible = false; grdGerenciamento.Columns["descricao"].Width = 300; grdGerenciamento.Columns["descricao"].HeaderText = "Nome do Item"; grdGerenciamento.Columns["tamanho"].Width = 80; grdGerenciamento.Columns["tamanho"].HeaderText = "Tamanho"; grdGerenciamento.Columns["grupo_descricao"].Width = 135; grdGerenciamento.Columns["grupo_descricao"].HeaderText = "Grupo"; grdGerenciamento.Columns["quantidade"].Width = 100; grdGerenciamento.Columns["quantidade"].HeaderText = "Estoque Atual"; grdGerenciamento.Columns["estoqueminimo"].Width = 100; grdGerenciamento.Columns["estoqueminimo"].HeaderText = "Estoque Mínimo"; grdImg = new DataGridViewImageColumn(); grdImg.Image = img.Images[0]; grdGerenciamento.Columns.Insert((int)ColunasDoGrid.Somar, grdImg); grdImg.HeaderText = "Somar"; grdImg.Name = "somar"; grdGerenciamento.Columns["somar"].Width = 70; grdImg = new DataGridViewImageColumn(); grdImg.Image = img.Images[1]; grdGerenciamento.Columns.Insert((int)ColunasDoGrid.Subtrair, grdImg); grdImg.HeaderText = "Subtrair"; grdImg.Name = "subtrair"; grdGerenciamento.Columns["subtrair"].Width = 70; grdImg = new DataGridViewImageColumn(); grdImg.Image = img.Images[2]; grdGerenciamento.Columns.Insert((int)ColunasDoGrid.Substituir, grdImg); grdImg.HeaderText = "Substituir"; grdImg.Name = "substituir"; grdGerenciamento.Columns["substituir"].Width = 70; grdGerenciamento.Columns["precocusto"].Width = 150; grdGerenciamento.Columns["precocusto"].HeaderText = "Preço de Custo"; grdGerenciamento.Columns["precovenda"].Width = 150; grdGerenciamento.Columns["precovenda"].HeaderText = "Preço de Venda"; // this.grdGerenciamento.RowEnter += new // DataGridViewCellEventHandler(grdGerenciamento_RowEnter); this.grdGerenciamento.Columns["quantidade"].DefaultCellStyle.Format = "#0"; this.grdGerenciamento.Columns["quantidade"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; this.grdGerenciamento.Columns["estoqueminimo"].DefaultCellStyle.Format = "#0"; this.grdGerenciamento.Columns["estoqueminimo"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; this.grdGerenciamento.Columns["tamanho"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; this.grdGerenciamento.Columns["precocusto"].DefaultCellStyle.Format = "c"; this.grdGerenciamento.Columns["precocusto"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; this.grdGerenciamento.Columns["precovenda"].DefaultCellStyle.Format = "c"; this.grdGerenciamento.Columns["precovenda"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; } catch (Exception ex) { MessageBox.Show(ex.Message, Principal.ActiveForm.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); lblBarra.Text = ""; } this.grdGerenciamento.ClearSelection(); }
public List <ItensParaGerenciamento> ItensParaGerenciamento(String grupos_selecionados, String nome_item, Enumeradores.TipoComparador tpOP, long quantidade, bool abaixo_do_minimo) { StringBuilder sql = new StringBuilder(); SqlDataReader sdr; SqlConnection con = new SqlConnection(); var result = new List <ItensParaGerenciamento>(); DataTable tabela = new DataTable(); try { using (_appConn = new AppDbConnection()) { sql.Append("select b.item_id, b.item_desc, "); sql.Append(String.Format(" b.item_tamanho, ")); //sql.Append(String.Format(" a.grupo_id, ")); sql.Append(String.Format(" a.grupo_desc, ")); sql.Append(String.Format(" b.item_qtd_atual, ")); sql.Append(String.Format(" b.item_estoque_minimo,")); sql.Append(String.Format(" b.item_preco_custo,")); sql.Append(String.Format(" b.item_preco_venda,")); sql.Append(String.Format(" case when b.item_qtd_atual <= b.item_estoque_minimo")); sql.Append(String.Format(" then 1 else 0 end as estoque_baixo")); sql.Append(String.Format(" from tab_grupo a inner join")); sql.Append(String.Format(" tab_item b on (a.grupo_id = b.grupo_id)")); sql.Append(String.Format(" where 1 = 1")); if (!grupos_selecionados.Equals(String.Empty)) { sql.Append(String.Format(" and a.grupo_id in ({0}) ", grupos_selecionados)); } if (!nome_item.Equals(String.Empty)) { sql.Append(String.Format(" and UPPER(b.item_desc) like '%{0}%' ", nome_item.ToUpper())); } if (!tpOP.Equals(Enumeradores.TipoComparador.Nenhum)) { if (tpOP.Equals(Enumeradores.TipoComparador.Maior_que)) { sql.Append(String.Format(" and b.item_qtd_atual >= {0} ", quantidade.ToString())); } if (tpOP.Equals(Enumeradores.TipoComparador.Menor_que)) { sql.Append(String.Format(" and b.item_qtd_atual <= {0} ", quantidade.ToString())); } } if (abaixo_do_minimo) { sql.Append(String.Format(" and b.item_qtd_atual <= b.item_estoque_minimo")); } sql.Append(String.Format(" order by a.grupo_desc, b.item_desc, b.item_qtd_atual")); sdr = _appConn.ExecuteQuery(sql.ToString()); while (sdr.Read()) { var item = new ItensParaGerenciamento { Id = Convert.ToInt32(sdr["item_id"].ToString()), Descricao = sdr["item_desc"].ToString(), Grupo_Descricao = sdr["grupo_desc"].ToString(), Quantidade = Convert.ToInt64(sdr["item_qtd_atual"].ToString()), EstoqueMinimo = Convert.ToInt64(sdr["item_estoque_minimo"].ToString()), Tamanho = sdr["item_tamanho"].ToString(), PrecoCusto = Convert.ToDouble(sdr["item_preco_custo"].ToString()), PrecoVenda = Convert.ToDouble(sdr["item_preco_venda"].ToString()), EstoqueBaixo = Convert.ToInt32(sdr["estoque_baixo"].ToString()) }; result.Add(item); } /*con = _appConn.Conexao(); * using (SqlCommand cmd = new SqlCommand(sql.ToString(), con)) * { * cmd.CommandType = CommandType.Text; * con.Open(); * tabela.Load(cmd.ExecuteReader()); * } * * return tabela;*/ } } catch (Exception) { throw; } return(result); }