Example #1
0
        public override submitResponse submitFormAfterData(string name)
        {
            // aggiunta backup del database
            if (name == "form-backup" && _page.query_param("type") == "ins")
            {
                db_utilities.backupDb(this, ((form_ctrl)control("form-backup")).fieldValue("title"),
                                      ((form_ctrl)control("form-backup")).fieldValue("des"), page.cfg_var("filesFolder"));

                return(submitResponse.ok);
            }
            else if (name == "import-backup")
            {
                // upload pacchetto
                string pathtmp = System.IO.Path.Combine(_page.tmpFolder(), System.IO.Path.GetRandomFileName() + ".gz");
                form_control(name).upload_save("pckfile", pathtmp);

                // estrazione schema
                xmlDoc doc = new xmlDoc(extract_dbpck_index(pathtmp));

                // importazione del pacchetto
                string title = ((form_ctrl)control(name)).fieldValue("titolo");
                string notes = ((form_ctrl)control(name)).fieldValue("notes");
                db_utilities.backupPck(this, pathtmp, doc.root_value("name")
                                       , title != "" ? title : doc.root_value("title", "importazione backup")
                                       , DateTime.Parse(doc.root_value("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")))
                                       , doc.root_value("ver"), notes != "" ? notes : doc.root_value("notes", "importazione backup da pacchetto esterno"));

                System.IO.File.Delete(pathtmp);

                return(submitResponse.ok);
            }

            return(submitResponse.notvalued);
        }
Example #2
0
        public override void add()
        {
            base.add();

            try {
                HtmlControl parentElement = parentOnAdd();
                if (parentElement == null)
                {
                    return;
                }

                // ctrl
                string ctrl = _cls.newIdControl, name = xmlDoc.node_val(_defNode, "name");
                _cls.addHtmlSection(string.Format(@"<table style='{2}'><tr>
              <td style='text-align:left;'>{5}</td><td style='text-align:center;'><span style='font-size:150%;'>{4}</span></td><td style='text-align:right;'>{6}</td></tr>
            <tr><td colspan='3'><div id='{0}' grname='{1}' style='width:100%;{3}'></div></td></tr></table>"
                                                  , ctrl, name, rootAttr("width") != "" ? "width:" + rootAttr("width") + ";" : "width:100%;"
                                                  , rootAttr("height") != "" ? "height:" + rootAttr("height") + ";" : "", rootAttr("title")
                                                  , xmlDoc.node_bool(_defNode, "scroll-x") ? "<span style='border-radius:25px;border:1pt solid;padding:3px;cursor:pointer;' class='mif-arrow-left' onclick=\"scroll_left('" + ctrl + "')\"></span>" : ""
                                                  , xmlDoc.node_bool(_defNode, "scroll-x") ? "<span style='border-radius:25px;border:1pt solid;padding:3px;cursor:pointer;' class='mif-arrow-right' onclick=\"scroll_right('" + ctrl + "')\"></span>" : ""));

                // vars, data
                xmlDoc doc = xmlDoc.create_fromxml("<root><datas/></root>");
                load_data(doc.node("/root/datas"), 0);
                _cls.xml_topage("data_" + name, doc.doc.InnerXml);
            } catch (Exception ex) { _cls.addError(ex); }
        }
Example #3
0
        /// <summary>
        /// Copia files di backup nell'ambiente
        /// </summary>
        public void files_from_backup(string index_path)
        {
            // copio i files in locale
            string bck = Path.GetDirectoryName(index_path), files_doc = Path.Combine(bck, deeper.db.db_schema._filesXml)
            , local = cfg_var("filesFolder"), err_cpy = "";

            if (!Directory.Exists(local))
            {
                Directory.CreateDirectory(local);
            }
            if (Directory.Exists(Path.Combine(bck, db.db_schema._filesFolder)) && File.Exists(files_doc))
            {
                xmlDoc doc_files = new xmlDoc(files_doc);
                doc_files.nodes("/files/file").Cast <XmlNode>().ToList().ForEach(file => {
                    try {
                        string from = Path.Combine(bck, db.db_schema._filesFolder, xmlDoc.node_val(file, "folder"), xmlDoc.node_val(file, "file"))
                        , to        = Path.Combine(local, xmlDoc.node_val(file, "folder"), xmlDoc.node_val(file, "file"))
                        , folder_to = Path.GetDirectoryName(to);
                        logDebug(string.Format("copy file from '{0}' to '{1}'", from, to));
                        if (!Directory.Exists(folder_to))
                        {
                            logDebug(string.Format("creazione folder '{0}'", folder_to));
                            Directory.CreateDirectory(folder_to);
                        }
                        File.Copy(from, to, true);
                    } catch (Exception ex) { logErr(ex); err_cpy = err_cpy == "" ? ex.Message : err_cpy; }
                });
            }
            if (err_cpy != "")
            {
                throw new Exception("errore durante la copia dei files: " + err_cpy);
            }
        }
