Asp.net class and instance details

Source: Internet
Author: User

Class and instance

Each object is different from other objects, but some objects may have similarities.

A class is the abstraction of an object, and an object is an instance of a class.

Class

Function stringbuffer (){
This. _ strings _ = new array ();
}
Stringbuffer. prototype. append = function (str ){
This. _ strings _. push (str );
};
Stringbuffer. prototype. tostring = function (){
Return this. _ strings _. join ("");
};

It can be considered that objects with the same behavior belong to the same class, and a "class" is a general classification of all similar objects.


A class is a prototype that defines the State and behavior of a certain type of object. It represents an abstraction of A Class of common objects in real life.


A class has an attribute. It is an abstraction of the object state and describes the attributes of a class using a data structure.

A class has operations. It is an abstraction of object behavior and is described by an operation name and an operation discount method.


Class allows me to describe the common behavior of a group of objects in a certain aspect, and then create an object with that behavior method when we need an object.


Instance

An object that represents behavior by a class in a specified way is called an "instance" of this class ". all objects are instances of some classes. Once an instance is created, it performs the same behavior as other instances of this class. Can receive messages to complete any operation specified by its method. In order to perform other operations in its name, this instance can also call other instances or other class instances.


Inheritance


Inheritance is an effective way to extend existing types in object-oriented languages.

Class is an extension of the inherited class.


Inheritance is the mechanism by which child classes automatically share the data structures and methods of parent classes. This is a relationship between classes. when defining and implementing a class, you can base an existing class, take the content defined by this existing class as your own content, and add some new content.


Inheritance features single inheritance:

A subclass can have only one superclass, while a superclass can have multiple subclasses.

Subclass inherits all non-private members of a super class

Sub-classes can create their own members.

The subclass cannot inherit the constructor of the superclass, but allows the sub-class to access the constructor of the superclass.


Subclass/derived class


A subclass is a class that inherits behavior from another class. A subclass usually adds its own behavior to define its own unique object type.


Superclass/parent class/base class


A superclass is a class that inherits special behaviors. A class can have a superclass and multiple superclasses.


Abstract class

Classes that do not need to generate instances or declare methods without implementing them are called "abstract classes". abstract classes cannot be instantiated and can only be used as superclasses of other classes. They are just a kind of existence. They can extract all kinds of common behaviors to a common place and make a definition there (if necessary, you only need to modify it once ), it can be used repeatedly. Abstract classes fully define their behaviors, but they do not need to be fully implemented. They can also define methods that are redefined by all subclasses. There may be a default implementation of a behavior to prevent system errors. You can improve or increase the implementation methods in the subclass to achieve this.

Take a look at a common asp tutorial. net access Data Encryption Class

Using system;
Using system. data;
Using system. configuration;
Using system. collections;
Using system. web;
Using system. web. security;
Using system. web. ui;
Using system. web. ui. webcontrols;
Using system. web. ui. webcontrols. webparts;
Using system.web.ui.html controls;
Using system. data. oledb;

// My using.


Using system. io;

/// <Summary>
/// Security -- manage user -- role -- power -- resource
/// </Summary>
/// <Summary>
/// Dbutil
/// </Summary>
Public abstract class dbutil
{

 


Public static string connectionstring = configurationmanager. apps tutorial ettings ["connectionstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"]);



/// <Summary>
/// Internal function to prepare a command for execution by the database
/// </Summary> se
/// <Param name = "cmd"> existing command object </param>
/// <Param name = "conn"> database connection object </param>
/// <Param name = "partition type"> command type, e.g. stored procedure </param
/// <Param name = "plain text"> command text </param>
Private static void preparecommand (oledbcommand cmd, oledbconnection conn, commandtype primitive type, string plain text)
{


// Open the connection if required
If (conn. state! = Connectionstate. open)
Conn. open ();

// Set up the command
Cmd. connection = conn;
Cmd. commandtext = plain text;
Cmd. commandtype = primitive type;

}

