protected void gridAptosPagamento_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string param = Request.Params["__CALLBACKPARAM"];

            if (param.Contains("|CUSTOMCALLBACK") || param.Contains("|PAGERONCLICK") || param.Contains("|SORT") || param.Contains("|COLUMNMOVE") || param.Contains("|EXPANDROW") || param.Contains("|COLLAPSEROW") || param.Contains("|SHOWDETAILROW"))
            {

                Control.AgendaPagamentos.Dados obj = new Control.AgendaPagamentos.Dados();

                string envolvido = string.Empty;
                string undOrc = string.Empty;
                DateTime dataIni = DateTime.MinValue;
                DateTime dataFim = DateTime.MaxValue;
                string procNumero = string.Empty;
                string empenho = string.Empty;

                if (cbbEnvolvido.Value != null) envolvido = cbbEnvolvido.Value.ToString();
                if (cbbUndOrc.Value != null) undOrc = cbbUndOrc.Value.ToString();
                if (dtCadastroIni.Value != null) dataIni = dtCadastroIni.Date;
                if (dtCadastroFim.Value != null) dataFim = dtCadastroFim.Date;
                if (txtProcessoNumero.Value != null) procNumero = txtProcessoNumero.Value.ToString();
                if (txtEmpenho.Value != null) empenho = txtEmpenho.Value.ToString();

                DataTable dt = obj.gridAptoPagamento(envolvido, undOrc, dataIni, dataFim, procNumero, empenho);
                gridAptosPagamento.DataSource = dt;
                gridAptosPagamento.DataBind();
                Session["GRIDAPTOSPAGAMENTO"]=  dt;
            }
        }
        protected void gridAptosPagamento_Init(object sender, EventArgs e)
        {
            if (Page.IsCallback)
            {
                string param = Request.Params["__CALLBACKPARAM"];
                string target = Request.Form["__EVENTTARGET"];

                if (!param.Contains("|CUSTOMCALLBACK") && !param.Contains("CBCF") && !param.Contains("|ROWVALUES"))
                {
                    Control.AgendaPagamentos.Dados obj = new Control.AgendaPagamentos.Dados();

                    string  envolvido   = string.Empty;
                    string undOrc       = string.Empty;
                    DateTime dataIni    = DateTime.MinValue;
                    DateTime dataFim    = DateTime.MaxValue;
                    string procNumero   = string.Empty;
                    string empenho      = string.Empty;

                    if (cbbEnvolvido.Value != null) envolvido = cbbEnvolvido.Value.ToString();
                    if (cbbUndOrc.Value != null) undOrc = cbbUndOrc.Value.ToString();
                    if (dtCadastroIni.Value != null) dataIni = dtCadastroIni.Date;
                    if (dtCadastroFim.Value != null) dataFim = dtCadastroFim.Date;
                    if (txtProcessoNumero.Value != null) procNumero = txtProcessoNumero.Value.ToString();
                    if (txtEmpenho.Value != null) empenho = txtEmpenho.Value.ToString();

                    gridAptosPagamento.DataSource = obj.gridAptoPagamento(envolvido, undOrc, dataIni, dataFim, procNumero, empenho);
                    gridAptosPagamento.DataBind();
                }
            }
        }
        protected void gridAgendados_Init(object sender, EventArgs e)
        {
            if (IsCallback)
            {
                string param = Request.Params["__CALLBACKPARAM"];

                if (param.Contains("|PAGERONCLICK") || param.Contains("|SORT") || param.Contains("|COLUMNMOVE") || param.Contains("|EXPANDROW") || param.Contains("|COLLAPSEROW") || param.Contains("|SHOWDETAILROW") || param.Contains("|FILTERPOPUP") || param.Contains("|NEXTPAGE"))
                {
                    Control.AgendaPagamentos.Dados obj = new Control.AgendaPagamentos.Dados();

                    string envolvido = string.Empty;
                    string undOrc = string.Empty;
                    DateTime dataIni = DateTime.MinValue;
                    DateTime dataFim = DateTime.MaxValue;

                    if (cbbEnvolvidoAgendado.Value != null) envolvido = cbbEnvolvidoAgendado.Value.ToString();
                    if (cbbUndOrcAgendado.Value != null) undOrc = cbbUndOrcAgendado.Value.ToString();
                    if (dtCadastroIniAgendado.Date != null) dataIni = dtCadastroIniAgendado.Date;
                    if (dtCadastroFimAgendado.Date != null) dataFim = dtCadastroFimAgendado.Date;

                    var tableAgendados = obj.gridAgendados(envolvido, undOrc, dataIni, dataFim);
                    Session["GRIDAGENDADOS"] = tableAgendados;
                    gridAgendados.DataSource = tableAgendados;
                    gridAgendados.DataBind();
                }
            }
        }
        protected void callbackAgendarPagamentos_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
        {
            string idUsuario  = hdfDadosUsuario["IDUSUARIO"].ToString();

            Control.AgendaPagamentos ag = new Control.AgendaPagamentos();

            ag.dataAgenda = DateTime.Parse(dtAgendamento.Date.ToString());
            ag.IDUsuario = int.Parse(idUsuario);
            ag.processos = txtProcessos.Text ;
            decimal valor = 0;

            if (txtValorAgendamento.Value != null)
            {
                if (Convert.ToInt16(txtProcessosQtde.Value) > 1)
                {
                    valor = 0;
                }
                else
                {
                    valor = Decimal.Parse(txtValorAgendamento.Value.ToString());
                }
            }

            ag.valorAgenda = valor;

            if (cbbPrioridade.Value != null) ag.IDPrioridade = int.Parse(cbbPrioridade.Value.ToString());

            Control.AgendaPagamentos.Dados obj = new Control.AgendaPagamentos.Dados();

            //if (DateTime.Parse(dtAgendamento.Date.ToShortDateString()) < DateTime.Parse(DateTime.Now.ToShortDateString()))
            //{
            //    e.Result = "Data de Agendamento Anterior a Data Atual !!!";
            //    callbackAgendarPagamentos.JSProperties["cpERROR"] = "1";
            //}
            //else {
                if (Convert.ToDecimal(txtValorOriginal.Value) < Convert.ToDecimal(txtValorAgendamento.Value))
                {
                    e.Result = "O Valor Agendado é maior do que o disponível!!!";
                    callbackAgendarPagamentos.JSProperties["cpERROR"] = "1";
                }
                else {
                    if (cbbPrioridade.Value == null)
                    {
                        e.Result = "Selecione a prioridade para o seu agendamento !!!";
                        callbackAgendarPagamentos.JSProperties["cpERROR"] = "1";
                    }
                    else
                    {
                        e.Result = obj.Gravar(ag);
                        callbackAgendarPagamentos.JSProperties["cpERROR"] = "0";
                    }
                }
            //}
        }
        //Agendados
        protected void ASPxGridViewExporter2_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack || Page.IsCallback)
            {
                string param = Request.Params["__EVENTTARGET"];
                if (param != null)
                {
                    if (param.Contains("ASPxButton4"))
                    {
                        Control.AgendaPagamentos.Dados obj = new Control.AgendaPagamentos.Dados();

                        string envolvido = string.Empty;
                        string undOrc = string.Empty;
                        DateTime dataIni = DateTime.MinValue;
                        DateTime dataFim = DateTime.MaxValue;

                        if (cbbEnvolvidoAgendado.Value != null) envolvido = cbbEnvolvidoAgendado.Value.ToString();
                        if (cbbUndOrcAgendado.Value != null) undOrc = cbbUndOrcAgendado.Value.ToString();
                        if (dtCadastroIniAgendado.Date != null) dataIni = dtCadastroIniAgendado.Date;
                        if (dtCadastroFimAgendado.Date != null) dataFim = dtCadastroFimAgendado.Date;

                        gridAgendados.DataSource = obj.gridAgendados(envolvido, undOrc, dataIni, dataFim);
                        gridAgendados.DataBind();
                        obj = null;
                    }
                }
            }
        }
        protected void ASPxGridViewExporter1_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack || Page.IsCallback)
            {
                string param = Request.Params["__EVENTTARGET"];
                if (param != null)
                {
                    if (param.Contains("btnExcel"))
                    {
                        Control.AgendaPagamentos.Dados obj = new Control.AgendaPagamentos.Dados();

                        string envolvido = string.Empty;
                        string undOrc = string.Empty;
                        DateTime dataIni = DateTime.MinValue;
                        DateTime dataFim = DateTime.MaxValue;
                        string procNumero = string.Empty;
                        string empenho = string.Empty;

                        if (cbbEnvolvido.Value != null) envolvido = cbbEnvolvido.Value.ToString();
                        if (cbbUndOrc.Value != null) undOrc = cbbUndOrc.Value.ToString();
                        if (dtCadastroIni.Value != null) dataIni = dtCadastroIni.Date;
                        if (dtCadastroFim.Value != null) dataFim = dtCadastroFim.Date;
                        if (txtProcessoNumero.Value != null) procNumero = txtProcessoNumero.Value.ToString();
                        if (txtEmpenho.Value != null) empenho = txtEmpenho.Value.ToString();

                        gridAptosPagamento.DataSource = obj.gridAptoPagamento(envolvido, undOrc, dataIni, dataFim, procNumero, empenho);
                        gridAptosPagamento.DataBind();
                    }
                }
            }
        }
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
        {
            string parametro = e.Parameter;

            string processos = string.Empty;

            if (parametro.Equals("gridProcessosAgendados"))
            {
                List<object> values = GetSelectedRowValues("VAL_LIQUIDADO", "PROCID", "PROCNUMERO", gridAgendados);

                foreach (List<object> obj in values)
                {
                    processos += obj[1].ToString() + "|";
                }
            }
            else {
                List<object> values = GetSelectedRowValues("VAL_LIQUIDADO", "PROCID", "PROCNUMERO", gridProcessosAgendadosConta);

                foreach (List<object> obj in values)
                {
                    processos += obj[1].ToString() + "|";
                }
            }

            Control.AgendaPagamentos ag = new Control.AgendaPagamentos();

            ag.processos = processos;

            Control.AgendaPagamentos.Dados objAg = new Control.AgendaPagamentos.Dados();
            e.Result = objAg.cancelarAgendamento(ag);
        }