Exemplo n.º 1
0
        private String GetFilterTemplate(List <FieldData> fieldList, Int64 fieldId, String fieldValue, String condition)
        {
            String defaultDataType = "";
            String dtValue         = MessageResource.FormatDate(DateTime.Now, true);
            String timeValue       = "00:00:00";
            String txtValue        = "";
            String numValue        = "";

            FilterConditionType dtCondition  = FilterConditionType.Equal;
            FilterConditionType txtCondition = FilterConditionType.Equal;
            FilterConditionType numCondition = FilterConditionType.Equal;

            String filterTemplate = "<div id=\"{0}\"><input type=\"hidden\" name=\"filter_id\" value=\"{0}\" /><input type=\"hidden\" name=\"filter_{0}_group\" value=\"{1}\" /><div class=\"filter\" filter-id=\"{0}\"><table><tbody><tr><td class=\"col1\">";

            filterTemplate += "<select class=\"filter-field\" id=\"filter_{0}_field_id\" name=\"filter_{0}_field_id\">";
            foreach (FieldData fd in fieldList)
            {
                if ((defaultDataType == "") || (fd.field_id == fieldId))
                {
                    defaultDataType = fd.data_type;
                }

                if (fd.field_id == fieldId)
                {
                    switch (fd.data_type.ToLower())
                    {
                    case "datetime":
                        try
                        {
                            if (fieldValue == "now")
                            {
                                dtValue = "now";
                            }
                            else
                            {
                                DateTime tmp = DateTime.Parse(fieldValue);
                                dtValue   = MessageResource.FormatDate(tmp, true);
                                timeValue = MessageResource.FormatTime(tmp);
                            }
                        }
                        catch { }

                        foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.DateTime))
                        {
                            if (ft.ToString().ToLower() == condition.ToLower())
                            {
                                dtCondition = ft;
                            }
                        }

                        break;

                    case "numeric":
                        numValue = fieldValue;

                        foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.Numeric))
                        {
                            if (ft.ToString().ToLower() == condition.ToLower())
                            {
                                numCondition = ft;
                            }
                        }
                        break;

                    default:
                        txtValue = fieldValue;

                        foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.Text))
                        {
                            if (ft.ToString().ToLower() == condition.ToLower())
                            {
                                txtCondition = ft;
                            }
                        }
                        break;
                    }
                }

                filterTemplate += "<option value=\"" + fd.field_id + "\" data-type=\"" + fd.data_type.ToLower() + "\" " + (fd.field_id == fieldId ? "selected" : "") + ">" + fd.name + "</option>";
            }
            filterTemplate += "</select>";
            filterTemplate += "</td><td class=\"col2\">";

            filterTemplate += "<div class=\"dt-check dt-datetime " + (defaultDataType == "datetime" ? "" : "dt-off") + "\"><select name=\"filter_{0}_condition_datetime\">";
            foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.DateTime))
            {
                filterTemplate += "<option value=\"" + ft.ToString().ToLower() + "\" " + (dtCondition == ft ? "selected" : "") + ">" + MessageResource.GetMessage(ft.ToString().ToLower(), ft.ToString()) + "</option>";
            }
            filterTemplate += "</select></div>";
            filterTemplate += "<div class=\"dt-check dt-numeric " + (defaultDataType == "numeric" ? "" : "dt-off") + "\"><select name=\"filter_{0}_condition_numeric\">";
            foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.Numeric))
            {
                filterTemplate += "<option value=\"" + ft.ToString().ToLower() + "\" " + (numCondition == ft ? "selected" : "") + ">" + MessageResource.GetMessage(ft.ToString().ToLower(), ft.ToString()) + "</option>";
            }
            filterTemplate += "</select></div>";
            filterTemplate += "<div class=\"dt-check dt-string " + (defaultDataType == "string" ? "" : "dt-off") + "\"><select name=\"filter_{0}_condition_string\">";
            foreach (FilterConditionType ft in IAM.Filters.FilterCondition.ConditionByDataType(DataType.Text))
            {
                filterTemplate += "<option value=\"" + ft.ToString().ToLower() + "\" " + (txtCondition == ft ? "selected" : "") + ">" + MessageResource.GetMessage(ft.ToString().ToLower(), ft.ToString()) + "</option>";
            }
            filterTemplate += "</select></div>";

            filterTemplate += "</td><td class=\"col3\">";

            filterTemplate += "<div class=\"dt-check dt-datetime " + (defaultDataType == "datetime" ? "" : "dt-off") + "\"><div display=\"block\" class=\"filter-now\"><input name=\"filter_{0}_now\" type=\"checkbox\" " + (dtValue == "now" ? "checked" : "") + " state=\"false\" />" + MessageResource.GetMessage("use_now", "Use Now() function") + "</div><input class=\"  " + (dtValue == "now" ? "dt-off date-mask-off" : "date-mask") + "\" name=\"filter_{0}_text_date\" type=\"text\" placeholder=\"Digite a data. Ex. dd/mm/yyyy\" value=\"" + dtValue + "\" /><input class=\"time-mask " + (dtValue == "now" ? "dt-off" : "") + "\" name=\"filter_{0}_text_time\" type=\"text\" placeholder=\"Digite a hora. Ex. hh:mm:ss\" value=\"" + timeValue + "\" /></div>";
            filterTemplate += "<div class=\"dt-check dt-numeric " + (defaultDataType == "numeric" ? "" : "dt-off") + "\"><input name=\"filter_{0}_text_numeric\" type=\"text\" placeholder=\"Digite o valor numérico\" value=\"" + numValue + "\" /></div>";
            filterTemplate += "<div class=\"dt-check dt-string " + (defaultDataType == "string" ? "" : "dt-off") + "\"><input name=\"filter_{0}_text_string\" type=\"text\" placeholder=\"Digite o texto\" value=\"" + txtValue + "\" /></div>";

            filterTemplate += "</td><td class=\"col4\"><div class=\"ico icon-close floatright\"></div><div class=\"ico icon-plus floatright\"></div></td></tr></tbody></table><div class=\"clear-block\"></div></div><div class=\"filter-selector-wrapper\">{2}</div></div>";

            return(filterTemplate);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.HttpMethod != "POST")
            {
                return;
            }

            String area = "";

            if (!String.IsNullOrWhiteSpace((String)RouteData.Values["area"]))
            {
                area = (String)RouteData.Values["area"];
            }

            Int64 enterpriseId = 0;

            if ((Session["enterprise_data"]) != null && (Session["enterprise_data"] is EnterpriseData))
            {
                enterpriseId = ((EnterpriseData)Session["enterprise_data"]).Id;
            }


            String ApplicationVirtualPath = Session["ApplicationVirtualPath"].ToString();

            LMenu menu1 = null;
            LMenu menu2 = null;
            LMenu menu3 = null;

            WebJsonResponse contentRet = null;

            String html  = "";
            String eHtml = "";
            String js    = null;



            String errorTemplate = "<span class=\"empty-results\">{0}</span>";


            switch (area)
            {
            case "":
            case "content":
                using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString()))
                {
                    DataTable dtServices = db.ExecuteDataTable("select * from service_status order by service_name", CommandType.Text, null);
                    if ((dtServices != null) && (dtServices.Rows.Count > 0))
                    {
                        html += "<table id=\"users-table\" class=\"sorter\"><thead>";
                        html += "    <tr>";
                        html += "        <th class=\"pointer header headerSortDown\" data-column=\"name\">Serviço <div class=\"icomoon\"></div></th>";
                        html += "        <th class=\"pointer tHide header\" data-column=\"login\">Status do serviço <div class=\"icomoon\"></div></th>";
                        html += "        <th class=\"pointer tHide mHide header\" data-column=\"login\">Data de inicio <div class=\"icomoon\"></div></th>";
                        html += "        <th class=\"pointer tHide mHide header\" data-column=\"login\">Status da execução <div class=\"icomoon\"></div></th>";
                        html += "        <th class=\"pointer tHide mHide header\" data-column=\"login\">Data do processamento <div class=\"icomoon\"></div></th>";
                        html += "        <th class=\"pointer w150 tHide mHide header\" data-column=\"login\">% <div class=\"icomoon\"></div></th>";
                        html += "        <th class=\"pointer tHide mHide header\" data-column=\"login\">Informações adicionais <div class=\"icomoon\"></div></th>";
                        html += "        <th class=\"pointer w80 tHide mHide header\" data-column=\"login\">Ações <div class=\"icomoon\"></div></th>";
                        html += "    </tr>";
                        html += "</thead>";

                        html += "<tbody>";

                        String trTemplate = "    <tr class=\"user\">";
                        trTemplate += "            <td class=\"pointer ident10\">{0}</td>";
                        trTemplate += "            <td class=\"pointer tHide\">{1}</td>";
                        trTemplate += "            <td class=\"pointer tHide mHide\">{2}</td>";
                        trTemplate += "            <td class=\"pointer tHide mHide\">{3}</td>";
                        trTemplate += "            <td class=\"pointer tHide mHide\">{4}</td>";
                        trTemplate += "            <td class=\"pointer tHide mHide\">{5}</td>";
                        trTemplate += "            <td class=\"pointer tHide mHide\" style=\"line-height: 17px;\">{6}</td>";
                        trTemplate += "            <td class=\"pointer tHide mHide\"><button href=\"/admin/service_status/{0}/action/restart/\" class=\"a-btn btn-service confirm-action\" confirm-title=\"Restart\" confirm-text=\"Deseja reiniciar o serviço '{0}'?\" ok=\"Sim\" cancel=\"Não\"><div class=\"ico icon-loop\"></div></button></td>";
                        trTemplate += "    </tr>";

                        foreach (DataRow drS in dtServices.Rows)
                        {
                            String eStatus  = "";
                            String eDate    = "";
                            String sDate    = "";
                            String ePercent = "";
                            String eInfo    = "";

                            try
                            {
                                sDate = MessageResource.FormatDate((DateTime)drS["started_at"], false);
                            }
                            catch { }

                            String   sStatus  = "";
                            DateTime lastSync = (DateTime)drS["last_status"];
                            TimeSpan ts       = DateTime.Now - lastSync;
                            if (ts.TotalSeconds > 60)
                            {
                                sStatus += "<div class=\"red-text level-icon level-300\" style=\"margin: 0;\"></div>";
                                sStatus += "<span class=\"red-text\">Último status a " + MessageResource.FormatTs(ts) + "</span>";
                            }
                            else
                            {
                                sStatus += "<div class=\"green-text level-icon level-200\" style=\"margin: 0;\"></div>";
                                sStatus += "<span class=\"green-text\">Ativo</span>";

                                try
                                {
                                    switch (drS["service_name"].ToString().ToLower())
                                    {
                                    case "engine":

                                        ServiceStatusEngine stE = JSON.Deserialize <ServiceStatusEngine>(drS["additional_data"].ToString());
                                        if (stE.executing)
                                        {
                                            eStatus = "Processando registros";

                                            if (!String.IsNullOrEmpty(stE.last_status))
                                            {
                                                eStatus = stE.last_status;
                                            }

                                            //ePercent = stE.percent + "%";

                                            ePercent += "<div class=\"center\"><canvas id=\"usrLockChart\" width=\"40\" height=\"40\"></canvas></div>";
                                            js       += "iamadmin.buildPercentChart('#usrLockChart'," + stE.percent + ",{strokeColor:'#e5e5e5',textColor:'#333',color:'#76c558',showText:true});";

                                            eInfo  = "Total de registros: " + stE.total_registers;
                                            eInfo += "<br />Processado: " + stE.atual_register;
                                            eInfo += "<br />Erros: " + stE.errors;
                                            eInfo += "<br />Ignorados: " + stE.ignored;
                                            eInfo += "<br />Novas entidades: " + stE.new_users;
                                            eInfo += "<br />Atualizados: " + (stE.atual_register - stE.errors - stE.ignored - stE.new_users);
                                            eInfo += "<br />Threads: " + stE.thread_count;
                                            eInfo += "<br />Fila nas threads: " + stE.queue_count;

                                            try
                                            {
                                                DateTime dt1 = DateTime.Parse(stE.start_time);
                                                eDate = MessageResource.FormatDate(dt1, false);

                                                //Tempo estimado para conclusão
                                                TimeSpan ts2  = DateTime.Now - dt1;
                                                Double   calc = (ts2.TotalSeconds / (Double)stE.atual_register) * (Double)(stE.total_registers - stE.atual_register);

                                                eInfo += "<br />Conclusão estimada: " + MessageResource.FormatTime(DateTime.Now.AddSeconds(calc));
                                            }
                                            catch { }
                                        }

                                        break;

                                    case "report":
                                        ServiceStatusBase stR = JSON.Deserialize <ServiceStatusBase>(drS["additional_data"].ToString());
                                        break;

                                    case "inbound":
                                        ServiceStatusInbound stI = JSON.Deserialize <ServiceStatusInbound>(drS["additional_data"].ToString());
                                        if (stI.executing)
                                        {
                                            eStatus = "Processando importação";

                                            if (!String.IsNullOrEmpty(stI.last_status))
                                            {
                                                eStatus = stI.last_status;
                                            }


                                            //ePercent = stE.percent + "%";

                                            ePercent += "<div class=\"center\"><canvas id=\"inboundLockChart\" width=\"40\" height=\"40\"></canvas></div>";
                                            js       += "iamadmin.buildPercentChart('#inboundLockChart'," + stI.percent + ",{strokeColor:'#e5e5e5',textColor:'#333',color:'#76c558',showText:true});";

                                            eInfo  = "Total de arquivos: " + stI.total_files;
                                            eInfo += "<br />Processado: " + stI.processed_files;

                                            try
                                            {
                                                DateTime dt1 = DateTime.Parse(stI.start_time);
                                                eDate = MessageResource.FormatDate(dt1, false);

                                                //Tempo estimado para conclusão
                                                TimeSpan ts2  = DateTime.Now - dt1;
                                                Double   calc = (ts2.TotalSeconds / (Double)stI.processed_files) * (Double)(stI.total_files - stI.processed_files);

                                                eInfo += "<br />Conclusão estimada: " + MessageResource.FormatTime(DateTime.Now.AddSeconds(calc));
                                            }
                                            catch { }
                                        }
                                        break;

                                    case "dispatcher":
                                        ServiceStatusDispatcher stD = JSON.Deserialize <ServiceStatusDispatcher>(drS["additional_data"].ToString());
                                        if (stD.executing)
                                        {
                                            eStatus += "Executando publicação";
                                        }

                                        if (stD.executing_deploy_now)
                                        {
                                            if (eStatus != "")
                                            {
                                                eStatus += "/";
                                            }

                                            eStatus += "Executando publicação sob demanda";
                                        }

                                        break;
                                    }
                                }
                                catch { }
                            }

                            html += String.Format(trTemplate, drS["service_name"], sStatus, sDate, eStatus, eDate, ePercent, eInfo);
                        }

                        html += "</tbody></table>";

                        html += "<span class=\"empty-results content-loading user-list-loader hide\"></span>";

                        contentRet    = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html));
                        contentRet.js = "iamadmin.doReload(10000);" + js;
                    }
                    else
                    {
                        eHtml     += String.Format(errorTemplate, MessageResource.GetMessage("api_error"));
                        contentRet = new WebJsonResponse("#content-wrapper", (eHtml != "" ? eHtml : html));
                    }
                }
                break;

            case "sidebar":
                break;

            case "mobilebar":
                break;


            case "buttonbox":
                break;
            }

            if (contentRet != null)
            {
                if (!String.IsNullOrWhiteSpace((String)Request["cid"]))
                {
                    contentRet.callId = (String)Request["cid"];
                }

                Retorno.Controls.Add(new LiteralControl(contentRet.ToJSON()));
            }
        }