public partial class Dashdoard : System.Web.UI.Page
{
#region SQL
String QUERY_INFORMACOES = @"
";
String QUERY_TAREFAS = @"
";
#endregion
protected void Page_Load(object sender, EventArgs e)
{
#region Associação de Eventos
gvTarefas.DirectEvents.Command.Event += new ComponentDirectEvent.DirectEventHandler(Command_EventRemoveTarefa);
btnSaveAddInformacoes.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(btnSaveAddInformacoes_Click);
btnDeleteInformacoes.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(Click_EventShowDeleteInformacoes);
btnDeleteSelectedInformacoes.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(Click_EventDeleteSelectedInformacoes);
btSaveAddTarefa.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(Click_EventAddTarefa);
btnAjuda.DirectEvents.Click.Event += new Ext.Net.ComponentDirectEvent.DirectEventHandler(Click_EventAjudaFavoritos);
#endregion
if (!Page.IsPostBack)
{
LoadTarefas();
LoadInformacoes();
LoadConsultas();
}
}
#region Tarefa
void Click_EventAddTarefa(object sender, DirectEventArgs e)
{
String INSERT_TAREFA = ...
if (tbDescricaoTarefa.Text != String.Empty && tbDataTarefa.Value != null && tbHoraTarefa.Value != null)
{
MXM.Connection.DBConnection dbConnection = new DBConnection((Session[0] as AmbienteList)[0]);
DbTransaction dbTransaction = dbConnection.Connection.BeginTransaction();
try
{
TimeSpan horaAux;
if (TimeSpan.TryParse(tbHoraTarefa.Text, out horaAux))
{
String insert = String.Format(INSERT_TAREFA,
(Session[0] as AmbienteList)[0].UserName,
tbDescricaoTarefa.Text,
String.Format("{0} {1}", Convert.ToDateTime(tbDataTarefa.Value).ToString("dd/MM/yyyy"), tbHoraTarefa.Text
), (cbAvisarTarefa.Checked ? 1 : 0)
);
dbConnection.ExecuteNonQuery(insert, dbTransaction);
dbTransaction.Commit();
}
else
{
Notification.Show(new NotificationConfig() { Html = "Formato de hora inválido." });
}
}
catch (Exception ex)
{
dbTransaction.Rollback();
throw ex;
}
finally
{
dbConnection.Connection.Close();
}
tbDescricaoTarefa.Text = String.Empty;
tbHoraTarefa.Text = String.Empty;
tbDataTarefa.Clear();
cbAvisarTarefa.Checked = false;
windowAddTarefa.Hide();
LoadTarefas();
}
else
{
Notification.Show(new NotificationConfig() { Html = "Todos os campos são obrigatórios" });
}
}
void Command_EventRemoveTarefa(object sender, DirectEventArgs e)
{
if (e.ExtraParams["command"] == "Remover")
{
String codigo = e.ExtraParams["codigo"];
MXM.Persistence.Persistence persist = new Persistence((Session[0] as AmbienteList)[0]);
try
{
persist.Delete(new Tarefa(Convert.ToDecimal(codigo)));
}
catch (Exception ex)
{
persist.Rollback();
throw ex;
}
finally
{
persist.Close();
}
LoadTarefas();
}
}
private void LoadTarefas()
{
AmbienteList ambList = Session[0] as AmbienteList;
MainConsult mainConsult = new MainConsult(ambList);
try
{
gvTarefasStore.SortInfo.Field = "DATA";
gvTarefasStore.SortInfo.Direction = Ext.Net.SortDirection.DESC;
gvTarefasStore.CustomConfig.Add(new ConfigItem("groupDir", "DESC", ParameterMode.Value));
DataTable dataTable = mainConsult.ExecSQLB(String.Format(QUERY_TAREFAS, ambList[0].UserName), "tarefas").Tables[0];
gvTarefasStore.DataSource = dataTable;
gvTarefasStore.DataBind();
gvTarefas.UpdateContent();
}
finally
{
mainConsult.CloseConnection();
}
}
#endregion
#region Informações
void Click_EventDeleteSelectedInformacoes(object sender, DirectEventArgs e)
{
Dictionary<String, String>[] selecionados = getSelectedDeleteInformacoes(e);
MXM.Persistence.Persistence persist = new Persistence((Session[0] as AmbienteList)[0]);
try
{
foreach (Dictionary<String, String> item in selecionados)
{
persist.Delete(new Rss(Convert.ToDecimal(item["MRSS_CODIGO"])));
}
}
catch (Exception ex)
{
persist.Rollback();
throw ex;
}
finally
{
persist.Close();
}
LoadGridDeleteInformacoes();
}
void btnSaveAddInformacoes_Click(object sender, DirectEventArgs e)
{
Rss rss = new Rss();
rss.Titulo = tbAddInfoTitulo.Text;
rss.Url = tbAddInfoUrl.Text;
rss.Usuario = (Session[0] as AmbienteList)[0].UserName;
MXM.Persistence.Persistence persist = new Persistence((Session[0] as AmbienteList)[0]);
try
{
persist.StartTransaction();
Rss auxRss = persist.GetObject(rss) as Rss;
if (auxRss == null)
persist.Save(rss);
persist.Commit();
//AddItemInformacoes(CreatePortLet(tbAddInfoTitulo.Text, tbAddInfoUrl.Text));
tbAddInfoTitulo.Text = String.Empty;
tbAddInfoUrl.Text = String.Empty;
}
catch (Exception ex)
{
persist.Rollback();
throw ex;
}
finally
{
persist.Close();
}
LoadInformacoes();
WindowAddInformacoes.Close();
}
private void LoadGridDeleteInformacoes()
{
AmbienteList ambList = Session[0] as AmbienteList;
MainConsult mainConsult = new MainConsult(ambList);
telaInformacoes.Items.Clear();
try
{
DataTable dataTable = mainConsult.ExecSQLB(String.Format(QUERY_INFORMACOES, ambList[0].UserName), "informações").Tables[0];
gvDeleteInformacoesStore.DataSource = dataTable;
gvDeleteInformacoesStore.DataBind();
}
finally
{
mainConsult.CloseConnection();
}
}
void Click_EventShowDeleteInformacoes(object sender, DirectEventArgs e)
{
LoadGridDeleteInformacoes();
windowDeleteInformacoes.Show();
}
private void LoadInformacoes()
{
AmbienteList ambList = Session[0] as AmbienteList;
MainConsult mainConsult = new MainConsult(ambList);
if (X.IsAjaxRequest)
{
informacoesColumn1.RemoveAll();
informacoesColumn2.RemoveAll();
informacoesColumn3.RemoveAll();
}
try
{
DataTable dataTable = mainConsult.ExecSQLB(String.Format(QUERY_INFORMACOES, ambList[0].UserName), "informações").Tables[0];
Int32 i = 0;
for (; i < dataTable.Rows.Count; i += 2)
{
Portlet portlet1 = CreatePortLet(dataTable.Rows[i]["MRSS_TITULO"].ToString(), dataTable.Rows[i]["MRSS_RSS"].ToString());
AddItemInformacoes(portlet1);
Portlet portlet2 = null;
if ((i + 1) < dataTable.Rows.Count)
{
portlet2 = CreatePortLet(dataTable.Rows[i + 1]["MRSS_TITULO"].ToString(), dataTable.Rows[i + 1]["MRSS_RSS"].ToString());
AddItemInformacoes(portlet2);
}
//telaInformacoes.Items.Add(CreateportalColumn(portlet1, portlet2));
}
//telaInformacoes.DoLayout();
}
finally
{
mainConsult.CloseConnection();
}
}
Int32 col1Items = 0;
Int32 col2Items = 0;
private void AddItemInformacoes(Portlet item)//, Boolean remove)
{
Boolean included = false;
if (!included)
{
if (X.IsAjaxRequest)
{
if (col1Items < 2)
{
item.AddTo(informacoesColumn1);
col1Items++;
}
else if (col2Items < 2)
{
item.AddTo(informacoesColumn2);
col2Items++;
}
else
{
item.AddTo(informacoesColumn3);
}
}
else
{
if (informacoesColumn1.Items.Count < 2)
{
informacoesColumn1.Items.Add(item);
}
else if (informacoesColumn2.Items.Count < 2)
{
informacoesColumn2.Items.Add(item);
}
else
{
informacoesColumn3.Items.Add(item);
}
}
}
}
private Dictionary<string, string>[] getSelectedDeleteInformacoes(DirectEventArgs e)
{
string json = e.ExtraParams["Values"];
return JSON.Deserialize<Dictionary<string, string>[]>(json);
}
#endregion
#region Consultas
private void LoadConsultas()
{
AmbienteList ambList = Session[0] as AmbienteList;
MainConsult mainConsult = new MainConsult(ambList);
telaConsultas.Items.Clear();
try
{
DataTable dataTable = mainConsult.ExecSQLB(String.Format(@"
SELECT MCN_CODIGO, MCN_TITULO
FROM MXS_CONSULTA_MCN,
MXS_USUARIOCONSULTA_MUC,
MXS_PERFILUSUARIO_MXPU
WHERE MCN_CODIGO = MUC_CONSULTA
AND MXPU_PERFILACESSO = MUC_PERFIL
AND MXPU_USUARIO = '{0}'
", ambList[0].UserName), "consultas").Tables[0];
for (Int32 i = 0; i < dataTable.Rows.Count; i += 2)
{
Portlet portlet1 = CreatePortLet(dataTable.Rows[i]["MCN_TITULO"].ToString(), "Consultas.aspx?CON=" + dataTable.Rows[i]["MCN_CODIGO"].ToString());
Portlet portlet2 = null;
if ((i + 1) < dataTable.Rows.Count)
portlet2 = CreatePortLet(dataTable.Rows[i + 1]["MCN_TITULO"].ToString(), "Consultas.aspx?CON=" + dataTable.Rows[i + 1]["MCN_CODIGO"].ToString());
telaConsultas.Items.Add(CreateportalColumn(portlet1, portlet2));
}
}
finally
{
mainConsult.CloseConnection();
}
}
#endregion
#region Favoritos
void Click_EventAjudaFavoritos(object sender, Ext.Net.DirectEventArgs e)
{
Ext.Net.Notification.Show(new Ext.Net.NotificationConfig()
{
Html = "Para adicionar ou remover favoritos utilize o menu ao lado do título na aba da tela",
Pinned = true,
Draggable = true,
Modal = true,
ShowPin = true,
AlignCfg = new NotificationAlignConfig()
{
ElementAnchor = AnchorPoint.Center,
TargetAnchor = AnchorPoint.Center
}
});
}
#endregion
#region Comum
private Portlet CreatePortLet(String title, String url)
{
Portlet portlet = new Portlet();
portlet.Title = title;
portlet.AutoHeight = true;
portlet.Frame = true;
portlet.AutoLoad.Url = url;
portlet.AutoLoad.ShowMask = true;
portlet.AutoLoad.Mode = LoadMode.IFrame;
portlet.AutoLoad.MaskMsg = "Carregando " + title + "...";
return portlet;
}
private PortalColumn CreateportalColumn(Portlet item1, Portlet item2)
{
PortalColumn portalColumn = new PortalColumn()
{
Layout = "Anchor",
AutoHeight = true,
StyleSpec = "padding:5px 0 5px 5px",
ColumnWidth = 0.33
};
portalColumn.Items.Add(item1);
if (item2 != null)
portalColumn.Items.Add(item2);
return portalColumn;
}
#endregion
}