Example #4
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("");
        }
Example #5
0
 private xmlDoc addXmlDocToSession(string nameDoc, string fullPath, string sessionVar, bool force)
 {
     if (Session[sessionVar] == null || force)
     {
         Session[sessionVar] = new xmlDoc(fullPath);
     }
     return((xmlDoc)Session[sessionVar]);
 }
Example #6
0
        public static xmlDoc GetXmlConfig(string url)
        {
            var         xmlText = File.ReadAllText(url);
            XmlDocument xml     = new XmlDocument();

            xml.LoadXml(xmlText);
            var _doc     = xml.ChildNodes[1];  //doc节点
            var _members = _doc.ChildNodes[1]; //members节点

            var _xmlDoc = new xmlDoc();        //实例一个Doc对象

            _xmlDoc.assembly      = new xmlParamText();
            _xmlDoc.assembly.name = _doc.ChildNodes[0].ChildNodes[0].InnerText;//找到节点
            _xmlDoc.members       = new xmlMember();
            var memberList = new List <xmlMethodJson>();

            //循环出子节点
            foreach (XmlNode member in _members.ChildNodes)
            {
                //类型为错误的节点时,
                if (member.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                var _xmlMJ = new xmlMethodJson();
                _xmlMJ.name  = member.Attributes["name"].InnerText;//方法名
                _xmlMJ.param = new List <xmlParamText>();
                foreach (XmlNode son in member.ChildNodes)
                {
                    //子节点-保存对应文本值
                    switch (son.Name)
                    {
                    case "param":
                        var sonName = son.Attributes["name"].InnerText;
                        var sonText = son.InnerText;
                        _xmlMJ.param.Add(new xmlParamText()
                        {
                            name = sonName, text = sonText
                        });
                        break;

                    case "summary":
                        _xmlMJ.summary = son.InnerText;
                        break;

                    case "returns":
                        _xmlMJ.returns = son.InnerText;
                        break;
                    }
                }
                memberList.Add(_xmlMJ);
            }
            _xmlDoc.members.member = memberList;
            return(_xmlDoc);
        }
Example #7
0
        public override void onInit(object sender, EventArgs e, bool request = false, bool addControls = true)
        {
            Exception exc      = null;
            bool      baseInit = true;

            try {
                if (_page.pageName == "export")
                {
                    // invio file o backup database
                    if (_page.query_param("idfl") != "")
                    {
                        sendFile(file_path(_page, _page.query_int("idfl")));
                    }
                    else
                    {
                        sendFile(page.conn_db_user().export(_page.tmpFolder(), "export database", DateTime.Now, _page.tmpFolder()
                                                            , "export database", Path.GetRandomFileName(), page.cfg_var("filesFolder")), "export-data.gz");
                    }

                    baseInit = false;
                }
                else if (_page.query_param("type") == "sch")
                {
                    xmlDoc doc    = new xmlDoc(Path.Combine(page.cfg_var("backupsFolder"), page.cfg_var("fsIndex")));
                    string pocket = Path.Combine(page.cfg_var("backupsFolder"),
                                                 doc.get_value("/root/files/file[@idfile=" + _page.query_param("idfl") + "]", "name"));
                    sendFile(extract_dbpck_index(pocket), "export-schema.xml");

                    baseInit = false;
                }
                else if (_page.query_param("type") == "dl-bck")
                {
                    xmlDoc doc = new xmlDoc(Path.Combine(page.cfg_var("backupsFolder"), page.cfg_var("fsIndex")));
                    sendFile(Path.Combine(page.cfg_var("backupsFolder")
                                          , doc.get_value("/root/files/file[@idfile=" + _page.query_param("idfl") + "]", "name")), "export-data.gz");

                    baseInit = false;
                }
            } catch (Exception ex) { exc = ex; }

            if (baseInit)
            {
                base.onInit(sender, e, request);
            }

            if (exc != null)
            {
                addError(exc);
            }
        }
Example #8
0
        public static void mountBackup(int id, deeper.frmwrk.lib_page page, bool onlyData = false, string logid = "", string name_db = "")
        {
            xmlDoc doc        = new xmlDoc(Path.Combine(page.cfg_var("backupsFolder"), page.cfg_var("fsIndex")));
            string index_path = page.classPage.extract_dbpck(Path.Combine(page.cfg_var("backupsFolder")
                                                                          , doc.get_value("/root/files/file[@idfile=" + id.ToString() + "]", "name")));

            // aggiorno db
            db.db_schema db = name_db != "" ? page.conn_db(name_db, true) : page.conn_db_user(true);
            db.upgrade_data(page.conn_schema(index_path), onlyData, false
                            , doc.get_value("/root/files/file[@idfile=" + id.ToString() + "]", "title"));

            // copio i files in locale
            page.files_from_backup(index_path);
        }
Example #9
0
    public void expSchema(Object sender, EventArgs e)
    {
        try {
            if (bcks.SelectedValue == "")
            {
                classPage.regScript(classPage.scriptStartAlert("Devi selezionare un backup!", "Ripristino backup"));
            }

            xmlDoc doc    = new xmlDoc(System.IO.Path.Combine(cfg_var("backupsFolder"), cfg_var("fsIndex")));
            string pocket = System.IO.Path.Combine(cfg_var("backupsFolder"),
                                                   doc.get_value("/root/files/file[@idfile=" + bcks.SelectedValue + "]", "name"));
            classPage.sendFile(classPage.extract_dbpck_index(pocket), "export-schema.xml");
        } catch (Exception ex) {
            classPage.regScript(classPage.scriptStartAlert("Si è verificato un errore: " + ex.Message, "Esportazione schema"));
        }
    }
Example #10
0
        protected virtual bool eval_request(string action, xmlDoc doc, xmlDoc outxml)
        {
            if (action == "ctrl_request")
            {
                if (_class.evalControlRequest(doc, outxml))
                {
                    return(true);
                }
            }
            else if (action == "save_unload_keys")
            {
                _class.saveUnloadKeys(doc);
                return(true);
            }

            return(false);
        }
Example #11
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);
                                                           }
            }
        }
