Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CDList

0.00/5 (No votes)
26 Apr 2004 1  
Application useful to archive your CD

Sample Image 1

Sample screenshot

Sample screenshot

Introduction

CDList is a useful application used to locate where your different CD or DVD are.
CDList is writen in C# using SQLCe.

Brief Code Description

public NewForm(MainForm mf, int ID) //Parent (to access to public function 
                                    // to refresh ListView), 
                                    //ID (0 if new, other if modify)
{
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();
    conn = new SqlCeConnection ("Data Source = CDList.sdf");
    parentForm = mf;
    IDEdit = ID;
    //
    // TODO: Add any constructor code after InitializeComponent call
    //
}

private void NewForm_Load(object sender, System.EventArgs e)
{
    UpdateCmbox(); //Populate ComboBoxes
    if (IDEdit != 0) //If Modify mode, populate all fields
    {
        conn.Open();
        cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT * FROM tbl_CDList WHERE ID = "+IDEdit+";";
        SqlCeDataReader rdr = cmd.ExecuteReader();
        rdr.Read();
        Title.Text = rdr.GetString(1);
        Content.Text = rdr.GetString(2);
        cmbType.Text = rdr.GetString(3);
        cmbLocation.Text = rdr.GetString(4);
        conn.Close();
    } 
}

private void UpdateCmbox() //Reset all fields and populate ComboBoxes
{
    Title.Text = "";
    Content.Text = "";
    cmbLocation.Text = "";
    cmbType.Text = "";
    cmbLocation.Items.Clear();
    conn.Open();
    cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT Title FROM tbl_Locations ORDER BY Title ASC;";
    SqlCeDataReader rdr = cmd.ExecuteReader();
    while(rdr.Read())
    {
        cmbLocation.Items.Add(rdr.GetString(0));
    }
    cmbLocation.Refresh();
    cmbType.Items.Clear();
    cmd.CommandText = "SELECT Title FROM tbl_Types ORDER BY Title ASC;";
    rdr = cmd.ExecuteReader();
    while(rdr.Read())
    {
        cmbType.Items.Add(rdr.GetString(0));
    }
    cmbType.Refresh();
    conn.Close();
}



private void Reset_Click(object sender, System.EventArgs e)
{
    UpdateCmbox();
}

private void Save_Click(object sender, System.EventArgs e)
{
    conn = new SqlCeConnection ("Data Source = CDList.sdf");
    conn.Open();
    cmd = conn.CreateCommand();
    if (IDEdit != 0) //If modify mode
    {
        cmd.CommandText = "UPDATE tbl_CDList SET Title = '"+Title.Text+"',"+ 
                           "Content = '"+Content.Text+"', +
                           "Location = '"+cmbLocation.Text+"', Type = '"+
                           cmbType.Text+"' WHERE ID = "+IDEdit;
    }
    else //else insert mode
    {
        cmd.CommandText = "INSERT INTO tbl_CDList(Title, Content, Location, "+
                           "Type) VALUES ('"+Title.Text+"', "+
                           "'"+Content.Text+"', '"+cmbLocation.Text+"' ,'"+
                           cmbType.Text+"')";
    }
    cmd.ExecuteNonQuery();
    conn.Close();
    parentForm.UpdateLView();
    UpdateCmbox();
}

Resources

MSDN Library January 2004 for how to connect to a SQLCe database.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here