public List <Fertigware> GetFertigwaren() { var fertigwarenList = new List <Fertigware>(); try { OpenDB(); com = con.CreateCommand(); com.CommandText = "SELECT * FROM tbl_fertig;"; var reader = com.ExecuteReader(); while (reader.Read()) { var fertigware = new Fertigware( reader.GetInt32(0), !reader.IsDBNull(1) ? reader.GetString(1) : "", // Bezeichnung !reader.IsDBNull(2) ? reader.GetString(2) : "", // Bildpfad !reader.IsDBNull(3) ? reader.GetDouble(3) : 0.0 // Preis ); fertigwarenList.Add(fertigware); } } catch (Exception ex) { MessageBox.Show("GF: " + ex.Message); } finally { CloseDB(); } return(fertigwarenList); }
private void btn_fertigHinzufuegen_Click(object sender, EventArgs e) { double.TryParse(tbx_fertigPreis.Text, out double preis); var fertigware = new Fertigware(-1, tbx_fertigBezeichnung.Text, tbx_fertigBild.Text, preis); db.AddFertigware(fertigware); GetLists(); PopulateLbxFertigwaren(); }
private void btn_fertigAktualisieren_Click(object sender, EventArgs e) { if (lbx_fertigwaren.SelectedIndex > -1) { double.TryParse(tbx_fertigPreis.Text, out double preis); var fertigware = new Fertigware(Convert.ToInt32(tbx_fertigArtNr.Text), tbx_fertigBezeichnung.Text, tbx_fertigBild.Text, preis); db.UpdateFertigware(fertigware); GetLists(); PopulateLbxFertigwaren(); } }
public void UpdateFertigware(Fertigware fertigware) { try { OpenDB(); com = con.CreateCommand(); com.CommandText = String.Format(@"UPDATE tbl_fertig SET fertig_bezeichnung = '{0}', fertig_bild = '{1}', fertig_preis = {2} WHERE fertig_id = {3};", fertigware.Bezeichnung, fertigware.Bild.Replace("\\", "\\\\"), fertigware.Preis.ToString().Replace(',', '.'), fertigware.ArtNr.ToString()); com.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("UF: " + ex.Message); } finally { CloseDB(); } }
public void AddFertigware(Fertigware fertigware) { try { OpenDB(); com = con.CreateCommand(); com.CommandText = String.Format("INSERT INTO tbl_fertig VALUES (null, '{0}', '{1}', {2});", fertigware.Bezeichnung, fertigware.Bild.Replace("\\", "\\\\"), fertigware.Preis.ToString().Replace(',', '.')); com.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("AF: " + ex.Message); } finally { CloseDB(); } }