コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets requested Kontakte out of the database.
        /// </summary>
        /// <param name="k">The Kunde/Kontakt object that shall be searched for</param>
        /// <param name="errorlabel">A label in the homeform in which errormessages can be displayed</param>
        /// <returns>List of matching Kontakt</returns>
        public List<KundeKontaktTable> LoadKundenKontakte(KundeKontaktTable k, Label errorlabel)
        {
            IRule doubv = new PositiveDoubleValidator();
            IRule intv = new PositiveIntValidator();
            IRule datev = new DateValidator();
            IRule lengthv = new StringLength150Validator();
            IRule percv = new PercentValidator();
            IRule lnhsv = new LettersNumbersHyphenSpaceValidator();
            IRule lhv = new LettersHyphenValidator();

            DataBindingFramework.BindFromString(k.Vorname, "Vorname", errorlabel, true, lhv, lengthv);
            DataBindingFramework.BindFromString(k.NachnameFirmenname, "Nachname", errorlabel, true, lnhsv, lengthv);
            k.ID = -1; // indicates that we don't want to search for an ID

            // if validation failed
            if (doubv.HasErrors || intv.HasErrors || datev.HasErrors || lengthv.HasErrors || percv.HasErrors || lnhsv.HasErrors || lhv.HasErrors)
            {
                throw new InvalidInputException();
            }

            // load elements
            try
            {
                return DALFactory.GetDAL().GetKundenKontakte(k);
            }
            catch (SQLiteException)
            {
                throw;
            }
        }
コード例 #3
0
        public void SaveZeiterfassung(ZeitaufzeichnungTable z, Label label)
        {
            IRule pdv = new PositiveDoubleValidator();
            IRule piv = new PositiveIntValidator();
            IRule piv2 = new PositiveIntValidator();
            IRule sl150v = new StringLength150Validator();
            IRule lnhsv = new LettersNumbersHyphenSpaceValidator();

            piv.Eval(z.ProjektID);
            piv2.Eval(z.Stunden);
            sl150v.Eval(z.Bezeichnung);
            lnhsv.Eval(z.Bezeichnung);
            pdv.Eval(z.Stundensatz);

            if (piv.HasErrors || piv2.HasErrors || sl150v.HasErrors || lnhsv.HasErrors || pdv.HasErrors)
            {
                throw new InvalidInputException("Daten ungültig!");
            }

            // load elements
            try
            {
                DALFactory.GetDAL().SaveNewZeiterfassung(z);
            }
            catch (SQLiteException)
            {
                throw;
            }
        }
