/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FileContentModel GetSimpleModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 * from [" + databaseprefix + "DetailContent] ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            FileContentModel model = new FileContentModel();
            DataSet          ds    = DbHelperFileContentSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                model = ChangeSimpleRowToFile(ds.Tables[0].Rows[0]);
                return(model);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select count(1) from " + databaseprefix + "DetailContent");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;
            return(DbHelperFileContentSQL.Exists(strSql.ToString(), parameters));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 系统检查
        /// </summary>
        public static void SystemCheck()
        {
            // 获取配置信息
            Model.SystemConfig config = SystemConfigBll.GetConfig();

            // 设置数据库连接
            string conn = string.Format("server={0};uid={1};pwd={2};database={3};", config.DbAddress, config.DbUser, config.DbPassword, config.DbName);

            DbHelperSQL.SetConnectionString(conn);

            string fileContentConn = string.Format("server={0};uid={1};pwd={2};database={3};", config.DbFileContentAddress, config.DbFileContentUser, config.DbFileContentPassword, config.DbFileContentName);

            DbHelperFileContentSQL.SetConnectionString(fileContentConn);
        }
        /// <summary>
        /// 获取文件内容
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public byte[] GetContent(string id)
        {
            id = "'" + id + "'";
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 File_Content from [" + databaseprefix + "DetailContent] ");
            strSql.Append(" where id=" + id);


            DataSet ds = DbHelperFileContentSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                return((byte[])ds.Tables[0].Rows[0]["File_Content"]);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public string Add(Model.FileContentModel model)
        {
            //文件内容的上传
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [" + databaseprefix + "DetailContent](");
            strSql.Append("ID,File_ID,File_VerID,File_Ver,File_Content,Add_Time)");
            strSql.Append(" values (");
            strSql.Append("@ID,@File_ID,@File_VerID,@File_Ver,@File_Content,@Add_Time )");
            //strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",           SqlDbType.NVarChar),
                new SqlParameter("@File_ID",      SqlDbType.Int),
                new SqlParameter("@File_VerID",   SqlDbType.Int),
                new SqlParameter("@File_Ver",     SqlDbType.NVarChar,100),
                new SqlParameter("@File_Content", SqlDbType.VarBinary),
                new SqlParameter("@Add_Time",     SqlDbType.DateTime),
            };

            parameters[0].Value = model.ID;
            parameters[1].Value = model.File_ID;
            parameters[2].Value = model.File_VerID;
            parameters[3].Value = model.File_Ver;
            parameters[4].Value = model.File_Content;
            parameters[5].Value = model.Add_Time;

            int obj = DbHelperFileContentSQL.ExecuteSql(strSql.ToString(), parameters);

            if (obj == 0)
            {
                return(string.Empty);
            }
            else
            {
                return(model.ID);
            }
        }