Example #1
0
        public void Deletar(TB_EST_PRODUTO produto, ref int posicaoTransacao)
        {
            try
            {
                Conexao.Iniciar(ref posicaoTransacao);

                var existente = Conexao.BancoDados.TB_EST_PRODUTOs.FirstOrDefault(a => a.ID_PRODUTO == produto.ID_PRODUTO);
                if (existente != null)
                {
                    existente.ST_ATIVO = false;
                }

                Conexao.Enviar();

                Conexao.Finalizar(ref posicaoTransacao);
            }
            catch (Exception excessao)
            {
                Conexao.Voltar(ref posicaoTransacao);
                throw excessao;
            }
        }
Example #2
0
        private void FProduto_Cadastro_Shown(object sender, EventArgs e)
        {
            try
            {
                // Seta os padrões para os componentes
                Padroes();

                if (Modo == Modo.Cadastrar)
                {
                    Produto = new TB_EST_PRODUTO();
                }
                else if (Modo == Modo.Alterar)
                {
                    if (Produto == null)
                    {
                        Excessoes.Alterar();
                    }

                    #region Aba "Detalhes"

                    teID_PRODUTO.Text = Produto.ID_PRODUTO.ToString();
                    teNM_PRODUTO.Text = Produto.NM.Validar();

                    beID_UNIDADE.Text = Produto.ID_UNIDADE.ToString();
                    beID_UNIDADE_Leave(null, null);

                    beID_GRUPO.Text = Produto.ID_GRUPO.ToString();
                    beID_GRUPO_Leave(null, null);

                    beID_MARCA.Text = Produto.ID_MARCA != null?Produto.ID_MARCA.ToString() : beID_MARCA.Text;

                    beID_MARCA_Leave(null, null);

                    beID_DEPARTAMENTO.Text = Produto.ID_DEPARTAMENTO != null?Produto.ID_DEPARTAMENTO.ToString() : beID_DEPARTAMENTO.Text;

                    beID_DEPARTAMENTO_Leave(null, null);

                    ceST_ALMOXARIFADO.Checked = Produto.ST_ALMOXARIFADO.Padrao();
                    ceST_FRACAO.Checked       = Produto.ST_FRACAO.Padrao();
                    ceST_COMPLEMENTO.Checked  = Produto.ST_COMPLEMENTO.Padrao();
                    ceST_SERVICO.Checked      = Produto.ST_SERVICO.Padrao();

                    #endregion

                    #region Aba "Fiscal"

                    #region Aba "Detalhes"

                    teFCI.Text      = Produto.ID_FCI.Padrao();
                    beID_NCM.Text   = Produto.ID_NCM.Padrao().ToString();
                    beID_CFOP.Text  = Produto.ID_CFOP.Padrao().ToString();
                    beID_CST.Text   = Produto.ID_CST.Padrao().ToString();
                    beID_CSOSN.Text = Produto.ID_CSOSN.Padrao().ToString();
                    beID_CE.Text    = Produto.ID_CLASSEENQUADRAMENTO.Padrao().ToString();
                    beID_E.Text     = Produto.ID_ENQUADRAMENTO.Padrao().ToString();

                    #endregion

                    #endregion

                    #region CODBARRA

                    teCodBarra.Text = Produto.TB_EST_PRODUTO_BARRAs.FirstOrDefault().ID_BARRA_REFERENCIA ?? "";

                    #endregion

                    // Aba gourmet
                    if (lcgGourmet.Visibility == LayoutVisibility.Always)
                    {
                        ceST_BALANCA.Checked = Produto.TB_GOU_PRODUTO != null ? (Produto.TB_GOU_PRODUTO.ST_BALANCA != null ? Produto.TB_GOU_PRODUTO.ST_BALANCA.Padrao() : false) : false;

                        beID_IMPRESSORA.Text = Produto.TB_GOU_PRODUTO != null ? (Produto.TB_GOU_PRODUTO.ID_IMPRESSORA != null ? Produto.TB_GOU_PRODUTO.TB_GOU_IMPRESSORA.ID_IMPRESSORA.ToString() : beID_IMPRESSORA.Text) : beID_IMPRESSORA.Text;
                        beID_IMPRESSORA_Leave(null, null);

                        //// Aba composição
                        //if (Produto.TB_GOU_PRODUTO != null && Produto.TB_GOU_PRODUTO.TB_GOU_COMPOSICAOs != null)
                        //    composicao = (from a in QQuery.BancoDados.TB_GOU_COMPOSICAOs
                        //                               join b in QQuery.BancoDados.TB_EST_PRODUTOs on a.ID_PRODUTO_COMPOSTO equals b.ID_PRODUTO
                        //                               where a.ID_PRODUTO == Produto.ID_PRODUTO
                        //                               select new QComposicao.MComposicao
                        //                               {
                        //                                   ID_PRODUTO = a.ID_PRODUTO_COMPOSTO,
                        //                                   NM = b.NM,
                        //                                   QT = a.QT ?? 0m
                        //                               }).ToList();


                        //// Aba complemento
                        //if (Produto.TB_GOU_PRODUTO != null && Produto.TB_GOU_PRODUTO.TB_GOU_PRODUTO_X_GRUPOs != null)
                        //    bsComplemento.DataSource = (from a in QQuery.BancoDados.TB_GOU_PRODUTO_X_GRUPOs
                        //                                where a.ID_PRODUTO == Produto.ID_PRODUTO
                        //                                select new SYS.QUERYS.Cadastros.Estoque.QGrupo.MGrupo
                        //                                {
                        //                                    ID_GRUPO = a.ID_GRUPO,
                        //                                    NM = a.TB_EST_GRUPO.NM
                        //                                }).ToList();
                    }
                }

                teNM_PRODUTO.Focus();
            }
            catch (Exception excessao)
            {
                excessao.Validar();
            }
        }
