My Sina Weibo:Http://weibo.com/freshairbrucewoo.
You are welcome to exchange ideas and improve your technology together.
Today, we will continue to explain the development of the general space data management platform project. The content introduced today is simple, that is, editing data dictionaries through the interface. As for the concept of data dictionary, you can search for it online. In the past, I had a blog dedicated to explaining the terminology used in this project. You can also check it.
The idea is to follow the idea of implementing this function at the time, basically restoring how to implement this relatively simple function step by step.
1. Define the member variables used.
-
- PrivateOraclecommandbuilder builder;// Command Construction
- PrivateOracledataadapter da;// Data adapter
-
- PrivateDataset Ds;// Dataset
-
- Private StringSelectednodetext;// Save the text content of the selected tree node
-
- Private StringTablename;// Table name
-
- ProtectedOracleconnection connection;// Connect to the database
- Private BoolIschanged =False;// Whether the content in the control changes
2. initialize the interface-related controls in the form loading function so that these controls are displayed normally and ready for subsequent operations.
-
- Private VoidDatadictionaryedit_load (ObjectSender, eventargs E)
-
- {
-
- // Load the corresponding data dictionary table to the tree
- Connection =NewOracleconnection (configurationsettings. deleettings ["Connectionstring"]);
-
-
- Node Tn =NewNode ();
-
- Tn. Text ="Data dictionary table";
-
-
- Advtree1.nodes. Add (TN );
-
- Node n1 =NewNode ();
- N1.text ="Data classification table";
-
- Node n2 =NewNode ();
-
- N2.text ="Element category table";
-
- Node N3 =NewNode ();
-
- N3.text ="Layer table";
-
- Node N4 =NewNode ();
- N4.text ="Field definition table";
-
- Tn. nodes. Add (N1 );
-
- Tn. nodes. Add (N2 );
-
- Tn. nodes. Add (N3 );
-
- Tn. nodes. Add (n4 );
-
- }
3. After selecting the corresponding node through the tree control, load the content of a table from the text (representing the table name) of the Tree node to the datagridview control, and display the page by page.
-
- // Select the corresponding table and load the data to the datagridview.
- Private VoidAdvtreeappsafternodeselect (ObjectSender, advtreenodeeventargs E)
-
- {
-
- Node Tn =NewNode ();
-
-
- Tn = E. node;
-
- Selectednodetext = tn. text;
-
-
- Switch(TN. Level)
- {
-
- Case1:
-
- Labelx1.text ="";
-
- Labelx1.text ="Current data table :"+ Tn. text;
-
-
- If(Connection. State! = Connectionstate. open)
- {
-
- Connection. open ();
-
- }
-
- If(TN. Text ="Data classification table")
-
- {
- Tablename ="Jcsjk_category";
-
- }
-
- Else If(TN. Text ="Element category table")
-
- {
- Tablename ="Jcsjk_element";
-
- }
-
- Else If(TN. Text ="Layer table")
-
- {
- Tablename ="Jcsjk_layer";
-
- }
-
- Else If(TN. Text ="Field definition table")
-
- {
- Tablename ="Jcsjk_fielddefine";
-
- }
-
-
- StringSQL ="Select * from"+ Tablename;
-
- DA =NewOracledataadapter (SQL, connection );
- Builder =NewOraclecommandbuilder (DA );
-
- DS =NewDataset ();
-
-
- Da. Fill (DS, tablename );
-
- Datagridviewx1.datasource = Ds. Tables [0];
-
- IntIntmod, DGR;
-
- // Let the vertical scroll bar disappear first
-
- Datagridviewx1.scrollbars = scrollbars. horizontal;
-
- // Retrieve the number of dgv rows. Why do you need to subtract one because it always has one more row to edit, so that row also occupies space of one row?
-
- DGR = maid-1;
- // Perform the modulo operation
-
- If(DGR % 10 = 0)
-
- {
-
- Intmod = 0;
-
- }
-
- Else
- {
-
- Intmod = 1;
-
- }
-
- // In the main case, this for loop divides the table into several pages and adds them to ComboBox.
-
- Comboboxex1.items. Clear ();
- For(IntI = 1; I <= DGR/10 + intmod; I ++)
-
- {
-
- Comboboxex1.items. Add ("Th"+ I +"Page");
-
- }
- // The first one is selected by default.
-
- If(Comboboxex1.items. Count> 0)
-
- {
-
- Comboboxex1.selectedindex = 0;
-
- }
- Break;
-
- Default:
-
- Break;
-
- }
-
- }
4. add or delete a record in the control, but the record has not been updated to the database. You need to keep it before entering the database. The subsequent function is implemented.
-
- // Delete a record
- Private VoidDelbtn_click (ObjectSender, eventargs E)
-
- {
-
- If(! Datagridviewx1.allowusertodeleterows)
-
- {
-
- Datagridviewx1.allowusertodeleterows =True;
-
- }
-
- If(Maid. index <0)
- {
-
- MessageBox. Show ("Select the row to be deleted");
-
- Return;
-
- }
-
- Ischanged =True;
-
- DS. Tables [0]. Rows [datagridviewx1.currentrow. Index]. Delete ();
-
- }
-
-
- // Add a record
- Private VoidAddbtn_click (ObjectSender, eventargs E)
-
- {
-
- If(! Datagridviewx1.allowusertoaddrows)
-
- {
-
- Datagridviewx1.allowusertoaddrows =True;
-
- }
-
- If(Datagridviewx1.readonly)
-
- {
-
- Datagridviewx1.readonly =False;
-
- }
-
- Ischanged =True;
-
- Datagridviewx1.firstdisplayedscrollingrowindex =
-
- Datagridviewx1.rows [maid-1]. index;
-
- }
5. update the modified, added, or deleted content in the control to the database. You can add, delete, and modify the content in the control at the same time, and then update the content to the database at a time, however, only one data dictionary table can be operated at a time.
-
- // Save the modified data to the database
-
- Private VoidSavebtn_click (ObjectSender, eventargs E)
-
- {
-
- IntResult = 0;
-
- If(Ischanged)
-
- {
- Try
-
- {
-
- Result = da. Update (DS, tablename );
-
- }
-
- Catch(Exception ex)
-
- {
-
- MessageBox. Show (ex. Message );
- }
-
- }
-
- Ischanged =False;
-
- Datagridviewx1.readonly =True;
-
- Datagridviewx1.allowusertoaddrows =False;
-
- Datagridviewx1.allowusertodeleterows =False;
-
- If(Result> 0)
-
- {
-
- Loghelp. writelog (frmmain. username,"Data Dictionary Editing",
-
- "Data Dictionary"+ Selectednodetext +"Edited");
-
- MessageBox. Show ("Database updated");
-
- }
- Else
-
- {
-
- Loghelp. writelog (frmmain. username,"Data Dictionary Editing",
-
- "Data Dictionary"+ Selectednodetext +"Edit failed");
-
- MessageBox. Show ("Database not updated");
-
- }
-
- }
6. other auxiliary small functions.
- // Enable editing
-
- Private VoidEditbtn_click (ObjectSender, eventargs E)
-
- {
-
- If(Datagridviewx1.readonly)
-
- {
-
- Datagridviewx1.readonly =False;
-
- }
- }
-
-
- // Check the data input format
-
- Private VoidDatagridviewx1_dataerror (ObjectSender, datagridviewdataerroreventargs E)
-
- {
-
- Labelx2.text ="Incorrect data input format";
-
- }
-
-
- // Whether the record value has changed
- Private VoidMaid (ObjectSender, datagridviewcelleventargs E)
-
- {
-
- Ischanged =True;
-
- }
-
-
- // Datagridview visible
- Private VoidShowallbtn_click (ObjectSender, eventargs E)
-
- {
-
- Datagridviewx1.scrollbars = scrollbars. Both;
-
- Try
-
- {
-
- Datagridviewx1.firstdisplayedscrollingrowindex = 0;
-
- }
- Catch(Argumentoutofrangeexception)
-
- {
-
-
- }
-
- }
-
-
- // Display the page number
-
- Private VoidComboboxex1_selectedindexchanged (ObjectSender, eventargs E)
-
- {
- Try
-
- {
-
- Datagridviewx1.firstdisplayedscrollingrowindex = comboboxex1.selectedindex * 10;
-
- }
-
- Catch(Argumentoutofrangeexception)
-
- {
-
-
- }
-
- }
Other functions include: locating and displaying page data, enabling controls for editing, and checking the validity of input control values.
7. Summary.
The so-called Data Dictionary Editing is actually an operation on several tables, which is exactly the same as the operations on common database tables. It is only based on the data types recorded by the function, data dictionary may sound more professional, and its role is more prominent.