小菜鸟一步步打造图书馆外挂之六:数据访问服务工程
前面写好了数据访问工程DAL,但由于用户界面也要访问数据还有中间业务层也访问,为了访问方便还要处理一些业务逻辑,我们再给它封装一层DALService来操作DAL和对上层提供服务。
添加一个工程DALService,分别对DAL里面的每个类提供一个操作的类,把该工程里面的命名空间也都改成LibraryHelper.DALService,如下BookXMLService类是对DAL中BooXML类的操作,由于业务比较简单,基本上都是一些对DAL中的方法的调用,要注意的是在添加图书时,由于从图书馆网站上读取下来的数据可能与上次保存的有些交叉,但还是以本次读取下来的为准,由于数据量比较小,我们并没有做一些查找类的运算再添加不相同的数据删除没有的数据,而是在保存之后全部删除再进行全部插入这种简单的处理。
以下是各个类的方法,由于这里的方法只是对DAL中的方法的调用,我们也没有必要进行测试了,
BookXMLService类:
Code
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.Model;
6using LibraryHelper.DAL;
7
8namespace LibraryHelper.DALService
9{
10 public class BookXMLService
11 {
12 BookXML bookXml;
13 public BookXMLService()
14 {
15 bookXml = new BookXML();
16 }
17
18 //保存从网络上读取下来的数据,之前应删除所有的记录再保存
19 public void SaveBookList(List<Book> bookList)
20 {
21 bookXml.DeleteAllBook();
22
23 Int32 bookNum = bookList.Count;
24 for (Int32 i = 0; i < bookNum; i++)
25 {
26 Book insertBook = bookList[i];
27 bookXml.InsertBook(insertBook);
28 }
29 }
30
31 //取得所有图书
32 public List<Book> GetBookList()
33 {
34 return bookXml.GetBookList();
35 }
36
37 //手动添加记录
38 public Boolean InsertBook(Book insertBook)
39 {
40 return bookXml.InsertBook(insertBook);
41 }
42
43 //取得一条记录
44 public Book GetSingleBookByRowIndex(Int32 rowIndex)
45 {
46 return bookXml.GetSingleBookByRowIndex(rowIndex);
47 }
48
49 //删除一条记录
50 public Boolean DeleteBookByRowIndex(Int32 rowIndex)
51 {
52 return bookXml.DeleteBookByRowIndex(rowIndex);
53 }
54
55 //修改一条记录
56 public Boolean UpdataBookByRowIndex(Int32 rowIndex, Book updateBook)
57 {
58 return bookXml.UpdataBookByRowIndex(rowIndex, updateBook);
59 }
60 }
61}
62
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.Model;
6using LibraryHelper.DAL;
7
8namespace LibraryHelper.DALService
9{
10 public class BookXMLService
11 {
12 BookXML bookXml;
13 public BookXMLService()
14 {
15 bookXml = new BookXML();
16 }
17
18 //保存从网络上读取下来的数据,之前应删除所有的记录再保存
19 public void SaveBookList(List<Book> bookList)
20 {
21 bookXml.DeleteAllBook();
22
23 Int32 bookNum = bookList.Count;
24 for (Int32 i = 0; i < bookNum; i++)
25 {
26 Book insertBook = bookList[i];
27 bookXml.InsertBook(insertBook);
28 }
29 }
30
31 //取得所有图书
32 public List<Book> GetBookList()
33 {
34 return bookXml.GetBookList();
35 }
36
37 //手动添加记录
38 public Boolean InsertBook(Book insertBook)
39 {
40 return bookXml.InsertBook(insertBook);
41 }
42
43 //取得一条记录
44 public Book GetSingleBookByRowIndex(Int32 rowIndex)
45 {
46 return bookXml.GetSingleBookByRowIndex(rowIndex);
47 }
48
49 //删除一条记录
50 public Boolean DeleteBookByRowIndex(Int32 rowIndex)
51 {
52 return bookXml.DeleteBookByRowIndex(rowIndex);
53 }
54
55 //修改一条记录
56 public Boolean UpdataBookByRowIndex(Int32 rowIndex, Book updateBook)
57 {
58 return bookXml.UpdataBookByRowIndex(rowIndex, updateBook);
59 }
60 }
61}
62
UserXMLService类:
Code
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.DAL;
6using LibraryHelper.Model;
7
8namespace LibraryHelper.DALService
9{
10 public class UserXMLService
11 {
12 UserXML userXML;
13 public UserXMLService()
14 {
15 userXML = new UserXML();
16 }
17
18
19 //取得用户账号信息
20 public User GetUser()
21 {
22 return userXML.GetUser();
23 }
24
25 //保存用户信息
26 public Boolean SaveUser(User user)
27 {
28 return userXML.SaveUser(user);
29 }
30 }
31}
32
ADSLXMLService类:1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.DAL;
6using LibraryHelper.Model;
7
8namespace LibraryHelper.DALService
9{
10 public class UserXMLService
11 {
12 UserXML userXML;
13 public UserXMLService()
14 {
15 userXML = new UserXML();
16 }
17
18
19 //取得用户账号信息
20 public User GetUser()
21 {
22 return userXML.GetUser();
23 }
24
25 //保存用户信息
26 public Boolean SaveUser(User user)
27 {
28 return userXML.SaveUser(user);
29 }
30 }
31}
32
Code
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.DAL;
6
7namespace LibraryHelper.DALService
8{
9 public class ADSLXMLService
10 {
11 ADSLXML adslXML;
12
13 public ADSLXMLService()
14 {
15 adslXML = new ADSLXML();
16 }
17
18 //返回连接名
19 public String GetConnectionName()
20 {
21 return adslXML.GetConnectionName();
22 }
23
24 //返回用户名
25 public String GetUserName()
26 {
27 return adslXML.GetUserName();
28 }
29
30 //返回密码
31 public String GetUserPassword()
32 {
33 return adslXML.GetUserPassword();
34 }
35
36 //保存
37 public Boolean SaveADSL(String connectionName, String userName, String userPassword)
38 {
39 return adslXML.SaveADSL(connectionName,userName,userPassword);
40 }
41 }
42}
43
SettingXMLService类:
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.DAL;
6
7namespace LibraryHelper.DALService
8{
9 public class ADSLXMLService
10 {
11 ADSLXML adslXML;
12
13 public ADSLXMLService()
14 {
15 adslXML = new ADSLXML();
16 }
17
18 //返回连接名
19 public String GetConnectionName()
20 {
21 return adslXML.GetConnectionName();
22 }
23
24 //返回用户名
25 public String GetUserName()
26 {
27 return adslXML.GetUserName();
28 }
29
30 //返回密码
31 public String GetUserPassword()
32 {
33 return adslXML.GetUserPassword();
34 }
35
36 //保存
37 public Boolean SaveADSL(String connectionName, String userName, String userPassword)
38 {
39 return adslXML.SaveADSL(connectionName,userName,userPassword);
40 }
41 }
42}
43
Code
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.DAL;
6
7namespace LibraryHelper.DALService
8{
9 public class SettingXMLService
10 {
11 SettingXML settingXML;
12
13 public SettingXMLService()
14 {
15 settingXML = new SettingXML();
16 }
17
18 //取得进入警戒时间
19 public String GetWarningDay()
20 {
21 return settingXML.GetWarningDay();
22 }
23
24 //取得启动类型
25 public String GetStartType()
26 {
27 return settingXML.GetStartType();
28 }
29
30 //取得上次启动时间
31 public String GetLastStartTime()
32 {
33 return settingXML.GetLastStartTime();
34 }
35
36 //取得是否断开宽带连接
37 public String GetDisconnectionADSL()
38 {
39 return settingXML.GetDisconnectionADSL();
40 }
41
42 //设置上次启动时间
43 public void SetLastStartTime(String lastStartTime)
44 {
45 settingXML.SetLastStartTime(lastStartTime);
46 }
47
48 //设置进入警戒时间
49 public void SetWarningDay(String warningDay)
50 {
51 settingXML.SetWarningDay(warningDay);
52 }
53
54 //设置启动类型
55 public void SetStartType(String startType)
56 {
57 settingXML.SetStartType(startType);
58 }
59
60 //设置是否断开宽带连接
61 public void SetDisconnectionADSL(String isConnection)
62 {
63 settingXML.SetDisconnectionADSL(isConnection);
64 }
65 }
66}
67
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using LibraryHelper.DAL;
6
7namespace LibraryHelper.DALService
8{
9 public class SettingXMLService
10 {
11 SettingXML settingXML;
12
13 public SettingXMLService()
14 {
15 settingXML = new SettingXML();
16 }
17
18 //取得进入警戒时间
19 public String GetWarningDay()
20 {
21 return settingXML.GetWarningDay();
22 }
23
24 //取得启动类型
25 public String GetStartType()
26 {
27 return settingXML.GetStartType();
28 }
29
30 //取得上次启动时间
31 public String GetLastStartTime()
32 {
33 return settingXML.GetLastStartTime();
34 }
35
36 //取得是否断开宽带连接
37 public String GetDisconnectionADSL()
38 {
39 return settingXML.GetDisconnectionADSL();
40 }
41
42 //设置上次启动时间
43 public void SetLastStartTime(String lastStartTime)
44 {
45 settingXML.SetLastStartTime(lastStartTime);
46 }
47
48 //设置进入警戒时间
49 public void SetWarningDay(String warningDay)
50 {
51 settingXML.SetWarningDay(warningDay);
52 }
53
54 //设置启动类型
55 public void SetStartType(String startType)
56 {
57 settingXML.SetStartType(startType);
58 }
59
60 //设置是否断开宽带连接
61 public void SetDisconnectionADSL(String isConnection)
62 {
63 settingXML.SetDisconnectionADSL(isConnection);
64 }
65 }
66}
67