コード例 #4
0
        /// <summary>
        /// Saves a new Ausgangsrechnung within the database
        /// </summary>
        /// <param name="projektID">The connected ProjektID</param>
        /// <param name="unpaidBalance">The amount of money which the Ausgangsrechnung shall include</param>
        /// <param name="rechnungstitelString">The title of the Ausgangsrechnung</param>
        public void CreateAusgangsrechnung(int projektID, double unpaidBalance, string rechnungstitelString)
        {
            // create business objects for Ausgangsrechnung, Ausgangsbuchung & Buchungszeilen
            AusgangsrechnungTable rechnung = new AusgangsrechnungTable();
            AusgangsbuchungTable buchung = new AusgangsbuchungTable();
            BuchungszeilenTable zeile = new BuchungszeilenTable();

            // fill with values and validate
            rechnung.ProjektID = projektID;
            rechnung.Rechnungsdatum = DateTime.Now.ToShortDateString();
            rechnung.Bezeichnung = rechnungstitelString;

            zeile.BetragNetto = unpaidBalance;
            zeile.Bezeichnung = rechnungstitelString;
            zeile.Buchungsdatum = rechnung.Rechnungsdatum;

            // initialise Rule objects
            PositiveIntValidator piv = new PositiveIntValidator();
            PositiveDoubleValidator pdv = new PositiveDoubleValidator();
            LettersNumbersHyphenSpaceValidator lnhsv = new LettersNumbersHyphenSpaceValidator();
            StringLength150Validator slv = new StringLength150Validator();

            // evaluate ProjektID
            piv.Eval(rechnung.ProjektID);

            if (piv.HasErrors)
            { throw new InvalidInputException("ProjektID ungültig!"); }

            // evaluate Bezeichnung
            lnhsv.Eval(rechnung.Bezeichnung);
            slv.Eval(rechnung.Bezeichnung);

            if (lnhsv.HasErrors || slv.HasErrors)
            { throw new InvalidInputException("Bezeichnung ungültig!"); }

            // evaluate Betrag
            pdv.Eval(zeile.BetragNetto);

            if (pdv.HasErrors)
            { throw new InvalidInputException("Betrag ungültig"); }

            // SAVE Ausgangsrechnung, Buchungszeile and Ausgangsbuchung
            try
            {
                buchung.AusgangsrechnungsID = DALFactory.GetDAL().SaveAusgangsrechnung(rechnung);
                buchung.BuchungszeilenID = DALFactory.GetDAL().SaveBuchungszeile(zeile);

                // create Ausgangsbuchung with ID values which just returned from database
                DALFactory.GetDAL().SaveAusgangsbuchung(buchung);
            }
            catch (SQLiteException e)
            {
                this.logger.Log(Logger.Level.Info, "A database exception occured while saving a new Ausgangsrechnung, Buchungszeile or Ausgangsbuchung.");
                throw new DataBaseException(e.Message, e);
            }
        }
コード例 #5
0
        /// <summary>
        /// Get values of GUI elements and send them to the business layer, they shall be stored in the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateZeiterfassung(object sender, EventArgs e)
        {
            string projektID = null;

            // hide error label
            this.HideMsgLabels();

            ZeitaufzeichnungTable z = new ZeitaufzeichnungTable();

            //define rules
            IRule lnhsv = new LettersNumbersHyphenSpaceValidator();
            IRule pdv = new PositiveDoubleValidator();
            IRule piv = new PositiveIntValidator();
            IRule sl150v = new StringLength150Validator();

            projektID = this.zeiterfassungCombobox.SelectedItem.ToString();
            projektID = projektID.Substring(0, projektID.IndexOf(':'));

            //Bind data
            z.ProjektID = DataBindingFramework.BindFromInt(projektID, "ProjektID", this.zeiterfassungMsgLabel, false, piv);
            z.Stunden = DataBindingFramework.BindFromInt(zeiterfassungHoursTextbox.Text, "Dauer", this.zeiterfassungMsgLabel, false, piv);
            z.Bezeichnung = DataBindingFramework.BindFromString(zeiterfassungDescriptionTextBox.Text, "Bezeichnung", this.zeiterfassungMsgLabel, false, lnhsv, sl150v);
            z.Stundensatz = DataBindingFramework.BindFromInt(zeiterfassungStundensatzTextBox.Text, "Stundensatz", this.zeiterfassungMsgLabel, false, pdv);

            ZeiterfassungsManager saver = new ZeiterfassungsManager();

            // only if binding had no errors
            if (!this.zeiterfassungMsgLabel.Visible)
            {
                try
                {
                    saver.SaveZeiterfassung(z, this.zeiterfassungMsgLabel);
                }
                catch (SQLiteException)
                {
                    this.zeiterfassungMsgLabel.Text = "Aussagekräftiger Fehler";
                    this.zeiterfassungMsgLabel.Show();

                }
                catch (InvalidInputException ex)
                {
                    this.zeiterfassungMsgLabel.Text = ex.Message;
                    this.zeiterfassungMsgLabel.Show();
                }
                GlobalActions.ShowSuccessLabel(this.zeiterfassungMsgLabel);
                ResetZeiterfassung();

            }
        }
