using System; using System.Collections.Generic; using System.Web; using MySQL; using System.Data; using System.Web.Configuration; using System.Web.UI.WebControls; namespace Intranet { /// /// Tratamento de Agenda /// public class Agenda { /// /// Listagem de eventos da agenda ainda por terminarem /// /// Número da página a mostrar /// DataTable public static DataTable Listagem(int Pagina) { DataTable dtInfo = new DataTable(); int offset = Convert.ToInt16(WebConfigurationManager.AppSettings["offset"].ToString()); sql sqlInfo = new sql(WebConfigurationManager.ConnectionStrings["Site"].ConnectionString); sqlInfo.Query = "SELECT a.id, " + " a.createuser, a.createdep, a.createdata, " + " a.edituser, a.editdep, a.editdata, " + " a.activo, " + " DATE_FORMAT(a.data_ini, '%Y.%m.%d %H:%i') AS data_ini, " + " DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i') AS data_fim, " + " a.actividade, a.local, a.descricao, " + " c.nome AS colaborador, c.abreviatura AS colaborador_abreviatura, " + " d.nome AS departamento, d.abreviatura AS departamento_abreviatura " + "FROM agenda a, colaborador c, departamento d " + "WHERE c.id=a.createuser " + " AND d.id=a.createdep " + " AND DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i')>DATE_FORMAT(now(), '%Y.%m.%d %H:%i') " + "ORDER BY a.data_ini, a.data_fim, a.actividade, a.local " + "LIMIT " + (Pagina * offset) + ", " + offset; dtInfo = sqlInfo.Read(); sqlInfo.closeConnection(); return dtInfo; } /// /// Retorna todas as actividades na agenda num detarminado mês. /// /// Ano da actividade /// Mês da actividade /// /// Retorna todas as actividades na agenda num detarminado mês. /// public static DataTable Listagem(int Ano, int Mes) { DataTable dtInfo = new DataTable(); sql sqlInfo = new sql(WebConfigurationManager.ConnectionStrings["Site"].ConnectionString); sqlInfo.Query = "SELECT a.id, " + " a.createuser, a.createdep, a.createdata, " + " a.edituser, a.editdep, a.editdata, " + " a.activo, " + " DATE_FORMAT(a.data_ini, '%Y.%m.%d %H:%i') AS data_ini, " + " DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i') AS data_fim, " + " a.actividade, a.local, a.descricao, " + " c.nome AS colaborador, c.abreviatura AS colaborador_abreviatura, " + " d.nome AS departamento, d.abreviatura AS departamento_abreviatura " + "FROM agenda a, colaborador c, departamento d " + "WHERE c.id=a.createuser " + " AND d.id=a.createdep " + " AND DATE_FORMAT(a.data_ini, '%Y.%m')=DATE_FORMAT('" + Ano + "." + Mes + ".1', '%Y.%m') " + " AND a.activo=1 " + "ORDER BY a.data_ini, a.data_fim, a.actividade, a.local"; dtInfo = sqlInfo.Read(); sqlInfo.closeConnection(); return dtInfo; } /// /// Retorna todas as actividades na agenda num detarminado dia. /// /// ID da peça. /// Ano da actividade /// Mês da actividade /// Dia da actividade /// /// Retorna todas as actividades na agenda num detarminado dia. /// public static DataTable Listagem(int Ano, int Mes, int Dia) { DataTable dtInfo = new DataTable(); sql sqlInfo = new sql(WebConfigurationManager.ConnectionStrings["Site"].ConnectionString); sqlInfo.Query = "SELECT a.id, " + " a.createuser, a.createdep, a.createdata, " + " a.edituser, a.editdep, a.editdata, " + " a.activo, " + " DATE_FORMAT(a.data_ini, '%Y.%m.%d %H:%i') AS data_ini, " + " DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i') AS data_fim, " + " a.actividade, a.local, a.descricao, " + " c.nome AS colaborador, c.abreviatura AS colaborador_abreviatura, " + " d.nome AS departamento, d.abreviatura AS departamento_abreviatura " + "FROM agenda a, colaborador c, departamento d " + "WHERE c.id=a.createuser " + " AND d.id=a.createdep " + " AND DATE_FORMAT(a.data_ini, '%Y.%c.%e')=DATE_FORMAT('" + Ano + "." + Mes + "." + Dia + "', '%Y.%c.%e') " + " AND a.activo=1 " + "ORDER BY a.data_ini, a.data_fim, a.actividade, a.local"; dtInfo = sqlInfo.Read(); sqlInfo.closeConnection(); return dtInfo; } /// /// Pesquisa de eventos /// /// DataTable public static DataTable Pesquisa(string Pesquisa) { DataTable dtInfo = new DataTable(); sql sqlInfo = new sql(WebConfigurationManager.ConnectionStrings["Site"].ConnectionString); /* sqlInfo.Query = "SELECT a.id, " + " a.createuser, a.createdep, a.createdata, " + " a.edituser, a.editdep, a.editdata, " + " a.activo, " + " DATE_FORMAT(a.data_ini, '%Y.%m.%d %H:%i') AS data_ini, " + " DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i') AS data_fim, " + " a.actividade, a.local, a.descricao, " + " c.nome AS colaborador, c.abreviatura AS colaborador_abreviatura, " + " d.nome AS departamento, d.abreviatura AS departamento_abreviatura " + "FROM agenda a, colaborador c, departamento d " + "WHERE c.id=a.createuser " + " AND d.id=a.createdep " + " AND DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i')>DATE_FORMAT(now(), '%Y.%m.%d %H:%i') " + " AND (a.data_ini LIKE '%" + Pesquisa + "%' " + " OR a.data_fim LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(a.data_ini, '%Y.%m.%d') LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(a.data_fim, '%Y.%m.%d') LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(a.data_ini, '%H:%i') LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(a.data_fim, '%H:%i') LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(a.data_ini, '%Y.%m.%d %H:%i') LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i') LIKE '%" + Pesquisa + "%' " + " OR a.actividade LIKE '%" + Pesquisa + "%' " + " OR a.local LIKE '%" + Pesquisa + "%' " + " OR a.descricao LIKE '%" + Pesquisa + "%' " + " OR c.nome LIKE '%" + Pesquisa + "%' " + " OR c.nomecompleto LIKE '%" + Pesquisa + "%' " + " OR c.abreviatura LIKE '%" + Pesquisa + "%' " + " OR c.foto LIKE '%" + Pesquisa + "%' " + " OR c.numero LIKE '%" + Pesquisa + "%' " + " OR c.identificacao LIKE '%" + Pesquisa + "%' " + " OR c.contribuinte LIKE '%" + Pesquisa + "%' " + " OR c.niss LIKE '%" + Pesquisa + "%' " + " OR c.nib LIKE '%" + Pesquisa + "%' " + " OR c.banco LIKE '%" + Pesquisa + "%' " + " OR c.morada1 LIKE '%" + Pesquisa + "%' " + " OR c.morada2 LIKE '%" + Pesquisa + "%' " + " OR c.codigopostal LIKE '%" + Pesquisa + "%' " + " OR c.localidade LIKE '%" + Pesquisa + "%' " + " OR c.telefone LIKE '%" + Pesquisa + "%' " + " OR c.telemovel LIKE '%" + Pesquisa + "%' " + " OR c.estadocivil LIKE '%" + Pesquisa + "%' " + " OR c.ndependentes LIKE '%" + Pesquisa + "%' " + " OR c.habilitacoes LIKE '%" + Pesquisa + "%' " + " OR c.funcao LIKE '%" + Pesquisa + "%' " + " OR c.data_admissao LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(c.data_admissao, '%Y.%m.%d') LIKE '%" + Pesquisa + "%' " + " OR c.observacao LIKE '%" + Pesquisa + "%' " + " OR c.login LIKE '%" + Pesquisa + "%' " + " OR c.perfil LIKE '%" + Pesquisa + "%' " + " OR c.email LIKE '%" + Pesquisa + "%' " + " OR c.data_nascimento LIKE '%" + Pesquisa + "%' " + " OR DATE_FORMAT(c.data_nascimento, '%Y.%m.%d') LIKE '%" + Pesquisa + "%' " + " OR c.ip LIKE '%" + Pesquisa + "%' " + " OR c.extensao LIKE '%" + Pesquisa + "%' " + " OR c.sessiontime LIKE '%" + Pesquisa + "%' " + " OR d.nome LIKE '%" + Pesquisa + "%' " + " OR d.abreviatura LIKE '%" + Pesquisa + "%' " + " OR d.email LIKE '%" + Pesquisa + "%') " + "ORDER BY a.data_ini, a.data_fim, a.actividade, a.local"; */ sqlInfo.Query = "SELECT a.id, " + " a.createuser, a.createdep, a.createdata, " + " a.edituser, a.editdep, a.editdata, " + " a.activo, " + " DATE_FORMAT(a.data_ini, '%Y.%m.%d %H:%i') AS data_ini, " + " DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i') AS data_fim, " + " a.actividade, a.local, a.descricao, " + " c.nome AS colaborador, c.abreviatura AS colaborador_abreviatura, " + " d.nome AS departamento, d.abreviatura AS departamento_abreviatura, " + " a.*, c.*, d.* " + "FROM agenda a, colaborador c, departamento d " + "WHERE c.id=a.createuser " + " AND d.id=a.createdep " + " AND DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i')>DATE_FORMAT(now(), '%Y.%m.%d %H:%i') " + "ORDER BY a.data_ini, a.data_fim, a.actividade, a.local"; dtInfo = sqlInfo.Read(); sqlInfo.closeConnection(); /* #1 - CONVERTE A PESQUISA NUM ARRAY EM QUE CADA POSIÇÃO CONTEM UM PARALVRA */ string[] _pesquisa = Pesquisa.Split(new char[] { ' ' }); /* #2 - PESQUISA TODAS AS OCURRÊNCIAS DE _pesquisa EM dtInfo. REMOVE DE dtInfo TODAS AS LINHAS QUE NÃO TENHAM PELO MENOS UMA OCURRÊNCIA */ Intranet.Geral.Pesquisa(ref dtInfo, _pesquisa); return dtInfo; } /// /// Mostra o detalhe de uma actividade da agenda /// /// Id do conteúdo a mostrar /// DataTable public static DataTable Detalhes(int Id) { DataTable dtInfo = new DataTable(); sql sqlInfo = new sql(WebConfigurationManager.ConnectionStrings["Site"].ConnectionString); sqlInfo.Query = "SELECT a.id, " + " a.createuser, a.createdep, a.createdata, " + " a.edituser, a.editdep, a.editdata, " + " a.activo, " + " DATE_FORMAT(a.data_ini, '%Y.%m.%d %H:%i') AS data_ini, " + " DATE_FORMAT(a.data_fim, '%Y.%m.%d %H:%i') AS data_fim, " + " a.actividade, a.local, a.descricao, " + " c.nome AS colaborador, c.abreviatura AS colaborador_abreviatura, " + " d.nome AS departamento, d.abreviatura AS departamento_abreviatura " + "FROM agenda a, colaborador c, departamento d " + "WHERE a.id=" + Id + " " + " AND c.id=a.createuser " + " AND d.id=a.createdep"; dtInfo = sqlInfo.Read(); sqlInfo.closeConnection(); return dtInfo; } /// /// Novo evento /// /// /// Data e hora de início /// Data e hora de fim /// Local do evento /// Descrição do evento /// Activo/Inactivo (1/0) /// Id de quem cria o conteúdo /// Departamento de quem cria o conteúdo /// True ou False public static Boolean Gravar(string Actividade, string Inicio, string Fim, string Local, string Descricao, int Activo, int CreateUser, int CreateDep) { bool gravado = false; sql sqlInfo = new sql(WebConfigurationManager.ConnectionStrings["Site"].ConnectionString); sqlInfo.Query = "INSERT INTO agenda(actividade, data_ini, data_fim, local, descricao, activo, createuser, createdep, createdata) " + "VALUES ('" + Actividade + "'," + " '" + Inicio + "'," + " '" + Fim + "'," + " '" + Local + "'," + " '" + Descricao + "'," + " " + Activo + " ," + " " + CreateUser + " ," + " " + CreateDep + " ," + " now())"; gravado = sqlInfo.Write(); sqlInfo.closeConnection(); return gravado; } /// /// Editar agenda /// /// Id do conteúdo a editar /// Data e hora de início /// Data e hora de fim /// Local do evento /// Descrição do evento /// Activo/Inactivo (1/0) /// Id de quem cria o conteúdo /// Departamento de quem cria o conteúdo /// True ou False public static Boolean Editar(int Id, string Actividade, string Inicio, string Fim, string Local, string Descricao, int Activo, int EditUser, int EditDep) { bool editado = false; sql sqlInfo = new sql(WebConfigurationManager.ConnectionStrings["Site"].ConnectionString); sqlInfo.Query = "UPDATE agenda " + "SET actividade='" + Actividade + "'," + " data_ini='" + Inicio + "'," + " data_fim='" + Fim + "'," + " local='" + Local + "'," + " descricao='" + Descricao + "'," + " activo=" + Activo + "," + " edituser=" + EditUser + "," + " editdep=" + EditDep + "," + " editdata=now() " + "WHERE id=" + Id; editado = sqlInfo.Write(); sqlInfo.closeConnection(); return editado; } } }