Read and write XML documents with parent-child relationships through frame Dataset

zhaozj2021-02-16  106

Namespace DataRead.Data {

Using system; using system.runtime.serialization;

///

/// ORDERREQUESTDATA inherits DataSet class ///

// [SerializableAttribute] public class OrderRequestData: DataSet {public DataTable OrderRequestTable; public DataTable OrderTable; public DataTable OrderDetailTable; ///

/// Table OrderRequestData /// public const String SessionID_OrderRequestData = "sessionID"; /// /// Table Order /// public const String Values_Order = "values"; public const String CustomerNo_Order = "customerNo"; public const String Remark_Order = "remark"; public const String RequireDate_Order = "requiredate"; public const string ORDERNO_ORDER = "ORDERNO";

///

/// Table ORDERDETAIL / / / ////

public const String ProducetNo_OrderDetail = "productNo"; public const String Price_OrderDetail = "price"; public const String Quantity_OrderDetail = "quantity"; public const String Remark_OrderDetail = "remark"; public const String OrderNo_OrderDetail = "orderNo"; public const String LineNo_OrderDetail = "lineno"; public const string discount_orderdetail = "discount";

Public OrderRequestData (SerializationInfo Info, StreamingContext Context): Base (Info, Context) {}

Public ORDERREQUESTDATA () {BuildDataTables ();

private void BuildDataTables () {// build table OrderRequestData structure OrderRequestTable = new DataTable ( "OrderRequestData"); DataColumnCollection oRColumn = OrderRequestTable.Columns; oRColumn.Add (SessionID_OrderRequestData, typeof (System.String)); oRColumn.Add ( "OrderRequestData_Id" , typeof (System.Int32)); this.Tables.Add (OrderRequestTable); this.Tables [ "OrderRequestData"] Columns [ "OrderRequestData_Id"] ColumnMapping = MappingType.Hidden;... this.Tables [ "OrderRequestData"] Columns [ "OrderRequestData_Id"] AutoIncrement = true;. // build Order table structure OrderTable = new DataTable ( "Order"); DataColumnCollection orderColumn = OrderTable.Columns; orderColumn.Add ( "OrderRequestData_Id", typeof (System.Int32)); orderColumn .Add (Values_Order, typeof (System.String)); orderColumn.Add (CustomerNo_Order, typeof (System.String)); orderColumn.Add (Remark_Order, typeof (System.String)); orderColumn.Add (RequireDate_Order, typeof (System . String); OrderColumn.Add (ORDERNO_ORDER, TYPEOF (System.String); this.Tables.Add (OrderTable);. this.Tables [ "Order"] Columns [ "OrderRequestData_Id"] ColumnMapping = MappingType.Hidden;... this.Tables [ "Order"] Columns [ "OrderRequestData_Id"] AutoIncrement = true ; // Create a table structure OrderDetail OrderDetailTable = new DataTable ( "OrderDetail"); DataColumnCollection orderDetailColumn = OrderDetailTable.Columns; orderDetailColumn.Add (ProducetNo_OrderDetail, typeof (System.String)); orderDetailColumn.Add (Price_OrderDetail, typeof (System.String) ); OrderDetailColumn.Add (Quantity_OrderDetail, TypeOf (System.String));

orderDetailColumn.Add (Remark_OrderDetail, typeof (System.String)); orderDetailColumn.Add (OrderNo_OrderDetail, typeof (System.String)); orderDetailColumn.Add (LineNo_OrderDetail, typeof (System.String)); orderDetailColumn.Add (Discount_OrderDetail, typeof ( System.String)); this.tables.add (ORDERDetailTable); // Establish THIS.RELATION.ADD ("Order_OrderDetail", this.tables ["Order"]. Columns ["Orderno"], this.tables [ "OrderDetail"]. Column ["Orderno"]); this.relations ["Order_OrderDetail"]. NESTED = true;

this.Relations.Add (.. "OrderRequestData_Order", this.Tables [ "OrderRequestData"] Columns [ "OrderRequestData_Id"], this.Tables [ "Order"] Columns [ "OrderRequestData_Id"]); this.Relations [ "OrderRequestData_Order" ] .Nested = true;

}

The XML file structure is as follows

-

<

NewDataSet

>

-

<

ORDERREQUESTDATA

>

<

SessionID

>

SessionID

SessionID

>

-

<

ORDER

>

<

Values

>

Values

Values

>

<

Customerno

>

Customnerno

Customerno

>

<

Remark

>

Remark

Remark

>

<

Requiredate

>

Requiredate

Requiredate

>

<

ORDERNO

>

ORDERNO

ORDERNO

>

-

<

ORDERDETAIL

>

<

ProductNo

>

ProductNo

ProductNo

>

<

PRICE

>

PRICE

PRICE

>

<

Quantity

>

Quantity

Quantity

>

<

Remark

>

Remark

Remark

>

<

ORDERNO

>

ORDERNO

ORDERNO

>

<

Lineno

>

Lineno

Lineno

>

<

Discount

>

Discount

Discount

>

ORDERDETAIL>

-

<

ORDERDETAIL

>

<

ProductNo

>

ProductNo

ProductNo

>

<

PRICE

>

PRICE

PRICE

>

<

Quantity

>

Quantity

Quantity

>

<

Remark

>

Remark

Remark

>

<

ORDERNO

>

ORDERNO

ORDERNO

>

<

Lineno

>

Lineno

Lineno

>

<

Discount

>

Discount

Discount

>

ORDERDETAIL

>

ORDER

>

ORDERREQUESTDATA

>

NewDataSet

>

As long as you add a table in an instance of ORDERREQUESTDATA, you can fill the dataset, and the table relationship has been determined, so don't need to be considered again, but not, note that the father must correspond to the value of the sub-line.

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

New Post(0)