Example #1
0
        internal string GetSelectSql(string tableName)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(" WHERE ");

//			foreach( PropertyInfo p in PropertyList )
//			{
//				string str = GetProperty(p);
//				if( str != null && str.Length > 0 )
//					sb.Append( p.Name + "=" + GetProperty(p) + "," );
//			}

            PropertyInfo key = MainKey;

            if (key == null)
            {
                return("");
            }
            string fname = DObjectHelper.GetFieldName(key);

            sb.Append(fname + "=" + GetProperty(key));

            string sql = sb.ToString();

            sql = sql.TrimEnd(',').Replace(",", " AND ");
            sql = GetSelectAllSql(tableName) + sql;

            return(sql);
        }
Example #2
0
        internal string GetUpdateSql(string tableName)
        {
            PropertyInfo[] plist = DObjectHelper.GetInsertablePropertyList(PropertyList);
            if (plist == null)
            {
                return("");
            }

            PropertyInfo key = MainKey;

            if (key == null)
            {
                return("");
            }
            string val = GetProperty(key);

            StringBuilder sb = new StringBuilder();

            sb.Append("UPDATE ");
            sb.Append(tableName);
            sb.Append(" SET ");

            foreach (PropertyInfo p in plist)
            {
                string fname = DObjectHelper.GetFieldName(p);
                sb.Append(fname + "=" + GetProperty(p) + ",");
            }

            string str   = sb.ToString();
            string kname = DObjectHelper.GetFieldName(key);
            string ostr  = str.TrimEnd(',') + " WHERE " + kname + "=" + val;

            return(ostr);
        }
Example #3
0
        private DObjectManager(string tableName, Type objectType)
        {
            _tableName  = tableName;
            _objectType = objectType;

            if (_tableName == null || _tableName.Length < 1 ||
                _objectType == null || !DObjectHelper.IsDObject(_objectType))
            {
                throw new ArgumentNullException("DObjectManager构造函数的参数不能为空,而且传入的objectType参数必须是DObject类型或DObject的派生类型。");
            }
        }
Example #4
0
        internal string GetMaxAutoIDSql(string tableName)
        {
            PropertyInfo key = MainKey;

            if (key == null || !DObjectHelper.IsAutoIncrementing(key))
            {
                return("");
            }

            string kname = DObjectHelper.GetFieldName(key);
            string sql   = "SELECT MAX(" + kname + ") FROM " + tableName;

            return(sql);
        }
Example #5
0
        internal string GetDeleteSql(string tableName)
        {
            PropertyInfo key = MainKey;

            if (key == null)
            {
                return("");
            }
            string val   = GetProperty(key);
            string fname = DObjectHelper.GetFieldName(key);
            string sql   = "DELETE FROM " + tableName + " WHERE " + fname + "=" + val;

            return(sql);
        }
Example #6
0
        internal bool LoadData(DbDataRecord dbData)
        {
            if (dbData == null)
            {
                return(false);
            }

            PropertyInfo[] plist = PropertyList;
            if (plist == null)
            {
                return(false);
            }

            foreach (PropertyInfo p in plist)
            {
                string fname = DObjectHelper.GetFieldName(p);
                SetProperty(p, dbData[fname]);
            }

            return(true);
        }
Example #7
0
        internal string GetSelectAllSql(string tableName)
        {
            PropertyInfo[] plist = PropertyList;
            if (plist == null)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("SELECT ");

            foreach (PropertyInfo p in plist)
            {
                string fname = DObjectHelper.GetFieldName(p);
                sb.Append(fname + ",");
            }

            string str = sb.ToString().TrimEnd(',');

            str = str + " FROM " + tableName;
            return(str);
        }
Example #8
0
        internal string GetInsertSql(string tableName)
        {
            PropertyInfo[] plist = DObjectHelper.GetInsertablePropertyList(PropertyList);
            if (plist == null)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("INSERT INTO ");
            sb.Append(tableName);
            sb.Append(" (");

            foreach (PropertyInfo p in plist)
            {
                string fname = DObjectHelper.GetFieldName(p);
                sb.Append(fname + ",");
            }

            string str = sb.ToString().TrimEnd(',');

            str = str + ") VALUES (";

            sb = new StringBuilder();
            sb.Append(str);

            foreach (PropertyInfo p in plist)
            {
                sb.Append(GetProperty(p) + ",");
            }

            str = sb.ToString().TrimEnd(',');
            str = str + ")";

            return(str);
        }
Example #9
0
        internal string GetCreateTableSql(string tableName)
        {
            PropertyInfo[] plist = PropertyList;
            if (plist == null)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("CREATE TABLE ");
            sb.Append(tableName + " (");

            foreach (PropertyInfo p in plist)
            {
                string finfo = DObjectHelper.GetFileInfor(p);
                sb.Append(finfo + ",");
            }

            string str = sb.ToString().TrimEnd(',');

            str = str + ")";
            return(str);
        }