Пример #1
0
    protected void refresh_scripts(db_schema db)
    {
        scripts_row.Visible = db != null && db.ver != "";
        if (!scripts_row.Visible)
        {
            return;
        }

        // elenco scripts
        string group = conn_group(db.name).Attributes["name"].Value;

        if (group != scriptsGroup.Value)
        {
            scripts.Items.Clear();
            foreach (db_script scr in group_scripts(group))
            {
                scripts.Items.Add(new ListItem((new xmlDoc(scr.path)).root_value("title"), scr.name));
            }

            scriptsGroup.Value = group;
            scripts_onsel(null, null);
        }

        btnExecScript.Visible = scripts.SelectedValue != "";
    }
Пример #2
0
 protected string fnc_ids(db_schema db, string main_table, string table, string field)
 {
     return(_page.parse(db.meta_doc.functionIds(table, field)
                        , new Dictionary <string, string>()
     {
         { "main_tbl", main_table }, { "field_ids", field }
     }, db));
 }
Пример #3
0
        public void xmldata_to_table(db_schema db, string table)
        {
            List <schema_field> cols = db.table_fields(table);

            // cols
            using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(data_path(table), "/root/data")) {
                if (xr.ReadUntilMatch())
                {
                    while (xr.MoveToNextAttribute())
                    {
                        schema_field field = findField(cols, xr.Value);
                        if (field == null)
                        {
                            continue;
                        }
                        field.AttrName = xr.Name;
                    }
                }
                else
                {
                    throw new Exception("la struttura xml del file data della tabella '" + table + "' non è corretta");
                }
            }

            // insert rows
            bool identity = db.type == dbType.sqlserver && cols.FirstOrDefault(x => x.AutoNumber) != null;

            if (identity)
            {
                db.set_identity(table, true);
            }
            try {
                using (GotDotNet.XPath.XPathReader xr = new GotDotNet.XPath.XPathReader(data_path(table), "/root/rows/row")) {
                    string header = string.Format("INSERT INTO {0} ({1})", table, string.Join(", ", cols.Select(x => "[" + x.Name + "]")));
                    while (xr.ReadUntilMatch())
                    {
                        db.exec(header + " VALUES (" + string.Join(", ", cols.Select(x => db.val_toqry(xr[x.AttrName], x.TypeField, type, _nullxml))) + ")");
                    }
                }
            }
            finally { if (identity)
                      {
                          db.set_identity(table, false);
                      }
            }
        }
Пример #4
0
        protected object invoke_method(string text, db_schema db = null)
        {
            try {
                // {@method='<method name>',<type argument>:<value argument>}
                if (text.IndexOf("{@method") >= 0)
                {
                    int startPar = text.IndexOf("{@method='") + 10;
                    int endPar   = text.IndexOf("}", startPar);
                    if (_page == null)
                    {
                        throw new Exception("non è possibile parsificare la parola chiave " + text.Substring(startPar, endPar - startPar));
                    }
                    string pars = text.Substring(startPar - 1, (endPar - startPar) + 1);

                    System.Reflection.MethodInfo mi = null;
                    List <object> lstpar            = new List <object>();
                    foreach (string item in pars.Split(','))
                    {
                        if (mi == null)
                        {
                            mi = _page.funcs.GetType().GetMethod(item.Substring(1, item.Length - 2));
                            if (mi == null)
                            {
                                throw new Exception("il metodo '" + item.Substring(1, item.Length - 2) + "' non è stato trovato!");
                            }
                            continue;
                        }

                        string type  = item.IndexOf(':') > 0 ? item.Substring(0, item.IndexOf(':')) : "string";
                        string value = item.IndexOf(':') > 0 ? item.Substring(item.IndexOf(':') + 1, item.Length - item.IndexOf(':') - 1) : item;
                        lstpar.Add(type == "string" ? (object)value : type == "int" ? (object)int.Parse(value) : null);
                    }

                    _page.funcs.set_active_db(db);

                    return(lstpar.Count == 0 ? mi.Invoke(_page.funcs, null) : mi.Invoke(_page.funcs, lstpar.ToArray()));
                }

                return(null);
            } finally { if (_page != null)
                        {
                            _page.funcs.set_active_db(null);
                        }
            }
        }
