private void BtnDelete_Click(object sender, RoutedEventArgs e) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Deseja prosseguir?", "Confirmação de exclusão", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { var sessao = AuxiliarNhibernate.AbrirSessao(); var paramdb = new ParametroDB_DAO(sessao); try { paramdb.Remover(paramDB[lastIndex - 1]); paramDB.RemoveAt(lastIndex - 1); if (paramDB.Count >= 1) { StaticParametersDB.clearListBanco(); foreach (var p in paramDB) { StaticParametersDB.SetListBanco(p); } StaticParametersDB.Setcurrent(paramDB[0].Id); refreshCBO(paramDB[0], 1); } else { StaticParametersDB.clearListBanco(); StaticParametersDB.clearAllStatic(); StaticParametros.SetIntegraBanco(false); BtnDelete.Visibility = Visibility.Hidden; CboConexao.Items.Clear(); CboConexao.Items.Insert(0, "Nova conexão"); CboConexao.SelectedIndex = 0; } cleanScreen(); } catch (Exception ex) { } //this.Close(); } }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (paramDB.Count >= 1) { StaticParametersDB.clearListBanco(); foreach (var p in paramDB) { StaticParametersDB.SetListBanco(p); } foreach (var p in paramDB) { if (p.Grupo == 0 || p.Token == null || p.Token == "") { __main.Show(); return; } } StaticParametersDB.Setcurrent(paramDB[0].Id); } __main.Show(); }
public void Init() { Processos process = new Processos(); DirectoryInfo dir = new DirectoryInfo(@"C:\\vch"); FileInfo fil = new FileInfo(@"C:\\vch\\dados.db"); int ctrlFirstExec = 0; if (dir.Exists != true) { ctrlFirstExec = 1; string user = System.Windows.Forms.SystemInformation.UserName; System.IO.DirectoryInfo folderInfo = new System.IO.DirectoryInfo("C:\\"); DirectorySecurity ds = new DirectorySecurity(); ds.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.Modify, AccessControlType.Allow)); ds.SetAccessRuleProtection(false, false); folderInfo.Create(ds); folderInfo.CreateSubdirectory("vch"); OrganizaTelaEvent(1); } if (fil.Exists != true) { try { AuxiliarNhibernate.AbrirSessao(); //fil.Create(); } catch (Exception e) { //System.Windows.Forms.MessageBox.Show(e.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (process.ReadPermissionFolder() == false || process.ReadPermissionFile() == false) { OrganizaTelaEvent(1); return; } var sessao = AuxiliarNhibernate.AbrirSessao(); Thread t = new Thread(process.VerificaParaAtualizar); t.Name = "UpdaterWorker"; t.Start(); if (ctrlFirstExec == 0) { var parametroDAO = new ParametroDAO(sessao); var param = parametroDAO.BuscarPorID(1);//Armazenamento.GetParametros(); int ctrl = 0; int ctrlVazio = 0; try { StaticParametros.SetGeraLogs(param.GeraLog); if (param.CaminhoToke.Contains(".ives") && param.CaminhoToke != "" && File.Exists(param.CaminhoToke)) { StaticParametros.SetDirToke(param.CaminhoToke); txtFolderToken.Text = param.CaminhoToke; DefineToken(param.CaminhoToke); ctrl++; } if (param.CaminhoDir != "") { if (Directory.Exists(param.CaminhoDir)) { txtFolderIni.Text = param.CaminhoDir; StaticParametros.SetDirOrigem(param.CaminhoDir); ctrl++; } } } catch (Exception ex) { //OrganizaTelaEvent(1); ctrlVazio = 1; } var parametroDBDAO = new ParametroDB_DAO(sessao); var paramDB = parametroDBDAO.BuscarTodos();//parametroDBDAO.BuscarPorID(1); //var paramDB = Armazenamento.GetParametrosDB(); try { if (paramDB.Count == 1) { StaticParametersDB.SetListBanco(paramDB[0]); if (paramDB[0].Grupo == 0 || paramDB[0].Token == null || paramDB[0].Token == "") { throw new Exception(); } else { StaticParametersDB.Setcurrent(paramDB[0].Id); } } else if (paramDB.Count > 1) { foreach (var p in paramDB) { StaticParametersDB.SetListBanco(p); } foreach (var p in paramDB) { if (p.Grupo == 0 || p.Token == null || p.Token == "") { throw new Exception(); } } StaticParametersDB.Setcurrent(paramDB[0].Id); } else { throw new Exception(); } StaticParametros.SetIntegraBanco(true); TxtStatusBanco.Text = "Conectado"; ctrl++; } catch (Exception ex) { StaticParametros.SetIntegraBanco(false); TxtStatusBanco.Text = "Desconectado"; if (ctrlVazio == 0) { var paramn = new Parametro { Id = 1, CaminhoDir = StaticParametros.GetDirOrigem(), CaminhoToke = StaticParametros.GetDirToke(), IntegraBanco = StaticParametros.GetIntegraBanco(), GeraLog = StaticParametros.GetGeraLogs() }; parametroDAO.Salvar(param); //Armazenamento.UpdateParametros(new Parametro { Id = 1, CaminhoDir = param.CaminhoDir, CaminhoToke = param.CaminhoToke, IntegraBanco = false }); } } if (ctrl >= 2) { try { if (txtFolderToken.Text == "") { OrganizaTelaEvent(1); } else { OrganizaTelaEvent(2); } //Job(); if (StaticParametros.GetDirOrigem() != null && StaticParametros.GetDirOrigem() != "") { process.CriarPastas(); } } catch (Exception ex) { OrganizaTelaEvent(1); } } else { Thread Tproc = new Thread(process.LimpaLog); Tproc.Start(); OrganizaTelaEvent(1); } } sessao.Close(); if (process.WritePermissionFolder() == false || process.WritePermissionFile() == false) { OrganizaTelaEvent(1); } }
public void Parametro() { var sessao = AuxiliarNhibernate.AbrirSessao(); var ParametroDAO = new ParametroDAO(sessao); var ParametroDBDAO = new ParametroDB_DAO(sessao); Processos process = new Processos(); StaticParametros.SetTipoApp("Service"); int ctrl = 0; try { var ret = ParametroDAO.BuscarPorID(1);//Armazenamento.GetParametros(); //var retdb = ParametroDBDAO.BuscarPorID(1); var retdb = ParametroDBDAO.BuscarTodos(); try { StaticParametros.SetGeraLogs(ret.GeraLog); if (File.Exists(ret.CaminhoToke)) { ctrl++; StaticParametros.SetDirToke(ret.CaminhoToke); if (DefineToken(StaticParametros.GetDirToke()) == false) { this.Stop(); } if (VerificaProcessoRun() == false) { Thread t = new Thread(process.VerificaParaAtualizar); t.Name = "UpdaterWorker"; t.Start(); } else { Log("Feche o integrador para iniciar o serviço.", 2); this.Stop(); } } } catch (Exception) { Log("Não foi possivel localizar as informações, por favor, abra o integrador e defina os parametros novamente.", 2); this.Stop(); } try { if (Directory.Exists(ret.CaminhoDir)) { ctrl++; StaticParametros.SetDirOrigem(ret.CaminhoDir); process.CriarPastas(); } } catch (Exception) { } try { if (retdb.Count == 1) { StaticParametersDB.SetListBanco(retdb[0]); if (retdb[0].Grupo == 0 || retdb[0].Token == null || retdb[0].Token == "") { throw new Exception(); } StaticParametersDB.Setcurrent(retdb[0].Id); } else if (retdb.Count > 1) { foreach (var p in retdb) { StaticParametersDB.SetListBanco(p); } foreach (var p in retdb) { if (p.Grupo == 0 || p.Token == null || p.Token == "") { throw new Exception(); } } StaticParametersDB.Setcurrent(retdb[0].Id); } else { throw new Exception(); } StaticParametros.SetIntegraBanco(true); ctrl++; } catch (Exception) { StaticParametros.SetIntegraBanco(false); } if (ctrl < 2) { Log("Não foi possivel localizar as informações, por favor, abra o integrador e defina os parametros novamente.", 2); this.Stop(); } } catch { StreamWriter vWriter = new StreamWriter(@"c:\vch\log\logServico.log", true); vWriter.WriteLine("--------------------------------------------------"); vWriter.WriteLine("Erro " + DateTime.Now.ToString()); vWriter.Flush(); vWriter.Close(); sessao.Close(); this.Stop(); } sessao.Close(); }
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) { } } }