我正在使用 Danny Beckett 的小型 Ini 文件,它运行得很好。但是,我想存储最近文件的历史列表。这个可以加吗

问题描述 投票:0回答:1

如标题中所述,我正在使用此处定义的 Danny Beckett 的 ini 文件类:读取/写入 INI 文件

它的效果真的很棒,满足了我最初的所有要求。但是,我真的希望能够访问一个部分并将该部分中的所有键/值对读入列表/字典中。使用这种方法,我可以将最近的输出历史记录存储到 ini 文件中。

就我而言,它将列出供应商/供应商,以及我的应用程序上次在我们的数据库中更新其价目表的时间。每个条目将包含作为键的供应商名称和指示该供应商的最后更新的日期字符串。

我知道我可以编写一个简单的日志文件来执行此操作,但这将是对现有功能的一个很好的补充。

我想不出如何准确地编写读取整个键和值部分的方法,但如果它返回一个字典那就太好了。

public Dictionary<string, string> ReadSection(string Section)
{
    var RetVal = new Dictionary<string, string>();
    // code to read the section and add it to dictionary
    return RetVal;
}
dictionary ini
1个回答
0
投票

我通过迭代数据库中所有参与方的列表并检查每个参与方是否在 ini 文件中都有条目来解决这个问题。每次我处理某个团体的记录时,我都会将日期写入 ini 文件,并以他们的 partyId 作为键。通过这种方式,我能够在 ini 文件中保留上次更新各方价格的历史记录。

这是代码的相关部分:

public static Dictionary<string, string> history = new Dictionary<string, string>();
public static List<string> partyList = new List<string>();

private void btnViewHistory_Click(object sender, EventArgs e)
{
    history.Clear();
    // iterate through list of all parties in database
    // check to see if each one has a history entry
    // if so, add it to the list of entries
    foreach (string party in partyList)
    {
        var historyRecord = MyIni.Read(party, "History");
        if (!String.IsNullOrEmpty(historyRecord))
        {
            history.Add(party, historyRecord);
        }
    //... bind list to DataGridView on form and show form ...
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.