Multi-state applications

Source: Internet
Author: User

Recently in the school's SRTP project-Student Information management system, which involves the following information on the database operations. Of course, before the persistence of the data to verify the legality, if the illegal to prompt reasonable information, if there are other problems will throw an exception.

This information is sorted almost by species, each class of data table, that is, a class of entities, in addition to individual entity attributes different operations on the difference is not big. So how do you make a unified operation of this information? This is where polymorphism is used. Let's use my implementation as an example, if you have any good ideas can be put forward, the wrong place to want to point out. Thank you, hehe!

Information involved:

1. Basic information: School number, Name, class, professional, age, ID number, native place, etc.

2. Family information: Home address, home phone, family member information, etc.

3. Scholarship information: Including the amount of scholarship awarded, time, project, etc.

4. Activity information: Participation in activities, activities held time, results of activities, etc.

5. Funding information: Funded projects, funding amount, funding time, etc.

6. Disposition Information: The disposition time, the reason, whether is withdrawn and so on

7. Quality assessment information: including assessment of time, style, time and other scoring situation

8. Participation in the contest information: including competition name, time, results, etc.

Implementation Overview:

Each kind of information adds, the modification has a specialized view, is also a WinForm, they mutually inherits form_base,base to handle the common question, the specific question subclass each processing

From_base implementation:

Code

1using System;


2using System.Collections.Generic;


3using System.ComponentModel;


4using System.Data;


5using System.Drawing;


6using System.Linq;


7using System.Text;


8using System.Windows.Forms;


9


10using studentmanagerv3.database;


11


12namespace StudentManagerV3


13{


public partial class Form_base:form


15 {


private Studentmanagerdatacontext context;


private bool Iseidt = false;


/**////<summary>


19///View references, updating the view when the model changes, presenting the user with new results


///</summary>


protected DataGridView GridView {get; set;}


22


/**////<summary>


24///If the information is edited, the entity is not empty and forced to be converted to the entity that the user needs


///</summary>


protected object Entity {get; set;}


27


/**////<summary>


29///Each form maintains a separate context for itself, preventing conflicts or raising errors


///</summary>


protected Studentmanagerdatacontext Context


32 {





34 {


(context = = null) throw new ArgumentNullException ();


to the context;


37}


38}


39


/**////<summary>


41///identifies whether to edit information or add new information,


///</summary>


protected bool Isedit {get {return iseidt;}}


44


public form_base ()


46 {}


47


public Form_base (object entity)


49 {


if (entity!= null) {Iseidt = true; Entity = Entity; }


Wuyi//appinfo contains configuration information for the system


the context = new Studentmanagerdatacontext (appinfo.connectionstring);


53}


54


55//Determine if the entity currently operating is valid


protected bool Islegal ()


57 {


58//Global information identifying the current entity


return datapool.studentnumber!= "0";


60}


61


public void Showhandleentityerror (String message)


63 {


(message!= null)


smsapplication.writelogandshowsuggestiveinfo (Message,


SysConfig.Document.SelectNodes (Xmlselectorinfo.applicationerror) [0]. InnerText);


Or else smsapplication.writelogandshowsuggestiveinfo (message,


SysConfig.Document.SelectNodes (Xmlselectorinfo.entityerror) [0]. InnerText);


69}


70


/**////<summary>


72///Add, modify the logic of student information (except basic information), unified processing (polymorphic implementation)


///</summary>


protected void Addoreditinfo ()


75 {


a try


77 {


(Islegal ())


79 {


Constructentityinfo ();


Bayi Smsapplication.showoperatesucceedresult ();


82}


-Else showhandleentityerror (null);


84}


catch (FormatException exp)


86 {


//smsapplication System writes to logs and displays friendly information about components, Xmlselectorinfo records XML configuration file addressing information


Smsapplication.writelogandshowsuggestiveinfo (exp. Message, SysConfig.Document.SelectNodes (Xmlselectorinfo.formaterror) [0]. InnerText);


89}


a catch (OverflowException exo)


91 {


Smsapplication.writelogandshowsuggestiveinfo (exo. Message, SysConfig.Document.SelectNodes (Xmlselectorinfo.overflowerror) [0]. InnerText);


93}


a catch (Exception ex)


95 {


Showhandleentityerror (ex. message);


97}


this. Dispose ();


99}


/**////<summary>


101///Method of obtaining new information entity, subclass implementation


102///</summary>


protected virtual void Constructentityinfo ()


104 {


throw new NotImplementedException ();


106}


107


108}


109}


110

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.