using System;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using JuSNS.Common;
using JuSNS.Home;
using JuSNS.Model;
using JuSNS.Config;

namespace JuSNS.Web.home.privacy
{
    public partial class index : JuSNS.UI.Page.UserPage
    {
        protected PrivacyInfo PRI = new PrivacyInfo();
        protected string succSTR = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            string a = Request.QueryString["a"];
            if (string.IsNullOrEmpty(a))
            {
                a = "profile";
            }
            a = a.ToLower();
            User u = new User();
            PRI = u.GetPrivacy(this.UserID);
            if (Request.Form.Count > 0)
            {
                switch (a)
                {
                    case "profile":
                        saveProfile();
                        break;
                    case "album":
                        saveAlbum();
                        break;
                    default:
                        break;
                }
            }
            else
            {
                if (a == "profile")
                {
                    this.profile.Visible = true;
                    this.wrap.Visible = false;
                }
                if (a == "album")
                {
                    this.profile.Visible = false;
                    this.wrap.Visible = true;
                    viewAlbumForm();
                }
            }
        }

        /// <summary>
        /// 保存隐私设置
        /// </summary>
        protected void saveProfile()
        {
            string aa = Request.Form["a"];
            if (aa == "minifeed")
            {
                saveMinifeed();
                return;
            }
            string PrivacySpace = Request.Form["PrivacySpace"];
            string PrivacyFavourite = Request.Form["PrivacyFavourite"];
            string PrivacyEducate = Request.Form["PrivacyEducate"];
            string PrivacyLasso = Request.Form["PrivacyLasso"];
            string PrivacyFriends = Request.Form["PrivacyFriends"];
            string PrivacyLeaveWord = Request.Form["PrivacyLeaveWord"];
            string PrivacyMiniBlog = Request.Form["PrivacyMiniBlog"];
            string PrivacyShare = Request.Form["PrivacyShare"];
            string PrivacyMovies = Request.Form["PrivacyMovies"];
            string PrivacyGroup = Request.Form["PrivacyGroup"];
            PrivacyInfo pri = PRI;
            pri.PrivacyGroup = (EnumPrivacy)Convert.ToInt32(PrivacyGroup);
            pri.PrivacyLeaveWord = (EnumPrivacy)Convert.ToInt32(PrivacyLeaveWord);
            pri.PrivacySpace = (EnumPrivacy)Convert.ToInt32(PrivacySpace);
            pri.PrivacyFavourite = (EnumPrivacy)Convert.ToInt32(PrivacyFavourite);
            pri.PrivacyEducate = (EnumPrivacy)Convert.ToInt32(PrivacyEducate);
            pri.PrivacyLasso = (EnumPrivacy)Convert.ToInt32(PrivacyLasso);
            pri.PrivacyFriends = (EnumPrivacy)Convert.ToInt32(PrivacyFriends);
            pri.PrivacyMiniBlog = (EnumPrivacy)Convert.ToInt32(PrivacyMiniBlog);
            pri.PrivacyShare = (EnumPrivacy)Convert.ToInt32(PrivacyShare);
            pri.PrivacyMovies = (EnumPrivacy)Convert.ToInt32(PrivacyMovies);
            pri.LastPostIP = Common.Public.GetClientIP();
            pri.LastPostTime = DateTime.Now;
            User u = new User();
            u.SetPrivacy(this.UserID, pri);
            PageRight("设置成功", rooDir + "/home/privacy");
        }

        /// <summary>
        /// 个人动态设置
        /// </summary>
        protected void saveMinifeed()
        {
            string minifeedProfile_space = Request.Form["minifeedProfile_space"];
            string minifeedFriend = Request.Form["minifeedFriend"];
            string minifeedWall = Request.Form["minifeedWall"];
            string minifeedPhotoComment = Request.Form["minifeedPhotoComment"];
            string minifeedGroup_leave = Request.Form["minifeedGroup_leave"];
            string minifeedGroupPost = Request.Form["minifeedGroupPost"];
            string minifeedBlogComment = Request.Form["minifeedBlogComment"];
            string minifeedMovie = Request.Form["minifeedMovie"];
            string minifeedPhotoTag = Request.Form["minifeedPhotoTag"];
            string minifeedShareComment = Request.Form["minifeedShareComment"];
            PrivacyInfo pri = PRI;
            pri.ActUpdateData = Convert.ToBoolean(Convert.ToInt32(minifeedProfile_space));
            pri.ActAddFriend = Convert.ToBoolean(Convert.ToInt32(minifeedFriend));
            pri.ActLeaveWord = Convert.ToBoolean(Convert.ToInt32(minifeedWall));
            pri.ActPicComment = Convert.ToBoolean(Convert.ToInt32(minifeedPhotoComment));
            pri.ActSecede = Convert.ToBoolean(Convert.ToInt32(minifeedGroup_leave));
            pri.ActDeliver = Convert.ToBoolean(Convert.ToInt32(minifeedGroupPost));
            pri.ActLogComment = Convert.ToBoolean(Convert.ToInt32(minifeedBlogComment));
            pri.ActMovieComment = Convert.ToBoolean(Convert.ToInt32(minifeedMovie));
            pri.ActPhotoLasso = Convert.ToBoolean(Convert.ToInt32(minifeedPhotoTag));
            pri.ActShareComment = Convert.ToBoolean(Convert.ToInt32(minifeedShareComment));
            pri.LastPostIP = Common.Public.GetClientIP();
            pri.LastPostTime = DateTime.Now;
            User u = new User();
            u.SetPrivacy(this.UserID, pri);
            PageRight("设置成功", rooDir + "/home/privacy");
        }

        /// <summary>
        /// 保存相册隐私设置
        /// </summary>
        protected void saveAlbum()
        {
            JuSNS.Home.Album ab = new JuSNS.Home.Album();
            List<AlbumInfo> albumlist = ab.AlbumList(this.UserID);
            for (int i = 0; i < albumlist.Count; i++)
            {
                string attr = Request.Form["attr[" + albumlist[i].AlbumID + "]"];
                EnumPrivacy ep = (EnumPrivacy)Convert.ToInt32(attr);
                AlbumInfo ai = albumlist[i];
                ai.Privacy = ep;
                ab.Edit(ai);
            }
            PageRight("设置成功", rooDir + "/home/privacy");
        }

        /// <summary>
        /// 相册表单设置
        /// </summary>
        protected void viewAlbumForm()
        {
            JuSNS.Home.Album ab = new JuSNS.Home.Album();
            List<AlbumInfo> albumlist = ab.AlbumList(this.UserID);
            this.albumform.DataSource = albumlist;
            this.albumform.DataBind();
        }
        /// <summary>
        /// 取得相册封面
        /// </summary>
        /// <returns>路径</returns>
        protected string getCover(object AlbumID)
        {
            JuSNS.Home.Album ab = new JuSNS.Home.Album();
            int ID = (int)AlbumID;
            return this.GetSmallPic(ab.CoverPath(ID), 1);
        }
        /// <summary>
        /// 隐私是否选中
        /// </summary>
        /// <param name="priva"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        protected string sected(object priva, int i)
        {
            if ((EnumPrivacy)priva == (EnumPrivacy)i)
            {
                return " selected";
            }
            else
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// 隐私是否选中
        /// </summary>
        /// <param name="priva"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        protected string sected(EnumPrivacy priva, int i)
        {
            if (priva == (EnumPrivacy)i)
            {
                return " selected";
            }
            else
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// checked选中情况
        /// </summary>
        /// <param name="o"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        protected string chked(bool priva, int i)
        {
            if (priva == Convert.ToBoolean(i))
            {
                return " checked";
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
