XML file display, modify, look up

xiaoxiao2021-03-06  70

public class Form1: System.Windows.Forms.Form {?? private System.Windows.Forms.DataGrid dataGrid1; ?? private System.Windows.Forms.OpenFileDialog openFileDialog1; ?? private System.Windows.Forms.TabControl tabControl1 ;?? ? private System.Windows.Forms.TabPage tabPageNormal; ?? private System.Windows.Forms.TabPage tabPageSearch; ?? private System.Windows.Forms.Panel panel1; ?? private System.Windows.Forms.Button btnSearch; ?? private System.Windows.Forms.TextBox tbValue; ?? private System.Windows.Forms.ComboBox cmbField; ?? private System.Windows.Forms.DataGrid dataGrid2; ?? private System.Windows.Forms.Button btnClose; ?? private System. Windows.Forms.Button BtnreadXML; ?? private system.windows.Forms.Button btnupdate; ?? ///

? /// The required designer variable. ?? ///

?? private system.componentmodel.container components = null;

?? public form1 () ?? {??? // ??? // Windows Form Designer Support for the necessary ??? // ??? INIALIZECMOMPONENT ();

??? // ??? // Todo: Add any constructor code after INITIALIZECOMPONENT calls ??? // ??}

?? ///

?? /// Clean all the resources being used. ?? ///

?? protected override void dispose (Bool Disposing)

?? {

??? i (disposing)

??? {

???? if (Components! = NULL)

???? {

????? components.dispose ();

????}

???}

? ?????????????????????????????????????????????????????????????????????????????

??}

??? Dataset ??? DS = new dataset ();

?? ///

??/// The main entry point for the application. ?? ///

?? [stathread]

?? static void main ()

?? {

??? Application.run (New Form1 ());

??}

?? ///

?? // update XML file ?? ///

?? ///

?? ///

?? Private void btnupdate_click (Object Sender, System.Eventargs E)

?? {

??? ds.writexml (this.openfiledialog1.filename);

??? Messagebox.show ("Update Complete!");

??? this.DataGrid1.focus ();

??}

?? ///

?? /// read the XML file ?? ///

?? ///

?? ///

?? private void btnreadxml_click (Object Sender, System.Eventargs E)

?? {

??? this.openfiledialog1.filter = "Data file | * .xml";

??? i (this.openfiledialog1.showdialog () == DialogResult.ok) ??? {

???? // Bind the read XML file as a data source to DataGrid

???? ds.reset ();

???? ds.readxml (this.openfiledialog1.filename);

???? this.DataGrid1.datasource = DS;

???? this.dataGrid1.focus ();

???}

??}

?? ///

?? /// Select a list of items to modify the '?? ////

?? ///

?? ///

?? Private void DataGrid1_DataSourceChanged (Object Sender, System.EventArgs E)

?? {???

??? // If the child name does not exist

??? if (this.DataGrid1.datamember == "")

??? {

???? this.btnsearch.enabled = false;

???? this.tbvalue.clear ();

???? this.tbvalue.enabled = false;

???? this.cmbfield.Items.clear ();

???}? // The child table exists, assign all the field names to ComboBox

??? ELSE

??? {

???? this.cmbfield.Items.clear ();

???? this.cmbfield.Items.add ("Please select field");

???? foreach (Datacolumn DC in Ds.Tables [this.DataGrid1.datamember] .columns)

???? {

????? this.cmbfield.Items.add (dc.columnname);

????}

???? this.cmbfield.selectedIndex = 0;

???}

??}

?? ///

?? // The user chose a column name ?? ///

?? ///

?? ///

?? Private void CMBField_selectedIndexchanged (Object Sender, System.EventArgs E)

?? {

??? if (this.cmbfield.selectedIndIndex! = 0)

???? this.tbvalue.enabled = true;

??? ELSE

???? this.tbvalue.enabled = false;

??}

?? ///

?? // User Enter the content to search ?? ///

?? ///

?? ///

?? private void tbvalue_textchanged (Object Sender, System.EventArgs E)

?? {

??? i (this.tbvalue.text.trim (). Length> 0)

???? this.btnsearch.enabled = true;

??? ELSE

???? this.btnsearch.enabled = false;

??}

?? ///

?? /// The user clicks the "Search" button ?? ///

?? ///

?? ///

?? Private void btnsearch_click (Object Sender, System.Eventargs E)

?? {

??? // store the search results into a DataView

??? DataView

???? dvsearch = new dataview ();

??? DVSearch.table = ds.tables [this.DataGrid1.datamember];

??? DVSearch.rowfilter = this.cmbfield.text "= '" this.tbvalue.text.trim () "'"; ??? // Show DataView content

??? this.DataGrid2.datasource = dvsearch;

??? this.tabcontrol1.selectedtab = this.tabpagesearch;

??? this.tbvalue.clear ();

??}

?? ///

?? /// Off - Query results page ?? ////

?? ///

?? ///

?? Private void btnclose_click (Object Sender, System.Eventargs E)

?? {

??? this.tabcontrol1.selectedTab = this.tabpagenormal

??}

?

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

New Post(0)