Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Jump Start and Discount Rule
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01322559
Message ID:
01322781
Views:
15
Shawn,

The Business Rule Generator does its best job in generating rules based on the database schema at the time. The reason the discount column does not allow zero is because that column is defined to not allow null values, so the BLG makes it required which also means not equal to zero.

However, you should just use this as a starting point and change the rules as needed. Just go into the rules class and change your code accordingly. For example on the discount column mentioned here, if you do not want this rule, just comment out the execution of the ValidateDiscount method.
// Call validation methods
						//this.ValidateDiscount(Entity.Discount);
						this.ValidateOrderID(Entity.OrderID);
						this.ValidateProductID(Entity.ProductID);
						this.ValidateQuantity(Entity.Quantity);
						this.ValidateUnitPrice(Entity.UnitPrice);
Or modify the ValidateDiscount method to allow zero but nothing less than zero.
/// <summary>
		/// Validates the Discount
		/// </summary>
		public string ValidateDiscount(Single discount)
		{
			string Msg = null;
			//if (mmType.IsEmpty(discount))
if (discount < 0)
			{
				this.EntityPropertyDisplayName = "Discount cannot be less than zero";

				Msg = this.RequiredFieldMessagePrefix + 
					this.EntityPropertyDisplayName + 
					this.RequiredFieldMessageSuffix;

				AddErrorProviderBrokenRule("Discount",  Msg);
			}
			return Msg;
		}
>Where does the MM Generator get this rule from?
>
>Can you give me an example of how I can circumvent (override), or change this rule?
>
>>Shawn,
>
>>The way the business rule is setup, it is requiring that the discount be non-zero. Probably a better check here would be to check for the >discount less than zero, but the point is that this is the way the rule is defined.
>
>>How zero discounts got in the database previously is probably due to inserts or updates applied to the table either before the rule was >created or via SQL commands executed outside the business rules logic.
>
>The bottom line of the business rule is that you create them as you see fit (or as the business demands).
>
>>HTH
>
>>Bob
>
>>In the Jump Start tutorial "Web Forms Application - C#" step 14 "Running the Order Edit Form"
>>s
>>When saving the Order Edit form the Discount in the OrderDetail fails entityRule.
>>
>>Stepping through the code in OrderDetailRules.cs:
>>discount = 0.0
>>mmType.IsEmpty(discount) = true
>>
>>I do not understand why 0.0 fails. Should I not be able to have a discount of 0.0?
>>
>>As you see in the tutorial documentation in step 14 the OrderDetail grid does show discount of 0 for each row.
>>And if the author tested this tutorial they would not have gotten the same error.
>>
>>In my test the save fails due to the following rules message "Discount is required"
>>
>>I know I could change the data, but I should be allowed to have a 0 discount.
>>Why is the Detail table being checked anyway? The data is readonly?
>>
>>Any help is appreciated.
Previous
Reply
Map
View

Click here to load this message in the networking platform