第一个程序的规划和开发步骤

发布于 2024-08-02 04:13:03 字数 503 浏览 4 评论 0原文

我正处于编写我的第一个真正程序的准备阶段。 我设计了一组表来存储我的财务数据。 我知道

1)什么数据放在表中的哪个位置

2)表和字段之间存在哪些关系

3)需要什么查询

4)将数据写入表的表单应该是什么样子

5)我需要什么输出以及如何组织它

我决定使用 C#,使用 WPF 作为 GUI,使用 SQL 数据库作为数据。 如果我理解正确的话,我将需要 ADO.NET 来与 SQL 数据库交互。 对我来说,问题是现在我只熟悉使用文本文件(或键盘)进行输入来编写非 GUI C++。

我不想成为一名具有多种技能和适销对路的程序员,所以我宁愿避免花时间学习不适用于该项目的东西。 我正在寻找从这里到有用的工作(和可维护)程序的最直接途径。

这就是我需要帮助的情况。 如果我遗漏了任何相关内容,请告诉我。

我的问题是,我需要从这里采取哪些步骤才能完成它?

感谢您的帮助。

I am in the preparation stages of writing my first real program. I've designed a set of tables to store my financial data. I know

1) what data goes where in the tables

2) what relationships exist between tables and fields

3) what queries are needed

4) what the forms should look like to write data to the tables

5) what output I need and how it should be organized

I've decided on C#, with WPF for the GUI, and a SQL database for the data. If I understand correctly I'll be needing ADO.NET to interface with the SQL db. The problem for me is that right now I am only familiar with writing non-GUI C++ using text files (or the keyboard) for input.

I'm not desiring to become a programmer with varied and marketable skills, so I'd rather avoid spending time learning things that won't apply to this project. I'm looking for the most direct route from here to a useful working (and maintainable) program.

So that's the situation I need help with. Please let me know if I left out anything relevant.

My question is, what are the steps I need to take from here to get it done?

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若无相欠,怎会相见 2024-08-09 04:13:03

我给您的建议是首先在所选平台下将您的第一个原型编写为控制台/文本程序。 当您按照您想要的方式获得输入和输出后,请再次请求重构帮助,以按照您想要的方式获得 UI。 您还可以轻松测试您的数据库查询,并且您可以更早地更有效地使用现有技能来获得正确的功能,但用户界面有限。

然后,您的控制台程序也将验证您的程序的 GUI 版本是否按预期工作。

编辑: 这是一个简单的程序,它从数据库并将其显示在屏幕上。

