/// <summary>
        /// 添加列,V3.5.2
        /// </summary>
        /// <param name="p"></param>
        public void AddColumn(ColumnP p)
        {
            if (schema.Where(w => w.ColumnName.ToLower() == p.ColumnName.ToLower()).Count() > 0)
            {
                return;
            }
            DataColumn dc = new DataColumn();

            dc.ColumnName = p.ColumnName;
            if (!string.IsNullOrEmpty(p.DataType))
            {
                dc.DataType = Type.GetType(p.DataType);
            }
            if (dc.DataType == typeof(string))
            {
                dc.MaxLength = p.Length;
            }
            dc.AllowDBNull       = p.IsAllowNull;
            dc.AutoIncrement     = p.IsAutoIncrement;
            dc.AutoIncrementSeed = p.AutoIncrementSeed;
            dc.AutoIncrementStep = p.AutoIncrementStep;
            bool isPK = p.IsPK;

            this.schema.Add(dc);
            if (isPK)
            {
                if (pkContent.Where(w => w.ColumnName != dc.ColumnName).Count() <= 0)
                {
                    pkContent.Add(dc);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 添加列,V1.0.0.1
        /// </summary>
        /// <param name="p"></param>
        public void AddColumn(ColumnP p)
        {
            DataColumn dc = new DataColumn();

            dc.ColumnName = p.ColumnName;
            dc.DataType   = Type.GetType(p.DataType);
            if (dc.DataType == typeof(string))
            {
                dc.MaxLength = p.Length;
            }
            dc.AllowDBNull       = p.IsAllowNull;
            dc.AutoIncrement     = p.IsAutoIncrement;
            dc.AutoIncrementSeed = p.AutoIncrementSeed;
            dc.AutoIncrementStep = p.AutoIncrementStep;
            bool isPK = p.IsPK;

            this.Value.Columns.Add(dc);
            if (isPK && !p.IsAutoIncrement)
            {
                List <DataColumn> l = new List <DataColumn>();
                for (int i = 0; i < this.Value.PrimaryKey.Length; i++)
                {
                    l.Add(this.Value.PrimaryKey[i]);
                }
                l.Add(dc);
                this.Value.PrimaryKey = l.ToArray();
            }
        }
Example #3
0
        public DataSetStd ConvertTo(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            DataSetStd rtn     = new DataSetStd();
            string     jsonstr = "";

            if (obj is string)
            {
                jsonstr = ComFunc.nvl(obj);
            }
            else
            {
                throw new Exception("Json2DataSet无法转化" + obj.GetType().FullName + "类型数据!");
            }
            JsonReader   reader        = new JsonTextReader(new StringReader(jsonstr));
            string       tablename     = "";
            int          index         = 0;
            bool         isStartArray  = false;
            string       currentColumn = "";
            DataTableStd currentdts    = null;

            while (reader.Read())
            {
                Console.WriteLine(reader.TokenType + "\t\t" + reader.ValueType + "\t\t" + reader.Value);
                if (!isStartArray)
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        tablename = ComFunc.nvl(reader.Value);
                    }
                    if (reader.TokenType == JsonToken.StartArray)
                    {
                        isStartArray = true;
                        currentdts   = new DataTableStd();
                    }
                }
                else
                {
                    //列表数据结束
                    if (reader.TokenType == JsonToken.EndArray)
                    {
                        isStartArray = false;
                        rtn.Tables.Add(currentdts);
                    }
                    //一行资料结束
                    if (reader.TokenType == JsonToken.EndObject)
                    {
                        currentdts.AddNewRow();
                        index++;
                    }

                    //抓取资料栏位
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        if (index == 0)
                        {
                            currentdts.AddColumn(ColumnP.CreatInstanse(ComFunc.nvl(reader.Value)));
                        }
                        currentColumn = ComFunc.nvl(reader.Value);
                    }
                    //抓取资料数据
                    if (reader.TokenType == JsonToken.String ||
                        reader.TokenType == JsonToken.Boolean ||
                        reader.TokenType == JsonToken.Bytes ||
                        reader.TokenType == JsonToken.Date ||
                        reader.TokenType == JsonToken.Float ||
                        reader.TokenType == JsonToken.Integer)
                    {
                        currentdts.SetNewRowValue(reader.Value, currentColumn);
                    }
                }
            }


            return(rtn);
        }