public void EvalTest1() { DateValidator target = new DateValidator(); DateTime input = DateTime.Today; target.Eval(input); Assert.AreEqual(target.HasErrors, false); }
public void EvalTest2() { DateValidator target = new DateValidator(); int input = DateTime.Today.Year; target.Eval(input); Assert.AreEqual(target.HasErrors, true); }
public void EvalTest() { DateValidator target = new DateValidator(); string input = DateTime.Today.ToShortDateString(); target.Eval(input); Assert.AreEqual(target.HasErrors, false); }
/// <summary> /// Checks parameters provided by the GUI and loads existing Projekte according to the provided values /// </summary> /// <returns>A list of all fitting Projekte</returns> public List<ProjektTable> Load(int id, DateTime from, DateTime until, Label message) { PositiveIntOrMinusOneValidator pimv = new PositiveIntOrMinusOneValidator(); DateValidator dvf = new DateValidator(); DateValidator dvu = new DateValidator(); string dateFrom = from.ToShortDateString(); string dateUntil = until.ToShortDateString(); pimv.Eval(id); dvf.Eval(dateFrom); dvu.Eval(dateUntil); if (pimv.HasErrors || dvf.HasErrors || dvu.HasErrors) { throw new InvalidInputException(); } // parse to date strings dateFrom = GlobalActions.ParseToSQLiteDateString(dateFrom); dateUntil = GlobalActions.ParseToSQLiteDateString(dateUntil); try { return DALFactory.GetDAL().LoadProjekte(dateFrom, dateUntil, id); } catch (SQLiteException) { throw; } }
/// <summary> /// Checks parameters provided by the GUI and delegates values to database which saves them. /// </summary> public void Create(ProjektTable pj) { // check data once again IRule lnhsv = new LettersNumbersHyphenSpaceValidator(); IRule posintv = new PositiveIntValidator(); IRule slv = new StringLength150Validator(); IRule dv = new DateValidator(); // call eval methods lnhsv.Eval(pj.Projektname); slv.Eval(pj.Projektname); posintv.Eval(pj.AngebotID); dv.Eval(pj.Projektstart); // check for errors if (lnhsv.HasErrors || slv.HasErrors || posintv.HasErrors || dv.HasErrors) { throw new InvalidInputException("Invalid values provided by GUI"); } // reformat data string pj.Projektstart = GlobalActions.ParseToSQLiteDateString(pj.Projektstart); // send values to database try { DALFactory.GetDAL().CreateProjekt(pj); } catch (SQLiteException ex) { this.logger.Log(Logger.Level.Error, ex.Message + ex.StackTrace); throw new DataBaseException(ex.Message); } }
public void EvalTest4() { DateValidator target = new DateValidator(); string date = "30.12.2011"; target.Eval(date); Assert.AreEqual(target.HasErrors, false); }
public void EvalTest3() { DateValidator target = new DateValidator(); DateTime date = new DateTime(2012, 2, 3); target.Eval(date); Assert.AreEqual(target.HasErrors, false); }
public int CreateEingangsrechnung(EingangsrechnungTable table) { LettersNumbersHyphenSpaceValidator lnhsv = new LettersNumbersHyphenSpaceValidator(); LettersNumbersHyphenSpaceValidator lnhsv2 = new LettersNumbersHyphenSpaceValidator(); StringLength150Validator slv = new StringLength150Validator(); StringLength150Validator slv2 = new StringLength150Validator(); PositiveIntValidator piv = new PositiveIntValidator(); DateValidator dv = new DateValidator(); lnhsv.Eval(table.Archivierungspfad); slv.Eval(table.Archivierungspfad); piv.Eval(table.KontaktID); dv.Eval(table.Rechnungsdatum); lnhsv2.Eval(table.Bezeichnung); slv2.Eval(table.Bezeichnung); if (lnhsv.HasErrors || lnhsv2.HasErrors || slv.HasErrors || slv2.HasErrors || piv.HasErrors || dv.HasErrors) { throw new InvalidInputException("Daten ungültig!"); } // if data is valid, pass table to DAL int returnedID; try { returnedID = DALFactory.GetDAL().CreateEingangsrechnung(table); } catch (SQLiteException) { throw; } return returnedID; }
/// <summary> /// Saves a new Buchungszeile to the Database /// </summary> /// <param name="table">The Buchungszeilentable</param> /// <param name="eingangsrechnungsID">The ID of the Eingangsrechnung</param> public void SaveBuchungszeile(BuchungszeilenTable table, int eingangsrechnungsID) { table.BetragUST = table.BetragNetto; // we don't use UST // check EingangsrechnungsID IRule piv = new PositiveIntValidator(); piv.Eval(eingangsrechnungsID); // check description IRule lnhsv = new LettersNumbersHyphenSpaceValidator(); IRule slv = new StringLength150Validator(); lnhsv.Eval(table.Bezeichnung); slv.Eval(table.Bezeichnung); // check Betrag IRule pdv = new PositiveDoubleValidator(); pdv.Eval(table.BetragNetto); // check date IRule dateval = new DateValidator(); dateval.Eval(table.Buchungsdatum); // check KategorieID for positive int IRule piv2 = new PositiveIntValidator(); piv2.Eval(table.KategorieID); if (piv.HasErrors || lnhsv.HasErrors || slv.HasErrors || pdv.HasErrors || dateval.HasErrors || piv2.HasErrors) { throw new InvalidInputException("Daten ungültig"); } // save Buchungszeile int bzID = -1; try { bzID = DALFactory.GetDAL().SaveBuchungszeile(table); } catch (SQLiteException) { throw; } // save Eingangsbuchung EingangsbuchungTable eingangsbuchung = new EingangsbuchungTable(); eingangsbuchung.BuchungszeilenID = bzID; eingangsbuchung.EingangsrechungsID = eingangsrechnungsID; try { DALFactory.GetDAL().SaveEingangsbuchung(eingangsbuchung); } catch (SQLiteException) { throw; } }