public List <KFZ> GetAllKFZ() { MySqlConnection myConnection = new MySqlConnection( "SERVER=localhost;DATABASE=kfzapp;UID=u_kfzapp;PASSWORD=u_kfzapp;"); myConnection.Open(); List <KFZ> allKFZ = new List <KFZ>(); string sqlSELECT = "SELECT * FROM kfz;"; MySqlCommand myCommand = new MySqlCommand(sqlSELECT); myCommand.Connection = myConnection; MySqlDataReader reader = myCommand.ExecuteReader(); while (reader.Read()) { KFZ newKFZ = new KFZ(); newKFZ.KFZid = Convert.ToInt32(reader["idkfz"]); //usw.... allKFZ.Add(newKFZ); } myConnection.Close(); return(allKFZ); }
public override void Save(IEntity entity) { KFZ obj = (KFZ)entity; string query = string.Format("INSERT INTO {0} VALUES(0, \"{1}\", \"{2}\", {3}, \"{4}\")", TableName, obj.FahrgestellNR, obj.Kennzeichen, obj.Leistung, obj.Typ); _Connection.GetAdapter().Adapter.ExecuteSQL(query); }
public DA_KFZ(KFZ kfz) : base() { this.Id = kfz.Id; this.FahrgestNr = kfz.FahrgestNr; this.Kennzeichen = kfz.Kennzeichen; this.Leistung = kfz.Leistung; this.Typ = kfz.Typ; }
private void _kfzm_KFZChanged(KFZ kfz) { Application.Current.Dispatcher.Invoke(() => { throw new NotImplementedException(); }, System.Windows.Threading.DispatcherPriority.Normal); }
public KFZDisplay(KFZ kfz) //Kaffee für Herrn Gentner { this.FahrgestNr = kfz.FahrgestNr; this.Id = kfz.Id; this.Kennzeichen = kfz.Kennzeichen; this.Leistung = kfz.Leistung; this.Typ = kfz.Typ; }
public override void Update(IEntity entity) { KFZ obj = (KFZ)entity; string query = string.Format("UPDATE {0} SET FahrgestellNR = \"{1}\", Kennzeichen = \"{2}\", Leistung = {3}, Typ = \"{4}\" WHERE {5} = {6}", TableName, obj.FahrgestellNR, obj.Kennzeichen, obj.Leistung, obj.Typ, IDColumnName, obj.ID); _Connection.GetAdapter().Adapter.ExecuteSQL(query); }
public bool Equals(KFZ other) { return(ID == other.ID && Typ == other.Typ && FahrgestellNR == other.FahrgestellNR && Kennzeichen == other.Kennzeichen && Leistung == other.Leistung); }
public void Delete(KFZ kfz) { //1. KFZ abmelden bei Zulassungsstelle //2. Fahrzeughalter benachrichtigen, dass KFZ abgemeldet wurde. //3. auf Bestätigung des Halters warten //4. usw. Connection.DeleteKFZ(kfz); }
public KFZDisplay(KFZ kfz) { this.FahrgestNr = kfz.FahrgestNr; this.Id = kfz.Id; this.Kennzeichen = kfz.Kennzeichen; this.Leistung = kfz.Leistung; this.Typ = kfz.Typ; }
//TODO: Einfügen eines KFZ in die Datenbank public static void InsertKFZ(KFZ kfz) { //DA_KFZ dakfz = new DA_KFZ(kfz); //dakfz.Insert(); string sqlInsertStatement = $@"INSERT INTO `kfz` (`idkfz`, `FahrgestellNr`, `Kennzeichen`, `Leistung`, `Typ`) VALUES (NULL, '{kfz.FahrgestNr}', '{kfz.Kennzeichen}', '{kfz.Leistung}', '{kfz.Typ}');"; Connection.Adapter.Adapter.Insert(sqlInsertStatement); }
private void _kfzm_KFZNew(KFZ kfz) //Aufruf durch "blauen" Workerthread. { Application.Current.Dispatcher.Invoke(() => { KFZDisplay kfzd = new KFZDisplay(kfz); KFZObservableCollection.Add(kfzd); }, System.Windows.Threading.DispatcherPriority.Normal); }
public void Insert(KFZ kfz) { //Überprüfen, ob das neue Kfz korrekte Werte besitzt. if (kfz.Id == -1 && kfz.FahrgestNr != string.Empty && kfz.Kennzeichen != string.Empty && kfz.Leistung > 0 && kfz.Typ != string.Empty) { Connection.InsertKFZ(kfz); } }
protected override void LoadObjects(out List <IEntity> result) { result = new List <IEntity>(); string query = string.Format("SELECT * FROM {0}", TableName); DataTable table = _Connection.GetAdapter().Adapter.GetDataTable(query); for (int i = 0; i < table.Rows.Count; ++i) { KFZ kfz = new KFZ(); kfz.ID = (int)table.Rows[i].ItemArray[0]; kfz.FahrgestellNR = table.Rows[i].ItemArray[1].ToString(); kfz.Kennzeichen = table.Rows[i].ItemArray[2].ToString(); kfz.Leistung = (int)table.Rows[i].ItemArray[3]; kfz.Typ = table.Rows[i].ItemArray[4].ToString(); result.Add(kfz); } }
public void SaveKFZDetails(KFZ k) { MySqlConnection myConnection = new MySqlConnection("SERVER=localhost;DATABASE=kfzapp;UID=u_kfzapp;PASSWORD=u_kfzapp;"); myConnection.Open(); //UPDATE-Statement string sqlUpdateStatement = $"UPDATE kfz SET FahrgestellNr='{k.FahrgestellNr}'," + $" Kennzeichen='{k.Kennzeichen}', Leistung='{k.Leistung}'," + $" Typ='{k.Typ}' WHERE idkfz='{k.KFZid}';"; //Connection und SQL-Statement zusammenführen. MySqlCommand myCommand = new MySqlCommand(sqlUpdateStatement); myCommand.Connection = myConnection; //SQL-Statement an DB senden. myCommand.ExecuteNonQuery(); //Ressourcen wieder freigeben. myConnection.Close(); }
//"CRUD" - "C"reate, "R"ead, "U"pdate, "D"elete - Szenario public void SaveKFZ(KFZ kfz) { MessageBox.Show($"Jetzt wird KFZ {kfz.Kennzeichen} gespeichert."); //In Azure-DB speichern INSERT-Statement MySqlConnection myConnection = new MySqlConnection("SERVER=localhost;DATABASE=kfzapp;UID=u_kfzapp;PASSWORD=u_kfzapp;"); myConnection.Open(); //INSERT-Statement zusammenbauen. string insertSQL = $"INSERT INTO `kfz`(`FahrgestellNr`, `Kennzeichen`, `Leistung`, `Typ`)" + $" VALUES ('{kfz.FahrgestellNr}','{kfz.Kennzeichen}',{kfz.Leistung},'{kfz.Typ}');"; //Connection und SQL-Statement zusammenführen. MySqlCommand myCommand = new MySqlCommand(insertSQL); myCommand.Connection = myConnection; //SQL-Statement an DB senden. myCommand.ExecuteNonQuery(); //Ressourcen wieder freigeben. myConnection.Close(); }
//TODO: Löschen eines KFZ in der Datenbank public static void DeleteKFZ(KFZ kfz) { string sqlDeleteStatement = $@"DELETE FROM kfz WHERE idkfz = {kfz.Id}"; Connection.Adapter.Adapter.ExecuteSQL(sqlDeleteStatement); }
private void _kfzm_KFZChanged(KFZ kfz) { throw new NotImplementedException(); }
//TODO: Ändern eines KFZ in der Datenbank public static void UpdateKFZ(KFZ kfz) { string sqlUpdateStatement = $@"UPDATE kfz SET FahrgestellNr='{kfz.FahrgestNr}', Kennzeichen='{kfz.Kennzeichen}', Leistung='{kfz.Leistung}', Typ='{kfz.Typ}' WHERE idkfz='{kfz.Id}';"; Connection.Adapter.Adapter.ExecuteSQL(sqlUpdateStatement); }
public bool Validate(IEntity entity) { KFZ casted = (KFZ)entity; return(!string.IsNullOrEmpty(casted.Kennzeichen) && !string.IsNullOrEmpty(casted.FahrgestellNR) && !string.IsNullOrEmpty(casted.Typ) && casted.Leistung > 0); }
public void Update(KFZ kfz) { Connection.UpdateKFZ(kfz); }
public static void InsertKFZ(KFZ kfz) { DA_KFZ k = new DA_KFZ(kfz); k.Insert(); }
public KFZViewModel(KFZ entity) { _Entity = entity; }
public void DeleteKFZ(KFZ k) { //k.KFZid }