Example #12
0
        public XmlNodeList backups_list()
        {
            string idxPath = System.IO.Path.Combine(_page.cfg_var("backupsFolder"), _page.cfg_var("fsIndex"));

            if (!System.IO.File.Exists(idxPath))
            {
                return(null);
            }

            xmlDoc doc = new xmlDoc(idxPath);

            // infos
            doc.nodes("/root/files/file[@type='db-backup']").Cast <XmlNode>().ToList().ForEach(file => {
                xmlDoc.set_attr(file, "infos", string.Join(",", file.SelectNodes("infos/info").Cast <XmlNode>().Select(info =>
                                                                                                                       xmlDoc.node_val(_page.cfg_node("/root/fs/filetypes/filetype[@name='db-backup']"
                                                                                                                                                      + "/infos/info[@name='" + info.Attributes["name"].Value + "']"), "title") + ": '" + info.InnerText + "'")));
            });

            return(doc.nodes("/root/files/file[@type='db-backup']"));
        }
Example #13
0
        static public XmlNode create_idx_node(xmlDoc doc, idx_table idx)
        {
            XmlNode idx_node = doc.doc.CreateElement("index");

            idx_node.Attributes.Append(doc.doc.CreateAttribute("name")).Value      = idx.Name;
            idx_node.Attributes.Append(doc.doc.CreateAttribute("clustered")).Value = idx.Clustered.ToString().ToLower();
            idx_node.Attributes.Append(doc.doc.CreateAttribute("unique")).Value    = idx.Unique.ToString().ToLower();
            idx_node.Attributes.Append(doc.doc.CreateAttribute("primary")).Value   = idx.Primary.ToString().ToLower();

            XmlNode fieldsNode = idx_node.AppendChild(doc.doc.CreateElement("fields"));

            foreach (idx_field field in idx.Fields)
            {
                XmlNode fieldNode = fieldsNode.AppendChild(doc.doc.CreateElement("field"));
                fieldNode.Attributes.Append(doc.doc.CreateAttribute("name")).Value      = field.Name;
                fieldNode.Attributes.Append(doc.doc.CreateAttribute("nameupper")).Value = field.Name.ToUpper();
                fieldNode.Attributes.Append(doc.doc.CreateAttribute("ascending")).Value = field.Ascending.ToString().ToLower();
            }

            return(idx_node);
        }