Пример #5
0
    public void init_infos_onclick(Object sender, EventArgs e)
    {
        try {
            db_schema db = conn_db(_dbname);
            if (db.ver == "")
            {
                if (!db.exist_info)
                {
                    db.create_table(db_schema.open_schema(db.cur_ver, db.schema_path).table_node("__infos"));
                }
                db.setInfo("ver", db.cur_ver, 0, "inizializzazione tabella infos");
            }
        } catch (Exception ex) {
            classPage.regScript(classPage.scriptStartAlert("Si è verificato un errore: " + ex.Message, "Pulizia tabelle storico"));
        }

        initCtrls();
    }
Пример #6
0
    public void reset_users_onclick(Object sender, EventArgs e)
    {
        try {
            db_schema db      = conn_db(_dbname);
            db_schema base_db = conn_db_base();
            string    reason  = "";
            cfg_var("user_tables").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()
            .ForEach(tbl => { if (!db.init_table(tbl.Trim(), base_db, out reason))
                              {
                                  throw new Exception(reason);
                              }
                     });

            classPage.regScript(classPage.scriptStartAlert("Tabelle utente inizializzate con successo!", "Copia impostazioni utenti"));
        } catch (Exception ex) { classPage.regScript(classPage.scriptStartAlert("Si è verificato un errore: " + ex.Message, "Inizializzazione utenti")); }

        initCtrls();
    }
Пример #7
0
        public db_schema conn_db(string name_conn, bool open = true, bool reconnect = false, string throw_msg = "")
        {
            if (string.IsNullOrEmpty(name_conn))
            {
                if (throw_msg != "")
                {
                    throw new Exception(throw_msg);
                }
                else
                {
                    throw new Exception("non hai specificato la connessione da aprire!");
                }
            }

            // vedo se la connessione è già stata aperta
            if (_dbconns.ContainsKey(name_conn))
            {
                if (!reconnect)
                {
                    return(_dbconns[name_conn]);
                }
                else
                {
                    _dbconns[name_conn].close_conn();
                    _dbconns.Remove(name_conn);
                }
            }

            XmlNode   dbconn  = conn_node(name_conn);
            db_schema newconn = db_schema.create_provider(name_conn, web_conn(name_conn), web_conn_provider(name_conn), xmlDoc.node_val(conn_group(name_conn), "curver")
                                                          , cfg_value_int("/root/dbconns", "timeout", -1), xmlDoc.node_val(dbconn, "group"), xmlDoc.node_val(dbconn, "language"), xmlDoc.node_val(dbconn.SelectSingleNode("formats"), "datetoquery")
                                                          , xmlDoc.node_val(dbconn.SelectSingleNode("formats"), "datetoquery2"), xmlDoc.node_val(dbconn, "des")
                                                          , schema_path_fromconn(name_conn, false), schema_path_fromconn(name_conn, false, false, true), group_scripts(xmlDoc.node_val(dbconn, "group")));

            _dbconns.Add(name_conn, newconn);

            if (open)
            {
                newconn.open_conn();
            }

            return(newconn);
        }
