/// <summary> /// Inserts field backcolor rule. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentException">The input DTO is null.</exception> /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception> public void InsertFieldBackcolorRule(FieldBackcolorRuleEditDto dto) { if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string sql = @" INSERT [dbo].[FieldBackcolorRules] ( [RuleId], [FieldGuid], [BackColor] ) VALUES ( @ruleId, @fieldGuid, @backColor );"; using (var cmd = new SqlCommand(sql)) { cmd.Parameters.AddWithValue("@ruleId", dto.RuleId); cmd.Parameters.AddWithValue("@fieldGuid", dto.FieldGuid); cmd.Parameters.AddWithValue("@backColor", dto.BackColor); var rowsAffetcted = Database.Execute(cmd); if (rowsAffetcted == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } }
/// <summary> /// Update field backcolor rule. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentException">The input DTO is null.</exception> /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data.</exception> public void UpdateFieldBackcolorRule(FieldBackcolorRuleEditDto dto) { if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string sql = @" UPDATE dbo.FieldBackcolorRules SET BackColor = @backColor, LastModifiedOn = GETDATE() WHERE RuleId = @ruleId AND FieldGuid = @fieldGuid"; using (var cmd = new SqlCommand(sql)) { cmd.Parameters.AddWithValue("@ruleId", dto.RuleId); cmd.Parameters.AddWithValue("@fieldGuid", dto.FieldGuid); cmd.Parameters.AddWithValue("@backColor", dto.BackColor); var rowsAffetcted = Database.Execute(cmd); if (rowsAffetcted == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } }
/// <summary> /// Reads field backcolor rules. /// </summary> /// <param name="process">The process.</param> /// <param name="sr">The reader.</param> private static void ReadFieldBackcolorRules(ProcessEditDto process, SafeDataReader sr) { int? ruleId = null; ProcessActionRuleEditDto rule = null; sr.NextResult(); while (sr.Read()) { var dto = new FieldBackcolorRuleEditDto { RuleId = sr.GetInt32(0), RuleGuid = sr.GetGuid(1), FieldGuid = sr.GetGuid(2), BackColor = sr.GetInt64(3), FieldSystemName = sr.GetString(4), FieldName = sr.GetString(5) }; if (dto.RuleId != ruleId) { rule = process.ActionRules.First(r => r.Id == dto.RuleId); ruleId = rule.Id; } rule.FieldBackcolorRules.Add(dto); } }