更改后的数据恢复中的价值

发布于 2025-01-26 06:10:09 字数 5201 浏览 1 评论 0原文

我正在通过数据表进行迭代并进行一些比较。如果值匹配我将标志设置为true。 我有几个情况下它找到了匹配项,设置了标志(设置后立即对其进行验证),在下一个代码中,标志又回到了false。

这是正在检查事物的代码:

foreach (string code in codeList)
{
    // Filters DataTable by code (should be 6 per code)
    expression = $"[Reason Code] = '{code}'";
    _foundRows = ReasonCodeTable.Select(expression);

    // Goes through the filtered rows
    for (int i = 0; i < _foundRows.Length; i++)
    {
        // Index of Source Row
        int _idx = Convert.ToInt32(_foundRows[i][0]);

        // Desc of Source Row
        string _strDesc = _foundRows[i][5].ToString();

        for (int x = 0; x < _foundRows.Length; x++)
        {
            // Index of the 2nd pass
            int _idx2 = Convert.ToInt32(_foundRows[x][0]);

            // Desc of the 2nd pass row
            string _strDesc2 = _foundRows[x]["Description"].ToString();

            Console.WriteLine($"{code}:  Comparing idx1 {_idx}: '{_strDesc}'  vs  idx2 {_idx2}: '{_strDesc2}'");

            // Loops through filtered list again to compare Descriptions and mark as Found
            if (_idx2 != _idx)
            {
                // Compares Descriptions
                if (_strDesc2.ToString() == _strDesc.ToString())
                {
                    Console.WriteLine($"MATCH FOUND (idx1: {_idx} = idx2: {_idx2})");

                    Console.WriteLine($"idx1 {_idx} Before: {ReasonCodeTable.Rows[_idx]["Found"]}");
                    ReasonCodeTable.Rows[_idx]["Found"] = "True";
                    Console.WriteLine($"idx1 {_idx} After: {ReasonCodeTable.Rows[_idx]["Found"]}");

                    Console.WriteLine($"idx2 {_idx2} After: {ReasonCodeTable.Rows[_idx2]["Found"]}");
                    ReasonCodeTable.Rows[_idx2]["Found"] = "True";
                    Console.WriteLine($"idx2 {_idx2} After: {ReasonCodeTable.Rows[_idx2]["Found"]}");

                    Console.WriteLine($"");
                    x = _foundRows.Length;
                }
            }
        }
    }
}

为我提供以下输出。您可以看到它将所有标志设置为真。

4:  Comparing idx1 51: 'Warehouse use and expense'  vs  idx2 51: 'Warehouse use and expense'
4:  Comparing idx1 51: 'Warehouse use and expense'  vs  idx2 52: 'Warehouse use and expense'
MATCH FOUND (idx1: 51 = idx2: 52)
idx1 51 Before: False
idx1 51 After: True
idx2 52 After: False
idx2 52 After: True

4:  Comparing idx1 52: 'Warehouse use and expense'  vs  idx2 51: 'Warehouse use and expense'
MATCH FOUND (idx1: 52 = idx2: 51)
idx1 52 Before: True
idx1 52 After: True
idx2 51 After: True
idx2 51 After: True

4:  Comparing idx1 53: 'Warehouse use and expense'  vs  idx2 51: 'Warehouse use and expense'
MATCH FOUND (idx1: 53 = idx2: 51)
idx1 53 Before: False
idx1 53 After: True
idx2 51 After: True
idx2 51 After: True

7:  Comparing idx1 54: 'Lost Inventory'  vs  idx2 54: 'Lost Inventory'
7:  Comparing idx1 54: 'Lost Inventory'  vs  idx2 55: 'Lost Inventory'
MATCH FOUND (idx1: 54 = idx2: 55)
idx1 54 Before: False
idx1 54 After: True
idx2 55 After: False
idx2 55 After: True

7:  Comparing idx1 55: 'Lost Inventory'  vs  idx2 54: 'Lost Inventory'
MATCH FOUND (idx1: 55 = idx2: 54)
idx1 55 Before: True
idx1 55 After: True
idx2 54 After: True
idx2 54 After: True

7:  Comparing idx1 56: 'Lost Inventory'  vs  idx2 54: 'Lost Inventory'
MATCH FOUND (idx1: 56 = idx2: 54)
idx1 56 Before: False
idx1 56 After: True
idx2 54 After: True
idx2 54 After: True

