Example #1
0
        public static string DeletaLanInsumos(TRegistro_LanInsumos val, TObjetoBanco banco)
        {
            bool           pode_liberar = false;
            TCD_LanInsumos lanInsumo    = new TCD_LanInsumos();

            try
            {
                if (banco == null)
                {
                    lanInsumo.CriarBanco_Dados(true);
                    pode_liberar = true;
                    banco        = lanInsumo.Banco_Dados;
                }
                else
                {
                    lanInsumo.Banco_Dados = banco;
                }

                string retorno = "";

                TlistLanInsumos_X_Estoque listaEstoque = TCN_LanInsumos_X_Estoque.Busca(val.CD_Empresa, val.CD_Produto, 0, Convert.ToDecimal(val.ID_Lancto), 0, Convert.ToDecimal(val.ID_LanctoAtiv));

                if (listaEstoque != null && listaEstoque.Count > 0)
                {
                    if (val.ID_Requisicao <= 0 || val.ID_Requisicao == null)
                    {
                        //GRAVA O LANÇAMENTO EM ESTOQUE
                        TRegistro_LanEstoque reg_estoque = new TRegistro_LanEstoque();

                        reg_estoque.Cd_produto       = val.CD_Produto;
                        reg_estoque.Cd_local         = val.CD_Local;
                        reg_estoque.Id_lanctoestoque = listaEstoque[0].Id_LanctoEstoque;
                        reg_estoque.Qtd_saida        = val.Quantidade;
                        reg_estoque.Cd_empresa       = val.CD_Empresa;
                        reg_estoque.St_registro      = "C";
                        reg_estoque.Tp_movimento     = "S";

                        TCD_LanEstoque TCD_Estoque = new TCD_LanEstoque();
                        TCD_Estoque.Banco_Dados = banco;
                        string ret_estoque = TCD_Estoque.DeletaEstoque(reg_estoque);
                    }


                    //MANDA GRAVAR A INSUMO
                    TRegistro_LanInsumos_X_Estoque InsumoEstoque = new TRegistro_LanInsumos_X_Estoque();
                    InsumoEstoque.Id_Lancto     = Convert.ToDecimal(val.ID_Lancto);
                    InsumoEstoque.ID_LanctoAtiv = Convert.ToDecimal(val.ID_LanctoAtiv);
                    //GRAVA O LANÇAMENTO INSUMO X ESTOQUE
                    InsumoEstoque.Cd_Produto       = val.CD_Produto;
                    InsumoEstoque.Cd_Empresa       = val.CD_Empresa;
                    InsumoEstoque.Id_LanctoEstoque = listaEstoque[0].Id_LanctoEstoque;

                    TCD_LanInsumos_X_Estoque TCD_InsumoEstoque = new TCD_LanInsumos_X_Estoque();
                    TCD_InsumoEstoque.Banco_Dados = banco;
                    TCD_InsumoEstoque.DeletaLanInsumos_X_Estoque(InsumoEstoque);

                    retorno = lanInsumo.DeletaLanInsumos(val);
                }
                else
                {
                    throw new Exception("Não foi possível remover o insumo, por favor tente novamente!");
                }

                if (pode_liberar)
                {
                    lanInsumo.Banco_Dados.Commit_Tran();
                }
                return(retorno);
            }
            catch (Exception erro)
            {
                if (pode_liberar)
                {
                    lanInsumo.Banco_Dados.RollBack_Tran();
                }

                throw new Exception(erro.Message);
            }
            finally
            {
                if (pode_liberar)
                {
                    lanInsumo.deletarBanco_Dados();
                }
            }
        }
Example #2
0
        public static string DeletarEstoque(TRegistro_LanEstoque val, TObjetoBanco banco)
        {
            if (val.Cd_empresa.Trim().Equals(""))
            {
                throw new Exception("Campo Obrigatorio !\r\n" +
                                    "Campo: CD_Empresa\r\n" +
                                    "Método: DeletarEstoque\r\n" +
                                    "Classe: TCN_LanEstoque");
            }
            if (val.Cd_produto.Trim().Equals(""))
            {
                throw new Exception("Campo Obrigatorio !\r\n" +
                                    "Campo: CD_Produto\r\n" +
                                    "Método: DeletarEstoque\r\n" +
                                    "Classe: TCN_LanEstoque");
            }
            if (val.Id_lanctoestoque < 1)
            {
                throw new Exception("Campo Obrigatorio !\r\n" +
                                    "Campo: ID_LanctoEstoque\r\n" +
                                    "Método: DeletarEstoque\r\n" +
                                    "Classe: TCN_LanEstoque");
            }
            string         retorno      = string.Empty;
            bool           pode_liberar = false;
            TCD_LanEstoque qtb_estoque  = new TCD_LanEstoque();

            try
            {
                if (banco == null)
                {
                    pode_liberar = qtb_estoque.CriarBanco_Dados(true);
                }
                else
                {
                    qtb_estoque.Banco_Dados = banco;
                }

                retorno = qtb_estoque.DeletaEstoque(val);
                if (pode_liberar)
                {
                    qtb_estoque.Banco_Dados.Commit_Tran();
                }
                return(retorno);
            }
            catch
            {
                if (pode_liberar)
                {
                    qtb_estoque.Banco_Dados.RollBack_Tran();
                }
                return(string.Empty);
            }
            finally
            {
                if (pode_liberar)
                {
                    qtb_estoque.deletarBanco_Dados();
                }
            }
        }