using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page 
{
    public string temp = "upload.aspx?sn=0";
    public string sn;
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //页面初始化时生成 唯一的SN码，我就用时间了~
            sn = lbl_ID.Text = System.DateTime.Now.ToString("yyyyMMddhhmmss");
            temp = "upload.aspx?sn=" + sn;
        }
    }
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txt_WorkName.Text.Trim()))
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请填写作品名称!')</script>");
        }
        else
        {
            string s_Content = null;
            ds = DbHelperOleDb.Query("select * from [temp] where temp_sn='" + lbl_ID.Text + "'");
            if (ds != null && ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        s_Content = ds.Tables[0].Rows[i][1].ToString() + "|" + s_Content;
                    }
                }
            }

            string strSql = "insert into [work](work_Name,work_Content) values(@work_Name,@work_Content)";
            OleDbParameter[] cmdParms = new OleDbParameter[]
                            {
                                new OleDbParameter("@work_Name",txt_WorkName.Text.Trim()),
                                new OleDbParameter("@work_Content",s_Content)
                            };
            if (DbHelperOleDb.ExecuteSql(strSql, cmdParms) > 0)
            {
                DbHelperOleDb.ExecuteSql("delete * from [temp] where temp_sn='" + lbl_ID.Text + "'");
                Response.Redirect("datashow.aspx");
            }
            else
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加失败!')</script>");
            }
        }
    }
}
