Пример #1
0
        /// <summary>
        /// Updates process KPI.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <param name="locDto">The localization DTO object.</param>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Data.DBConcurrencyException"></exception>
        /// <exception cref="DBConcurrencyException">Indicates stale data.</exception>
        public void UpdateProcessKpiWithLocalization(ProcessKpiEditDto dto, ProcessKpiLocalizationDto locDto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText =
@"
UPDATE [dbo].[Kpis]
SET
     [MetricGuid]                  = @p_MetricGuid
    ,[LastModifiedOn]              = @p_LastModifiedOn
    ,[GuidId]                      = @p_GuidId
    ,[TargetValue]                 = @p_TargetValue
    ,[FavorableDirection]          = @p_FavorableDirection
    ,[GreenIconUrl]                = @p_GreenIconUrl
    ,[GreenIconId]                 = @p_GreenIconId
    ,[GreenValue]                  = @p_GreenValue
    ,[YellowIconUrl]               = @p_YellowIconUrl
    ,[YellowIconId]                = @p_YellowIconId
    ,[YellowValue]                 = @p_YellowValue
    ,[RedIconUrl]                  = @p_RedIconUrl
    ,[RedIconId]                   = @p_RedIconId
    ,[FilterGuid]                  = @p_FilterGuid
    ,[FilterDefinition]            = @p_FilterDefinition
WHERE [Id] = @p_Id;
";
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_Id", dto.Id);
                    command.Parameters.AddWithValue("@p_MetricGuid", dto.MetricGuid);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", dto.LastModifiedOn);
                    command.Parameters.AddWithValue("@p_GuidId", dto.GuidId);
                    command.Parameters.AddWithValue("@p_TargetValue", dto.TargetValue);
                    command.Parameters.AddWithValue("@p_FavorableDirection", dto.FavorableDirection);
                    command.Parameters.AddWithValue("@p_GreenIconUrl", dto.GreenIconUrl);
                    command.Parameters.AddWithValue("@p_GreenIconId", dto.GreenIconId.HasValue ? (object)dto.GreenIconId.Value : DBNull.Value);
                    command.Parameters.AddWithValue("@p_GreenValue", dto.GreenValue);
                    command.Parameters.AddWithValue("@p_YellowIconUrl", dto.YellowIconUrl);
                    command.Parameters.AddWithValue("@p_YellowIconId", dto.YellowIconId.HasValue ? (object)dto.YellowIconId.Value : DBNull.Value);
                    command.Parameters.AddWithValue("@p_YellowValue", dto.YellowValue);
                    command.Parameters.AddWithValue("@p_RedIconUrl", dto.RedIconUrl);
                    command.Parameters.AddWithValue("@p_RedIconId", AdoHelper.NullCheck(dto.RedIconId));
                    command.Parameters.AddWithValue("@p_FilterGuid", AdoHelper.NullCheck(dto.FilterGuid));
                    command.Parameters.AddWithValue("@p_FilterDefinition", AdoHelper.NullCheck(dto.FilterDefinition));

                    if (command.ExecuteNonQuery() == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }

            UpdateProcessKpiLocalization(locDto);
        }
Пример #2
0
        /// <summary>
        /// Inserts process KPI.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void InsertProcessKpi(ProcessKpiEditDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText =
@"
INSERT INTO [dbo].[Kpis]
(
     [ProcessId]
    ,[MetricGuid]
    ,[LastModifiedOn]
    ,[GuidId]
    ,[Name]
    ,[Documentation]
    ,[TargetValue]
    ,[FavorableDirection]
    ,[GreenIconUrl]
    ,[GreenIconId]
    ,[GreenValue]
    ,[YellowIconUrl]
    ,[YellowIconId]
    ,[YellowValue]
    ,[RedIconUrl]
    ,[RedIconId]
    ,[FilterGuid]
    ,[FilterDefinition]
)
VALUES
(
     @p_ProcessId
    ,@p_MetricGuid
    ,@p_LastModifiedOn
    ,@p_GuidId
    ,@p_Name
    ,@p_Documentation
    ,@p_TargetValue
    ,@p_FavorableDirection
    ,@p_GreenIconUrl
    ,@p_GreenIconId
    ,@p_GreenValue
    ,@p_YellowIconUrl
    ,@p_YellowIconId
    ,@p_YellowValue
    ,@p_RedIconUrl
    ,@p_RedIconId
    ,@p_FilterGuid
    ,@p_FilterDefinition
);
SELECT [Id]
FROM [dbo].[Kpis]
WHERE [Id] = SCOPE_IDENTITY()";

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

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_ProcessId", dto.ProcessId);
                    command.Parameters.AddWithValue("@p_MetricGuid", dto.MetricGuid);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", dto.LastModifiedOn);
                    command.Parameters.AddWithValue("@p_GuidId", dto.GuidId);
                    command.Parameters.AddWithValue("@p_Name", dto.Name);
                    command.Parameters.AddWithValue("@p_Documentation", dto.Documentation);
                    command.Parameters.AddWithValue("@p_TargetValue", dto.TargetValue);
                    command.Parameters.AddWithValue("@p_FavorableDirection", dto.FavorableDirection);
                    command.Parameters.AddWithValue("@p_GreenIconUrl", dto.GreenIconUrl);
                    command.Parameters.AddWithValue("@p_GreenIconId", dto.GreenIconId.HasValue ? (object)dto.GreenIconId.Value : DBNull.Value);
                    command.Parameters.AddWithValue("@p_GreenValue", dto.GreenValue);
                    command.Parameters.AddWithValue("@p_YellowIconUrl", dto.YellowIconUrl);
                    command.Parameters.AddWithValue("@p_YellowIconId", dto.YellowIconId.HasValue ? (object)dto.YellowIconId.Value : DBNull.Value);
                    command.Parameters.AddWithValue("@p_YellowValue", dto.YellowValue);
                    command.Parameters.AddWithValue("@p_RedIconUrl", dto.RedIconUrl);
                    command.Parameters.AddWithValue("@p_RedIconId", AdoHelper.NullCheck(dto.RedIconId));
                    command.Parameters.AddWithValue("@p_FilterGuid", AdoHelper.NullCheck(dto.FilterGuid));
                    command.Parameters.AddWithValue("@p_FilterDefinition", AdoHelper.NullCheck(dto.FilterDefinition));

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