Hello Programmers,
I'll like to build a big program.
But i have some little problems.
I'll use classes in my program. So for every 'thing' like customers is a seporate class. In the class i can make a new user and i can add that user to the database.
Something like this:
I like to read the database and make a list of alll customers.
I thought like this:
- make a SQL query like select * from customers
- a for loop
- for every record fill the class (class array).
- read the class and add the properties to a listbox
- the class has methods like .save etc. to save changes to the good directory
Is this good thinking ???
Or is it to complex....
I like to use the classes on multiple forms...
Gr. Jelmer
I'll like to build a big program.
But i have some little problems.
I'll use classes in my program. So for every 'thing' like customers is a seporate class. In the class i can make a new user and i can add that user to the database.
Something like this:
Code:
public class customers
{
int ID;
string Bedrijf,Contactpersoon,Adres,Postcode,Plaats,Tel,Mobiel,Fax,Email,Website,KVK,BTW,Debiteurnr, Opmerkingen;
public customers(int id,string bedrijf,string contactpersoon,string adres,string postcode,string plaats,string tel,string mobiel,string fax,string email,string website,string kvk,string btw,string debiteurnr,string opmerkingen)
{
//
// TODO: Add constructor logic here
//
ID = id;
Bedrijf = bedrijf;
Contactpersoon = contactpersoon;
Adres = adres;
Postcode = postcode;
Plaats = plaats;
Tel = tel;
Mobiel = mobiel;
Fax = fax;
Email = email;
Website = website;
KVK = kvk;
BTW = btw;
Debiteurnr = debiteurnr;
Opmerkingen = opmerkingen;
}
static OleDbConnection dbase(OleDbConnection Connection){
IniFile ini = new IniFile("test.ini");
string database;
database = ini.IniReadValue("Info","Database");
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;";
connectionString += @"Data Source=" + database + ";";
Connection.ConnectionString = connectionString;
Connection.Open();
return Connection;
}
public void insert()
{
try
{
OleDbConnection Connection = new OleDbConnection();
Connection = dbase(Connection);
// Create an OleDb command,
OleDbCommand command = new OleDbCommand();
command.Connection = Connection;
command.CommandText = "insert into Bedrijven (Bedrijf,Contactpersoon,Adres,Postcode,Plaats,Tel,Mobiel,Fax,Email,Website,kvk,btw,debiteurnr,opmerkingen) values('" + Bedrijf + "','" + Contactpersoon + "','" + Adres + "','" + Postcode + "','" + Plaats + "','" + Tel + "','" + Mobiel + "','" + Fax + "','" + Email + "','" + Website + "','" + KVK + "','" + BTW + "','" + Debiteurnr + "','" + Opmerkingen + " ') ";
command.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
I like to read the database and make a list of alll customers.
I thought like this:
- make a SQL query like select * from customers
- a for loop
- for every record fill the class (class array).
- read the class and add the properties to a listbox
- the class has methods like .save etc. to save changes to the good directory
Is this good thinking ???
Or is it to complex....
I like to use the classes on multiple forms...
Gr. Jelmer