Exemplo n.º 1
0
 private void PreencherFicha(string pCd_produto)
 {
     //Buscar Ficha Formula
     CamadaDados.Estoque.Cadastros.TList_FichaTecProduto lFichaTec =
         CamadaNegocio.Estoque.Cadastros.TCN_FichaTecProduto.Buscar(pCd_produto, string.Empty, null);
     if (lFichaTec.Exists(p => string.IsNullOrEmpty(p.Cd_local)))
     {
         string vColunas = "a.ds_local|Local Armazenagem|150;" +
                           "a.cd_local|Código|50";
         string vParam = "|exists|(select 1 from tb_est_empresa_x_localarm x " +
                         "           where x.cd_local = a.cd_local and x.cd_empresa = '" + (bsItensOrcamento.Current as TRegistro_Orcamento_Item).Cd_empresa.Trim() + "')";
         DataRowView linha = FormBusca.UtilPesquisa.BTN_BUSCA(vColunas, null,
                                                              new CamadaDados.Estoque.Cadastros.TCD_CadLocalArm(), vParam);
         try
         {
             if (linha != null)
             {
                 lFichaTec.ForEach(p =>
                 {
                     p.Cd_local = string.IsNullOrEmpty(p.Cd_local) ? linha["cd_local"].ToString() : p.Cd_local;
                     CamadaNegocio.Estoque.Cadastros.TCN_FichaTecProduto.Gravar(p, null);
                 });
             }
             else
             {
                 PreencherFicha(pCd_produto);
             }
         }
         catch { }
     }
     lFichaTec.ForEach(p =>
     {
         (bsItensOrcamento.Current as TRegistro_Orcamento_Item).lFichaTec.Add(
             new TRegistro_FichaTecOrcItem()
         {
             Nr_orcamento    = (bsItensOrcamento.Current as TRegistro_Orcamento_Item).Nr_orcamento,
             Id_item         = (bsItensOrcamento.Current as TRegistro_Orcamento_Item).Id_item,
             Cd_item         = p.Cd_item,
             Ds_item         = p.Ds_item,
             Cd_local        = p.Cd_local,
             Ds_local        = p.Ds_local,
             Sg_unditem      = p.Sg_unditem,
             Cd_unditem      = p.Cd_unditem,
             Ds_unditem      = p.Ds_unditem,
             Quantidade      = p.Quantidade,
             SaldoEstoque    = TCN_LanEstoque.Busca_Saldo_Local((bsItensOrcamento.Current as TRegistro_Orcamento_Item).Cd_empresa, p.Cd_item, p.Cd_local, null),
             Vl_custo        = TCN_LanEstoque.BuscarVlEstoqueUltimaCompra((bsItensOrcamento.Current as TRegistro_Orcamento_Item).Cd_empresa, p.Cd_produto, null),
             Vl_ultimacompra = TCN_LanEstoque.BuscarVlUltimaCompra((bsItensOrcamento.Current as TRegistro_Orcamento_Item).Cd_empresa, p.Cd_produto, null)
         });
     });
     bsItensOrcamento.ResetCurrentItem();
 }