将选中的复选框的详细信息保存在xml文件中 [英] Saving details of checked checkbox in xml file

查看:122
本文介绍了将选中的复选框的详细信息保存在xml文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

我再次在这个网站上问这个问题是因为我无法在Web中找到更好的解决方案.我的问题是我想将所有选中的复选框保存在xml文件中,并出于打印目的对其进行检索..xml文件仅用作选中的复选框的临时数据库.
任何帮助将不胜感激...

晚安,上帝保佑人们..=)


谢谢..

Hi...

I came to this point of asking in this site AGAIN because I can''t find a better solution in web. My problem is I want to save all the checked checkbox in an xml file and retrieve it for printing purposes.. the xml file will only serve as a temporary database of checked checkbox..

Any help will be appreciated...

Good night and God bless people.. =)


Thanks..

推荐答案

这是您需要做的:您确实需要UI和持久性之间的数据层.不要以XML加载商店UI;加载或存储可以绑定到UI的数据层.还有很多其他原因要有单独的数据层.在您的情况下,它只是一个或多个纯数据类/结构.

如果要直接链接UI和XML,则将自己锁定在UI,XML表示形式和数据的硬耦合刚性设置中,而这些设置将无法以任何向后兼容的方式进行更改.甚至不要玩让您的UI可序列化之类的想法.不要手动操作XML.

如果问题很简单,则可以进行一些手动"数据绑定:开发一个从数据实例填充UI(复选框设置或其他选项)的过程,并使UI事件修改数据实例(用于复选框) ,请使用事件CheckedChanged;对于WPF:Unchecked).

(再次,不要再给我们添麻烦了!我已经厌倦了检查三种不同库的API!请始终对您的UI库进行标记(如果您使用的是一种).)

现在,用于持久性的内容是什么?毫无疑问,请使用数据合同.请参阅 http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

无需手动使用XML.数据协定自动提供一种非侵入性的方式来存储和恢复几乎任何数据的对象图.您只需要添加属性到您的类型及其成员就可以了;因此您的程序在这里纯粹是声明性的.

请在我倡导这种方法的地方查看我过去的答案:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [ http://en.wikipedia .org/wiki/Architectural_pattern_(computer_science) [^ ]):

MVVM —模型视图视图模型,
http://en.wikipedia.org/wiki/Model_View_ViewModel [> http://en.wikipedia.org/wiki/Model-view-controller [ ^ ])),

MVA —模型视图适配器,
http://en.wikipedia.org/wiki/Model–view–adapter [ ^ ],

MVP —模型视图呈现器,
> http://en.wikipedia.org/wiki/Model-view-presenter [ ^ ].
请注意这些架构的动机.如果您了解它,就可以提出更好的设计思路.

如果您遇到任何问题,请问一个后续问题.我很乐意回答.

—SA
Here is what you need to do: you really need a data layer between UI and persistence. Don''t load of store UI in XML; load or store your data layer which you can bind to UI. There are many other reasons to have a separate data layer. In your case it would be just one or more pure-data classes/structures.

If you want to link UI and XML directly you will lock yourself in hard-coupled rigid settings for UI, XML presentation and data which you won''t be able to change in any backward-compatible manner. Don''t even play with the idea of making you UI serializeable or something like that. Don''t operate XML manually.

If you problem is simple enough, you can make some "manual" data binding: develop a procedure of populating you UI (check boxes set or whatever) from the instance of data and make your UI events modifying an instance of data (for check boxes, use the event CheckedChanged; for WPF: Checked, Unchecked).

(Again, stop giving us hard time! I''m tired of checking APIs for three different libraries! Please, always tag your UI library if you use one.)

Now, what to use for persistence? No doubt, use Data Contract. See http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

There is no need to use XML manually. Data contract automatically provides a non-intrusive way to store and restore any object graph with practically any data. You only add attributed to your types and their members you need to persist; so your programming is purely declarative here.

Please also see my past answers where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

I suggest you learn and analyze applicability of the following architectural patterns (http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)[^]):

MVVM — Model View View Model,
http://en.wikipedia.org/wiki/Model_View_ViewModel[^],

MVC — Model-View-Controller,
http://en.wikipedia.org/wiki/Model-view-controller[^]),

MVA — Model-View-Adapter,
http://en.wikipedia.org/wiki/Model–view–adapter[^],

MVP — Model-View-Presenter,
http://en.wikipedia.org/wiki/Model-view-presenter[^].
Pay attention for the motivation of those architectures. If you understand it, you would be able to create better design ideas.

If you face any problems, ask a follow-up question; I''ll gladly answer.

—SA


这篇关于将选中的复选框的详细信息保存在xml文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