📄 findata.fxjdata.cs
字号:
msg = "";
fileStruct dzhFileStruct = new fileStruct(dataType);
if (newFileName != "") dzhFileStruct.fileName = newFileName; //如果用户重新指定了文件名
code = code.Trim().ToUpper();
if (code == "")
{
msg = @"CODE参数不可为空。请提供证券代码,如SZ000001。";
return new string[1, 1] { { null } };
}
ArrayList recordList = new ArrayList();
int intField; float floatField; double doubleField; //string stringField;
System.Globalization.CultureInfo cnCultureInfo = new System.Globalization.CultureInfo("zh-CN");
string market = code.Substring(0, 2);
int recordCounts = 0;
short[] blocks = new short[25];
long len = -1;
long pos = 0;
if (this.DzhDataPath == "")
{
msg = @"无法在注册表中到大智慧数据文件目录,请自行将属性 DzhDataPath设置为有效路径,如c:\dzh\data\。";
return new string[1, 1] { { null } };
}
string DzhFile = dzhDataPath + dzhFileStruct.fileName;
DzhFile = DzhFile.ToUpper();
if (!File.Exists(DzhFile))
{
DzhFile = dzhDataPath + market +@"\" +dzhFileStruct.fileName;
}
msg = "";
if (!File.Exists(DzhFile))
{
msg = dzhFileStruct.fileName + "没有找到!";
return new string[1, 1] { { null } };
}
#endregion
if (dzhFileStruct.isIndexDataStruct == true)
{
#region 处理DAY.DAT等结构(索引/数据)的数据
try
{
this.checkFileStream(DzhFile);
int secCounts = 0;//文件中证券总数
string code0 = "";
len = fs.Length;
fs.Position = 12;
secCounts = br.ReadInt32();
bool codeRead = false;
for (int i = 0; i < secCounts && codeRead==false; i++)
{
pos = 24 + 64 * i;
if (pos <= len)
{
fs.Position = pos;
//code0 = new string(br.ReadChars(10));//大智慧用10个字节保存代码,一般用8个字节
code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
code0 = code0.Replace("\0", "");
code0 = code0.Replace("HKHK", "HK"); //香港证券代码本身保存为HKxxxx
if (dzhFileStruct.codeIsLong == false && code == market + code0 || dzhFileStruct.codeIsLong == true && code == code0)
{
recordCounts = br.ReadInt32();
for (int j = 0; j < 25; j++)
{
blocks[j] = br.ReadInt16();
}
codeRead = true;
}
}
}
int iRecord = 1;//记录
int iBlock = 0;//第iBlock块
int fieldCounts = dzhFileStruct.fields.GetLength(0);
while (iBlock < 25 && blocks[iBlock] != -1)
{
int r = 0;
while (iRecord < recordCounts + 1 && r < dzhFileStruct.blockSize / dzhFileStruct.recordSize) //16=3776/236
{
string[] record = new string[fieldCounts];
pos = dzhFileStruct.startAddress + blocks[iBlock] * dzhFileStruct.blockSize + r * dzhFileStruct.recordSize;
for (int iField = 0; iField < fieldCounts; iField++)
{
fs.Position = pos + Convert.ToInt64(dzhFileStruct.fields[iField, 5]);
switch (dzhFileStruct.fields[iField, 2].ToLower())
{
case "code":
//code0 = new string(br.ReadChars(8));//有12位,实际用了8位,第9-12位一般为\0,有时是错误字节,因为只读8位
//code0 = code0.Replace("\0", "");
record[iField] = code;
break;
case "date":
intField = br.ReadInt32();
record[iField] = (intField == 0 ? "" : (date19700101.AddDays(intField / 86400)).ToString("yyyy-MM-dd"));
break;
case "datetime":
intField = br.ReadInt32();
record[iField] = (intField == 0 ? "" : (date19700101.AddSeconds(intField)).ToString("yyyy-MM-dd HH:mm:ss"));
break;
case "int":
intField = br.ReadInt32();
record[iField] = intField.ToString("D", cnCultureInfo);
break;
case "single":
//floatField = br.ReadSingle();
//if (dzhFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
//record[iField] = floatField.ToString("G", cnCultureInfo);
doubleField =(double) br.ReadSingle();
if (dzhFileStruct.fields[iField, 6].ToUpper() == "A") doubleField *= 100;
record[iField] = doubleField.ToString("_jj_qz".IndexOf(this.GetCodeType(code)) > 0 ? "F3" : "F", cnCultureInfo);
break;
case "double":
doubleField = br.ReadDouble();
record[iField] = doubleField.ToString("F", cnCultureInfo);
break;
case "string":
record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(dzhFileStruct.fields[iField, 3]))).Replace("\0", "");
break;
}
}
recordList.Add(record);
r = r + 1;
iRecord = iRecord + 1;
}
iBlock = iBlock + 1;
}
//fs.Close();
string[,] records = new string[recordList.Count, fieldCounts];
for (int i = 0; i < recordList.Count; i++)
{
string[] record0 = (string[])recordList[i];
for (int j = 0; j < fieldCounts; j++)
{
records[i, j] = record0[j];
}
}
if (records.GetLength(0) == 0) msg = "没有读到数据!";
return records;
}
catch (Exception e)
{
msg = e.Message;
}
#endregion
}
else
{
switch (dataType)
{
case DataTypes.dm:
#region 代码表(处理STKINFO60.DAT等结构的数据)
try
{
this.checkFileStream(DzhFile);
string[,] codesRename = new string[,]
{
{"SH1A0001","SH000001"},
{"SH1A0002","SH000002"},
{"SH1A0003","SH000003"},
{"SH1B0001","SH000004"},
{"SH1B0002","SH000005"},
{"SH1B0004","SH000006"},
{"SH1B0005","SH000007"},
{"SH1B0006","SH000008"},
{"SH1B0007","SH000010"},
{"SH1B0008","SH000011"},
{"SH1B0009","SH000012"},
{"SH1B0010","SH000013"},
{"SH1C0003","SH000016"}
};
int secCounts = 0;//文件中证券总数
string code0 = "";
fs.Position = 12;//8
secCounts = br.ReadInt32();
int fieldCounts = dzhFileStruct.fields.GetLength(0);
for (int i = 0; i < secCounts; i++)
{
pos = dzhFileStruct.startAddress + i * dzhFileStruct.recordSize;
fs.Position = pos;
code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
code0 = code0.Replace("\0", "");
code0 = code0.Replace("HKHK", "HK"); //香港证券代码本身保存为HKxxxx
if (Regex.IsMatch(code0, @"(1[ABC]00\d\d)") == false)
{
string[] recordFieldName = new string[fieldCounts];
string[] record = new string[fieldCounts];
for (int iField = 0; iField < fieldCounts; iField++)
{
fs.Position = pos + Convert.ToInt64(dzhFileStruct.fields[iField, 5]);
switch (dzhFileStruct.fields[iField, 2].ToLower())
{
case "code":
record[iField] = dzhFileStruct.codeIsLong == true ? code0 : market + code0;
record[iField] = record[iField].Replace("HKHK", "HK");
for (int icode = 0; icode < codesRename.GetLength(0); icode++)
{
record[iField] = record[iField].Replace(codesRename[icode, 0], codesRename[icode, 1]);
}
break;
case "date":
intField = br.ReadInt32();
record[iField] = (intField == 0 ? "" : (date19700101.AddDays(intField / 86400)).ToString("yyyy-MM-dd"));
break;
case "datetime":
intField = br.ReadInt32();
record[iField] = (intField == 0 ? "" : (date19700101.AddSeconds(intField)).ToString("yyyy-MM-dd HH:mm:ss"));
break;
case "int":
intField = br.ReadInt32();
record[iField] = intField.ToString("D");
break;
case "single":
floatField = br.ReadSingle();
if (dzhFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
record[iField] = floatField.ToString("F");
break;
case "double":
doubleField = br.ReadDouble();
record[iField] = doubleField.ToString("F");
break;
case "string":
record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(dzhFileStruct.fields[iField, 3]))).Replace("\0", "");
break;
}
}
recordList.Add(record);
}
}
//fs.Close();
string[,] records = new string[recordList.Count, fieldCounts];
for (int i = 0; i < recordList.Count; i++)
{
string[] record0 = (string[])recordList[i];
for (int j = 0; j < fieldCounts; j++)
{
records[i, j] = record0[j];
}
}
if (records.GetLength(0) == 0) msg = "没有读到数据!";
return records;
}
catch (Exception e)
{
msg = e.Message;
}
#endregion
break;
case DataTypes.hq0:
#region 最新行情(处理STKINFO60.DAT等结构的数据)
try
{
this.checkFileStream(DzhFile);
int secCounts = 0;//文件中证券总数
string code0 = "";
fs.Position = 12;
secCounts = br.ReadInt32();
int fieldCounts = dzhFileStruct.fields.GetLength(0);
bool hasCode = false;
for (int i = 0; i < secCounts && hasCode==false; i++)
{
pos = dzhFileStruct.startAddress + i * dzhFileStruct.recordSize;
fs.Position = pos;
code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
code0 = code0.Replace("\0", "");
code0 = code0.Replace("HKHK", "HK"); //香港证券代码本身保存为HKxxxx
if (dzhFileStruct.codeIsLong == false && code == market + code0 || dzhFileStruct.codeIsLong == true && code == code0)
{
hasCode = true;
string[] record = new string[fieldCounts];
for (int iField = 0; iField < fieldCounts; iField++)
{
fs.Position = pos + Convert.ToInt64(dzhFileStruct.fields[iField, 5]);
switch (dzhFileStruct.fields[iField, 2].ToLower())
{
case "code":
record[iField] = code;
break;
case "date":
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -