Hi!
I was wondering if any of you has had a brilliant idea to deal with null values on fields of numeric type (int, bigint, float, etc on sql server). Here's my situation:
when I want to set the Text property of a textbox with a value from a numerical database field, I first check if the field was originally null (TestOriginalFieldValueForNull) If it's null then I put an empty string in the field (otherwise a "0" appears when I convert to llbl property (which is an int, double ,etc) to a string. If it's not null, I simply convert the property value to a string and put it in the textbox.
when I read the value back in the entity, I must check if the input value is an empty string (for instance if the user cleared the field). In this case, I must set the isNull property of the field to true, otherwise I set it to false (because if I keep the entity in memory and try to TestOriginalFieldValueForNull again then it must return false..) and assign the textbox value to the llbl property.
It makes a lot of "dirty" and useless code in my app. So I thought about encapsulating all this code directly into the entity classes by redefining each property that links to a numerical database field that can be read from a textbox in my application. So If I have a property called Salary (that is a double) in entity Employee, I redefine in EmployeeEntity:
public new string Salary
{
get {if(base.TestOriginalFieldValueForNull(EmployeeFieldIndex.Salary)) return ""; else return base.Salary.ToString();}
set {if(value != "") base.Salary = Convert.ToDouble(value); this.Fields["Salary"].IsNull = false; else this.Fields["Salary"].IsNull = true;}
}
So assuming a valid double is typed in a textbox, I could use this thing by simply doing:
employee.Salary = txtSalary.Text;
I wanted to know if someone developped a better/simpler way to do it or if I missed something that already does that in llbl.
Thank you all for taking the time to read this