【机房重构】——增删改查(一)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/MirabelleZWH/article/details/84336305

【增】

UI层

            
Entity.UserInfo user = new Entity.UserInfo();
user.UserID = txtUserID.Text.Trim();
Facade.StuFacade facade = new Facade.StuFacade();
                                          
//将信息填到UserInfo表里
user.UserID = txtUserID.Text.Trim();
user.UserName = txtUserName.Text.Trim();
user.Password = txtPassword.Text.Trim();

bool userfalg = facade.addUser(user);

门面层

    public class StuFacade
    {
        public bool addUser(Entity.UserInfo user)
        {
            bool falg;
            BLL.StuBLL addStuBLL = new StuBLL();
            falg = addStuBLL.addUser(user);
            return falg;
        }
    }

BLL层

    public class StuBLL
    {       
         public bool addUser(Entity.UserInfo user)
        {
            Factory.LoginFactory fact = new Factory.LoginFactory();
            IDAL.StuIDAL idal = fact.User();
            int result = idal.addUser(user);//接收D层返回值
            bool falg;
            if (result == 0)
            {
                falg = false;
            }
            else
            {
                falg = true;
            }
            return falg; 
        }
    }

工厂层

    public class LoginFactory
    {
        public IDAL.StuIDAL User()
        {
            string ClassName = strDB + "." + "StuDAL";
            return (IDAL.StuIDAL)Assembly.Load(strDB).CreateInstance(ClassName);
        }
    }

IDAL层

    public interface StuIDAL
    {
        int addUser(Entity.UserInfo user);
    }

DAL层

    public class StuDAL:IDAL.StuIDAL
    {
        public int addUser(Entity.UserInfo user)
        {
            SqlHelper sqlHelper = new SqlHelper();
            string sql = "INSERT INTO userInfo(UserID,UserName,Password)values(@UserID,@UserName,@Password)";
            SqlParameter[] sqlParams = 
            {
                new SqlParameter("@UserID",user.UserID),                
                new SqlParameter("@UserName",user.UserName ),
                new SqlParameter("@Password",user.Password ),
            };

            int result = sqlHelper.ExecuteNonQuery(sql, sqlParams, CommandType.Text);
            return result;
        }
    }

猜你喜欢

转载自blog.csdn.net/MirabelleZWH/article/details/84336305
今日推荐