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 CardManage_DeliverCard : System.Web.UI.Page
{
    CardManage cardmanage = new CardManage();
    ModuleManage modulemanage = new ModuleManage();
    UserManage usermanage = new UserManage();
    HostManage hostmanage = new HostManage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ddlMName.DataSource = modulemanage.GetAllModule("tb_Module");
            ddlMName.DataTextField = "版块名称";
            ddlMName.DataBind();
        }
        DataSet ds = null;
        string strName = "";
        if (Session["Name"] == null)
        {
            strName = "匿名";
            labName.Text = strName;
            labEmail.Text = "无";
            labQQ.Text = "无";
            labIndex.Text = "无";
            imgPhoto.ImageUrl = "../Images/Visiter.jpg";
        }
        else
        {
            strName = Session["Name"].ToString();
            if (Session["Pop"].ToString() == "用户")
            {
                usermanage.UserName = strName;
                ds = usermanage.FindUserByName(usermanage, "tb_User");
                labName.Text = strName;
                labEmail.Text = ds.Tables[0].Rows[0][9].ToString();
                labQQ.Text = ds.Tables[0].Rows[0][7].ToString();
                labIndex.Text = ds.Tables[0].Rows[0][12].ToString();
                imgPhoto.ImageUrl = ds.Tables[0].Rows[0][8].ToString();
                return;
            }
            if (Session["Pop"].ToString() == "版主")
            {
                hostmanage.HostName = strName;
                ds = hostmanage.FindHostByName(hostmanage, "tb_Host");
                labName.Text = strName;
                labEmail.Text = ds.Tables[0].Rows[0][10].ToString();
                labQQ.Text = ds.Tables[0].Rows[0][8].ToString();
                labIndex.Text = ds.Tables[0].Rows[0][13].ToString();
                imgPhoto.ImageUrl = ds.Tables[0].Rows[0][9].ToString();
                return;
            }
            if (Session["Pop"].ToString() == "管理员")
            {
                labName.Text = strName;
                labEmail.Text = "无";
                labQQ.Text = "无";
                labIndex.Text = "无";
                imgPhoto.ImageUrl = "../Images/Admin.jpg";
                return;
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strName = "";
        string strPop = "";
        if (txtCName.Text == string.Empty)
        {
            Response.Write("<script language=javascript>alert('帖子名称不能为空！')</script>");
            return;
        }
        if (Session["Name"] == null)
        {
            strName = "匿名";
            strPop = "游客";
        }
        else
        {
            strName = Session["Name"].ToString();
            strPop = Session["Pop"].ToString();
        }
        cardmanage.CardID = cardmanage.GetCID();
        cardmanage.CardName = txtCName.Text;
        modulemanage.ModuleName = ddlMName.SelectedValue;
        cardmanage.ModuleID = modulemanage.FindModuleByName(modulemanage, "tb_Module").Tables[0].Rows[0][0].ToString();
        cardmanage.CardContent = FreeTextBox1.Text;
        cardmanage.CardTime = DateTime.Now;
        cardmanage.CardPeople = strName;
        cardmanage.Pop = strPop;
        cardmanage.AddCard(cardmanage);
        Response.Write("<script language=javascript>alert('帖子发表成功！')</script>");
        txtCName.Text = FreeTextBox1.Text = string.Empty;
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        txtCName.Text = FreeTextBox1.Text = string.Empty;
    }
}
