Пример #1
0
        /// <summary>
        /// Updates reverse cross ref required step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data</exception>
        /// <exception cref="System.ArgumentException">The input DTO is null.</exception>
        public void UpdateReverseCrossRefRequiredStep(ReverseCrossRefRequiredStepDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CmdText =
                @"
UPDATE [dbo].[ReverseCrossRefRequiredFieldStep]
SET [ReverseCrossRefProcessId] = @reverseCrossRefProcessId
  , [CrossRefFieldName] = @crossRefFieldName
  , [FieldId] = @fieldId
  , [DisplayFieldName] = @displayFieldName
  , [DisplayMultiple] = @displayMultiple
WHERE [Id] = @stepId";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                using (var cmd = new SqlCommand(CmdText, cn))
                {
                    cmd.Parameters.AddWithValue("@stepId", dto.Id);
                    cmd.Parameters.AddWithValue("@reverseCrossRefProcessId", AdoHelper.NullCheck(dto.ReverseCrossRefProcessId));
                    cmd.Parameters.AddWithValue("@crossRefFieldName", dto.CrossRefFieldName);
                    cmd.Parameters.AddWithValue("@fieldId", dto.FieldId);
                    cmd.Parameters.AddWithValue("@displayFieldName", dto.DisplayFieldName);
                    cmd.Parameters.AddWithValue("@displayMultiple", dto.DisplayMultiple);

                    var rowsAffetcted = cmd.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Retrieves reverse cross ref required step.
        /// </summary>
        /// <param name="processName">The process name.</param>
        /// <param name="fieldName">The field name.</param>
        /// <param name="isPublishedCopy">The is published copy.</param>
        /// <returns>The <see cref="ReverseCrossRefRequiredStepDto" />.</returns>
        public ReverseCrossRefRequiredStepDto FetchReverseCrossRefRequiredStep(string processName, string fieldName, bool isPublishedCopy = false)
        {
            const string CmdText =
                @"
DECLARE @fieldId AS INT

SELECT @fieldId = f.Id
FROM
    [dbo].[Processes] p
    INNER JOIN [dbo].[Sections] s ON s.ProcessId = p.Id
    INNER JOIN [dbo].[Fields] f ON f.SectionId = s.Id
WHERE p.[SystemName] = @processName AND p.IsRemoved = 0 AND p.IsPublishedCopy = @isPublishedCopy AND f.SystemName = @fieldName;

EXEC [dbo].[GetReverseCrossRefRequiredStep] @FieldId = @fieldId;
";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                using (var cmd = new SqlCommand(CmdText, ctx.Connection))
                {
                    cmd.Parameters.AddWithValue("@processName", processName);
                    cmd.Parameters.AddWithValue("@fieldName", fieldName);
                    cmd.Parameters.AddWithValue("@isPublishedCopy", isPublishedCopy);

                    using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            var dto = new ReverseCrossRefRequiredStepDto
                                          {
                                              Id = reader.GetInt32(0),
                                              FieldId = reader.GetInt32(1),
                                              ReverseCrossRefProcessId = reader.GetNullableInt(2),
                                              CrossRefFieldName = reader.GetString(3),
                                              DisplayFieldName = reader.GetString(4),
                                              DisplayMultiple = reader.GetBoolean(5)
                                          };

                            if (reader.NextResult())
                            {
                                while (reader.Read())
                                {
                                    var df = new ReverseCrossReferenceDisplayFieldDto
                                                 {
                                                     Id = reader.GetInt32(0),
                                                     DisplayName = reader.GetString(1),
                                                     FullPath = reader.GetString(2),
                                                     Order = reader.GetDouble(3)
                                                 };

                                    dto.SelectedDisplayFields.Add(df);
                                }
                            }

                            return dto;
                        }
                    }
                }
            }

            return null;
        }
Пример #3
0
        ///// <summary>
        ///// Retrieves reverse cross ref required step.
        ///// </summary>
        ///// <param name="childData">
        ///// The child data.
        ///// </param>
        ///// <returns>
        ///// The <see cref="ReverseCrossRefRequiredStepDto"/>.
        ///// </returns>
        //[Obsolete]
        //public ReverseCrossRefRequiredStepDto FetchReverseCrossRefRequiredStep(BaseStepDto childData)
        //{
        //    if (childData == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "childData"));

        //    using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
        //    {
        //        var connection = ctx.Connection;

        //        const string CommandText = "[GetReverseCrossRefRequiredStep]";

        //        using (var cmd = new SqlCommand(CommandText, connection))
        //        {
        //            cmd.CommandType = CommandType.StoredProcedure;
        //            cmd.Parameters.AddWithValue("@fieldId", childData.FieldId);

        //            using (var reader = new SafeDataReader(cmd.ExecuteReader()))
        //            {
        //                return new ReverseCrossRefRequiredStepFetcher().Fetch(childData, reader);
        //            }
        //        }
        //    }
        //}

        /// <summary>
        /// Inserts reverse cross ref required step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentException">The input DTO is null.</exception>
        public void InsertReverseCrossRefRequiredStep(ReverseCrossRefRequiredStepDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CmdText =
                @"
INSERT INTO [dbo].[ReverseCrossRefRequiredFieldStep]([FieldId], [ReverseCrossRefProcessId], [CrossRefFieldName], [DisplayFieldName], [DisplayMultiple])
VALUES (@fieldId, @reverseCrossRefProcessId, @crossRefFieldName, @displayFieldName, @displayMultiple);
SELECT [Id]
FROM   [dbo].[ReverseCrossRefRequiredFieldStep]
WHERE  [Id] = SCOPE_IDENTITY()";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                using (var cmd = new SqlCommand(CmdText, cn))
                {
                    cmd.Parameters.AddWithValue("@fieldId", dto.FieldId);
                    cmd.Parameters.AddWithValue("@reverseCrossRefProcessId", AdoHelper.NullCheck(dto.ReverseCrossRefProcessId));
                    cmd.Parameters.AddWithValue("@crossRefFieldName", dto.CrossRefFieldName);
                    cmd.Parameters.AddWithValue("@displayFieldName", dto.DisplayFieldName);
                    cmd.Parameters.AddWithValue("@displayMultiple", dto.DisplayMultiple);

                    dto.Id = (int)cmd.ExecuteScalar();
                }
            }
        }