using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using DAL; using System.Data.SqlClient; using CCH; namespace FFT { public class Utility { string dadosconexao = DadosDaConexao.StringDeConexao; //private variable private string folderDirectoy = "C:\\ibrCad\\"; private string folderDirectoyConfig = "C:\\ibrCad\\Config"; private string fileConfigDB = "C:\\ibrCad\\Config\\config.db"; private string fileConfigEmail = "C:\\ibrCad\\Config\\ServerEmail.ini"; private string filefolderlogsLogin = "C:\\ibrCad\\Logs\\logsLogin.ini"; //public variable public string FolderDirectoy { get => folderDirectoy; set => folderDirectoy = value; } public string FolderDirectoyConfig { get => folderDirectoyConfig; set => folderDirectoyConfig = value; } public string FileConfigDB { get => fileConfigDB; set => fileConfigDB = value; } public string FileConfigEmail { get => fileConfigEmail; set => fileConfigEmail = value; } public string FilefolderlogsLogin { get => filefolderlogsLogin; set => filefolderlogsLogin = value; } //verify folder public void verifyfolder(string folder) { bool vr = Directory.Exists(folder); if (vr == false) { Directory.CreateDirectory(folder); } else { return; } }//end verify folder public Boolean verifyfile(string fileConfigDB) { if(File.Exists(fileConfigDB)) { return true; } else { return false; } }//end verify fileconfigdb public Boolean createfiledbconfig(string folderconfig, string ipserver, string dbname, string usrdb, string pwd, bool rtn) { StreamWriter sw = new StreamWriter(FileConfigDB); sw.WriteLine(ipserver); sw.WriteLine(dbname); sw.WriteLine(usrdb); sw.WriteLine(pwd); sw.Close(); return rtn = true; } public void cleandata(string ipserv,string dbname,string userdb, string pwddb) { ipserv= string.Empty; dbname= string.Empty; userdb= string.Empty; pwddb= string.Empty; }//clean public Boolean verifyconectdatabase() { SqlConnection conn = new SqlConnection(dadosconexao); try { //conn.Open(); if(conn.State == System.Data.ConnectionState.Open) { //conn.Close(); return true; } else { // conn.Open(); return false; } } finally { conn.Close(); } }//end verifyconection public bool IsFileEmpty(string filePath) { // Verifica se o arquivo existe if (!File.Exists(filePath)) { //throw new FileNotFoundException("O arquivo não foi encontrado.", filePath); File.Create(filePath); } // Obtém o tamanho do arquivo FileInfo fileInfo = new FileInfo(filePath); long fileSize = fileInfo.Length; // Retorna verdadeiro se o tamanho do arquivo for 0, indicando que está vazio return fileSize == 0; }//end verify is file empty public void loadconfigdb(string folder) { if (File.Exists(folder)) { StreamReader sr = new StreamReader(folder); DadosDaConexao.servidor = sr.ReadLine(); DadosDaConexao.banco = sr.ReadLine(); DadosDaConexao.usuario = sr.ReadLine(); DadosDaConexao.senha = sr.ReadLine(); sr.Close(); } } public void ServerEmailConfigWrite(string folder,string senderMail, string password, string host,int port, Boolean ssl) { if (File.Exists(folder)) { StreamWriter sw =new StreamWriter(folder); sw.WriteLine(senderMail); sw.WriteLine(password); sw.WriteLine(host); sw.WriteLine(port); sw.WriteLine(ssl); sw.Close(); } }//end write config public void ServerEmailConfigReader(string folder) { if (File.Exists(folder)) { StreamReader sr = new StreamReader(folder); ServerEmailConfig.senderMail = sr.ReadLine(); ServerEmailConfig.password = sr.ReadLine(); ServerEmailConfig.host = sr.ReadLine(); ServerEmailConfig.port =Convert.ToInt32( sr.ReadLine()); ServerEmailConfig.ssl = Convert.ToBoolean(sr.ReadLine()); sr.Close(); } }//end reader config } }