Example #3
0
        public void Gravar(TB_EST_PRODUTO produto, ref int posicaoTransacao)
        {
            try
            {
                Conexao.Iniciar(ref posicaoTransacao);

                var existente = Conexao.BancoDados.TB_EST_PRODUTOs.FirstOrDefault(a => a.ID_PRODUTO == produto.ID_PRODUTO);

                #region Inserção

                if (existente == null)
                {
                    produto.ID_PRODUTO = (Conexao.BancoDados.TB_EST_PRODUTOs.Any() ? Conexao.BancoDados.TB_EST_PRODUTOs.Max(a => a.ID_PRODUTO) : 0) + 1;
                    Conexao.BancoDados.TB_EST_PRODUTOs.InsertOnSubmit(produto);

                    foreach (var tributo in produto.TB_EST_PRODUTO_TRIBUTOs)
                    {
                        tributo.ID_PRODUTO = produto.ID_PRODUTO;
                        Conexao.BancoDados.TB_EST_PRODUTO_TRIBUTOs.InsertOnSubmit(tributo);
                        Conexao.Enviar();
                    }

                    foreach (var barra in produto.TB_EST_PRODUTO_BARRAs)
                    {
                        barra.ID_PRODUTO = produto.ID_PRODUTO;
                        barra.ID_BARRA   = (Conexao.BancoDados.TB_EST_PRODUTO_BARRAs.Where(a => a.ID_PRODUTO == produto.ID_PRODUTO).Any() ? Conexao.BancoDados.TB_EST_PRODUTO_BARRAs.Where(a => a.ID_PRODUTO == produto.ID_PRODUTO).Max(a => a.ID_BARRA) : 0) + 1;
                        Conexao.BancoDados.TB_EST_PRODUTO_BARRAs.InsertOnSubmit(barra);
                        Conexao.Enviar();
                    }

                    if (Parametros.ST_Gourmet)
                    {
                        var st_balanca    = produto.TB_GOU_PRODUTO.ST_BALANCA;
                        var id_impressora = produto.TB_GOU_PRODUTO.ID_IMPRESSORA;
                        produto.TB_GOU_PRODUTO            = new TB_GOU_PRODUTO();
                        produto.TB_GOU_PRODUTO.ID_PRODUTO = produto.ID_PRODUTO;
                        produto.TB_GOU_PRODUTO.ST_BALANCA = st_balanca;
                        if (id_impressora > 0)
                        {
                            produto.TB_GOU_PRODUTO.ID_IMPRESSORA = id_impressora;
                        }
                        Conexao.BancoDados.TB_GOU_PRODUTOs.InsertOnSubmit(produto.TB_GOU_PRODUTO);
                        Conexao.Enviar();

                        foreach (var complemento in produto.TB_GOU_PRODUTO.TB_GOU_PRODUTO_X_GRUPOs)
                        {
                            complemento.ID_PRODUTO = produto.ID_PRODUTO;
                            Conexao.BancoDados.TB_GOU_PRODUTO_X_GRUPOs.InsertOnSubmit(complemento);
                            Conexao.Enviar();
                        }

                        foreach (var composicao in produto.TB_GOU_PRODUTO.TB_GOU_COMPOSICAOs)
                        {
                            composicao.ID_PRODUTO = produto.ID_PRODUTO;
                            Conexao.BancoDados.TB_GOU_COMPOSICAOs.InsertOnSubmit(composicao);
                            Conexao.Enviar();
                        }
                    }
                }

                #endregion

                #region Atualização

                else
                {
                    existente.NM              = produto.NM;
                    existente.ID_UNIDADE      = produto.ID_UNIDADE;
                    existente.ID_GRUPO        = produto.ID_GRUPO;
                    existente.ID_MARCA        = produto.ID_MARCA;
                    existente.ID_DEPARTAMENTO = produto.ID_DEPARTAMENTO;
                    existente.ST_ALMOXARIFADO = produto.ST_ALMOXARIFADO;
                    existente.ST_FRACAO       = produto.ST_FRACAO;
                    existente.ST_COMPLEMENTO  = produto.ST_COMPLEMENTO;
                    existente.ST_SERVICO      = produto.ST_SERVICO;

                    existente.ID_FCI   = produto.ID_FCI;
                    existente.ID_NCM   = produto.ID_NCM;
                    existente.ID_CFOP  = produto.ID_CFOP;
                    existente.ID_CST   = produto.ID_CST;
                    existente.ID_CSOSN = produto.ID_CSOSN;
                    existente.ID_CLASSEENQUADRAMENTO = produto.ID_CLASSEENQUADRAMENTO;
                    existente.ID_ENQUADRAMENTO       = produto.ID_ENQUADRAMENTO;

                    var tributosDeletar = from a in Conexao.BancoDados.TB_EST_PRODUTO_TRIBUTOs
                                          where
                                          a.ID_PRODUTO == produto.ID_PRODUTO &&
                                          !produto.TB_EST_PRODUTO_TRIBUTOs.Select(b => b.ID_TRIBUTO).Contains(a.ID_TRIBUTO)
                                          select a;

                    if (tributosDeletar != null && tributosDeletar.Count() > 0)
                    {
                        Conexao.BancoDados.TB_EST_PRODUTO_TRIBUTOs.DeleteAllOnSubmit(tributosDeletar);
                        Conexao.Enviar();
                    }

                    var tributosCadastrar = from a in produto.TB_EST_PRODUTO_TRIBUTOs
                                            where Conexao.BancoDados.TB_EST_PRODUTO_TRIBUTOs.Where(b => b.ID_PRODUTO == produto.ID_PRODUTO).Select(b => b.ID_TRIBUTO).ToList().Contains(a.ID_TRIBUTO)
                                            select a;

                    if (tributosCadastrar != null && tributosCadastrar.Count() > 0)
                    {
                        Conexao.BancoDados.TB_EST_PRODUTO_TRIBUTOs.InsertAllOnSubmit(tributosCadastrar);
                        Conexao.Enviar();
                    }

                    var barrasDeletar = from a in Conexao.BancoDados.TB_EST_PRODUTO_BARRAs
                                        where
                                        a.ID_PRODUTO == produto.ID_PRODUTO &&
                                        !produto.TB_EST_PRODUTO_BARRAs.Select(b => b.ID_BARRA).Contains(a.ID_BARRA)
                                        select a;

                    if (barrasDeletar != null && barrasDeletar.Count() > 0)
                    {
                        Conexao.BancoDados.TB_EST_PRODUTO_BARRAs.DeleteAllOnSubmit(barrasDeletar);
                        Conexao.Enviar();
                    }

                    var barrasCadastrar = from a in produto.TB_EST_PRODUTO_BARRAs
                                          where Conexao.BancoDados.TB_EST_PRODUTO_BARRAs.Where(b => b.ID_PRODUTO == produto.ID_PRODUTO).Select(b => b.ID_BARRA).ToList().Contains(a.ID_BARRA)
                                          select a;

                    if (tributosCadastrar != null && tributosCadastrar.Count() > 0)
                    {
                        Conexao.BancoDados.TB_EST_PRODUTO_TRIBUTOs.InsertAllOnSubmit(tributosCadastrar);
                        Conexao.Enviar();
                    }

                    if (Parametros.ST_Gourmet)
                    {
                        var complementosDeletar = from a in Conexao.BancoDados.TB_GOU_PRODUTO_X_GRUPOs
                                                  where
                                                  a.ID_PRODUTO == produto.ID_PRODUTO &&
                                                  !produto.TB_GOU_PRODUTO.TB_GOU_PRODUTO_X_GRUPOs.Select(b => b.ID_GRUPO).Contains(a.ID_GRUPO)
                                                  select a;

                        if (complementosDeletar != null && complementosDeletar.Count() > 0)
                        {
                            Conexao.BancoDados.TB_GOU_PRODUTO_X_GRUPOs.DeleteAllOnSubmit(complementosDeletar);
                            Conexao.Enviar();
                        }

                        var complementosCadastrar = from a in produto.TB_GOU_PRODUTO.TB_GOU_PRODUTO_X_GRUPOs
                                                    where Conexao.BancoDados.TB_GOU_PRODUTO_X_GRUPOs.Where(b => b.ID_PRODUTO == produto.ID_PRODUTO).Select(b => b.ID_GRUPO).ToList().Contains(a.ID_GRUPO)
                                                    select a;

                        if (complementosCadastrar != null && complementosCadastrar.Count() > 0)
                        {
                            Conexao.BancoDados.TB_GOU_PRODUTO_X_GRUPOs.InsertAllOnSubmit(complementosCadastrar);
                            Conexao.Enviar();
                        }

                        var composicoesDeletar = from a in Conexao.BancoDados.TB_GOU_COMPOSICAOs
                                                 where
                                                 a.ID_PRODUTO == produto.ID_PRODUTO &&
                                                 !produto.TB_GOU_PRODUTO.TB_GOU_COMPOSICAOs.Select(b => b.ID_PRODUTO_COMPOSTO).Contains(a.ID_PRODUTO_COMPOSTO)
                                                 select a;

                        if (composicoesDeletar != null && composicoesDeletar.Count() > 0)
                        {
                            Conexao.BancoDados.TB_GOU_COMPOSICAOs.DeleteAllOnSubmit(composicoesDeletar);
                            Conexao.Enviar();
                        }

                        var composicoesCadastrar = from a in produto.TB_GOU_PRODUTO.TB_GOU_COMPOSICAOs
                                                   where Conexao.BancoDados.TB_GOU_COMPOSICAOs.Where(b => b.ID_PRODUTO == produto.ID_PRODUTO).Select(b => b.ID_PRODUTO_COMPOSTO).ToList().Contains(a.ID_PRODUTO_COMPOSTO)
                                                   select a;

                        if (composicoesCadastrar != null && composicoesCadastrar.Count() > 0)
                        {
                            Conexao.BancoDados.TB_GOU_COMPOSICAOs.InsertAllOnSubmit(composicoesCadastrar);
                            Conexao.Enviar();
                        }
                    }
                }

                #endregion

                Conexao.Enviar();

                Conexao.Finalizar(ref posicaoTransacao);
            }
            catch (Exception excessao)
            {
                Conexao.Voltar(ref posicaoTransacao);
                throw excessao;
            }
        }