資源簡介
XML在我們的程序中用到的越來越多,因為它存儲、讀取、修改都比較方便。本例是就是對Xml的增刪改查...

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;
using?System.xml;
using?System.Runtime.Serialization.Formatters.Binary;
namespace?Parsexml
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????IList?studentList;
????????///?
????????///?創建
????????///?
????????///?
????????///?
????????private?void?btnCreate_Click(object?sender?EventArgs?e)
????????{
????????????if?(!InputCheck())
????????????{
????????????????return;
????????????}
????????????if?(File.Exists(“Student.xml“)?&&?MessageBox.Show(“文件已經存在,是否覆蓋?“?“提示“?MessageBoxButtons.YesNo?MessageBoxIcon.Information)?==?DialogResult.No)
????????????????return;
????????????Student?s?=?BindData();
????????????xmlFunc.Createxml(“Student.xml“?s);
????????????ShowData(“Student.xml“);
????????}
????????///?
????????///?綁定數據
????????///?
????????///?
????????private?Student?BindData()
????????{
????????????Student?s?=?new?Student();
????????????s.SID?=?Convert.ToInt32(nudSID.Value);
????????????s.Sex?=?cboSex.Text;
????????????s.Name?=?txtName.Text.Trim();
????????????s.Age?=?Convert.ToInt32(nudAge.Value);
????????????s.Address?=?txtAddress.Text.Trim();
????????????return?s;
????????}
????????///?
????????///?添加
????????///?
????????///?
????????///?
????????private?void?btnAdd_Click(object?sender?EventArgs?e)
????????{
????????????if?(!InputCheck())
????????????{
????????????????return;
????????????}
????????????if?(!File.Exists(“Student.xml“))
????????????{
????????????????MessageBox.Show(“沒有xml文件,請先點擊創建!“?“提示?“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????????????return;
????????????}
????????????Student?s?=?BindData();
????????????xmlFunc.Append(“Student.xml“?s);
????????????ShowData(“Student.xml“);
????????}
????????///?
????????///?刪除
????????///?
????????///?
????????///?
????????private?void?btnDel_Click(object?sender?EventArgs?e)
????????{
????????????string?sid?=?string.Empty;
????????????if?(treeView1.SelectedNode?==?null)
????????????{
????????????????MessageBox.Show(“請先選擇學員!“?“提示“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????????????return;
????????????}
????????????if?(treeView1.SelectedNode.Level?==?0)
????????????????sid?=?treeView1.SelectedNode.Tag.ToString();
????????????else
????????????????sid?=?treeView1.SelectedNode.Parent.Tag.ToString();
????????????if?(MessageBox.Show(“確定要刪除該學員嗎?“?“提示“?MessageBoxButtons.YesNo?MessageBoxIcon.Information)?==?DialogResult.No)
????????????????return;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????32768??2010-04-11?12:09??Parsexm
?????文件??????42496??2010-04-11?12:09??Parsexm
?????文件???????5632??2005-11-11?22:25??Parsexm
?????文件???????1065??2010-04-11?12:03??Parsexm
?????文件????????697??2010-04-11?16:32??Parsexm
?????文件???????8494??2010-04-11?12:08??Parsexm
?????文件??????12565??2009-07-12?17:14??Parsexm
?????文件???????5814??2009-07-12?17:14??Parsexm
?????文件????????842??2010-04-11?11:56??Parsexm
?????文件??????32768??2010-04-11?12:09??Parsexm
?????文件????????180??2009-07-12?17:17??Parsexm
?????文件??????42496??2010-04-11?12:09??Parsexm
?????文件????????180??2009-07-10?16:05??Parsexm
?????文件????????275??2010-04-11?12:09??Parsexm
?????文件???????3299??2009-07-10?16:34??Parsexm
?????文件????????467??2009-07-10?16:01??Parsexm
?????文件???????1188??2009-07-10?16:01??Parsexm
?????文件???????2870??2009-07-10?16:01??Parsexm
?????文件???????5612??2009-07-10?16:00??Parsexm
?????文件???????1091??2009-07-10?16:01??Parsexm
?????文件????????249??2009-07-10?16:00??Parsexm
?????文件???????1587??2010-04-11?11:56??Parsexm
?????文件???????6541??2010-04-11?11:56??Parsexm
?????文件????????913??2009-07-10?16:01??Parsexm
????..A..H.?????15872??2010-04-11?12:09??Parsexm
?????目錄??????????0??2010-04-11?16:31??Parsexm
?????目錄??????????0??2010-04-11?16:31??Parsexm
?????目錄??????????0??2010-04-11?16:31??Parsexm
?????目錄??????????0??2010-04-11?16:31??Parsexm
?????目錄??????????0??2010-04-11?16:31??Parsexm
............此處省略7個文件信息
- 上一篇:LDPC源代碼
- 下一篇:CSDN小秘書v1.1源碼
評論
共有 條評論