Пример #1
0
        public MyCommand ToInsert()
        {
            foreach (TableFieldInfo tableFieldInfo in this.tableInfo.TableFieldInfoList)
            {
                object o = entityType.GetProperty(tableFieldInfo.Property).GetValue(entity, null);
                if (!StringUtil.IsNullOrEmpty(o))
                {
                    this.whereInfos.Add(WhereInfoHelper.Eq(tableFieldInfo.Column, o));
                }
            }
            if (this.whereInfos.Count == 0)
            {
                throw new Exception("新增操作数据不得为空");
            }
            StringBuilder sbColumn = new StringBuilder(50);
            StringBuilder sbParam  = new StringBuilder(50);

            foreach (WhereInfo whereInfo in whereInfos)
            {
                sbColumn.AppendFormat("{0},", whereInfo.Column);
                sbParam.AppendFormat("@{0},", whereInfo.Column);
            }
            string text = string.Format(SqlCondition.INSERT,
                                        tableInfo.TableName,
                                        sbColumn.Remove(sbColumn.Length - 1, 1).ToString(),
                                        sbParam.Remove(sbParam.Length - 1, 1).ToString());

            return(new MyCommand(text, whereInfos));
        }
Пример #2
0
        public MyCommand ToDelete()
        {
            foreach (TableFieldInfo tableFieldInfo in this.tableInfo.TableFieldInfoList)
            {
                object o = entityType.GetProperty(tableFieldInfo.Property).GetValue(entity, null);
                if (!StringUtil.IsNullOrEmpty(o))
                {
                    whereInfos.Add(WhereInfoHelper.Eq(tableFieldInfo.Column, o));
                }
            }
            string text = string.Format(SqlCondition.DELETE, tableInfo.TableName, this.GetWhereStr());

            return(new MyCommand(text, whereInfos));
        }
Пример #3
0
        public MyCommand ToUpdateById()
        {
            TableFieldInfo idInfo       = this.tableInfo.TableFieldInfoList[0];
            PropertyInfo   propertyInfo = entityType.GetProperty(idInfo.Property);
            object         o            = propertyInfo.GetValue(entity, null);

            if (!StringUtil.IsNullOrEmpty(o))
            {
                throw new Exception("ToUpdateById操作id需要有id");
            }
            whereInfos.Clear();
            whereInfos.Add(WhereInfoHelper.Eq(idInfo.Column, o));
            propertyInfo.SetValue(entity, StringUtil.INT_NULL);
            return(this.ToUpdate());
        }
Пример #4
0
        public MyCommand ToSelect()
        {
            string select = string.IsNullOrEmpty(selectStr) ? tableInfo.AllSqlSelect : selectStr;

            foreach (TableFieldInfo tableFieldInfo in this.tableInfo.TableFieldInfoList)
            {
                object o = entityType.GetProperty(tableFieldInfo.Property).GetValue(entity, null);
                if (!StringUtil.IsNullOrEmpty(o))
                {
                    whereInfos.Add(WhereInfoHelper.Eq(tableFieldInfo.Column, o));
                }
            }
            string text = string.Format(SqlCondition.SELECT, select, tableInfo.TableName, this.GetWhereStr())
                          + orderByInfo.ToString()
                          + limitInfo.ToString();

            return(new MyCommand(text, whereInfos));
        }
Пример #5
0
        public MyCommand ToUpdate()
        {
            List <WhereInfo> valueList = new List <WhereInfo>();

            foreach (TableFieldInfo tableFieldInfo in this.tableInfo.TableFieldInfoList)
            {
                object o = entityType.GetProperty(tableFieldInfo.Property).GetValue(entity, null);
                if (!StringUtil.IsNullOrEmpty(o))
                {
                    valueList.Add(WhereInfoHelper.Eq(tableFieldInfo.Column, o));
                }
            }
            if (valueList.Count == 0 || whereInfos.Count == 0)
            {
                throw new Exception("更新操作数据不得为空");
            }
            string text = string.Format(SqlCondition.UPDATE, tableInfo.TableName, string.Join(", ", valueList), this.GetWhereStr());

            this.whereInfos.AddRange(valueList);
            return(new MyCommand(text, this.whereInfos));
        }
Пример #6
0
 public QueryWrapper <T> Ge(string column, string value)
 {
     base.whereInfos.Add(WhereInfoHelper.Ge(column, value));
     return(this);
 }