/// <Summary>
/// Execute an oraclecommand (that returns no resultset) against an existing database transaction
/// Using the provided parameters.
/// </Summary>
/// <Remarks>
/// E.g .:
/// Int result = executenonquery (trans, commandtype. storedprocedure, "publishorders", new parameter (": prodid", 24 ));
/// </Remarks>
/// <Param name = "commandtext"> the stored procedure name or pl/SQL command </param>
/// <Returns> an int representing the number of rows affected by the command </returns>
Public static int executenonquery (string plain text)
{
// Create a new oracle command

Oledbcommand cmd = new oledbcommand ();

// Create a connection
Using (oledbconnection connection = new oledbconnection (configurationmanager. appsettings ["connectionstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"])
{

// Prepare the command
Preparecommand (cmd, connection, commandtype. text, plain text );

// Execute the command
Int rowsaffected = cmd.exe cutenonquery ();

Return rowsaffected;
}
}


/// <Summary>
/// Execute a select query that will return a result set
/// </Summary>
/// <Param name = "commandtext"> the stored procedure name or pl/SQL command </param>
/// <Returns> </returns>
Public static oledbdatareader executereader (string plain text)
{
// Create the command and connection
Oledbcommand cmd = new oledbcommand ();
Oledbconnection conn = new oledbconnection (configurationmanager. appsettings ["connectionstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"]);

Try
{
// Prepare the command to execute
Preparecommand (cmd, conn, commandtype. text, plain text );

// Execute the query, stating that the connection shoshould close when the resulting datareader has been read
Oledbdatareader rdr = cmd.exe cutereader (commandbehavior. closeconnection );
Return rdr;

}
Catch
{

// If an error occurs close the connection as the reader will not be used and we have CT it to close the connection
Conn. close ();
Throw;
}
}


/// <Summary>
/// Execute an oraclecommand that returns the first column of the first record against the database specified in the connection string
/// </Summary>
/// <Param name = "commandtext"> the stored procedure name or pl/SQL command </param>
/// <Returns> an object that shocould be converted to the expected type using convert. to {type} </returns>
Public static object executescalar (string plain text)
{
Oledbcommand cmd = new oledbcommand ();
Using (oledbconnection conn = new oledbconnection (configurationmanager. appsettings ["connectionstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"])
{
Preparecommand (cmd, conn, commandtype. text, plain text );
Object val = cmd.exe cutescalar ();
Return val;
}
}

/// <Summary>
/// Execute the SQL statement for uploading blob files
/// </Summary>
/// <Param name = "plain text"> run the SQL command to mark the file field value with ": files". </param>
/// <Param name = "filefullname"> full file path </param>
/// <Returns> </returns>
Public static int uploadfile (string plain text, string filefullname)
{
// Create a new oracle command
Oledbcommand cmd = new oledbcommand ();

// Create a connection
Using (oledbconnection conn = new oledbconnection (configurationmanager. appsettings ["connectionstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"])
{

// Prepare the command
Preparecommand (cmd, conn, commandtype. text, plain text );

// Upload file
Filestream fs = file. openread (filefullname );
Byte [] content = new byte [fs. length];
Fs. read (content, 0, content. length );
Fs. close ();

Cmd. parameters. add ("@ files", system. data. oledb. oledbtype. binary). value = content;

// Execute the command
Int rowsaffected = cmd.exe cutenonquery ();

Return rowsaffected;
}
}

 

Public static dataset getdataset (string plain text)
{
Oledbcommand cmd = new oledbcommand ();

Using (oledbconnection conn = new oledbconnection (configurationmanager. appsettings ["connectionstring"]. tostring () + system. web. httpcontext. current. server. mappath (configurationmanager. appsettings ["dbpath"])
{
Preparecommand (cmd, conn, commandtype. text, plain text );

Oledbdataadapter apr = new oledbdataadapter (cmd );

Dataset ds = new dataset ();
Apr. fill (ds );

Return ds;
}
}
}


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.