question

yobook avatar image
0 Likes"
yobook asked ·

XmlSerializer with Finding api?

> namespace _03_04_01 { > public partial class Form1 : Form { > > DataSet dsXIN; > DataTable dtCustomer; > BindingSource bsCustomer; > > public Form1() > { > InitializeComponent(); > } > > private void Form1_Load(object sender, EventArgs e) > { > dsXIN = new DataSet("XIN"); > CreateCustomerTable(); > BindingData(); > bsCustomer.AddingNew += new > AddingNewEventHandler(bsCustomer_AddingNew); > bsCustomer.ListChanged += new > ListChangedEventHandler(bsCustomer_ListChanged); > bsCustomer.PositionChanged += new > EventHandler(bsCustomer_PositionChanged); > } > > private void CreateCustomerTable() > { > dtCustomer = new DataTable("Customer"); > dsXIN.Tables.Add(dtCustomer); > //客戶編號 > DataColumn colCustomerID = new DataColumn("CustomerID"); > colCustomerID.DataType = System.Type.GetType("System.String"); > colCustomerID.MaxLength = 8; > colCustomerID.AllowDBNull = false; > //公司名稱 > DataColumn colCompanyName = new DataColumn("CompanyName"); > colCompanyName.DataType = System.Type.GetType("System.String"); > colCompanyName.MaxLength = 40; > colCompanyName.AllowDBNull = false; > //連絡人 > DataColumn colContact = new DataColumn("Contact"); > colContact.DataType = System.Type.GetType("System.String"); > colContact.MaxLength = 12; > colContact.AllowDBNull = false; > //電話 > DataColumn colPhone = new DataColumn("Phone"); > colPhone.DataType = System.Type.GetType("System.String"); > colPhone.MaxLength = 20; > //傳真 > DataColumn colFax = new DataColumn("Fax"); > colFax.DataType = System.Type.GetType("System.String"); > colFax.MaxLength = 20; > //地址 > DataColumn colAddress = new DataColumn("Address"); > colAddress.DataType = System.Type.GetType("System.String"); > colAddress.MaxLength = 60; > //建立欄位並加入客戶資料表 > dtCustomer.Columns.Add(colCustomerID); > dtCustomer.Columns.Add(colCompanyName); > dtCustomer.Columns.Add(colContact); > dtCustomer.Columns.Add(colPhone); > dtCustomer.Columns.Add(colFax); > dtCustomer.Columns.Add(colAddress); > > dtCustomer.PrimaryKey = new DataColumn[] { colCustomerID }; > > > > private void BindingData() > { > //建立BindingSource物件 > bsCustomer = new BindingSource(dsXIN, "Customer"); > //設定TextBox控制項的資料繫結 > txtCustomerID.DataBindings.Add("Text", > bsCustomer, "CustomerID"); > txtCompanyName.DataBindings.Add("Text", > bsCustomer, "CompanyName"); > txtContact.DataBindings.Add("Text", > bsCustomer, "Contact"); > txtPhone.DataBindings.Add("Text", > bsCustomer, "Phone"); > txtFax.DataBindings.Add("Text", > bsCustomer, "Fax"); > txtAddress.DataBindings.Add("Text", > bsCustomer, "Address"); > //設定DataGridView1控制項顯示BindingSource的資料來源 > DataGridView1.DataSource = bsCustomer; > //將DataColumn載入ComboBox,做為排序或尋找的參考欄位 > comboSortDataColumn.Items.Clear(); > comboFindDataColumn.Items.Clear(); > int i; > for (i = 0; i <= dtCustomer.Columns.Count - 1; i++) > { > comboSortDataColumn.Items.Add(dtCustomer.Columns[i].ColumnName); > comboFindDataColumn.Items.Add(dtCustomer.Columns[i].ColumnName); > } > comboSortDataColumn.SelectedIndex = 0; > comboFindDataColumn.SelectedIndex = 0; > } > > //AddingNew事件 > private void bsCustomer_AddingNew(object sender, > AddingNewEventArgs e) > { > txtCustomerID.Focus(); > } > > //ListChanged事件 > private void bsCustomer_ListChanged(object sender, > ListChangedEventArgs e) > { > ListBox1.Items.Add(e.ListChangedType); > ListBox1.Items.Add(e.NewIndex); > ListBox1.Items.Add(e.OldIndex); > } > > //利用PositionChanged改變記錄指標按鈕的狀態 > private void bsCustomer_PositionChanged(Object > sender, EventArgs e) > { > btnMoveFirst.Enabled = (bsCustomer.Position > 0); > btnMovePrevious.Enabled = (bsCustomer.Position > 0); > btnMoveNext.Enabled = (bsCustomer.Position < > bsCustomer.Count - 1); > btnMoveLast.Enabled = (bsCustomer.Position < > bsCustomer.Count - 1); > } > > private void btnMoveFirst_Click(object sender, > EventArgs e) > { > //移到第一筆記錄 > bsCustomer.MoveFirst(); > } > > private void btnMovePrevious_Click(object sender, > EventArgs e) > { > //移到上一筆記錄 > bsCustomer.MovePrevious(); > } > > private void btnMoveNext_Click(object sender, > EventArgs e) > { > //移到下一筆記錄 > bsCustomer.MoveNext(); > } > > private void btnMoveLast_Click(object sender, > EventArgs e) > { > //移到最後一筆記錄 > bsCustomer.MoveLast(); > } > > private void btnAddNew_Click(object sender, > EventArgs e) > { > //新增一筆空的記錄 > bsCustomer.AddNew(); > } > > private void btnEndEdit_Click(object sender, > EventArgs e) > { > //儲存編輯 > bsCustomer.EndEdit(); > } > > private void btnCancelEdit_Click(object sender, > EventArgs e) > { > //取消編輯 > bsCustomer.CancelEdit(); > } > > private void btnRemove_Click(object sender, > EventArgs e) > { > //移除目前記錄指標的記錄 > bsCustomer.RemoveCurrent(); > } > > private void btnFilter_Click(object sender, > EventArgs e) > { > //記錄篩選 > bsCustomer.Filter = txtFilter.Text; > } > > private void btnSort_Click(object sender, EventArgs > e) > { > //執行排序 > if (radioASC.Checked) > { > //升冪 > bsCustomer.Sort = comboSortDataColumn.Text + " " + > "ASC"; > } > else > { > //降冪 > bsCustomer.Sort = comboSortDataColumn.Text + " " + > "DESC"; > } > } > > private void btnRemoveFilter_Click(object sender, > EventArgs e) > { > //移除篩選條件 > bsCustomer.RemoveFilter(); > } > > private void btnRemoveSort_Click(object sender, > EventArgs e) > { > //移除排序條件 > bsCustomer.RemoveSort(); > } > > private void btnFind_Click(object sender, EventArgs > e) > { > //尋找記錄 > int foundIndex = bsCustomer.Find(comboFindDataColumn.Text, > > txtFindValue.Text); > if (foundIndex > -1) > { > bsCustomer.Position = foundIndex; > } > else > { > MessageBox.Show("找不到要尋找的記錄!"); > } > } > } } Now 1、BinaryFormatter;2、SoapFormatter;3、XmlSerializer 3.XmlSerializer is easier for rookie. How to used Finding API with XmlSerializer Thanks!
apiebayc#
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.