zoukankan      html  css  js  c++  java
  • [置顶] 最近研究了下接口,对interface的有关总结

    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>");
            }

  • 相关阅读:
    改了一下分辨率,Areo特效奇迹般的恢复了...
    此连接需要活动的Internet连接
    Apple Mac OS X每日一技巧026:Spotlight打开文件所在的文件夹
    WP7有约(八):在ListPicker控件的选择页面上播放铃声
    WP7有约(七):实现铃声设置的播放图标的效果
    WP7有约(五):回到主页
    WP7有约:一个应用的破蛋过程
    WP7有约(六):AppBarUtils使用指南
    IE与firefox事件处理
    C#试题
  • 原文地址:https://www.cnblogs.com/luofuxian/p/2377474.html
Copyright © 2011-2022 走看看