Beispiel #1
0
        //显示
        public void ShowUnPacker(CT2UnPacker lpUnPack)
        {
            int count = lpUnPack.GetDatasetCount();

            for (int k = 0; k < count; k++)
            {
                Debug.Print(string.Format("第[{0}]个数据集", k));
                lpUnPack.SetCurrentDatasetByIndex(k);
                String strInfo = string.Format("记录行数:           {0}", lpUnPack.GetRowCount());
                Debug.Print(strInfo);
                strInfo = string.Format("列行数:			 {0}", lpUnPack.GetColCount());
                Debug.Print(strInfo);
                while (lpUnPack.IsEOF() == 0)
                {
                    for (int i = 0; i < lpUnPack.GetColCount(); i++)
                    {
                        String colName = lpUnPack.GetColName(i);
                        sbyte  colType = lpUnPack.GetColType(i);
                        if (!colType.Equals('R'))
                        {
                            String colValue = lpUnPack.GetStrByIndex(i);
                            String str      = string.Format("{0}:			[{1}]", colName, colValue);
                            Debug.Print(str);
                        }
                        else
                        {
                            int colLength = 0;
                            unsafe
                            {
                                void * colValue = (char *)lpUnPack.GetRawByIndex(i, &colLength);
                                string str      = string.Format("{0}:			[{1}]({2})", colName, Marshal.PtrToStringAuto(new IntPtr(colValue)), colLength);
                            }
                        }
                    }
                    lpUnPack.Next();
                }
            }
        }
Beispiel #2
0
        public void UnPack(CT2UnPacker lpUnPack)
        {
            var flag  = 0;
            var count = lpUnPack.GetRowCount();

            _showlist           = new ShowList();
            _showlist.ValueList = new List <string> [count];
            _showlist.NameList  = new List <string>();

            for (int i = 0; i < count; i++)
            {
                _showlist.ValueList[i] = new List <string>();
            }


            while (lpUnPack.IsEOF() != 1)
            {
                for (int j = 0; j < lpUnPack.GetColCount(); j++)
                {
                    var   colName = lpUnPack.GetColName(j);
                    sbyte colType = lpUnPack.GetColType(j);
                    if (colType != 'R')
                    {
                        var colValue = lpUnPack.GetStrByIndex(j);
                        if (flag == 0)
                        {
                            _showlist.NameList.Add(colName);
                        }
                        _showlist.ValueList[flag].Add(colValue);
                    }
                }

                lpUnPack.Next();
                flag++;
            }
            var aa = _showlist;
        }
