using System;
using System.Data;
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.Model;
using JuSNS.Common;

namespace JuSNS.Web.user.share
{
    public partial class PostShareComment : JuSNS.UI.Page.UserPage
    {
        public string Gaction = string.Empty;
        public string Gurl = string.Empty;
        public string Gcontent = string.Empty;
        public int myID;
        protected void Page_Load(object sender, EventArgs e)
        {
            GetIsNotEmail();
            Gaction = Request.QueryString["action"];
            string PostAction = Request.QueryString["postaction"];
            Gurl = Request.QueryString["url"];
            Gcontent = Request.QueryString["txtcontent"];
            myID = UserID;
            string result = Request.QueryString["result"];//
            if (result != null && result != string.Empty)
            {
                if (result == "1")
                {
                    GetMessage.InnerHtml = "<div class=\"msg-succ\">恭喜！分享成功。</div>";
                }
                else if (result == "error")
                {
                    GetMessage.InnerHtml = "<div class=\"msg-error\">找不到用户，或者用户错误。</div>";
                }
            }
            if (PostAction == "add")
            { 
                //增加网址
                //FriendIDGroup=&Title=&tcontent=&shareurl=&postaction=add&postType=0
                string FriendIDGroup = Request.QueryString["FriendIDGroup"];
                string Title = Request.QueryString["Title"];
                string tcontent = Request.QueryString["tcontent"];
                string posttype = Request.QueryString["postType"];
                string shareurl = Request.QueryString["shareurl"];
                string Hid_UserID = Request.QueryString["Hid_UserID"];
                if (posttype != null && posttype!=string.Empty)
                {
                    ShareInfo info = new ShareInfo();
                    JuSNS.Home.Share shareBill = new JuSNS.Home.Share();
                    info.UserID = UserID;
                    info.Title = Title;
                    info.Description = tcontent;
                    if (shareurl.Substring(0,7) != "http://")
                    {
                        shareurl = "http://" + shareurl;
                    }
                    info.Url = shareurl;
                    info.ShareType = EnumShareType.ShareWeb;
                    info.CaseID = 0;
                    info.IsLock = 0;
                    info.PostTime = DateTime.Now;
                    info.PostIP = JuSNS.Common.Public.GetClientIP();
                    info.Comments = 0;
                    info.Privacy = EnumPrivacy.ForFriends;
                    string ResultStr = string.Empty;
                    if (posttype == "0")
                    {
                        //分享给好友
                        int GetFriendIDGroup = 0;
                        if (Input.IsInteger(Hid_UserID))
                        {
                            GetFriendIDGroup = Convert.ToInt32(Hid_UserID);
                            info.FriendIDGroup = GetFriendIDGroup;
                            ResultStr = "1";
                        }
                        else
                        {
                            ResultStr = "error";
                        }
                    }
                    else
                    {
                        //分享到自己空间
                        info.FriendIDGroup = 0;
                        ResultStr = "1";
                    }
                    if (ResultStr == "1")
                    {
                        shareBill.Add(info);
                    }
                    Response.Redirect("postshare.aspx?action=newurl&url=&result=" + ResultStr + "");
                }
            }
        }

        /// <summary>
        /// 得到头像
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public string GetUserHeadPic()
        {
            return "<img src=\"" + GetHeadImage(UserID) + "\" style=\"width:48px;height:48px;\" />";
        }
    }
}
