public ActionResult _GraphView(FormCollection form)
        {
            if (form["queryGraphID"] != null)
            {
                StringBuilder javascriptGraficos = new StringBuilder();
                List <string> ltypeGraphs        = new List <string>();

                List <datosdivs> liTabs       = new List <datosdivs>();
                List <datosdivs> divsTabs     = new List <datosdivs>();
                List <datosdivs> divsGraficos = new List <datosdivs>();

                //form fields
                string nameGraph  = form["name"];
                string titleGraph = form["title"];
                string queryGraph = "";
                var    query      = db.BaseQueryGraphs.Find(int.Parse(form["queryGraphID"]));
                if (query != null)
                {
                    queryGraph = query.query;
                }
                foreach (var item in form["TypeGraphID"].Split(','))
                {
                    var typ = db.BaseTypesGraphs.Find(int.Parse(item));
                    if (typ != null)
                    {
                        ltypeGraphs.Add(typ.name);
                    }
                }

                //para el grafico
                string namedivsTab      = "";
                string namedivsgraficos = "";
                string active           = "active";

                //li de los tabs
                foreach (var item in ltypeGraphs)
                {
                    namedivsTab = nameGraph.Replace(" ", "") + "div" + item;
                    liTabs.Add(new datosdivs()
                    {
                        name = namedivsTab, status = active, text = TypeGraphsTranslate(item)
                    });
                    active = "";
                }

                //divs de los graficos
                foreach (var item in ltypeGraphs)
                {
                    namedivsgraficos = "morris-" + item + "_" + nameGraph.Replace(" ", "_");
                    divsGraficos.Add(new datosdivs()
                    {
                        name = namedivsgraficos
                    });
                }

                //divs a donde se moveran los graficos
                active = "active";
                foreach (var item in ltypeGraphs)
                {
                    namedivsTab = nameGraph.Replace(" ", "") + "div" + item;
                    divsTabs.Add(new datosdivs()
                    {
                        name = namedivsTab, status = active
                    });
                    active = "";
                }
                //json
                string consulta = MorrisHelper.getJson(queryGraph, db);

                javascriptGraficos.AppendLine(" var startMorris = function () { \n");
                javascriptGraficos.AppendFormat(" var json = {0}; \n", consulta);
                javascriptGraficos.AppendLine("");
                javascriptGraficos.AppendLine("");
                foreach (var item in ltypeGraphs)
                {
                    namedivsgraficos = "#morris-" + item + "_" + nameGraph.Replace(" ", "_");
                    javascriptGraficos.AppendLine(" $('" + namedivsgraficos + "').buildMorris({ \n");
                    javascriptGraficos.AppendFormat(" type: \"{0}\", \n", item.ToLower());
                    javascriptGraficos.AppendLine(" json: json \n");
                    javascriptGraficos.AppendLine("}); \n");

                    //moviendo divs de los graficos a divs de tabs
                    namedivsTab = "#" + nameGraph.Replace(" ", "") + "div" + item;
                    javascriptGraficos.AppendFormat(" $(\"{0}\").appendTo(\"{1}\");\n", namedivsgraficos, namedivsTab);
                    javascriptGraficos.AppendLine("");
                }
                javascriptGraficos.AppendLine("}");
                javascriptGraficos.AppendLine("");
                javascriptGraficos.AppendLine("");
                javascriptGraficos.AppendLine("$.fn.buildMorris.loadMorris(startMorris);");

                ViewBag.tabs               = liTabs;
                ViewBag.divsTabs           = divsTabs;
                ViewBag.divsGraficos       = divsGraficos;
                ViewBag.javascriptGraficos = javascriptGraficos.ToString();
            }


            return(PartialView());
        }
        public ActionResult _GraphView(int widgetID = 0, string fechad = "", string fechah = "")
        {
            if (widgetID > 0)
            {
                StringBuilder javascriptGraficos     = new StringBuilder();
                StringBuilder JSONjavascriptGraficos = new StringBuilder();
                List <string> ltypeGraphs            = new List <string>();

                List <datosdivs> liTabs       = new List <datosdivs>();
                List <datosdivs> divsTabs     = new List <datosdivs>();
                List <datosdivs> divsGraficos = new List <datosdivs>();

                var           widget     = db.BaseWidgets.Find(widgetID);
                string        active     = "active";
                StringBuilder textFilter = new StringBuilder();

                if (fechad != "" && fechah != "")
                {
                    textFilter.AppendLine(" <div> ");
                    textFilter.AppendFormat("<p>From: {0} hasta: {1}</p>", fechad, fechah);
                    textFilter.AppendLine("</div>");
                }
                else if (fechah != "" && fechad == "")
                {
                    textFilter.AppendLine(" <div> ");
                    textFilter.AppendFormat("<p>To: {0} </p>", fechah);
                    textFilter.AppendLine("</div>");
                }
                else if (fechad != "" && fechah == "")
                {
                    textFilter.AppendLine(" <div> ");
                    textFilter.AppendFormat("<p>From: {0} To: {1}</p>", fechad, DateTime.Now.ToString("yyyy-MM-dd"));
                    textFilter.AppendLine("</div>");
                }
                else if (fechad == "" && fechah == "" && widget.hasRange)
                {
                    textFilter.AppendLine(" <div> ");
                    textFilter.AppendFormat("<p>No Filters</p>", fechad, fechah);
                    textFilter.AppendLine("</div>");
                }

                var graficos = widget.BaseGraphs.ToList();
                if (graficos.Count(x => x.queryGraphID != null) > 0)
                {
                    javascriptGraficos.AppendLine(" var startMorris = function () { \n");
                }

                foreach (var g in graficos)
                {
                    ltypeGraphs = new List <string>();

                    if (g.queryGraphID != null)
                    {
                        ViewBag.filter = textFilter;
                    }

                    //form fields
                    string nameGraph  = g.name;
                    string titleGraph = g.title;
                    string queryGraph = "";
                    var    query      = db.BaseQueryGraphs.Find(g.queryGraphID);
                    if (query != null)
                    {
                        queryGraph = query.query;
                    }

                    foreach (var item in g.BaseTypesGraphs.ToList())
                    {
                        var typ = db.BaseTypesGraphs.Find(item.id);
                        if (typ != null)
                        {
                            ltypeGraphs.Add(typ.name);
                        }
                    }

                    //para el grafico
                    string namedivsTab      = "";
                    string namedivsgraficos = "";

                    //li de los tabs
                    string textli = g.title;
                    foreach (var item in ltypeGraphs)
                    {
                        namedivsTab = nameGraph.Replace(" ", "") + "div" + item + widgetID;
                        //liTabs.Add(new datosdivs() { name = namedivsTab, status = active, text = textli });
                        liTabs.Add(new datosdivs()
                        {
                            name = namedivsTab, status = active, text = TypeGraphsTranslate(item)
                        });
                        //divs a donde se moveran los graficos
                        divsTabs.Add(new datosdivs()
                        {
                            name = namedivsTab, status = active
                        });
                        active = "";
                    }

                    //divs de los graficos
                    foreach (var item in ltypeGraphs)
                    {
                        namedivsgraficos = "morris-" + item + "_" + nameGraph.Replace(" ", "_") + widgetID;
                        divsGraficos.Add(new datosdivs()
                        {
                            name = namedivsgraficos
                        });
                    }

                    //json
                    string con      = "";
                    string consulta = "";
                    if (g.queryGraphID != null)
                    {
                        con = queryGraph;

                        if (fechad != "" && fechah != "")
                        {
                            con = queryGraph.Replace("2015-01-01", fechad).Replace("3000-02-01", fechah);
                        }

                        consulta = MorrisHelper.getJson(con, db);

                        //javascriptGraficos.AppendLine(" var startMorris = function () { \n");
                        //javascriptGraficos.AppendFormat(" var json = {0}; \n", consulta);
                        //javascriptGraficos.AppendLine("");
                        //javascriptGraficos.AppendLine("");
                        foreach (var item in ltypeGraphs)
                        {
                            string namejson = "JSON_" + item + "" + g.id;
                            JSONjavascriptGraficos.AppendFormat(" var {1} = {0}; \n", consulta, namejson);
                            JSONjavascriptGraficos.AppendLine("");

                            namedivsgraficos = "#morris-" + item + "_" + nameGraph.Replace(" ", "_") + widgetID;
                            javascriptGraficos.AppendLine(" $('" + namedivsgraficos + "').buildMorris({ \n");
                            javascriptGraficos.AppendFormat(" type: \"{0}\", \n", item.ToLower());
                            //javascriptGraficos.AppendLine(" json: json \n");
                            javascriptGraficos.AppendFormat(" json: {0} \n", namejson);
                            javascriptGraficos.AppendLine("}); \n");

                            //moviendo divs de los graficos a divs de tabs
                            namedivsTab = "#" + nameGraph.Replace(" ", "") + "div" + item + widgetID;
                            javascriptGraficos.AppendFormat(" $(\"{0}\").appendTo(\"{1}\");\n", namedivsgraficos, namedivsTab);
                            javascriptGraficos.AppendLine("");
                        }
                        //javascriptGraficos.AppendLine("}");
                        //javascriptGraficos.AppendLine("");
                        //javascriptGraficos.AppendLine("");
                        //javascriptGraficos.AppendLine("$.fn.buildMorris.loadMorris(startMorris);");

                        javascriptGraficos.AppendLine("}");
                        javascriptGraficos.AppendLine("");
                        javascriptGraficos.AppendLine("");
                        javascriptGraficos.AppendLine("$.fn.buildMorris.loadMorris(startMorris);");
                    }
                }
                ViewBag.tabs                   = liTabs;
                ViewBag.divsTabs               = divsTabs;
                ViewBag.divsGraficos           = divsGraficos;
                ViewBag.javascriptGraficos     = javascriptGraficos.ToString();
                ViewBag.JSONjavascriptGraficos = JSONjavascriptGraficos.ToString();
            }


            return(PartialView());
        }