protected virtual PXGraph CreateGraph(string graphName, string screenID)
        {
            Type gt = System.Web.Compilation.PXBuildManager.GetType(graphName, false);

            if (gt == null)
            {
                gt = Type.GetType(graphName);
            }
            if (gt != null)
            {
                gt = System.Web.Compilation.PXBuildManager.GetType(PX.Api.CustomizedTypeManager.GetCustomizedTypeFullName(gt), false) ?? gt;
                using (new PXPreserveScope())
                {
                    try
                    {
                        return(gt == typeof(PXGenericInqGrph) ? PXGenericInqGrph.CreateInstance(screenID) : (PXGraph)PXGraph.CreateInstance(gt));
                    }
                    catch (System.Reflection.TargetInvocationException ex)
                    {
                        throw PXException.ExtractInner(ex);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
        public PXGenericInqGrph GetGIGraph(Guid gi)
        {
            GIDesign giDesign = PXSelect <GIDesign, Where <GIDesign.designID,
                                                           Equal <Required <GIDesign.designID> > > > .Select(Base, new object[] { gi });

            return(PXGenericInqGrph.CreateInstance(giDesign.DesignID.Value.ToString(), giDesign.Name,
                                                   parameters: new Dictionary <string, string>()));
        }
    protected void form_DataBinding(object sender, EventArgs e)
    {
        PXGenericInqGrph graph  = (PXGenericInqGrph)this.DefaultDataSource.DataGraph;
        IPXMasterPage    master = Page.Master as IPXMasterPage;

        if (master != null && graph != null && graph.Design != null)
        {
            master.ScreenTitle = graph.Design.SitemapTitle ?? graph.Design.Name;
        }
    }
Exemple #4
0
        //Función que crea la esturcuta de una tabla (Columnas)
        public static DataTable CreateTableStructure(GIDesign genericInq)
        {
            //Crea la instancia al graph de las consultas genericas
            PXGenericInqGrph graphGetColumns = PXGenericInqGrph.CreateInstance(genericInq.DesignID.Value);

            //Inicializa el listado de columnas
            List <string> listColumns = new List <string>();

            //Recorre, acomoda y agrega las columnas a la lista en orden
            foreach (GIResult resultMap in PXSelectReadonly <GIResult, Where <GIResult.designID, Equal <Required <GIResult.designID> > >, OrderBy <Asc <GIResult.lineNbr> > > .Select(graphGetColumns, new object[] { genericInq.DesignID.Value }))
            {
                // Solo agregamos si no está vacío
                if (!string.IsNullOrWhiteSpace(resultMap?.Caption))
                {
                    listColumns.Add(resultMap.Caption.ToString());
                }
            }

            //Crea una nueva Tabla DataTable.
            System.Data.DataTable table = new DataTable("Result");

            // Define las filas y columnas
            DataColumn column;

            // Crea la primera columna (autonumerable)
            column               = new DataColumn();
            column.DataType      = System.Type.GetType("System.Int32");
            column.ColumnName    = "_id";
            column.AutoIncrement = true;
            // Agrega la columna a la tabla
            table.Columns.Add(column);

            //Genera las columnas de acuerdo a la consulta genérica
            foreach (var itemColumn in listColumns)
            {
                // Crea la segunda columna
                column               = new DataColumn();
                column.DataType      = System.Type.GetType("System.String");
                column.ColumnName    = itemColumn;
                column.AutoIncrement = false;

                // Agrega la columna a la tabla
                table.Columns.Add(column);
            }

            // Vuelve la columna "_id" PrimaryKey
            DataColumn[] PrimaryKeyColumns = new DataColumn[1];
            PrimaryKeyColumns[0] = table.Columns["_id"];
            table.PrimaryKey     = PrimaryKeyColumns;

            //Regresa el esquema base de la tabla (columnas)
            return(table);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        ds.PrepareScreen();

        PXGenericInqGrph genGraph = (PXGenericInqGrph)ds.DataGraph;

        if (genGraph.Design != null)
        {
            if (genGraph.Design.PrimaryScreenID != null && PXList.Provider.IsList(genGraph.Design.PrimaryScreenID))
            {
                PXContext.Session.SetString(LastEntryScreenSessionKey, genGraph.Design.PrimaryScreenID);
            }

            // Clear saved searches in case if parameters changed
            if (genGraph.Design.DesignID != null && PXGenericInqGrph.ParametersChanged[genGraph.Design.DesignID.Value])
            {
                ds.SavedSearchesClear(true);
                PXGenericInqGrph.ParametersChanged[genGraph.Design.DesignID.Value] = false;
            }
        }
        else         // GI configuration with defined ID/Name does not exist in this company (for example, when changing company)
        {
            string screenID = PXContext.Session[LastEntryScreenSessionKey] as string;
            PXContext.Session.SetString("LastUrl", null);             // clear last url to prevent loading GI page again (Main.aspx loads LastUrl when there is no ScreenID)
            string redirectUrl = PXUrl.MainPagePath;
            if (!String.IsNullOrEmpty(screenID))
            {
                redirectUrl += "?ScreenID=" + screenID;
            }
            Redirector.SmartRedirect(HttpContext.Current, redirectUrl);
        }
        PXContext.SetSlot <Guid?>("__GEN_INQ_DESIGN_ID__", genGraph.Design.DesignID);
        var phF = this.FindControl("cont2");

        if (!form.Visible)
        {
            //grid.GridStyles.ToolsCell.CssClass += " transparent";
            form.Parent.Parent.Visible = false;
        }
    }
Exemple #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ds.PrepareScreen();

        PXGenericInqGrph genGraph = (PXGenericInqGrph)ds.DataGraph;

        if (genGraph.Design != null)
        {
            // Check access rights - they are handled by SiteMapProvider by URL
            // but GI can be opened by using different URLs (by ID and by Name)
            if (!PXGraph.ProxyIsActive && !PXGraph.GeneratorIsActive && this.Context != null)
            {
                string nodeUrl = PXUrl.IgnoreSystemParameters(PXUrl.ToRelativeUrl(this.Request.Url.ToString()));
                var    node    = PXSiteMap.Provider.FindSiteMapNodeUnsecure(nodeUrl);

                if (node == null || !node.IsAccessibleToUser(this.Context))
                {
                    // If there is no access to the GI itself or it is not in site map,
                    // consider it as a "Preview" mode in the GI designer and check access rights for the GI designer itself
                    var designerNode = PXSiteMap.Provider.FindSiteMapNodeByGraphType(typeof(PX.Data.Maintenance.GI.GenericInquiryDesigner).FullName);

                    if (designerNode == null)
                    {
                        Redirector.SmartRedirect(HttpContext.Current, PXUrl.MainPagePath);
                        return;
                    }
                }
            }

            if (genGraph.Design.PrimaryScreenID != null && PXList.Provider.IsList(genGraph.Design.PrimaryScreenID))
            {
                PXContext.Session.SetString(LastEntryScreenSessionKey, genGraph.Design.PrimaryScreenID);
            }

            // Clear saved searches in case if parameters changed
            if (genGraph.Design.DesignID != null && PXGenericInqGrph.ParametersChanged[genGraph.Design.DesignID.Value])
            {
                ds.SavedSearchesClear(true);
                PXGenericInqGrph.ParametersChanged[genGraph.Design.DesignID.Value] = false;
            }
        }
        else         // GI configuration with defined ID/Name does not exist in this company (for example, when changing company)
        {
            string screenID = PXContext.Session[LastEntryScreenSessionKey] as string;
            PXContext.Session.SetString("LastUrl", null);             // clear last url to prevent loading GI page again (Main page loads LastUrl when there is no ScreenID)
            string redirectUrl = PXUrl.MainPagePath;
            if (!String.IsNullOrEmpty(screenID))
            {
                redirectUrl += "?ScreenID=" + screenID;
            }
            Redirector.SmartRedirect(HttpContext.Current, redirectUrl);
        }
        PXContext.SetSlot <Guid?>("__GEN_INQ_DESIGN_ID__", genGraph.Design.DesignID);
        var phF = this.FindControl("cont2");

        if (!form.Visible)
        {
            //grid.GridStyles.ToolsCell.CssClass += " transparent";
            form.Parent.Parent.Visible = false;
        }
    }
Exemple #7
0
        public static DataTable LoadRowsToTable(GIDesign genericInq, DataTable structureTable, Dictionary <string, DateTime?> parameters)
        {
            //Define la fila que se generará y la variable de autoincremento
            DataRow row;
            int     i = 0;

            //Crea la instancia al graph de las consultas genericas
            PXGenericInqGrph graphGetRows = PXGenericInqGrph.CreateInstance(genericInq.DesignID.Value);

            //Define los parametros del filtro de la consulta genérica
            foreach (var itemParameters in parameters)
            {
                graphGetRows.Caches[typeof(GenericFilter)].SetValueExt(graphGetRows.Filter.Current, itemParameters.Key, itemParameters.Value);
            }

            //Recorre los renglones recuperados
            foreach (GenericResult resultRow in graphGetRows.Views["Results"].SelectMulti())
            {
                //Genera las filas de la tabla
                row        = structureTable.NewRow();
                row["_id"] = i++;

                //Recorre las llaves del renglon (DAC's de los que se componen los renglones)
                foreach (string key in resultRow.Values.Keys)
                {
                    //Determina si son DAC's mapeados y genericos(formulas)
                    if (key != "GenericResult")
                    {
                        //Si son DAC´s nativos, recorre las columnas definidas en la consulta genérica
                        foreach (GIResult resultMap in PXSelectReadonly <GIResult, Where <GIResult.designID, Equal <Required <GIResult.designID> >, And <GIResult.objectName, Equal <Required <GIResult.objectName> > > > > .Select(graphGetRows, new object[] { genericInq.DesignID.Value, key }))
                        {
                            //Inicializa la variable result
                            var result = new object();
                            //Inicializa el campo como vacío
                            string fieldValue = string.Empty;

                            //Recupera el valor de esa columna en el renglón vigente
                            if (resultMap.Field.Contains("Attributes"))
                            {
                                //Recupera el NoteID del registro
                                result = graphGetRows.Caches[resultRow.Values[key].GetType()].GetValue(resultRow.Values[key], "NoteID");
                                Guid dresult = (Guid)result;

                                //Descompone la columna del atributo y recupera el nombre (llave)
                                string[] values        = resultMap.Field.Split('_');
                                string   attributeName = values[0];

                                //Rastrea el valor del atributo
                                CSAnswers resultAttribute = PXSelectReadonly <CSAnswers, Where <CSAnswers.refNoteID, Equal <Required <CSAnswers.refNoteID> >, And <CSAnswers.attributeID, Equal <Required <CSAnswers.attributeID> > > > > .Select(graphGetRows, new object[] { dresult, attributeName });

                                //Coloca la descripción del atributo en el valor del campo
                                if (resultAttribute != null)
                                {
                                    fieldValue = resultAttribute.Value;
                                }
                            }
                            else
                            {
                                result = graphGetRows.Caches[resultRow.Values[key].GetType()].GetValue(resultRow.Values[key], resultMap.Field);

                                //Si el resultado es diferente de nulo permite la conversión a texto
                                if (result != null)
                                {
                                    //Realiza la conversión del valor recuperado
                                    fieldValue = result.ToString();

                                    //Determina si es tipo Fecha
                                    if (graphGetRows.Caches[resultRow.Values[key].GetType()].GetValue(resultRow.Values[key], resultMap.Field).GetType() == typeof(DateTime))
                                    {
                                        fieldValue = ((DateTime)result).ToString("yyyy-MM-dd");
                                    }

                                    //Determina si es tipo decimal
                                    if (graphGetRows.Caches[resultRow.Values[key].GetType()].GetValue(resultRow.Values[key], resultMap.Field).GetType() == typeof(Decimal))
                                    {
                                        fieldValue = ((Decimal)result).ToString("0.00");
                                    }
                                }
                            }

                            // Agrega el valor de la fila a la columna definida por el número de línea en la definición de la tabla
                            // pero solo agregamos si el titulo no está vacío
                            if (!string.IsNullOrWhiteSpace(resultMap?.Caption))
                            {
                                row[resultMap.Caption.ToString()] = fieldValue;
                            }
                        }
                    }
                    else
                    {
                        //Recupera los registros dinámicos (fórmulas)
                        Dictionary <string, object> resGI = (Dictionary <string, object>)resultRow.Values[key];

                        //Recorre todos esos campos calculados
                        foreach (var entry in resGI)
                        {
                            //Obtiene llave y valor de cada fórmula
                            string keyGI   = entry.Key;
                            var    valueGI = entry.Value;

                            //La llave es un valor compuesto, se separa e identifica el RowID para saber a que columna le corresponde y lo convierte en su respectivo RowID
                            string[] words      = keyGI.Split('_');
                            string   objectName = words[0];
                            string   rowId      = words[1];
                            rowId = rowId.Replace("Formula", "");
                            Guid createRowId = Guid.ParseExact(rowId, "N");

                            //Rastrea la línea (posición de la columna)
                            GIResult resultMapRowId = PXSelectReadonly <GIResult, Where <GIResult.designID, Equal <Required <GIResult.designID> >, And <GIResult.rowID, Equal <Required <GIResult.rowID> > > > > .Select(graphGetRows, new object[] { genericInq.DesignID.Value, createRowId });

                            string fieldValueRowId = string.Empty;
                            if (fieldValueRowId != null)
                            {
                                fieldValueRowId = valueGI.ToString();
                            }

                            //Agrega el valor de la fila a la columna definida por el número de línea en la definición de la tabla
                            // pero solo agregamos si el titulo no está vacío
                            if (!string.IsNullOrWhiteSpace(resultMapRowId?.Caption))
                            {
                                row[resultMapRowId.Caption.ToString()] = fieldValueRowId;
                            }
                        }
                    }
                }

                //Agrega el renglon completo a la tabla
                structureTable.Rows.Add(row);
            }

            //Regresa la estructura completa de la tabla
            return(structureTable);
        }