示例#1
0
        /// <summary>
        /// 添加表
        /// </summary>
        /// <param name="model"></param>
        public void CreateTable(We7.Model.Core.ModelInfo model)
        {
            if (model.Type != ModelType.ARTICLE)
            {
                return;
            }
            string table = model.DataSet.Tables[0].Name;
            string sql   = String.Format(SqlCreate, table);

            try
            {
                try
                {
                    ModelDBHelper DbHelper = ModelDBHelper.Create(model.ModelName);
                    //TODO:不知道以下代码作用是什么,看起来像是创建完表结构之后检测一下
                    DbHelper.Query(String.Format(SqlSelectTable, table));
                }
                catch
                {
                    ExecuteSql(sql);
                }
            }
            catch { }

            UpdateTable(model);
        }
示例#2
0
        /// <summary>
        /// 删除表
        /// </summary>
        /// <param name="model"></param>
        public void DeleteTable(We7.Model.Core.ModelInfo model)
        {
            string table = model.DataSet.Tables[0].Name;
            string sql   = String.Format(SqlDropTable, table);

            ExecuteSql(sql);
        }
示例#3
0
        /// <summary>
        /// 更新表
        /// </summary>
        /// <param name="model"></param>
        public void UpdateTable(We7.Model.Core.ModelInfo model)
        {
            ModelDBHelper DbHelper = ModelDBHelper.Create(model.ModelName);

            string    table = model.DataSet.Tables[0].Name;
            DataTable dt    = DbHelper.Query(String.Format(SqlSelectTable, table));
            We7DataColumnCollection columns = model.DataSet.Tables[0].Columns;

            if (!columns.Contains("Updated", true))
            {
                columns.Add(new We7DataColumn()
                {
                    DataType = TypeCode.DateTime, Name = "Updated"
                });
            }
            if (!columns.Contains("AccountID", true))
            {
                columns.Add(new We7DataColumn()
                {
                    DataType = TypeCode.String, Name = "AccountID", MaxLength = 40
                });
            }
            foreach (We7DataColumn c in columns)
            {
                try
                {
                    if (c.Direction == ParameterDirection.ReturnValue)
                    {
                        continue;
                    }

                    string sql = String.Empty;
                    if (ContainsColumn(dt, c.Name))
                    {
                        if (IgnoreUpdateFields.Contains(c.Name))
                        {
                            continue;
                        }

                        sql = String.Format(SqlAlterColumn, table, c.Name, GetDbType(c));
                    }
                    else
                    {
                        sql = String.Format(SqlAddColumn, table, c.Name, GetDbType(c));
                    }
                    //DbHelper.Execute(sql);
                    ExecuteSql(sql);
                }
                catch (Exception ex) { }
            }
        }
示例#4
0
        /// <summary>
        /// 根据名称获取对象模型
        /// </summary>
        /// <param name="name">模型名称</param>
        /// <returns></returns>
        public static ModelInfo GetModelInfoByName(string name)
        {
            //根据ModelInfo的名称获取路径
            string fileName = GetModelInfoPath(name);

            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }
            ModelInfo modelInfo = SerializationHelper.Load(typeof(ModelInfo), fileName)
                                  as ModelInfo;

            if (modelInfo != null)
            {
                return(modelInfo);
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        /// <summary>
        /// 根据模型名创建数据集
        /// </summary>
        /// <param name="modelname"></param>
        /// <returns></returns>
        public static DataSet CreateDataset(string modelname)
        {
            ModelInfo model = GetModelInfo(modelname);

            return(CreateDataSet(model));
        }
示例#6
0
        /// <summary>
        /// 保存模型信息
        /// </summary>
        /// <param name="modelInfo">内容模型</param>
        /// <returns></returns>
        public static bool SaveModelInfo(ModelInfo modelInfo)
        {
            string fileName = GetModelInfoPath(modelInfo.ModelName);

            return(SerializationHelper.Save(modelInfo, fileName));
        }