private void ReplaceDBAgrupado(string tabelaAlterar, string campoAlterar, string schema = "neo")
    {
        try
        {
            YS.Dados.PostgreSQL.Data data = new YS.Dados.PostgreSQL.Data();
            data.Sql = $@"SELECT MAX({campoAlterar}) AS {campoAlterar} 
                            FROM {schema}.{tabelaAlterar} 
                            WHERE {campoAlterar} IS NOT NULL 
                            AND {campoAlterar} NOT LIKE '%[$%' 
                            GROUP BY {campoAlterar}";

            DataTable dt = data.GetDataTable();

            foreach (DataRow dr in dt.Rows)
            {
                var textoOriginal = dr[campoAlterar].ToString();

                var Chave = $"[${Normalize(textoOriginal)}$]";

                if (Chave == "[$$]")
                {
                    continue;
                }
                try
                {
                    data.Sql = @"INSERT INTO yoursales.globalizacao (
                                    glob_cultura, 
                                    glob_texto, 
                                    glob_chave
                                    ) VALUES (
                                    @glob_cultura, 
                                    @glob_texto, 
                                    @glob_chave)";

                    data.AddParameter("@glob_cultura", Culture);
                    data.AddParameter("@glob_texto", textoOriginal);
                    data.AddParameter("@glob_chave", Chave);
                    data.ExecuteQuery();
                }
                catch { }
                data.Sql = $@"UPDATE {schema}.{tabelaAlterar} 
                                SET {campoAlterar}=@chave 
                                WHERE {campoAlterar}=@id 
                                AND {campoAlterar} NOT LIKE '%[$%'";

                data.AddParameter("@chave", Chave);
                data.AddParameter("@id", dr[campoAlterar]);
                data.ExecuteQuery();
            }
        }
        catch (Exception er)
        {
            Response.Write(er);
            Response.Write("error");
        }
    }
Exemplo n.º 2
0
    private void EncontraArquivos(FileSystemInfo[] f)
    {
        if (f != null)
        {
            foreach (FileSystemInfo obj in f)
            {
                if (obj is DirectoryInfo)
                {
                    DirectoryInfo dinfo = (DirectoryInfo)obj;
                    EncontraArquivos(dinfo.GetFileSystemInfos());
                }
                else if (obj is FileInfo)
                {
                    try
                    {
                        Thread.Sleep(10);
                        string[] lines = System.IO.File.ReadAllLines(obj.FullName);

                        int nlinha = 0;
                        foreach (var line in lines)
                        {
                            nlinha++;

                            string patternForce = "<ccc>.*?<ccc>";
                            Regex  regexForce   = new Regex(patternForce, RegexOptions.None);

                            MatchCollection matches = regexForce.Matches(line);


                            foreach (Match match in matches)
                            {
                                if (match.Value.Contains("[$"))
                                {
                                    continue;
                                }
                                if (match.Value.Length == 0)
                                {
                                    continue;
                                }


                                string texto = match.Value.Replace("<ccc>", "");
                                texto = texto.Replace("<ccc>", "");

                                if (texto.Length == 0)
                                {
                                    continue;
                                }

                                var Chave = $"[${Normalize(texto)}$]";

                                try
                                {
                                    var linhas = File.ReadAllLines(obj.FullName);

                                    linhas[nlinha - 1] = linhas[nlinha - 1].Replace(match.Value, Chave);
                                    Response.Write(texto + " <br>");

                                    File.WriteAllLines(obj.FullName, linhas, UnicodeEncoding.GetEncoding(65001));

                                    YS.Dados.PostgreSQL.Data data = new YS.Dados.PostgreSQL.Data();

                                    data.Sql = @"INSERT INTO yoursales.globalizacao (
                                                    glob_cultura, 
                                                    glob_texto, 
                                                    glob_chave
                                                    ) VALUES (
                                                    @glob_cultura, 
                                                    @glob_texto, 
                                                    @glob_chave)";
                                    data.AddParameter("@glob_cultura", Culture);
                                    data.AddParameter("@glob_texto", texto);
                                    data.AddParameter("@glob_chave", Chave);
                                    data.ExecuteQuery();
                                    Response.Write("Success <br>");
                                }
                                catch (Exception er)
                                {
                                    Response.Write("Error <br>");
                                }
                            }
                        }
                    }
                    catch (Exception er)
                    {
                    }
                }
            }
        }
    }