6:  Comparing idx1 57: 'Customer Samples'  vs  idx2 57: 'Customer Samples'
6:  Comparing idx1 57: 'Customer Samples'  vs  idx2 58: 'Customer Samples'
MATCH FOUND (idx1: 57 = idx2: 58)
idx1 57 Before: False
idx1 57 After: True
idx2 58 After: False
idx2 58 After: True

6:  Comparing idx1 58: 'Customer Samples'  vs  idx2 57: 'Customer Samples'
MATCH FOUND (idx1: 58 = idx2: 57)
idx1 58 Before: True
idx1 58 After: True
idx2 57 After: True
idx2 57 After: True

6:  Comparing idx1 59: 'Customer Samples'  vs  idx2 57: 'Customer Samples'
MATCH FOUND (idx1: 59 = idx2: 57)
idx1 59 Before: False
idx1 59 After: True
idx2 57 After: True
idx2 57 After: True

就在下面,我有以下代码:

// Marks remaining items as either 'Missing' or 'Inconsistent Description'
            foreach (DataRow _dr in ReasonCodeTable.Rows)
            {
                if ((_dr["Issue"].ToString() == "") && (_dr["Found"].ToString() == "False"))
                {
                    Console.WriteLine($"idx: {_dr["ID"]}");
                    Console.WriteLine($"Code: {_dr["Reason Code"]}");
                    Console.WriteLine($"Issue: {_dr["Issue"]}");
                    Console.WriteLine($"Found: {_dr["Found"]}");
                    Console.WriteLine($"");
                    _dr["Issue"] = "Inconsistent Description";
                }
                else if ((_dr["Issue"].ToString() == "Missing"))
                    _dr["Found"] = false;
            }

我得到了此输出,该输出显示了上面设置的几个索引true又回到了false(特定于53、56、59),

idx: 27
Code: 20
Issue:
Found: False

idx: 53
Code: 4
Issue:
Found: False

idx: 59
Code: 6
Issue:
Found: False

idx: 56
Code: 7
Issue:
Found: False

idx: 68
Code: GENERAL
Issue:
Found: False

我不明白为什么[ “找到”]列正在恢复。

