Exemple #1
0
        public JsonResult GetDataToShow(string id, int idTablero)
        {
            Session["SpartanOperationId"] = id;
            _tokenManager.GenerateToken();
            ModelSearchResult        resultFinal       = new ModelSearchResult();
            List <ModelSearchFields> resultFinalFields = new List <ModelSearchFields>();
            var    searchResult = (ModelResultsFields)Session["SearchResult"];
            var    search       = searchResult.ValuesColumns.Where(x => x.Values[0] == id).FirstOrDefault();
            var    management   = (Spartan_Record_Detail_Management)Session["Management"];
            string label        = management.Reference_Label;
            string labelValue   = search.Values[1];

            resultFinal.Label      = label;
            resultFinal.LabelValue = labelValue;
            string query = management.Query_Data_Detail;

            query = query.Replace("@@LLAVE@@", id);
            _ISpartaneQueryApiConsumer.SetAuthHeader(_tokenManager.Token);
            _ISpartan_RDM_Operations_DetailApiConsumer.SetAuthHeader(_tokenManager.Token);
            var result     = _ISpartaneQueryApiConsumer.ExecuteRawQuery(HttpUtility.UrlEncode(query)).Resource;
            var serializer = new JavaScriptSerializer();

            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic obj = serializer.Deserialize(result, typeof(object));

            var           columnsDictionary = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(result);
            List <string> columns           = new List <string>();

            foreach (var dict in columnsDictionary[0])
            {
                columns.Add(dict.Key);
            }
            foreach (var item in obj)
            {
                var row = new List <string>();
                foreach (var col in columns)
                {
                    resultFinalFields.Add(new ModelSearchFields {
                        Label = col, Value = item[col] == null ? "" : item[col].ToString(), Group = ""
                    });
                }
            }
            resultFinal.Data = resultFinalFields;


            /*GRILLA DETALLE*/
            List <ResultGeneralDetail> resultDetail            = new List <ResultGeneralDetail>();
            List <ModelSearchFields>   resultFinalFieldsDetail = new List <ModelSearchFields>();
            ResultGeneralDetail        aux;
            var details = _ISpartan_RDM_Operations_DetailApiConsumer.ListaSelAll(0, 9999, "Spartan_RDM_Operations_Detail.Record_Detail_Management=" + idTablero.ToString(), "").Resource;

            if (details.RowCount > 0)
            {
                foreach (var item in details.Spartan_RDM_Operations_Details.OrderBy(x => x.Order_Shown))
                {
                    aux          = new ResultGeneralDetail();
                    aux.ObjectId = item.Object_Name.Value;
                    string faseStringPaso = (_faseid == null ? "null" : _faseid.ToString());
                    var    counter        = _ISpartaneQueryApiConsumer.ExecuteQuery(item.Count_Query.Replace("@@LLAVE@@", id).Replace("@@FASE@@", faseStringPaso)).Resource;
                    aux.Counter = Convert.ToInt32(counter);
                    aux.Label   = item.Object_Label;

                    //Buscamos el nombre del archivo
                    _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                    var fileInfo = _ISpartane_FileApiConsumer.GetByKey(item.Icono).Resource;
                    //preparamos la url del archivo fisico
                    aux.Icon = ConfigurationManager.AppSettings["urlpublicaimagenes"] + "/api/Spartan_File/Files/" + item.Icono + "/" + fileInfo.Description;

                    aux.Details = new ModelResultsFields();
                    string queryDataDetail   = item.Query_Data.Replace("@@LLAVE@@", id).Replace("@@FASE@@", faseStringPaso);
                    var    resultQueryDetail = _ISpartaneQueryApiConsumer.ExecuteRawQuery(HttpUtility.UrlEncode(queryDataDetail)).Resource;
                    if (resultQueryDetail != null && resultQueryDetail != "[]")
                    {
                        serializer = new JavaScriptSerializer();
                        serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
                        dynamic objDetail = serializer.Deserialize(resultQueryDetail, typeof(object));

                        List <ModelResultsValueFields> valuesColumnsDetail = new List <ModelResultsValueFields>();
                        var           columnsDictionaryDetail = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(resultQueryDetail);
                        List <string> columnsDetail           = new List <string>();
                        foreach (var dict in columnsDictionaryDetail[0])
                        {
                            columnsDetail.Add(dict.Key);
                        }
                        aux.Details.Columns       = columnsDetail;
                        aux.Details.ValuesColumns = new List <ModelResultsValueFields>();
                        foreach (var itemDetail in objDetail)
                        {
                            var row = new List <string>();
                            foreach (var col in columnsDetail)
                            {
                                row.Add(itemDetail[col] == null ? "" : itemDetail[col].ToString());
                            }
                            var values = new ModelResultsValueFields();
                            values.Values = row;
                            valuesColumnsDetail.Add(values);
                        }
                        ModelResultsFields resultDetailNew = new ModelResultsFields();
                        resultDetailNew.Columns       = columnsDetail;
                        resultDetailNew.ValuesColumns = valuesColumnsDetail;
                        aux.Details = resultDetailNew;
                    }
                    resultDetail.Add(aux);
                }
                Session["DataByTab"] = resultDetail;
            }
            resultFinal.Details = resultDetail;

            return(Json(resultFinal, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public JsonResult GetDetalleBySearchResult(string id, int idTablero, string idTab)
        {
            //List<ResultGeneralDetail> allData = (List<ResultGeneralDetail>)Session["DataByTab"];
            //var data = allData.Where(x => x.Label == idTab).ToList();

            ModelSearchResult resultFinal = new ModelSearchResult();
            var serializer = new JavaScriptSerializer();
            //serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            //dynamic obj = serializer.Deserialize(result, typeof(object));


            /*GRILLA DETALLE*/
            List <ResultGeneralDetail> resultDetail            = new List <ResultGeneralDetail>();
            List <ModelSearchFields>   resultFinalFieldsDetail = new List <ModelSearchFields>();
            ResultGeneralDetail        aux;

            _tokenManager.GenerateToken();

            _ISpartan_RDM_Operations_DetailApiConsumer.SetAuthHeader(_tokenManager.Token);
            var details = _ISpartan_RDM_Operations_DetailApiConsumer.ListaSelAll(0, 9999, "Spartan_RDM_Operations_Detail.Record_Detail_Management=" + idTablero.ToString(), "").Resource;

            if (details.RowCount > 0)
            {
                foreach (var item in details.Spartan_RDM_Operations_Details)
                {
                    aux          = new ResultGeneralDetail();
                    aux.ObjectId = item.Object_Name.Value;
                    string fase = "";
                    if (Session["Phase"] != null)
                    {
                        if (Session["Phase"].ToString() != "")
                        {
                            fase = "," + Session["Phase"].ToString();
                        }
                    }
                    //aqui
                    string faseStringPaso = (_faseid == null ? "null" : _faseid.ToString());



                    var counter = _ISpartaneQueryApiConsumer.ExecuteQuery(item.Count_Query.Replace("@@LLAVE@@", id).Replace("@@FASE@@", faseStringPaso).Replace("@@FASE@@", faseStringPaso)).Resource;
                    aux.Counter = Convert.ToInt32(counter);
                    aux.Label   = item.Object_Label;

                    //Buscamos el nombre del archivo
                    _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                    var fileInfo = _ISpartane_FileApiConsumer.GetByKey(item.Icono).Resource;
                    //preparamos la url del archivo fisico
                    aux.Icon = ConfigurationManager.AppSettings["BaseUrl"] + "/api/Spartan_File/Files/" + item.Icono + "/" + fileInfo.Description;

                    aux.Details = new ModelResultsFields();
                    string queryDataDetail   = item.Query_Data.Replace("@@LLAVE@@", id).Replace("@@FASE@@", faseStringPaso);
                    var    resultQueryDetail = _ISpartaneQueryApiConsumer.ExecuteRawQuery(HttpUtility.UrlEncode(queryDataDetail)).Resource;
                    if (resultQueryDetail != null && resultQueryDetail != "[]")
                    {
                        serializer = new JavaScriptSerializer();
                        serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
                        dynamic objDetail = serializer.Deserialize(resultQueryDetail, typeof(object));

                        List <ModelResultsValueFields> valuesColumnsDetail = new List <ModelResultsValueFields>();
                        var           columnsDictionaryDetail = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(resultQueryDetail);
                        List <string> columnsDetail           = new List <string>();
                        foreach (var dict in columnsDictionaryDetail[0])
                        {
                            columnsDetail.Add(dict.Key);
                        }
                        aux.Details.Columns       = columnsDetail;
                        aux.Details.ValuesColumns = new List <ModelResultsValueFields>();
                        foreach (var itemDetail in objDetail)
                        {
                            var row = new List <string>();
                            foreach (var col in columnsDetail)
                            {
                                row.Add(itemDetail[col] == null ? "" : itemDetail[col].ToString());
                            }
                            var values = new ModelResultsValueFields();
                            values.Values = row;
                            valuesColumnsDetail.Add(values);
                        }
                        ModelResultsFields resultDetailNew = new ModelResultsFields();
                        resultDetailNew.Columns       = columnsDetail;
                        resultDetailNew.ValuesColumns = valuesColumnsDetail;
                        aux.Details = resultDetailNew;
                    }
                    resultDetail.Add(aux);
                }
                //  Session["DataByTab"] = resultDetail;
            }
            resultFinal.Details = resultDetail;


            List <ResultGeneralDetail> allData = resultDetail;
            var data = allData.Where(x => x.Label == idTab).ToList();



            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        public JsonResult GetResultSearchTable(List <ModelSearchFields> resultsSearch)
        {
            string where = "";
            if (resultsSearch != null)
            {
                foreach (var item in resultsSearch)
                {
                    if (!String.IsNullOrEmpty(item.Value))
                    {
                        switch (item.TypeControl)
                        {
                        case "text":
                            if (where != "")
                            {
                                where += " AND ";
                            }
                            where += item.FieldDB + " LIKE '%" + item.Value + "%'";
                            break;

                        case "number":
                            if (where != "")
                            {
                                where += " AND ";
                            }
                            where += item.FieldDB + "=" + item.Value;
                            break;

                        case "date":
                            if (where != "")
                            {
                                where += " AND ";
                            }
                            if (item.FieldDB.Contains("_From") || item.FieldDB.Contains("_Desde"))
                            {
                                where += item.FieldDB.Replace("_Desde", "") + ">='" + DateTime.Parse(item.Value).ToString("yyyyMMdd") + "'";
                            }
                            else
                            {
                                where += item.FieldDB.Replace("_Hasta", "") + "<='" + DateTime.Parse(item.Value).ToString("yyyyMMdd") + "'";
                            }

                            break;

                        case "combobox":
                            if (item.Value != "-1")
                            {
                                if (where != "")
                                {
                                    where += " AND ";
                                }
                                where += item.FieldDB + "=" + item.Value;
                            }
                            break;
                        }
                    }
                }
            }
            //WHERE DE WORKFLOW
            if (WhereWF != null)
            {
                if (WhereWF != "")
                {
                    if (where != "")
                    {
                        where += " AND ";
                    }
                    where += WhereWF;
                }
            }

            //EJECUTO QUERY
            _tokenManager.GenerateToken();
            //_service.SetAuthHeader(_tokenManager.Token);
            _ISpartaneQueryApiConsumer.SetAuthHeader(_tokenManager.Token);
            var management = (Spartan_Record_Detail_Management)Session["Management"];// _service.GetByKey(ID, false).Resource;

            if (where != "")
            {
                if (management.Search_Result_Query.ToUpper().Contains("WHERE"))
                {
                    where = " AND " + where;
                }
                else
                {
                    where = " WHERE " + where;
                }
            }

            string queryResult = management.Search_Result_Query + where;

            //Aplicar reemplazo de variables de sesión
            queryResult = Helper.ReplaceGlobalQuery(queryResult);
            var dataTableJson = _ISpartaneQueryApiConsumer.ExecuteRawQuery(HttpUtility.UrlEncode(queryResult)).Resource;

            if (String.IsNullOrEmpty(dataTableJson) || dataTableJson == "[]")
            {
                ModelResultsFields resultError = new ModelResultsFields();
                resultError.Columns       = null;
                resultError.ValuesColumns = null;

                return(Json(resultError, JsonRequestBehavior.AllowGet));
            }
            var serializer = new JavaScriptSerializer();

            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });

            dynamic obj = serializer.Deserialize(dataTableJson, typeof(object));

            List <ModelResultsValueFields> valuesColumns = new List <ModelResultsValueFields>();
            var           columnsDictionary = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(dataTableJson);
            List <string> columns           = new List <string>();

            foreach (var dict in columnsDictionary[0])
            {
                columns.Add(dict.Key);
            }
            foreach (var item in obj)
            {
                var row = new List <string>();
                foreach (var col in columns)
                {
                    row.Add(item[col] == null ? "" : item[col].ToString());
                }
                var values = new ModelResultsValueFields();
                values.Values = row;
                valuesColumns.Add(values);
            }

            ModelResultsFields result = new ModelResultsFields();

            result.Columns          = columns;
            result.ValuesColumns    = valuesColumns;
            Session["SearchResult"] = result;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }