Beispiel #1
0
        public override string demandBeforeSubmit(string name)
        {
            string msg = base.demandBeforeSubmit(name);

            if (msg != "")
            {
                return(msg);
            }

            // pacchetto gz
            if (name == "form-import" && _page.query_param("type") != "csv")
            {
                // upload
                string pathtmp = Path.Combine(_page.tmpFolder(), Path.GetRandomFileName() + ".gz");
                form_control(name).upload_save("fileXml", pathtmp);

                // check schema
                deeper.db.db_schema db = page.conn_db_user();
                xmlDoc doc             = new xmlDoc(extract_dbpck_index(pathtmp));
                if (db.ver != doc.root_value("ver"))
                {
                    form_control(name).upload_set_path("fileXml", pathtmp);
                    return("Il database che si desidera importare ha una versione inferiore di quella installata.<br><br>"
                           + "Vuoi continuare ugualmente?");
                }
            }

            return("");
        }
Beispiel #2
0
        public static void backupDb(page_cls pageClass, string title, string des = "", string folder_files = "")
        {
            // export sql db
            deeper.db.db_schema db   = pageClass.page.conn_db_user();
            DateTime            date = DateTime.Now;
            string pocket            = db.export(pageClass.page.tmpFolder(), title, date
                                                 , pageClass.page.tmpFolder(), des, Path.GetRandomFileName(), folder_files);

            backupPck(pageClass, pocket, db.name, title, date, db.ver, des);
        }
Beispiel #3
0
        public override void onInit(object sender, EventArgs e, bool request = false, bool addControls = true)
        {
            _db = page.query_param("dbname") != "" ? page.conn_db(page.query_param("dbname")) : page.conn_db_user();
            if (!_db.exist_schema || !_db.exist_meta)
            {
                throw new Exception("attenzione, il database non ha lo schema xml e non è possibile gestire i collegamenti fra le tabelle!");
            }

            _viewtbl     = page.pageName == "table_view";
            _only_linked = page.query_param("lnk") == "1";
            _table       = page.query_param("tbl") != "" ? page.query_param("tbl") : _db.schema.tableFromPk(page.query_param("fld"));
            _meta        = _db.meta_doc.meta_tbl(_table);
            _exists      = !_viewtbl?_db.get_count("select count(*) from [" + _table + "] "
                                                   + " where [" + page.query_param("fld") + "] = " + page.query_param("val")) > 0 : false;

            // esiste l'elemento?
            if (addControls)
            {
                if (!_viewtbl)
                {
                    if (!_exists)
                    {
                        regScript(scriptStartAlert("L'elemento è già stato rimosso in precedenza!", "Messaggio", "navToPrev()"));
                    }
                    else
                    {
                        // conteggio elementi correlati
                        long count = _db.rel_tables_count(_table, page.query_param("val")).Sum(kv => kv.Value);
                        if (_only_linked && count == 0)
                        {
                            regScript(scriptStartAlert("Non ci sono elementi correlati!", "Messaggio", "navToPrev()"));
                        }
                        else
                        {
                            setPageDoc(docForDel(count, _db.count_notnull_remove_links(_table, long.Parse(page.query_param("val")))
                                                 , page.query_param("iddmain")));
                        }
                    }
                }
                else
                {
                    setPageDoc(addGrid(_db, xmlDoc.doc_from_xml("<page schema='xmlschema.ctrls'><contents/></page>")
                                       , _table, "grid0", "tabella " + (_meta != null ? _meta.title : _table), "", meta_link.types_link.normal, "", "", "=", true, true));
                }
            }

            base.onInit(sender, e, request, addControls);
        }
Beispiel #4
0
        protected static void import_db(page_cls pg, xmlDoc sch, out long elab, out long inserted, out long updated, out long err)
        {
            inserted = 0; updated = 0; err = 0; elab = 0;
            deeper.db.db_schema src = null, db = null;
            try {
                bool is_count = pg.there_sql("count", sch.root_node), is_check = pg.there_sql("check", sch.root_node);
                src = pg.page.conn_db(sch.root_value("conn")); db = pg.page.conn_db_base();
                pg.exec_updates("before", "", null, null, sch.root_node);
                foreach (DataRow dr in src.dt_table(pg.sql_from_id("load", "", src.conn_keys, null, sch.root_node)).Rows)
                {
                    try {
                        // check - count
                        int?count = is_count ? int.Parse(pg.dt_from_id("count", "", "", null, dr, true, sch.root_node).Rows[0][0].ToString()): (int?)null;
                        Dictionary <string, string> values = null;
                        if (is_check)
                        {
                            DataTable dt = pg.dt_from_id("check", "", "", null, dr, true, sch.root_node);
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                values = new Dictionary <string, string>();
                                foreach (DataColumn dc in dt.Columns)
                                {
                                    values.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
                                }
                            }
                        }

                        // ins - upd rows
                        if ((is_count && count.Value == 0) || (is_check && values == null))
                        {
                            inserted += pg.exec_updates("ins", "", values, dr, sch.root_node);
                        }
                        else if ((is_count && count.Value > 0) || (is_check && values != null))
                        {
                            updated += pg.exec_updates("upd", "", values, dr, sch.root_node);
                        }
                    } catch { err++; }
                    elab++;
                }
            } catch (Exception ex) { throw ex; } finally { if (db != null)
                                                           {
                                                               pg.exec_updates("after", "", null, null, sch.root_node);
                                                           }
            }
        }
Beispiel #5
0
        protected string desElement(deeper.db.db_schema db, string table, string fldprimary, string value)
        {
            deeper.db.meta_table metatbl = db.meta_doc.meta_tbl(table);
            if (!_exists)
            {
                return(metatbl.single);
            }

            string sqlfields = "", sqljoins = "";

            foreach (KeyValuePair <string, Dictionary <string, string> > col
                     in db.meta_doc.tableCols(table, new List <meta_doc.col_type> { /*meta_doc.col_type.diretta, */
                meta_doc.col_type.linked, meta_doc.col_type.info
            }))                                                                     // false, true, true, false, true
            {
                if (bool.Parse(col.Value["diretta"]))
                {
                    sqlfields += " tbl.[" + col.Key + "], ";
                }
                else if (bool.Parse(col.Value["linked"]))
                {
                    string indice = col.Value["indice"], lnktable = col.Value["linkedtable"];

                    if (col.Value["linkedtype"] == "list")
                    {
                        sqlfields += fnc_ids(db, table, lnktable, "tbl.[" + col.Key + "]")
                                     + " AS [" + col.Key + "_" + lnktable + "], ";
                    }
                    else
                    {
                        sqljoins += " left join [" + lnktable + "] tbl" + indice + " ON "
                                    + " tbl" + indice + ".[" + db.schema.pkOfTable(lnktable) + "] = tbl.[" + col.Key + "] ";

                        // colonne dirette linkedtable
                        Dictionary <string, Dictionary <string, string> > cols2 = db.meta_doc.tableCols(lnktable, new List <meta_doc.col_type> {
                            meta_doc.col_type.diretta, meta_doc.col_type.info
                        });                                                                                                                                                            // false, true, false, false, true
                        foreach (KeyValuePair <string, Dictionary <string, string> > col2 in cols2)
                        {
                            if (bool.Parse(col2.Value["diretta"]))
                            {
                                sqlfields += " tbl" + indice + ".[" + col2.Key + "] AS [" + col2.Key + "_" + lnktable + "], ";
                            }
                        }
                    }
                }
            }

            System.Data.DataTable dt = db.dt_table("select " + sqlfields.Substring(0, sqlfields.Length - 2)
                                                   + " from [" + table + "] tbl " + sqljoins + " where tbl.[" + fldprimary + "] = " + value);

            string result = "";

            foreach (System.Data.DataColumn col in dt.Columns)
            {
                result += dt.Rows[0][col.ColumnName].ToString() != "" ?
                          (result != "" ? ", " : "") + dt.Rows[0][col.ColumnName].ToString() : "";
            }

            return(result != "" ? metatbl.single + ": " + result : metatbl.single);
        }
Beispiel #6
0
        protected xmlDoc addGrid(deeper.db.db_schema db, xmlDoc page_doc, string table, string id, string title, string tab = "", meta_link.types_link type_link = meta_link.types_link.normal
                                 , string primaryfield = "", string value = "", string operatore = "=", bool with_dip = false, bool with_linked = false, bool delCol = false, string par_subst_key = "iddtbl"
                                 , Dictionary <string, Dictionary <string, string> > actions = null)
        {
            string  pk_table = db.schema.pkOfTable(table);
            XmlNode grid     = page_doc.add_xml("/page/contents", "<grid name='" + id + "' title=\"" + title + "\" "
                                                + " selects='load' pagesize='15' " + (tab != "" ? " tab='" + tab + "'" : "") + " top='100'/>");

            // cols, query
            deeper.db.meta_table metatbl = db.meta_doc.meta_tbl(table);
            Dictionary <string, Dictionary <string, string> > grd_cols = db.meta_doc.tableCols(table, new List <meta_doc.col_type> {
                meta_doc.col_type.primary, /*meta_doc.col_type.diretta,*/ meta_doc.col_type.info
            });
            XmlNode cols = xmlDoc.add_xml(grid, db.schema.there_pk(table) ? "<cols key='" + pk_table.ToLower() + "(" + par_subst_key + ")'/>" : "<cols/>");
            string  sqlfields = "", sqljoins = "";

            if (grd_cols.Count > 0)
            {
                //sqlfields += "tbl.[" + pk_table + "], ";

                // colonne dirette
                foreach (KeyValuePair <string, Dictionary <string, string> > item in grd_cols)
                {
                    // colonne linked
                    if (item.Value["linkedtable"] != "")
                    {
                        string lnktable = item.Value["linkedtable"];

                        if (item.Value["linkedtype"] == "list")
                        {
                            xmlDoc.add_xml(cols, "<col title='" + db.meta_doc.titleCol(item.Key) + "'"
                                           + " field='" + item.Key + "_" + lnktable + "'/>");

                            sqlfields += fnc_ids(db, table, lnktable, "tbl.[" + item.Key + "]")
                                         + " AS [" + item.Key + "_" + lnktable + "], ";
                        }
                        else
                        {
                            string indice = item.Value["indice"];
                            sqljoins += " left join [" + lnktable + "] tbl" + indice + " ON "
                                        + " tbl" + indice + ".[" + db.schema.pkOfTable(lnktable) + "] = tbl.[" + item.Key + "] ";

                            // colonne dirette linkedtable
                            Dictionary <string, Dictionary <string, string> > tblcols = db.meta_doc.tableCols(lnktable, new List <meta_doc.col_type> { /*meta_doc.col_type.diretta, meta_doc.col_type.linked, *//*meta_doc.col_type.service,*/
                                meta_doc.col_type.info
                            });
                            foreach (KeyValuePair <string, Dictionary <string, string> > item2 in tblcols)
                            {
                                string indice2 = item2.Value["indice"], lnktable2 = item2.Value["linkedtable"];

                                if (!bool.Parse(item2.Value["linked"]))
                                {
                                    xmlDoc.add_xml(cols, "<col title='" + titleCol(db.meta_doc, item2.Key, lnktable, item.Key) + "'"
                                                   + " field='" + item.Key + "_" + item2.Key + "_" + lnktable + "'"
                                                   + " type='" + gridTypeCol(db, item2.Value["type"]) + "'/>");

                                    sqlfields += " tbl" + indice + ".[" + item2.Key + "] AS [" + item.Key + "_" + item2.Key + "_" + lnktable + "], ";
                                }
                                else
                                {
                                    if (item2.Value["linkedtype"] == "list")
                                    {
                                        xmlDoc.add_xml(cols, "<col title='" + titleCol(db.meta_doc, item2.Key, lnktable, item.Key) + "'"
                                                       + " field='" + item2.Key + "_" + lnktable2 + "'/>");

                                        sqlfields += fnc_ids(db, lnktable, lnktable2, "tbl" + indice + ".[" + item2.Key + "]")
                                                     + " AS [" + item2.Key + "_" + lnktable2 + "], ";
                                    }
                                    else
                                    {
                                        sqljoins += " left join [" + lnktable2 + "] tbl" + indice + "_" + indice2
                                                    + " ON tbl" + indice + "_" + indice2 + ".[" + db.schema.pkOfTable(lnktable2) + "]"
                                                    + " = tbl" + indice + ".[" + item2.Key + "] ";

                                        Dictionary <string, Dictionary <string, string> > tbl2cols = db.meta_doc.tableCols(lnktable2, new List <meta_doc.col_type> {
                                            meta_doc.col_type.diretta, meta_doc.col_type.info
                                        }, false);
                                        foreach (KeyValuePair <string, Dictionary <string, string> > item3 in tbl2cols)
                                        {
                                            xmlDoc.add_xml(cols, "<col title='" + titleCol(db.meta_doc, item3.Key, lnktable2, item.Key) + "'"
                                                           + " field='" + item.Key + "_" + item2.Key + "_" + item3.Key + "_" + lnktable2 + "'"
                                                           + " type='" + gridTypeCol(db, item3.Value["type"]) + "'/>");

                                            sqlfields += " tbl" + indice + "_" + indice2 + ".[" + item3.Key + "] AS [" + item.Key + "_" + item2.Key + "_" + item3.Key + "_" + lnktable2 + "], ";
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        xmlDoc.add_xml(cols, "<col title='" + db.meta_doc.titleCol(item.Key) + "' field='" + item.Key + "'"
                                       + " type='" + gridTypeCol(db, item.Value["type"]) + "'/>");

                        sqlfields += "tbl.[" + item.Key + "], ";
                    }
                }

                // colonne di servizio
                foreach (KeyValuePair <string, Dictionary <string, string> > item in
                         db.meta_doc.tableCols(table, new List <meta_doc.col_type> {
                    meta_doc.col_type.service
                }))
                {
                    xmlDoc.add_xml(cols, "<col title='" + db.meta_doc.titleCol(item.Key) + "' field='" + item.Key + "'"
                                   + " type='" + gridTypeCol(db, item.Value["type"]) + "'/>");

                    sqlfields += "tbl.[" + item.Key + "], ";
                }

                // colonna dipendenze
                if (with_dip)
                {
                    xmlDoc.add_xml(cols, "<col title='Dipendenze' field='dipendenze' type='integer'/>");

                    string flddip = "";
                    foreach (deeper.db.meta_link lnk in db.meta_doc.table_links(table))
                    {
                        flddip += (flddip != "" ? " union all " : "") + "select count(*) as conteggio from [" + lnk.table_link + "] "
                                  + (lnk.type == meta_link.types_link.list ? " where charindex('[' + cast(tbl.[" + pk_table + "] as varchar) + ']', [" + lnk.field + "]) > 0"
                : " where [" + lnk.field + "] = tbl.[" + pk_table + "]");
                    }

                    sqlfields += flddip != "" ? string.Format("(select sum(conteggio) from ({0}) tblconteggi) as Dipendenze, ", flddip) : "(select 0) as Dipendenze, ";
                }

                if (with_linked)
                {
                    xmlDoc.add_xml(cols, "<action des='elementi correlati...' icon='mif-arrow-right' type='linked' primarykey='" + pk_table + "'/>");
                }

                // colonna azioni
                if (actions != null)
                {
                    foreach (KeyValuePair <string, Dictionary <string, string> > act in actions)
                    {
                        xmlDoc.add_xml(cols, "<action action='" + act.Key + "' des=\"" + act.Value["des"] + "\" pageref=\"" + act.Value["url"] + "\" icon='" + act.Value["icon"] + "'/>");
                    }
                }

                // colonna di eliminazione singolo elemento
                if (delCol)
                {
                    xmlDoc.add_xml(cols, "<action des=\"elimina " + metatbl.single + "...\" "
                                   + " icon='mif-cross' primarykey='" + pk_table + "'/>");
                }
            }
            else
            {
                // colonne dirette
                foreach (db.schema_field fld in db.table_fields(table))
                {
                    xmlDoc.add_xml(cols, "<col title='" + db.meta_doc.titleCol(fld.Name) + "' field='" + fld.Name + "'"
                                   + " type='" + gridTypeCol(db, fld.OriginalType) + "'/>");

                    sqlfields += "tbl.[" + fld.Name + "], ";
                }
            }

            if (sqlfields != "")
            {
                xmlDoc.set_attr(xmlDoc.add_node(xmlDoc.add_node(grid, "queries"), "select"), "name", "load")
                .InnerText = "select " + sqlfields.Substring(0, sqlfields.Length - 2) + " from [" + table + "] tbl " + sqljoins
                             + (primaryfield != "" && operatore != "" && value != "" ? (type_link == meta_link.types_link.list && operatore == "=" ?
                                                                                        "where charindex('[" + value + "]', [" + primaryfield + "]) > 0" : " where tbl.[" + primaryfield + "] " + operatore + " " + value) : "");
            }

            return(page_doc);
        }
Beispiel #7
0
        protected string parse_text(string text, string cname = "", Dictionary <string, string> fields = null
                                    , System.Xml.XmlNode row  = null, System.Data.DataRow dr           = null, System.Web.UI.WebControls.GridViewRow container = null
                                    , bool exclude_method     = false, db_schema db = null)
        {
            try {
                string result = text;
                if (text == "" || text == null)
                {
                    return(result);
                }

                // {@cond='<SCRIPT NAME>'}
                while (result.IndexOf("{@cond") >= 0)
                {
                    int startPar = result.IndexOf("{@cond='") + 8;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par = result.Substring(startPar, endPar - startPar);
                    result = result.Replace("{@cond='" + par + "'}", _page.code_cond_id(cname, par));
                }

                // {@text_qry='<ID UNIVOCO QUERY>'}
                while (result.IndexOf("{@text_qry") >= 0)
                {
                    int startPar = result.IndexOf("{@text_qry='") + 12;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par = result.Substring(startPar, endPar - startPar);
                    result = result.Replace("{@text_qry='" + par + "'}", _page.classPage.qry_text(par, cname));
                }

                // {@res_qry='<ID UNIVOCO QUERY>'}
                while (result.IndexOf("{@res_qry") >= 0)
                {
                    int startPar = result.IndexOf("{@res_qry='") + 11;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par = result.Substring(startPar, endPar - startPar);
                    System.Data.DataTable dt = _page.classPage.dt_from_id(par, cname, "", fields, dr, true);
                    result = result.Replace("{@res_qry='" + par + "'}", dt != null && dt.Rows.Count > 0 && dt.Rows[0][0] != DBNull.Value ? dt.Rows[0][0].ToString() : "");
                }

                // {@siteurl}
                while (result.IndexOf("{@siteurl}") >= 0)
                {
                    if (_page == null)
                    {
                        throw new Exception("non è specificata la pagina web per la parsificazione dell'espressione '" + text + "'");
                    }

                    result = result.Replace("{@siteurl}", _page.getRootUrl());
                }

                // {@approot}
                while (result.IndexOf("{@approot}") >= 0)
                {
                    result = result.Replace("{@approot}", _page.approot);
                }

                // {@ctrlname}
                while (result.IndexOf("{@ctrlname}") >= 0)
                {
                    if (cname == "")
                    {
                        throw new Exception("non è stato specificato il nome del controllo per la parsificazione dell'espressione '" + text + "'");
                    }

                    result = result.Replace("{@ctrlname}", cname);
                }

                // {@usr_type}
                while (result.IndexOf("{@usr_type}") >= 0)
                {
                    result = result.Replace("{@usr_type}", _page.userTypeLogged);
                }

                // {@usr_childs}
                while (result.IndexOf("{@usr_childs}") >= 0)
                {
                    result = result.Replace("{@usr_childs}", _page.userChilds.ToString());
                }

                // {@pagename}
                while (result.IndexOf("{@pagename}") >= 0)
                {
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave {@activepage}");
                    }

                    result = result.Replace("{@pagename}", _page.pageName);
                }

                // {@activepage}
                while (result.IndexOf("{@activepage}") >= 0)
                {
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave {@activepage}");
                    }

                    result = result.Replace("{@activepage}", _page.getCurrentUrl());
                }

                // {@currurl}
                while (result.IndexOf("{@currurl}") >= 0)
                {
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave {@currurl}");
                    }

                    result = result.Replace("{@currurl}", _page.getCurrentUrl(true));
                }

                // {@currurlargs='<LIST ARGUMENTS>'}
                while (result.IndexOf("{@currurlargs") >= 0)
                {
                    int startPar = result.IndexOf("{@currurlargs='") + 15;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave {@currurlargs='...'}");
                    }

                    string par = result.Substring(startPar, endPar - startPar);

                    result = result.Replace("{@currurlargs='" + par + "'}", strings.combineurl(_page.getCurrentUrl(true), par));
                }

                // {@qrypar_def='<QUERY STRING PARAMETER>'}
                while (result.IndexOf("{@qrypar_def") >= 0)
                {
                    int startPar = result.IndexOf("{@qrypar_def='") + 14;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par   = result.Substring(startPar, endPar - startPar);
                    string value = _page.query_param(par);
                    result = result.Replace("{@qrypar_def='" + par + "'}", !string.IsNullOrEmpty(value) ? value : "''");
                }

                // {@qrypar='<QUERY STRING PARAMETER>'}
                while (result.IndexOf("{@qrypar") >= 0)
                {
                    int startPar = result.IndexOf("{@qrypar='") + 10;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par   = result.Substring(startPar, endPar - startPar);
                    string value = _page.query_param(par);
                    result = result.Replace("{@qrypar='" + par + "'}", value);
                }

                // {@valpar='<QUERY STRING PARAMETER>'}
                while (result.IndexOf("{@valpar") >= 0)
                {
                    int startPar = result.IndexOf("{@valpar='") + 10;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par   = result.Substring(startPar, endPar - startPar);
                    string value = _page.query_param(par);
                    result = result.Replace("{@valpar='" + par + "'}", string.IsNullOrEmpty(value) ? "0" : "1");
                }

                // {@qrykey='<QUERY STRING PARAMETER>'}
                while (result.IndexOf("{@qrykey") >= 0)
                {
                    int startPar = result.IndexOf("{@qrykey='") + 10;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par = result.Substring(startPar, endPar - startPar);
                    result = result.Replace("{@qrykey='" + par + "'}", _page.keystr(par) != "" ? _page.key(par).ToString() : "0");
                }

                // {@qryfields='<TABLE NAME>'}
                while (result.IndexOf("{@qryfields") >= 0)
                {
                    int startPar = result.IndexOf("{@qryfields='") + 13;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null || cname == "")
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par = result.Substring(startPar, endPar - startPar);

                    deeper.db.db_schema dbl = _page.conn_db_user();
                    if (!db.exist_schema)
                    {
                        throw new Exception("il database '" + dbl.name + "' non ha associato nessuno schema xml!");
                    }

                    string value = "";
                    foreach (string col_name in dbl.schema.fields_name(par))
                    {
                        value += (value != "" ? ", " : "") + "[" + col_name + "]";
                    }

                    if (value == "")
                    {
                        throw new Exception("il parametro '" + par + "' della stringa url dev'essere valorizzato!");
                    }
                    result = result.Replace("{@qryfields='" + par + "'}", value);
                }
                // {@var='<NAME VAR>'}
                while (result.IndexOf("{@var") >= 0)
                {
                    int startPar = result.IndexOf("{@var='") + 7;
                    int endPar   = result.IndexOf("'}", startPar);

                    string par = result.Substring(startPar, endPar - startPar);
                    result = result.Replace("{@var='" + par + "'}", _page.cfg_var(par));
                }

                // {@attr='<ATTRIBUTE NAME XML NODE>'}
                while (result.IndexOf("{@attr") >= 0)
                {
                    int    startPar = result.IndexOf("{@attr='") + 8;
                    int    endPar   = result.IndexOf("'}", startPar);
                    string attr     = result.Substring(startPar, endPar - startPar);

                    if (row == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string value = "";
                    if (row.Attributes[attr] != null)
                    {
                        value = row.Attributes[attr].Value;
                    }

                    result = result.Replace("{@attr='" + attr + "'}", value);
                }

                // {@node='<NODE NAME XML NODE>'}
                while (result.IndexOf("{@node") >= 0)
                {
                    int startPar = result.IndexOf("{@node='") + 8;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (row == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }
                    string node = result.Substring(startPar, endPar - startPar);

                    string value = "";
                    if (row.SelectSingleNode(node) != null)
                    {
                        value = row.SelectSingleNode(node).InnerText;
                    }

                    result = result.Replace("{@node='" + node + "'}", value);
                }

                // {@pagerefargs='<PAGE NAME>','<LIST ARGUMENTS>'}
                while (result.IndexOf("{@pagerefargs") >= 0)
                {
                    int startPar = result.IndexOf("{@pagerefargs=") + 14;
                    int endPar   = result.IndexOf("}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string contents = result.Substring(startPar, endPar - startPar);

                    string value = "";
                    {
                        bool     first = true;
                        string[] pars  = contents.Split(',');
                        foreach (string par in pars)
                        {
                            string arg = par.Substring(1, par.Length - 2);
                            if (first)
                            {
                                value = _page.getPageRef(arg);
                                first = false;
                            }
                            else
                            {
                                value = strings.combineurl(value, arg);
                            }
                        }
                    }

                    result = result.Replace("{@pagerefargs=" + contents + "}", value);
                }

                // {@pageref='<PAGE NAME>'}
                while (result.IndexOf("{@pageref") >= 0)
                {
                    int startPar = result.IndexOf("{@pageref='") + 11;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par   = result.Substring(startPar, endPar - startPar);
                    string value = _page.getPageRef(par);

                    result = result.Replace("{@pageref='" + par + "'}", value);
                }

                // {@qrypar='<QUERY STRING PARAMETER>'}
                while (result.IndexOf("{@qrypar") >= 0)
                {
                    int startPar = result.IndexOf("{@qrypar='") + 10;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par   = result.Substring(startPar, endPar - startPar);
                    string value = _page.query_param(par);
                    result = result.Replace("{@qrypar='" + par + "'}", value);
                }

                // {@siteurl='<SITE NAME>'}
                while (result.IndexOf("{@siteurl='") >= 0)
                {
                    int startPar = result.IndexOf("{@siteurl='") + 11;
                    int endPar   = result.IndexOf("'}", startPar);

                    string par = result.Substring(startPar, endPar - startPar);
                    result = result.Replace("{@siteurl='" + par + "'}"
                                            , _page.cfg_value("/root/websites/website[@name='" + par + "']", "url"));
                }

                // {@imageurl='<IMAGE NAME>'}
                while (result.IndexOf("{@imageurl='") >= 0)
                {
                    int startPar = result.IndexOf("{@imageurl='") + 12;
                    int endPar   = result.IndexOf("'}", startPar);

                    string par   = result.Substring(startPar, endPar - startPar);
                    string value = get_string(_page.cfg_value("/root/images/image[@name='" + par + "']", "url"), cname, fields, row, dr);
                    result = result.Replace("{@imageurl='" + par + "'}", value);
                }

                // {@pagetitle=''}
                while (result.IndexOf("{@pagetitle='") >= 0)
                {
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave {@pagetitle=''}");
                    }

                    int    startPar = result.IndexOf("{@pagetitle='") + 13, endPar = result.IndexOf("'}", startPar);
                    string par = result.Substring(startPar, endPar - startPar);

                    result = result.Replace("{@pagetitle='" + par + "'}"
                                            , _page.classPage.titlePage(_page.cfg_node("/root/pages/page[@name='" + par + "']"), fields, row, dr));
                }

                // {@desPage}
                while (result.IndexOf("{@pagedes='") >= 0)
                {
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave {@pagedes=''}");
                    }

                    int    startPar = result.IndexOf("{@pagedes='") + 11, endPar = result.IndexOf("'}", startPar);
                    string par = result.Substring(startPar, endPar - startPar)
                    , des      = _page.classPage.desPage(_page.cfg_node("/root/pages/page[@name='" + par + "']"), fields, row, dr);

                    result = result.Replace("{@pagedes='" + par + "'}", des != "" ? des : "&nbsp;");
                }

                // {@field='<FIELD NAME>'}, {@field='<FORM NAME.FIELD NAME>'}
                while (result.IndexOf("{@field") >= 0)
                {
                    int    startPar = result.IndexOf("{@field='") + 9;
                    int    endPar   = result.IndexOf("'}", startPar);
                    string src      = result.Substring(startPar, endPar - startPar);
                    string field    = src.IndexOf('.') >= 0 ? src.Substring(src.IndexOf('.') + 1) : src;
                    string formname = src.IndexOf('.') >= 0 ? src.Substring(0, src.IndexOf('.')) : "";

                    string value = null;
                    if (container != null)
                    {
                        value = System.Web.UI.DataBinder.Eval(container.DataItem, field).ToString();
                    }
                    if (value == null && (_page != null && (formname != "" || cname != "")) &&
                        _page.classPage.existControl(formname != "" ? formname : cname) && !_page.classPage.control(formname != "" ? formname : cname).fieldValue(field, out value))
                    {
                        value = null;
                    }
                    if (value == null && (fields != null && fields.ContainsKey(field)))
                    {
                        value = fields[field];
                    }
                    if (value == null && (dr != null && dr[field] != null))
                    {
                        value = dr[field].ToString();
                    }

                    if (value != null)
                    {
                        result = result.Replace("{@field='" + src + "'}", value);
                    }
                    else
                    {
                        throw new Exception("non è stato possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }
                }

                // {@datefld='<FIELD NAME>','<FORMAT>'}
                while (result.IndexOf("{@datefld") >= 0)
                {
                    int    startPar = result.IndexOf("{@datefld=") + 10;
                    int    endPar   = result.IndexOf("}", startPar);
                    string field    = result.Substring(startPar, endPar - startPar).Split(',')[0];
                    field = field.Substring(1, field.Length - 2);
                    string format = result.Substring(startPar, endPar - startPar).Split(',')[1];
                    format = format.Substring(1, format.Length - 2);
                    _page.classPage.formatDates(format, out format);

                    // valore della form o dei campi passati da codice
                    if (_page != null && fields == null)
                    {
                        if (cname == "")
                        {
                            throw new Exception("l'espressione '" + text + "' non può essere valutata senza specificare il controllo d'appartenenza.");
                        }

                        string value = null;
                        if (container != null)
                        {
                            value = System.Web.UI.DataBinder.Eval(container.DataItem, field).ToString();
                        }
                        if (value == null && (_page != null && cname != "") &&
                            _page.classPage.existControl(cname) && !_page.classPage.control(cname).fieldValue(field, out value))
                        {
                            value = null;
                        }
                        if (value == null && (dr != null && dr[field] != null))
                        {
                            value = dr[field].ToString();
                        }
                        if (value == null && (fields != null && fields.ContainsKey(field)))
                        {
                            value = fields[field];
                        }

                        if (!string.IsNullOrEmpty(value))
                        {
                            value = DateTime.Parse(value).ToString(format);
                        }

                        result = result.Replace("{@datefld=" + result.Substring(startPar, endPar - startPar) + "}", value);
                    }
                    else if (fields != null)
                    {
                        if (!fields.ContainsKey(field))
                        {
                            throw new Exception("non è stato specificato il campo '" + field + "' richiesto dalla espressione '" + text + "'");
                        }

                        string value = fields[field];

                        if (value != "")
                        {
                            value = DateTime.Parse(value).ToString(format);
                        }

                        result = result.Replace("{@datefld=" + result.Substring(startPar, endPar - startPar) + "}", value);
                    }
                    else
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }
                }

                // {@qry????='<FIELD NAME>'}
                foreach (string type in (new string[10] {
                    "Text", "EqText", "Void", "Numb", "Euro", "Migl", "Real", "Flag", "Date", "EqDate"
                }))
                {
                    while (result.IndexOf("{@qry" + type) >= 0)
                    {
                        int    startPar = result.IndexOf("{@qry" + type + "='") + (7 + type.Length);
                        string flds     = result.Substring(startPar, result.IndexOf("'}", startPar) - startPar);

                        // valore dalla form o dei campi passati da codice
                        string value = null;
                        foreach (string f in flds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (_page != null && cname != "" &&
                                _page.classPage.existControl(cname) && !_page.classPage.control(cname).fieldValue(f, out value, type == "Text" || type == "EqText" || type == "Void"))
                            {
                                value = null;
                            }
                            if (value == null && container != null)
                            {
                                value = System.Web.UI.DataBinder.Eval(container.DataItem, f).ToString();
                            }
                            if (value == null && (dr != null && dr.Table.Columns.Contains(f)))
                            {
                                value = dr[f].ToString();
                            }
                            if (value == null && (fields != null && fields.ContainsKey(f)))
                            {
                                value = fields[f];
                            }

                            if (value != null)
                            {
                                break;
                            }
                        }

                        // parse valore da inserire nella query
                        if (value == "" || value == null)
                        {
                            value = type == "Void" ? "''" : (type == "EqDate" || type == "EqText" ? "is NULL" : "NULL");
                        }
                        else
                        {
                            if (type == "Flag")
                            {
                                value = value.ToLower() == "false" || value.ToLower() == "falso" || value.ToLower() == "0" ? "0" : "1";
                            }
                            else if (type == "Text" || type == "EqText" || type == "Void")
                            {
                                value = (type == "EqText" ? " = " : "") + "'" + value.Replace("'", "''") + "'";
                            }
                            else if (type == "Date" || type == "EqDate")
                            {
                                value = (type == "EqDate" ? " = " : "") + "'"
                                        + DateTime.Parse(value).ToString(_page != null && _page.conn_db_user() != null
                  ? _page.conn_db_user().dateFormatToQuery : "") + "'";
                            }
                            else if (type == "Euro" || type == "Migl")
                            {
                                value = page_ctrl.euroToDouble(value)
                                        .ToString(System.Globalization.CultureInfo.GetCultureInfo("en-GB"));
                            }
                            else if (type == "Real")
                            {
                                value = double.Parse(value)
                                        .ToString(System.Globalization.CultureInfo.GetCultureInfo("en-GB"));
                            }
                        }

                        result = result.Replace("{@qry" + type + "='" + flds + "'}", value);
                    }
                }

                // function

                // {@property='<PROPERTY NAME PAGE>'}
                while (result.IndexOf("{@property") >= 0)
                {
                    int startPar = result.IndexOf("{@property='") + 12;
                    int endPar   = result.IndexOf("'}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }

                    string par = result.Substring(startPar, endPar - startPar);

                    System.Reflection.PropertyInfo pi = _page.GetType().GetProperty(par);
                    if (pi == null)
                    {
                        throw new Exception("la proprietà '" + par + "' non esiste!");
                    }

                    result = result.Replace("{@property='" + par + "'}", pi.GetValue(_page, null).ToString());
                }

                // {@method='<method name>',<type argument>:<value argument>}
                while (!exclude_method && result.IndexOf("{@method") >= 0)
                {
                    int startPar = result.IndexOf("{@method='") + 10;
                    int endPar   = result.IndexOf("}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + result.Substring(startPar, endPar - startPar));
                    }
                    string pars = result.Substring(startPar - 1, (endPar - startPar) + 1);

                    result = result.Replace("{@method=" + pars + "}", invoke_method(result, db).ToString());
                }

                return(result);
            } catch (Exception ex) { _page.logErr("parseExpression: '" + text + "'"); throw ex; }
        }