Example #1
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));
        }
Example #2
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));
        }