Tracking_自定义Profile筛选(2)
将Pofile对象的XML串存入数据库
该方法 调用了Tacking数据库的默认存储过程UpdateTrackingProfile,也可用自已的方式直接对Tacking数据库操作 private static void 插入Profile的XML串到数据库(string XML字串, Version 版本)
{
string sql = @"Initial Catalog=Tracking;Data Source=WXWINTER\SQLEXPRESS;Integrated Security=SSPI;";
//调用存储过程UpdateTrackingProfile
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure; //类型是存储过程
command.CommandText = "dbo.UpdateTrackingProfile"; //操作 的存储过程
command.Connection = new SqlConnection(sql); //数据库连接字串
try
{
//字段---------------------------------------------
SqlParameter typeFullName = new SqlParameter();
typeFullName.ParameterName = "@TypeFullName";
typeFullName.SqlDbType = SqlDbType.NVarChar;
//值为要设置工作流类的类名 : typeof(wxdlzm1).ToString()
typeFullName.SqlValue = typeof(wxdlzm_wxwinter).ToString();
command.Parameters.Add(typeFullName);
//字段----------------------------------------------------
SqlParameter assemblyFullName = new SqlParameter();
assemblyFullName.ParameterName = "@AssemblyFullName";
assemblyFullName.SqlDbType = SqlDbType.NVarChar;
//值为要设置工作流类的全称名 : typeof(wxdlzm1).Assembly.FullName
assemblyFullName.SqlValue = typeof(wxdlzm_wxwinter).Assembly.FullName;
command.Parameters.Add(assemblyFullName);
//TrackingProfile表Version字段--------------------------------
SqlParameter versionId = new SqlParameter();
versionId.ParameterName = "@Version";
versionId.SqlDbType = SqlDbType.VarChar;
//值为要指定的片本号的字串:格式"3.0.0.7"
versionId.SqlValue = 版本.ToString();
command.Parameters.Add(versionId);
//TrackingProfile表TrackingProfileXml字段-----------------------
SqlParameter trackingProfile = new SqlParameter();
trackingProfile.ParameterName = "@TrackingProfileXml";
trackingProfile.SqlDbType = SqlDbType.NVarChar;
//值为TrackingProfile格式的XML字串
trackingProfile.SqlValue = XML字串;
command.Parameters.Add(trackingProfile);
//-----------------------------------------------------------
command.Connection.Open();//打开连接
command.ExecuteNonQuery();//执行
Console.WriteLine();
Console.WriteLine("已将Profile插入");
Console.WriteLine();
}
catch (SqlException e)
{
Console.WriteLine();
Console.WriteLine("插入Profile方法的Try捕获:插入数据出错了:");
Console.WriteLine(e.Message);
Console.WriteLine();
command.Dispose();
return;
}
finally
{
if ((null != command) && (null != command.Connection) && (ConnectionState.Closed != command.Connection.State))
{
command.Connection.Close();
}
}
command.Dispose();
}
{
string sql = @"Initial Catalog=Tracking;Data Source=WXWINTER\SQLEXPRESS;Integrated Security=SSPI;";
//调用存储过程UpdateTrackingProfile
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure; //类型是存储过程
command.CommandText = "dbo.UpdateTrackingProfile"; //操作 的存储过程
command.Connection = new SqlConnection(sql); //数据库连接字串
try
{
//字段---------------------------------------------
SqlParameter typeFullName = new SqlParameter();
typeFullName.ParameterName = "@TypeFullName";
typeFullName.SqlDbType = SqlDbType.NVarChar;
//值为要设置工作流类的类名 : typeof(wxdlzm1).ToString()
typeFullName.SqlValue = typeof(wxdlzm_wxwinter).ToString();
command.Parameters.Add(typeFullName);
//字段----------------------------------------------------
SqlParameter assemblyFullName = new SqlParameter();
assemblyFullName.ParameterName = "@AssemblyFullName";
assemblyFullName.SqlDbType = SqlDbType.NVarChar;
//值为要设置工作流类的全称名 : typeof(wxdlzm1).Assembly.FullName
assemblyFullName.SqlValue = typeof(wxdlzm_wxwinter).Assembly.FullName;
command.Parameters.Add(assemblyFullName);
//TrackingProfile表Version字段--------------------------------
SqlParameter versionId = new SqlParameter();
versionId.ParameterName = "@Version";
versionId.SqlDbType = SqlDbType.VarChar;
//值为要指定的片本号的字串:格式"3.0.0.7"
versionId.SqlValue = 版本.ToString();
command.Parameters.Add(versionId);
//TrackingProfile表TrackingProfileXml字段-----------------------
SqlParameter trackingProfile = new SqlParameter();
trackingProfile.ParameterName = "@TrackingProfileXml";
trackingProfile.SqlDbType = SqlDbType.NVarChar;
//值为TrackingProfile格式的XML字串
trackingProfile.SqlValue = XML字串;
command.Parameters.Add(trackingProfile);
//-----------------------------------------------------------
command.Connection.Open();//打开连接
command.ExecuteNonQuery();//执行
Console.WriteLine();
Console.WriteLine("已将Profile插入");
Console.WriteLine();
}
catch (SqlException e)
{
Console.WriteLine();
Console.WriteLine("插入Profile方法的Try捕获:插入数据出错了:");
Console.WriteLine(e.Message);
Console.WriteLine();
command.Dispose();
return;
}
finally
{
if ((null != command) && (null != command.Connection) && (ConnectionState.Closed != command.Connection.State))
{
command.Connection.Close();
}
}
command.Dispose();
}
查询自定义Pofile的版本
该方法 调用了Tacking数据库的默认存储过程GetTrackingProfile,也可用自已的方式直接对Tacking数据库操作 private static Version 得到Profile版本()
{
//调用存储过程GetTrackingProfile
string sql = @"Initial Catalog=Tracking;Data Source=WXWINTER\SQLEXPRESS;Integrated Security=SSPI;";
TrackingProfile profile = null;
SqlDataReader SQL读取对象= null;
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;//类型是存储过程
command.CommandText = "dbo.GetTrackingProfile"; //操作的存储过程
command.Connection = new SqlConnection(sql); //数据库连接字串
try
{
//字段
SqlParameter typeFullName = new SqlParameter();
typeFullName.ParameterName = "@TypeFullName";
typeFullName.SqlDbType = SqlDbType.NVarChar;
//值为要查询的工作流类的类名: typeof(wxdlzm1).ToString() 或typeof(wxdlzm1).FullName
typeFullName.SqlValue = typeof(wxdlzm_Wxwinter).FullName; //
command.Parameters.Add(typeFullName);
//字段
SqlParameter assemblyFullName = new SqlParameter();
assemblyFullName.ParameterName = "@AssemblyFullName";
assemblyFullName.SqlDbType = SqlDbType.NVarChar;
//值为要查询工作流类的全称名: typeof(wxdlzm1).Assembly.FullName
assemblyFullName.SqlValue = typeof(wxdlzm_Wxwinter).Assembly.FullName;
command.Parameters.Add(assemblyFullName);
//
SqlParameter versionId = new SqlParameter();
versionId.ParameterName = "@Version";
versionId.SqlDbType = SqlDbType.VarChar;
command.Parameters.Add(versionId);
//
SqlParameter createDefault = new SqlParameter();
createDefault.ParameterName = "@CreateDefault";
createDefault.SqlDbType = SqlDbType.Bit;
createDefault.SqlValue = 0;
command.Parameters.Add(createDefault);
command.Connection.Open();
SQL读取对象= command.ExecuteReader();
if (SQL读取对象.Read())
{
string profile的Xml字串= SQL读取对象[0] as string;
if (null != profile的Xml字串)
{
TrackingProfileSerializer 串行化对象= new TrackingProfileSerializer();
StringReader stringReader对象= null;
try
{
stringReader对象= new StringReader(profile的Xml字串);
profile = 串行化对象.Deserialize(stringReader对象);
}
finally
{
if (stringReader对象!= null)
stringReader对象.Close();
}
}
}
}
//--------以上得到从数据库中得到profile的Xml字串,并将其返串为TrackingProfile对象
finally
{
if ((SQL读取对象!= null) && (!SQL读取对象.IsClosed))
SQL读取对象.Close();
if ((command != null) && (command.Connection != null) && (ConnectionState.Closed != command.Connection.State))
{
command.Connection.Close();
}
command.Dispose();
}
//----------------------------------
if (profile != null)
{
return new Version(profile.Version.ToString());
}
else
{//如果数据库中没有,就返回"0.0.0.0"格式,表示没有,此为自定义约定
return new Version("0.0.0.0");
}
}
{
//调用存储过程GetTrackingProfile
string sql = @"Initial Catalog=Tracking;Data Source=WXWINTER\SQLEXPRESS;Integrated Security=SSPI;";
TrackingProfile profile = null;
SqlDataReader SQL读取对象= null;
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;//类型是存储过程
command.CommandText = "dbo.GetTrackingProfile"; //操作的存储过程
command.Connection = new SqlConnection(sql); //数据库连接字串
try
{
//字段
SqlParameter typeFullName = new SqlParameter();
typeFullName.ParameterName = "@TypeFullName";
typeFullName.SqlDbType = SqlDbType.NVarChar;
//值为要查询的工作流类的类名: typeof(wxdlzm1).ToString() 或typeof(wxdlzm1).FullName
typeFullName.SqlValue = typeof(wxdlzm_Wxwinter).FullName; //
command.Parameters.Add(typeFullName);
//字段
SqlParameter assemblyFullName = new SqlParameter();
assemblyFullName.ParameterName = "@AssemblyFullName";
assemblyFullName.SqlDbType = SqlDbType.NVarChar;
//值为要查询工作流类的全称名: typeof(wxdlzm1).Assembly.FullName
assemblyFullName.SqlValue = typeof(wxdlzm_Wxwinter).Assembly.FullName;
command.Parameters.Add(assemblyFullName);
//
SqlParameter versionId = new SqlParameter();
versionId.ParameterName = "@Version";
versionId.SqlDbType = SqlDbType.VarChar;
command.Parameters.Add(versionId);
//
SqlParameter createDefault = new SqlParameter();
createDefault.ParameterName = "@CreateDefault";
createDefault.SqlDbType = SqlDbType.Bit;
createDefault.SqlValue = 0;
command.Parameters.Add(createDefault);
command.Connection.Open();
SQL读取对象= command.ExecuteReader();
if (SQL读取对象.Read())
{
string profile的Xml字串= SQL读取对象[0] as string;
if (null != profile的Xml字串)
{
TrackingProfileSerializer 串行化对象= new TrackingProfileSerializer();
StringReader stringReader对象= null;
try
{
stringReader对象= new StringReader(profile的Xml字串);
profile = 串行化对象.Deserialize(stringReader对象);
}
finally
{
if (stringReader对象!= null)
stringReader对象.Close();
}
}
}
}
//--------以上得到从数据库中得到profile的Xml字串,并将其返串为TrackingProfile对象
finally
{
if ((SQL读取对象!= null) && (!SQL读取对象.IsClosed))
SQL读取对象.Close();
if ((command != null) && (command.Connection != null) && (ConnectionState.Closed != command.Connection.State))
{
command.Connection.Close();
}
command.Dispose();
}
//----------------------------------
if (profile != null)
{
return new Version(profile.Version.ToString());
}
else
{//如果数据库中没有,就返回"0.0.0.0"格式,表示没有,此为自定义约定
return new Version("0.0.0.0");
}
}