コード例 #6
0
        /// <summary>
        /// Deletes an existing Kunde/Kontakt
        /// </summary>
        /// <param name="k">The Kunde/Kontakt object that shall be deleted</param>
        /// <param name="label">The label in which errormessages can be shown</param>
        public void Delete(KundeKontaktTable k, Label label)
        {
            PositiveIntValidator checkkundenid = new PositiveIntValidator();
            checkkundenid.Eval(k.ID);

            if (checkkundenid.HasErrors)
            {
                this.logger.Log(Logger.Level.Error, "No valid ID provided from GUI layer!");
                throw new InvalidInputException("Es wurde keine gültige ID übergeben!");
            }

            this.logger.Log(Logger.Level.Info, "User requested to delete " + (k.Type == false ? "Kunde" : "Kontakt") + " with ID " + k.ID);

            try
            {
                DALFactory.GetDAL().DeleteKundeKontakt(k);
            }
            catch (SQLiteException)
            {
                throw;
            }
        }
コード例 #7
0
        public List<ZeitaufzeichnungTable> LoadZeiterfassung(ZeitaufzeichnungTable z, Label label)
        {
            IRule doubv = new PositiveDoubleValidator();
            IRule intv = new PositiveIntValidator();
            IRule datev = new DateValidator();
            IRule lengthv = new StringLength150Validator();
            IRule percv = new PercentValidator();
            IRule lnhsv = new LettersNumbersHyphenSpaceValidator();
            IRule lhv = new LettersHyphenValidator();

            // load elements
            try
            {
                //return DALFactory.GetDAL()
            }
            catch (SQLiteException)
            {
                throw;
            }

            return new List<ZeitaufzeichnungTable>();
        }
コード例 #8
0
        /// <summary>
        /// Gets values from the GUI, validates them and then sends them to the database to create a new Angebot
        /// </summary>
        public void Create(AngebotTable angebot, Label errorlabel)
        {
            IRule doubv = new PositiveDoubleValidator();
            IRule intv = new PositiveIntValidator();
            IRule datev = new DateValidator();
            IRule lengthv = new StringLength150Validator();
            IRule percv = new PercentValidator();
            IRule lnhsv = new LettersNumbersHyphenSpaceValidator();
            IRule lhv = new LettersHyphenValidator();

            DataBindingFramework.BindFromDouble(angebot.Angebotssumme.ToString(), "Angebotssumme", errorlabel, false, doubv);
            DataBindingFramework.BindFromInt(angebot.Umsetzungschance.ToString(), "Umsetzungschance", errorlabel, false, percv);
            DataBindingFramework.BindFromString(angebot.Angebotsdauer, "GültigBis", errorlabel, false, datev);
            DataBindingFramework.BindFromString(angebot.Beschreibung, "Beschreibung", errorlabel, false, lnhsv, lengthv);
            DataBindingFramework.BindFromInt(angebot.KundenID.ToString(), "kundenID", errorlabel, false, intv);
            DataBindingFramework.BindFromString(angebot.Erstellungsdatum, "Erstellungsdatum", errorlabel, false, datev);

            // change date formats
            angebot.Angebotsdauer = GlobalActions.ParseToSQLiteDateString(angebot.Angebotsdauer);

            if (errorlabel.Visible)
            {
                throw new InvalidInputException();
            }

            this.logger.Log(Logger.Level.Info, "A new Angebot will be created");

            // create Angebot
            try
            {
                DALFactory.GetDAL().CreateAngebot(angebot);
            }
            catch (SQLiteException)
            {
                throw;
            }
        }
コード例 #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static int GetIdFromCombobox(string data, Label messages)
        {
            int id;
            // if no Kunde has been chosen, set kundenID to -1, which indicates, that it shall not be searched for a certain Kunde
            if (data != string.Empty)
            {
                data = data.Substring(0, data.IndexOf(':'));

                IRule posintval = new PositiveIntValidator();
                id = DataBindingFramework.BindFromInt(data, "Kunden ID", messages, false, posintval);

                if (posintval.HasErrors)
                {
                    throw new InvalidInputException("Problem with getting KundenID. Unknown hard error.");
                }
            }
            else
            {
                id = -1;
            }
            return id;
        }