Пример #8
0
    protected void refresh_backups(db_schema db)
    {
        mount_row.Visible = db != null && db.ver != "";
        if (!mount_row.Visible)
        {
            return;
        }

        // elenco backups
        string group = conn_group(db.name).Attributes["name"].Value;

        if (group != bcksGroup.Value)
        {
            bcks.Items.Clear();
            string idx = System.IO.Path.Combine(cfg_var("backupsFolder"), cfg_var("fsIndex"));
            if (File.Exists(idx))
            {
                xmlDoc doc = new xmlDoc(idx);
                foreach (System.Xml.XmlNode file in doc.nodes("/root/files/file[@type='db-backup']")
                         .Cast <XmlNode>().OrderByDescending(x => x.Attributes["date"].Value))
                {
                    XmlNode cg = conn_group(file.SelectSingleNode("infos/info[@name='conn']").InnerText, false);
                    if (cg != null && group == cg.Attributes["name"].Value)
                    {
                        bcks.Items.Add(new ListItem(file.Attributes["title"].Value
                                                    + " - del: " + DateTime.Parse(file.Attributes["date"].Value).ToString(classPage.formatDates("dataEstesa"))
                                                    + (file.SelectSingleNode("infos/info[@name='conn']") != null ? " - conn.: " + file.SelectSingleNode("infos/info[@name='conn']").InnerText : "")
                                                    + (file.SelectSingleNode("infos/info[@name='ver']") != null ? " - ver.: " + file.SelectSingleNode("infos/info[@name='ver']").InnerText : "")
                                                    , file.Attributes["idfile"].Value));
                    }
                }
            }
            bcksGroup.Value = group;
        }

        btnMount.Visible     = bcks.SelectedValue != "";
        btnMountData.Visible = bcks.SelectedValue != "";
    }
Пример #9
0
        protected void for_each_table(db_schema conn, db_script_cmd cmd)
        {
            // filtri
            string[] filter = cmd.attr("filter_type").Split(new char[] { ',' }
                                                            , StringSplitOptions.RemoveEmptyEntries);
            string[] exclude = cmd.attr("exclude").ToLower().Split(new char[] { ',' }
                                                                   , StringSplitOptions.RemoveEmptyEntries);
            bool no_enums = cmd.attr_bool("exclude_enums");

            // ciclo tabelle
            foreach (string tbl in conn.tables())
            {
                if (filter == null || (filter != null && (filter.Contains("data") && conn.meta_doc.type_table(tbl) == db.meta_doc.table_type.data ||
                                                          filter.Contains("history") && conn.meta_doc.type_table(tbl) == db.meta_doc.table_type.storico)) &&
                    (exclude == null || (exclude != null && !exclude.Contains(tbl.ToLower()))) &&
                    (!no_enums || (no_enums && !conn.meta_doc.enum_tbl(tbl))))
                {
                    foreach (db_script_cmd sub_cmd in cmd.sub_cmds)
                    {
                        if (sub_cmd.sub_type == db_script_cmd.cmd_sub_type.remove_idx_ins_on_table)
                        {
                            conn.table_idxs(tbl, true).ForEach(i => {
                                if (i.Fields.Count == 1 && i.Fields[0].Name.ToLower() == conn.meta_doc.field_ins().ToLower())
                                {
                                    conn.drop_index(i.Name, tbl);
                                }
                            });
                        }
                        else if (sub_cmd.sub_type == db_script_cmd.cmd_sub_type.delete_data)
                        {
                            conn.clean_table(tbl);
                        }
                    }
                }
            }
        }
