#region //获得数据库服务器当前时间
///
/// 获得数据库服务器当前时间
///
///
public DateTime Get_DbServerTime()
{
SqlDataReader rs = null;
DateTime dt = new DateTime();
try
{
CloseDb();
OpenDb();
SqlCommand cm = new SqlCommand("select getdate() ", conn);
rs = cm.ExecuteReader(CommandBehavior.CloseConnection);
cm.Dispose();
cm = null;
//Close();
if (rs.Read())
{ dt = DateTime.Parse(rs[0].ToString()); }
CloseDb();
}
catch
{
throw new Exception("取服务器时间出错!");
}
return dt;
}
#endregion
#region //执行对单个Entity的更新
///
/// 执行对单个Entity的更新
///
///
public void ExecuteObjectUpdate(BaseEntity baseEntity)
{
ExecuteObjectUpdate(baseEntity, "");
}
#endregion
#region //C#利用反射获取对象属性值
///
/// C#利用反射获取对象属性值
///
///
///
/// 需要更改的值
///
public static string GetObjectPropertyValue(Type type, BaseEntity baseEntity, string propertyname)
{
PropertyInfo property = type.GetProperty(propertyname);//根据变量名得到变量对象
//if (property == null) return null;//BaseEntity.cs属性名与BaseModel.cs中属性名不相同时,并不进行编辑
object o = property.GetValue(baseEntity, null);//从实体中获取具体值 重要
if (o == null) return null;
return o.ToString();
}
#endregion