private void ReadRunPlan(SqlConnection con)
{
List<string> lsStr = new List<string>();
using (SqlCommand cmd = con.CreateCommand())
{
string[] restrictionValues = new string[4];
restrictionValues[0] = null; // Catalog
restrictionValues[1] = null; // Owner
restrictionValues[2] = runplanData.CurrentSCHName; // Table
restrictionValues[3] = null; // Column
using (DataTable dt = con.GetSchema(SqlClientMetaDataCollectionNames.Columns, restrictionValues))
{
foreach (DataRow item in dt.Rows)
{
string str = item["column_name"].ToString();
lsStr.Add(str);
}
}
cmd.CommandText = string.Format("select * from [{0}]", runplanData.CurrentSCHName);
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
RunPlanData m_RunPlanData = new RunPlanData();
Type t = m_RunPlanData.GetType();
PropertyInfo[] f = t.GetProperties();
foreach (PropertyInfo item in f)
{
IList<CustomAttributeData> ls = item.GetCustomAttributesData();
foreach (var oAttr in ls)
{
var lstAttrArgu = oAttr.NamedArguments;
if (lsStr.Contains(lstAttrArgu[0].TypedValue.Value.ToString()))
item.SetValue(m_RunPlanData, Convert.ChangeType(reader[lstAttrArgu[0].TypedValue.Value.ToString()].ToString(), item.PropertyType), null);
}
}
mRunPlan.Add(m_RunPlanData);
}
}
///删选出时刻表计划的车的数量
runplanData.ListTrainID = mRunPlan.Select(item => item.Train_ID).Distinct().ToList<int>();
}
}