"Unlimited Level Classification Act" with C # and Database

xiaoxiao2021-03-06  83

After the last time I wrote this article, I immediately found a mistake, which may have an Node missed. Because when adding a node, there is only one loop, when the node is added, the parent node has not been added yet, that is, if you can't find your father, this will cause missed. Really sorry, no cautious. However, it is very casual, one thing does not want to make mature, but it is wrong, it will be revised. If you don't like me, throw the article aside. Original procedure:

///

/// Reset TreeView

/// resetSortView () function

///

#REGION ResetSortView () function implementation

Private void resetsortview ()

{

Trvsort.nodes.clear ();

Arrnode.clear ();

ExNode nd = new exNode ();

//

// Add product category

//

Sort mysort = new sort ();

mysort.id = 0;

mysort.name = "Classification of Commodities";

mysort.parentId = -1;

mysort.isnd = false;

mysort.disable = false;

Nd.sort = myster;

nd.imageIndex = 0;

nd.selectedImageIndex = 0;

Trvsort.Nodes.Add (Nd);

ArrNode.Add (ND);

// Open the database

// Sorry, I will define the database in Database, all in DBCLASS

// This is saved for SQL Server.

// DataSet here is also packaged for mydb.dbdataset

// Lazy to get the database, if you are not familiar with the database, learn quickly

String SQL = "Select * from merchandisesesort order by merchandises";

DBCLASS MYDB = New Dbclass ();

Mydb.dbopen ();

Mydb.createadapter (SQL);

Mydb.filldataSet ();

//

// Add data records one by one to the tree

/ / Error start from here --/ ------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------------------

For (int i = 1; i <= mydb.dbdatas.tables [0] .rows.count; i )

{

Mysort.id = (int) mydb.dbdataset.tables [0] .rows [i-1] ["merchandiseesortid"];

Mysort.name = mydb.dbdatas.tables [0] .rows [i-1] ["name"]. TOSTRING ();

MYSORT.PARENTID = (int) mydb.dbdatanet.tables [0] .rows [i-1] ["parentID"];

Mysort.isnd = (bool) mydb.dbdataset.tables [0] .rows [i-1] ["isend"];

Mysort.disable = (bool) mydb.dbdatanet.tables [0] .rows [i-1] ["disable"]; addnode (mysort);

} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------

Mydb.dbclose ();

Trvsort.expandall ();

} This code rewrite, that is, after successful addition of the TreeView, remove the node record from the DataSet port, and perform a new cycle, otherwise the DataSet looks down to the record. The procedure is as follows: The subroutine of the corrected add node: ///

/// Add Node in TreeView, add Node to an array, easy to query /// Private Bool AddNode (Sort Addsort) {Bool added = false;

ExNode ParentNode = New ExNode (); // To Mount Father EXNode AddNode = New ExNode (); // This Node

AddNode.Sort = addsort;

IF (addnode.sort.parentId == 0) {trvsort.nodes [0] .nodes.add (addnode); // makes the flag to find Added = true; arrnode.add (addnode); addnode.idpath = "root // 0 ";} else {foreach (ExNode PNode in Arrnode) {if (pnode.sort.id == addsort.parentId) {ParentNode = PNode; ParentNode.Nodes.Add (addNode); arrnode.add (addnode); Addnode.idpath = ParentNode.idpath "//" addnode.sort.parentId.tostring (); // Make the flag to find Added = true;

Break;}}} // If not found, return false if (! added) Return False; if (address.isend) {if (address.disable) {addnode.imageindex = 4; addnode.selectedImageIndex = 4; addnode.forecolor = SystemColors.GrayText;} else {addNode.ImageIndex = 2; addNode.SelectedImageIndex = 2; addNode.ForeColor = SystemColors.WindowText;}} else {if (addSort.Disable) {addNode.ImageIndex = 3; addNode.SelectedImageIndex = 3 ; Addnode.forecolor = systemcolors.graytext;} else {addnode.imageIndex = 1; addnode.selectedimageIndex = 1; addnode.forecolor = systemcolors.windowtext;}}}}}}}}}}}}}}} Return True;} Removed display classification tree program: ///

/// Reset product classification TreeView //// public void recsortsortview () {trvsort.nodes.clear (); arrnode.clear ();

ExNode Nd = new exNode (); // / Add Product Class // Sort mysort = new sort (); mysort.id = 0; mysort.name = "Commodity class"; mysort.parentId = -1; mysort .Isnd = false; mysort.disable = false; nd.sort = mysort; nd.imageIndex = 0; nd.selectedimageIndex = 0; trvsort.nodes.add (nd); arrnode.add (nd); nd.idpath = " Root "; string SQL =" Select * from merchandises "; dbclass mydb = new dbclass (); mydb.dbopen (); mydb.createadapter (SQL); mydb.filldataset ();

// / / The following correction code, use two cycles, true to the record in the DataSet Add // While (mydb.dbdataset.tables [0] .Rows.count> 0) {for (int i = 1; I <= mydb.dbdataset.tables [0] .Rows.count; i ) {mysort.id = (int) mydb.dbdataset.tables [0] .rows [i-1] ["merchandises"]; mysort.name = mydb.dbdataset.tables [0] .rows [i-1] ["sortname"]. Tostring (); mysort.parentId = (int) mydb.dbdatanet.tables [0] .rows [i-1] [" ParentID "]; mysort.isnd = (bool) mydb.dbdataset.tables [0] .rows [i-1] [" isend "]; mysort.disable = (bool) mydb.dbdataset.tables [0] .rows [ I-1] ["disable"];

// If adding success, delete the corresponding record in the DataSet, and enter the new cycle IF (addnode (mysort)) {mydb.dbdataset.tables [0] .Rows.Removeat (i - 1); mydb.dbdataset.tables [ 0] .acceptchange (); break;}}} mydb.dbclose (); trvsort.collapseall (); trvsort.nodes [0] .expand ();

转载请注明原文地址:https://www.9cbs.com/read-105822.html

New Post(0)