using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DAL; using System.Data.SqlTypes; using System.IO; using System.Data.SqlClient; using FFT; using ENP; namespace IBRCAD { public partial class frm_configDB : Form { Utility ult = new Utility(); bool bRet; string fileconfigdb = ""; public frm_configDB() { InitializeComponent(); } private void btn_clean_data_Click(object sender, EventArgs e) { txt_ip_server1.Text = string.Empty; txt_nome_banco.Text = string.Empty; txt_nome_usrdb.Text = string.Empty; txt_pwd_db.Text = string.Empty; unlockedbtn(); }//limpar dados private void btn_save_con_Click(object sender, EventArgs e) { fileconfigdb = ult.FileConfigDB; bRet = ult.createfiledbconfig(fileconfigdb, txt_ip_server1.Text, txt_nome_banco.Text, txt_nome_usrdb.Text, txt_pwd_db.Text, bRet); if (bRet) { Encrypted.EncryptAndSaveToFileConfigDB(txt_ip_server1.Text, txt_nome_banco.Text, txt_nome_usrdb.Text, txt_pwd_db.Text, EndConfig.EncryptedDBfile,keys.KeyEncripted); MessageBox.Show("Configuração Salva com Sucesso!."); Application.Restart(); } } private void blkbtn() { txt_ip_server1.Enabled = false; txt_nome_banco.Enabled = false; txt_nome_usrdb.Enabled = false; txt_pwd_db.Enabled = false; }//end blkbtn private void unlockedbtn() { txt_ip_server1.Enabled = true; txt_nome_banco.Enabled = true; txt_nome_usrdb.Enabled = true; txt_pwd_db.Enabled = true; } private void btn_new_con_Click(object sender, EventArgs e) { unlockedbtn(); }//end new conection private void readerFileConfig() { this.descript(EndConfig.EncryptedDBfile, keys.KeyEncripted); //StreamReader sr = new StreamReader(fileconfigdb); //try //{ // txt_ip_server1.Text = sr.ReadLine(); // txt_nome_banco.Text = sr.ReadLine(); // txt_nome_usrdb.Text = sr.ReadLine(); // txt_pwd_db.Text = sr.ReadLine(); //} //finally //{ // sr.Close(); //} } private void frm_configDB_Load(object sender, EventArgs e) { Boolean fileVerify; fileconfigdb = ult.FileConfigDB; fileVerify = ult.verifyfile(EndConfig.EncryptedDBfile); if (fileVerify) { readerFileConfig(); blkbtn(); } else { MessageBox.Show("Arquivo de configuração do banco inexistente"); } }// private void btn_test_db_Click(object sender, EventArgs e) { try { DadosDaConexao.servidor = txt_ip_server1.Text; DadosDaConexao.banco = txt_nome_banco.Text; DadosDaConexao.usuario = txt_nome_usrdb.Text; DadosDaConexao.senha = txt_pwd_db.Text; SqlConnection cx = new SqlConnection(); cx.ConnectionString = DadosDaConexao.StringDeConexao; cx.Open(); cx.Close(); MessageBox.Show("Conexão efetuada com sucesso", "Conexão com banco de dados configurada", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (SqlException) { MessageBox.Show("Erro ao se conectar no banco de dados \n" + "Verifique os dados informados"); } catch (Exception erros) { MessageBox.Show(erros.Message); } }//end btn test conection private void descript(string inputFile, string key) { // Descriptografando o arquivo e lendo os dados string[] decryptedData = Encrypted.DecryptAndReadFromFileAll(inputFile, key); // Exibindo os dados nos TextBoxes if (decryptedData.Length >= 0) { DadosDaConexao.servidor = decryptedData[0]; DadosDaConexao.banco = decryptedData[1]; DadosDaConexao.usuario = decryptedData[2]; DadosDaConexao.senha= decryptedData[3]; txt_ip_server1.Text = DadosDaConexao.servidor; txt_nome_banco.Text = DadosDaConexao.banco; txt_nome_usrdb.Text = DadosDaConexao.usuario; txt_pwd_db.Text = DadosDaConexao.senha; txt_pwd_db.PasswordChar = '*'; } else { txt_ip_server1.Text = "0"; txt_nome_banco.Text = "ibr"; txt_nome_usrdb.Text = "sa"; txt_pwd_db.Text = ""; } } } }