Пример #1
0
        /// <summary>
        /// Speichern.
        /// </summary>
        /// <param name="param">Der Parameter.</param>
        /// <returns>"LieferRhythmusOrgEinheitenEntityA"</returns>
        LieferRhythmusOrgEinheitenEntityA IServiceLieferRhythmusOrgEinheitenEntity.Speichern(LieferRhythmusOrgEinheitenEntityF param)
        {
            #region ------------------------------ Initialisierung ------------------------------

            LieferRhythmusOrgEinheitenEntityA ret = new LieferRhythmusOrgEinheitenEntityA();
            ret.HatFehler = true;

            // für ado.net
            SqlConnection sqlConnection = null;
            SqlCommand sqlCommand1 = null;
            SqlCommand sqlCommand2 = null;


            #endregion --------------------------- Initialisierung Ende -------------------------


            #region ------------------------------ Implementierung ------------------------------

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    // was ist mit ... new DebuggerWriter();  // writing to the debugger log window

                    Speichern_VorImpl(param);
                    sqlConnection = new SqlConnection(VerbindungsEinstellung.ConnectionString);
                    sqlConnection.Open();

                    // speichern des eigentlichen Satzes mit sp_Table_Update
                    sqlCommand1 = new SqlCommand("Controlling.sp_LieferRhythmusOrgEinheiten_UpdateCols", sqlConnection);
                    sqlCommand1.CommandTimeout = 300;
                    AddParameterDef4Update(sqlCommand1);
                    sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure;

                    for (int i = 0; i < param.LieferRhythmusOrgEinheitenEntity.Count; i++)
                    {
                        //if (param.LieferRhythmusOrgEinheitenEntity[i].Timestamp != null) // update nicht mehr über timestamp
                        //{
                        System.Collections.Generic.List<string> changedColumns = param.LieferRhythmusOrgEinheitenEntity[i].GetUpdatedColumns();

                        sqlCommand1.Parameters["@rowid"].Value = (Guid)param.LieferRhythmusOrgEinheitenEntity[i].Rowid;
                        sqlCommand1.Parameters["@timestamp"].Value = param.LieferRhythmusOrgEinheitenEntity[i].Timestamp;
                        sqlCommand1.Parameters["@mandant"].Value = (Guid)param.MandantenID;
                        sqlCommand1.Parameters["@geaendertvon"].Value = (string)param.UserName;
                        if (changedColumns.Contains("OrganisationsEinheit")) // && (param.LieferRhythmusOrgEinheitenEntity[i].OrganisationsEinheit != Guid.Empty))
                        {
                            sqlCommand1.Parameters["@organisationseinheit"].Value = (Guid)param.LieferRhythmusOrgEinheitenEntity[i].OrganisationsEinheit;
                        }
                        else
                        {
                            sqlCommand1.Parameters["@organisationseinheit"].Value = DBNull.Value;
                        }
                        if (changedColumns.Contains("LieferRhythmus")) // && (param.LieferRhythmusOrgEinheitenEntity[i].LieferRhythmus != Guid.Empty))
                        {
                            sqlCommand1.Parameters["@lieferrhythmus"].Value = (Guid)param.LieferRhythmusOrgEinheitenEntity[i].LieferRhythmus;
                        }
                        else
                        {
                            sqlCommand1.Parameters["@lieferrhythmus"].Value = DBNull.Value;
                        }

                        SqlDataReader sqlReader = sqlCommand1.ExecuteReader();

                        int timestampOid = sqlReader.GetOrdinal("timestamp");
                        int geaendertamOid = sqlReader.GetOrdinal("geaendertam");
                        int geaendertvonOid = sqlReader.GetOrdinal("geaendertvon");
                        int organisationseinheitOid = sqlReader.GetOrdinal("organisationseinheit");
                        int lieferrhythmusOid = sqlReader.GetOrdinal("lieferrhythmus");


                        if (sqlReader.Read())
                        {
                            LieferRhythmusOrgEinheitenEntityDM rs = new LieferRhythmusOrgEinheitenEntityDM();
                            rs.DisableUpdateMask = true;

                            rs.Rowid = param.LieferRhythmusOrgEinheitenEntity[i].Rowid;
                            if (!sqlReader.IsDBNull(timestampOid))
                            {
                                byte[] tbyte = new byte[sqlReader.GetBytes(timestampOid, 0, null, 0, int.MaxValue)]; // länge ermitteln
                                sqlReader.GetBytes(timestampOid, 0, tbyte, 0, int.MaxValue); // timestamp in buffer einlesen
                                rs.Timestamp = tbyte;
                            }
                            rs.Mandant = param.MandantenID;
                            rs.ErstelltVon = param.LieferRhythmusOrgEinheitenEntity[i].ErstelltVon;
                            rs.ErstelltAm = param.LieferRhythmusOrgEinheitenEntity[i].ErstelltAm;
                            rs.GeaendertVon = sqlReader.IsDBNull(geaendertvonOid) ? string.Empty : sqlReader.GetString(geaendertvonOid);
                            rs.GeaendertAm = sqlReader.IsDBNull(geaendertamOid) ? DateTime.MinValue : sqlReader.GetDateTime(geaendertamOid);
                            rs.OrganisationsEinheit = sqlReader.IsDBNull(organisationseinheitOid) ? Guid.Empty : sqlReader.GetGuid(organisationseinheitOid);
                            rs.LieferRhythmus = sqlReader.IsDBNull(lieferrhythmusOid) ? Guid.Empty : sqlReader.GetGuid(lieferrhythmusOid);

                            rs.DisableUpdateMask = false;
                            ret.LieferRhythmusOrgEinheitenEntity.Add(rs);
                        }
                        else
                        {
                            ret.FehlerText = "Der Datensatz konnte nicht gespeichert werden!";
                            ret.HatFehler = true;
                            return ret;
                        }

                        sqlReader.Close();
                        //}
                    }
                    Speichern_NachImpl(param, ret);
                    scope.Complete();
                }
                catch (SqlException ex)
                {
                    // logging des fehlers noch implementieren
                    ret = new LieferRhythmusOrgEinheitenEntityA();
                    ret.HatFehler = true;
                    ret.FehlerText = "Sql-Fehler: " + ex.Number.ToString() + " " + ex.Message;

                    return ret;
                }
                catch (Exception e)
                {
                    // logging des fehlers noch implementieren
                    ret = new LieferRhythmusOrgEinheitenEntityA();
                    ret.HatFehler = true;
                    ret.FehlerText = e.Message;
                    return ret;
                }
                finally
                {
                    if (sqlCommand1 != null)
                        sqlCommand1.Dispose();
                    if (sqlCommand2 != null)
                        sqlCommand2.Dispose();
                    if (sqlConnection != null)
                        sqlConnection.Close();
                }
            }

            #endregion --------------------------- Implementierung Ende -------------------------


            #region ------------------------------ Rueckgabe ------------------------------

            ret.HatFehler = false;
            return ret;

            #endregion --------------------------- Rueckgabe Ende -------------------------
        }
