Пример #1
0
    void updateAuthor()
    {
        try
        {
            SqlConnection conn = new SqlConnection(strConn);
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            //UPDATE 語法
            SqlCommand sqlCmd = new SqlCommand(
                "UPDATE author_master_table SET "
                + "author_name = @author_name WHERE author_id = '" + AuthorIDTextBox.Text.Trim() + "'", conn);

            //接收TextBox值
            sqlCmd.Parameters.AddWithValue("@author_name", AuthorNameTextBox.Text.Trim()); //Trim 移除前後空白
            sqlCmd.ExecuteNonQuery();
            conn.Close();
            Response.Write("<script>alert('Author update successful!');</script>");
            clearForm();
            AuthorGridView.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
    }
Пример #2
0
    void signUpNewAuthor()
    {
        try
        {
            SqlConnection conn = new SqlConnection(strConn);
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            //INSERT INTO語法
            SqlCommand sqlCmd = new SqlCommand(
                "INSERT INTO author_master_table"
                + "(author_id, author_name)"
                + "VALUES(@author_id, @author_name)", conn);

            //接收TextBox值
            sqlCmd.Parameters.AddWithValue("@author_id", AuthorIDTextBox.Text.Trim()); //Trim 移除前後空白
            sqlCmd.Parameters.AddWithValue("@author_name", AuthorNameTextBox.Text.Trim());
            sqlCmd.ExecuteNonQuery();
            conn.Close();
            Response.Write("<script>alert('Add author successful!');</script>");
            clearForm();
            AuthorGridView.DataBind(); //Grid auto refresh after insert data
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "');</script>");
        }
    }
Пример #3
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            if (authorIdTextBox.Text=="")
            {
                Response.Write("<script>alert('Please Insert Author Id');</script>");

            }
            else
            {
                author = new Author();
                author.AuthorId = Convert.ToInt32(authorIdTextBox.Text);
                string message = authorManager.DeleteAuthor(author.AuthorId);
                Response.Write("<script>alert('" + message + "');</script>");
                AuthorGridView.DataBind();
            }
        }
Пример #4
0
 protected void AddButton_Click(object sender, EventArgs e)
 {
     if (authorNameTextBox.Text=="")
     {
         Response.Write("<script>alert('Please Insert Author Name');</script>");
     }
     else
     {
         author = new Author();
         author.AuthorName = authorNameTextBox.Text;
         string message = authorManager.SaveAuthor(author);
         Response.Write("<script>alert('" + message + "');</script>");
         AuthorGridView.DataBind();
     }
    
 }
Пример #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     AuthorGridView.DataBind();
 }