I have recently studied the interfaces and summarized them.

Source: Internet
Author: User

Interface defined in C:

Public interface sk_userscl
{
Int uid {Get ;}
String username {set; get ;}
String password {set; get ;}
String sex {set; get ;}
String connectionstring {set; get ;}
Int insuserscl ();
Int getdatauserscl ();

}

Classes that implement interfaces:

Public class sk_usersclscl: sk_userscl
{
Private int puid;
Private string pusername;
Private string ppassword;
Private string limit X;
Private string pconnectionstring;
Private SqlConnection conn;

Public int Uid
{
Get {return puid ;}
}
Public string UserName
{
Set {pusername = value ;}
Get {return pusername ;}
}
Public String Password
{
Set {ppassword = value ;}
Get {return ppassword ;}
}
Public String sex
{
Set {struct x = value ;}
Get {return response X ;}
}
Public String connectionstring
{
Set {pconnectionstring = value ;}
Get {return pconnectionstring ;}
}
Public void open ()
{
Conn = new sqlconnection (pconnectionstring );
If (conn. State = system. Data. connectionstate. Closed)
{
Conn. Open ();
}
}
Public void Close ()
{
If (conn. State = System. Data. ConnectionState. Open)
{
Conn. Close ();
}
}
Public int InsusersCL ()
{
Open ();
String strinssql = "insert into users (user_name, pwd, sex) values ('" + UserName + "', '" + PassWord + "', '" + Sex + "') ";
SqlCommand cmd = new SqlCommand (strinssql, conn );
Int intnum = cmd. ExecuteNonQuery ();
Close ();
Return intnum;
}

Public int UpdusersCL ()
{
Open ();
String strupdsql = "update users set pwd = '" + PassWord + "'where user_name ='" + UserName + "'";
SqlCommand cmd = new SqlCommand (strupdsql, conn );
Int rcount = cmd. ExecuteNonQuery ();
Close ();
Return rcount;
}
Create a logic layer:

// Create an interface
Sk_usersCL.Sk_usersCL userCL;
# Region defines attributes,
Private int puid;
Private string pusername;
Private string ppassword;
Private string limit X;
Private string pconnstr;
Public int Uid
{
Get {return puid ;}
Set {puid = value ;}
}
Public string UserName
{
Get {return pusername ;}
Set {pusername = value ;}
}
Public String Password
{
Get {return ppassword ;}
Set {ppassword = value ;}
}
Public String sex
{
Get {return response X ;}
Set {struct x = value ;}
}
Public string Connectionstring
{
Get {return pconnstr ;}
Set {pconnstr = value ;}
}
# Endregion
Public string GetConnstr ()
{
Return "server = Data-11; User id = 11; Pwd = 11; database = 11 ";
}
Public int insusers ()
{
Sk_usersclsCL users = new sk_usersclsCL ();
UserCL = users;
UserCL. UserName = pusername;
UserCL. PassWord = ppassword;
UserCL. Sex = policx;
UserCL. Connectionstring = GetConnstr ();
Return userCL. InsusersCL ();
}

Public int Updusers ()
{
Sk_usersclsCL users = new sk_usersclsCL (); // creates an object at the data layer.
UserCL = users; // assign a value to the interface object. An interface call inherits the class of this interface.
UserCL. UserName = pusername;
UserCL. PassWord = ppassword;
UserCL. Sex = policx;
UserCL. Connectionstring = GetConnstr ();
Return userCL. UpdusersCL ();
}
}

Presentation Layer call logic layer:

Sk_usersBL.Class1 us = new Sk_usersBL.Class1 (); // declares the object of the logic layer.
Us. UserName = TBusername. Text;
Us. PassWord = TBpassword. Text;
If (us. Updusers ()> 0)
{
Response. Write ("<script language = javascript> alert ('modification successful! ') </Script> ");
}
Else
{
Response. Write ("<script language = javascript> alert ('modification failed! ') </Script> ");
}

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.