简单的物流项目实战,WPF的MVVM设计模式(三)

往Services文件里面添加接口以及实现接口

IUserService接口

        List GetAllUser();

简单的物流项目实战,WPF的MVVM设计模式(三)_第1张图片

GetUserService类

简单的物流项目实战,WPF的MVVM设计模式(三)_第2张图片

        ConnectToDatabase connect = new ConnectToDatabase();

        ConnectObject connectObject = new ConnectObject();
        public List GetAllUser()
        {
            connectObject.SQLRead = "select * from User";
            List users = new List();
            SQLiteCommand command = new SQLiteCommand(connectObject.SQLRead, connect.SQLiteConnections);
            SQLiteDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                User user = new User();
                user.UserAccount = reader["UserAccount"].ToString();
                user.Password = reader["Password"].ToString();
                users.Add(user);
            }
            return users;

        }

IRegisteredService接口

     User InsertUser(string useraccount, string password);

简单的物流项目实战,WPF的MVVM设计模式(三)_第3张图片

实现类InsertRegisteredService

        ConnectToDatabase connect = new ConnectToDatabase();

        ConnectObject connectObject = new ConnectObject();
        User insertuser = new User();
        public User InsertUser(string useraccount, string password)
        {
            //User insertuser = new User();
            connectObject.SQLInsert = "insert into User (UserAccount,Password) values('" + useraccount + "','" + password + "')";
            SQLiteCommand command = new SQLiteCommand(connectObject.SQLInsert, connect.SQLiteConnections);
            command.ExecuteNonQuery();
            insertuser.Password = password;
            insertuser.UserAccount = useraccount;
            return insertuser;
        }

简单的物流项目实战,WPF的MVVM设计模式(三)_第4张图片

IExpressService接口

        Express GetExpressData();

简单的物流项目实战,WPF的MVVM设计模式(三)_第5张图片

GetExpressService实现类

        ConnectToDatabase connect = new ConnectToDatabase();

        ConnectObject connectObject = new ConnectObject();
        List expresses = new List();
        public Express GetExpressData()
        {
            connectObject.SQLRead = "select * from Express";
            SQLiteCommand command = new SQLiteCommand(connectObject.SQLRead, connect.SQLiteConnections);
            SQLiteDataReader reader = command.ExecuteReader();
            Express expresses = new Express();
            while (reader.Read())
            {
                expresses.Province = reader["Province"].ToString();
                expresses.City = reader["City"].ToString();
                expresses.Area = reader["Area"].ToString();
                expresses.Street = reader["Street"].ToString();
                expresses.UserName = reader["UserName"].ToString();
                expresses.PhoneNumber = reader["PhoneNumber"].ToString();
                expresses.CteateTime = reader["CteateTime"].ToString();
            }
            return expresses;
        }

简单的物流项目实战,WPF的MVVM设计模式(三)_第6张图片

ICreateExpressService接口

        Express InsertExpress(string province, string city, string area, string streat, string username, string phonenumber, string createtime);

简单的物流项目实战,WPF的MVVM设计模式(三)_第7张图片

InsertExpressService实现类

简单的物流项目实战,WPF的MVVM设计模式(三)_第8张图片

        ConnectToDatabase connect = new ConnectToDatabase();

        ConnectObject connectObject = new ConnectObject();

        /// 
        /// 
        /// 
        /// 省份
        /// 城市
        /// 区域
        /// 街道
        /// 用户名
        /// 手机号码
        /// 创建时间
        /// 
        public Express InsertExpress(string province, string city, string area, string streat, string username, string phonenumber, string createtime)
        {
            Express express = new Express();
            connectObject.SQLInsert = "insert into Express(province,city,area,street,username,phonenumber,cteateTime) values('" + province + "','" + city + "','" + area + "','" + streat + "','" + username + "','" + phonenumber + "','" + createtime+ "')";
            SQLiteCommand command = new SQLiteCommand(connectObject.SQLInsert, connect.SQLiteConnections);
            command.ExecuteNonQuery();

            express.Province = province;
            express.City = city;
            express.Area = area;
            express.Street = streat;
            express.UserName = username;
            express.PhoneNumber = phonenumber;
            express.CteateTime = createtime;

            return express;
        }

服务层就先到这里,下一篇讲ViewModels。谢谢观赏。

 

你可能感兴趣的:(简单的物流项目实战,WPF的MVVM设计模式(三))