Example #1
0
        public TOCHandler(string tocFileName, string gamePath)
        {
            using (FileStream tocStream = File.OpenRead(tocFileName))
            {
                if (tocStream.ReadValueU32() != 0x3AB70C13)
                {
                    throw new Exception("not a toc.bin file");
                }

                tocFilePath   = Path.GetFullPath(tocFileName);
                this.gamePath = gamePath;

                chunkList = new List <chunk>();

                tocStream.Seek(8, SeekOrigin.Begin);

                int numChunks = tocStream.ReadValueS32();
                for (int i = 0; i < numChunks; i++)
                {
                    chunk newChunk = new chunk();
                    newChunk.offset      = tocStream.Position;
                    newChunk.relPosition = tocStream.ReadValueS32();
                    int countBlockFiles = tocStream.ReadValueS32();

                    if (countBlockFiles == 0)
                    {
                        chunkList.Add(newChunk);
                        continue;
                    }

                    newChunk.fileList = new List <fileStruct>();
                    tocStream.Seek(newChunk.relPosition - 8, SeekOrigin.Current);

                    for (int j = 0; j < countBlockFiles; j++)
                    {
                        fileStruct newFileStruct = new fileStruct();

                        long fileOffset = tocStream.Position;
                        tocStream.Seek(2, SeekOrigin.Current);
                        newFileStruct.flag     = tocStream.ReadValueS16();
                        newFileStruct.fileSize = tocStream.ReadValueS32();
                        newFileStruct.sha1     = tocStream.ReadBytes(20);
                        newFileStruct.filePath = tocStream.ReadStringZ();
                        newFileStruct.exist    = true;

                        tocStream.Seek(fileOffset + newFileStruct.blockSize, SeekOrigin.Begin);

                        newChunk.fileList.Add(newFileStruct);
                    }

                    tocStream.Seek(newChunk.offset + 8, SeekOrigin.Begin);

                    chunkList.Add(newChunk);
                }
            }
        }
Example #2
0
        public string saveToFile(bool fileOverwrite = true)
        {
            bChanged = false;

            string finalTocFile = fileOverwrite ? tocFilePath : tocFilePath + ".tmp";

            using (FileStream newFileStream = File.Create(finalTocFile))
            {
                newFileStream.WriteValueU32(0x3AB70C13);
                newFileStream.WriteValueS32(0x0);
                newFileStream.WriteValueS32(chunkList.Count);

                int chunkOffset = 12;
                int fileOffset  = 12 + (chunkList.Count * 8);

                string lastFile = chunkList.Last(x => (x.fileList != null) && x.fileList.Count(/*y => y.exist*/) != 0).fileList.Last(/*z => z.exist*/).filePath;

                //foreach (chunk element in chunkList)
                for (int i = 0; i < chunkList.Count; i++)
                {
                    chunk element = chunkList[i];
                    newFileStream.Seek(chunkOffset, SeekOrigin.Begin);

                    if (element.countNextFiles == 0)// || element.fileList.Count(x => x.exist) == 0)
                    {
                        newFileStream.WriteValueS64(0x0);
                        chunkOffset = (int)newFileStream.Position;
                    }
                    else
                    {
                        newFileStream.WriteValueS32(fileOffset - chunkOffset);
                        newFileStream.WriteValueS32(element.fileList.Count /*(x => x.exist)*/);
                        chunkOffset = (int)newFileStream.Position;

                        newFileStream.Seek(fileOffset, SeekOrigin.Begin);
                        //foreach (fileStruct fileElement in element.fileList.Where(x => x.exist))
                        for (int j = 0; j < element.fileList.Count; j++)
                        {
                            fileStruct fileElement = element.fileList[j];

                            //if (!fileElement.exist)
                            //    continue;
                            MemoryStream buffer = new MemoryStream(fileElement.blockSize);
                            {
                                if (fileElement.filePath == lastFile)
                                {
                                    buffer.WriteValueS16(0x0);
                                }
                                else
                                {
                                    buffer.WriteValueS16(fileElement.blockSize);
                                }
                                buffer.WriteValueS16(fileElement.flag);
                                buffer.WriteValueS32(fileElement.fileSize);
                                buffer.WriteBytes(fileElement.sha1);
                                buffer.WriteStringZ(fileElement.filePath);
                                byte[] byteBuff = new byte[fileElement.blockSize];
                                buffer.ToArray().CopyTo(byteBuff, 0);
                                newFileStream.WriteBytes(byteBuff);
                            }
                            //newFileStream.Seek(fileOffset, SeekOrigin.Begin);
                        }
                        fileOffset = (int)newFileStream.Position;
                    }
                }
            }

            return(finalTocFile);
        }
Example #3
0
        public void addFile(string newFileName, int blockIndex)
        {
            if (newFileName.Substring(0, gamePath.Length) != gamePath)
            {
                throw new Exception("Can't add \"" + Path.GetFileName(newFileName) + "\", it must reside inside \n" + gamePath);
            }

            string tocBinFilePath = newFileName.Substring(gamePath.Length);

            if (existsFile(newFileName))
            {
                throw new Exception("Can't add \"" + tocBinFilePath + "\",\nit already exist inside PCConsoleTOC.bin.");
            }

            /*foreach (chunk chunkElem in chunkList)
             * {
             *  if (chunkElem.fileList == null)
             *      continue;
             *  foreach (fileStruct fileElem in chunkElem.fileList)
             *  {
             *      if (tocBinFilePath.ToLower() == fileElem.filePath.ToLower())
             *      {
             *          throw new Exception("Can't add \"" + tocBinFilePath + "\",\nit already exist inside PCConsoleTOC.bin.");
             *      }
             *  }
             * }*/

            fileStruct addFileStruct = new fileStruct();

            switch (Path.GetExtension(newFileName))
            {
            case ".tlk":
            case ".tfc": addFileStruct.flag = 0x09; break;

            default: addFileStruct.flag = 0x01; break;
            }

            addFileStruct.filePath = tocBinFilePath;
            addFileStruct.exist    = true;

            using (FileStream fileStream = File.OpenRead(newFileName))
            {
                addFileStruct.fileSize = (int)fileStream.Length;
                using (SHA1 sha = SHA1.Create())
                {
                    sha.Initialize();
                    byte[] buffer     = new byte[fileStream.Length];
                    int    inputCount = fileStream.Read(buffer, 0, buffer.Length);
                    sha.TransformBlock(buffer, 0, inputCount, null, 0);
                    sha.TransformFinalBlock(buffer, 0, 0);
                    addFileStruct.sha1 = sha.Hash;
                }
            }

            if (chunkList[blockIndex].fileList == null)
            {
                chunkList[blockIndex].fileList = new List <fileStruct>();
            }
            chunkList[blockIndex].fileList.Add(addFileStruct);

            bChanged = true;
        }
