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;

public partial class Common_ModifyInfo : System.Web.UI.Page
{
    UserManage usermanage = new UserManage();
    HostManage hostmanage = new HostManage();
    ImageManage imagemanage = new ImageManage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlPhoto.DataSource = imagemanage.GetAllPhoto("tb_Image").Tables[0].DefaultView;
            ddlPhoto.DataTextField = "编号";
            ddlPhoto.DataBind();
            if (Session["Pop"].ToString() == "用户")
            {
                usermanage.UserName = Session["Name"].ToString();
                txtName.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][0].ToString();
                txtPwd.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][1].ToString();
                txtTName.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][2].ToString();
                if (usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][3].ToString() == "True")
                    ddlSex.SelectedIndex = 0;
                if (usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][3].ToString() == "False")
                    ddlSex.SelectedIndex = 1;
                txtBirthday.Text = Convert.ToDateTime(usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][4].ToString()).ToShortDateString();
                txtTel.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][5].ToString();
                txtMobile.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][6].ToString();
                txtQQ.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][7].ToString();
                imgPhoto.ImageUrl = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][8].ToString();
                txtEmail.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][9].ToString();
                txtHAddress.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][10].ToString();
                txtRAddress.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][11].ToString();
                txtIndex.Text = usermanage.FindUserByName(usermanage, "tb_User").Tables[0].Rows[0][12].ToString();
                return;
            }
            if (Session["Pop"].ToString() == "版主")
            {
                hostmanage.HostName = Session["Name"].ToString();
                txtName.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][0].ToString();
                txtPwd.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][2].ToString();
                txtTName.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][3].ToString();
                if (hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][4].ToString() == "True")
                    ddlSex.SelectedIndex = 0;
                if (hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][4].ToString() == "False")
                    ddlSex.SelectedIndex = 1;
                txtBirthday.Text = Convert.ToDateTime(hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][5].ToString()).ToShortDateString();
                txtTel.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][6].ToString();
                txtMobile.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][7].ToString();
                txtQQ.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][8].ToString();
                imgPhoto.ImageUrl = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][9].ToString();
                txtEmail.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][10].ToString();
                txtHAddress.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][11].ToString();
                txtRAddress.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][12].ToString();
                txtIndex.Text = hostmanage.FindHostByName(hostmanage, "tb_Host").Tables[0].Rows[0][13].ToString();
                return;
            }
        }
    }
    protected void btnSelDate_Click(object sender, EventArgs e)
    {
        calDate.Visible = true;
    }
    protected void calDate_SelectionChanged(object sender, EventArgs e)
    {
        txtBirthday.Text = calDate.SelectedDate.ToShortDateString();
        calDate.Visible = false;
    }
    protected void ddlPhoto_SelectedIndexChanged(object sender, EventArgs e)
    {
        imagemanage.PhotoID = ddlPhoto.SelectedValue;
        imgPhoto.ImageUrl = imagemanage.FindPhotoByID(imagemanage, "tb_Image").Tables[0].Rows[0][1].ToString();
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        if (Session["Pop"].ToString() == "用户")
        {
            usermanage.UserName = txtName.Text;
            usermanage.UserPwd = txtPwd.Text;
            usermanage.TName = txtTName.Text;
            if (ddlSex.SelectedIndex == 0)
                usermanage.Sex = true;
            if (ddlSex.SelectedIndex == 1)
                usermanage.Sex = false;
            usermanage.Birthday = DateTime.Parse(txtBirthday.Text);
            usermanage.Tel = txtTel.Text;
            usermanage.Mobile = txtMobile.Text;
            usermanage.QQ = Int32.Parse(txtQQ.Text);
            imagemanage.PhotoID = ddlPhoto.SelectedValue;
            usermanage.Photo = imagemanage.FindPhotoByID(imagemanage, "tb_Image").Tables[0].Rows[0][1].ToString();
            usermanage.Email = txtEmail.Text;
            usermanage.FAddress = txtHAddress.Text;
            usermanage.RAddress = txtRAddress.Text;
            usermanage.Index = txtIndex.Text;
            usermanage.UpdateUser(usermanage);
            Response.Write("<script language=javascript>alert('用户信息修改成功！')</script>");
            return;
        }
        if (Session["Pop"].ToString() == "版主")
        {
            hostmanage.HostName = txtName.Text;
            hostmanage.HostPwd = txtPwd.Text;
            hostmanage.TName = txtTName.Text;
            if (ddlSex.SelectedIndex == 0)
                hostmanage.Sex = true;
            if (ddlSex.SelectedIndex == 1)
                hostmanage.Sex = false;
            hostmanage.Birthday = DateTime.Parse(txtBirthday.Text);
            hostmanage.Tel = txtTel.Text;
            hostmanage.Mobile = txtMobile.Text;
            hostmanage.QQ = Int32.Parse(txtQQ.Text);
            imagemanage.PhotoID = ddlPhoto.SelectedValue;
            hostmanage.Photo = imagemanage.FindPhotoByID(imagemanage, "tb_Image").Tables[0].Rows[0][1].ToString();
            hostmanage.Email = txtEmail.Text;
            hostmanage.FAddress = txtHAddress.Text;
            hostmanage.RAddress = txtRAddress.Text;
            hostmanage.Index = txtIndex.Text;
            hostmanage.UpdateHost(hostmanage);
            Response.Write("<script language=javascript>alert('版主信息修改成功！')</script>");
            return;
        }
    }
}
