Software for memorizing words-Design and Implementation

Source: Internet
Author: User

2014-08-28

Layer-3 Structure

Data access layer

Business logic layer

Presentation Layer

Data Structure

Technical Points

Lessons learned

Reference

Layer-3 Structure

Return

Three-tier structure advantages: clear responsibilities, easy to understand, improved code reuse rate, easy to modify.

Three-tier structure disadvantages: the upper layer depends on the lower layer, and the lower layer must be modified accordingly.

Figure 1 Solution

As shown in figure 1, the software is a three-tier structure, namely the presentation layer, business logic layer, and data access layer. The layer-3 structure is the upper-layer invocation layer: presentation layer-> business logic layer-> data access layer, and presentation layer-> data access layer.

Data access layer

The data access layer provides simple operations (add, delete, modify, and query) on permanent layer data (such as files and databases ).

Note: this layer of operation logic must be simple and easy to call at the business logic layer.

Figure 2 shows taskdataaccess methods and attributes. Only the operations for adding, deleting, modifying, querying, creating, and saving XML files are supported.

Figure 2 taskdataaccess

Business logic layer

If the data access layer method is relatively simple, the data access layer method is relatively complex and has a higher granularity. More judgment and related operations are added.

The following are the main public methods of taskdatacontrol. CS:

 1 public void Refresh(); 2 public List<string> ReciteUnitNow(); 3 public void AutoChangeRecitePeriod(string unitName, DateTime dt); 4 public void RedoRecitePeriod(string unitName); 5 public void RedoReciteUnit(string unitName); 6 public void ReDoFilterUnit(string unitName); 7 public void CompleteRecitePeriod(string unitName); 8 public void CompleteReciteUnit(string unitName); 9 public void DeleteUnit(string unitName);10 public void FilterUnit(string unitName);11 public void ReciteUnit(string unitName);
View code

 

Presentation Layer

The presentation layer includes the interface design and status. Taking frmreciteword_task as an example, it includes the frmreciteword_task interface, the code behind the scenes, and taskdiplay. CS. Taskdisplay. CS is mainly responsible for separating the interface status to facilitate understanding and reuse.

Data Structure

Return

Permanent Layer

File taskfile. xml

 1 <?xml version="1.0"?> 2 <Units> 3   <Unit Name="Lession01" UnitStatus="Complete" /> 4   <Unit Name="Lession02" UnitStatus="Start"> 5     <Detail Period="2" PeriodStatus="Complete" CurrentReciteTime="8/27/2014 11:04:26 PM" /> 6   </Unit> 7   <Unit Name="Lession03" UnitStatus="Start"> 8     <Detail Period="2" PeriodStatus="Start" CurrentReciteTime="8/27/2014 11:04:26 PM" /> 9   </Unit>10   <Unit Name="Lession04" UnitStatus="Start">11     <Detail Period="0" PeriodStatus="Start" CurrentReciteTime="8/27/2014 11:01:26 PM" />12   </Unit>13   <Unit Name="Lession05" UnitStatus="Start">14     <Detail Period="0" PeriodStatus="Start" CurrentReciteTime="8/27/2014 09:01:26 PM" />15   </Unit>16   <Unit Name="Lession06" UnitStatus="Filter" />17   <Unit Name="Lession07" UnitStatus="Raw" />18 </Units>
View code

We can see that the properties of the permanent layer include: name, unitstatus, period, periodstatus, currentrecitetime

Business logic layer

File taskdatacontrol. CS

Figure 3 Task business data Constructor

The business logic layer attributes include: name, unitstatus, period, periodstatus, currentrecitetime, priority, and nextrecitetime. Here, priority and nextrecitetime are calculated.

Among these attributes, unitstatus and periodstatus are similar. Their values are listed one by one using enumeration:

1 enum EnumTaskUnitStatus { Start, Complete, Raw, Filter }2 enum EnumTaskPeriodStatus { Start, Complete }

We can see that both the start and complete statuses are available. To remember words in the text permanently, you need to remember and forget words in multiple cycles. Unitstatus start and complet refer to start learning and end at the end. periodstatus start and complete only end at the beginning of the current cycle.

Note:: When you have a vague understanding of a property in a data structure, you must stop and think clearly. Clear design makes it easy to implement.

Of course, the data structure of the permanent layer and the data structure of the business logic layer do not have to be exactly one-to-one, depending on the actual situation.

Difficulties and Solutions

Return

Automatic playback of recite

At that time, I wanted to use a thread, and then directly change the value of the control in winform in the thread to change the winform interface display. However, this will throw an exception:

Cross-thread operation not valid: Control accessed from a thread other than the trhead it was created on.

The solution is to change the control value through control. invoke. Detailed Principles:

Winform (1) message loop

Winform 2nd three things (1) Addendum

Winform two three things (2) Asynchronous Operation

Winform 2: 3 events (3) control. Invoke & control. begininvoke

Playback pause function of recite

As mentioned above, automatic playback is implemented through thread. Originally, the pause function was intended to be implemented through suspend (), but the depreciated method of Net Framework mark in a later version. Therefore, to find another way, use the autoresetevent class to notify thread wait or contiune. Sample Code:

 1     public partial class Form1 : Form 2     { 3         System.Windows.Forms.Timer tm = new System.Windows.Forms.Timer(); 4  5         //through autoEvent notify a thread waiting or continue 6         AutoResetEvent autoEvent = new AutoResetEvent(false);         7  8         public Form1() 9         {10             InitializeComponent();11             ProgressBar.CheckForIllegalCrossThreadCalls = false;12 13             14             tm.Interval = 1;15             tm.Tick += new EventHandler(tm_Tick);            16         }17 18         void tm_Tick(object sender, EventArgs e)19         {20             autoEvent.Set(); //allow waiting thread proceed    21         }22         23 24         //method for thread   25         private void DoWork()26         {27             while (progressBar1.Value < progressBar1.Maximum)28             {29                 progressBar1.PerformStep();30                 System.Threading.Thread.Sleep(100);31                 autoEvent.WaitOne();  //Block current thread until autoEvent.Set()    32             }33         }34 35         private void btnStart_Click(object sender, EventArgs e)36         {37             tm.Start();38 39             Thread t = new Thread(DoWork);40             t.Start();41             t.Suspend();42         }43 44         private void btnSuspend_Click(object sender, EventArgs e)45         {46             tm.Stop();47         }48 49         private void btnResume_Click(object sender, EventArgs e)50         {51             tm.Start();52         }   53     }
Pass data between view code windows

The following two methods are used:

  • Public attributes
  • Set a separate class through static set and get Methods
Set Information Processing

For setting information, see the setting function in the previous article. It can be stored in an xml configuration file. But to make the program simpler, put the information in the registry. The static methods of set and get registries are stored in the utility. CS file.

Lessons learned

Return

Reference

Software for memorizing words-Design and Implementation

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.