菜菜吃菜 2022-07-15 10:24 采纳率: 57.5%
浏览 90
已结题

读取文件多条件显示到table

string sql = "SELECT unid FROM DeviceModifyDetail WHERE DevLabel LIKE '%028%'";
            object d = SqlHelper.ExecuteScalar(Connstr, CommandType.Text, sql);  //查询结果

            string UniqueID = Convert.ToString(d);
  long dianID = Convert.ToInt64(UniqueID);
            DateTime dt1 = dateEdit1.DateTime;
            DateTime dt2 = dateEdit2.DateTime;
            
将数据库的查询结果,放到ReadFile再读取文件中的数据显示出
            DataTable dataTable = ReadFile(mcFile, false, dt1, dt2, dianID, true, 0);

            dataTable.AcceptChanges();
            gridControl1.DataSource = dataTable;

ReadFile方法
 public DataTable ReadFile(string string_0, bool bool_0, DateTime StartTime, DateTime EndTime, long DianID, bool bool_1 = true, int int_0 = 0)
        {
            idList = new List<long>();

            DataTable dataTable = NewTable(bool_1);
            //progressBar1.Value = 0;
            if (File.Exists(string_0))
            {
                BinaryReader binaryReader = OpenFile(string_0, Encoding.Default);
                //progressBar1.Maximum = Convert.ToInt32(binaryReader.BaseStream.Length / 36) + 2;
                int i = 100;
                for (int j = 0; i < binaryReader.BaseStream.Length; i += 36, j++)
                {
                    //progressBar1.Value++;
                    binaryReader.BaseStream.Position = i;
                    long num = BitConverter.ToInt64(binaryReader.ReadBytes(8), 0);
                    binaryReader.BaseStream.Position = i + 8;
                    uint num2 = BitConverter.ToUInt32(binaryReader.ReadBytes(4), 0);
                    binaryReader.BaseStream.Position = i + 12;
                    double num3 = BitConverter.ToDouble(binaryReader.ReadBytes(8), 0);
                    binaryReader.BaseStream.Position = i + 20;
                    uint num4 = BitConverter.ToUInt32(binaryReader.ReadBytes(4), 0);
                    binaryReader.BaseStream.Position = i + 24;
                    uint num5 = BitConverter.ToUInt32(binaryReader.ReadBytes(4), 0);
                    binaryReader.BaseStream.Position = i + 28;
                    long dateData = BitConverter.ToInt64(binaryReader.ReadBytes(8), 0);
                    DateTime dateTime = DateTime.FromBinary(dateData);
                    bool flag = false;
                    if (bool_0)
                    {
                        if ((num5 & 0x40000u) != 0 || (num5 & 0x80000u) != 0 || (num5 & 0x200000u) != 0)
                        {
                            flag = true;
                        }
                    }
                    else
                    {
                        flag = true;
                    }
                    if (!flag)
                    {
                        continue;
                    }
                    if (num3.ToString().ToUpper().Contains("E"))
                    {
                        int length = num3.ToString().ToUpper().IndexOf("E");
                        num3 = Convert.ToDouble(num3.ToString().Substring(0, length));
                    }
                    idList.Add(num);
                    DataRow dataRow = dataTable.NewRow();
                    dataRow["所在密采文件"] = Path.GetFileName(string_0);
                    dataRow["记录ID"] = j;
                    dataRow["唯一编码"] = num;
                    dataRow["物理地址"] = num2;
                    dataRow["值"] = num3;
                    dataRow["原始值"] = num4;
                    dataRow["状态ID"] = num5;
                    dataRow["对应时间"] = dateTime;
                    dataRow["文件路径"] = Path.GetDirectoryName(string_0);
                    Enum2 @enum = (Enum2)int_0;
                    dataRow["文件来源"] = @enum.ToString();

                    DateTime value = dateTime;
                    if (value >= StartTime && value <= EndTime)
                    {
                        if (DianID == 0 || num == DianID)
                        {
                            dataTable.Rows.Add(dataRow);
                            continue;
                        }
                    }

                }
                //progressBar1.Value = progressBar1.Maximum;
                binaryReader.Close();
            }

            return dataTable;
        }

现在只能显示出一条想将查询出的多条UniqueID 结果,显示到dataTable,怎样实现呢?

  • 写回答

1条回答 默认 最新

  • Hello World, 2022-07-15 10:47
    关注

    符合条件的数据就一条吧

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月19日
  • 赞助了问题酬金20元 7月15日
  • 修改了问题 7月15日
  • 创建了问题 7月15日

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图