Example #4
0
        public void addFile(string newFileName, int blockIndex)
        {
            if (newFileName.Substring(0, gamePath.Length) != gamePath)
            {
                throw new Exception("Can't add \"" + Path.GetFileName(newFileName) + "\", it must reside inside \n" + gamePath);
            }

            string tocBinFilePath = newFileName.Substring(gamePath.Length);
            if (existsFile(newFileName))
                throw new Exception("Can't add \"" + tocBinFilePath + "\",\nit already exist inside PCConsoleTOC.bin.");

            /*foreach (chunk chunkElem in chunkList)
            {
                if (chunkElem.fileList == null)
                    continue;
                foreach (fileStruct fileElem in chunkElem.fileList)
                {
                    if (tocBinFilePath.ToLower() == fileElem.filePath.ToLower())
                    {
                        throw new Exception("Can't add \"" + tocBinFilePath + "\",\nit already exist inside PCConsoleTOC.bin.");
                    }
                }
            }*/

            fileStruct addFileStruct = new fileStruct();

            switch (Path.GetExtension(newFileName))
            {
                case ".tlk":
                case ".tfc": addFileStruct.flag = 0x09; break;
                default: addFileStruct.flag = 0x01; break;
            }

            addFileStruct.filePath = tocBinFilePath;
            addFileStruct.exist = true;

            using (FileStream fileStream = File.OpenRead(newFileName))
            {
                addFileStruct.fileSize = (int)fileStream.Length;
                using (SHA1 sha = SHA1.Create())
                {
                    sha.Initialize();
                    byte[] buffer = new byte[fileStream.Length];
                    int inputCount = fileStream.Read(buffer, 0, buffer.Length);
                    sha.TransformBlock(buffer, 0, inputCount, null, 0);
                    sha.TransformFinalBlock(buffer, 0, 0);
                    addFileStruct.sha1 = sha.Hash;
                }
            }

            if (chunkList[blockIndex].fileList == null)
                chunkList[blockIndex].fileList = new List<fileStruct>();
            chunkList[blockIndex].fileList.Add(addFileStruct);

            bChanged = true;
        }
