/// <summary> /// Gibt eine Liste aller Seminarbuchungen zu einer BelegPosition anhand der VorPosID zurück /// </summary> /// <param name="mandant"></param> /// <param name="vorPosID"></param> /// <returns></returns> public static Seminarbuchungen GetSeminarbuchungen(Mandant mandant, int vorPosID) { try { var list = new Seminarbuchungen(); var qry = "SELECT BuchungID FROM PSDSeminarbuchungen WHERE Mandant=@mandant AND VorPosID=@vorposid"; var command = mandant.MainDevice.GenericConnection.CreateSqlStringCommand(qry); command.AppendInParameter("mandant", typeof(short), mandant.Id); command.AppendInParameter("vorposid", typeof(int), vorPosID); using (var reader = command.ExecuteReader()) { while (reader.Read()) { list.Add(SeminarData.GetSeminarbuchung(mandant, reader.GetInt32("BuchungID"))); } } return(list); } catch (Exception ex) { TraceLog.LogException(ex); throw; } }
/// <summary> /// Aktualisiert oder legt eine neue Seminarbuchung an /// </summary> /// <param name="mandant"></param> /// <param name="buchung"></param> /// <returns></returns> /// <exception cref="Exception">wird bei allgemeinen Fehler geworfen.</exception> /// <exception cref="RecordUpdateException">wird bei Fehlern im DB-Update geworfen.</exception> public static Seminarbuchung UpdateOrInsertSeminarbuchung(Mandant mandant, Seminarbuchung buchung) { var qry = new StringBuilder(); if (buchung.BuchungID == 0) { // Neuanlage buchung.BuchungID = mandant.MainDevice.GetTan("PSDSeminarbuchungen", mandant.Id); buchung.Mandant = buchung.Mandant == 0 ? mandant.Id : buchung.Mandant; qry.AppendLine("INSERT INTO PSDSeminarbuchungen "); qry.AppendLine("(BuchungID, Mandant, SeminarterminID, BelID, BelPosID, VorPosID, Adresse, "); qry.AppendLine("Konto, KontoMatchcode, Ansprechpartnernummer, AnsprechpartnerVorname, "); qry.AppendLine("AnsprechpartnerNachname, AnsprechpartnerEmail, EmailBestaetigungGesendet)"); qry.AppendLine("VALUES"); qry.AppendLine("(@buchungid, @mandant, @seminarterminid, @belid, @belposid, @vorposid, @adresse, "); qry.AppendLine("@konto, @kontomatchcode, @ansprechpartnernummer, @ansprechpartnervorname, "); qry.AppendLine("@ansprechpartnernachname, @ansprechpartneremail, @emailbestaetigunggesendet)"); } else { // Aktualisierung qry.AppendLine("UPDATE PSDSeminarbuchungen SET "); qry.AppendLine("SeminarterminID=@seminarterminid, BelID=@belid, BelPosID=@belposid, VorPosID=@vorposid, "); qry.AppendLine("Adresse=@adresse, Konto=@konto, KontoMatchcode=@kontomatchcode, Ansprechpartnernummer=@ansprechpartnernummer, AnsprechpartnerVorname=@ansprechpartnervorname, "); qry.AppendLine("AnsprechpartnerNachname=@ansprechpartnernachname, AnsprechpartnerEmail=@ansprechpartneremail, EmailbestaetigungGesendet=@emailbestaetigunggesendet "); qry.AppendLine("WHERE Mandant=@mandant AND BuchungID=@buchungID"); } var command = mandant.MainDevice.GenericConnection.CreateSqlStringCommand(qry.ToString()); command.AppendInParameter("buchungid", typeof(int), buchung.BuchungID); command.AppendInParameter("mandant", typeof(short), buchung.Mandant); command.AppendInParameter("seminarterminid", typeof(string), buchung.SeminarterminID); command.AppendInParameter("belid", typeof(int), buchung.BelID); command.AppendInParameter("belposid", typeof(int), buchung.BelPosID); command.AppendInParameter("vorposid", typeof(int), buchung.VorPosID); command.AppendInParameter("adresse", typeof(int), buchung.Adresse); command.AppendInParameter("konto", typeof(string), buchung.Konto); command.AppendInParameter("kontomatchcode", typeof(string), buchung.KontoMatchcode); command.AppendInParameter("ansprechpartnernummer", typeof(int), buchung.Ansprechpartnernummer); command.AppendInParameter("ansprechpartnervorname", typeof(string), buchung.AnsprechpartnerVorname); command.AppendInParameter("ansprechpartnernachname", typeof(string), buchung.AnsprechpartnerNachname); command.AppendInParameter("ansprechpartneremail", typeof(string), buchung.AnsprechpartnerEmail); command.AppendInParameter("emailbestaetigunggesendet", typeof(short), ConversionHelper.ToDBBoolean(buchung.EmailBestaetigungGesendet)); var result = command.TryExecuteNonQuery(); if (result.State.IsSucceeded) { buchung = SeminarData.GetSeminarbuchung(mandant, buchung.BuchungID); return(buchung); } else { TraceLog.LogException(result.State.ExceptionOccurred); throw new RecordUpdateException("Seminarbuchung", buchung.BuchungID.ToString()); } }