public void TestAddBuchungMin() { Buchung b = new Buchung(4,23.33,1,DateTime.Now,1,ObjectStates.New); BL.saveBuchung(b); Assert.That(BL.getBuchungen(1).Last().Betrag, Is.EqualTo(23.33)); Assert.That(BL.getBuchungen(1).Last().Kategorie, Is.EqualTo(1)); BL.deleteBuchung(b); }
public void TestDeleteBuchung() { Buchung b = new Buchung(); int oldlength = BL.getBuchungen().Count(); b = BL.getBuchungen().Last(); BL.deleteBuchung(b); Assert.That(BL.getBuchungen().Count, Is.EqualTo(oldlength - 1)); Assert.That(BL.getBuchungen().Last(), Is.Not.EqualTo(b)); }
public void TestAddBuchung() { Buchung b = new Buchung(); int oldlength = BL.getBuchungen().Count(); b.Betrag = 656; b.Datum = DateTime.Parse("2012-4-4"); b.Kategorie = 1; b.Rechnungid = 3; b.Status = ObjectStates.New; BL.saveBuchung(b); Assert.That(BL.getBuchungen().Count, Is.EqualTo(oldlength + 1)); Assert.That(BL.getBuchungen().ElementAt(oldlength).Betrag, Is.EqualTo(656)); Assert.That(BL.getBuchungen().ElementAt(oldlength).Datum, Is.EqualTo(DateTime.Parse("2012-4-4"))); Assert.That(BL.getBuchungen().ElementAt(oldlength).Kategorie, Is.EqualTo(1)); Assert.That(BL.getBuchungen().ElementAt(oldlength).Rechnungid, Is.EqualTo(3)); Assert.That(BL.getBuchungen().ElementAt(oldlength).Status, Is.EqualTo(ObjectStates.Unmodified)); }
public void saveBuchung(Buchung b) { if (b.Status == ObjectStates.New) { b.Status = ObjectStates.Unmodified; b.Buchungid = buchungen.Count + 1; buchungen.Add(b); } else if (b.Status == ObjectStates.Modified) { int index = buchungen.IndexOf(b); buchungen[index].Buchungid = b.Buchungid; buchungen[index].Betrag = b.Betrag; buchungen[index].Datum = b.Datum; buchungen[index].Kategorie = b.Kategorie; buchungen[index].Rechnungid = b.Rechnungid; buchungen[index].Status = ObjectStates.Unmodified; } }
public void deleteBuchung(Buchung b) { buchungen.Remove(b); }
public static void saveBuchung(Buchung b) { DALFactory.getDAL().saveBuchung(b); }
public static void deleteBuchung(Buchung b) { DALFactory.getDAL().deleteBuchung(b); }
public List<Buchung> getBuchungViewList() { buildconnection(); List<Buchung> blist = new List<Buchung>(); NpgsqlCommand comm = null; NpgsqlDataReader reader = null; try { string sql = @"Select b.buchungid, b.betrag, b.katid, b.datum, rb.rechnungid from buchungen b, rechnungen_buchungen rb where b.buchungid = rb.buchungid;"; comm = new NpgsqlCommand(sql, conn); reader = comm.ExecuteReader(); while (reader.Read()) { Buchung b = new Buchung(); b.Buchungid = reader.GetInt32(0); b.Betrag = reader.GetDouble(1); b.Kategorie = reader.GetInt32(2); b.Datum = reader.GetDateTime(3); b.Rechnungid = reader.GetInt32(4); blist.Add(b); } } catch (NpgsqlException exp) { throw new DALException("DAL: Buchungsliste konnte nicht aus der Datenbank geladen werden!", exp); } finally { reader.Close(); comm.Dispose(); conn.Close(); } return blist; }
public void saveBuchung(Buchung b) { buildconnection(); NpgsqlCommand commbuch = null, commrechbuch = null; try { string sqlbuch="", sqlrechbuch = ""; if (b.Status == ObjectStates.New) { sqlbuch = @"Insert into buchungen (betrag,katid, datum) values (@betrag, @katid, @datum)"; sqlrechbuch = @"Insert into rechnungen_buchungen (rechnungid, buchungid) values (@rechnungid, currval('buchungen_buchungid_seq'))"; commbuch = new NpgsqlCommand(sqlbuch, conn); commrechbuch = new NpgsqlCommand(sqlrechbuch, conn); } else if (b.Status == ObjectStates.Modified) { sqlbuch = @"Update buchungen set betrag = @betrag, katid = @katid, datum = @datum where buchungid = @buchungid"; sqlrechbuch = @"Update rechnungen_buchungen set rechnungid = @rechnungid where buchungid = @buchungid"; commbuch = new NpgsqlCommand(sqlbuch, conn); commrechbuch = new NpgsqlCommand(sqlrechbuch, conn); commbuch.Parameters.AddWithValue("@buchungid", b.Buchungid); commrechbuch.Parameters.AddWithValue("@buchungid", b.Buchungid); } commbuch.Parameters.AddWithValue("@betrag", b.Betrag); commbuch.Parameters.AddWithValue("@katid", b.Kategorie); commbuch.Parameters.AddWithValue("@datum", b.Datum); commbuch.Prepare(); commbuch.ExecuteNonQuery(); commrechbuch.Parameters.AddWithValue("@rechnungid", b.Rechnungid); commrechbuch.Prepare(); commrechbuch.ExecuteNonQuery(); b.Status = ObjectStates.Unmodified; } catch (NpgsqlException exp) { throw new DALException("DAL: Buchung konnte nicht gespeichert werden!", exp); } finally { commbuch.Dispose(); commrechbuch.Dispose(); conn.Close(); } }
public void deleteBuchung(Buchung b) { buildconnection(); NpgsqlCommand comm = null; try { string sql = "Delete from rechnungen_buchungen where buchungid = @buchungid"; comm = new NpgsqlCommand(sql, conn); comm.Parameters.AddWithValue("@buchungid", b.Buchungid); comm.Prepare(); comm.ExecuteNonQuery(); sql = "Delete from buchungen where buchungid = @buchungid"; comm = new NpgsqlCommand(sql, conn); comm.Parameters.AddWithValue("@buchungid", b.Buchungid); comm.Prepare(); comm.ExecuteNonQuery(); b.Status = ObjectStates.Deleted; } catch (NpgsqlException exp) { throw new DALException("DAL: Buchung konnte nicht gelöscht werden!", exp); } finally { comm.Dispose(); conn.Close(); } }