/// <summary> /// Updates numeric required step. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception> public void UpdateNumericRequiredStep(NumericRequiredStepDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; const string CommandText = @" UPDATE [dbo].[NumericRequiredFieldStep] SET [NumericType] = @p_NumericType ,[NumberOfDigits] = @p_NumberOfDigits ,[FieldId] = @p_FieldId ,[Minimum] = @p_Minimum ,[Maximum] = @p_Maximum WHERE id = @p_id"; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_NumericType", dto.NumericType); command.Parameters.AddWithValue("@p_NumberOfDigits", dto.NumberOfDigits); command.Parameters.AddWithValue("@p_Id", dto.Id); command.Parameters.AddWithValue("@p_FieldId", dto.FieldId); command.Parameters.AddWithValue("@p_Minimum", dto.Minimum); command.Parameters.AddWithValue("@p_Maximum", dto.Maximum); var result = command.ExecuteNonQuery(); Debug.WriteLine(result); } } }
/// <summary> /// Inserts numeric required step. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception> public void InsertNumericRequiredStep(NumericRequiredStepDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; const string CommandText = @" INSERT INTO [dbo].[NumericRequiredFieldStep] ([NumericType] ,[NumberOfDigits] ,[FieldId] ,[Minimum] ,[Maximum] ) VALUES (@p_NumericType ,@p_NumberOfDigits ,@p_FieldId ,@p_Minimum ,@p_Maximum) SELECT CAST(SCOPE_IDENTITY() AS INT) "; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_NumericType", dto.NumericType); command.Parameters.AddWithValue("@p_FieldId", dto.FieldId); command.Parameters.AddWithValue("@p_NumberOfDigits", dto.NumberOfDigits); command.Parameters.AddWithValue("@p_Minimum", dto.Minimum); command.Parameters.AddWithValue("@p_Maximum", dto.Maximum); dto.Id = (int)command.ExecuteScalar(); } } }
/// <summary> /// Retrieves numeric 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="NumericRequiredStepDto" />.</returns> public NumericRequiredStepDto FetchNumericRequiredStep(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].[GetNumericRequiredStep] @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 NumericRequiredStepDto { Id = reader.GetInt32(0), NumericType = reader.GetInt32(1), NumberOfDigits = reader.GetInt32(2), Minimum = reader.GetDouble(3), Maximum = reader.GetDouble(4) }; return dto; } } } } return null; }