-
大小: 80KB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2021-06-03
- 語言: C#
- 標(biāo)簽: c#??xml??數(shù)據(jù)庫??
資源簡介
實(shí)現(xiàn)了XML文件的讀寫,與傳統(tǒng)的讀寫方式不一樣,采用的是XML序列化的讀寫方式,先將xml轉(zhuǎn)化成List,再進(jìn)行增刪改,非常方便。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.IO;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?System.Runtime.Serialization;
using?System.Runtime.Serialization.Json;
using?System.xml.Serialization;
namespace?WinFormNoteBook
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????public?string?FilePath=“d:note.xml“;
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????????NoteType?noteType?=?new?NoteType
????????????{
????????????????ID?=?new?Guid(“2d1c47b6-e0d0-4aa8-bfe4-c1bedd30827c“)
????????????????Name?=?“分類1“
????????????????Description?=?“這是分類“
????????????????SortCode?=?“1“
????????????};
????????????//構(gòu)造數(shù)據(jù)
????????????List?noteList?=?new?List
????????????{
????????????????new?Note?{ID=Guid.NewGuid()Name=“陳大“SortCode=“1“NoteTypeName=noteType.NameNoteTypeID=noteType.ID?}
????????????????new?Note?{ID=Guid.NewGuid()Name=“王大“SortCode=“2“NoteTypeName=noteType.NameNoteTypeID=noteType.ID?}
????????????????new?Note?{ID=Guid.NewGuid()Name=“李大“SortCode=“3“NoteTypeName=noteType.NameNoteTypeID=noteType.ID?}
????????????????new?Note?{ID=Guid.NewGuid()Name=“阿大“SortCode=“4“?NoteTypeName=noteType.NameNoteTypeID=noteType.ID?}
????????????};
????????????for?(int?i?=?0;?i?3;?i++)
????????????{
????????????????var?bo?=?new?Note?{?ID?=?Guid.NewGuid()?Name?=?“陳大“+i?SortCode?=?“1“?NoteTypeName?=?noteType.Name?NoteTypeID?=?noteType.ID?};
????????????????noteList.Add(bo);?
????????????}
????????????for?(int?i?=?1;?i?10+1;?i++)
????????????{
????????????????cbPageSize.Items.Add(i*10);
????????????}
?????????
????????????noteType.Notes?=?noteList;
????????????//寫進(jìn)文件
????????????//var?jsonStr=?ToJson(noteType);?
????????????//?WriteFile(FilePath?jsonStr);
????????????WritexmlFile(noteType);
????????????//讀取文件
????????????//??jsonStr?=?ReadFile(“d:note.txt“);
????????????//var?data=?Toobject(jsonStr);
????????????//int?pageIndex?=?1;
????????????//int?pageSize?=?2;
????????????//var?boColl?=?gotoPage(1);
????????????////初始化頁數(shù)
????????????//for?(int?i?=?1;?i?????????????//{
????????????//????cbPages.Items.Add(i);
????????????//}
????????????initPageItem(1);
????????????gvData.CurrentCell?=?null;
????????
????????
???????????
????????}
????????public?void?initPageItem(int?pageIndex)
????????{
????????????var?boColl?=?gotoPage(pageIndex);
????????????if?(boColl.Count?==?0)
????????????{
????????????????pageIndex--;
????????????????if?(pageIndex?!=?0)?
????????????????boColl?=?gotoPage(pageIndex);
????????????}
????????????//初始化頁數(shù)
????????????//?cbPages.Items.Clear();
????????????var?pageItemList?=?new?List();
????????????for?(int?i?=?1;?i?
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-06-04?14:45??xm
?????文件?????????184??2016-05-23?09:47??xm
?????文件???????14739??2016-05-22?16:11??xm
?????文件???????20396??2016-05-22?16:46??xm
?????文件????????5817??2016-05-22?16:11??xm
?????文件?????????527??2016-05-18?20:47??xm
?????目錄???????????0??2016-06-04?14:45??xm
?????文件????????1338??2016-05-18?20:47??xm
?????文件????????2870??2016-05-23?09:47??xm
?????文件????????5612??2016-05-18?20:47??xm
?????文件????????1115??2016-05-23?09:47??xm
?????文件?????????249??2016-05-18?20:47??xm
?????文件????????4102??2016-05-23?09:47??xm
?????文件?????????998??2016-05-23?09:54??xm
?????文件???????12288??2016-05-23?09:54??xm
?????目錄???????????0??2016-06-04?14:45??xm
?????目錄???????????0??2016-06-04?14:45??xm
?????文件???????24576??2016-05-23?09:47??xm
?????文件?????????184??2016-05-23?09:47??xm
?????文件???????42496??2016-05-23?09:47??xm
?????文件???????24224??2016-05-23?09:53??xm
?????文件?????????184??2016-05-23?09:47??xm
?????文件?????????490??2012-06-02?22:34??xm
?????目錄???????????0??2016-06-04?14:45??xm
?????目錄???????????0??2016-06-04?14:45??xm
?????文件????????1464??2016-05-19?22:55??xm
?????文件????????7272??2016-05-23?09:47??xm
?????目錄???????????0??2016-06-04?14:45??xm
?????文件????????4608??2016-05-23?09:47??xm
?????文件???????????0??2016-05-18?20:47??xm
?????文件???????????0??2016-05-18?20:47??xm
............此處省略8個(gè)文件信息
- 上一篇:NPOI方式讀取、保存等excel操作
- 下一篇:北大青鳥s1ktv1.rar
評論
共有 條評論