using System;
using System.Data;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        using (SqlConnection connection = new SqlConnection("Data Source=server;database=mydb; Integrated Security=SSPI"))
        {
            SqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT CategoryID, CategoryName FROM dbo.Categories;";

            try
            {
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                // process each row one at a time
                while (reader.Read())
                {
                    // reader contains the row (reader[0] is first column, etc)
                    Console.WriteLine("\t{0}\t{1}", reader[0], reader[1]);
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

使用这个(以及我从那里获得另一个版本的链接)来帮助您最初通过 ado.net。 作为经验丰富的程序员,您可以看到,如果遵循此模型,您可以创建基于传入查询返回数据的常用函数。 当您想要返回数据表而不是简单值时,我建议从 ExecuteReader 转移到 其他数据函数函数。

注意
一般来说,我不建议你从这里开始 - 我建议 Fluent NHbernate 但这对于初学者来说有点复杂在您了解代码(在.net中)与数据库及其中的数据的关系之后会更好。

还有一个想法。 如果您想使用 SqlClient 之外的其他技术,您可以使用 Linq2Sql。 观看此视频,看看是否有帮助。。 事实上,DimeCasts.net 上有一些非常有用的免费视频。

My suggestion to you is to first write your first prototype as a console/text program under the platform of choice. When you've got the input and output the way you want it - then ask again for refactoring help in getting the UI the way you want it. You can also get your db queries easily tested and you're using your existing skills more efficiently earlier on to get the functionality right but with a limited UI.

Your console program will then also be a verification that the GUI version of your program is working as expected.

Edit: Here is a simple program that reads a value from the database and puts it on the screen.

using System;
using System.Data;
using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        using (SqlConnection connection = new SqlConnection("Data Source=server;database=mydb; Integrated Security=SSPI"))
        {
            SqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT CategoryID, CategoryName FROM dbo.Categories;";

            try
            {
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                // process each row one at a time
                while (reader.Read())
                {
                    // reader contains the row (reader[0] is first column, etc)
                    Console.WriteLine("\t{0}\t{1}", reader[0], reader[1]);
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

Use this (and the link from where I got another version of this) to help you through through ado.net initially. As an experience programmer you can see that if you follow this model you can create common functions that return data based on passed in queries. When you want to get tables of data back instead of simple values, I'd suggest moving from ExecuteReader to other data functions functions.

N.B.
Generally I wouldn't suggest you start here - I'd suggest fluent NHbernate but that is bit more complex for a beginner and would be better after you understand the relationship your code (in .net) has to the DB and the data therein.

Also jsut had a thought. If you want to use another technology rather that SqlClient you can use Linq2Sql. Watch this video to see if its helpful.. In fact there are some very useful free videos on DimeCasts.net.

赤濁 2024-08-09 04:13:03

开始一个新的答案,因为我的旧答案不适用于这些非常具体的步骤。 这个答案是为了支持 Preet Sangha 的答复,但其目的是比我们任何人都更具体。

启动控制台应用程序并在应用程序顶部添加“using System.Data.SqlClient”行。 您需要从 Connection 对象开始,然后是 Command 对象。 尝试使用命令对象执行查询。 尝试使用“insert”语句和“select”语句。 对于“选择”,您将从数据库中获取一些内容。 为此,请使用 SqlDataReader(在命令上执行 Reader)并尝试提取值(reader.read() 和 getXXX,其中 XXX 是您要检索的数据类型)。 这些应该让你足够舒服地解决问题并返回一个更有针对性的问题。

鉴于您对此还很陌生,MSDN 将是您最好的朋友。 这应该有助于你开始:)
http://msdn.microsoft .com/en-us/library/system.data.sqlclient.sqlconnection(VS.71).aspx

Starting a new answer cause my old doesn't apply to these very specific steps. This answer is in support of Preet Sangha's reply, but is intended to be more specific than any of us have yet been.

Start a console app and add a "using System.Data.SqlClient" line at the top of the app. You'll need to start with a Connection object, then a Command object. Experiment with executing queries using your command object. Try both an "insert" statement and a "select" statement. For the "select", you'll be getting something back from the database. Use a SqlDataReader (executeReader on the command) for this and experiment with pulling values out (reader.read() & getXXX where XXX is the type of data you want to retrieve). These should make you comfortable enough to get your arms around the problem and return with a more directed question.

Given how new you are to this, MSDN will be your best friend. This should help get ya started :)
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(VS.71).aspx

归属感 2024-08-09 04:13:03

您是否有任何文档指定应用程序将要做什么,而不是规范如何完成事情?

如果您没有,请退后一步,编写功能规范。之后您可能想重做一些已经完成的工作。

您还应该花一些时间思考如何组织您的代码。 您将使用什么命名空间和类。 您将把代码放在哪里:

  • 用户界面
  • 业务逻辑
  • 数据库访问

您应该隔离应用程序的这些部分,以使其更易于维护。

Do You have any document specifying what the application is going to do instead of a specification how thing are going to be done?

If you don't have that, then take a step back and write a Functional Specification. After you have that you might want to redo some of the work you already did.

You also should take a few moment's to think how are you going to ogranize your code. What namespaces and classes are you going to use. Where will you put the code for:

  • User interface
  • Business logic
  • Database access

You should isolate those parts of your application to make it easier to maintain.

红玫瑰 2024-08-09 04:13:03

我并不想成为
程序员具有多样化且适销对路的
技能,所以我宁愿避免花钱
花时间学习不适用的东西
到这个项目。

在这种情况下,请跳过.Net。 你需要花时间来学好它才能做好工作。 既然您提到您有(也许很少)C++ 经验,我可能会在 Qt Designer 的帮助下使用 Qt 来布局 GUI。 从那时起,应用程序的其余部分应该与您已经完成的内容非常相似。

除非您知道使用 .Net 做什么,否则您很快就会得到极其难以维护的代码。 我将此归咎于 Visual Studio。 默认情况下,它鼓励“将这个东西拖到这里,放到那里,双击并编写代码”的编码方法,这通常会导致可怕的混乱。

如果您坚持认为无论如何都需要 C#/.Net,我鼓励您从后端开始并继续前进。 在考虑 GUI 之前,请花时间对您的实体、数据访问和业务层进行建模。 您甚至可以更进一步编写两个项目。 其中之一是您的 dll,其中包含业务和数据访问逻辑。 另一个是您的可执行文件,您可以在其中将 UI 事件连接到 dll 的 api。

祝你好运。

I'm not desiring to become a
programmer with varied and marketable
skills, so I'd rather avoid spending
time learning things that won't apply
to this project.

In that case, skip .Net. It'll take you time to learn it well enough to do a good job. Since you mentioned you have (perhaps minimal) C++ experience, I'd maybe use Qt instead with the aid of Qt Designer to layout the GUI. From that point the rest of the app should be much like the stuff you've already done.

Unless you know what your doing with .Net, you'll end up with wildly unmaintainable code very, very quickly. I blame Visual Studio for this. By default, it encourages a "drag this thingy here, drop that there, double click and write code" approach to coding that usually results in a horrendous mess.

If you insist that you want C#/.Net anyway, I encourage you to start at the backend and work your way forward. Take the time to model your entities and your data access and your business layer before you even think about GUI. You may even take this a step further and write two project. One would be your dll, containing business and data access logic. The other would be your executable, where you wire your UI events into the dll's api.

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文