Example #14
0
        public override bool action(string actionName, string formName, string keys = "", string noConfirm = "", string refurl = "")
        {
            if (base.action(actionName, formName, keys, noConfirm, refurl))
            {
                return(true);
            }

            if (actionName == "remove-db-backups")
            {
                Directory.Delete(_page.cfg_var("backupsFolder"), true);

                return(true);
            }
            else if (actionName == "remove-db-backup")
            {
                // aggiorno l'indice ed elimino il backup
                xmlDoc doc = new xmlDoc(Path.Combine(page.cfg_var("backupsFolder"), page.cfg_var("fsIndex")));
                string xp  = "/root/files/file[@idfile=" + keyValue(keys, "idfile") + "]";
                File.Delete(Path.Combine(page.cfg_var("backupsFolder"), doc.get_value(xp, "name")));
                doc.remove(xp);
                doc.save();

                return(true);
            }
            else if (actionName == "mount-db-backup")
            {
                mountBackup(int.Parse(keyValue(keys, "idfile")), page);

                return(true);
            }
            else if (actionName == "mount-data-db-backup")
            {
                mountBackup(int.Parse(keyValue(keys, "idfile")), page, true);

                return(true);
            }

            return(false);
        }
Example #15
0
        public override bool evalControlRequest(xmlDoc doc, xmlDoc outxml)
        {
            bool evaluated = false;

            if (base.evalControlRequest(doc, outxml))
            {
                return(true);
            }

            string type = doc.get_value("/request/pars/par[@name='type']");

            if (type == "graph.scroll")
            {
                evaluated = true;
                int i_x = doc.get_int("/request/pars/par[@name='i_x']");

                outxml.load_xml("<datas/>");
                load_data(outxml.node("/datas"), i_x);
            }

            return(evaluated);
        }
Example #16
0
        protected virtual void init()
        {
            try {
                logDebug("inizializzazione parser");
                _parser = new frmwrk.parser(this);

                // init lantern lib
                _approot = clean_root_path(web_setting("approot"));

                // config
                _config = addXmlDocToSession("webconfig", web_setting("config"), "webConfigDoc", web_setting_bool("reloadConfig"));
                if (!System.IO.File.Exists(_config.path))
                {
                    throw new Exception("il percorso del config '" + _config.path + "' non è configurato correttamente!");
                }

                logDebug("caricamento pagina '" + Request.Url + "'");

                // inizializzo la variabile di sessione
                //bool tmp = isConsoleBrowser();
            } catch (Exception ex) { logErr(ex); throw ex; }
        }
Example #17
0
        protected static void import_csv(page_cls pg, string path_file, xmlDoc sch)
        {
            System.IO.StreamReader rdr = null;
            int i_line = 0;

            try {
                // schema
                Dictionary <string, string> flds = sch.nodes("/root/fields/field").Cast <XmlNode>()
                                                   .ToDictionary(x => x.Attributes["name"].Value, x => (string)null);

                // lines
                db.db_schema db = pg.page.conn_db_user();
                rdr = new System.IO.StreamReader(path_file);
                int    from_line = var_import_int(sch, "from_line");
                string line      = rdr.ReadLine();
                while (!string.IsNullOrEmpty(line))
                {
                    if (i_line >= from_line)
                    {
                        parse_line_csv(line.Trim(), var_import(sch, "separator"), flds);
                        if (int.Parse(pg.dt_from_id("check", "", "", flds, null, true, sch.root_node)
                                      .Rows[0][0].ToString()) == 0)
                        {
                            pg.exec_updates("ins", "", flds, null, sch.root_node); System.Threading.Thread.Sleep(50);
                        }
                        else
                        {
                            pg.exec_updates("upd", "", flds, null, sch.root_node); System.Threading.Thread.Sleep(50);
                        }
                    }
                    line = rdr.ReadLine(); i_line++;
                }
            } catch (Exception ex) { throw new Exception(ex.Message + " (line: " + i_line.ToString() + ")"); } finally { if (rdr != null)
                                                                                                                         {
                                                                                                                             rdr.Close();
                                                                                                                         }
            }
        }
