0% found this document useful (0 votes)
23 views

Message

Uploaded by

leonardolab245
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Message

Uploaded by

leonardolab245
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

using Microsoft.

Win32;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using connectWeb;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
using System.Data.Odbc;
using Grafiki245Plus;

namespace connectWeb
{
public class Program
{
[DllImport("odbc32.dll")]
internal static extern int SQLDataSources(int EnvHandle, int Direction,
StringBuilder ServerName, int ServerNameBufferLenIn, ref int
ServerNameBufferLenOut, StringBuilder Driver, int DriverBufferLenIn, ref int
DriverBufferLenOut);

[DllImport("odbc32.dll")]
internal static extern int SQLAllocEnv(ref int EnvHandle);

static string[] arrayDataSources;


static string paginaInicial;
static List<string> listaDataSources;
static Dictionary<string, string> Entrada = new Dictionary<string,
string>();
static string[] argumentos;
/// <summary>
/// Ponto de entrada principal para o aplicativo.
/// </summary>
[STAThread]
static void Main(string[] args)
{

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());

//string path = AppDomain.CurrentDomain.BaseDirectory.ToString();


StreamWriter escritor = new StreamWriter("C:\\Program Files (x86)\\
Lab245\\Softwares\\ConnectManagerWeb\\" + "\\" + args[2].Replace(".\\", ""));
StreamWriter escritorLog = new StreamWriter("C:\\Program Files (x86)\\
Lab245\\Softwares\\ConnectManagerWeb\\log.txt");
//ConexaoDB conexaoDB = new ConexaoDB();
//conexaoDB.CarregaDados();
LePedido2();
escritorLog.WriteLine("C:\\Program Files(x86)\\Lab245\\Softwares\\
ConnectManagerWeb\\" + argumentos[0]);
//string processo = Entrada["processo"];

string processos = "";


//escritorLog.WriteLine($"{processo}");
escritorLog.Close();
switch (processos)
{
case "carregaPaginaInicial":
EscrevePaginaInicial();
escritor.WriteLine(paginaInicial);
escritor.Close();
break;

case "carregaBasesCriarTopico":

CarregaDataSources();
escritor.WriteLine(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML
1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""pt-BR""
lang=""pt-BR"">

<head>
<meta charset=""utf-8"" />
<meta http-equiv=""Content-Type"" content=""text/html""/>
<title>Connect Web - Bem Vindo!</title>
<style>

</style>
</head>

<body>
<select>");
foreach (var item in arrayDataSources)
{
escritor.WriteLine($"<option>{item}</option>");
}
escritor.WriteLine("</select></body></html>");
escritor.Close();

break;
}

/*CarregaDataSources();
foreach(string baseOdbc in arrayDataSources)
{
escritor.WriteLine($" < option value=opcao> {baseOdbc} </option>");
escritor.Close();
}*/

Application.Exit();
}
static void LePedido2()
{
try
{
StreamReader literal = new StreamReader("C:\\Program Files(x86)\\
Lab245\\Softwares\\ConnectManagerWeb\\" + argumentos[0].Replace(".\\", ""));
StreamWriter saida = new StreamWriter("C:\\Program Files(x86)\\
Lab245\\Softwares\\ConnectManagerWeb\\" + argumentos[2].Replace(".\\", ""));
StreamReader external = new StreamReader("C:\\Program Files(x86)\\
Lab245\\Softwares\\ConnectManagerWeb\\" + argumentos[1].Replace(".\\", ""));
//Read the first line of text
//TrataLog.EscreveLog("[LePedido.cs > LePedido2] Caminho do arquivo
de entrada: " + "C:\\Program Files(x86)\\Lab245\\Softwares\\ConnectManagerWeb\\" +
EstruturaDados.argumentos[0].Replace(".\\", ""), true);
//TrataLog.EscreveLog("[LePedido.cs > LePedido2] Caminho do arquivo
de saída: " + "C:\\Program Files(x86)\\Lab245\\Softwares\\ConnectManagerWeb\\" +
EstruturaDados.argumentos[2].Replace(".\\", ""), true);
//TrataLog.EscreveLog("[LePedido.cs > LePedido2] Caminho do arquivo
external: " + "C:\\Program Files(x86)\\Lab245\\Softwares\\ConnectManagerWeb\\" +
EstruturaDados.argumentos[1].Replace(".\\", ""), true);
string line2 = "";

string line = "";


line = literal.ReadLine();
line = literal.ReadLine();

//Continue to read until you reach end of file


while (line != null)
{
line = literal.ReadLine();
//TrataLog.EscreveLog("[LePedido.cs > LePedido2] Linhas do
arquivo de entrada: " + line, true);

}
string[] conteudo = File.ReadAllLines("C:\\Program Files(x86)\\
Lab245\\Softwares\\ConnectManagerWeb\\" + argumentos[0].Replace(".\\", ""));
string[] conteudoEx = File.ReadAllLines("C:\\Program Files(x86)\\
Lab245\\Softwares\\ConnectManagerWeb\\" + argumentos[1].Replace(".\\", ""));
bool controle = false;
bool controle2 = false;
for (int i = 0; i < conteudo.Length; i++)
{
if (conteudo[i] == "[Form Literal]")
{
controle = true;
}
if (conteudo[i].IndexOf('=') > 0 && controle)
{
string linha = conteudo[i].Split('=')[0].Trim().ToUpper();
string valor = conteudo[i].Split('=')[1].Trim();
Entrada.Add(linha, valor);
}
if (conteudo[i] == "[Form External]")
{
controle = false;
controle2 = true;
}
if (conteudo[i].IndexOf('=') > 0 && controle2)
{
for (int n = 0; n < conteudoEx.Length; n++)
{
line2 = external.ReadLine();
string linhaEx = conteudo[i].Split('=')
[0].Trim().ToUpper();
string valorEx = conteudoEx[n];
Entrada.Add(linhaEx, valorEx);
}
}
}
//Write a line of text
}
catch
{
}
}
static void EscrevePaginaInicial()
{
paginaInicial = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0
Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""pt-BR""
lang=""pt-BR"">

<head>
<meta charset=""utf-8"" />
<meta http-equiv=""Content-Type"" content=""text/html""/>
<title>Connect Web - Bem Vindo!</title>
<style>

</style>
</head>

<body>
<h1>Connect Web</h1>

<div>

<button>Criar/Editar Topico</button>
<button>Capture List</button>
<button>Magali Config</button>
<button>Magali Service</button>

</div>

<div>
<ul>
<li>
<div>
<p>Nome do Tópico:</p>
<input name=""txtNomeTopico"" type=""text"" />
</div>

<div>
<p>Base:</p>
<button class""btnMostraBase""
id=""btnMostrarBase"">...</button>
<form name=""formBaseSelecionada""
action=""/connectWeb245/connectWeb.dll"" target=""basesCriarTopico"">
<input type=""hidden"" name=""processo""
value=""carregaBasesCriarTopico"" />
</form>
<iframe id=""frmBasesDisponiveis""
name=""basesCriarTopico"" style=""height:200px;width: 200px;
display:none;""></iframe>
</div>
</li>
</ul>
</div>
<script>
let frmBasesDisponiveis =
document.getElementById(""frmBasesDisponiveis"");
let btnMostrarBase =
document.getElementById(""btnMostrarBase"");
btnMostrarBase.addEventListener('click', function (){
if(frmBasesDisponiveis.style.display === 'none')
{
frmBasesDisponiveis.style.display=""flex"";
document.formBaseSelecionada.submit();
}
else
{
frmBasesDisponiveis.style.display=""none"";
}
});
</script>
</body>
</html>";
}

static void CarregaDataSources()


{
arrayDataSources = new string[0];
listaDataSources = new List<string>();
// Defina a chave do registro da qual você deseja ler as subchaves
string registryKeyPath = @"SOFTWARE\Wow6432Node\ODBC\ODBC.INI";

using (RegistryKey key =


Registry.LocalMachine.OpenSubKey(registryKeyPath))
{
if (key != null)
{
try
{
// Obtenha as subchaves da chave do registro
string[] subKeys = key.GetSubKeyNames();

// Verifique se existem subchaves


if (subKeys.Length > 0)
{

// Itere sobre as subchaves e imprima seus nomes


foreach (string subKey in subKeys)
{
listaDataSources.Add(subKey);
}

arrayDataSources = listaDataSources.ToArray();
}
}
catch
{
return;
}
}
else
{
}
}

}
}

You might also like