Beispiel #3
0
        public void PrintUnPack(CT2UnPacker lpUnPack)
        {
            Console.WriteLine("记录行数: {0}", lpUnPack.GetRowCount());
            Console.WriteLine("列行数:{0}", lpUnPack.GetColCount());

            for (int i = 0; i < lpUnPack.GetDatasetCount(); i++)
            {
                //设置当前结果集
                lpUnPack.SetCurrentDatasetByIndex(i);

                //打印字段
                for (int j = 0; j < lpUnPack.GetColCount(); j++)
                {
                    Console.Write("{0,20:G}", lpUnPack.GetColName(j));
                }

                Console.WriteLine();

                //打印所有记录
                for (int k = 0; k < lpUnPack.GetRowCount(); k++)
                {
                    //打印每条记录
                    for (int t = 0; t < lpUnPack.GetColCount(); t++)
                    {
                        switch (lpUnPack.GetColType(t))
                        {
                        case (sbyte)'I':      //I 整数
                            Console.Write("{0,20:D}", lpUnPack.GetIntByIndex(t));
                            break;

                        case (sbyte)'C':      //C
                            Console.Write("{0,20:G}", (char)lpUnPack.GetCharByIndex(t));
                            break;

                        case (sbyte)'S':       //S
                            Console.Write("{0,20:G}", lpUnPack.GetStrByIndex(t));
                            break;

                        case (sbyte)'F':      //F
                            Console.Write("{0,20:F2}", lpUnPack.GetDoubleByIndex(t));
                            break;

                        case (sbyte)'R':      //R
                        {
                            break;
                        }

                        default:
                            // 未知数据类型
                            Console.Write("未知数据类型\n");
                            break;
                        }
                    }

                    Console.WriteLine();
                    lpUnPack.Next();
                }
            }

            Console.WriteLine();


            /*
             * while (lpUnPack.IsEOF() != 1)
             * {
             *  for (int i = 0; i < lpUnPack.GetColCount(); i++)
             *  {
             *      String colName = lpUnPack.GetColName(i);
             *      sbyte colType = lpUnPack.GetColType(i);
             *      if (!colType.Equals('R'))
             *      {
             *          String colValue = lpUnPack.GetStrByIndex(i);
             *          Console.WriteLine("{0}:{1}", colName, colValue);
             *      }
             *      else
             *      {
             *          int colLength = 0;
             *          unsafe
             *          {
             *              void* colValue = (char*)lpUnPack.GetRawByIndex(i, &colLength);
             *              string str = String.Format("{0}:[{1}]({2})", colName, Marshal.PtrToStringAuto(new IntPtr(colValue)), colLength);
             *          }
             *      }
             *  }
             *  lpUnPack.Next();
             * }
             */
        }
        public void Parse(CT2UnPacker lpUnPack)
        {
            for (int i = 0, dsLen = lpUnPack.GetDatasetCount(); i < dsLen; i++)
            {
                RawDataSet dataSet = new RawDataSet();
                dataSet.Rows = new List <RawDataRow>();
                //设置当前结果集
                lpUnPack.SetCurrentDatasetByIndex(i);

                Dictionary <int, string> columnDic = new Dictionary <int, string>();
                //数据包中字段
                for (int j = 0, hLen = lpUnPack.GetColCount(); j < hLen; j++)
                {
                    columnDic.Add(j, lpUnPack.GetColName(j));
                }

                //所有记录
                for (int k = 0, rLen = (int)lpUnPack.GetRowCount(); k < rLen; k++)
                {
                    RawDataRow row = new RawDataRow();
                    row.Columns = new Dictionary <string, DataValue>();

                    //每条记录
                    for (int t = 0, cLen = lpUnPack.GetColCount(); t < cLen; t++)
                    {
                        string    colName   = columnDic[t];
                        DataValue dataValue = new DataValue();
                        switch (lpUnPack.GetColType(t))
                        {
                        case (sbyte)'I':      //I 整数
                        {
                            dataValue.Type  = DataValueType.Int;
                            dataValue.Value = lpUnPack.GetIntByIndex(t);
                        }
                        break;

                        case (sbyte)'C':      //C
                        {
                            dataValue.Type  = DataValueType.Char;
                            dataValue.Value = lpUnPack.GetCharByIndex(t);
                        }
                        break;

                        case (sbyte)'S':       //S
                        {
                            dataValue.Type  = DataValueType.String;
                            dataValue.Value = lpUnPack.GetStrByIndex(t);
                        }
                        break;

                        case (sbyte)'F':      //F
                        {
                            dataValue.Type  = DataValueType.Float;
                            dataValue.Value = lpUnPack.GetDoubleByIndex(t);
                        }
                        break;

                        case (sbyte)'R':      //R
                        {
                            break;
                        }

                        default:
                            // 未知数据类型
                            break;
                        }

                        if (!row.Columns.ContainsKey(colName))
                        {
                            row.Columns.Add(colName, dataValue);
                        }
                    }//end to read all column for each row

                    dataSet.Rows.Add(row);

                    Console.WriteLine();
                    lpUnPack.Next();
                }//end to read rows

                _dataSets.Add(dataSet);
            }
        }
        public void Parse(CT2UnPacker lpUnPack)
        {
            for (int i = 0; i < lpUnPack.GetDatasetCount(); i++)
            {
                DataSet dataSet = new DataSet();
                dataSet.Rows = new List <DataRow>();
                //设置当前结果集
                lpUnPack.SetCurrentDatasetByIndex(i);

                Dictionary <int, string> columnDic = new Dictionary <int, string>();
                //打印字段
                for (int j = 0; j < lpUnPack.GetColCount(); j++)
                {
                    columnDic.Add(j, lpUnPack.GetColName(j));
                }

                //打印所有记录
                for (int k = 0; k < lpUnPack.GetRowCount(); k++)
                {
                    DataRow row = new DataRow();
                    row.Columns = new Dictionary <string, DataValue>();

                    //打印每条记录
                    for (int t = 0; t < lpUnPack.GetColCount(); t++)
                    {
                        string colName = columnDic[t];
                        switch (lpUnPack.GetColType(t))
                        {
                        case (sbyte)'I':      //I 整数
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.Int,
                                Value = lpUnPack.GetIntByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'C':      //C
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.Char,
                                Value = lpUnPack.GetCharByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'S':       //S
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.String,
                                Value = lpUnPack.GetStrByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'F':      //F
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.Float,
                                Value = lpUnPack.GetDoubleByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'R':      //R
                        {
                            break;
                        }

                        default:
                            // 未知数据类型
                            break;
                        }
                    }//end to read all column for each row

                    dataSet.Rows.Add(row);

                    Console.WriteLine();
                    lpUnPack.Next();
                }//end to read rows

                _dataSets.Add(dataSet);
            }

            /*
             * while (lpUnPack.IsEOF() != 1)
             * {
             *  for (int i = 0; i < lpUnPack.GetColCount(); i++)
             *  {
             *      String colName = lpUnPack.GetColName(i);
             *      sbyte colType = lpUnPack.GetColType(i);
             *      if (!colType.Equals('R'))
             *      {
             *          String colValue = lpUnPack.GetStrByIndex(i);
             *          Console.WriteLine("{0}:{1}", colName, colValue);
             *      }
             *      else
             *      {
             *          int colLength = 0;
             *          unsafe
             *          {
             *              void* colValue = (char*)lpUnPack.GetRawByIndex(i, &colLength);
             *              string str = String.Format("{0}:[{1}]({2})", colName, Marshal.PtrToStringAuto(new IntPtr(colValue)), colLength);
             *          }
             *      }
             *  }
             *  lpUnPack.Next();
             * }
             */
        }