Example #18
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 != "";
    }
Example #19
0
 public schema_doc(string path)
 {
     _doc = new xmlDoc(path);
 }
Example #20
0
 public schema_doc()
 {
     _doc = new xmlDoc();
 }
Example #21
0
        public static void backupPck(page_cls pageClass, string pocket, string dbname, string title, DateTime date, string ver = "", string des = "")
        {
            if (title == "")
            {
                throw new Exception("Non è specificato il titolo.");
            }
            if (dbname == "")
            {
                throw new Exception("Non è specificato il nome del database.");
            }

            // salvo il backup nella cartella dei backups
            string bckFolder = pageClass.page.cfg_var("backupsFolder");

            if (!Directory.Exists(bckFolder))
            {
                Directory.CreateDirectory(bckFolder);
            }
            string pathBackup = Path.Combine(pageClass.page.cfg_var("backupsFolder"), "db-backup_" + date.ToString("yyyyMMdd-HHmmss") + ".gz");

            File.Move(pocket, pathBackup);

            // aggiorno l'indice xml
            XmlNode files = null;
            string  fsidx = Path.Combine(pageClass.page.cfg_var("backupsFolder"), pageClass.page.cfg_var("fsIndex"));
            {
                xmlDoc doc = new xmlDoc(fsidx);
                if (!File.Exists(fsidx))
                {
                    doc.load_xml("<root schema='xmlschema.ifs'/>");
                }

                // id file
                int idfile = doc.get_int("/root/files", "lastid") + 1;
                files = doc.node("/root/files", true);
                doc.set_attr("/root/files", "lastid", idfile.ToString());

                // file
                XmlNode file = files.AppendChild(doc.doc.CreateElement("file"));
                file.Attributes.Append(doc.doc.CreateAttribute("idfile")).Value = idfile.ToString();
                file.Attributes.Append(doc.doc.CreateAttribute("name")).Value   = Path.GetFileName(pathBackup);
                file.Attributes.Append(doc.doc.CreateAttribute("title")).Value  = title;
                if (des != "")
                {
                    file.Attributes.Append(doc.doc.CreateAttribute("des")).Value = des;
                }
                file.Attributes.Append(doc.doc.CreateAttribute("date")).Value = date.ToString("yyyy-MM-ddTHH:mm:ss");
                file.Attributes.Append(doc.doc.CreateAttribute("type")).Value = "db-backup";

                // infos
                XmlNode infos = file.AppendChild(doc.doc.CreateElement("infos"));

                // info: conn
                XmlNode iconn = infos.AppendChild(doc.doc.CreateElement("info"));
                iconn.InnerText = dbname;
                iconn.Attributes.Append(doc.doc.CreateAttribute("name")).Value = "conn";

                // info: ver
                if (ver != "")
                {
                    XmlNode iver = infos.AppendChild(doc.doc.CreateElement("info"));
                    iver.InnerText = ver;
                    iver.Attributes.Append(doc.doc.CreateAttribute("name")).Value = "ver";
                }

                doc.save();
            }
        }
Example #22
0
 protected static int var_import_int(xmlDoc doc, string name, int def_value = 0)
 {
     return(doc.get_int("/root/vars/var[@name='" + name + "']", "", def_value));
 }
Example #23
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);
        }
Example #24
0
 protected static string var_import(xmlDoc doc, string name)
 {
     return(doc.get_value("/root/vars/var[@name='" + name + "']"));
 }
Example #25
0
 protected static bool var_import_bool(xmlDoc doc, string name)
 {
     return(doc.get_bool("/root/vars/var[@name='" + name + "']"));
 }
Example #26
0
 public meta_doc(string path, schema_doc sch)
 {
     _doc = new xmlDoc(path); _schema = sch;
 }
Example #27
0
 public schema_doc(XmlDocument doc)
 {
     _doc = new xmlDoc(doc);
 }
Example #28
0
 public meta_doc(XmlDocument doc, schema_doc sch)
 {
     _doc = new xmlDoc(doc); _schema = sch;
 }
