/// <summary>
/// 将模型的每个属性设置为默认值
/// </summary>
/// <param name="sModelName"></param>
private void SetPropertyDefaultValue4Master(ICStockBill mICStockBill)
{
Type t = typeof(ICStockBill);
//获取所有属性
System.Reflection.PropertyInfo[] properties = t.GetProperties();
foreach (System.Reflection.PropertyInfo property in properties)
{
string sColType = t.GetProperty(property.Name).PropertyType.ToString().ToLower();
//如果可以为空
if (sColType.IndexOf("system.null") > -1)
{
t.GetProperty(property.Name).SetValue(mICStockBill, null , null);
}
else if (sColType == "system.string")
{
t.GetProperty(property.Name).SetValue(mICStockBill, "", null);
}
else if (sColType == "system.int32")
{
t.GetProperty(property.Name).SetValue(mICStockBill, 0, null);
}
else if (sColType == "system.decimal")
{
t.GetProperty(property.Name).SetValue(mICStockBill, decimal.Parse("0"), null);
}
else if (sColType == "system.datetime")
{
t.GetProperty(property.Name).SetValue(mICStockBill, DateTime.MinValue, null);
}
else if (sColType == "system.boolean")
{
t.GetProperty(property.Name).SetValue(mICStockBill, bool.Parse("false"), null);
}
else if (sColType == "system.guid")
{
t.GetProperty(property.Name).SetValue(mICStockBill, new Guid(), null);
}
else
{
MessageBoxEx.Show(sColType.ToLower() + "数据类型未登记!");
}
}
}