コード例 #10
0
        /// <summary>
        /// Reads values of concerning fields and asks business layer to create a new Angebot with the provided parameters
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The event params</param>
        private void CreateNewAngebot(object sender, EventArgs e)
        {
            // reset error/success labels
            this.createAngebotMsgLabel.Hide();
            this.createAngebotMsgLabel.Text = string.Empty;

            // existing or newly to-be-created
            bool createKunde = false;
            string kundenID = null;

            // Table for the Kontakt
            KundeKontaktTable k = new KundeKontaktTable();

            // new Kunde
            if (this.angebotErstellenSubTab.SelectedTab == this.angebotErstellenSubTab.TabPages[0])
            {
                createKunde = true;
            }
            // existing Kunde
            else
            {
                // no Kunde chosen or first element chosen (which is empty) -> show error label
                if (this.createAngebotExistingKundeComboBox.SelectedIndex <= 0)
                {
                    this.createAngebotMsgLabel.Text = "Error: kein Kunde ausgewählt";
                    this.createAngebotMsgLabel.ForeColor = Color.Red;
                    this.createAngebotMsgLabel.Show();
                    return; // skip rest of function
                }
                // Kunde chosen - get ID out of ComboBox
                else
                {
                    kundenID = this.createAngebotExistingKundeComboBox.SelectedItem.ToString();
                    kundenID = kundenID.Substring(0, kundenID.IndexOf(':'));

                    IRule posint = new PositiveIntValidator();
                    k.ID = DataBindingFramework.BindFromInt(kundenID, "KundenID", this.createAngebotMsgLabel, false, posint);

                    // Check for errors while databinding
                    if (posint.HasErrors)
                    {
                        this.logger.Log(Logger.Level.Error, k.ID + " is an invalid Kunden ID");
                        return;
                    }

                    // get Kunde table out of Database
                    KundenKontakteLoader loader = new KundenKontakteLoader();
                    List<KundeKontaktTable> results = loader.LoadKundenKontakte(k.ID, false);

                    // there must be exactly one result, for ID is unique!
                    if (results.Count != 1)
                    {
                        this.logger.Log(Logger.Level.Error, "More than one Kunde returned - impossible, because ID is unique!");
                        this.createAngebotMsgLabel.Text = "Error: Datenbank inkonsistent!";
                        this.createAngebotMsgLabel.Visible = true;
                        return; // skip rest of function
                    }

                    // everything went fine
                    k = results[0];
                }
            }

            // Create new Kunde, if requested
            if (createKunde)
            {
                // define Rules
                IRule lhv = new LettersHyphenValidator();
                IRule lnhsv = new LettersNumbersHyphenSpaceValidator();
                IRule slv = new StringLength150Validator();

                // validate data
                k.Vorname = DataBindingFramework.BindFromString(this.createAngebotNewKundeVnTextBox.Text, "Vorname", this.createAngebotMsgLabel, true, lhv, slv);
                k.NachnameFirmenname = DataBindingFramework.BindFromString(this.createAngebotNewKundeNnTextBox.Text, "Nachname", this.createAngebotMsgLabel, false, lnhsv, slv);
                k.Type = false; // Kunde

                if (lhv.HasErrors || lnhsv.HasErrors || slv.HasErrors)
                {
                    this.logger.Log(Logger.Level.Error, "Invalid signs within create Angebot / create Kunde");
                    return;
                }

                KundenKontakteSaver saver = new KundenKontakteSaver();

                try
                {
                    k.ID = saver.SaveNewKundeKontakt(k, this.createAngebotMsgLabel);
                }
                catch (InvalidInputException ex)
                {
                    this.logger.Log(Logger.Level.Error, ex.Message + ex.StackTrace);
                    this.createAngebotMsgLabel.Text = "Error: Kundenfelder ungültig!";
                    this.createAngebotMsgLabel.Visible = true;
                    return;
                }
                catch (SQLiteException ex)
                {
                    this.logger.Log(Logger.Level.Error, ex.Message + ex.StackTrace);
                    this.createAngebotMsgLabel.Text = "Error: Datenbankproblem!";
                    this.createAngebotMsgLabel.Visible = true;
                    return;
                }

                this.createAngebotMsgLabel.Text = "Kunde wurde gespeichert.";
            }

            // Create Angebot business object
            this.logger.Log(Logger.Level.Info, "Start creating new Angebot...");

            // define Rules
            IRule pdv2 = new PositiveDoubleValidator();
            IRule pcv2 = new PercentValidator();
            IRule dv2 = new DateValidator();
            IRule lnhsv2 = new LettersNumbersHyphenSpaceValidator();
            IRule slv2 = new StringLength150Validator();
            IRule piv2 = new PositiveIntValidator();

            AngebotTable angebot = new AngebotTable();
            angebot.Angebotssumme = DataBindingFramework.BindFromDouble(this.createAngebotAngebotssummeTextBox.Text, "Angebotssumme", this.createAngebotMsgLabel, false, pdv2);
            angebot.Umsetzungschance = DataBindingFramework.BindFromInt(this.createAngebotUmsetzungswahrscheinlichkeitTextBox.Text, "Umsetzungschance", this.createAngebotMsgLabel, false, pcv2);
            angebot.Angebotsdauer = DataBindingFramework.BindFromString(this.angebotValidUntilDateTimePicker.Value.ToShortDateString(), "GültigBis", this.createAngebotMsgLabel, false, dv2);
            angebot.Beschreibung = DataBindingFramework.BindFromString(this.createAngebotDescriptionTextBox.Text, "Beschreibung", this.createAngebotMsgLabel, false, lnhsv2, slv2);
            angebot.KundenID = DataBindingFramework.BindFromInt(k.ID.ToString(), "kundenID", this.createAngebotMsgLabel, false, piv2);
            angebot.Erstellungsdatum = DateTime.Now.ToShortDateString();

            // in case of errors in Databinding
            if (createAngebotMsgLabel.Visible)
            {
                this.logger.Log(Logger.Level.Error, "No angebot has been saved because of invalid inputs.");
                //createAngebotMsgLabel.ForeColor = Color.Red;
                //createAngebotMsgLabel.Show();
                return;
            }

            // send Angebot object to database
            try
            {
                AngebotManager manager = new AngebotManager();
                manager.Create(angebot, createAngebotMsgLabel);
            }
            catch (InvalidInputException ex)
            {
                this.logger.Log(Logger.Level.Error, ex.Message + ex.StackTrace);
                this.createAngebotMsgLabel.Text += "\nError: " + ex.Message;
                this.createAngebotMsgLabel.Show();
            }
            catch (SQLiteException ex)
            {
                this.logger.Log(Logger.Level.Error, ex.Message + ex.StackTrace);
                this.createAngebotMsgLabel.Text += "\nError: " + ex.Message;
                this.createAngebotMsgLabel.Show();
            }

            // show success message, if no error has been thrown
            if (!createAngebotMsgLabel.Visible)
            {
                this.createAngebotMsgLabel.Text += "\nAngebot wurde gespeichert.";
                this.createAngebotMsgLabel.ForeColor = Color.Green;
                this.createAngebotMsgLabel.Show();
            }
        }
