码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2019-07-15 13:26:52      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:简单的   mvvm   rom   comm   col   sqli   base   ssd   pass   

往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。谢谢观赏。

 

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

标签:简单的   mvvm   rom   comm   col   sqli   base   ssd   pass   

原文地址:https://www.cnblogs.com/R00R/p/11188235.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!