Пример #1
0
        public override BuildResultEntity DbUpdateSqlBuilder <T>(T model)
        {
            BuildResultEntity     bre        = new BuildResultEntity();
            string                tablename  = typeof(T).Name;
            List <DBMemberEntity> entitylist = GetEntityInfo(model);

            bre.entities = entitylist;

            if (entitylist.Count == 0)
            {
            }
            else
            {
                PropertyInfo          pi              = model.GetType().GetProperty("keyfields");
                List <string>         keyfields       = pi.GetValue(model) as List <string>;
                List <DBMemberEntity> conditiontities = new List <DBMemberEntity>();
                string valuesql = string.Empty;
                for (int i = 0; i < entitylist.Count; i++)
                {
                    if (keyfields.Contains(entitylist[i].MemberName))
                    {
                        conditiontities.Add(entitylist[i]);
                    }
                    else
                    {
                        valuesql += entitylist[i].MemberName + "=@" + entitylist[i].MemberName + ",";
                    }
                }

                string wheresql = DbConditionSqlBuilder(conditiontities);
                bre.sql = string.Format("update {0} set {1} {2}", tablename, valuesql.TrimEnd(','), wheresql);
            }
            return(bre);
        }
Пример #2
0
        public override int Delete <T>(System.Data.Common.DbConnection conn, System.Data.Common.DbTransaction trans, T model)
        {
            BuildResultEntity bre = DbDeleteSqlBuilder(model);

            SqlCommand cmd = new SqlCommand(bre.sql, (SqlConnection)conn);

            cmd.Transaction = (SqlTransaction)trans;
            if (bre.entities != null)
            {
                foreach (DBMemberEntity m in bre.entities)
                {
                    SqlParameter param = new SqlParameter(m.MemberName, m.MemberValue);
                    cmd.Parameters.Add(param);
                }
            }

            return(cmd.ExecuteNonQuery());
        }
Пример #3
0
        public override BuildResultEntity DbDeleteSqlBuilder <T>(T model)
        {
            BuildResultEntity     bre        = new BuildResultEntity();
            string                tablename  = typeof(T).Name;
            List <DBMemberEntity> entitylist = GetEntityInfo(model);

            bre.entities = entitylist;

            if (entitylist.Count == 0)
            {
            }
            else
            {
                string strCondition = DbConditionSqlBuilder(entitylist);

                bre.sql = string.Format("DELETE FROM {0} {1}", tablename, strCondition);
            }
            return(bre);
        }
Пример #4
0
        public override BuildResultEntity DbInsertSqlBuilder <T>(T model)
        {
            BuildResultEntity     bre        = new BuildResultEntity();
            string                tablename  = typeof(T).Name;
            List <DBMemberEntity> entitylist = GetEntityInfo(model);

            bre.entities = entitylist;

            if (entitylist.Count == 0)
            {
            }
            else
            {
                string strNameSQL  = string.Empty;
                string strValueSQL = string.Empty;
                foreach (DBMemberEntity entity in entitylist)
                {
                    strNameSQL  += entity.MemberName + ",";
                    strValueSQL += "@" + entity.MemberName + ",";
                }
                bre.sql = string.Format("insert into {0}({1}) values ({2})", tablename, strNameSQL.TrimEnd(','), strValueSQL.TrimEnd(','));
            }
            return(bre);
        }