using System;
using System.Data;
using System.Data.SqlClient;
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 DeliverCard : System.Web.UI.Page
{
    DataOperate sqlBind = new DataOperate();
    SqlConnection sqlcon=new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                labUserName.Text = Session["Name"].ToString() + "！";
                string strsql = "select * from tb_Module";
                sqlcon.Open();
                SqlDataAdapter myApter = new SqlDataAdapter(strsql, sqlcon);
                DataSet myDS = new DataSet();
                myApter.Fill(myDS, "tb_Module");
                sqlcon.Close();
                ddlModuleName.DataSource = myDS;
                ddlModuleName.DataValueField = "ModuleName";
                ddlModuleName.DataBind();
            }
            catch
            {
                Response.Write("<script>alert('您还没有登录，或是服务器超时，请重新登录！');location='Login.aspx'</script>");
            }
        }
    }
    
    protected void btnDeliver_Click(object sender, EventArgs e)
    {
        string strMod = "select ModuleID,ModuleName from tb_Module"
            + " where ModuleName='" + ddlModuleName.SelectedValue + "'";
        sqlcon.Open();
        SqlDataAdapter myApter = new SqlDataAdapter(strMod, sqlcon);
        DataSet myDS = new DataSet();
        myApter.Fill(myDS, "tb_Module");
        sqlcon.Close();
        DataRowView rowView = myDS.Tables["tb_Module"].DefaultView[0];
        string strModuleID = Convert.ToString(rowView["ModuleID"]);
        string sqlstr = "insert into tb_Card ([User],ModuleID,CardName,CardContent)"
                + " values('" + Session["Name"].ToString().Trim() + "','" + strModuleID.ToString().Trim()
                + "','" + txtCardTitle.Text.Trim() + "','" + txtCardContent.Text.Trim() + "')";
        sqlBind.DataCom(sqlstr);
        Response.Write("<script language=javascript>alert('发表成功');location='javascript:history.go(-1)';</script>");
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");
    }
}