Example #29
0
        protected xmlDoc docForDel(long count, long c_notnull, string id_replace)
        {
            xmlDoc doc = xmlDoc.doc_from_xml("<page schema='xmlschema.ctrls'><contents/></page>");

            // form
            if (!_only_linked)
            {
                if (count > 0)
                {
                    XmlNode form = doc.add_xml("/page/contents", "<form name='main' title='Elemento sostitutivo' selects='load' width='800px' height='100px'>"
                                               + "<contents><row><field><label text='sostituisci con:'/></field>"
                                               + "  <field><input field='id_elemento' type='text' hide='true'/>"
                                               + "   <input field='des_elemento' type='text' enabled='false'/></field></row>"
                                               + " <row><field colspan='2'><label text='numero elementi correlati: " + count.ToString() + "'/></field></row>"
                                               + " <row><field class='footer' maxspan='true' right='true'>"
                                               + (!_only_linked ? "<button type='action' action='remove-all' tooltip='eliminazione o sostituzione di tutti gli elementi collegati' value='Togli gli elementi'/>" : "")
                                               + " <button type='action' action='replace-all' value='" + ((id_replace != "") ? "Sostituisci tutto" : "Togli ogni riferimento")
                                               + "' " + (id_replace == "" && c_notnull > 0 ? "demand='Alcune tabelle hanno il campo obbligatorio e non saranno aggiornate, vuoi continuare ugualmente?'" : "") + "/>"
                                               + " <button type='exit' value='Esci'/></field></row></contents>"
                                               + "<queries><select name='load'><![CDATA[" + (id_replace != "" ? "select '" + id_replace + "' as id_elemento"
                                                                                             + ", '" + desElement(_db, _table, page.query_param("fld").ToUpper(), id_replace) + "' as des_elemento"
                : "select '' as id_elemento, '' as des_elemento") + "]]></select></queries></form>");
                }
                else
                {
                    XmlNode form = doc.add_xml("/page/contents", "<form name='main' selects='load' width='800px' height='100px'>"
                                               + "<contents><row><field><label text='cancellazione:'/></field>"
                                               + "  <field><input field='id_elemento' type='text' hide='true'/>"
                                               + "   <input field='des_elemento' type='text' enabled='false'/></field></row>"
                                               + " <row><field class='footer' maxspan='true' right='true'><button type='action' action='remove-element' tooltip='eliminazione elemento' value='Rimuovi'/>"
                                               + "   <button type='exit' value='Esci'/></field></row></contents>"
                                               + "<queries><select name='load'><![CDATA[select '" + page.query_param("val") + "' as id_elemento"
                                               + " , '" + desElement(_db, _table, page.query_param("fld").ToUpper(), page.query_param("val")) + "' as des_elemento]]></select>"
                                               + "</queries></form>");
                }
            }

            if (count > 0)
            {
                // dettagli
                if (!_only_linked)
                {
                    doc.add_xml("/page/contents", "<section name='titleDetail'><![CDATA[<h3>Dettaglio elementi collegati</h3><br/>]]></section>");
                }

                // tabs
                XmlNode tabs = xmlDoc.set_attr(doc.add_node("/page/contents", "tabs"), "name", "tablestab");

                // main grid
                if (!_only_linked)
                {
                    addGrid(_db, doc, _table, "grid" + tabs.ChildNodes.Count.ToString(), "tabella " + _meta.title, "tablestab." + addTab(tabs, _meta.title)
                            , meta_link.types_link.normal, page.query_param("fld"), page.query_param("val"), "<>", true, false, false, "iddmain"
                            , (!_only_linked ? new Dictionary <string, Dictionary <string, string> >()
                    {
                        { "set-substitute-element"
                          , new Dictionary <string, string>()
                          {
                              { "des", "imposta come elemento sostitutivo..." }, { "icon", "mif-arrow-right" }, { "url", "{@currurlargs='nohstr=1'}" }
                          } }
                    } : null));
                }

                // aggiunta griglie collegate
                foreach (deeper.db.meta_link lnk in _db.meta_doc.table_links(_table)
                         .Where(t => _db.count_links(t, page.query_param("val")) > 0))
                {
                    addGrid(_db, doc, lnk.table_link
                            , "grid" + tabs.ChildNodes.Count.ToString(), "tabella " + lnk.title
                            , "tablestab." + addTab(tabs, lnk.title), lnk.type, lnk.field.ToUpper()
                            , page.query_param("val"), "=", true, _only_linked, !_only_linked);
                }
            }

            return(doc);
        }
Example #30
0
 public schema_doc(xmlDoc doc)
 {
     _doc = new xmlDoc(doc.doc, doc.path);
 }