public void CreateEingangsrechnungTest() { RechnungsManager target = new RechnungsManager(); EingangsrechnungTable table = new EingangsrechnungTable(); table.Archivierungspfad = "path"; table.Bezeichnung = "test"; table.KontaktID = 1; table.Rechnungsdatum = string.Empty; // this should lead to exception target.CreateEingangsrechnung(table); }
// If NE tab visible, create Eingangsrechnung AND Buchungszeile. Otherwise, only create Buchungszeile to current Eingangsrechnung private void AddBuchungszeile(object sender, EventArgs e) { this.eingangsrechnungMsgLabel.Text = string.Empty; this.eingangsrechnungMsgLabel.Hide(); // in case of new Eingangsrechnung, the input fields are not locked if (!this.eingangsrechnungBezeichnungTextBox.ReadOnly == true) { this.logger.Log(Logger.Level.Info, "Beginning with new Eingangsrechnung"); // create new Eingangsrechnung this.eingangsrechnung = new EingangsrechnungTable(); // check Eingangsrechnungs input fields if (this.existingKontakteComboBox.SelectedIndex < 1) { this.eingangsrechnungMsgLabel.Text = "Keine KundenID gewählt!"; this.eingangsrechnungMsgLabel.ForeColor = Color.Red; this.eingangsrechnungMsgLabel.Show(); return; } // get KontaktID out of Combobox string kontaktID = this.existingKontakteComboBox.SelectedItem.ToString(); this.eingangsrechnung.KontaktID = -1; try { this.eingangsrechnung.KontaktID = GlobalActions.GetIdFromCombobox(kontaktID, this.eingangsrechnungMsgLabel); } catch (InvalidInputException) { logger.Log(Logger.Level.Error, "Unknown Exception while getting ID from Projekte from AngeboteTab!"); } // check for valid KontaktID IRule posint = new PositiveIntValidator(); DataBindingFramework.BindFromInt(this.eingangsrechnung.KontaktID.ToString(), "KontaktID", this.eingangsrechnungMsgLabel, false, posint); // check other vals eingangsrechnung.Rechnungsdatum = this.eingangsrechnungDatePicker.Value.ToShortDateString(); eingangsrechnung.Bezeichnung = this.eingangsrechnungBezeichnungTextBox.Text; // check date IRule dateval = new DateValidator(); DataBindingFramework.BindFromString(eingangsrechnung.Rechnungsdatum, "Datum", this.eingangsrechnungMsgLabel, false, dateval); // check description IRule lnhsv = new LettersNumbersHyphenSpaceValidator(); IRule slv = new StringLength150Validator(); DataBindingFramework.BindFromString(eingangsrechnung.Bezeichnung, "Bez. Eingangsrechnung", this.eingangsrechnungMsgLabel, false, lnhsv, slv); // add Archivierungspfad // Year/Month/Date/KontaktID/Bezeichnung eingangsrechnung.Archivierungspfad = DateTime.Now.Year.ToString() + '/' + DateTime.Now.Month.ToString() + '/' + DateTime.Now.ToShortDateString() + '-' + this.eingangsrechnung.KontaktID + '-' + this.eingangsrechnung.Bezeichnung; // check for errors if (this.eingangsrechnungMsgLabel.Visible) { return; } } // save Buchungszeile this.AddBuchungszeileToDataGridView(); // lock Eingangsrechnungs elements, if not already done if (!this.eingangsrechnungBezeichnungTextBox.ReadOnly == true) { this.existingKontakteComboBox.Enabled = false; this.eingangsrechnungDatePicker.Enabled = false; this.eingangsrechnungBezeichnungTextBox.ReadOnly = true; this.logger.Log(Logger.Level.Info, "Locked Eingangsrechnungs-elements"); } }
// Clear everything within Eingangsrechnungstab private void ResetEingangsrechnung(object sender, EventArgs e) { this.buchungszeilenBindingSource.Clear(); this.eingangsrechnung = null; this.existingKontakteComboBox.Enabled = true; this.eingangsrechnungDatePicker.Enabled = true; this.eingangsrechnungBezeichnungTextBox.ReadOnly = false; this.existingKontakteComboBox.ResetText(); this.eingangsrechnungDatePicker.ResetText(); this.eingangsrechnungBezeichnungTextBox.ResetText(); this.buchungszeileBezeichnungTextBox.ResetText(); this.eingangsrechnungBetragTextBox.ResetText(); this.kategorieComboBox.ResetText(); this.logger.Log(Logger.Level.Info, "Unocked Eingangsrechnungs-elements. Reset all Eingangsrechnungs-Inputfields."); }
/// <summary> /// Saves a new Eingangsrechnung to the sqlite database /// </summary> /// <param name="table">The business object</param> /// <returns>The id of the just inserted Eingangsrechnung</returns> public int CreateEingangsrechnung(EingangsrechnungTable table) { string sql = "INSERT INTO Eingangsrechnung (KontaktID, Bezeichnung, Rechnungsdatum, Archivierungspfad) VALUES (?, ?, ?, ?)"; int insertedID; // open connection and save new Kunde/Kontakt in database SQLiteConnection con = null; SQLiteTransaction tra = null; SQLiteCommand cmd = null; try { // initialise connection con = new SQLiteConnection(ConfigFileManager.ConnectionString); con.Open(); // initialise transaction tra = con.BeginTransaction(); cmd = new SQLiteCommand(sql, con); // initialise parameter SQLiteParameter p_firstparam = new SQLiteParameter(); SQLiteParameter p_secondparam = new SQLiteParameter(); SQLiteParameter p_thirdparam = new SQLiteParameter(); SQLiteParameter p_forthparam = new SQLiteParameter(); // bind kontaktID p_firstparam.Value = table.KontaktID; cmd.Parameters.Add(p_firstparam); // bind bezeichnung p_secondparam.Value = table.Bezeichnung; cmd.Parameters.Add(p_secondparam); // bind archivierungspfad p_thirdparam.Value = table.Rechnungsdatum; cmd.Parameters.Add(p_thirdparam); // bind rechnungsdatum p_forthparam.Value = table.Archivierungspfad; cmd.Parameters.Add(p_forthparam); // execute and commit cmd.ExecuteNonQuery(); tra.Commit(); // get rowID cmd.Parameters.Clear(); cmd.CommandText = "SELECT last_insert_rowid() AS id FROM Eingangsrechnung"; cmd.ExecuteNonQuery(); System.Object temp = cmd.ExecuteScalar(); insertedID = int.Parse(temp.ToString()); } catch(SQLiteException) { throw; } finally { if (tra != null) { tra.Dispose(); } if (cmd != null) { cmd.Dispose(); } if (con != null) { con.Dispose(); } } // success logging string successmessage = "A new Eingangsrechnung has been saved to the database: " + insertedID; this.logger.Log(Logger.Level.Info, successmessage); // return ID of inserted item return insertedID; }
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 Eingangsrechnung to the mock database /// </summary> /// <param name="table">The business object</param> /// <returns>The id of the just inserted Eingangsrechnung</returns> public int CreateEingangsrechnung(EingangsrechnungTable table) { table.ID = MockDataBaseManager.EingangsrechnungsID; MockDataBaseManager.savedEingangsrechnungen.Add(table); return table.ID; }