CreateAttribute() public method

public CreateAttribute ( string prefix, string localName, string namespaceUri ) : XmlAttribute
prefix string
localName string
namespaceUri string
return System.Xml.XmlAttribute
コード例 #1
0
    public void Save()
    {
        string errorMessage = null;

        if (!HROne.CommonLib.FileIOProcess.IsFolderAllowWritePermission(AppDomain.CurrentDomain.BaseDirectory, out errorMessage))
        {
            throw new Exception(errorMessage);
        }
        string filename = getFilename();


        System.Configuration.ConfigXmlDocument config = new System.Configuration.ConfigXmlDocument();
        XmlElement   settings = config.CreateElement("Settings");
        XmlAttribute version  = config.CreateAttribute("Version");

        version.Value = "2.0";
        settings.Attributes.Append(version);
        config.AppendChild(settings);
        //SetDatabaseConfigList(settings);

        settings.AppendChild(config.CreateElement("HROneConfigFullPath"));
        settings["HROneConfigFullPath"].InnerText = HROneConfigFullPath;


        config.Save(filename);
    }
コード例 #2
0
    public void Save()
    {
        string errorMessage = null;

        if (!HROne.CommonLib.FileIOProcess.IsFolderAllowWritePermission(AppDomain.CurrentDomain.BaseDirectory, out errorMessage))
        {
            throw new Exception(errorMessage);
        }
        string filename = getFilename();

        if (config == null)
        {
            config = new System.Configuration.ConfigXmlDocument();
        }
        else
        {
            filename = config.Filename;
        }

        XmlElement settings = GetOrCreateElement(config, "Settings");

        if (settings.Attributes["Version"] == null)
        {
            settings.RemoveAll();
        }
        settings.RemoveAttribute("Version");
        XmlAttribute version = config.CreateAttribute("Version");

        version.Value = "2.0";
        settings.Attributes.Append(version);
        config.AppendChild(settings);
        SetDatabaseConfigList(settings);

        XmlElement shutdownOption = GetOrCreateElement(settings, "ShutdownAfterUsed");

        shutdownOption.InnerText = ShutDownDomainAfterUsed ? "true" : "false";

        XmlElement multiDBOption = GetOrCreateElement(settings, "AllowMultiDB");

        multiDBOption.InnerText = AllowMultiDB ? "true" : "false";

        XmlElement EncryptedURLOption = GetOrCreateElement(settings, "EncryptedURLQueryString");

        EncryptedURLOption.InnerText = EncryptedURLQueryString ? "true" : "false";

        XmlElement UsePDFCreatorOption = GetOrCreateElement(settings, "UsePDFCreator");

        UsePDFCreatorOption.InnerText = UsePDFCreator ? "true" : "false";

        XmlElement PDFCreatorPrinterNameOption = GetOrCreateElement(settings, "PDFCreatorPrinterNameOption");

        PDFCreatorPrinterNameOption.InnerText = PDFCreatorPrinterName;

        config.Save(filename);
    }
コード例 #3
0
        public static bool UpdateConnectionString( )
        {
            Project pjt = Kit.GetProjectByName(Kit.SlnKeel.UIProjectName);

            if (pjt == null)
            {
                Common.ShowInfo("您尚未设置UI主界面项目, 因此无法自动配置连接字符串到你的app.config 或者web.config中!");
                return(true);
            }
            ProjectItem PI = null;

            for (int i = 1; i <= pjt.ProjectItems.Count; i++)
            {
                ProjectItem pix = pjt.ProjectItems.Item(i);
                if (pix.Name.ToLower().Contains("app.config") || pix.Name.ToLower().Contains("web.config"))
                {
                    PI = pix;
                    break;
                }
            }
            if (PI == null)
            {
                Common.ShowInfo(string.Format("您设置的主UI项目{0}中未找到app.config 或者web.config,因此无法自动设置链接字符串配置", pjt.Name));
            }
            else
            {
                bool needUpdate = true;

                ConfigXmlDocument cxd = new System.Configuration.ConfigXmlDocument();

                cxd.Load(PI.get_FileNames(1));
                XmlNode xnx  = cxd.SelectSingleNode("descendant::configuration/connectionStrings");
                string  csss = GetProjectConfigNamespec(GetProjectLangType(GetProjectUI()));

                string name = "";
                if (pjt.Kind == "{E24C65DC-7377-472b-9ABA-BC803B73C61A}")
                {
                    name = "Keel" + csss + ".ConnectionString";
                }
                else
                {
                    name = ((string)pjt.Properties.Item("RootNamespace").Value) + csss + ".ConnectionString";
                }
                if (xnx != null)
                {
                    for (int i = 0; i < xnx.ChildNodes.Count; i++)
                    {
                        if (xnx.ChildNodes[i].Attributes["name"].Value.Contains(name))
                        {
                            if (xnx.ChildNodes[i].Attributes["providerName"].Value != Kit.SlnKeel.ProviderName)
                            {
                                xnx.ChildNodes[i].Attributes["providerName"].Value = Kit.SlnKeel.ProviderName;
                            }
                            if (xnx.ChildNodes[i].Attributes["connectionString"].Value != Kit.SlnKeel.ConnectString)
                            {
                                xnx.ChildNodes[i].Attributes["connectionString"].Value = Kit.SlnKeel.ConnectString;
                            }
                            cxd.Save(PI.get_FileNames(1));
                            needUpdate = false;
                            break;
                        }
                    }
                }
                if (needUpdate)
                {
                    XmlNode      xn             = cxd.CreateNode("element", "add", "");
                    XmlAttribute xzproviderName = cxd.CreateAttribute("providerName");
                    xzproviderName.Value = Kit.SlnKeel.ProviderName;
                    XmlAttribute xaconnectionString = cxd.CreateAttribute("connectionString");
                    xaconnectionString.Value = Kit.SlnKeel.ConnectString;
                    XmlAttribute xaname = cxd.CreateAttribute("name");
                    xaname.Value = name;
                    xn.Attributes.Append(xaname);
                    xn.Attributes.Append(xaconnectionString);
                    xn.Attributes.Append(xzproviderName);
                    if (xnx == null)
                    {
                        XmlNode xnx1 = cxd.SelectSingleNode("descendant::configuration");
                        xnx = cxd.CreateElement("connectionStrings");
                        xnx1.AppendChild(xnx);
                    }
                    xnx.AppendChild(xn);
                    // cxd.SelectSingleNode("descendant::configuration/connectionStrings").InnerXml = xnx.InnerXml;
                    cxd.Save(PI.get_FileNames(1));
                    //;// = cxd.SelectSingleNode("descendant::configuration/connectionStrings/add[@name='" + appnamespace + ".Properties.Settings.ConnectionString']");
                    //if (xnl.Attributes["providerName"] != null && xnl.Attributes["connectionString"] != null)
                    //{

                    //}
                }
                Common.ShowInfo(string.Format("您设置的主UI项目{0}中到app.config 或者web.config,已经设置了链接字符串{1}", pjt.Name, name));
            }
            return(true);
        }