WinForm开发一个MVP模式的桌面应用程序 [英] WinForm development of a desktop application in MVP - pattern

查看:365
本文介绍了WinForm开发一个MVP模式的桌面应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是


我正在开发WinForms应用程序并有一些问题。



该应用程序应用于数据采集。它应记录车辆信息,将其存储在数据库中并在应用程序中显示。此外,数据将通过按钮导出到Excel表格。我是编程新手,这个
是我第一次用C#,Visual Studio和WinForms开发。我已经开始创建一个具有不同UserControls的GUI(其他"windows")。该应用程序没有很多功能。 DataGridView用于将数据存储在
数据库中,并将其显示在另一个DataGridView中的另一个UserControl上。其余的是在窗口/菜单项之间切换的按钮和用于计算输入的车辆的按钮。 DataGridView看起来像这样=列:品牌,型号,构造年份,
KM状态,颜色和最后2列填充按钮。一个用于添加设备,另一个用于删除创建的车辆。我考虑过这个,因为否则DataGridView表会填充太多信息(设备:
皮革,导航等)。设备按钮应打开一个新窗口,以输入每辆车的设备。在Table(DataGridView)下的表单末尾有很多可用空间。我想用它来提取从DB输入的
的设备数据并将其显示在那里,这样你仍然可以通过在应用程序的DataGridView中点击车辆来了解车辆所具有的设备。为此,我将分配一个唯一的ID,并使用SQL查询仅显示表
中具有相应ID(车辆)的设备。我对我的项目有一些疑问,但我从基础开始,因为它太多了。
$


如何在MVP模式中开发它。 />
如上所述显示设备的想法是否可行?


非常感谢提前!



解决方案

您好,


由于您不熟悉在Visual Studio中使用C#进行开发我的建议是开始简单。


在Visual Studio中创建一个解决方案,为Windows窗体项目中使用的数据操作创建一个类项目。


关于使用数据,使用像SQL-Server(有免费版SQL-Server Express)这样的体面数据库,使用托管数据提供程序SqlClient。此外,在编写任何代码之前创建数据库和关系,然后填充表,
直接在数据库中运行任何预期的SQL语句,以确保它们按预期运行。一旦满意,然后开始编写数据操作,然后使用您的业务需求针对数据库编写单元测试。只有这样才能启动
编写代码来与前端项目进行交互。


以上只是一个开始,比你想要的模式更容易但是没有开始使用模式,而是从托管数据提供程序开始。稍后转换到使用Entity Framework选项的模式。


最后,当使用Excel查看开源库(如SpreadSheetLight,EPPlus等)而不是使用Excel自动化时,一本书可以写下为什么要远离Excel自动化,尤其是刚才提到的库,或者如果数据需要格式化,则依赖于
,还可以选择使用与SQL-Server相切(或不相关)的OleDb管理数据提供程序。


Hello, everybody,

I am working on the development of a WinForms application and have some questions.

The application should be used for data acquisition. It should record vehicle information, store it in a database and display it in the application. In addition, the data is to be exported to an Excel table via a button. I am quite new to programming and this is the first time that I have developed in C#, Visual Studio and WinForms. I have already started and created a GUI with different UserControls (other "windows"). The application doesn't have many features. A DataGridView is used to store data in the database and display it on another UserControl in another DataGridView. The rest are buttons to switch between the windows/menu items and a button to count the entered vehicles. DataGridView looks like this= columns: Brand, model, year of construction, KM status, color and the last 2 columns are filled with buttons. One for adding the equipment and the other for deleting the created vehicle. I have considered this, because otherwise the DataGridView table would be filled with too much information (equipment: leather, navigation, etc.). The equipment button should open a new window to enter the equipment for each vehicle. At the end of the form under Table (DataGridView) there is a lot of free space. I want to use this to extract the equipment data that have been entered from the DB and display it there, so that you still know which equipment the vehicle has by clicking on the vehicle in the DataGridView in the app. For this I would assign a unique ID, and with a SQL query to display only the equipment from the table with the respective ID(vehicle). I have some questions concerning my project, but I start with the basics, because it is getting too much.

How can I develop this in the MVP pattern.
Is the idea of displaying the equipment as explained above feasible?

Many thanks in advance!

解决方案

Hello,

Since you are new to developing in C# in Visual Studio my recommendation is to start out simple.

Create a solution in Visual Studio, create a class project for data operations which is used in a Windows form project.

In regards to working with data, use a decent database such as SQL-Server (there is a free edition SQL-Server Express), use the managed data provider SqlClient. Also, create the database and relationships prior to writing any code and then populate the tables, run any expected SQL statements directly in the database to ensure they function as expected. Once satisfied then begin writing your data operations and then write unit test against the database using your business requirements. Only then should you start writing code to interface with the front end project.

The above is simply a start and much easier then the pattern you desire yet one doesn't start with the pattern but instead start with managed data providers. Later transition to the pattern with the option to use Entity Framework.

Lastly, when working with Excel look at open source libraries such as SpreadSheetLight, EPPlus etc rather than using Excel automation, a book could be written on why to stay clear of Excel automation especially with libraries just mentioned or depending on if data needs formatting or not there is also the option to use OleDb manage data provider in tangent (or not) with SQL-Server.


这篇关于WinForm开发一个MVP模式的桌面应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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