C #: Office supplies management software project summary

Source: Internet
Author: User

The course design of this semester is to do an office supplies management software, the class only gave five lessons 10 hours, because the teacher to the needs of the document is not too comprehensive, basically is the class to write, encountered problems in class to ask the teacher, the function of the wrong place to change. The software itself is not complex, after all, is the school's work and not the company's products, remove the interface part of the rest is the operation of the database. Database in the table is built by the teacher, a total of only four tables, but the teacher to build the table when the associated table does not set the foreign key, the primary key is not established to self-increment, so in addition and deletion operation, always feel very awkward, delete when can not cascade Delete, to a table in turn delete, time-consuming laborious, Fortunately there are only four tables. This situation will certainly not be available to the company.

This article is to write me the process of writing this little piece of software again, the process of some of the problems encountered, learned some of the knowledge recorded, so as to be convenient to view later.

Interface

Main interface:


Individual subdirectories of the menu bar:






This is the French version of the interface, introduce:

    • Fichier:file file
    • Article: Items
    • Marque: Brand
    • Famille: Kind
    • Sous-famille: Sub-species
    • Sélectionner: Select
    • Afficher: Display
    • Ajouter: Add
    • Modifier: Modify
    • Supprimer: Delete

      Click the "Select" button to bring up the "Data Integration dialog", as follows:


      Click on the top left button to pop up a file selection dialog box, you can select an XML file, all the data are saved in an XML file format. The Radio box at the top right is the way to determine how the data is integrated: the top choice is to delete all the data in the database, and to store the new XML file in the database; the selection below is to update the database. Click the "Integration" button to start reading the data, if you encounter any anomalies and errors, displayed in the Exception window, the data after reading the window automatically disappears.

Read data

In order to read the data from the database, I first created an object entity class Article_model, which has six properties, corresponding to the six attributes in the XML file, which is the format of the data in the XML file:


Then create a class that specifically reads the XML file data: Xml_read, the class has only one method:

 PublicList<article_model>Read_xml(stringFileName) {XmlDocument Doc =NewXmlDocument ();    Doc.load (FileName); XmlElement Rootelem = doc.documentelement;//root ElementXmlNodeList Articlenodes = Rootelem.getelementsbytagname ("article");//all ArticlesList<article_model> atl_model_list =NewList<article_model> ();//get datas    foreach(XmlNode NodeinchArticlenodes) {XmlNodeList Childs = node.childnodes;stringDescription = Childs.item (0). InnerText;stringRefarticle = Childs.item (1). InnerText;stringMarque = Childs.item (2). InnerText;stringFamille = Childs.item (3). InnerText;stringSousfamille = Childs.item (4). InnerText;stringStrprixht = Childs.item (5). InnerText;string[] Str = Strprixht.split (New Char[] {', '});stringTempprix = str[0] +"."+ str[1];floatPrixht =float.        Parse (Tempprix); Article_model AM =NewArticle_model (Description, refarticle, Marque, famille, Sousfamille, prixht);    Atl_model_list.add (AM); }returnAtl_model_list; }

Because the data in the Commodity Price column data decimal point is a comma (teacher why do you want to use a comma!!!!) ), all of them are converted again, converting the value to the float type.

When I open the File selection dialog box, I add a filter because I can only select files in XML format:

OpenFileDialog Ofd = new OpenFileDialog();Ofd.Filter"xml files(*.xml)|*.xml";Ofd.ShowDialog();


When the data is stored in a list from an XML file and then stored in a database, the problem is that the data may be duplicated. For example, there are 50 catalogs in the XML file, but they may belong to 30 different brands, that is, brands, types, sub-categories may be duplicated, and the primary keys of these tables are not self-increasing, it is necessary to insert data into the database before the data in the database to check if there is no existing inserted. Because the MVC pattern was required, I encapsulated the functions of the database operations into a class: Db_controller. Take the Marques table as an example, the workaround:

DB_Controller DataBase = new DB_Controller();//insert data to table Marquesif (DataBase.SelectMarquesTable(ArtModelList[i].marque) == -1){    DataBase.InsertMarquesTable(MarqueId++, ArtModelList[i].marque);}

The query function and the Insert function are as follows:

 Public void insertmarquestable(intRefmarque,stringNom) {Sqliteconnection Db_conn =NewSqliteconnection ("Data source=mercure.sqlite;"); Db_conn.open ();stringSQL =INSERT into Marques (refmarque,nom) VALUES ("+ Refmarque +", '"+ Nom +"')"; Sqlitecommand Command =NewSqlitecommand (SQL, db_conn);     Command.executenonquery (); Db_conn.close (); } Public int selectmarquestable(stringNom) {Sqliteconnection Db_conn =NewSqliteconnection ("Data source=mercure.sqlite;"); Db_conn.open ();stringSQL ="Select Refmarque from Marques WHERE Nom = '"+ Nom +"'"; Sqlitecommand Command =NewSqlitecommand (SQL, db_conn); Sqlitedatareader Date = Command.ExecuteReader ();intI =-1;if(Date.read ()) {I =int. Parse (date["Refmarque"].     ToString ()); }Else{I =-1;     } date.close (); Db_conn.close ();returnI; }


There are four tables in the database, Articles,marques,familles,sousfamilles. Example diagram:





After reading the data, click the "Show" button, you can display the information of all the products, which requires four tables federated query, with the ListView control display information. Effects such as:

Data deletion and modification

For the three small table: Marques,familles,sousfamilles The addition of simple, click "Add" button, directly pop up a dialog box, the user input name can be. When adding Sousfamille, the user chooses a famille that already exists, so the famille in the Add-in window is displayed as a ComboBox for the user to select. The addition of articles is also a window, and the Marque,sousfamille on the window is also displayed with a dropdown list for the user to select.

Modify and delete three small tables: Marques,familles,sousfamilles data, the corresponding articles table content also to update, and the display window of the data to be updated in real time.

To modify and delete a function, take the Marques table as an example:

 Public void updatemarquestable(stringDenom,stringNom) {Sqliteconnection Db_conn =NewSqliteconnection ("Data source=mercure.sqlite;"); Db_conn.open ();stringSQL ="UPDATE Marques SET Nom = '"+ Nom +"' WHERE Nom = '"+ Denom +"'"; Sqlitecommand Command =NewSqlitecommand (SQL, db_conn);     Command.executenonquery (); Db_conn.close (); } Public void Deletemarquebyname(stringNom) {Sqliteconnection Db_conn =NewSqliteconnection ("Data source=mercure.sqlite;"); Db_conn.open ();stringSQL ="DELETE from Marques WHERE Nom = '"+ Nom +"'"; Sqlitecommand Command =NewSqlitecommand (SQL, db_conn);     Command.executenonquery (); Db_conn.close (); }


Summarize

In general, the course design is not difficult, the interface words in the VS2015 drag and drop on the picture, the data is mainly operating database, as long as the control of the logic between the various functions, all naturally become. This is the first time I use C #, feeling and C++,java not much difference, may be not deep contact. But the computer language is the same, carefully mastered a door, the other is also good to get started.

C #: Office supplies management software project summary

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.