Пример #1
0
        /// <summary>
        /// 获取某一个类型的所有记录;
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static DataTable GetAllDataTable <T>()
        {
            TableAttribute tba       = GetTableAttribute <T>();
            string         sqlcmd    = "select * from [";
            string         tablename = tba.TableName;

            sqlcmd += tablename + "]";
            bool      iscache = tba.IsCahche;
            DataTable dt      = GetTableByName(tablename);

            if (dt != null)
            {
                return(dt);
            }
            else
            {
                dt = IDataSourceTypeFactory.Create().ExecuteTable(sqlcmd);
                if (dt != null && tba.IsCahche)
                {
                    dt.TableName = tablename;
                    Cache.Add(dt);
                    return(dt);
                }
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        ///  根据实体对象和IDataSourceType对象删除一条记录,
        ///  该实体必须明确主键值才能删除记录;如果该实体没有主键可自己编写SQL代码删除;
        /// </summary>
        /// <typeparam name="T">要删除的表对应的实体对象</typeparam>
        /// <param name="t">Model实体</param>
        /// <param name="idatasource">IDataSourceType数据源类型对象</param>
        /// <returns>删除是否成功;1成功,0失败</returns>
        public static int DeleteModelById <T>(T t, IDataSourceType idatasource) where T : new()
        {
            string sqlstring;                                                                                            //保存要执行的T-SQL语句
            List <IDataParameter> paramlist = (List <IDataParameter>)GetDeleteModelParameterT_SQL <T>(t, out sqlstring); //获取利用Model删除时的语句和参数列表

            if (idatasource != null)
            {
                return(IDataSourceTypeFactory.Create().ExecuteNonQuery(CommandType.Text, sqlstring, paramlist.ToArray()));
            }
            return(IDataSourceTypeFactory.Create().ExecuteNonQuery(CommandType.Text, sqlstring, paramlist.ToArray()));
        }
Пример #3
0
        public static int InsertModelId <T>(T t, IDataSourceType idatasource) where T : new()
        {
            string sqlstring             = string.Empty;
            List <IDataParameter> parame = (List <IDataParameter>)GetInsertModelParameterT_SQL <T>(t, out sqlstring);

            if (idatasource != null)
            {
                return((int)idatasource.ExecuteScalar(CommandType.Text, sqlstring, parame.ToArray()));
            }
            return((int)IDataSourceTypeFactory.Create().ExecuteScalar(CommandType.Text, sqlstring, parame.ToArray()));
        }
Пример #4
0
        public static DataTable GetNumDataTable <T>(string Where, int num)
        {
            TableAttribute tba       = GetTableAttribute <T>();
            string         sqlcmd    = "select TOP " + num.ToString() + " * from [";
            string         tablename = tba.TableName;

            sqlcmd += tablename + "] where ";
            // sqlcmd += " where ";
            sqlcmd += Where;


            DataTable dt = new DataTable();

            dt = IDataSourceTypeFactory.Create().ExecuteTable(sqlcmd);
            if (dt != null)
            {
                return(dt);
            }
            return(null);
        }
Пример #5
0
 public static int ExeSql(string SqlCmd)
 {
     return(IDataSourceTypeFactory.Create().ExecuteNonQuery(SqlCmd));
 }