Пример #2
0
        /// <summary>
        /// Lesen.
        /// </summary>
        /// <param name="param">Der Parameter.</param>
        /// <returns>"LieferRhythmusOrgEinheitenEntityA"</returns>
        LieferRhythmusOrgEinheitenEntityA IServiceLieferRhythmusOrgEinheitenEntity.Lesen(LieferRhythmusOrgEinheitenEntityF param)
        {
            #region ------------------------------ Initialisierung ------------------------------

            LieferRhythmusOrgEinheitenEntityA ret = new LieferRhythmusOrgEinheitenEntityA();
            ret.HatFehler = true;
            PagingA paging = Paging.CheckPaging(param);

            // für ado.net
            SqlConnection sqlConnection = null;
            SqlCommand sqlCommand1 = null;
            SqlCommand sqlCommand2 = null;
            SqlDataReader sqlReader = null;

            StringBuilder strFilter = new StringBuilder();
            StringBuilder strSortierung = new StringBuilder();

            // queryfilter aufbereiten
            strFilter.Append(" LieferRhythmusOrgEinheiten.mandant='");
            strFilter.Append(param.MandantenID.ToString());
            strFilter.Append("' ");
            if ((Guid)param.Filter.Rowid != Guid.Empty)
            {
                strFilter.Append(" AND LieferRhythmusOrgEinheiten.rowid='");
                strFilter.Append(param.Filter.Rowid.ToString());
                strFilter.Append("' ");
            }
            if (param.Filter.ErstelltVon.ToString().Length > 0)
            {
                strFilter.Append(" AND lower(LieferRhythmusOrgEinheiten.ERSTELLTVON) LIKE '%");
                strFilter.Append(param.Filter.ErstelltVon.ToString().ToLower());
                strFilter.Append("%'");
            }
            if (param.Filter.ErstelltAm != DateTime.MinValue)
            {
                strFilter.Append(" AND CAST(FLOOR(CAST(LieferRhythmusOrgEinheiten.ERSTELLTAM AS float)) AS datetime)='");
                strFilter.Append(param.Filter.ErstelltAm.ToSqlDateFormat());
                strFilter.Append("'");
            }
            if (param.Filter.GeaendertVon.ToString().Length > 0)
            {
                strFilter.Append(" AND lower(LieferRhythmusOrgEinheiten.GEAENDERTVON) LIKE '%");
                strFilter.Append(param.Filter.GeaendertVon.ToString().ToLower());
                strFilter.Append("%'");
            }
            if (param.Filter.GeaendertAm != DateTime.MinValue)
            {
                strFilter.Append(" AND CAST(FLOOR(CAST(LieferRhythmusOrgEinheiten.GEAENDERTAM AS float)) AS datetime)='");
                strFilter.Append(param.Filter.GeaendertAm.ToSqlDateFormat());
                strFilter.Append("'");
            }
            if ((Guid)param.Filter.OrganisationsEinheit != Guid.Empty)
            {
                strFilter.Append(" AND LieferRhythmusOrgEinheiten.organisationseinheit='");
                strFilter.Append(param.Filter.OrganisationsEinheit.ToString());
                strFilter.Append("' ");
            }
            if ((Guid)param.Filter.LieferRhythmus != Guid.Empty)
            {
                strFilter.Append(" AND LieferRhythmusOrgEinheiten.lieferrhythmus='");
                strFilter.Append(param.Filter.LieferRhythmus.ToString());
                strFilter.Append("' ");
            }

            // erweiterte Sql Bedingung aus Basisobjekt
            if (!string.IsNullOrEmpty(param.ExtSqlRestriction))
            {
                strFilter.Append(" AND ");
                strFilter.Append(param.ExtSqlRestriction);
            }

            // sortierung

            #endregion --------------------------- Initialisierung Ende -------------------------


            #region ------------------------------ Implementierung ------------------------------

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    // was ist mit ... new DebuggerWriter();  // writing to the debugger log window

                    Lesen_VorImpl(param);
                    sqlConnection = new SqlConnection(VerbindungsEinstellung.ConnectionString);
                    sqlConnection.Open();

                    sqlCommand1 = new SqlCommand("sp_SelectRecords", sqlConnection);
                    sqlCommand1.CommandTimeout = 300;
                    sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure;
                    sqlCommand1.Parameters.AddWithValue("@tablename", "Controlling.LieferRhythmusOrgEinheiten");
                    sqlCommand1.Parameters.AddWithValue("@queryfilter", strFilter.ToString());
                    sqlCommand1.Parameters.AddWithValue("@sortfield", strSortierung.ToString());
                    sqlCommand1.Parameters.AddWithValue("@userid", param.UserId);
                    if (!string.IsNullOrEmpty(param.TableSortRefTable))
                        sqlCommand1.Parameters.AddWithValue("@tablesortreftable", param.TableSortRefTable.ToString());
                    if (!string.IsNullOrEmpty(param.TableSortColumn))
                        sqlCommand1.Parameters.AddWithValue("@tablesortcolumn", param.TableSortColumn.ToString());
                    //sqlCommand1.Parameters.AddWithValue("@pagesize", 500);
                    //sqlCommand1.Parameters.AddWithValue("@pageindex", 1);

                    sqlReader = sqlCommand1.ExecuteReader();
                    int rowidOid = sqlReader.GetOrdinal("rowid");
                    int mandantOid = sqlReader.GetOrdinal("mandant");
                    int timestampOid = sqlReader.GetOrdinal("timestamp");
                    int erstelltamOid = sqlReader.GetOrdinal("erstelltam");
                    int erstelltvonOid = sqlReader.GetOrdinal("erstelltvon");
                    int geaendertamOid = sqlReader.GetOrdinal("geaendertam");
                    int geaendertvonOid = sqlReader.GetOrdinal("geaendertvon");
                    int organisationseinheitOid = sqlReader.GetOrdinal("organisationseinheit");
                    int lieferrhythmusOid = sqlReader.GetOrdinal("lieferrhythmus");

                    while (sqlReader.Read())
                    {
                        LieferRhythmusOrgEinheitenEntityDM rs = new LieferRhythmusOrgEinheitenEntityDM();
                        rs.DisableUpdateMask = true;

                        rs.Rowid = sqlReader.IsDBNull(rowidOid) ? Guid.Empty : sqlReader.GetGuid(rowidOid);
                        if (!sqlReader.IsDBNull(timestampOid))
                        {
                            byte[] tbyte = new byte[sqlReader.GetBytes(timestampOid, 0, null, 0, int.MaxValue)]; // länge ermitteln
                            sqlReader.GetBytes(timestampOid, 0, tbyte, 0, int.MaxValue); // timestamp in buffer einlesen
                            rs.Timestamp = tbyte;
                        }
                        rs.Mandant = sqlReader.IsDBNull(mandantOid) ? Guid.Empty : sqlReader.GetGuid(mandantOid);
                        rs.ErstelltVon = sqlReader.IsDBNull(erstelltvonOid) ? string.Empty : sqlReader.GetString(erstelltvonOid);
                        rs.ErstelltAm = sqlReader.IsDBNull(erstelltamOid) ? DateTime.MinValue : sqlReader.GetDateTime(erstelltamOid);
                        rs.GeaendertVon = sqlReader.IsDBNull(geaendertvonOid) ? string.Empty : sqlReader.GetString(geaendertvonOid);
                        rs.GeaendertAm = sqlReader.IsDBNull(geaendertamOid) ? DateTime.MinValue : sqlReader.GetDateTime(geaendertamOid);
                        rs.OrganisationsEinheit = sqlReader.IsDBNull(organisationseinheitOid) ? Guid.Empty : sqlReader.GetGuid(organisationseinheitOid);
                        rs.LieferRhythmus = sqlReader.IsDBNull(lieferrhythmusOid) ? Guid.Empty : sqlReader.GetGuid(lieferrhythmusOid);

                        rs.DisableUpdateMask = false;
                        ret.LieferRhythmusOrgEinheitenEntity.Add(rs);
                    }
                    // sind dem benutzer alle orgeinheiten zugewiesen? 
                    if ((param.BenuterHatAlleMasterOrgEinheitenHolen) && (param.Filter.Rowid != Guid.Empty))
                    {
                        sqlCommand2 = new SqlCommand("sp_SelectHatAlleOrgEinheiten", sqlConnection);
                        sqlCommand2.CommandTimeout = 300;
                        sqlCommand2.CommandType = System.Data.CommandType.StoredProcedure;
                        sqlCommand2.Parameters.Add("@tablename", System.Data.SqlDbType.VarChar);
                        sqlCommand2.Parameters["@tablename"].DbType = System.Data.DbType.String;
                        sqlCommand2.Parameters["@tablename"].Direction = System.Data.ParameterDirection.Input;
                        sqlCommand2.Parameters["@tablename"].Value = "LieferRhythmusOrgEinheiten";
                        sqlCommand2.Parameters.Add("@rowid2query", System.Data.SqlDbType.UniqueIdentifier);
                        sqlCommand2.Parameters["@rowid2query"].DbType = System.Data.DbType.Guid;
                        sqlCommand2.Parameters["@rowid2query"].Direction = System.Data.ParameterDirection.Input;
                        sqlCommand2.Parameters["@rowid2query"].Value = (Guid)param.Filter.Rowid;
                        sqlCommand2.Parameters.Add("@userid", System.Data.SqlDbType.UniqueIdentifier);
                        sqlCommand2.Parameters["@userid"].DbType = System.Data.DbType.Guid;
                        sqlCommand2.Parameters["@userid"].Direction = System.Data.ParameterDirection.Input;
                        sqlCommand2.Parameters["@userid"].Value = (Guid)param.UserId;
                        sqlCommand2.Parameters.Add("@hatalleorgeinheiten", System.Data.SqlDbType.Bit);
                        sqlCommand2.Parameters["@hatalleorgeinheiten"].DbType = System.Data.DbType.Boolean;
                        sqlCommand2.Parameters["@hatalleorgeinheiten"].Direction = System.Data.ParameterDirection.InputOutput;
                        sqlCommand2.Parameters["@hatalleorgeinheiten"].Value = false;

                        sqlReader.Close();
                        sqlReader = sqlCommand2.ExecuteReader();
                        ret.BenutzerHatAlleMasterOrgEinheiten = (bool)sqlCommand2.Parameters["@hatalleorgeinheiten"].Value;
                    }
                    Lesen_NachImpl(param, ret);
                    scope.Complete();
                }
                catch (SqlException ex)
                {
                    // logging des fehlers noch implementieren
                    ret = new LieferRhythmusOrgEinheitenEntityA();
                    ret.HatFehler = true;
                    ret.FehlerText = "Sql-Fehler: " + ex.Number.ToString() + " " + ex.Message;

                    return ret;
                }
                catch (Exception e)
                {
                    // logging des fehlers noch implementieren
                    ret = new LieferRhythmusOrgEinheitenEntityA();
                    ret.HatFehler = true;
                    ret.FehlerText = e.Message;
                    return ret;
                }
                finally
                {
                    if (sqlReader != null)
                        sqlReader.Close();
                    if (sqlCommand1 != null)
                        sqlCommand1.Dispose();
                    if (sqlCommand2 != null)
                        sqlCommand2.Dispose();
                    if (sqlConnection != null)
                        sqlConnection.Close();
                }
            }

            #endregion --------------------------- Implementierung Ende -------------------------


            #region ------------------------------ Rueckgabe ------------------------------

            ret.HatFehler = false;
            return ret;

            #endregion --------------------------- Rueckgabe Ende -------------------------
        }
Пример #3
0
        /// <summary>
        /// Loeschen.
        /// </summary>
        /// <param name="param">Der Parameter.</param>
        /// <returns>"LieferRhythmusOrgEinheitenEntityA"</returns>
        LieferRhythmusOrgEinheitenEntityA IServiceLieferRhythmusOrgEinheitenEntity.Loeschen(LieferRhythmusOrgEinheitenEntityF param)
        {
            #region ------------------------------ Initialisierung ------------------------------

            LieferRhythmusOrgEinheitenEntityA ret = new LieferRhythmusOrgEinheitenEntityA();
            ret.HatFehler = true;

            // für ado.net
            SqlConnection sqlConnection = null;
            SqlCommand sqlCommand1 = null;
            SqlCommand sqlCommand2 = null;


            #endregion --------------------------- Initialisierung Ende -------------------------


            #region ------------------------------ Implementierung ------------------------------

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    // was ist mit ... new DebuggerWriter();  // writing to the debugger log window

                    Loeschen_VorImpl(param);
                    sqlConnection = new SqlConnection(VerbindungsEinstellung.ConnectionString);
                    sqlConnection.Open();

                    // löschen aller abhängigen datensätze mit sp_DeleteRelationships
                    sqlCommand1 = new SqlCommand("dbo.sp_DeleteRelationships", sqlConnection);
                    sqlCommand1.CommandTimeout = 300;
                    sqlCommand1.CommandType = System.Data.CommandType.StoredProcedure;
                    AddParameterDef4DeleteRelationships(sqlCommand1);

                    // löschen des eigentlichen Satzes mit sp_Table_Delete
                    sqlCommand2 = new SqlCommand("Controlling.sp_LieferRhythmusOrgEinheiten_Delete", sqlConnection);
                    sqlCommand2.CommandTimeout = 300;
                    sqlCommand2.CommandType = System.Data.CommandType.StoredProcedure;
                    AddParameterDef4Delete(sqlCommand2);

                    sqlCommand1.Parameters["@tablename"].Value = (string)"LieferRhythmusOrgEinheiten";
                    sqlCommand1.Parameters["@geaendertvon"].Value = param.UserName;
                    sqlCommand2.Parameters["@mandant"].Value = param.MandantenID;
                    sqlCommand2.Parameters["@geaendertvon"].Value = param.UserName;

                    for (int i = 0; i < param.LieferRhythmusOrgEinheitenEntity.Count; i++)
                    {
                        if (param.LieferRhythmusOrgEinheitenEntity[i].Timestamp != null)
                        {
                            sqlCommand1.Parameters["@uirowid"].Value = (Guid)param.LieferRhythmusOrgEinheitenEntity[i].Rowid;
                            sqlCommand1.ExecuteScalar();

                            int iReturnValue = (int)sqlCommand1.Parameters["@errorvalue"].Value;
                            if (iReturnValue == 1)
                            {
                                String sFKInfo = (string)sqlCommand1.Parameters["@fkdelinfo"].Value.ToString().Replace(",", "\n");
                                if (String.IsNullOrEmpty(sFKInfo))
                                    ret.FehlerText = "Es bestehen noch abhängige Daten.\nDer Datensatz kann nicht gelöscht werden!";
                                else
                                    ret.FehlerText = "Es bestehen noch abhängige Daten:\n" + sFKInfo + "\n\nDer Datensatz kann nicht gelöscht werden!";
                                ret.HatFehler = true;
                                return ret;
                            }

                            sqlCommand2.Parameters["@rowid"].Value = (Guid)param.LieferRhythmusOrgEinheitenEntity[i].Rowid;
                            sqlCommand2.Parameters["@timestamp"].Value = param.LieferRhythmusOrgEinheitenEntity[i].Timestamp;

                            iReturnValue = sqlCommand2.ExecuteNonQuery();
                            if (iReturnValue == 0)
                            {
                                ret.FehlerText = "Der Datensatz konnte nicht gelöscht werden!";
                                ret.HatFehler = true;
                                return ret;
                            }
                        }
                    }
                    Loeschen_NachImpl(param, ret);
                    scope.Complete();
                }
                catch (SqlException ex)
                {
                    // logging des fehlers noch implementieren
                    ret = new LieferRhythmusOrgEinheitenEntityA();
                    ret.HatFehler = true;
                    ret.FehlerText = "Sql-Fehler: " + ex.Number.ToString() + " " + ex.Message;

                    return ret;
                }
                catch (Exception e)
                {
                    // logging des fehlers noch implementieren
                    ret = new LieferRhythmusOrgEinheitenEntityA();
                    ret.HatFehler = true;
                    ret.FehlerText = e.Message;
                    return ret;
                }
                finally
                {
                    if (sqlCommand1 != null)
                        sqlCommand1.Dispose();
                    if (sqlCommand2 != null)
                        sqlCommand2.Dispose();
                    if (sqlConnection != null)
                        sqlConnection.Close();
                }
            }

            #endregion --------------------------- Implementierung Ende -------------------------


            #region ------------------------------ Rueckgabe ------------------------------

            ret.HatFehler = false;
            return ret;

            #endregion --------------------------- Rueckgabe Ende -------------------------
        }
Пример #4
0
 partial void Speichern_NachImpl(LieferRhythmusOrgEinheitenEntityF paramF, LieferRhythmusOrgEinheitenEntityA paramA);
Пример #5
0
 partial void Speichern_VorImpl(LieferRhythmusOrgEinheitenEntityF param);
Пример #6
0
 partial void Neu_VorImpl(LieferRhythmusOrgEinheitenEntityF paramF);
Пример #7
0
 partial void Loeschen_NachImpl(LieferRhythmusOrgEinheitenEntityF paramF, LieferRhythmusOrgEinheitenEntityA paramA);
Пример #8
0
 partial void Loeschen_VorImpl(LieferRhythmusOrgEinheitenEntityF param);