-4

这是我必须使用的工资单文件中的一个示例,它列出了员工编号、不同类型的收入和检查日期。目标是获得每个员工的小计,列出员工的总工资和其他收入。我无法理解如何做到这一点,有人可以提供一些建议吗?我正在尝试在 C# 中执行此操作。一些员工可能只有一条线,其他员工可能有没有固定工资类型的线,只有扣除/收入(奖金、保险等......)

240 TN  DP  800.00  1696.65 .00 .00 .00 .00 65  46.20   11/10/11
240 TN  DP  800.00  1696.65 .00 .00 .00 .00 66  124.83  11/10/11
240 TN  DP  800.00  1696.65 .00 .00 .00 .00 72  5.27    11/10/11
240 TN  DP  800.00  1696.65 .00 .00 .00 .00 ZC  1933.75 11/10/11
240 TN  DP  800.00  1643.55 .00 .00 .00 .00 65  46.20   11/25/11
240 TN  DP  800.00  1643.55 .00 .00 .00 .00 66  122.18  11/25/11
240 TN  DP  800.00  1643.55 .00 .00 .00 .00 72  5.27    11/25/11
240 TN  DP  800.00  1643.55 .00 .00 .00 .00 ZC  1893.87 11/25/11
240 TN  DP  .00 .00 .00 .00 400.00  .00 66  20.00   12/09/11
240 TN  DP  800.00  1595.25 .00 80.00   .00 .00 65  46.20   12/09/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 65  .00 07/08/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 67  .00 07/08/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 69  .00 07/08/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 72  .00 07/08/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 74  .00 07/08/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 ZC  1299.03 07/08/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 65  181.85  07/22/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 67  12.46   07/22/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 69  .00 07/22/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 72  22.15   07/22/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 74  .00 07/22/11
242 TN  DP  1538.46 .00 .00 .00 .00 .00 ZC  1124.70 07/22/11

编辑:在回答一些问题时,这些字段从左到右依次为:员工编号、州、部门、正常工资、加班工资、假期工资、假期工资、病假工资、特殊工资、收入代码、收入金额、检查日期。我需要为每个字段获取每位员工的总数,同时确保每个检查日期不会多次添加一个人的工资。

4

1 回答 1

0

如果您正在使用文本文件,您应该阅读它,然后详细说明数据。所以这就是我要做的:

string[] lines = File.ReadLines(path);

然后对于数组中的每个元素(行),我将按数据拆分它:

 __Data1___ ______________Data2_______________D3_ __D4__ ___Data5___
|          |                                |    |      |           |
 240 TN  DP  800.00  1696.65 .00 .00 .00 .00 65  46.20   11/10/11
 240 TN  DP  800.00  1696.65 .00 .00 .00 .00 66  124.83  11/10/11
 240 TN  DP  800.00  1696.65 .00 .00 .00 .00 72  5.27    11/10/11
 240 TN  DP  800.00  1696.65 .00 .00 .00 .00 ZC  1933.75 11/10/11
 240 TN  DP  800.00  1643.55 .00 .00 .00 .00 65  46.20   11/25/11
 240 TN  DP  800.00  1643.55 .00 .00 .00 .00 66  122.18  11/25/11
 240 TN  DP  800.00  1643.55 .00 .00 .00 .00 72  5.27    11/25/11
 240 TN  DP  800.00  1643.55 .00 .00 .00 .00 ZC  1893.87 11/25/11
 240 TN  DP  .00 .00 .00 .00 400.00  .00 66  20.00   12/09/11
 240 TN  DP  800.00  1595.25 .00 80.00   .00 .00 65  46.20   12/09/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 65  .00 07/08/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 67  .00 07/08/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 69  .00 07/08/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 72  .00 07/08/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 74  .00 07/08/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 ZC  1299.03 07/08/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 65  181.85  07/22/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 67  12.46   07/22/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 69  .00 07/22/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 72  22.15   07/22/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 74  .00 07/22/11
 242 TN  DP  1538.46 .00 .00 .00 .00 .00 ZC  1124.70 07/22/11

所以我会创建一个类并获取我需要的数据:

class Data
{
    public string Data1;
    public string Data2;
    public string Data3;
    public string Data4;
    public string Data5;
}

List<Data> myList = new List<Data>();

//Split lines
foreach(string s in lines)
{
   string[] buffer = s.Split(' '); //split by space

   Data data = new Data();
   data.Data1 = string.Concat(buffer.Take(3).ToArray());
   data.Data2 = string.Concat(buffer.Skip(3).Take(6).ToArray());
   data.Data3 = string.Concat(buffer.Skip(9).Take(1).ToArray());
   data.Data4 = string.Concat(buffer.Skip(10).Take(1).ToArray());
   data.Data5 = string.Concat(buffer.Skip(11).Take().ToArray());

   myList.Add(data);
}
于 2012-06-19T21:06:54.843 回答