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;
}
private void checkButton1_CheckedChanged(object sender, EventArgs e)
{
string sql = "SELECT UniqueID FROM DeviceModifyDetail WHERE DevLabel LIKE '%028A04%'";
object d = SqlHelper.ExecuteScalar(Connstr, CommandType.Text, sql);
string UniqueID =Convert.ToString(d);
for (int i = 0; i < this.gridView1.RowCount; i++)
//遍历表中的所有行
{
if (this.gridView1.IsRowSelected(i) == true)
//判断当前行是否被选中
{
try
{
UniqueID = this.gridView1.GetDataRow(i)["UniqueID"].ToString();//取选中行的ID字段的值
}
catch
{
}
}
}
string str = dateEdit1.DateTime.ToString("yyyyMMddHH");
string mc = mcPath;//读取密采文件夹
string fileName = mc + str + ".mcZ";
isCompress = true;
bool exist = System.IO.File.Exists(fileName);
if (!exist)
{
fileName = mc + str + ".mc";
isCompress = false;
mcFile = fileName;
}
////解压,存在就不重复解压
if (isCompress)
{
mcFile = fileName.Substring(0, fileName.Length - 1);
if (!File.Exists(mcFile))
DeZip(fileName, mcFile);
}
long dianID = Convert.ToInt64(UniqueID);
DateTime dt1 = dateEdit1.DateTime;
DateTime dt2 = dateEdit2.DateTime;
new Thread(() => {
DataTable dataTable = ReadFile(mcFile, false, dt1, dt2, dianID, true, 0);
dataTable.AcceptChanges();
gridControl1.DataSource = dataTable;
}).Start();
Thread tr = new Thread(Thread.EndThreadAffinity);
}
ReadFile方法根据条件查找文件中的内容,显示出。
想实现通过sql语句查询出的结果多条件“ID”,查询文件中的内容显示出来。
现在只能实现单条查询,如何实现呢?