Click here to Skip to main content
13,006,020 members (67,673 online)
Click here to Skip to main content
Add your own
alternative version

Stats

38K views
131 downloads
18 bookmarked
Posted 26 Apr 2004

CDList

, 26 Apr 2004
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Anne Saouter
Web Developer
France France
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralNice work Pin
Fad B12-May-04 4:17
memberFad B12-May-04 4:17 
GeneralRe: Nice work Pin
Anne Saouter13-May-04 23:36
memberAnne 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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170628.1 | Last Updated 27 Apr 2004
Article Copyright 2004 by Anne Saouter
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid