18 (C # Development)-Data Dictionary Editing

Source: Internet
Author: User
Tags oracleconnection

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.

  1. PrivateOraclecommandbuilder builder;// Command Construction
  2. PrivateOracledataadapter da;// Data adapter
  3. PrivateDataset Ds;// Dataset
  4. Private StringSelectednodetext;// Save the text content of the selected tree node
  5. Private StringTablename;// Table name
  6. ProtectedOracleconnection connection;// Connect to the database
  7. 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.

 

  1. Private VoidDatadictionaryedit_load (ObjectSender, eventargs E)
  2. {
  3. // Load the corresponding data dictionary table to the tree
  4. Connection =NewOracleconnection (configurationsettings. deleettings ["Connectionstring"]);
  5. Node Tn =NewNode ();
  6. Tn. Text ="Data dictionary table";
  7. Advtree1.nodes. Add (TN );
  8. Node n1 =NewNode ();
  9. N1.text ="Data classification table";
  10. Node n2 =NewNode ();
  11. N2.text ="Element category table";
  12. Node N3 =NewNode ();
  13. N3.text ="Layer table";
  14. Node N4 =NewNode ();
  15. N4.text ="Field definition table";
  16. Tn. nodes. Add (N1 );
  17. Tn. nodes. Add (N2 );
  18. Tn. nodes. Add (N3 );
  19. Tn. nodes. Add (n4 );
  20. }

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.

  1. // Select the corresponding table and load the data to the datagridview.
  2. Private VoidAdvtreeappsafternodeselect (ObjectSender, advtreenodeeventargs E)
  3. {
  4. Node Tn =NewNode ();
  5. Tn = E. node;
  6. Selectednodetext = tn. text;
  7. Switch(TN. Level)
  8. {
  9. Case1:
  10. Labelx1.text ="";
  11. Labelx1.text ="Current data table :"+ Tn. text;
  12. If(Connection. State! = Connectionstate. open)
  13. {
  14. Connection. open ();
  15. }
  16. If(TN. Text ="Data classification table")
  17. {
  18. Tablename ="Jcsjk_category";
  19. }
  20. Else If(TN. Text ="Element category table")
  21. {
  22. Tablename ="Jcsjk_element";
  23. }
  24. Else If(TN. Text ="Layer table")
  25. {
  26. Tablename ="Jcsjk_layer";
  27. }
  28. Else If(TN. Text ="Field definition table")
  29. {
  30. Tablename ="Jcsjk_fielddefine";
  31. }
  32. StringSQL ="Select * from"+ Tablename;
  33. DA =NewOracledataadapter (SQL, connection );
  34. Builder =NewOraclecommandbuilder (DA );
  35. DS =NewDataset ();
  36. Da. Fill (DS, tablename );
  37. Datagridviewx1.datasource = Ds. Tables [0];
  38. IntIntmod, DGR;
  39. // Let the vertical scroll bar disappear first
  40. Datagridviewx1.scrollbars = scrollbars. horizontal;
  41. // 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?
  42. DGR = maid-1;
  43. // Perform the modulo operation
  44. If(DGR % 10 = 0)
  45. {
  46. Intmod = 0;
  47. }
  48. Else
  49. {
  50. Intmod = 1;
  51. }
  52. // In the main case, this for loop divides the table into several pages and adds them to ComboBox.
  53. Comboboxex1.items. Clear ();
  54. For(IntI = 1; I <= DGR/10 + intmod; I ++)
  55. {
  56. Comboboxex1.items. Add ("Th"+ I +"Page");
  57. }
  58. // The first one is selected by default.
  59. If(Comboboxex1.items. Count> 0)
  60. {
  61. Comboboxex1.selectedindex = 0;
  62. }
  63. Break;
  64. Default:
  65. Break;
  66. }
  67. }

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.

  1. // Delete a record
  2. Private VoidDelbtn_click (ObjectSender, eventargs E)
  3. {
  4. If(! Datagridviewx1.allowusertodeleterows)
  5. {
  6. Datagridviewx1.allowusertodeleterows =True;
  7. }
  8. If(Maid. index <0)
  9. {
  10. MessageBox. Show ("Select the row to be deleted");
  11. Return;
  12. }
  13. Ischanged =True;
  14. DS. Tables [0]. Rows [datagridviewx1.currentrow. Index]. Delete ();
  15. }
  16. // Add a record
  17. Private VoidAddbtn_click (ObjectSender, eventargs E)
  18. {
  19. If(! Datagridviewx1.allowusertoaddrows)
  20. {
  21. Datagridviewx1.allowusertoaddrows =True;
  22. }
  23. If(Datagridviewx1.readonly)
  24. {
  25. Datagridviewx1.readonly =False;
  26. }
  27. Ischanged =True;
  28. Datagridviewx1.firstdisplayedscrollingrowindex =
  29. Datagridviewx1.rows [maid-1]. index;
  30. }

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.

  1. // Save the modified data to the database
  2. Private VoidSavebtn_click (ObjectSender, eventargs E)
  3. {
  4. IntResult = 0;
  5. If(Ischanged)
  6. {
  7. Try
  8. {
  9. Result = da. Update (DS, tablename );
  10. }
  11. Catch(Exception ex)
  12. {
  13. MessageBox. Show (ex. Message );
  14. }
  15. }
  16. Ischanged =False;
  17. Datagridviewx1.readonly =True;
  18. Datagridviewx1.allowusertoaddrows =False;
  19. Datagridviewx1.allowusertodeleterows =False;
  20. If(Result> 0)
  21. {
  22. Loghelp. writelog (frmmain. username,"Data Dictionary Editing",
  23. "Data Dictionary"+ Selectednodetext +"Edited");
  24. MessageBox. Show ("Database updated");
  25. }
  26. Else
  27. {
  28. Loghelp. writelog (frmmain. username,"Data Dictionary Editing",
  29. "Data Dictionary"+ Selectednodetext +"Edit failed");
  30. MessageBox. Show ("Database not updated");
  31. }
  32. }

6. other auxiliary small functions.

  1. // Enable editing
  2.  Private VoidEditbtn_click (ObjectSender, eventargs E)
  3. {
  4. If(Datagridviewx1.readonly)
  5. {
  6. Datagridviewx1.readonly =False;
  7. }
  8. }
  9.  // Check the data input format
  10.  Private VoidDatagridviewx1_dataerror (ObjectSender, datagridviewdataerroreventargs E)
  11. {
  12. Labelx2.text ="Incorrect data input format";
  13. }
  14.  // Whether the record value has changed
  15.  Private VoidMaid (ObjectSender, datagridviewcelleventargs E)
  16. {
  17. Ischanged =True;
  18. }
  19.  // Datagridview visible
  20.  Private VoidShowallbtn_click (ObjectSender, eventargs E)
  21. {
  22. Datagridviewx1.scrollbars = scrollbars. Both;
  23. Try
  24. {
  25. Datagridviewx1.firstdisplayedscrollingrowindex = 0;
  26. }
  27. Catch(Argumentoutofrangeexception)
  28. {
  29. }
  30. }
  31.  // Display the page number
  32.  Private VoidComboboxex1_selectedindexchanged (ObjectSender, eventargs E)
  33. {
  34. Try
  35. {
  36. Datagridviewx1.firstdisplayedscrollingrowindex = comboboxex1.selectedindex * 10;
  37. }
  38. Catch(Argumentoutofrangeexception)
  39. {
  40. }
  41. }

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.

Related Article

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.