Witam serdecznie.
Piszę aplikację, która ma dodawać studentów do Obiektowej Bazy Danych. ( db4objects .NET )
Mam 3 tabele ( 3 klasy )
Student / Adres / Telefon
Chciałbym aby student mógł posiadać wiele telefonów a numer indeksu był zawsze unikalny.
Do tej pory udało mi się wydłubać coś takiego:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Db4objects;
using Db4objects.Db4o;
namespace Program_1
{
public partial class Form1 : Form
{
public List<Student> ListaStudentow = new List<Student>();
public List<Adres> ListaAdresow = new List<Adres>();
public List<Telefon> ListaTelefonow = new List<Telefon>();
public Form1()
{
InitializeComponent();
}
private void btnDodajStudenta_Click(object sender, EventArgs e)
{
using (IObjectContainer db = Db4oEmbedded.OpenFile("BazaStudentow.yap"))
{
Student nowy = new Student();
Telefon tel = new Telefon();
Adres adr = new Adres();
nowy.Imie = tbxImie.Text;
nowy.Nazwisko = tbxNazwisko.Text;
nowy.Numer = tbxNumerIndeksu.Text;
adr.Miasto = tbxMiasto.Text;
adr.Ulica = tbxUlica.Text;
adr.KodPocztowy = tbxKodPocztowy.Text;
tel.Numer = tbxTelefon.Text;
tel.Operator = tbxOperator.Text;
db.Store(nowy);
db.Store(adr);
db.Store(tel);
db.Commit();
IObjectSet result1 = db.QueryByExample(nowy);
IObjectSet result2 = db.QueryByExample(adr);
IObjectSet result3 = db.QueryByExample(tel);
ListResult(result1,result2,result3);
}
}
public void ListResult(IObjectSet result1, IObjectSet result2, IObjectSet result3)
{
int totalResult = result1.Count + result2.Count + result3.Count;
tbxIloscStudentow.Text = "Aktualnie "+totalResult.ToString()+" studentów";
foreach (Student item in result1)
{
ListaStudentow.Add(item);
}
foreach (Adres item in result2)
{
ListaAdresow.Add(item);
}
foreach (Telefon item in result3)
{
ListaTelefonow.Add(item);
}
DGV.DataSource = ListaStudentow.ToList() + " " + ListaAdresow.ToList() + " " + ListaTelefonow.ToList();
}
}
public class Student
{
string _imie;
string _nazwisko;
string _numer;
string _adres;
List<Student> _telefony;
public Student()
{
}
public Student(string imie, string nazwisko, string numer, string adres, List<Student> telefony)
{
this._imie = imie;
this._nazwisko = nazwisko;
this._numer = numer;
this._adres = adres;
this._telefony = telefony;
}
public string Imie
{
get
{
return _imie;
}
set
{
_imie = value;
}
}
public string Nazwisko
{
get
{
return _nazwisko;
}
set
{
_nazwisko = value;
}
}
public string Numer
{
get
{
return _numer;
}
set
{
_numer = value;
}
}
public string Adres
{
get
{
return _adres;
}
set
{
_adres = value;
}
}
public List<Student> Telefony
{
get
{
return _telefony;
}
set
{
_telefony = value;
}
}
public override string ToString()
{
return string.Format("{0}/{1}/{2}/{3}/{4}", _imie, _nazwisko, _numer, _adres, _telefony);
}
}
public class Adres
{
string _ulica;
string _kodPocztowy;
string _miasto;
public Adres()
{
}
public Adres(string ulica, string kodPocztowy, string miasto)
{
this._ulica = ulica;
this._kodPocztowy = kodPocztowy;
this._miasto = miasto;
}
public string Ulica
{
get
{
return _ulica;
}
set
{
_ulica = value;
}
}
public string KodPocztowy
{
get
{
return _kodPocztowy;
}
set
{
_kodPocztowy = value;
}
}
public string Miasto
{
get
{
return _miasto;
}
set
{
_miasto = value;
}
}
public override string ToString()
{
return string.Format("{0}/{1}/{2}", _ulica, _kodPocztowy, _miasto);
}
}
public class Telefon
{
string _numer;
string _operator;
public Telefon()
{
}
public Telefon(string numer, string oper)
{
this._numer = numer;
this._operator = oper;
}
public string Numer
{
get
{
return _numer;
}
set
{
_numer = value;
}
}
public string Operator
{
get
{
return _operator;
}
set
{
_operator = value;
}
}
public override string ToString()
{
return string.Format("{0}/{1}", _numer, _operator);
}
}
}
Przepraszam za sieczkę ale usiłuje aby wartości wprowadzone w textboxy na formie wpisały się w bazę BazaStudentów.yap i później ładnie wyświetliły mi się na DataGridzie.
Problem w tym, że muszę działać tak jakby na 3 odmiennych obiektach a chciałbym wyświetlić to wszystko w jednym wierszu na datagridzie.
Jak to jakoś fajnie oprogramować? Z góry dziękuję.