public void Remover(ParametroDB parametro)
 {
     if (parametro != null)
     {
         sessao.Delete(parametro);
         sessao.Flush();
     }
 }
Esempio n. 2
0
 public static void clearAllStatic()
 {
     current      = new ParametroDB();
     Driver       = null;
     Host         = null;
     Port         = null;
     ServiceName  = null;
     User         = null;
     Password     = null;
     Trusted_Conn = null;
     Id           = null;
     Grupo        = 0;
     Token        = null;
 }
        private void salvaDB(ParametroDB paramdbNew)
        {
            var sessao      = AuxiliarNhibernate.AbrirSessao();
            var ParametroDB = new ParametroDB_DAO(sessao);
            var process     = new Processos();

            if (lastIndex != 0)
            {
                ParametroDB.Salvar(paramDB[lastIndex - 1]);
                refreshCBO(paramDB[lastIndex - 1], 1);
            }
            else
            {
                ParametroDB.Salvar(paramdbNew);
                refreshCBO(paramdbNew, 0);
            }
        }
 public void Atualizar(ParametroDB parametroCurrent, ParametroDB paramentroNew)
 {
     if (paramentroNew != null)
     {
         parametroCurrent.Driver       = paramentroNew.Driver;
         parametroCurrent.Host         = paramentroNew.Host;
         parametroCurrent.Port         = paramentroNew.Port;
         parametroCurrent.ServiceName  = paramentroNew.ServiceName;
         parametroCurrent.User         = paramentroNew.User;
         parametroCurrent.Password     = paramentroNew.Password;
         parametroCurrent.Trusted_Conn = paramentroNew.Trusted_Conn;
         parametroCurrent.Ativo        = paramentroNew.Ativo;
         parametroCurrent.Descr        = paramentroNew.Descr;
         parametroCurrent.Grupo        = paramentroNew.Grupo;
         parametroCurrent.Token        = paramentroNew.Token;
         sessao.Update(parametroCurrent);
         sessao.Flush();
     }
 }
        public void Salvar(ParametroDB parametro)
        {
            try
            {
                var param = BuscarPorID(Convert.ToInt64(parametro.Id));

                if (param.Driver != null)
                {
                    Atualizar(param, parametro);
                }
            }
            catch (Exception ex)
            {
                if (parametro != null)
                {
                    sessao.Save(parametro);
                    sessao.Flush();
                }
            }
        }
Esempio n. 6
0
        public static void Setcurrent(long?id)
        {
            foreach (var b in ListBanco)
            {
                if (id == b.Id)
                {
                    current = b;
                }
            }

            Processos process = new Processos();

            StaticParametersDB.SetDriver(current.Driver);
            StaticParametersDB.SetHost(current.Host);
            StaticParametersDB.SetPort(current.Port);
            StaticParametersDB.SetServiceName(current.ServiceName);
            StaticParametersDB.SetUser(current.User);
            StaticParametersDB.SetPassword(AESThenHMAC.SimpleDecryptWithPassword(current.Password, process.GetMacAdress()));
            StaticParametersDB.SetTrustedCon(current.Trusted_Conn);
            StaticParametersDB.SetId(current.Id.ToString());
            StaticParametersDB.SetGrupo(current.Grupo);
            StaticParametersDB.SetToken(current.Token);
        }