コード例 #11
0
        /// <summary>
        /// Creates a new Projekt
        /// </summary>
        /// <param name="sender">The sending object</param>
        /// <param name="e">The event args</param>
        private void CreateProjekt(object sender, EventArgs e)
        {
            // hide label
            this.projektNeuMsgLabel.Text = string.Empty;
            this.projektNeuMsgLabel.Hide();

            // define Rules
            IRule lnhsv = new LettersNumbersHyphenSpaceValidator();
            IRule slv = new StringLength150Validator();

            ProjektTable projekt = new ProjektTable();

            // bind values
            projekt.Projektname = DataBindingFramework.BindFromString(this.projektNeuProjekttitelTextbox.Text, "Projekttitel", this.projektNeuMsgLabel, false, lnhsv, slv);

            if (lnhsv.HasErrors || slv.HasErrors)
            { this.projektNeuMsgLabel.Text = "Projektname ungültig!"; }

            // no Angebot chosen or first element chosen (which is empty) -> show error label
            if (this.projektErstellenAngebotCombobox.SelectedIndex <= 0)
            {
                this.projektNeuMsgLabel.Text += "\nKein Angebot ausgewählt";
                this.projektNeuMsgLabel.ForeColor = Color.Red;
                this.projektNeuMsgLabel.Show();
                return;
            }
            // Angebot chosen - get ID out of ComboBox
            else
            {
                string s_angebotID = this.projektErstellenAngebotCombobox.SelectedItem.ToString();
                s_angebotID = s_angebotID.Substring(0, s_angebotID.IndexOf(':'));

                IRule posint = new PositiveIntValidator();
                IRule datev = new DateValidator();

                projekt.AngebotID = DataBindingFramework.BindFromInt(s_angebotID, "AngebotID", this.projektNeuMsgLabel, false, posint);
                projekt.Projektstart = DataBindingFramework.BindFromString(this.projektNeuStartdatumDatepicker.Value.ToShortDateString(), "Startdatum", projektNeuMsgLabel, false, datev);

                // Check for errors while databinding
                if (this.projektNeuMsgLabel.Visible)
                {
                    this.logger.Log(Logger.Level.Error, projekt.AngebotID + " is an invalid Angebot ID or invalid date chosen or invalid project name.");
                    return;
                }

                // get Kunde table out of Database
                AngebotManager loader = new AngebotManager();
                List<AngebotTable> results = loader.Load(projekt.AngebotID, new DateTime(1900, 1, 1), new DateTime(2100, 1, 1), this.projektNeuMsgLabel, true);

                // there must be exactly one result, for ID is unique!
                if (results.Count != 1)
                {
                    this.logger.Log(Logger.Level.Error, "More than one Angebot returned - impossible, because ID is unique!");
                    this.projektNeuMsgLabel.Text = "Error: Datenbank inkonsistent!";
                    this.projektNeuMsgLabel.Visible = true;
                    return;
                }

                // everything went fine
                ProjektManager saver = new ProjektManager();

                try
                {
                    saver.Create(projekt);
                    //logger.Log(Logger.Level.Info, "uebergabe von projekttab: " + projekt.AngebotID+ " " + projekt.Projektstart);
                }
                catch (InvalidInputException ex)
                {
                    this.logger.Log(Logger.Level.Error, "Input was invalid, although checked." + ex.Message);
                }
                catch (DataBaseException ex)
                {
                    this.logger.Log(Logger.Level.Error, "Some serious problem with the database occured!" + ex.Message);
                }

                GlobalActions.ShowSuccessLabel(this.projektNeuMsgLabel);
            }
        }
コード例 #12
0
 public void ValidatePositiveIntTest1()
 {
     PositiveIntValidator val = new PositiveIntValidator();
     string input = "32";
     val.Eval(input);
     Assert.AreEqual(false, val.HasErrors);
 }
コード例 #13
0
        public void BindFromIntTest()
        {
            TextBox sender = new TextBox();
            sender.Text = "42";
            Label label = new Label();
            int expected = 42;
            int actual;

            IRule posval = new PositiveIntValidator();

            actual = DataBindingFramework.BindFromInt(sender.Text, "Integer", label, false, posval);
            Assert.AreEqual(expected, actual);
        }
コード例 #14
0
        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;
        }
コード例 #15
0
        /// <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;
            }
        }