• 大小: 80KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-03
  • 语言: C#
  • 标签: c#  xml  数据库  

资源简介

实现了XML文件的读写,与传统的读写方式不一样,采用的是XML序列化的读写方式,先将xml转化成List,再进行增删改,非常方便。

资源截图

代码片段和文件信息

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“
            };
            //构造数据
            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;
            //写进文件
            //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);
            ////初始化页数
            //for (int i = 1; i < boColl.TotalPageCount+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);
            }
            //初始化页数
            // cbPages.Items.Clear();
            var pageItemList = new List();
            for (int i = 1; i < boColl.TotalP

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-06-04 14:45  xml\
     文件         184  2016-05-23 09:47  xml\App.config
     文件       14739  2016-05-22 16:11  xml\Form1.Designer.cs
     文件       20396  2016-05-22 16:46  xml\Form1.cs
     文件        5817  2016-05-22 16:11  xml\Form1.resx
     文件         527  2016-05-18 20:47  xml\Program.cs
     目录           0  2016-06-04 14:45  xml\Properties\
     文件        1338  2016-05-18 20:47  xml\Properties\AssemblyInfo.cs
     文件        2870  2016-05-23 09:47  xml\Properties\Resources.Designer.cs
     文件        5612  2016-05-18 20:47  xml\Properties\Resources.resx
     文件        1115  2016-05-23 09:47  xml\Properties\Settings.Designer.cs
     文件         249  2016-05-18 20:47  xml\Properties\Settings.settings
     文件        4102  2016-05-23 09:47  xml\WinFormNoteBook.csproj
     文件         998  2016-05-23 09:54  xml\WinFormNoteBook.sln
     文件       12288  2016-05-23 09:54  xml\WinFormNoteBook.v12.suo
     目录           0  2016-06-04 14:45  xml\bin\
     目录           0  2016-06-04 14:45  xml\bin\Debug\
     文件       24576  2016-05-23 09:47  xml\bin\Debug\WinFormNoteBook.exe
     文件         184  2016-05-23 09:47  xml\bin\Debug\WinFormNoteBook.exe.config
     文件       42496  2016-05-23 09:47  xml\bin\Debug\WinFormNoteBook.pdb
     文件       24224  2016-05-23 09:53  xml\bin\Debug\WinFormNoteBook.vshost.exe
     文件         184  2016-05-23 09:47  xml\bin\Debug\WinFormNoteBook.vshost.exe.config
     文件         490  2012-06-02 22:34  xml\bin\Debug\WinFormNoteBook.vshost.exe.manifest
     目录           0  2016-06-04 14:45  xml\obj\
     目录           0  2016-06-04 14:45  xml\obj\Debug\
     文件        1464  2016-05-19 22:55  xml\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7272  2016-05-23 09:47  xml\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2016-06-04 14:45  xml\obj\Debug\TempPE\
     文件        4608  2016-05-23 09:47  xml\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll
     文件           0  2016-05-18 20:47  xml\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
     文件           0  2016-05-18 20:47  xml\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
............此处省略8个文件信息

评论

共有 条评论