/// <summary>
 /// 修改资源文件
 /// </summary>
 /// <param name="Data"></param>
 /// <returns></returns>
 private bool UpdateResourcesFile(AcademicResources_File Data)
 {
     try
     {
         StringBuilder sql = new StringBuilder();
         sql.AppendLine(@"update de2_aresource_file set title=@title,createTime=@createTime,targetFileUrl=@targetFileUrl,sourceTypeID=@sourceTypeID ,lastModifyTime=@lastModifyTime,lastModifyUsrID=@lastModifyUsrID where parentID=@parentID");
         //执行sql语句
         MySqlClient _Client = new MySqlClient();
         _Client.ExecuteNonQuery(sql.ToString()
                                 , new MySqlParameter("@title", Data.title)
                                 , new MySqlParameter("@createTime", Data.createTime)
                                 , new MySqlParameter("@targetFileUrl", Data.targetFileUrl)
                                 , new MySqlParameter("@sourceTypeID", Data.sourceTypeID)
                                 , new MySqlParameter("@parentID", Data.parentID)
                                 , new MySqlParameter("@parentID", Data.parentID)
                                 , new MySqlParameter("@lastModifyTime", Data.lastModifyTime)
                                 , new MySqlParameter("@lastModifyUsrID", Data.lastModifyUsrID));
         return(true);
     }
     catch (Exception ex)
     {
         LogFactory _LogFactory = new LogFactory(this.GetType());
         _LogFactory.CreateLog(LogType.Error, "新建资源文件", "AddResourcesFile", ex);
     }
     return(false);
 }
        /// <summary>
        /// 修改目录
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        public BaseResopne <string> UpdateResourceMenu(AcademicResources_Menu Param)
        {
            BaseResopne <string> result = new BaseResopne <string>();

            try
            {
                //获取当前登录人
                AccountProvider _AccountProvider = new AccountProvider();
                var             user             = _AccountProvider.GetCurrentUser();
                if (user == null)
                {
                    result.IsSuccess = false;
                    result.Error     = "获取当前用户信息失败";
                    return(result);
                }
                Param.lastModifyTime  = DateTime.Now;
                Param.lastModifyUsrID = user.id;
                string sql = @"update  de2_aresource_menu set title=@title,parentID=@parentID,sourceTypeID=@sourceTypeID,author=@author,lastModifyUsrID=@lastModifyUsrID,lastModifyTime=@lastModifyTime";
                //执行sql
                MySqlClient _Client    = new MySqlClient();
                var         ResourceID = _Client.Inster(sql
                                                        , new MySqlParameter("@title", Param.title)
                                                        , new MySqlParameter("@parentID", Param.parentID)
                                                        , new MySqlParameter("@sourceTypeID", Param.sourceTypeID)
                                                        , new MySqlParameter("@author", Param.author)
                                                        , new MySqlParameter("@lastModifyUsrID", Param.lastModifyUsrID)
                                                        , new MySqlParameter("@lastModifyTime", Param.lastModifyTime));
                //判断文件路径是否为空
                if (!string.IsNullOrEmpty(Param.resourceFile))
                {
                    AcademicResources_File _AcademicResources_File = new AcademicResources_File();
                    _AcademicResources_File.lastModifyTime  = DateTime.Now;
                    _AcademicResources_File.lastModifyUsrID = user.id;
                    _AcademicResources_File.parentID        = Param.id;
                    _AcademicResources_File.sourceTypeID    = Param.sourceTypeID;
                    _AcademicResources_File.targetFileUrl   = Param.resourceFile;
                    _AcademicResources_File.title           = Param.title;
                    UpdateResourcesFile(_AcademicResources_File);
                }
                else
                {
                    result.IsSuccess = false;
                    result.Error     = "资源文件路径为空";
                    return(result);
                }
                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "修改目录", "UpdateResourceMenu", ex);
                result.IsSuccess = false;
            }
            return(result);
        }
 public HttpResponseMessage SaveResourcesFile([FromBody] AcademicResources_File Param)
 {
     try
     {
         AcademicResourcesProvider _Provider = new AcademicResourcesProvider();
         var result = _Provider.SaveResourcesFile(Param);
         return(Request.CreateResponse(HttpStatusCode.OK, result));
     }
     catch (Exception ex)
     {
         LogFactory _LogFactory = new LogFactory(this.GetType());
         _LogFactory.CreateLog(LogType.Error, "保存资源文件", "SaveResourcesFile", ex);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
        /// <summary>
        /// 保存资源文件
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public BaseResopne <Int32> SaveResourcesFile(AcademicResources_File Data)
        {
            BaseResopne <Int32> result = new BaseResopne <Int32>();

            try
            {
                //获取当前登录
                AccountProvider _AccountProvider = new AccountProvider();
                var             user             = _AccountProvider.GetCurrentUser();
                if (user == null)
                {
                    result.IsSuccess = false;
                    result.Error     = "获取当前用户信息失败";
                    return(result);
                }
                //判断数据是否存在
                StringBuilder sql = new StringBuilder();
                sql.AppendLine("select count(id) from de2_aresource_file where parentID=@parentID");
                MySqlClient _Client = new MySqlClient();
                var         count   = Convert.ToInt32(_Client.ExecuteScalar(sql.ToString(), new MySqlParameter("@parentID", Data.parentID)));
                if (count == 0)
                {
                    Data.createTime      = DateTime.Now;
                    Data.createUserID    = user.id;
                    Data.lastModifyTime  = DateTime.Now;
                    Data.lastModifyUsrID = user.id;
                    AddResourcesFile(Data);
                }
                else
                {
                    Data.lastModifyTime  = DateTime.Now;
                    Data.lastModifyUsrID = user.id;
                    AddResourcesFile(Data);
                }
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "保存资源文件", "SaveResourcesFile", ex);
                result.IsSuccess = false;
            }
            return(result);
        }
        /// <summary>
        /// 获取学术资源详细
        /// </summary>
        /// <param name="parentID">父级ID</param>
        /// <returns></returns>
        public AcademicResources_File GetAcademicResourcesFile(int parentID)
        {
            AcademicResources_File result = null;

            try
            {
                StringBuilder sql = new StringBuilder();
                sql.AppendLine(@"select daf.id,title ,createTime ,createUserID ,u.userName as createUserName
                ,targetFileUrl,sourceTypeID,dat.typeName as sourceTypeName,parentID   
                from de2_aresource_file daf
                LEFT JOIN de2_user u on  u.id=daf.createUserID
                LEFT JOIN de2_aresource_type dat on dat.id=daf.sourceTypeID");
                //检索条件
                sql.AppendLine("where parentID=@parentID");
                MySqlClient _Client = new MySqlClient();
                result = _Client.ExecuteQuery <AcademicResources_File>(sql.ToString(), new MySqlParameter("@parentID", parentID)).FirstOrDefault();;
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "获取目录", "GetAcademicResourcesMenu", ex);
            }
            return(result);
        }
        /// <summary>
        /// 修改学术资源信息
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public BaseResopne <string> UpdateAcademicResources(AcademicResources Data)
        {
            BaseResopne <string> result = new BaseResopne <string>();

            try
            {
                //获取当前登录人
                AccountProvider _AccountProvider = new AccountProvider();
                var             user             = _AccountProvider.GetCurrentUser();
                if (user == null)
                {
                    result.IsSuccess = false;
                    result.Error     = "获取当前用户信息失败";
                    return(result);
                }
                Data.lastModifyTime  = DateTime.Now;
                Data.lastModifyUsrID = user.id;
                //生成sql
                StringBuilder sql = new StringBuilder();
                sql.AppendLine(@"update  de2_aresource set `name`=@`name`,parentID=@parentID,sourceTypeID=@sourceTypeID,isChild=@,author=@,isPublish=@isPublish,`year`=@`year`,periodNumber=@periodNumber,lastModifyTime=@lastModifyTime,lastModifyUsrID=@lastModifyUsrID,isMenu=@isMenu where id=@id");
                //执行sql语句
                MySqlClient _Client = new MySqlClient();
                _Client.ExecuteNonQuery(sql.ToString()
                                        , new MySqlParameter("@`name`", Data.name)
                                        , new MySqlParameter("@parentID", Data.parentID)
                                        , new MySqlParameter("@sourceTypeID", Data.sourceTypeID)
                                        , new MySqlParameter("@isChild", Data.isChild)
                                        , new MySqlParameter("@author", Data.author)
                                        , new MySqlParameter("@isPublish", Data.isPublish)
                                        , new MySqlParameter("@`year`", Data.year)
                                        , new MySqlParameter("@periodNumber", Data.periodNumber)
                                        , new MySqlParameter("@lastModifyTime", Data.lastModifyTime)
                                        , new MySqlParameter("@lastModifyUsrID", Data.lastModifyUsrID)
                                        , new MySqlParameter("@isMenu", Data.isMenu)
                                        , new MySqlParameter("@id", Data.id));
                //判断文件路径是否为空
                if (string.IsNullOrEmpty(Data.resourceFile))
                {
                    AcademicResources_File _AcademicResources_File = new AcademicResources_File();
                    _AcademicResources_File.lastModifyTime  = DateTime.Now;
                    _AcademicResources_File.lastModifyUsrID = user.id;
                    _AcademicResources_File.parentID        = Data.id;
                    _AcademicResources_File.sourceTypeID    = Data.sourceTypeID;
                    _AcademicResources_File.targetFileUrl   = Data.resourceFile;
                    _AcademicResources_File.title           = Data.name;
                    UpdateResourcesFile(_AcademicResources_File);
                }
                else
                {
                    DelResourcesFileByParent(Data.id);
                }
                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "修改学术资源信息", "UpdateAcademicResources", ex);
                result.IsSuccess = false;
            }
            return(result);
        }
        /// <summary>
        /// 保存学术资源信息
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public BaseResopne <Int32> AddAcademicResources(AcademicResources Data)
        {
            BaseResopne <Int32> result = new BaseResopne <Int32>();

            try
            {
                //获取当前登录人
                AccountProvider _AccountProvider = new AccountProvider();
                var             user             = _AccountProvider.GetCurrentUser();
                if (user == null)
                {
                    result.IsSuccess = false;
                    result.Error     = "获取当前用户信息失败";
                    return(result);
                }
                Data.createUserID    = user.id;
                Data.createTime      = DateTime.Now;
                Data.lastModifyTime  = DateTime.Now;
                Data.lastModifyUsrID = user.id;
                //生成sql
                StringBuilder sql = new StringBuilder();
                sql.AppendLine(@"insert into de2_aresource (`name`,parentID,sourceTypeID,createTime,createUserID,isChild,author,isPublish,`year`,periodNumber,lastModifyTime,lastModifyUsrID,isMenu) values(@`name`,@parentID,@sourceTypeID,@createTime,@createUserID,@isChild,@author,@isPublish,@`year`,@periodNumber,@lastModifyTime,@lastModifyUsrID,@isMenu)");
                //执行sql语句
                MySqlClient _Client    = new MySqlClient();
                var         ResourceID = _Client.Inster(sql.ToString()
                                                        , new MySqlParameter("@`name`", Data.name)
                                                        , new MySqlParameter("@parentID", Data.parentID)
                                                        , new MySqlParameter("@sourceTypeID", Data.sourceTypeID)
                                                        , new MySqlParameter("@createTime", Data.createTime)
                                                        , new MySqlParameter("@createUserID", Data.createUserID)
                                                        , new MySqlParameter("@isChild", Data.isChild)
                                                        , new MySqlParameter("@author", Data.author)
                                                        , new MySqlParameter("@isPublish", Data.isPublish)
                                                        , new MySqlParameter("@`year`", Data.year)
                                                        , new MySqlParameter("@periodNumber", Data.periodNumber)
                                                        , new MySqlParameter("@lastModifyTime", Data.lastModifyTime)
                                                        , new MySqlParameter("@lastModifyUsrID", Data.lastModifyUsrID)
                                                        , new MySqlParameter("@isMenu", Data.isMenu));
                result.Data = Convert.ToInt32(ResourceID);
                //判断文件路径是否为空
                if (!string.IsNullOrEmpty(Data.resourceFile))
                {
                    AcademicResources_File _AcademicResources_File = new AcademicResources_File();
                    _AcademicResources_File.lastModifyTime  = DateTime.Now;
                    _AcademicResources_File.lastModifyUsrID = user.id;
                    _AcademicResources_File.createTime      = DateTime.Now;
                    _AcademicResources_File.createUserID    = user.id;
                    _AcademicResources_File.parentID        = Convert.ToInt32(ResourceID);
                    _AcademicResources_File.sourceTypeID    = Data.sourceTypeID;
                    _AcademicResources_File.targetFileUrl   = Data.resourceFile;
                    _AcademicResources_File.title           = Data.name;
                    AddResourcesFile(_AcademicResources_File);
                }
                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "保存学术资源信息", "AddAcademicResources", ex);
                result.IsSuccess = false;
            }
            return(result);
        }