如何动态创建文本框并在C#windows窗体应用程序中将值插入数据库 [英] How do I create textbox dynamically and insert value into database on C# windows form application

查看:134
本文介绍了如何动态创建文本框并在C#windows窗体应用程序中将值插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个C#windows窗体项目,用于计算员工的个人所得税,我遇到的问题是我的客户在表格上动态创建津贴的奇怪要求,公司有不同的政策,关于哪些津贴会给予他们的员工,我试图在申请中获取流行的津贴,并提供其他津贴的文本框,因此可以输入申请表格中未包含的其他津贴的总和值,因为申请表不会仅用于一家公司,现在的问题是:我的客户不希望我在表格中包含的其他配额texbox,他希望能够点击表格上的某些东西,并且应该打开他可以输入的地方任何其他未包含在表格字段中的补贴,我已尝试在表格上贴上补贴名称和津贴金额的标签,但这似乎不起作用,因为肠衣ld每个月只为每位员工做一次,有时根据公司的要求,他们的津贴可能达到10。我不知道我们这里的任何高级合作伙伴是否做过类似的事情,如果他们能与我分享他们的知识,我将不胜感激。谢谢



我的尝试:



我试过这种方法在表格上贴上津贴名称和津贴金额的标签,但这似乎没有用,因为每个员工只能在一个月内完成一次,而且他们的津贴有时可能达到10个,具体视公司而定。

I am currently working on a C# windows form project that would be used to calculate personal income tax for employee, i am having issue with my client weird requirement of creating allowances dynamically on the form, companies have different policies concerning which allowance would be given to thier employee, i have tried to captured the popular allowances in the application, and also provided a textbox for other allowances, so could enter the sum value of other allowances that is not included in the application form since the application is not going to be used for only one company, the issue now is: my client does not want the others allowances texbox that i included on the form, he wants to be able to click on somthing on the form and that should open where he can type in any other allowances that was not included on the form fields, i have tried the approach of putting a label for allowance name and allowance amount on the form, but this didn't seem to work since enteries could only be done once for each employee very month and thier allowances could up to ten sometimes depending on the company. I dont know whether any of our senior colleadgues here had done anything similar to this, i will appreciate if they could share thier knowledge with me. Thanks

What I have tried:

I have tried the approach of putting a label for allowance name and allowance amount on the form, but this didn't seem to work since enteries could only be done once for each employee very month and thier allowances could up to ten sometimes depending on the company.

推荐答案

听起来你的客户想要一个弹出对话(模态)的津贴。



我建议在表单上的列表框中显示每个员工的配额列表 - 使其可滚动,以便无论有多少都无关紧要。您还可以考虑使用ComboBox输入任何非标准的配额 - 如果您离标准条款太远,您可能会遇到收入问题。

参考:下拉列表&组合框(Windows) [ ^ ]



如果您使用模态对话框,那么您可能会发现本文很有用(还有其他文章链接在文章本身)

在两个表格之间传递信息,第1部分:父母对孩子 [ ^ ]



最后在UI方面,最好使用Button而不是标签来触发对话框。



至于数据库方面的事情,请不要,我的意思是不要将这些限额存储为单个字符串。管理它们真的很痛苦,使用它们真的很痛苦,最终你会耗尽列空间来存储它们。这是您可以选择的最糟糕的设计。 (你猜对了我真的不喜欢这个想法吗?:-))/ b $ b一个更好的解决方案就是有一个链接表...例如

It sounds like your "client" wants a pop-up Dialog (modal) for the Allowances.

I would suggest displaying the list of allowances per individual employee in a listbox on the form - make it scrollable so that it doesn't matter how many there are. You could also consider using a ComboBox to enter any allowances that aren't "standard" - but you might run into problems with the Revenue if you go too far away from standard terms.
Reference: Drop-down Lists & Combo Boxes (Windows)[^]

If you do use a modal dialog then you might find this article useful (there are further article links in the article itself)
Transferring information between two forms, Part 1: Parent to Child[^]

Finally on the UI side of things it would be better to use a Button than a label to trigger the dialog.

As to the database side of things, do NOT, I really mean DO NOT store these allowances as a single string. It is a real pain to manage them, a real pain to use them and eventually you will run out of column space to store them. It is the WORST possible design you could choose. (Have you guessed I really don't like the idea? :-) )
A better solution is to have a linking table...e.g.
Table Employee (EmpId, FirstName, LastName, etc)
Table Allowances (AllowId, Description, etc)



这样的表可以将配额链接到特定员工:


A table like this can link allowances to specific employees:

Create table AllowEmpl
(
    EmpId int,   -- Foreign Key to Employee table
    AllowId int  -- Foreign Key to Allowances table
)

通过使用这种结构,您可以为每位员工提供无限制的津贴,它们可以轻松插入,搜索,删除,您无需更改添加更多Allowances时的数据库模式。

By using this construction you can have unlimited allowances per employee, they are easily inserted, searched for, deleted and you won't have to change the database schema when more Allowances are added.


这篇关于如何动态创建文本框并在C#windows窗体应用程序中将值插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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