Click here to Skip to main content
15,886,199 members
Articles / Mobile Apps / Windows Mobile

CDList

Rate me:
Please Sign up or sign in to vote.
2.77/5 (23 votes)
26 Apr 2004CPOL 45.8K   144   17   2
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

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNice work Pin
Fad B12-May-04 4:17
Fad B12-May-04 4:17 
GeneralRe: Nice work Pin
Anne Saouter13-May-04 23:36
Anne Saouter13-May-04 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.