/// <summary>
 /// 新增共享
 /// </summary>
 /// <param name="gxEntity">共享实体</param>
 /// <param name="userId">共享用户ID</param>
 public void AddGx(GxEntity gxEntity,int userId)
 {
     try
     {
         GxEntity gxEntityResult = AllGxmxById(userId);
         foreach (var user in gxEntity.UserList)
         {
             AddFriend(user, userId.ToString());
             foreach (var file in gxEntity.FileList)
             {
                 if (ZyhValidate(user, file, gxEntityResult)) continue;
                 var zyhgx = new gxgl_zyhgx
                 {
                     file_id = file,
                     user_id = Convert.ToInt32(user),
                     gx_ly = userId,
                     gx_sj = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),
                     gx_isread = "否"
                 };
                 zyhGxFilesDB.gxgl_zyhgx.InsertOnSubmit(zyhgx);
                 zyhGxFilesDB.SubmitChanges();
             }
         }
         foreach (var fsyh in gxEntity.FsyhList)
         {
             foreach (var file in gxEntity.FileList)
             {
                 if (FsyhValidate(fsyh, file, gxEntityResult)) continue;
                 var fsyhgx = new gxgl_fsyhgxb
                 {
                     file_id = file,
                     fsyh_id = Convert.ToInt32(fsyh),
                     fsyhgx_ly = userId,
                     fsyhgx_sj = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
                 };
                 fsyhGxFilesDB.gxgl_fsyhgxb.InsertOnSubmit(fsyhgx);
                 fsyhGxFilesDB.SubmitChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public ActionResult SetGx(UserModel user)
        {
            List<string> userList = new List<string>();
            List<string> fileList = new List<string>();
            List<string> fsyhList = new List<string>();
            GxEntity gxEntity = new GxEntity();
            try
            {
                if (Request.Form["filesGx"] == null)
                {
                    throw new Exception("没有选择要共享的文件!");
                }
                if (Request.Form["usersGx"] == null && Request.Form["fsyhsGx"] == null)
                {
                    throw new Exception("没有选择要共享的用户!");
                }
                var files = Request.Form["filesGx"];
                var users = Request.Form["usersGx"] == null ? string.Empty : Request.Form["usersGx"];
                var fsyhs = Request.Form["fsyhsGx"] == null ? string.Empty : Request.Form["fsyhsGx"];
                if (users != "")
                {
                    foreach (var userInfo in users.Split(','))
                        userList.Add(userInfo);
                }

                foreach (var fileInfo in files.Split(','))
                    fileList.Add(fileInfo);
                if (fsyhs != "")
                {
                    foreach (var fsyhInfo in fsyhs.Split(','))
                        fsyhList.Add(fsyhInfo);
                }
                gxEntity.UserList = userList;
                gxEntity.FileList = fileList;
                gxEntity.FsyhList = fsyhList;
                gxglDAO.AddGx(gxEntity, user.UserInfo.user_id);
                return JavaScript("alert('设置成功!')");
            }
            catch (Exception e)
            {
                return JavaScript("alert('" + e.Message + "')");
            }
        }
        public GxEntity AllGxmxById(int userId)
        {
            var zyhgx = (from u in zyhGxFilesDB.gxgl_zyhgx
                         where u.gx_ly == userId
                         select u).ToList();
            var fsyhgx = (from fyf in fsyhGxFilesDB.gxgl_fsyhgxb
                             where fyf.fsyhgx_ly == userId
                             select fyf).ToList();

            var gxEntity = new GxEntity
            {
                ZyhgxMx = zyhgx,
                FsyhgxMx = fsyhgx
            };
            return gxEntity;
        }
 /// <summary>
 /// 验证是否已经存在该共享(主用户)
 /// </summary>
 /// <param name="userId">被共享的用户ID</param>
 /// <param name="fileId">被共享的文件ID</param>
 /// <returns></returns>
 bool ZyhValidate(string userId, string fileId,GxEntity gxEntityResult)
 {
     foreach (var zyhgx in gxEntityResult.ZyhgxMx)
     {
         if (zyhgx.user_id == Convert.ToInt32(userId) && zyhgx.file_id == fileId)
             return true;//已经存在这个共享
     }
     return false;
 }
 /// <summary>
 /// 验证是否已经存在该共享(附属用户)
 /// </summary>
 /// <param name="fsyhId">被共享的附属用户ID</param>
 /// <param name="fileId">被共享的文件ID</param>
 /// <returns></returns>
 bool FsyhValidate(string fsyhId, string fileId, GxEntity gxEntityResult)
 {
     foreach (var fsyhgx in gxEntityResult.FsyhgxMx)
     {
         if (fsyhgx.fsyh_id == Convert.ToInt32(fsyhId) && fsyhgx.file_id == fileId)
             return true;//已经存在这个共享
     }
     return false;
 }