protected void lstAuthor_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable table = AuthorAccess.GetAuthorInfoByID(lstAuthor.SelectedValue);

        try
        {
            foreach (DataRow row in table.Rows)
            {
                txtID.Text          = row["au_id"].ToString();
                txtFirstName.Text   = row["au_fname"].ToString();
                txtLastName.Text    = row["au_lname"].ToString();
                txtPhone.Text       = row["phone"].ToString();
                txtAddress.Text     = row["address"].ToString();
                txtCity.Text        = row["city"].ToString();
                txtState.Text       = row["state"].ToString();
                txtZip.Text         = row["zip"].ToString();
                chkContract.Checked = (bool)row["contract"];
                lblResults.Text     = "";
            }
        }
        catch (Exception err)
        {
            lblResults.Text = "Error getting author.  " + err.Message;
        }
    }
Exemple #2
0
    protected void cmdDelete_Click(object sender, EventArgs e)
    {
        int deleted = AuthorAccess.DeleteAuthor(txtID.Text);

        if (deleted > 0)
        {
            FillAuthorList();
        }
    }
Exemple #3
0
    protected void cmdInsert_Click(object sender, EventArgs e)
    {
        //This method uses a paramaterized sql statement to insert a new author into the database
        //See pages 459-460
        int inserted = AuthorAccess.InsertAuthor(txtID.Text, txtLastName.Text, txtFirstName.Text, txtPhone.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text, chkContract.Checked);

        if (inserted > 0)
        {
            FillAuthorList();
        }
    }
    private void FillAuthorList()
    {
        DataTable newTable = AuthorAccess.GetAllAuthorNames();

        foreach (DataRow row in newTable.Rows)
        {
            ListItem newItem = new ListItem();
            newItem.Text  = row["au_lname"] + ", " + row["au_fname"];
            newItem.Value = row["au_id"].ToString();
            lstAuthor.Items.Add(newItem);
        }
    }
Exemple #5
0
    protected void cmdUpdate_Click(object sender, EventArgs e)
    {
        //This method uses a paramaterized sql statement to update author attributes in the database
        //See pages 460-461

        int updated = AuthorAccess.UpdateAuthor(txtID.Text, txtLastName.Text, txtFirstName.Text, txtPhone.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text, chkContract.Checked);

        // If the update succeeded, refresh the author list.
        if (updated > 0)
        {
            FillAuthorList();
        }
    }
Exemple #6
0
    private void FillAuthorList()
    {
        //This method should populate the lstAuthor DropDownList with the authors in the pubs database
        //Author names are shown as the text for each ListItem and author IDs are stored as the values
        //See Pages 451-452
        lstAuthor.Items.Clear();

        DataTable table = AuthorAccess.GetAllAuthorNames();


        foreach (DataRow row in table.Rows)
        {
            ListItem newItem = new ListItem();
            newItem.Text  = row["au_lname"] + "," + row["au_fname"];
            newItem.Value = row["au_id"].ToString();
            lstAuthor.Items.Add(newItem);
        }
    }
Exemple #7
0
    protected void lstAuthor_SelectedIndexChanged(object sender, EventArgs e)
    {
        //This method retrieves all of the attributes of the selected author from the database and
        //populates the controls with these values
        //See page 455


        DataTable table = AuthorAccess.GetAuthorInfoByID(lstAuthor.SelectedValue);

        DataRow row = table.Rows[0];

        txtID.Text          = row["au_id"].ToString();
        txtFirstName.Text   = row["au_fname"].ToString();
        txtLastName.Text    = row["au_lname"].ToString();
        txtPhone.Text       = row["phone"].ToString();
        txtAddress.Text     = row["address"].ToString();
        txtCity.Text        = row["city"].ToString();
        txtState.Text       = row["state"].ToString();
        txtZip.Text         = row["zip"].ToString();
        chkContract.Checked = (bool)row["contract"];
        lblResults.Text     = "";
    }
 protected void cmdDelete_Click(object sender, EventArgs e)
 {
     AuthorAccess.DeleteAuthor(lstAuthor.SelectedValue);
 }
 protected void cmdUpdate_Click(object sender, EventArgs e)
 {
     AuthorAccess.UpdateAuthor(txtID.Text, txtLastName.Text, txtFirstName.Text, txtPhone.Text, txtAddress.Text, txtCity.Text, txtState.Text, txtZip.Text, chkContract.Checked);
 }