Esempio n. 1
0
        public void Gravar(TB_CON_EMPRESA empresa, ref int posicaoTransacao)
        {
            try
            {
                Conexao.Iniciar(ref posicaoTransacao);

                var existente = Conexao.BancoDados.TB_CON_EMPRESAs.FirstOrDefault(a => a.ID_EMPRESA == empresa.ID_EMPRESA);
                if (existente == null)
                {
                    empresa.ID_EMPRESA = (Conexao.BancoDados.TB_CON_EMPRESAs.Any() ? Conexao.BancoDados.TB_CON_EMPRESAs.Max(a => a.ID_EMPRESA) : 0) + 1;
                    Conexao.BancoDados.TB_CON_EMPRESAs.InsertOnSubmit(empresa);
                }
                else
                {
                    existente.ID_CLIFOR  = empresa.ID_CLIFOR;
                    existente.ID_EMPRESA = empresa.ID_EMPRESA;
                    existente.ST_GOURMET = empresa.ST_GOURMET;
                }

                Conexao.Enviar();

                Conexao.Finalizar(ref posicaoTransacao);
            }
            catch (Exception excessao)
            {
                Conexao.Voltar(ref posicaoTransacao);
                throw excessao;
            }
        }
Esempio n. 2
0
        public override void Gravar()
        {
            try
            {
                Validar();

                empresa = new TB_CON_EMPRESA();

                empresa.ID_EMPRESA = teIdentificador.Text.ToInt32().Padrao();
                empresa.ID_CLIFOR  = beClifor.Text.Trim().ToInt32().Padrao();
                empresa.ST_GOURMET = ceGourmet.Checked;

                var posicaoTransacao = 0;
                new QEmpresa().Gravar(empresa, ref posicaoTransacao);

                base.Gravar();
            }
            catch (Exception excessao)
            {
                excessao.Validar();
            }
        }
Esempio n. 3
0
        public void Deletar(TB_CON_EMPRESA empresa, ref int posicaoTransacao)
        {
            try
            {
                Conexao.Iniciar(ref posicaoTransacao);

                var existente = Conexao.BancoDados.TB_CON_EMPRESAs.FirstOrDefault(a => a.ID_EMPRESA == empresa.ID_EMPRESA);
                if (existente != null)
                {
                    Conexao.BancoDados.TB_CON_EMPRESAs.DeleteOnSubmit(existente);
                }

                Conexao.Enviar();

                Conexao.Finalizar(ref posicaoTransacao);
            }
            catch (Exception excessao)
            {
                Conexao.Voltar(ref posicaoTransacao);
                throw excessao;
            }
        }
Esempio n. 4
0
        public FEmpresa_Cadastro()
        {
            InitializeComponent();

            this.Shown += delegate
            {
                try
                {
                    beClifor.ButtonClick += delegate
                    {
                        try
                        {
                            using (var filtro = new SYS.FORMS.FFiltro()
                            {
                                Consulta = Clifor(false),
                                Colunas = new List <SYS.FORMS.Coluna>()
                                {
                                    new SYS.FORMS.Coluna {
                                        Nome = "ID", Descricao = "Identificador do clifor", Tamanho = 100
                                    },
                                    new SYS.FORMS.Coluna {
                                        Nome = "NM", Descricao = "Nome do clifor", Tamanho = 350
                                    }
                                }
                            })
                            {
                                if (filtro.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    beClifor.Text = (filtro.Selecionados.FirstOrDefault().ID as int?).Padrao().ToString();
                                    teRazao.Text  = (filtro.Selecionados.FirstOrDefault().NM as string).Validar();
                                }
                            }
                        }
                        catch (Exception excessao)
                        {
                            excessao.Validar();
                        }
                    };
                    Action CliforLeave = delegate
                    {
                        try
                        {
                            var grupo = Clifor(true).FirstOrDefaultDynamic();

                            beClifor.Text = grupo != null ? (grupo.ID as int?).Padrao().ToString() : "";
                            teRazao.Text  = grupo != null ? (grupo.NM as string).Validar() : "";
                        }
                        catch (Exception excessao)
                        {
                            excessao.Validar();
                        }
                    };
                    beClifor.Leave += delegate { CliforLeave(); };

                    if (Modo == Modo.Cadastrar)
                    {
                        empresa = new TB_CON_EMPRESA();
                    }
                    else if (Modo == Modo.Alterar)
                    {
                        if (empresa == null)
                        {
                            Excessoes.Alterar();
                        }

                        teIdentificador.Text = empresa.ID_EMPRESA.ToString();
                        beClifor.Text        = empresa.ID_CLIFOR.ToString().Validar();
                        CliforLeave();
                        ceGourmet.Checked = empresa.ST_GOURMET.Padrao();// ?? false;
                    }
                }
                catch (Exception excessao)
                {
                    excessao.Validar();
                }
            };
        }