Hi Nettiers,
First great job - steep learning curve for us junior programmers but - great job. It has actually given me insight into how many of the .NET framework interfaces should be used.
However, I am struggling to understand why the validation for empty strings doesn't seem to work in my bound winform DataGridView control. I am using the latest SVN trunk code and have changed my EntityInstanceBase.generated.cst template to include the following in the AddValidationRules method:
if (! cols[x].AllowDBNull && IsCSReferenceDataType(cols[x]))
{%>
ValidationRules.AddRule(Validation.CommonRules.NotNull,"<%=propertyName%>");
ValidationRules.AddRule(Validation.CommonRules.StringRequired,"<%=propertyName%>");
<%
}
After generation my entities include this new validation rule.
I have a number of basic settings forms with DataGridViews bound to basicSettingXService.GetAll() .
On adding a new item I hijack the bindingSource addingNew event and have the option of setting a default for the basicSetting object description. If I set it to null the DataDridView reports on the invalid null state of the description property. BUT an empty string in the same property is mysteriously valid. See form code below.
I have read quite a few different notes on this in the forums and although the same issue repeated gets described it is passed off as programmer error. Given the simplicity of the example below I cannot see why the validation for StringNotNullOrEmpty fails.
//WEIGHT UNIT FORM
using System;
using System.ComponentModel;
using System.Windows.Forms;
using
Dal.Component;
using Dal.Entities;
namespace
App
{
public partial class FormWeightUnit : Form
{
//Create a new Service Workspace object to work with;
WeightUnitService weightUnitService = new WeightUnitService();
// Fields
private static FormWeightUnit instance;
protected FormWeightUnit(Form form)
{
InitializeComponent();
MdiParent = form;
}
// Methods
public static FormWeightUnit Instance(Form form)
{
// Uses "Lazy initialization"
if( instance == null )
{
instance = new FormWeightUnit(form);
}
return instance;
}
private void FormWeightUnit_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
weightUnitBindingSource.DataSource = weightUnitService.GetAll();
weightUnitDataGridView.AutoGenerateColumns = true;
weightUnitDataGridView.Columns["ID"].Visible = false;
}
private void SaveAll()
{
TList<WeightUnit> list = weightUnitBindingSource.DataSource as TList<WeightUnit>;
if(list.IsValid)
{
weightUnitService.Save(list);
}
}
private void weightUnitBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
SaveAll();
}
private void FormWeightUnit_FormClosed(object sender, FormClosedEventArgs e)
{
instance = null;
}
private void weightUnitBindingSource_AddingNew(object sender, AddingNewEventArgs e)
{
//A WeightUnit consists of an ID identity and a string Description
WeightUnit w = new WeightUnit();
//w.Description = null;
e.NewObject = w;
}
}
}