Esempio n. 7
0
 public static void SetListBanco(ParametroDB banco)
 {
     ListBanco.Add(banco);
 }
        private void BtnSalvar_Click(object sender, RoutedEventArgs e)
        {
            ParametroDB paramdbNew = new ParametroDB();
            Processos   proc       = new Processos();

            if (TxbHost.Text != "" && TxbPort.Text != "" && TxbServiceName.Text != "" && TxbUser.Text != "" && PwbSenha.Password != "" && CboDriver.SelectedIndex != -1 && CboConexao.SelectedIndex != -1 && TxbDescr.Text != "" && TxbGrupo.Text != "" && TxbToken.Text != "")
            {
                if (proc.VerificaConexaoBanco(TxbHost.Text, TxbPort.Text, TxbServiceName.Text, TxbUser.Text, PwbSenha.Password, (string)CboDriver.SelectedItem) == true)
                {
                    if (lastIndex != 0)
                    {
                        if (CboDriver.SelectedIndex == 0)
                        {
                            paramDB[lastIndex - 1].Driver = "oracle";
                        }
                        else
                        {
                            paramDB[lastIndex - 1].Driver = "sqlserver";
                        }
                        paramDB[lastIndex - 1].Descr        = TxbDescr.Text;
                        paramDB[lastIndex - 1].Host         = TxbHost.Text;
                        paramDB[lastIndex - 1].Port         = TxbPort.Text;
                        paramDB[lastIndex - 1].ServiceName  = TxbServiceName.Text;
                        paramDB[lastIndex - 1].User         = TxbUser.Text;
                        paramDB[lastIndex - 1].Password     = AESThenHMAC.SimpleEncryptWithPassword(PwbSenha.Password, proc.GetMacAdress());
                        paramDB[lastIndex - 1].Trusted_Conn = "True";
                        paramDB[lastIndex - 1].Token        = TxbToken.Text;
                        try
                        {
                            paramDB[lastIndex - 1].Grupo = Convert.ToInt64(TxbGrupo.Text);
                            salvaDB(paramDB[lastIndex - 1]);
                        }
                        catch (Exception error)
                        {
                            System.Windows.MessageBox.Show("Campo Grupo deve ser numerico", "Atenção", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (CboDriver.SelectedIndex == 0)
                        {
                            paramdbNew.Driver = "oracle";
                        }
                        else
                        {
                            paramdbNew.Driver = "sqlserver";
                        }
                        paramdbNew.Descr        = TxbDescr.Text;
                        paramdbNew.Host         = TxbHost.Text;
                        paramdbNew.Port         = TxbPort.Text;
                        paramdbNew.ServiceName  = TxbServiceName.Text;
                        paramdbNew.User         = TxbUser.Text;
                        paramdbNew.Password     = AESThenHMAC.SimpleEncryptWithPassword(PwbSenha.Password, proc.GetMacAdress());
                        paramdbNew.Trusted_Conn = "True";
                        paramdbNew.Token        = TxbToken.Text;
                        try
                        {
                            paramdbNew.Grupo = Convert.ToInt64(TxbGrupo.Text);
                            salvaDB(paramdbNew);
                        }
                        catch (Exception error)
                        {
                            System.Windows.MessageBox.Show("Campo Grupo deve ser numerico", "Atenção", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }

                    cleanScreen();
                    lastIndex = -1;
                }
                else if (proc.VerificaConexaoBanco(TxbHost.Text, TxbPort.Text, TxbServiceName.Text, TxbUser.Text, PwbSenha.Password, (string)CboDriver.SelectedItem, "False") == true)
                {
                    if (lastIndex != 0)
                    {
                        if (CboDriver.SelectedIndex == 0)
                        {
                            paramDB[lastIndex - 1].Driver = "oracle";
                        }
                        else
                        {
                            paramDB[lastIndex - 1].Driver = "sqlserver";
                        }
                        paramDB[lastIndex - 1].Descr        = TxbDescr.Text;
                        paramDB[lastIndex - 1].Host         = TxbHost.Text;
                        paramDB[lastIndex - 1].Port         = TxbPort.Text;
                        paramDB[lastIndex - 1].ServiceName  = TxbServiceName.Text;
                        paramDB[lastIndex - 1].User         = TxbUser.Text;
                        paramDB[lastIndex - 1].Password     = AESThenHMAC.SimpleEncryptWithPassword(PwbSenha.Password, proc.GetMacAdress());
                        paramDB[lastIndex - 1].Trusted_Conn = "False";
                        paramDB[lastIndex - 1].Token        = TxbToken.Text;
                        try
                        {
                            paramDB[lastIndex - 1].Grupo = Convert.ToInt64(TxbGrupo.Text);
                            salvaDB(paramDB[lastIndex - 1]);
                        }
                        catch (Exception error)
                        {
                            System.Windows.MessageBox.Show("Campo Grupo deve ser numerico", "Atenção", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (CboDriver.SelectedIndex == 0)
                        {
                            paramdbNew.Driver = "oracle";
                        }
                        else
                        {
                            paramdbNew.Driver = "sqlserver";
                        }
                        paramdbNew.Descr        = TxbDescr.Text;
                        paramdbNew.Host         = TxbHost.Text;
                        paramdbNew.Port         = TxbPort.Text;
                        paramdbNew.ServiceName  = TxbServiceName.Text;
                        paramdbNew.User         = TxbUser.Text;
                        paramdbNew.Password     = AESThenHMAC.SimpleEncryptWithPassword(PwbSenha.Password, proc.GetMacAdress());
                        paramdbNew.Trusted_Conn = "False";
                        StaticParametersDB.SetListBanco(paramdbNew);
                        paramdbNew.Token = TxbToken.Text;
                        try
                        {
                            paramdbNew.Grupo = Convert.ToInt64(TxbGrupo.Text);
                            salvaDB(paramdbNew);
                        }
                        catch (Exception error)
                        {
                            System.Windows.MessageBox.Show("Campo Grupo deve ser numerico", "Atenção", MessageBoxButton.OK, MessageBoxImage.Warning);
                            return;
                        }
                    }

                    cleanScreen();
                    lastIndex = -1;
                }
            }
            else
            {
                System.Windows.MessageBox.Show("Preencha todos os campos antes de continuar", "Atenção", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void refreshCBO(ParametroDB paramdbNew, int tipo)
        {
            BtnDelete.Visibility = Visibility.Hidden;
            BtnDelete.Visibility = Visibility.Hidden;
            if (tipo == 1)
            {
                try
                {
                    CboConexao.Items.Clear();
                    CboConexao.Items.Insert(0, "Nova conexão");
                    CboConexao.SelectedIndex = 0;

                    if (paramDB.Count > 1)
                    {
                        StaticParametersDB.clearListBanco();
                        foreach (var p in paramDB)
                        {
                            StaticParametersDB.SetListBanco(p);
                        }
                        for (int i = 0; i < paramDB.Count; i++)
                        {
                            CboConexao.Items.Insert(i + 1, paramDB[i].Descr);
                        }
                    }
                    else
                    {
                        StaticParametersDB.clearListBanco();
                        StaticParametersDB.SetListBanco(paramDB[0]);
                        CboConexao.Items.Insert(1, paramDB[0].Descr);
                    }
                }
                catch (Exception e)
                {
                }
            }
            else
            {
                try
                {
                    var process = new Processos();
                    paramDB.Add(paramdbNew);

                    CboConexao.Items.Clear();
                    CboConexao.Items.Insert(0, "Nova conexão");
                    CboConexao.SelectedIndex = 0;

                    if (paramDB.Count > 1)
                    {
                        StaticParametersDB.clearListBanco();
                        foreach (var p in paramDB)
                        {
                            StaticParametersDB.SetListBanco(p);
                        }
                        for (int i = 0; i < paramDB.Count; i++)
                        {
                            CboConexao.Items.Insert(i + 1, paramDB[i].Descr);
                        }
                    }
                    else
                    {
                        StaticParametersDB.clearListBanco();
                        StaticParametersDB.SetListBanco(paramDB[0]);
                        CboConexao.Items.Insert(1, paramDB[0].Descr);
                    }
                }
                catch (Exception e)
                {
                }
            }
        }