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

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

IUserService接口

        List<User> GetAllUser();

GetUserService类

        ConnectToDatabase connect = new ConnectToDatabase();

        ConnectObject connectObject = new ConnectObject();
        public List<User> GetAllUser()
        {
            connectObject.SQLRead = "select * from User";
            List<User> users = new List<User>();
            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);

实现类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;
        }

IExpressService接口

        Express GetExpressData();

GetExpressService实现类

        ConnectToDatabase connect = new ConnectToDatabase();

        ConnectObject connectObject = new ConnectObject();
        List<Express> expresses = new List<Express>();
        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;
        }

ICreateExpressService接口

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

InsertExpressService实现类

        ConnectToDatabase connect = new ConnectToDatabase();

        ConnectObject connectObject = new ConnectObject();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="province">省份</param>
        /// <param name="city">城市</param>
        /// <param name="area">区域</param>
        /// <param name="streat">街道</param>
        /// <param name="username">用户名</param>
        /// <param name="phonenumber">手机号码</param>
        /// <param name="createtime">创建时间</param>
        /// <returns></returns>
        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。谢谢观赏。

 

posted @ 2019-07-15 12:53  Lexan  阅读(723)  评论(0编辑  收藏  举报