using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;

namespace NScontract.NSUser
{
    /// <summary>
    /// NSAddBook 的摘要说明。
    /// </summary>
    public partial class NSAddBook : System.Web.UI.Page
    {
        SqlConnection NSconn;

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (Session["NSNickName"] != null)
            {
                string NSconnection = ConfigurationSettings.AppSettings["strconnection"];
                NSconn = new SqlConnection(NSconnection);
                if (!IsPostBack)
                {
                    NSconn.Open();

                    string NSNickName = Session["NSNickName"].ToString();
                    string NSmysql = "select NSBookDe.ID,NSBookDe.NSBookID,NSBookDe.NSDepID,NSBookDe.NSBookName,NSBookDe.NSBookPrice,NSBookDe.NSBookNum,NSBookDe.NSBookDate,NSBookDe.NSBookSH,NSBookDe.NSBookInfo from NSBookDe,NSUser where NSBookDe.NSDepID = NSUser.NSDepID and NSUser.NSNickName = '" + NSNickName + "'";
                    SqlCommand NScmd = new SqlCommand(NSmysql, NSconn);
                    SqlDataReader NSsdr = NScmd.ExecuteReader();
                    if (NSsdr.Read())
                    {
                        Session["NSBookID"] = NSsdr["NSBookID"];
                        NSBookID.Text = Session["NSBookID"].ToString();
                        Session["NSBookName"] = NSsdr["NSBookName"];
                        NSBookName.Text = Session["NSBookName"].ToString();
                        Session["NSBookPrice"] = NSsdr["NSBookPrice"];
                        NSBookPrice.Text = Session["NSBookPrice"].ToString();
                        Session["NSBookDate"] = NSsdr["NSBookDate"];
                        NSBookDate.Text = Session["NSBookDate"].ToString();
                        Session["NSBookSH"] = NSsdr["NSBookSH"];
                        NSBookSH.Text = Session["NSBookSH"].ToString();
                        Session["NSBookInfo"] = NSsdr["NSBookInfo"];
                        NSBookInfo.Text = Session["NSBookInfo"].ToString();
                        Session["NSBookNum"] = NSsdr["NSBookNum"];
                        NSBookNum.Text = Session["NSBookNum"].ToString();
                        Session["NSDepID"] = NSsdr["NSDepID"];



                    }
                    NSconn.Close();
                }
            }
            else
            {
                Response.Redirect("../Index.aspx");
            }

        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion

        public void btnOK_Click(object sender, System.EventArgs e)
        {
            string NSDepID = Session["NSDepID"].ToString();


            SqlCommand NScmd = new SqlCommand("update_NSBooke_1", NSconn);
            NScmd.CommandType = CommandType.StoredProcedure;
            try
            {
                NScmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, 4));
                NScmd.Parameters.Add(new SqlParameter("@NSBookID", SqlDbType.Int, 4));
                NScmd.Parameters.Add(new SqlParameter("@NSDepID", SqlDbType.Int, 4));
                NScmd.Parameters.Add(new SqlParameter("@NSBookName", SqlDbType.VarChar, 50));
                NScmd.Parameters.Add(new SqlParameter("@NSBookInfo", SqlDbType.VarChar, 200));
                NScmd.Parameters.Add(new SqlParameter("@NSBookPrice", SqlDbType.Decimal, 9));
                NScmd.Parameters.Add(new SqlParameter("@NSBookNum", SqlDbType.Decimal, 9));
                NScmd.Parameters.Add(new SqlParameter("@NSBookDate", SqlDbType.Decimal, 9));
                NScmd.Parameters.Add(new SqlParameter("@NSBookSH", SqlDbType.DateTime, 8));
                NScmd.Parameters["@ID"].Value = Request.QueryString["ID"];
                NScmd.Parameters["@NSBookID"].Value = NSBookID.Text;
                NScmd.Parameters["@NSDepID"].Value = NSDepID;
                NScmd.Parameters["@NSBookName"].Value = NSBookName.Text;
                NScmd.Parameters["@NSBookInfo"].Value = NSBookInfo.Text;
                NScmd.Parameters["@NSBookPrice"].Value = NSBookPrice.Text;
                NScmd.Parameters["@NSBookNum"].Value = NSBookNum.Text;
                NScmd.Parameters["@NSBookDate"].Value = NSBookDate.Text;
                NScmd.Parameters["@NSBookSH"].Value = NSBookSH.Text;


                NScmd.Connection.Open();
                NScmd.ExecuteNonQuery();

            }
            catch (SqlException ex)
            {
                throw ex;
            }
            NScmd.Connection.Close();

            string str = "<script language=javascript>window.dialogArguments.document.location.href='NSUserBook.aspx';window.close();</script>";
            Response.Write(str);
        }
    }
}