I am iterating through a DataTable and doing some comparisons. If values match I set a flag to true.
I have several cases where the it finds the match, sets the flag (I verify it right after it's set), and in the next bit of code the flag is back to false.

Here is the code that's checking things:

foreach (string code in codeList)
{
    // Filters DataTable by code (should be 6 per code)
    expression = 
quot;[Reason Code] = '{code}'";
    _foundRows = ReasonCodeTable.Select(expression);

    // Goes through the filtered rows
    for (int i = 0; i < _foundRows.Length; i++)
    {
        // Index of Source Row
        int _idx = Convert.ToInt32(_foundRows[i][0]);

        // Desc of Source Row
        string _strDesc = _foundRows[i][5].ToString();

        for (int x = 0; x < _foundRows.Length; x++)
        {
            // Index of the 2nd pass
            int _idx2 = Convert.ToInt32(_foundRows[x][0]);

            // Desc of the 2nd pass row
            string _strDesc2 = _foundRows[x]["Description"].ToString();

            Console.WriteLine(
quot;{code}:  Comparing idx1 {_idx}: '{_strDesc}'  vs  idx2 {_idx2}: '{_strDesc2}'");

            // Loops through filtered list again to compare Descriptions and mark as Found
            if (_idx2 != _idx)
            {
                // Compares Descriptions
                if (_strDesc2.ToString() == _strDesc.ToString())
                {
                    Console.WriteLine(
quot;MATCH FOUND (idx1: {_idx} = idx2: {_idx2})");

                    Console.WriteLine(
quot;idx1 {_idx} Before: {ReasonCodeTable.Rows[_idx]["Found"]}");
                    ReasonCodeTable.Rows[_idx]["Found"] = "True";
                    Console.WriteLine(
quot;idx1 {_idx} After: {ReasonCodeTable.Rows[_idx]["Found"]}");

                    Console.WriteLine(
quot;idx2 {_idx2} After: {ReasonCodeTable.Rows[_idx2]["Found"]}");
                    ReasonCodeTable.Rows[_idx2]["Found"] = "True";
                    Console.WriteLine(
quot;idx2 {_idx2} After: {ReasonCodeTable.Rows[_idx2]["Found"]}");

                    Console.WriteLine(
quot;");
                    x = _foundRows.Length;
                }
            }
        }
    }
}

That gives me the output below. You can see that it's setting all of the flags to true.

4:  Comparing idx1 51: 'Warehouse use and expense'  vs  idx2 51: 'Warehouse use and expense'
4:  Comparing idx1 51: 'Warehouse use and expense'  vs  idx2 52: 'Warehouse use and expense'
MATCH FOUND (idx1: 51 = idx2: 52)
idx1 51 Before: False
idx1 51 After: True
idx2 52 After: False
idx2 52 After: True

4:  Comparing idx1 52: 'Warehouse use and expense'  vs  idx2 51: 'Warehouse use and expense'
MATCH FOUND (idx1: 52 = idx2: 51)
idx1 52 Before: True
idx1 52 After: True
idx2 51 After: True
idx2 51 After: True

4:  Comparing idx1 53: 'Warehouse use and expense'  vs  idx2 51: 'Warehouse use and expense'
MATCH FOUND (idx1: 53 = idx2: 51)
idx1 53 Before: False
idx1 53 After: True
idx2 51 After: True
idx2 51 After: True

7:  Comparing idx1 54: 'Lost Inventory'  vs  idx2 54: 'Lost Inventory'
7:  Comparing idx1 54: 'Lost Inventory'  vs  idx2 55: 'Lost Inventory'
MATCH FOUND (idx1: 54 = idx2: 55)
idx1 54 Before: False
idx1 54 After: True
idx2 55 After: False
idx2 55 After: True

7:  Comparing idx1 55: 'Lost Inventory'  vs  idx2 54: 'Lost Inventory'
MATCH FOUND (idx1: 55 = idx2: 54)
idx1 55 Before: True
idx1 55 After: True
idx2 54 After: True
idx2 54 After: True

7:  Comparing idx1 56: 'Lost Inventory'  vs  idx2 54: 'Lost Inventory'
MATCH FOUND (idx1: 56 = idx2: 54)
idx1 56 Before: False
idx1 56 After: True
idx2 54 After: True
idx2 54 After: True

6:  Comparing idx1 57: 'Customer Samples'  vs  idx2 57: 'Customer Samples'
6:  Comparing idx1 57: 'Customer Samples'  vs  idx2 58: 'Customer Samples'
MATCH FOUND (idx1: 57 = idx2: 58)
idx1 57 Before: False
idx1 57 After: True
idx2 58 After: False
idx2 58 After: True

6:  Comparing idx1 58: 'Customer Samples'  vs  idx2 57: 'Customer Samples'
MATCH FOUND (idx1: 58 = idx2: 57)
idx1 58 Before: True
idx1 58 After: True
idx2 57 After: True
idx2 57 After: True

6:  Comparing idx1 59: 'Customer Samples'  vs  idx2 57: 'Customer Samples'
MATCH FOUND (idx1: 59 = idx2: 57)
idx1 59 Before: False
idx1 59 After: True
idx2 57 After: True
idx2 57 After: True

Right below I have the following bit of code:

// Marks remaining items as either 'Missing' or 'Inconsistent Description'
            foreach (DataRow _dr in ReasonCodeTable.Rows)
            {
                if ((_dr["Issue"].ToString() == "") && (_dr["Found"].ToString() == "False"))
                {
                    Console.WriteLine(
quot;idx: {_dr["ID"]}");
                    Console.WriteLine(
quot;Code: {_dr["Reason Code"]}");
                    Console.WriteLine(
quot;Issue: {_dr["Issue"]}");
                    Console.WriteLine(
quot;Found: {_dr["Found"]}");
                    Console.WriteLine(
quot;");
                    _dr["Issue"] = "Inconsistent Description";
                }
                else if ((_dr["Issue"].ToString() == "Missing"))
                    _dr["Found"] = false;
            }

And I get this output, which shows several of the indices from above that were set true are back to false (specificaly 53, 56, 59)

idx: 27
Code: 20
Issue:
Found: False

idx: 53
Code: 4
Issue:
Found: False

idx: 59
Code: 6
Issue:
Found: False

idx: 56
Code: 7
Issue:
Found: False

idx: 68
Code: GENERAL
Issue:
Found: False

I do not understand why the value of the ["Found"] column is reverting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文