Little cainiao builds library plug-ins step by step: Extracts books that enter the warning Scope

Source: Internet
Author: User
The flowchart shows that when Program During Automatic startup, you need to worry about entering the prompt box from the books you read, regardless of whether the network connection is normal or not. Therefore, it is necessary to implement this implementation separately to avoid repeated work.
Create a project sendwarningbook, add a class named warningbookservice, and add the expected reference. The function of this class is very simple, that is, to enter a collection of library classes, then it reads the time set by the user from the local XML file to enter the warning range, and compares the time with the time of the books that are sent in, if the requirements are met, send a prompt box. If the requirements are not met, exit the program.
Another problem here is that when the network connection is normal and abnormal, the processing is a little different. When the network connection is normal, it is waiting for application. run () and then it comes here. If it is abnormal, there is no application. run () is here, so when there is no book into the warning scope, we can not directly exit the program, it returns a value to determine whether there is a book into the warning scope.
This class provides a constructor to receive a collection of books and a method for sending execution.
The implementation is as follows:

Code
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. Windows. forms;

UsingLibraryhelper. model;
UsingLibraryhelper. dalservice;
UsingLibraryhelper. warningui;

Namespace Libraryhelper. sendwarningbook
{
Public   Class Warningbookservice
{
// Book entering alert range
List < Book > Warningbooklist =   New List < Book > ();
// All the books read
List < Book > Allbooklist;

Boolean isrun =   True ; // Set whether to start the run method of the application. If the book does not enter the warning scope, it will not start.

Public Warningbookservice (list < Book > Allbooklist)
{
This . Allbooklist = Allbooklist;
}

Public Boolean sendwarningbook ()
{< br> /// days in which the alert range is obtained from the configuration file
settingxmlservice = New settingxmlservice ();
int32 warningday = convert. toint32 (settingxmlservice. getwarningday ();

//Current Time
Datetime timenow=Datetime. now;

// Traverse all the books and find out
Int32 booknum = Allbooklist. count;
For (Int32 I =   0 ; I < Booknum; I ++ )
{
// Time of Returning books
Datetime timereturn = Allbooklist [I]. returndate;
// Time Difference
Timespan = Timereturn - Timenow;
// Days only
Int32 daynum = Timespan. days;

// If the time difference is less than or equal to the set number of days, add the prompt box.
If (Warningday > = Daynum)
{
Allbooklist [I]. warningday = Daynum;
Warningbooklist. Add (allbooklist [I]);
}
}

// If there is any warning range, a prompt box will pop up, and the program will be exited if there is no warning range
If (Warningbooklist. Count >   0 )
{
Frmwarning FRM =   New Frmwarning (warningbooklist );
FRM. Show ();
}
Else
{
Isrun =   False ; // When the network connection is abnormal and the books that do not enter the warning range return false and do not start the run method.
Application. Exit (); // When the network connection is normal, the run method has been started, and some methods are used to exit the program
}

ReturnIsrun;
}
}
}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.