Example #1
0
        private static void IncrementNumAcessos(int id)
        {
            BaseDados bd = new BaseDados();

            string sql     = @"SELECT n_acessos FROM login WHERE id = @1;";
            int    n_acess = bd.ExecNumberQuery(sql, id) + 1;

            sql = @"UPDATE login SET n_acessos = @2 WHERE id = @1;";
            bd.ExecNonQuery(sql, id, n_acess);
        }
Example #2
0
        public static void AtualizarBD()
        {
            try
            {
                if (String.IsNullOrEmpty(PathBackups))
                {
                    throw new ApplicationException("Caminho da pasta de backups em falta!");
                }

                if (String.IsNullOrEmpty(PathBackups))
                {
                    throw new ApplicationException("Caminho da pasta dos scripts em falta!");
                }

                if (!BackupBaseDados())
                {
                    throw new ApplicationException("Backup da base de dados nao foi feita!");
                }

                if (!HasAtualizacaoInDB())
                {
                    throw new ApplicationException("Não existe ou nao esta configurada a tabela de atualizacoes!");
                }



                BaseDados bd = new BaseDados();

                int VersaoRelease = -1;
                if (HasUpdates(out VersaoRelease))
                {
                    for (int i = VersaoRelease; i < (VersaoUpdate - VersaoRelease); i++)
                    {
                        UtilsEx.Log("Entrou no ciclo for. script n " + i);

                        string script = "\\" + string.Format(ScriptName, i);
                        string path   = PathScripts + script;

                        if (!File.Exists(path))
                        {
                            throw new ApplicationException("Script" + i + " não existe!");
                        }

                        try
                        {
                            string content = File.ReadAllText(path);
                            bd.ExecNonQuery(path);

                            UtilsEx.Log("Executou script n " + i);
                        }catch (Exception e)
                        {
                            UtilsEx.Log(e, "Erro ao executar: script" + i);
                            break;
                        }
                    }
                }
            }catch (Exception e)
            {
                UtilsEx.Log(e, "Erro ao fazer update da base de dados!");
            }
        }