往Services文件里面添加接口以及实现接口
IUserService接口
ListGetAllUser();
GetUserService类
ConnectToDatabase connect = new ConnectToDatabase(); ConnectObject connectObject = new ConnectObject(); public ListGetAllUser() { 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);
实现类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(); Listexpresses = 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; }
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(); ////// /// /// 省份 /// 城市 /// 区域 /// 街道 /// 用户名 /// 手机号码 /// 创建时间 /// 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。谢谢观赏。