Example #5
0
        public TOCHandler(string tocFileName, string gamePath)
        {
            using (FileStream tocStream = File.OpenRead(tocFileName))
            {
                if (tocStream.ReadValueU32() != 0x3AB70C13)
                    throw new Exception("not a toc.bin file");

                tocFilePath = Path.GetFullPath(tocFileName);
                this.gamePath = gamePath;

                chunkList = new List<chunk>();

                tocStream.Seek(8, SeekOrigin.Begin);

                int numChunks = tocStream.ReadValueS32();
                for (int i = 0; i < numChunks; i++)
                {
                    chunk newChunk = new chunk();
                    newChunk.offset = tocStream.Position;
                    newChunk.relPosition = tocStream.ReadValueS32();
                    int countBlockFiles = tocStream.ReadValueS32();

                    if (countBlockFiles == 0)
                    {
                        chunkList.Add(newChunk);
                        continue;
                    }

                    newChunk.fileList = new List<fileStruct>();
                    tocStream.Seek(newChunk.relPosition - 8, SeekOrigin.Current);

                    for (int j = 0; j < countBlockFiles; j++)
                    {
                        fileStruct newFileStruct = new fileStruct(); 
                        
                        long fileOffset = tocStream.Position;
                        tocStream.Seek(2, SeekOrigin.Current);
                        newFileStruct.flag = tocStream.ReadValueS16();
                        newFileStruct.fileSize = tocStream.ReadValueS32();
                        newFileStruct.sha1 = tocStream.ReadBytes(20);
                        newFileStruct.filePath = tocStream.ReadStringZ();
                        newFileStruct.exist = true;

                        tocStream.Seek(fileOffset + newFileStruct.blockSize, SeekOrigin.Begin);

                        newChunk.fileList.Add(newFileStruct);
                    }

                    tocStream.Seek(newChunk.offset + 8, SeekOrigin.Begin);

                    chunkList.Add(newChunk);
                }
            }
        }
        //��ȡ���ݣ�����
        public string[,] GetData(DataTypes dataType,string code,string newFileName)
        {
            #region ��ȡ����ǰ��ʼ��
            msg = "";
            fileStruct fxjFileStruct = new fileStruct(dataType);
            if (newFileName != "") fxjFileStruct.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;
            string market = code.Substring(0, 2);
            int recordCounts = 0;
            short[] blocks = new short[25];
            long len = -1;
            long pos = 0;
            if (this.FxjDataPath == "")
            {
                msg = @"�޷���ע����е������������ļ�Ŀ¼�������н����� FxjDataPath����Ϊ��Ч·������c:\fxj\data\��";
                return new string[1, 1] { { null } };
            }
            string FxjFile = fxjDataPath + fxjFileStruct.fileName;
            if (!File.Exists(FxjFile))
            {
                FxjFile = fxjDataPath + market +@"\" +fxjFileStruct.fileName;
            }
            msg = "";
            if (!File.Exists(FxjFile))
            {
                msg = fxjFileStruct.fileName + "û���ҵ���";
                return new string[1, 1] { { null } };
            }
            #endregion
            if (fxjFileStruct.isIndexDataStruct == true)
            {
                #region ����DAY.DAT�Ƚṹ������/���ݣ�������
                try
                {
                    FileStream fs = new FileStream(FxjFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    BinaryReader br = new BinaryReader(fs);
                    int secCounts = 0;//�ļ���֤ȯ����
                    string code0 = "";
                    len = fs.Length;
                    fs.Position = 12;
                    secCounts = br.ReadInt32();
                    for (int i = 0; i < secCounts; 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 (fxjFileStruct.codeIsLong == false && code == market + code0 || fxjFileStruct.codeIsLong == true && code == code0)
                            {
                                recordCounts = br.ReadInt32();
                                for (int j = 0; j < 25; j++)
                                {
                                    blocks[j] = br.ReadInt16();
                                }
                            }
                        }
                    }
                    int iRecord = 1;//��¼
                    int iBlock = 0;//��iBlock��
                    int fieldCounts = fxjFileStruct.fields.GetLength(0);
                    while (iBlock < 25 && blocks[iBlock] != -1)
                    {
                        int r = 0;
                        while (iRecord < recordCounts + 1 && r < fxjFileStruct.blockSize / fxjFileStruct.recordSize)   //16=3776/236
                        {
                            string[] record = new string[fieldCounts];
                            pos = fxjFileStruct.startAddress + blocks[iBlock] * fxjFileStruct.blockSize + r * fxjFileStruct.recordSize;
                            for (int iField = 0; iField < fieldCounts; iField++)
                            {
                                fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                switch (fxjFileStruct.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 "int":
                                        intField = br.ReadInt32();
                                        record[iField] = intField.ToString();
                                        break;
                                    case "single":
                                        floatField = br.ReadSingle();
                                        if (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                        record[iField] = floatField.ToString();
                                        break;
                                    case "double":
                                        doubleField = br.ReadDouble();
                                        record[iField] = doubleField.ToString();
                                        break;
                                    case "string":
                                        record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.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];
                        }
                    }
                    return records;
                }
                catch (Exception e)
                {
                    msg = e.Message;
                }
                #endregion
            }
            else
            {
                switch (dataType)
                {
                    case DataTypes.dm:
                        #region ����������STKINFO51.DAT�Ƚṹ�����ݣ�
                        try
                        {
                            FileStream fs = new FileStream(FxjFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            BinaryReader br = new BinaryReader(fs);
                            int secCounts = 0;//�ļ���֤ȯ����
                            string code0 = "";
                            fs.Position = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            for (int i = 0; i < secCounts; i++)
                            {
                                pos = fxjFileStruct.startAddress + i * fxjFileStruct.recordSize;
                                fs.Position = pos;
                                code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
                                code0 = code0.Replace("\0", "");
                                code0 = code0.Replace("HKHK", "HK");   //���֤ȯ���뱾�����ΪHKxxxx
                                string[] recordFieldName = new string[fieldCounts];
                                string[] record = new string[fieldCounts];
                                for (int iField = 0; iField < fieldCounts; iField++)
                                {
                                    fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                    switch (fxjFileStruct.fields[iField, 2].ToLower())
                                    {
                                        case "code":
                                            record[iField] = fxjFileStruct.codeIsLong == true ? code0 : market + code0;
                                            record[iField] = record[iField].Replace("HKHK", "HK");
                                            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();
                                            break;
                                        case "single":
                                            floatField = br.ReadSingle();
                                            if (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                            record[iField] = floatField.ToString();
                                            break;
                                        case "double":
                                            doubleField = br.ReadDouble();
                                            record[iField] = doubleField.ToString();
                                            break;
                                        case "string":
                                            record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.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];
                                }
                            }
                            return records;
                        }
                        catch (Exception e)
                        {
                            msg = e.Message;
                        }
                        #endregion
                        break;
                    case DataTypes.zxhq:
                        #region �������飨����STKINFO51.DAT�Ƚṹ�����ݣ�
                        try
                        {
                            FileStream fs = new FileStream(FxjFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            BinaryReader br = new BinaryReader(fs);
                            int secCounts = 0;//�ļ���֤ȯ����
                            string code0 = "";
                            fs.Position = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            bool hasCode = false;
                            for (int i = 0; i < secCounts && hasCode==false; i++)
                            {
                                pos = fxjFileStruct.startAddress + i * fxjFileStruct.recordSize;
                                fs.Position = pos;
                                code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
                                code0 = code0.Replace("\0", "");
                                code0 = code0.Replace("HKHK", "HK");   //���֤ȯ���뱾�����ΪHKxxxx
                                if (fxjFileStruct.codeIsLong == false && code == market + code0 || fxjFileStruct.codeIsLong == true && code == code0)
                                {
                                    hasCode = true;
                                    string[] record = new string[fieldCounts];
                                    for (int iField = 0; iField < fieldCounts; iField++)
                                    {
                                        fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                        switch (fxjFileStruct.fields[iField, 2].ToLower())
                                        {
                                            case "code":
                                                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();
                                                break;
                                            case "single":
                                                floatField = br.ReadSingle();
                                                if (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                                record[iField] = Math.Round(floatField,2).ToString();
                                                break;
                                            case "double":
                                                doubleField = br.ReadDouble();
                                                record[iField] = Math.Round(doubleField,2).ToString();
                                                break;
                                            case "string":
                                                record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.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];
                                }
                            }
                            return records;
                        }
                        catch (Exception e)
                        {
                            msg = e.Message;
                        }
                        #endregion
                        break;
                    case DataTypes.cq:
                        #region �ֺ����䣨����STKINFO51.DAT�Ƚṹ�����ݣ�
                        try
                        {
                            FileStream fs = new FileStream(FxjFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            BinaryReader br = new BinaryReader(fs);
                            int secCounts = 0;//�ļ���֤ȯ����
                            string code0 = "";
                            fileStruct fxjdmStruct = new fileStruct(DataTypes.dm);//    ����Ľṹ
                            int dmpos=0;
                            fs.Position = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            bool hasCode = false;
                            for (int i = 0; i < secCounts && hasCode==false; i++)
                            {
                                dmpos = fxjdmStruct.startAddress + i * fxjdmStruct.recordSize;
                                fs.Position = dmpos;
                                code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
                                code0 = code0.Replace("\0", "");
                                code0 = code0.Replace("HKHK", "HK");   //���֤ȯ���뱾�����ΪHKxxxx
                                if (fxjdmStruct.codeIsLong == false && code == market + code0 || fxjdmStruct.codeIsLong == true && code == code0)
                                {
                                    hasCode = true;
                                    int iRecord=0;
                                    pos = fxjFileStruct.startAddress + i * fxjFileStruct.blockSize + iRecord * fxjFileStruct.recordSize;
                                    fs.Position=pos;
                                    while (br.ReadInt32() != 0)
                                    {
                                        string[] record = new string[fieldCounts];
                                        for (int iField = 0; iField < fieldCounts; iField++)
                                        {
                                            fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                            switch (fxjFileStruct.fields[iField, 2].ToLower())
                                            {
                                                case "code":
                                                    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();
                                                    break;
                                                case "single":
                                                    floatField = br.ReadSingle();
                                                    if (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                                    record[iField] = Math.Round(floatField,2).ToString();
                                                    break;
                                                case "double":
                                                    doubleField = br.ReadDouble();
                                                    record[iField] = Math.Round(doubleField,2).ToString();
                                                    break;
                                                case "string":
                                                    record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.fields[iField, 3]))).Replace("\0", "");
                                                    break;
                                            }

                                        }
                                        recordList.Add(record);
                                        iRecord = iRecord + 1;
                                        pos = fxjFileStruct.startAddress + i * fxjFileStruct.blockSize + iRecord * fxjFileStruct.recordSize;
                                        fs.Position = pos;

                                    }

                                }

                            }

                            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];
                                }
                            }
                            return records;
                        }
                        catch (Exception e)
                        {
                            msg = e.Message;
                        }
                        #endregion
                        break;
                    case DataTypes.cw0:
                        #region ��������--�򵥣�����STKINFO51.DAT�Ƚṹ�����ݣ�
                        try
                        {
                            FileStream fs = new FileStream(FxjFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            BinaryReader br = new BinaryReader(fs);
                            int secCounts = 0;//�ļ���֤ȯ����
                            string code0 = "";
                            fileStruct fxjdmStruct = new fileStruct(DataTypes.dm);//    ����Ľṹ
                            int dmpos = 0;
                            fs.Position = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            bool hasCode = false;
                            for (int i = 0; i < secCounts && hasCode == false; i++)
                            {
                                dmpos = fxjdmStruct.startAddress + i * fxjdmStruct.recordSize;
                                fs.Position = dmpos;
                                code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
                                code0 = code0.Replace("\0", "");
                                code0 = code0.Replace("HKHK", "HK");   //���֤ȯ���뱾�����ΪHKxxxx
                                if (fxjdmStruct.codeIsLong == false && code == market + code0 || fxjdmStruct.codeIsLong == true && code == code0)
                                {
                                    hasCode = true;
                                    int iRecord = 0;
                                    pos = fxjFileStruct.startAddress + i * fxjFileStruct.blockSize + iRecord * fxjFileStruct.recordSize;
                                    fs.Position = pos;
                                    string[] record = new string[fieldCounts];
                                    for (int iField = 0; iField < fieldCounts; iField++)
                                    {
                                        fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                        switch (fxjFileStruct.fields[iField, 2].ToLower())
                                        {
                                            case "code":
                                                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();
                                                break;
                                            case "single":
                                                floatField = br.ReadSingle();
                                                if (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                                record[iField] = Math.Round(floatField,2).ToString();
                                                break;
                                            case "double":
                                                doubleField = br.ReadDouble();
                                                record[iField] = Math.Round(doubleField,2).ToString();
                                                break;
                                            case "string":
                                                record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.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];
                                }
                            }
                            return records;
                        }
                        catch (Exception e)
                        {
                            msg = e.Message;
                        }
                        #endregion
                        break;
                    case DataTypes.fbcj:
                        #region ����Report.DAT���ݣ��ṹ����DAY.DAT������Щ��ֵ��Ҫ��һ�����������
                        try
                        {
                            FileStream fs = new FileStream(FxjFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            BinaryReader br = new BinaryReader(fs);
                            int secCounts = 0;//�ļ���֤ȯ����
                            string code0 = "";
                            len = fs.Length;
                            fs.Position = 12;
                            secCounts = br.ReadInt32();
                            for (int i = 0; i < secCounts; 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 (fxjFileStruct.codeIsLong == false && code == market + code0 || fxjFileStruct.codeIsLong == true && code == code0)
                                    {
                                        recordCounts = br.ReadInt32();
                                        for (int j = 0; j < 25; j++)
                                        {
                                            blocks[j] = br.ReadInt16();
                                        }
                                    }
                                }
                            }
                            int iRecord = 1;//��¼
                            int iBlock = 0;//��iBlock��
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            while (iBlock < 25 && blocks[iBlock] != -1)
                            {
                                int r = 0;
                                while (iRecord < recordCounts + 1 && r < fxjFileStruct.blockSize / fxjFileStruct.recordSize)   //16=3776/236
                                {
                                    string[] record = new string[fieldCounts];
                                    pos = fxjFileStruct.startAddress + blocks[iBlock] * fxjFileStruct.blockSize + r * fxjFileStruct.recordSize;
                                    for (int iField = 0; iField < fieldCounts; iField++)
                                    {
                                        fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                        switch (fxjFileStruct.fields[iField, 0].ToLower()) //�������ȡDAY.DAT�÷���ͬ���жϵ��Ǵ������������
                                        {
                                            case "dm":
                                                record[iField] = code;
                                                break;
                                            case "rq":
                                                intField = br.ReadInt32();
                                                record[iField] = (intField == 0 ? "" : (date19700101.AddSeconds(intField)).ToString("yyyy-MM-dd HH:mm:ss"));
                                                break;
                                            case "zjcj":
                                            case "zss":
                                            case "je":
                                                floatField = br.ReadSingle();
                                                record[iField] = floatField.ToString();
                                                break;
                                            case "mr1sl":
                                            case "mr2sl":
                                            case "mr3sl":
                                            case "mc1sl":
                                            case "mc2sl":
                                            case "mc3sl":
                                                record[iField] = br.ReadInt16().ToString();
                                                break;
                                            case "mr1jg":
                                            case "mr2jg":
                                            case "mr3jg":
                                            case "mc1jg":
                                            case "mc2jg":
                                            case "mc3jg":
                                                float jg=br.ReadSByte();
                                                jg = Convert.ToSingle(record[2])  + jg / 100;
                                                record[iField] = jg.ToString();
                                                break;
                                            case "xss":
                                                record[iField] = "";//���������������
                                                break;
                                            case "mm":
                                                int mm = br.ReadSByte();
                                                record[iField] = "";
                                                if (mm == -128) record[iField] = "��"; //-128 = 0x80
                                                if (mm == -64) record[iField] = "��";  //-64 = 0xC0
                                                break;
                                        }

                                    }

                                    recordList.Add(record);

                                    r = r + 1;
                                    iRecord = iRecord + 1;
                                }
                                iBlock = iBlock + 1;
                            }

                            fs.Close();
                            float zssSaved = 0;
                            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++)
                                {
                                    if (j == 5)  //������
                                    {
                                        record0[j]= (Convert.ToSingle(record0[3]) - zssSaved).ToString();
                                        zssSaved = Convert.ToSingle(record0[3]);
                                    }
                                    records[i, j] = record0[j];
                                }
                            }
                            return records;
                        }
                        catch (Exception e)
                        {
                            msg = e.Message;
                        }
                        #endregion

                        break;
                }

            }
            msg = "���ؿ����顣";
            return new string[1, 1] { { null } };
        }
        public string[,] GetFields(DataTypes dataType)
        {
            msg = "";
            try
            {
                fileStruct fxjFileStruct = new fileStruct(dataType);
                string[,] fields = new string[fxjFileStruct.fields.GetLength(0), 3];
                //fields[0, 0] = "<�ֶ���>"; fields[0, 1] = "<����>"; fields[0, 2] = "<����>";
                for (int i = 0; i < fxjFileStruct.fields.GetLength(0); i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        fields[i, j] = fxjFileStruct.fields[i, j];
                    }
                }

                return fields;
            }
            catch
            {
                msg = "����"; return new string[1, 1] { { null } };
            }
        }
Example #8
0
        private string[,] GetPJ(string code)//评级数据
        {
            msg = "";
            fileStruct fxjFileStruct = new fileStruct(DataTypes.pj);
            code = code.Trim().ToUpper();
            ArrayList recordList = new ArrayList();
            if (this.FxjDataPath == "")
            {
                msg = @"无法在注册表中到分析家数据文件目录,请自行将属性 FxjDataPath设置为有效路径,如c:\fxj\data\。";
                return new string[1, 1] { { null } };
            }
            string fxjSubPath = fxjDataPath;
            fxjSubPath = fxjSubPath.ToUpper().Replace("\\DATA\\", "\\USERDATA\\SelfData\\"); //假设目录中含有data文字
            string FxjFile = fxjSubPath + fxjFileStruct.fileName;

            msg = "";
            if (!File.Exists(FxjFile))
            {
                msg = fxjFileStruct.fileName +"无法找到。";
                return new string[1, 1] { { null } };
            }
            try
            {
                this.checkFileStream(FxjFile);
                int n = 0;
                int pos =fxjFileStruct.startAddress + n * fxjFileStruct.recordSize;
                fs.Position = pos;
                while (br.PeekChar()!=-1)
                {
                    string[] record = new string[3];
                    pos = fxjFileStruct.startAddress + n * fxjFileStruct.recordSize;
                    fs.Position = pos;
                    record[0]=System.Text.Encoding.Default.GetString(br.ReadBytes(8));//dm 
                    if (code==""||(code!="" && code==record[0]))
                    {
                        fs.Position = pos+12;
                        record[2] = System.Text.Encoding.Default.GetString(br.ReadBytes(244));
                        record[1] = record[2].Substring(0,2).Trim();
                        record[2] = record[2].Replace("\0","").Trim();
                        if(record[0]!="") recordList.Add(record);
                    }
                    n = n + 1;
                }

                if (n > 0)
                {
                    string[,] records = new string[recordList.Count, 3];
                    for (int i = 0; i < recordList.Count; i++)
                    {
                        string[] record0 = (string[])recordList[i];
                        if (record0[0] != null)
                        {
                            records[i, 0] = record0[0];
                            records[i, 1] = record0[1];
                            records[i, 2] = record0[2];
                        }
                    }
                    if (records.GetLength(0) == 0) msg = "没有读到数据!";
                    return records;
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            return new string[1, 1] { { null } };

        }
Example #9
0
        private string[,] GetBK(string code)//板块定义数据
        {
            msg = "";
            fileStruct fxjFileStruct = new fileStruct(DataTypes.bk);
            if (code == null) code = "";
            code = code.Trim().ToUpper();
            ArrayList recordList = new ArrayList();
            if (this.FxjDataPath == "")
            {
                msg = @"无法在注册表中到分析家数据文件目录,请自行将属性 FxjDataPath设置为有效路径,如c:\fxj\data\。";
                return new string[1, 1] { { null } };
            }
            string FxjBlockPath = fxjDataPath;
            FxjBlockPath = FxjBlockPath.ToUpper().Replace("\\DATA\\", "\\USERDATA\\BLOCK\\") ; //假设目录中含有data文字
            string FxjFile = FxjBlockPath + fxjFileStruct.fileName;
            
            msg = "";
            if (!File.Exists(FxjFile))
            {
                msg = "板块文件无法找到。";
                return new string[1, 1] { { null } };
            }
            try
            {
                this.checkFileStream(FxjFile);
                string bklines="";string lb="";string bk="";
                string bkFile = ""; string dmLines = ""; int n = -1;
                bklines=System.Text.Encoding.Default.GetString(br.ReadBytes((int)fs.Length));
                string[] bks = bklines.Replace("\r\n","\n").Split(new Char[] { '\n' });
                for(int i =0 ; i<bks.Length;i++)
                {
                    if (bks[i] != "")
                    {
                        bks[i] = bks[i].Trim();
                        if (bks[i].StartsWith("[") && bks[i].EndsWith("]"))
                        {
                            lb = bks[i].Replace("[","").Replace("]","");
                        }
                        else
                        {
                            bk = bks[i];
                            if (bk != "")
                            {
                                if (code == "" || (code!="" && bk.ToUpper()==code) )
                                {
                                    bkFile = FxjBlockPath + bk + ".blk";
                                    if (File.Exists(bkFile))
                                    {
                                        StreamReader bkReader = new StreamReader(bkFile);
                                        bkReader.Read(); bkReader.Read();
                                        dmLines = bkReader.ReadToEnd();
                                        dmLines = dmLines.Replace("\x05", "\0").Replace("\0Z00", "\0\0\0\0").Replace("\0\0\0\0", ",");
                                        string[] dms = dmLines.Split(',');
                                        string[,] record = new string[dms.Length, 3];
                                        for (int r = 0; r < dms.Length; r++)
                                        {
                                            if (dms[r] != "")
                                            {
                                                n = n + 1;
                                                record[r, 0] = lb;
                                                record[r, 1] = bk;
                                                record[r, 2] = dms[r];
                                            }
                                        }
                                        recordList.Add(record);
                                    }
                                }
                            }
                        }
                    }
                }
                if (n > 0)
                {
                    string[,] records = new string[n+1, 3];
                    int rr = 0;
                    for (int i = 0; i < recordList.Count; i++)
                    {
                        string[,] record0 = (string[,])recordList[i];
                        for (int j = 0; j < record0.GetLength(0); j++)
                        {
                            if (record0[j, 0] != null && record0[j, 1] != null && record0[j,2]!=null)
                            {
                                records[rr, 0] = record0[j, 0];
                                records[rr, 1] = record0[j, 1];
                                records[rr, 2] = record0[j, 2];
                                rr = rr + 1;
                            }
                        }
                    }
                    if (records.GetLength(0) == 0) msg = "没有读到数据!";
                    return records;
                }
            }
            catch (Exception e)
            {
                msg = e.Message;
            }
            return new string[1, 1] { { null } };

        }
Example #10
0
        private string[,] GetData(DataTypes dataType,string code,string newFileName,int iRecordCount) //读取数据,重载
        {
            if (dataType == DataTypes.bk) return GetBK(code);
            if (dataType == DataTypes.pj) return GetPJ(code);
            if (dataType == DataTypes.hqfq) return GetHqfq(dataType,code,newFileName,iRecordCount );
            #region 读取数据前初始化
            msg = "";
            fileStruct fxjFileStruct = new fileStruct(dataType);
            if (newFileName != "") fxjFileStruct.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.FxjDataPath == "")
            {
                msg = @"无法在注册表中到分析家数据文件目录,请自行将属性 FxjDataPath设置为有效路径,如c:\fxj\data\。";
                return new string[1, 1] { { null } };
            }
            string FxjFile = fxjDataPath + fxjFileStruct.fileName;
            FxjFile = FxjFile.ToUpper();
            if (!File.Exists(FxjFile))
            {
                FxjFile = fxjDataPath + market +@"\" +fxjFileStruct.fileName;
            }
            msg = "";
            if (!File.Exists(FxjFile)) 
            {
                msg = fxjFileStruct.fileName + "没有找到!";
                return new string[1, 1] { { null } };
            }
            #endregion
            if (fxjFileStruct.isIndexDataStruct == true)
            {
                #region 处理DAY.DAT等结构(索引/数据)的数据,目前包括分时数据、1分钟数据、5分钟数据、日数据...
                try
                {
                    this.checkFileStream(FxjFile);
                    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 (fxjFileStruct.codeIsLong == false && code == market + code0 || fxjFileStruct.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 = fxjFileStruct.fields.GetLength(0);

                    while (iBlock < 25 && blocks[iBlock] != -1)
                    {
                        int r = 0;
                        ////long tempAddress = 0;
                        ////long tempAddress1 = 0;
                        ////long tempResult = 0;
                        ////int tempPos = 0;
                         //while (iRecord < 20000)   //test
                       while (iRecord < recordCounts + 1 && r < fxjFileStruct.blockSize / fxjFileStruct.recordSize)
                        {
                            string[] record = new string[fieldCounts];
                            //pos = fxjFileStruct.startAddress + r * fxjFileStruct.recordSize;//test,用来推测单个blocks数据块的大小
                            pos = fxjFileStruct.startAddress + blocks[iBlock] * fxjFileStruct.blockSize + r * fxjFileStruct.recordSize;
                            for (int iField = 0; iField < fieldCounts; iField++)
                            {
                                fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                switch (fxjFileStruct.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":

                                        ////tempAddress1 = tempAddress; //lps
                                        ////tempAddress = fs.Position; //lps

                                        ////if (iRecord > 1) //lps
                                        ////    tempResult = tempAddress - tempAddress1;  //lps

                                        ////intField = br.ReadInt32();
                                        ////if (intField >= 14148.625 * 86400)//test
                                        ////    Console.WriteLine(tempAddress.ToString());

                                        ////record[iField] = (intField == 0 ? "" : (date19700101.AddSeconds(intField)).ToString("yyyy-MM-dd HH:mm:ss"));
                                        ////record[iField] = record[iField] + "|地址:" + tempAddress.ToString() + "(" + tempResult.ToString() + ")";  //test


                                        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 (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                        //record[iField] = floatField.ToString("G", cnCultureInfo);
                                        doubleField =(double) br.ReadSingle();
                                        if (fxjFileStruct.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(fxjFileStruct.fields[iField, 3]))).Replace("\0", "");
                                        break;
                                }
                            }

                            recordList.Add(record);

                            r = r + 1;
                            iRecord = iRecord + 1;                        
                        }
                        iBlock = iBlock + 1;  
                    }

                    if (iRecordCount == 0 || iRecordCount > recordList.Count) iRecordCount = recordList.Count;
                    string[,] records = new string[iRecordCount, fieldCounts];
                    for (int i = 0; i < iRecordCount; i++)
                    {
                        string[] record0 = (string[])recordList[recordList.Count - 1 - 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(FxjFile);
                            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 = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            for (int i = 0; i < secCounts; i++)
                            {
                                pos = fxjFileStruct.startAddress + i * fxjFileStruct.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(fxjFileStruct.fields[iField, 5]);
                                        switch (fxjFileStruct.fields[iField, 2].ToLower())
                                        {
                                            case "code":
                                                record[iField] = fxjFileStruct.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 (fxjFileStruct.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(fxjFileStruct.fields[iField, 3]))).Replace("\0", "");
                                                break;
                                        }

                                    }
                                    if (code0 != "") 
                                        recordList.Add(record);
                                }                             
                            }

                            if (iRecordCount == 0 || iRecordCount > recordList.Count) iRecordCount = recordList.Count;
                            string[,] records = new string[iRecordCount, fieldCounts];
                            for (int i = 0; i < iRecordCount; 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(FxjFile);
                            int secCounts = 0;//文件中证券总数
                            string code0 = "";
                            fs.Position = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            bool hasCode = false;
                            for (int i = 0; i < secCounts && hasCode==false; i++)
                            {
                                pos = fxjFileStruct.startAddress + i * fxjFileStruct.recordSize;
                                fs.Position = pos;
                                code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
                                code0 = code0.Replace("\0", "");
                                code0 = code0.Replace("HKHK", "HK");   //香港证券代码本身保存为HKxxxx
                                if (fxjFileStruct.codeIsLong == false && code == market + code0 || fxjFileStruct.codeIsLong == true && code == code0 || code0 != "" && code.Length ==2)
                                {
                                    

                                    if (code0 != "" && code.Length ==2)
                                        hasCode = false;
                                    else 
                                        hasCode = true;

                                    string[] record = new string[fieldCounts];
                                    double doubleTemp=0;
                                    for (int iField = 0; iField < fieldCounts ; iField++)
                                    {
                                        fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                        doubleTemp = fs.Position;
                                        switch (fxjFileStruct.fields[iField, 2].ToLower())
                                        {
                                            case "code":
                                                record[iField] = code;
                                                if (code0 != "" && code.Length == 2)
                                                    record[iField] = market + code0;
                                                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":
                                                doubleField = (double)br.ReadSingle();
                                                if (fxjFileStruct.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] = Math.Round(doubleField, 2).ToString("F");
                                                break;
                                            case "string":
                                                record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.fields[iField, 3]))).Replace("\0", "");
                                                break;
                                        }

                                        ////Console.WriteLine((doubleTemp.ToString())+":" + record[iField]);
                                    }
                                    if (code0 != "")
                                        recordList.Add(record);
                                }
                            }

                            if (iRecordCount == 0 || iRecordCount > recordList.Count) iRecordCount = recordList.Count;
                            string[,] records = new string[iRecordCount, fieldCounts];
                            for (int i = 0; i < iRecordCount; 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.cq:
                        #region 分红送配(处理STKINFO60.DAT等结构的数据)//除权
                        try
                        {
                            this.checkFileStream(FxjFile);
                            int secCounts = 0;//文件中证券总数
                            string code0 = "";
                            fileStruct fxjdmStruct = new fileStruct(DataTypes.dm);//    代码的结构
                            int dmpos=0;
                            fs.Position = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            bool hasCode = false;
                            for (int i = 0; i < secCounts && hasCode==false; i++)
                            {
                                dmpos = fxjdmStruct.startAddress + i * fxjdmStruct.recordSize;
                                fs.Position = dmpos;
                                code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
                                code0 = code0.Replace("\0", "");
                                code0 = code0.Replace("HKHK", "HK");   //香港证券代码本身保存为HKxxxx
                                if (fxjdmStruct.codeIsLong == false && code == market + code0 || fxjdmStruct.codeIsLong == true && code == code0)
                                {
                                    hasCode = true;
                                    int iRecord=0;
                                    pos = fxjFileStruct.startAddress + i * fxjFileStruct.blockSize + iRecord * fxjFileStruct.recordSize;
                                    fs.Position=pos;
                                    while (br.ReadInt32() != 0)
                                    {
                                        string[] record = new string[fieldCounts];
                                        for (int iField = 0; iField < fieldCounts; iField++)
                                        {
                                            fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                            switch (fxjFileStruct.fields[iField, 2].ToLower())
                                            {
                                                case "code":
                                                    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");
                                                    break;
                                                case "single":
                                                    floatField = br.ReadSingle();
                                                    if (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                                    record[iField] = Math.Round(floatField, 2).ToString("F");
                                                    break;
                                                case "double":
                                                    doubleField = br.ReadDouble();
                                                    record[iField] = Math.Round(doubleField, 2).ToString("F");
                                                    break;
                                                case "string":
                                                    record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.fields[iField, 3]))).Replace("\0", "");
                                                    break;
                                            }
                                        }
                                        recordList.Add(record);
                                        iRecord = iRecord + 1;
                                        pos = fxjFileStruct.startAddress + i * fxjFileStruct.blockSize + iRecord * fxjFileStruct.recordSize;
                                        fs.Position = pos;

                                    }
                                }
                            }

                            if (iRecordCount == 0 || iRecordCount > recordList.Count) iRecordCount = recordList.Count;
                            string[,] records = new string[iRecordCount, fieldCounts];
                            for (int i = 0; i < iRecordCount; 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.cw0:
                        #region 财务数据--简单(处理STKINFO60.DAT等结构的数据)
                        try
                        {
                            this.checkFileStream(FxjFile);
                            int secCounts = 0;//文件中证券总数
                            string code0 = "";
                            fileStruct fxjdmStruct = new fileStruct(DataTypes.dm);//    代码的结构
                            int dmpos = 0;
                            fs.Position = 8;
                            secCounts = br.ReadInt32();
                            int fieldCounts = fxjFileStruct.fields.GetLength(0);
                            bool hasCode = false;
                            for (int i = 0; i < secCounts && hasCode == false; i++)
                            {
                                dmpos = fxjdmStruct.startAddress + i * fxjdmStruct.recordSize;
                                fs.Position = dmpos;
                                code0 = System.Text.Encoding.Default.GetString(br.ReadBytes(10));
                                code0 = code0.Replace("\0", "");
                                code0 = code0.Replace("HKHK", "HK");   //香港证券代码本身保存为HKxxxx
                                if (fxjdmStruct.codeIsLong == false && code == market + code0 || fxjdmStruct.codeIsLong == true && code == code0)
                                {
                                    hasCode = true;
                                    int iRecord = 0;
                                    pos = fxjFileStruct.startAddress + i * fxjFileStruct.blockSize + iRecord * fxjFileStruct.recordSize;
                                    fs.Position = pos;
                                    string[] record = new string[fieldCounts];
                                    for (int iField = 0; iField < fieldCounts; iField++)
                                    {
                                        fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                        switch (fxjFileStruct.fields[iField, 2].ToLower())
                                        {
                                            case "code":
                                                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");
                                                break;
                                            case "single":
                                                floatField = br.ReadSingle();
                                                if (fxjFileStruct.fields[iField, 6].ToUpper() == "A") floatField *= 100;
                                                record[iField] = Math.Round(floatField, 3).ToString("F3");
                                                break;
                                            case "double":
                                                doubleField = br.ReadDouble();
                                                record[iField] = Math.Round(doubleField, 3).ToString("F3");
                                                break;
                                            case "string":
                                                record[iField] = System.Text.Encoding.Default.GetString(br.ReadBytes(Convert.ToInt32(fxjFileStruct.fields[iField, 3]))).Replace("\0", "");
                                                break;
                                        }

                                    }
                                    recordList.Add(record);
                                }

                            }

                            if (iRecordCount == 0 || iRecordCount > recordList.Count) iRecordCount = recordList.Count;
                            string[,] records = new string[iRecordCount, fieldCounts];
                            for (int i = 0; i < iRecordCount; 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.hqmb:
                        #region 处理Report.DAT数据(结构类似DAY.DAT,但有些数值需要进一步计算而来)
                        try
                        {
                            this.checkFileStream(FxjFile);
                            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 (fxjFileStruct.codeIsLong == false && code == market + code0 || fxjFileStruct.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 = fxjFileStruct.fields.GetLength(0);
                            while (iBlock < 25 && blocks[iBlock] != -1)
                            {
                                int r = 0;
                                //long tempAddress = 0;
                                //long tempAddress1 = 0;
                                //long tempResult = 0;
                                //int tempPos = 0;
                                UInt16 curValue_bs, preValue_bs = 0;
                                while (iRecord < recordCounts + 1 && r < fxjFileStruct.blockSize / fxjFileStruct.recordSize)   //12272/52=236条记录
                                {

                                    string[] record = new string[fieldCounts];
                                    pos = fxjFileStruct.startAddress + blocks[iBlock] * fxjFileStruct.blockSize + r * fxjFileStruct.recordSize;

                                    #region 调试数据结构
                                    /*
                                //tempPos = 0x41000 + 0x0047 * 0x2FF0;
                                //tempPos = 0x41000 + 0x0427 * 0x2FF0;
                                //tempPos = 0x41000 + 0x0573 * 0x2FF0;
                                tempPos = 0x41000 + 0x06CC * 0x2FF0;
                                //tempPos = 0x41000 + 0x0836 * 0x2FF0;

                                while (iRecord < 250 + 1 && r < 250)  
                                {
                                    string[] record = new string[fieldCounts];
                                    pos = fxjFileStruct.startAddress + blocks[iBlock] * fxjFileStruct.blockSize + r * fxjFileStruct.recordSize;


                                   
                                    //for (int iField = 0; iField < recordCounts ; iField ++)
                                    //{

                                    record[0] = code;

                                    fs.Position = tempPos;
                                    tempAddress1 = tempAddress;
                                    tempAddress = fs.Position; //lps
                                        intField = br.ReadInt32();
                                        record[1] = (intField == 0 ? "" : (date19700101.AddSeconds(intField)).ToString("yyyy-MM-dd HH:mm:ss"));
                                        tempPos = tempPos + 52;


                                        if (iRecord > 1)
                                            tempResult = tempAddress - tempAddress1;

                                        floatField = tempAddress;
                                        record[4] = "地址:" + floatField.ToString() + "(" + tempResult.ToString() + ")"; 

                                    //}
                                */
                                    #endregion

                                    for (int iField = 0; iField < fieldCounts; iField++)
                                    {
                                        fs.Position = pos + Convert.ToInt64(fxjFileStruct.fields[iField, 5]);
                                        switch (fxjFileStruct.fields[iField, 0].ToLower()) //这里与读取DAY.DAT用法不同,判断的是代码而不是类型
                                        {
                                            case "dm":
                                                record[iField] = code;
                                                break;
                                            case "rq":
                                                //tempAddress1 = tempAddress; //lps
                                                //tempAddress = fs.Position; //lps

                                                //if (iRecord > 1) //lps
                                                //    tempResult = tempAddress - tempAddress1;  //lps
                                                
                                                intField = br.ReadInt32();
                                                //if (intField >= 14148.625*86400)//test
                                                //    intField = intField;
                                            
                                                record[iField] = (intField == 0 ? "" : (date19700101.AddSeconds(intField)).ToString("yyyy-MM-dd HH:mm:ss"));
                                                ////record[iField] = record[iField] + "|地址:" + tempAddress.ToString() + "(" + tempResult.ToString() + ")";  //test                                                
                                                break;
                                            case "zjcj":
                                            case "zss":
                                            case "je":
                                                floatField = br.ReadSingle();
                                                record[iField] = floatField.ToString("_jj_qz".IndexOf(this.GetCodeType(code)) > 0 ? "F3" : "F");                                              
                                                break;
                                            case "mr1sl":
                                            case "mr2sl":
                                            case "mr3sl":
                                            case "mr4sl":
                                            case "mr5sl":
                                            case "mc1sl":
                                            case "mc2sl":
                                            case "mc3sl":
                                            case "mc4sl":
                                            case "mc5sl":
                                                record[iField] = br.ReadUInt16().ToString("D");
                                                //if (iField==26)
                                                //    record[iField] = br.ReadUInt16().ToString("D");
                                                break;
                                            case "mr1jg":
                                            case "mr2jg":
                                            case "mr3jg":
                                            case "mr4jg":
                                            case "mr5jg":
                                            case "mc1jg":
                                            case "mc2jg":
                                            case "mc3jg":
                                            case "mc4jg":
                                            case "mc5jg":
                                                //int temp = 0;//test
                                                //if (fxjFileStruct.fields[iField, 0].ToLower() == "mc5jg")
                                                //     temp =1;

                                                float jg=br.ReadSByte();
                                                if ("_jj_qz".IndexOf(this.GetCodeType(code)) > 0)
                                                {
                                                    jg = Convert.ToSingle(record[2]) + jg / 1000;
                                                    record[iField] = jg.ToString("F3");
                                                }
                                                else
                                                {
                                                    jg = Convert.ToSingle(record[2]) + jg / 100;
                                                    record[iField] = jg.ToString("F");
                                                }
                                                break;
                                            case "xss":
                                                record[iField] = "";//现手数在下面计算
                                                break;
                                            case "mm":
                                                int mm = br.ReadSByte();
                                                record[iField] = "";
                                                if (mm == -128) record[iField] = "内盘"; //-128 = 0x80
                                                if (mm == -64) record[iField] = "外盘";  //-64 = 0xC0
                                                break;
                                            case "bs":                                                
                                                curValue_bs = br.ReadUInt16();
                                                record[iField] = (curValue_bs - preValue_bs).ToString("D");//当前笔数=当前总笔数减上一次笔数
                                                preValue_bs = curValue_bs;
                                                break;
                                        }
                                        
                                    }
                                    recordList.Add(record);
                                    
                                    r = r + 1;
                                    iRecord = iRecord + 1;
                                }
                                iBlock = iBlock + 1;
                            }

                            float zssSaved = 0;
                            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++)
                                {
                                    if (j == 5)  //现手数
                                    {
                                        record0[j] = (Convert.ToSingle(record0[3]) - zssSaved).ToString();
                                        zssSaved = Convert.ToSingle(record0[3]);
                                    }
                                    records[i, j] = record0[j];
                                }
                            }
                            
                            if (iRecordCount == 0 || iRecordCount >recordList.Count ) iRecordCount = recordList.Count;
                            records = new string[iRecordCount, fieldCounts];
                            for (int i = 0; i<iRecordCount; i++)
                            {
                                string[] record0 = (string[])recordList[recordList.Count - 1 - 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;
                }

            }
            msg = "返回空数组。";
            return new string[1, 1] { { null } };

        }
Example #11
0
        public string GetTableDef(string dataType, string descDataType, bool delOldTable)
        {
            dataType = dataType.Trim(); descDataType = descDataType.Trim();
            string result = "";
            fileStruct fxjFileStruct = new fileStruct((DataTypes)Enum.Parse(typeof(DataTypes), dataType.ToLower()));
            switch (descDataType.ToUpper())
            {
                case "SAS":
                    for (int i = 0; i < fxjFileStruct.fields.GetLength(0); i++)
                    {
                        if (result != "") result += ",";
                        result += fxjFileStruct.fields[i, 0];//字段
                        if ("  ,code,string".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " char(" + fxjFileStruct.fields[i, 3] + ") format=$" + fxjFileStruct.fields[i, 3] + "."; //字符串
                        }
                        else if ("  ,int,single,double".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " num "; //数值类型
                        }
                        else if ("  ,date".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " num format=YYMMDD10."; //date类型
                        }
                        else if ("  ,datetime".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " num format=datetime."; //datetime类型
                        }
                        result += " label='" + fxjFileStruct.fields[i, 1] + "'";//标签

                    }
                    result = "create table FinData." + dataType + "(" + result + ");";
                    if (delOldTable == true)
                    {
                        result = "drop table FinData." + dataType + ";" + result;
                    }
                    result = "proc sql;" + result + "quit;";
                    break;
                case "SASINPUT"://用于SAS直接读取数据时所用的INPUT语句,需进一步修改
                    for (int i = 0; i < fxjFileStruct.fields.GetLength(0); i++)
                    {
                        if ("  ,code,string".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " @(p+" + fxjFileStruct.fields[i, 5] + ") " + fxjFileStruct.fields[i, 0] + " $" + fxjFileStruct.fields[i, 3] + "."; //字符串
                        }
                        else if ("  ,int,date,datetime".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " @(p+" + fxjFileStruct.fields[i, 5] + ") " + fxjFileStruct.fields[i, 0] + " ib" + fxjFileStruct.fields[i, 3] + "."; //数值类型
                        }
                        else if ("  ,single".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " @(p+" + fxjFileStruct.fields[i, 5] + ") " + fxjFileStruct.fields[i, 0] + " float" + fxjFileStruct.fields[i, 3] + "."; //数值类型
                        }
                        else if ("  ,double".IndexOf(fxjFileStruct.fields[i, 2]) > 0)
                        {
                            result += " @(p+" + fxjFileStruct.fields[i, 5] + ") " + fxjFileStruct.fields[i, 0] + " rb" + fxjFileStruct.fields[i, 3] + "."; //数值类型
                        }
                    }
                    break;
                case "FIELDS"://列出字段名称
                    for (int i = 0; i < fxjFileStruct.fields.GetLength(0); i++)
                    {
                        result += " " + fxjFileStruct.fields[i, 0] ;
                    }
                    break;

                default:
                    result = "";
                    break;
            }
            return result;

        }
Example #12
0
        public string[,] GetTables()
        {
            if (tableNames[0, 2] == "")
            {
                for (int i = 0; i < tableNames.GetLength(0); i++)
                {
                    DataTypes d = (DataTypes)Enum.Parse(typeof(DataTypes), tableNames[i,0].ToLower());
                    fileStruct fxjFileStruct = new fileStruct(d);
                    tableNames[i, 2] = fxjFileStruct.fileName;
                }

            }

            return tableNames;
        }