Esempio n. 1
0
        /// <summary>
        /// 根据表结构创建数据表
        /// </summary>
        /// <param name="dataFields">数据字典</param>
        /// <returns></returns>
        static void BuildFieldDict(CJia.Net.Serialization.SerializationReader sr, Dictionary <string, int> dataFields)
        {
            dataFields.Clear();
            string colName, colType, tableName = "";

            string[] arySchema;
            int      rowsCount = sr.ReadOptimizedInt32();
            int      colsCount = 0;
            Dictionary <string, int> listColumn = new Dictionary <string, int>(rowsCount);

            for (int i = 0; i < rowsCount; i++)
            {
                arySchema = sr.ReadOptimizedStringArray();
                tableName = arySchema[0];
                colName   = arySchema[1];
                colType   = arySchema[2];

                if (!listColumn.TryGetValue(colName, out colsCount))
                {
                    listColumn.Add(colName, 1);
                }
                else
                {
                    listColumn[colName] = colsCount + 1;
                    colName             = colName + "_" + colsCount.ToString();
                }

                dataFields.Add(colName, i);
            }
            listColumn.Clear();
            listColumn = null;
        }
Esempio n. 2
0
        /// <summary>
        /// 根据表结构创建数据表
        /// </summary>
        /// <param name="sr">反序列化工具</param>
        /// <returns></returns>
        DataTable BuildDataTable(CJia.Net.Serialization.SerializationReader sr)
        {
            string    colName, colType, tableName = "";
            DataTable dtData = new DataTable();

            string[] arySchema;
            int      rowsCount = sr.ReadOptimizedInt32();
            int      colsCount = 0;
            Dictionary <string, int> listColumn = new Dictionary <string, int>(rowsCount);

            for (int i = 0; i < rowsCount; i++)
            {
                arySchema = sr.ReadOptimizedStringArray();
                tableName = arySchema[0];
                colName   = arySchema[1];
                colType   = arySchema[2];

                if (!listColumn.TryGetValue(colName, out colsCount))
                {
                    listColumn.Add(colName, 1);
                }
                else
                {
                    listColumn[colName] = colsCount + 1;
                    colName             = colName + "_" + colsCount.ToString();
                }

                dtData.Columns.Add(colName, Type.GetType(colType));
            }
            listColumn.Clear();
            listColumn       = null;
            dtData.TableName = tableName;
            return(dtData);
        }