WEB programming based on unified plug-in interface [middle]

xiaoxiao2021-03-06  41

Connect back: The code written this time is the so-called plugin, because the actual plugin file should be a DLL or some edited file format [all companies have their own naming rules], I am lazy here, only use Simple CS original file replaces the file name: user.csusing system; using system.data.oledb;

// using clubstar.iplug; using clubstar;

Namespace clubstar.iplug.dataop {

public struct UserTable // user table structure variables {public int id; // public int sessionid; public string name; public string nickname; // public string password; // public bool sex; // public DateTime birthday; // public string City; // public int weightt; // public int hotht; // public string education; //////////// Public String education; // // PUBLIC INT Height; //

public int bloodtype; // public string xingzuo; public bool marry; public string job; // public string favorstar; // public string favordo; // public string introduce; // public string email; // public DateTime joindate; // Public datetime logindate; // public intend; // public string pic; // public string pic_id; // public int jifen; // public int renqi; // public int accessWho; ///////////// PUBLIC INT RENS

}

///

/// user's summary description. /// /// public class user: iplugstarclub {public condb_op utertable = connd_op.instance (); // Call the single mode mode for database connection protected string sqlstring = ""; public user () {} public User (string sql) {sqlstring = SQL;}

#Region iplugstarclub memory ///

/// Returns the name of the call plugin /// public string name {get {// Return "User_plugin: User Table Plugin"; Return "ClubStar.iplug.Dataop. User ";}}

///

/// user table operation /// /// public oledbdatarader performselect (iplugsql sql) {//sql.sqlstring=sqlstring; Return UserTable.executeReader (Sql.sqlstring);} public void PerformDelete (iPlugsql SQL) {//sql.sqlstring =sqlstring; userTable.executenonQuery (SQL.SQLSTRING);}

public void PerformInsert (IPlugSql sql) {//sql.SqlString=SqlString; UserTable.ExecuteNonQuery (sql.SqlString);} public void PerformUpdate (IPlugSql sql) {//sql.SqlString=SqlString; UserTable.ExecuteNonQuery (sql.SqlString) }

#ndregion

}} The write method for the database connection class is as follows: connd_op.csusing system; using system.data; using system.data.sqlclient; using system.data.oledb; using system.configuration;

Namespace ClubStar.iplug.dataop {///

/// connd_op summary description. /// Adopt Facade design mode to encapsulate all of the database-related operation //// public class connd_op {private oledbdataadapter Da = new oledbdataadapter (); private dataset ds = new dataset (); private oledbcommand cmd = new OleDbCommand (); public OleDbConnection MyConn; public OleDbDataReader dr; public string SqlString = ""; public string strConn = "Provider = SQLOLEDB;" ConfigurationSettings.AppSettings [ "clubstar"]; // database connection using Singleton pattern, only through Instance () to create the unique example private static connd_op connd_op = null; public static connd_op instance () {if (null == connd_op) connd_op = new connd_op (); return condb_op;}

Private connd_op (string sqlstring) {strconn = strconn; sqlstring = SQLSTRING;

Private connd_op () {} ........ The following file is used to actually handle the plugin's operation file name: PlugInsectionHandler.csusing system; use system.xml; useing system.configuration; use cloud clubstar.iplug; namespace clubstar { ///

/// This class implements IConfigurationSectionHandler and allows /// us to parse the "plugin" XML nodes found inside App.Config /// and return a PluginCollection object /// public class PluginSectionHandler : IConfigurationSectionHandler {Public PlugInsectionHandler () {} #Region IconfigurationSectionHandler MEMBERS

///

/// iprow through all the child nodes /// of the xmlnode That was passed in and create instances /// of the specified type by Reading the attribite value of the nodes /// we use a try / Catch here because some of the nodes /// might contain an invalid reference to a plugin type /// /// /// /// The xml section we will ity ity against /// /// public system.web.httpresponse DAI; public object Create (object parent, object configContext, System.Xml.XmlNode section) {PluginCollection plugins = new PluginCollection (); foreach (XmlNode node in section.ChildNodes) {try {// Use the Activator class's 'CreateInstance' method // To try and create an instance of the point name specified in the attribute value object plugobject = activator.createInstance (node.attype (node.attributes ["TATTYPUTES Ype "]. Value)); // Read the corresponding configuration section in WebConfig // Cast this to an iplugin interface and add to the collection iplugstarclub plugin = (iplugstarclub) PlugObject; plugins.add (plugin);} catch {/ / Catch any Exceptions // But Continue ITERATING more plugins //dai.write (section); throw;}} return plugins;} #endregion}

} And the following file is used to get the name information of the plugin: file name: plugsqlop.csusing system; using clubstar.iplug;

Namespace Clubstar {///

/// userop Summary Description. /// public class plugsqlop: iplugsql {private string m_user = ""; public plugsqlop (String user) {m_user = user;

#REGON PLUGSQLOP MEMBERS PUBLIC STRING SQLSTRING {Get {m_user = value;}} #ENDREGON}}

转载请注明原文地址:https://www.9cbs.com/read-82627.html

New Post(0)