Exemplo n.º 1
0
 private void Busca()
 {
     if (tcConsulta.SelectedTab.Equals(tpAnalitico))
     {
         string auxtpmov = string.Empty;
         string virg     = string.Empty;
         if (st_entrada.Checked)
         {
             auxtpmov = "'E'";
             virg     = ",";
         }
         if (st_saida.Checked)
         {
             auxtpmov += virg = "'S'";
             virg      = ",";
         }
         string auxtplancto = string.Empty;
         virg = string.Empty;
         if (cck_Normal.Checked)
         {
             auxtplancto = "'N'";
             virg        = ",";
         }
         if (cck_Provisao.Checked)
         {
             auxtplancto += virg + "'P'";
             virg         = ",";
         }
         if (cck_Manual.Checked)
         {
             auxtplancto += virg + "'M'";
             virg         = ",";
         }
         if (cck_Inventario.Checked)
         {
             auxtplancto += virg + "'I'";
             virg         = ",";
         }
         if (cck_Transferencia.Checked)
         {
             auxtplancto += virg + "'T'";
             virg         = ",";
         }
         if (cbCompDev.Checked)
         {
             auxtplancto += virg + "'L'";
             virg         = ",";
         }
         string auxstatus = string.Empty;
         if (st_ativo.Checked)
         {
             auxstatus = "'A'";
             virg      = ",";
         }
         if (st_cancelado.Checked)
         {
             auxstatus += virg + "'C'";
         }
         TList_RegLanEstoque lista = TCN_LanEstoque.Busca(cd_empresa.Text,
                                                          CD_Produto.Text,
                                                          cd_grupo.Text,
                                                          tp_produto.Text,
                                                          cd_marca.Text,
                                                          id_lanctoestoque.Text,
                                                          CD_Local.Text,
                                                          string.Empty,
                                                          auxtpmov,
                                                          auxtplancto,
                                                          DT_Inicial.Text,
                                                          DT_Final.Text,
                                                          auxstatus,
                                                          string.Empty,
                                                          string.Empty,
                                                          id_variedade.Text,
                                                          0,
                                                          string.Empty,
                                                          null);
         if ((lista != null) && (lista.Count > 0))
         {
             BS_Estoque.DataSource = lista;
         }
         else
         {
             BS_Estoque.Clear();
         }
     }
     else if (tcConsulta.SelectedTab.Equals(tpSintetico))
     {
         TpBusca[] filtro = new TpBusca[0];
         if (cd_empresa.Text.Trim() != string.Empty)
         {
             Array.Resize(ref filtro, filtro.Length + 1);
             filtro[filtro.Length - 1].vNM_Campo = "a.cd_empresa";
             filtro[filtro.Length - 1].vOperador = "=";
             filtro[filtro.Length - 1].vVL_Busca = "'" + cd_empresa.Text.Trim() + "'";
         }
         if (CD_Produto.Text.Trim() != string.Empty)
         {
             Array.Resize(ref filtro, filtro.Length + 1);
             filtro[filtro.Length - 1].vNM_Campo = "a.cd_produto";
             filtro[filtro.Length - 1].vOperador = "=";
             filtro[filtro.Length - 1].vVL_Busca = "'" + CD_Produto.Text.Trim() + "'";
         }
         if (cd_grupo.Text.Trim() != string.Empty)
         {
             Array.Resize(ref filtro, filtro.Length + 1);
             filtro[filtro.Length - 1].vNM_Campo = "b.cd_grupo";
             filtro[filtro.Length - 1].vOperador = "like";
             filtro[filtro.Length - 1].vVL_Busca = "'" + cd_grupo.Text.Trim() + "%'";
         }
         if (tp_produto.Text.Trim() != string.Empty)
         {
             Array.Resize(ref filtro, filtro.Length + 1);
             filtro[filtro.Length - 1].vNM_Campo = "b.tp_produto";
             filtro[filtro.Length - 1].vOperador = "=";
             filtro[filtro.Length - 1].vVL_Busca = "'" + tp_produto.Text.Trim() + "'";
         }
         if (cd_marca.Text.Trim() != string.Empty)
         {
             Array.Resize(ref filtro, filtro.Length + 1);
             filtro[filtro.Length - 1].vNM_Campo = "b.cd_marca";
             filtro[filtro.Length - 1].vOperador = "=";
             filtro[filtro.Length - 1].vVL_Busca = cd_marca.Text;
         }
         if (cbProdSaldoMinimo.Checked)
         {
             Array.Resize(ref filtro, filtro.Length + 1);
             filtro[filtro.Length - 1].vNM_Campo = string.Empty;
             filtro[filtro.Length - 1].vOperador = "exists";
             filtro[filtro.Length - 1].vVL_Busca = "(select 1 from TB_EST_Produto_QTDEstoque x " +
                                                   "where x.cd_produto = a.cd_produto " +
                                                   "and x.cd_empresa = a.cd_empresa " +
                                                   "and x.qt_min_estoque > a.tot_saldo) ";
         }
         if (cbItensSaldo.Checked)
         {
             Array.Resize(ref filtro, filtro.Length + 1);
             filtro[filtro.Length - 1].vNM_Campo = "a.Tot_Saldo";
             filtro[filtro.Length - 1].vOperador = ">";
             filtro[filtro.Length - 1].vVL_Busca = "0";
         }
         DataTable tb = new TCD_LanEstoque().BuscarEstoqueSintetico(filtro, string.Empty, "b.ds_produto");
         tb.Columns.Add(new DataColumn("saldo_futuro", typeof(decimal), "Tot_Saldo - Qtd_reservada"));
         bsSintetico.DataSource = tb;
         bsSintetico_PositionChanged(this, new EventArgs());
         //Buscar custo total do estoque
         tot_estoque.Text = TCN_LanEstoque.CustoTotalEstoque(string.IsNullOrEmpty(cd_empresa.Text) ? string.Empty : "'" + cd_empresa.Text.Trim() + "'", null).ToString("N2", new System.Globalization.CultureInfo("pt-BR", true));
     }
 }