Пример #10
0
        public long exec(db_schema conn, string name_cmd = "", page_cls pg_parse = null, Dictionary <string, string> fields = null, DataRow row = null)
        {
            long result = 0;

            // ciclo comandi
            if (fields == null)
            {
                fields = new Dictionary <string, string>();
            }
            foreach (db_script_cmd cmd in cmds(name_cmd))
            {
                if (cmd.type == db_script_cmd.cmd_type.sql)
                {
                    string sql = pg_parse == null ? cmd.text : pg_parse.page.parse(cmd.text, "", fields, row);
                    if (cmd.attr("setkey") != "")
                    {
                        long key = conn.exec(sql, true); result++;
                        if (!fields.ContainsKey(cmd.attr("setkey")))
                        {
                            fields.Add(cmd.attr("setkey"), key.ToString());
                        }
                        else
                        {
                            fields[cmd.attr("setkey")] = key.ToString();
                        }
                    }
                    else
                    {
                        result += conn.exec(sql);
                    }
                }
                else if (cmd.type == db_script_cmd.cmd_type.init_tables)
                {
                    conn.upgrade_data(new db_xml(new xmlDoc(conn.parse_dbexpression(conn.schema_path, conn.parse_dbexpression(cmd.attr("ver"))))
                                                 , conn.parse_dbexpression(conn.meta_path, conn.parse_dbexpression(cmd.attr("ver")))), false, true, cmd.attr("notes"));
                }
                else if (cmd.type == db_script_cmd.cmd_type.init_table)
                {
                    if (conn.exist_table(cmd.attr("table")))
                    {
                        conn.drop_table(cmd.attr("table"));
                    }
                    conn.create_table(conn.schema.table_node(cmd.attr("table")));
                }
                else if (cmd.type == db_script_cmd.cmd_type.drop_tables)
                {
                    conn.dropTables();
                }
                else if (cmd.type == db_script_cmd.cmd_type.drop_functions)
                {
                    conn.dropFunctions();
                }
                else if (cmd.type == db_script_cmd.cmd_type.drop_procedures)
                {
                    conn.dropProcedures();
                }
                else if (cmd.type == db_script_cmd.cmd_type.exec_script)
                {
                    conn.exec_script(cmd.attr("name"));
                }
                else if (cmd.type == db_script_cmd.cmd_type.for_each_table)
                {
                    for_each_table(conn, cmd);
                }
                else if (cmd.type == db_script_cmd.cmd_type.set_info)
                {
                    conn.setInfo(cmd.attr("name"), conn.parse_dbexpression(cmd.attr("value")), 0, cmd.attr("notes"));
                }
            }

            return(result);
        }
Пример #11
0
 public DataTable dt_from_cmd(db_schema conn, string name_cmd, page_cls pg_parse, DataRow row)
 {
     return(conn.dt_table(pg_parse.page.parse(qry_text(name_cmd), row)));
 }
Пример #12
0
 public DataTable dt_from_cmd(db_schema conn, string name_cmd, page_cls pg_parse, Dictionary <string, string> fields)
 {
     return(conn.dt_table(pg_parse.page.parse(qry_text(name_cmd), fields)));
 }
Пример #13
0
        public string val_to_qry(string field, db_schema db_ref)
        {
            schema_field sfld = get_field(field);

            return(db_ref.val_toqry(_xr[sfld.AttrName], sfld.TypeField, db_schema.null_value));
        }
Пример #14
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; }
        }
Пример #15
0
 public string get_string(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, db_schema db = null)
 {
     return(parse_text(text, cname, fields, row, dr, container, false, db));
 }
Пример #16
0
 public string parse(string text, Dictionary <string, string> fields, db_schema db = null)
 {
     return(_parser.get_string(text, "", fields, null, null, null, db));
 }
Пример #17
0
 public string val_to_qry(string val, string field, db_schema db_ref)
 {
     return(db_ref.val_toqry(val == null ? db_schema.null_value : val, get_field(field).TypeField, db_schema.null_value));
 }
Пример #18
0
 public DataTable dt_from_cmd(db_schema conn, string name_cmd)
 {
     return(conn.dt_table(qry_text(name_cmd)));
 }
