The parsing of the template is mainly about the parsing of the main template.
First of all, the business logic, first click on the tree node, the tree code to pay the material code, and then through the material code to query the main template (including the main template ID and main template information) and sub-template (without {} information);
If there is information in the form of {}, we pay the main template ID and the main template information to the string parameter to the foreground. In the foreground, first determine whether the string parameter passed is empty, if it is empty, it means that there is no master template, otherwise the child template information is loaded.
To parse the main template:
The first step:
The main template information obtained from the above logic is {: diesel locomotives, 0; electric locomotives, 1; passenger cars, 2; wagons, 3; EMU, 4; To be scrapped, 5; other obsolete materials, 9;} This form of data.
Step Two:
We split it.
Define a DataTable and assign it two fields: an ID, a name.
Step Three:
cut string, first two characters {: Delete method as follows: Substring (2 , smatlcate.length-2)
string becomes Diesel locomotives, 0; electric locomotives, 1; passenger cars, 2; wagons, 3; EMU, 4; To be scrapped, 5; other obsolete materials, 9;} &NBSP
Then we'll remove the last} method as follows:. Split ('} ') [0]. Trim ()
string becomes diesel locomotive , 0; electric locomotive, 1; passenger car, 2; lorry, 3; EMU, 4; To be scrapped, 5; other obsolete materials, 9;
We'll take the final semicolon, and remove the method as follows: TrimEnd (';')
strings become diesel locomotives, 0, electric locomotives, 1, passenger cars, 2, trucks, 3, EMU, 4, scrap, 5, other obsolete supplies, 9
Span style= "White-space:pre" > step three:
So we can do array conversions: string[] Strarr = Smatlcate.split (';') This is an array conversion with a semicolon bit delimiter
Fourth Step:
Finally, we can make a loop assignment for the previously defined DataTable (with two lots) in the following way:
DataRow dr = Dt_childtemplets.newrow ();
dr["ID"] = Strarr[i]. Split (', ') [1]. Trim ();
dr["NAME"] = "series:" + Strarr[i]. Split (', ') [0]. Trim () + "," + strarr[i]. Split (', ') [1]. Trim ();
Finally, we succeeded in uploading the information from the array to the DataTable.
The DT and drop-down lists are data-bound and can be assigned values.
There will also be posts for child template parsing and template testing.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Template Maintenance-Template parsing