コード例 #1
0
 public DatabaseTemplate(string templatePath, List <Setting> properties, Model.Database database)
     : base(templatePath, properties, database)
 {
     Config.System syscfg = Config.System.Load();
     foreach (KeyValuePair <string, object> item in ModelProperties <Model.Database> .GetPropertyValues(database))
     {
         Variables.Add(syscfg.DatabaseVariablePrefix + item.Key, item.Value);
     }
 }
コード例 #2
0
        public static List <Setting> GetSettings(string templateFolder)
        {
            Config.System  syscfg   = Config.System.Load();
            List <Setting> settings = new List <Setting>();

            string settingFilePath = templateFolder.EndsWith(@"\") ? templateFolder : templateFolder + @"\" + syscfg.SettingFile;

            if (File.Exists(settingFilePath))
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(settingFilePath);
                XmlNode root = xml.SelectSingleNode("settings");

                foreach (XmlNode settingNode in root.ChildNodes)
                {
                    if (settingNode.Name.Equals("setting", StringComparison.CurrentCultureIgnoreCase))
                    {
                        Setting setting = new Setting();
                        setting.Name = settingNode.Attributes["name"].Value;
                        if (settingNode.Attributes["description"] != null)
                        {
                            setting.Description = settingNode.Attributes["description"].Value;
                        }

                        if (settingNode.ChildNodes.Count == 0) //不存在Option节点
                        {
                            setting.Value = settingNode.Attributes["value"].Value;
                        }
                        else
                        {
                            foreach (XmlNode optionNode in settingNode.ChildNodes)
                            {
                                string name        = optionNode.Attributes["name"].Value;
                                string description = string.Empty;
                                if (optionNode.Attributes["description"] != null)
                                {
                                    description = optionNode.Attributes["description"].Value;
                                }
                                setting.Options.Add(new SettingOption()
                                {
                                    Name = name, Description = description
                                });
                                if (optionNode.Attributes["selected"] != null && optionNode.Attributes["selected"].Value.Equals("true", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    setting.Value = name;
                                }
                            }
                        }
                        settings.Add(setting);
                    }
                }
            }

            return(settings);
        }
コード例 #3
0
ファイル: FieldTemplate.cs プロジェクト: LDT2016/SocanCode6
        public FieldTemplate(string templatePath, List <Setting> settings, Model.Field field)
            : base(templatePath, settings, field)
        {
            Config.System syscfg = Config.System.Load();
            foreach (KeyValuePair <string, object> item in ModelProperties <Model.Field> .GetPropertyValues(field))
            {
                Variables.Add(syscfg.FieldVariablePrefix + item.Key, item.Value);
            }

            foreach (KeyValuePair <string, object> item in ModelProperties <Model.Table> .GetPropertyValues(field.Table))
            {
                Variables.Add(syscfg.TableVariablePrefix + item.Key, item.Value);
            }

            foreach (KeyValuePair <string, object> item in ModelProperties <Model.Database> .GetPropertyValues(field.Table.Database))
            {
                Variables.Add(syscfg.DatabaseVariablePrefix + item.Key, item.Value);
            }
        }
コード例 #4
0
ファイル: Template.cs プロジェクト: LDT2016/SocanCode6
        public static List <Template> CreateTemplates(string templateFolder, Model.Database database, List <Setting> settings)
        {
            Config.System syscfg   = Config.System.Load();
            List <string> xmlFiles = new List <string>();

            foreach (string item in Directory.GetFiles(templateFolder, "*.xml"))
            {
                if (false == item.EndsWith(syscfg.SettingFile, StringComparison.CurrentCultureIgnoreCase))
                {
                    xmlFiles.Add(item);
                }
            }

            List <Template> templates = new List <Template>();

            foreach (string xmlFile in xmlFiles)
            {
                string forAttr = new TemplateBase(xmlFile).For;

                if (forAttr.Equals(typeof(Model.Database).Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    Template generator = new DatabaseTemplate(xmlFile, settings, database);
                    if (generator.On)
                    {
                        templates.Add(generator);
                    }
                }
                else if (forAttr.Equals(typeof(Model.Table).Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    foreach (Model.Table item in database.SelectedTables)
                    {
                        Template generator = new TableTemplate(xmlFile, settings, item);
                        if (generator.On)
                        {
                            templates.Add(generator);
                        }
                    }
                }
            }

            templates.Sort();
            return(templates);
        }
コード例 #5
0
        public static void SaveSettings(string templateFolder, List <Setting> settings)
        {
            Config.System syscfg          = Config.System.Load();
            string        settingFilePath = templateFolder.EndsWith(@"\") ? templateFolder : templateFolder + @"\" + syscfg.SettingFile;

            if (false == File.Exists(settingFilePath))
            {
                return; //文件不存在
            }

            XmlDocument xml = new XmlDocument();

            xml.Load(settingFilePath);
            XmlNode root = xml.SelectSingleNode("settings");

            if (root == null)
            {
                return;//根节点不是Settings
            }

            foreach (XmlNode settingNode in root.ChildNodes)
            {
                if (false == settingNode.Name.Equals("setting", StringComparison.CurrentCultureIgnoreCase))
                {
                    return; //节点名不是setting
                }

                foreach (Setting setting in settings)
                {
                    //找到对应的控件uc
                    if (setting.Name.Equals(settingNode.Attributes["name"].Value, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (setting.Options.Count == 0) //是文本框直接赋value值
                        {
                            settingNode.Attributes["value"].Value = setting.Value;
                        }
                        else //是下拉框
                        {
                            foreach (XmlNode optionNode in settingNode.ChildNodes)
                            {
                                if (optionNode.Attributes["name"].Value.Equals(setting.Value, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    if (optionNode.Attributes["selected"] == null)
                                    {
                                        XmlAttribute attr = xml.CreateAttribute("selected");
                                        attr.Value = "true";
                                        optionNode.Attributes.Append(attr);
                                    }
                                    else
                                    {
                                        optionNode.Attributes["selected"].Value = "true";
                                    }
                                }
                                else
                                {
                                    if (optionNode.Attributes["selected"] != null)
                                    {
                                        optionNode.Attributes.Remove(optionNode.Attributes["selected"]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            xml.Save(settingFilePath);
        }