Пример #19
0
    protected void initCtrls(bool reconnect = true)
    {
        // inizializzazioni
        conn_des.InnerText  = _dbname != "" ? cfg_value("/root/dbconns/dbconn[@name='" + _dbname + "']", "des") : "";
        view_tables.Visible = view_meta.Visible = view_schema.Visible = title_infos.Visible = import_pocket.Visible
                                                                                                  = gen_schema.Visible = integrita_schema.Visible = upgrade_schema.Visible = init_infos.Visible
                                                                                                                                                                                 = exp_all.Visible = exp_db.Visible = false;
        infos.Controls.Clear();

        // utente
        uid.InnerText   = userLogged;
        utype.InnerText = userTypeLogged;
        uconn.InnerText = userConn;
        try { uvis.InnerText = classPage.user_childs(userId); } catch (Exception ex) { uvis.InnerText = ex.Message; }

        // mi connetto
        db_schema db = null;

        try {
            db = _dbname != "" ? conn_db(_dbname, true, reconnect) : null;
            conn_state.InnerText = "connessione effettuata con successo";
            conn_ver.InnerText   = db.ver == "" ? "versione non presente, è necessario inizializzare le infos!" : db.ver;
            last_ver.InnerText   = _dbname != "" ? conn_curver(_dbname) : "nessun database selezionato";
        } catch (Exception ex) {
            _dbname = "";
            conn_state.InnerText = "non è stato possibile effettuare la connessione: " + ex.Message;
            classPage.regScript(classPage.scriptStartAlert("Si è verificato un errore: " + ex.Message + ". <br><br><b>E' consigliabile un ripristino del database o selezionare una connessione raggiungibile.</b>", "Caricamento pagina"));
        }

        // check utenti
        check_utenti.InnerText = "";
        set_utenti.Visible     = false;
        if (db != null && db.name != base_conn() && xmlDoc.node_val(conn_group(db.name), "name") == "web")
        {
            remove_cfg_style(check_utenti, "rcvry-sec-err");
            check_utenti.InnerText = "ok";
            db_schema base_db = conn_db_base();
            cfg_var("user_tables").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()
            .ForEach(tbl => {
                string reason = "";
                if (!base_db.same_contents(tbl.Trim(), db, out reason))
                {
                    add_cfg_style(check_utenti, "rcvry-sec-err"); check_utenti.InnerText = reason; set_utenti.Visible = true; return;
                }
            });
        }

        // aggiorno i controlli
        try {
            // tables
            if (view_tables.Visible = db != null && db.exist_schema)
            {
                view_tables.HRef = getPageRef("tables_list", "dbname=" + _dbname);
            }

            if (_dbname != "")
            {
                init_infos.Visible = db.ver == "";
                gen_schema.Visible = exp_db.Visible = true;
                exp_all.Visible    = integrita_schema.Visible = db.ver != "";

                // meta
                if (view_meta.Visible = db.exist_meta && File.Exists(schema_path_fromconn(_dbname, false, false, true, db.ver)))
                {
                    view_meta.HRef = schema_path_fromconn(_dbname, false, true, true, db.ver);
                }

                // schema
                if (view_schema.Visible = db.exist_schema && File.Exists(schema_path_fromconn(_dbname, false, false, false, db.ver)))
                {
                    view_schema.HRef = schema_path_fromconn(_dbname, false, true, false, db.ver);
                }

                // infos
                if (db.existInfos())
                {
                    title_infos.Visible = true;
                    foreach (Dictionary <string, string> info in db.getInfos())
                    {
                        ctrlsToParent(infos, new label(info["name"] + ":", "rcvry-sec-subtitle").control
                                      , dd_exclude("name", db.info_story(info["name"])));
                    }
                }

                // pockets
                import_pocket.Visible = true;

                // upgrade schema
                if (db.ver != "" && db.ver != db.cur_ver && db.ver_long < db.cur_ver_long)
                {
                    upgrade_schema.Visible = true;
                }
            }

            // backups
            refresh_backups(db);

            // scripts
            refresh_scripts(db);
        } catch (Exception ex) {
            classPage.regScript(classPage.scriptStartAlert("Si è verificato un errore: " + ex.Message
                                                           + ". <br><br><b>E' consigliabile un ripristino del database o selezionare una connessione raggiungibile.</b>"
                                                           , "Caricamento pagina"));
        }
    }
Пример #20
0
 public void set_active_db(db_schema db)
 {
     _db = db;
 }