最近研究了下接口,对interface的有关总结
2008-08-02 21:00
316 查看
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();
}
实现接口的类:
public class sk_usersclsCL : Sk_usersCL
{
private int puid;
private string pusername;
private string ppassword;
private string psex;
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 { psex = value; }
get { return psex; }
}
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;
}
创建一个逻辑层:
//创建接口
Sk_usersCL.Sk_usersCL userCL;
#region 定义属性,
private int puid;
private string pusername;
private string ppassword;
private string psex;
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 psex; }
set { psex = 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 = psex;
userCL.Connectionstring = GetConnstr();
return userCL.InsusersCL();
}
public int Updusers()
{
sk_usersclsCL users = new sk_usersclsCL();//创建数据层的对象
userCL = users; //赋值给接口对象,接口调用继承该接口的类
userCL.UserName = pusername;
userCL.PassWord = ppassword;
userCL.Sex = psex;
userCL.Connectionstring = GetConnstr();
return userCL.UpdusersCL();
}
}
表现层调用逻辑层:
Sk_usersBL.Class1 us = new Sk_usersBL.Class1(); //声明逻辑层的对象
us.UserName = TBusername.Text;
us.PassWord = TBpassword.Text;
if (us.Updusers() > 0)
{
Response.Write("<script language=javascript>alert('修改成功!')</script>");
}
else
{
Response.Write("<script language=javascript>alert('修改失败!')</script>");
}
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();
}
实现接口的类:
public class sk_usersclsCL : Sk_usersCL
{
private int puid;
private string pusername;
private string ppassword;
private string psex;
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 { psex = value; }
get { return psex; }
}
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;
}
创建一个逻辑层:
//创建接口
Sk_usersCL.Sk_usersCL userCL;
#region 定义属性,
private int puid;
private string pusername;
private string ppassword;
private string psex;
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 psex; }
set { psex = 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 = psex;
userCL.Connectionstring = GetConnstr();
return userCL.InsusersCL();
}
public int Updusers()
{
sk_usersclsCL users = new sk_usersclsCL();//创建数据层的对象
userCL = users; //赋值给接口对象,接口调用继承该接口的类
userCL.UserName = pusername;
userCL.PassWord = ppassword;
userCL.Sex = psex;
userCL.Connectionstring = GetConnstr();
return userCL.UpdusersCL();
}
}
表现层调用逻辑层:
Sk_usersBL.Class1 us = new Sk_usersBL.Class1(); //声明逻辑层的对象
us.UserName = TBusername.Text;
us.PassWord = TBpassword.Text;
if (us.Updusers() > 0)
{
Response.Write("<script language=javascript>alert('修改成功!')</script>");
}
else
{
Response.Write("<script language=javascript>alert('修改失败!')</script>");
}
相关文章推荐
- [置顶] 最近研究了下接口,对interface的有关总结
- Interface接口学习总结浅析
- 有关继承,实现接口,子类,实例化对象之间总结
- User Interface Process(UIP) Application Block 2.0 研究总结
- abstract(抽象类)和Interface(接口)总结
- User Interface Process(UIP) Application Block 2.0 研究总结
- Java之抽象(abstract)类、接口(interface)的用法总结
- 最近在研究JVM,总结设置Xmn的值不同对测试结果的影响:
- User Interface Process(UIP) Application Block 2.0 研究总结
- 关于static静态的、继承、接口interface、final关键字、单例设计模式总结
- User Interface Process(UIP) Application Block 2.0 研究总结
- User Interface Process(UIP) Application Block 2.0 研究总结
- User Interface Process(UIP) Application Block 2.0 研究总结
- Objective-C初步研究 - 接口文件(interface file)
- UserInterfaceProcess(UIP)AB2.0研究总结
- java接口interface知识点实例总结
- User Interface Process(UIP) Application Block 2.0 研究总结
- 最近研究libjingle的经验总结
- java学习总结(16.07.11—16.07.12)接口--interface
- User Interface Process(UIP) Application Block 2.0 研究总结