Private Bindingmanagerbase bm1 = Null ;
Private Bindingmanagerbase bm2 = Null ;
Private Void Datascaninform2_load ( Object Sender, eventargs E)
{
String Sqlstring1 = " Select * from customer " ;
String Sqlstring2 = " Select * From Order " ;
String [] Sqlstrings = New String [] {Sqlstring1, sqlstring2 };
String [] Tablenames = New String [] { " Customer " ," Order " };
Dataset DS = New Dataset ();
DS = rabbit. dbutility. dbhelperoledb. Query (sqlstrings, tablenames );
Datacolumn parentcolumn = New Datacolumn ();
Datacolumn childcolumn = New Datacolumn ();
Parentcolumn = Ds. Tables [ " Customer " ]. Columns [ " ID " ];
Childcolumn = Ds. Tables [ " Order " ]. Columns [ " Customer ID " ];
Datarelation relation = New Datarelation ( " Orders of each customer " , Parentcolumn, childcolumn );
DS. relations. Add (relation );
// Bind
Txtcid. databindings. Add ( " Text " , DS, " Customer. ID " );
Txtccompany. databindings. Add ( " Text " , DS," Customer. Company " );
Txtcfamliyname. databindings. Add ( " Text " , DS, " Customer. Surname " );
Txtchomepage. databindings. Add ( " Text " , DS, " Customer. Homepage " );
Txtoid. databindings. Add ( " Text " , DS, " Customer. Order of each customer. Order ID " );
Dtpodate. databindings. Add ( " Value " , DS, " Customer. Order of each customer. Order Date " );
Txtoname. databindings. Add ( " Text " , DS, " Customer. Order of each customer. Delivery name " );
Txtocity. databindings. Add ( " Text " , DS, " Customer. Order of each customer. Delivery City " );
Nudocost. databindings. Add ( " Value " , DS, " Customer. Order of each customer. Freight " );
Binding btax = New Binding ( " Text " , DS, " Customer. Order and tax of each customer " );
Btax. Format + = New Converteventhandler (btax_format); txtotax. databindings. Add (btax );
Bm1 = This . Bindingcontext [ds, " Customer " ];
Bm2 = This . Bindingcontext [ds, " Customer. Orders of each customer " ];
Bm1.positionchanged + = New Eventhandler (bm1_positionchanged );
Bm2.positionchanged + = New Eventhandler (bm2_positionchanged );
This . Bm1_positionchanged ( Null , New Eventargs ());
This . Bm2_positionchanged ( Null , New Eventargs ());
}
Private Void Btax_format ( Object Sender, converteventargs E)
{
E. value = String . Format ( " {0: C3} " ,( Decimal ) E. value );
}
Private Void Bm1_positionchanged ( Object Sender, eventargs E)
{
Textbox1.text = String . Format (" Current location: {0}, total: {1} " , Bm1.position + 1 , Bm1.count );
This . Bm2_positionchanged ( Null , New Eventargs ());
}
Private Void Bm2_positionchanged ( Object Sender, eventargs E)
{
// When bm1.position changes, run the positionchanged event of bm2.position first,
// Execute the positionchanged event of bm1.position. While running the bm2.position
// Before the positionchanged event, bm2.position has already pointed
// The first subrecord of the record, that is, bm2.position = 0; if no subrecord exists, bm2.position =-1
Textbox2.text = String . Format ( " Current location: {0}, total: {1} " , Bm2.position + 1 , Bm2.count );
}
Private Void Btncback_click ( Object Sender, eventargs E)
{
If (Bm1.position> 0 )
{
Bm1.position-= 1 ;
}
}
Private Void Btncnext_click ( Object Sender, eventargs E)
{
If (Bm1.position <bm1.count- 1 )
{
Bm1.position + = 1 ;
}
}
Private Void Btncfirst_click ( Object Sender, eventargs E)
{
Bm1.position = 0 ;
}
Private Void Btnclast_click ( Object Sender, eventargs E)
{
Bm1.position = bm1.count- 1 ;
}
Private Void Btnoback_click ( Object Sender, eventargs E)
{
If (Bm2.position> 0 )
{
Bm2.position-= 1 ;
}
}
Private Void Btnonext_click ( Object Sender, eventargs E)
{
If (Bm2.position <bm2.count- 1 )
{
// When the data of the current record cannot pass the validity test of the control bound to it, // It will cause failure to point to the next record, that is, the next calculation fails, bm2.position remains unchanged // For example, there is a numericupdown control showing the freight in the figure. If the freight of the next record is 300, and the maxvalue attribute value of the control is 200, this will cause the point to fail.
Bm2.position + =1;
}
}
Private VoidBtnofirst_click (ObjectSender, eventargs E)
{
Bm2.position =0;
}
Private VoidBtnolast_click (ObjectSender, eventargs E)
{
Bm2.position = bm2.count-1;
}