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;

namespace JuSNS.Web.Inc.Ajax
{
    public partial class DelGroupMemAjax : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            StartDel();
        }

        /// <summary>
        /// 开始删除
        /// </summary>
        /// <returns></returns>
        protected void StartDel()
        {
            string s_Type = Request.QueryString["Type"];
            string s_GID = Request.QueryString["groupid"];
            string s_UID = Request.QueryString["userid"];
            string s_Return = "";
            int GID = Convert.ToInt32(s_GID);
            int UID = Convert.ToInt32(s_UID);
            JuSNS.Home.GroupMember gmember = new JuSNS.Home.GroupMember();
            JuSNS.Model.GroupMemberInfo memberinfo = new JuSNS.Model.GroupMemberInfo();
            JuSNS.Home.Group gdiscuss = new JuSNS.Home.Group();
            JuSNS.Model.GroupDiscussInfo gdisinfo = new JuSNS.Model.GroupDiscussInfo();
            JuSNS.Home.UserGroup usergroup = new JuSNS.Home.UserGroup();
            JuSNS.Model.UserGroupInfo usergroupinfo = new JuSNS.Model.UserGroupInfo();
            JuSNS.Home.GroupInvite invite = new JuSNS.Home.GroupInvite();
            JuSNS.Model.GroupInviteInfo inviteinfo = new JuSNS.Model.GroupInviteInfo();
            switch (s_Type)
            {
                case "SetGroupAdmin":
                    s_Return = gmember.SetAdmin(UID, GID, UserID).ToString();
                    break;
                case "DelGroupAdmin":
                    s_Return = gmember.DelAdmin(UID, GID, UserID).ToString();
                    break;
                case "DelGroupMem":
                    s_Return = gmember.Out(UID, GID).ToString();
                    break;
                case "QuitGroup":
                    gmember.QuitGroup(UID, GID);
                    break;
                case "TopTopic":
                    gdisinfo = gdiscuss.Info(GID);
                    usergroupinfo = usergroup.Info(gdisinfo.GroupID);
                    if (gmember.IsGroupAdmin(UID, gdisinfo.GroupID) || usergroupinfo.UserID == UserID)
                    {
                        gdiscuss.Top(GID);
                        s_Return = "置顶：" + gdisinfo.Topic;
                    }
                    break;
                case "UnTopTopic":
                    gdisinfo = gdiscuss.Info(GID);
                    usergroupinfo = usergroup.Info(gdisinfo.GroupID);
                    if (gmember.IsGroupAdmin(UID, gdisinfo.GroupID) || usergroupinfo.UserID == UserID)
                    {
                        gdiscuss.UnTop(GID);
                        s_Return = gdisinfo.Topic;
                    }
                    break;
                case "DelTopTopic":
                    gdisinfo = gdiscuss.Info(GID);
                    usergroupinfo = usergroup.Info(gdisinfo.GroupID);
                    if (gmember.IsGroupAdmin(UID, gdisinfo.GroupID) || usergroupinfo.UserID == UserID)
                    {
                        gdiscuss.Del(GID, UID);
                        s_Return = "Group.aspx?GroupID=" + gdisinfo.GroupID;
                    }
                    break;
                case "DelReplys":
                    gdisinfo = gdiscuss.Info(GID);
                    usergroupinfo = usergroup.Info(gdisinfo.GroupID);
                    if (gmember.IsGroupAdmin(UID, gdisinfo.GroupID) || usergroupinfo.UserID == UserID)
                        gdiscuss.Del(GID);
                    else
                        gdiscuss.Del(GID, UID);
                    s_Return = (gdisinfo.SeriesNum + 1) + " 楼的回复已被删除";
                    break;
                case "AcceptGroup":
                    inviteinfo.ID = 0;
                    inviteinfo.Response = 1;
                    inviteinfo.RespTime = DateTime.Now;
                    inviteinfo.RespIP = JuSNS.Common.Public.GetClientIP();
                    inviteinfo.GroupID = GID;
                    inviteinfo.JoinUserID = UserID;
                    inviteinfo.UserID = 0;
                    inviteinfo.PostTime = DateTime.Now;
                    inviteinfo.Postscript = string.Empty;
                    inviteinfo.PostIP =string.Empty;
                    inviteinfo.InviteFlag = false;

                    memberinfo.ID = 0;
                    memberinfo.GroupID = GID;
                    memberinfo.JoinTime = DateTime.Now;
                    memberinfo.UserID = UserID;
                    memberinfo.Grade = JuSNS.Model.EnumGroupGrade.Common;

                    invite.Reponse(inviteinfo);
                    gmember.Join(memberinfo);

                    usergroupinfo = usergroup.Info(GID);

                    s_Return = "<div class=\"req\">加入群组 <a href=\""+rooDir+"/home/group/group.aspx?groupID=" + GID + "\">" + usergroupinfo.GroupName + "</a> 成功！</div>";
                    break;
                case "IgnoreGroup":
                    inviteinfo.ID = 0;
                    inviteinfo.Response = 2;
                    inviteinfo.RespTime = DateTime.Now;
                    inviteinfo.RespIP = JuSNS.Common.Public.GetClientIP();
                    inviteinfo.GroupID = GID;
                    inviteinfo.JoinUserID = UserID;
                    inviteinfo.UserID = 0;
                    inviteinfo.PostTime = DateTime.Now;
                    inviteinfo.Postscript = "";
                    inviteinfo.PostIP = "";
                    inviteinfo.InviteFlag = false;
                    invite.Reponse(inviteinfo);

                    usergroupinfo = usergroup.Info(GID);

                    s_Return = "<div  class=\"req\">你忽略了群组 <a href=\""+rooDir+"/home/group/group.aspx?groupID=" + GID + "\">" + usergroupinfo.GroupName + "</a>的邀请</div>";
                    break;
            }
            Response.Write(s_Return);
            Response.End();
        }
    }
}
