【问题标题】:Advice for loading application options加载应用程序选项的建议
【发布时间】:2012-07-03 06:20:57
【问题描述】:

我想创建一个 WinForms 应用程序。 此应用程序将有许多可配置的选项,这些选项将保存在数据库中,因此它们可以在执行过程中持久化(例如打印设置、设计选项等)。

您会推荐什么方法来加载这些选项,以避免频繁访问数据库?

谢谢!

【问题讨论】:

  • 您在读取数据库时遇到问题?你的问题不是很清楚。

标签: c# .net configuration persistence


【解决方案1】:

如果安全性不重要,您还可以将设置保存在表单读取的 xml 文件中。您可以拥有一个加载所需属性的类。

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx

[Serializable()]
public class Defaults
{
    public string Description { get; set; }
    public double Tolerance { get; set; }
    public string Units { get; set; }
 }

internal class FormDefaults
{
public void LoadSettings()
    {
      string kfileString = @"C:\Default_Settings.xml";

      var q = from el in XElement.Load(kfileString).Elements()
                select new FormDefault()
                {
                    Description = el.Element("InstrumentDescription").Value,
                    Tolerance = Double.Parse(el.Element("InstrumentMassTolerance").Value),
                    Units = el.Element("InstrumentMassUnits").Value,

                };
        }
    }
}

这很粗糙,但我有类似的东西,效果很好,而且很容易设置。

干杯

【讨论】:

    【解决方案2】:

    有一些问题,保存在数据库中的设置将被所有用户共享。在这种情况下,您已经考虑为每个用户设置设置。更好的选择是保存在可以加密和使用的本地配置文件中。如果需要在用户之间共享任何内容,则可以将 db 用于该特定选项。您可以在应用程序加载之前加载这些选项并通过对象访问它。

    您可以在 SPlash 屏幕中通过向用户显示进度来执行这些数据库获取操作。

    【讨论】:

      猜你喜欢
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      相关资源
      最近更新 更多