小菜鸟一步步打造图书馆外挂之十一:IDoWork接口的各种实现
根据流程图可以看到当程序启动时再根据网络连接状况可能有四种方式来实现IDoWork:
(一)当程序自动启动而网络连接正常时要做的工作是读取数据发送到警戒框,保存到本地XML文件,用HttpSendToWarningUI类去实现抽象类的SendBookList方法,实现把图书信息发到警戒框
(二)当程序手动启动而网络连接正常时要做的工作是读取数据更新用户编辑界面,保存到本地XML文件,用HttpSendToEditUI去实现抽象类的SendBookList方法,把读取下来的数据去更新用户编辑界面的数据
(三)当自动启动程序而网络连接不正常时要做的工作是读取本地的数据发送给用户,我们用GetBookFromXMl类去实现IDoWork接口
(四)当手动启动程序而网络连接不正常时什么事也不做,我们用DoNothing类去实现IDoWork接口,什么事也没有做,只返回一个真值
创建DoWork工程,添加相应的引用。
using System;
using System.Collections.Generic;
using System.Text;
using LibraryHelper.SendWarningBook;
using LibraryHelper.HttpService;
namespace LibraryHelper.DoWork
{
public class HttpSendToWarningUI:AbsHttp
{
protected override void SendBookList()
{
WarningBookService warningBookService = new WarningBookService(bookList);
warningBookService.SendWarningBook();
}
}
}
using System.Collections.Generic;
using System.Text;
using LibraryHelper.SendWarningBook;
using LibraryHelper.HttpService;
namespace LibraryHelper.DoWork
{
public class HttpSendToWarningUI:AbsHttp
{
protected override void SendBookList()
{
WarningBookService warningBookService = new WarningBookService(bookList);
warningBookService.SendWarningBook();
}
}
}
HttpSendToEditUI类实现如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using LibraryHelper.EditUI;
using LibraryHelper.HttpService;
namespace LibraryHelper.DoWork
{
public class HttpSendToEditUI:AbsHttp
{
protected override void SendBookList()
{
frmLiraryEdit frmEdit = frmLiraryEdit.GetSinglefrmEdit();
frmEdit.DataBindBook(bookList);
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using LibraryHelper.EditUI;
using LibraryHelper.HttpService;
namespace LibraryHelper.DoWork
{
public class HttpSendToEditUI:AbsHttp
{
protected override void SendBookList()
{
frmLiraryEdit frmEdit = frmLiraryEdit.GetSinglefrmEdit();
frmEdit.DataBindBook(bookList);
}
}
}
GetBookFromXMl类实现如下:
using System;
using System.Collections.Generic;
using System.Text;
using LibraryHelper.IDoWork;
using LibraryHelper.DALService;
using LibraryHelper.SendWarningBook;
using LibraryHelper.Model;
namespace LibraryHelper.DoWork
{
public class GetBookFromXMl : ILibraryHelperDoWork
{
public Boolean DoWork()
{
BookXMLService bookXMLService = new BookXMLService();
List<Book> bookList = bookXMLService.GetBookList();
WarningBookService warningBookService = new WarningBookService(bookList);
Boolean isRun = warningBookService.SendWarningBook();
return isRun;
}
}
}
using System.Collections.Generic;
using System.Text;
using LibraryHelper.IDoWork;
using LibraryHelper.DALService;
using LibraryHelper.SendWarningBook;
using LibraryHelper.Model;
namespace LibraryHelper.DoWork
{
public class GetBookFromXMl : ILibraryHelperDoWork
{
public Boolean DoWork()
{
BookXMLService bookXMLService = new BookXMLService();
List<Book> bookList = bookXMLService.GetBookList();
WarningBookService warningBookService = new WarningBookService(bookList);
Boolean isRun = warningBookService.SendWarningBook();
return isRun;
}
}
}
DoNothing类实现如下:
using System;
using System.Collections.Generic;
using System.Text;
using LibraryHelper.IDoWork;
namespace LibraryHelper.DoWork
{
public class DoNothing : ILibraryHelperDoWork
{
public Boolean DoWork()
{
//空方法,什么也不做
return false;
}
}
}
using System.Collections.Generic;
using System.Text;
using LibraryHelper.IDoWork;
namespace LibraryHelper.DoWork
{
public class DoNothing : ILibraryHelperDoWork
{
public Boolean DoWork()
{
//空方法,什么也不做
return false;
}
}
}