如何控制序列

编程入门 行业动态 更新时间:2024-10-04 09:32:03
本文介绍了如何控制序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个包含数据库的XML文件的应用程序。它有客户服务器结构。因此,这里的服务器将使用数据读取XML文件中的数据并将其存储在XML模式。然后,服务器将序列化数据并把它传递到UI(客户端)。所以UI数据的是通过在leftside,列表视图在右上角和PropertyGrid中的右下方使用树状视图显示。

数据在用户界面被分为类和对象。所以,现在我们已经在我们的数据库中的XML文件machinesclass.xml和machineobjects.xml。 machinesclass.xml包含各种类,如电子类,计算机类里面,agriculturetool类等,并machineobjects.xml包含电视,电脑的Pentium4,Tractror等,所以现在的用户界面,如果我选择树形电子节点,它会列出电视,收音机,电话等什么都反对它在右上角部分含有利用ListView和如果我选择的对象TV的电视相关属性在右下角的PropertyGrid所示。

所以现在我们有一个任务,如果有人想夺回从UI所选对象的XML文件(的.xml)方面,从父machinesclass.xml和machineobjects.xml

例如,如果有人从UI列表视图选择电视,并希望在.xml文件(tv.xml)方面采取的备份,这样一段时间后,他就可以导入数据,什么逻辑,我们可以实现吗?我可以序列ListView和PropertyGrid的,或者是有任何选项做到这一点?这是一个有点code的我使用了

中的UI复制粘贴操作解决方案   

我可以序列ListView和PropertyGrid的,或者是有任何选项  这样做吗?

下面是如何序列化一个ListView:结果的www.$c$cproject/Articles/3335/Persist-ListView-settings-with-serialization

下面是如何序列化的PropertyGrid:结果的www.$c$cproject/Articles/27326/Load-and-Save-Data-Using-PropertyGrid

我的建议是正确地做到这一点,我认为正确的解决办法是序列化的ListView和PropertyGrid中绑定了太多的业务对象。从GUI中分离业务逻辑,那么它真的容易的!

修改(OP后编辑的问题,以显示code):

将数据保存到XML文件:

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BinFormatter =新System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();System.IO.FileStream FS =新System.IO.FileStream(C:\\\\ tv.xml,IO.FileMode.Create);BinFormatter.Serialize(FS,新的ArrayList(listview1.Items));FS.C​​lose();

从XML文件中读取数据:

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BinFormatter =新System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();串FNAME;System.IO.FileStream FS =新System.IO.FileStream(C:\\\\ tv.xml,IO.FileMode.Open);listview1.Items.AddRange(BinFormatter.Deserialize(FS).ToArray(typeof运算(ListViewItem的)));FS.C​​lose();

下面是你如何用PropertyGrid中做到这一点: PropertyGrid.Serialize

We have an application which contains database as xml files. It has client server architecture. So here server will read data from xml file by using dataset and store it in xml schema. Then server will serialize the data and pass it to the UI(client).So UI data’s are displayed by using Treeview on leftside, listview on right top and propertygrid on right bottom.

Data’s in Ui are categorized in to classes and objects. So now we have an xml file machinesclass.xml and machineobjects.xml in our database. machinesclass.xml contains various classes like electronic class,computer classs,agriculturetool class etc and machineobjects.xml contains TV,pentium4 computer,Tractror etc. So now in UI if I select electronic node from treeview ,it will list TV,radio,telephone etc what ever objects it contains in right top part by using Listview and if I select object "TV" related properties of TV are shown in propertygrid on right bottom.

So now we have a task that if somebody wants to take back up of selected objects from UI in terms of xml file(.xml), from parent machinesclass.xml and machineobjects.xml

for example if somebody selects TV from UI listview and wants to take back up in terms of .xml file(tv.xml) so that after sometime he can import data , what logic we can implement here? Can I serialize listview and propertygrid, or is there any options to do that? This is a bit of code i am using for copy paste operation within UI

解决方案

Can I serialize listview and propertygrid, or is there any options to do that?

Here is how to serialize a ListView: www.codeproject/Articles/3335/Persist-ListView-settings-with-serialization

Here is how to serialize a PropertyGrid: www.codeproject/Articles/27326/Load-and-Save-Data-Using-PropertyGrid

My advice is to do it properly, and I think the correct solution would be to serialize the business objects that the ListView and PropertyGrid are bound too. Separate the business logic from the GUI, then its really easy!

Edit (after OP edited question to show code):

To Save Data to the XML file:

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BinFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.FileStream FS = new System.IO.FileStream("C:\\tv.xml", IO.FileMode.Create); BinFormatter.Serialize(FS, new ArrayList(listview1.Items)); FS.Close();

To Read Data in from an XML file:

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BinFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); string fname; System.IO.FileStream FS = new System.IO.FileStream("C:\\tv.xml", IO.FileMode.Open); listview1.Items.AddRange(BinFormatter.Deserialize(FS).ToArray(typeof(ListViewItem))); FS.Close();

Here's how you do it with a PropertyGrid: PropertyGrid.Serialize

更多推荐

如何控制序列

本文发布于:2023-11-29 15:23:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646786.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!