只需单击一下,如何保存所有注册员工的数据? [英] How to save data against all registered employees with single click?

查看:45
本文介绍了只需单击一下,如何保存所有注册员工的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何保存所有注册员工的数据?

how to save data against all registered employees?

我希望当我单击按钮时,然后保存不存在"(Absent)

i want that when i'm click a button then save "Absent" in a column name 'Status' against all registerd employees id... 

推荐答案

这与WPF有什么关系?

How is this related to WPF?

推荐答案

您还没有提供足够多的信息来让任何人做比猜测更多的事情.

You've also not supplied anywhere near enough information for anyone to do any more than guess.

.

随便吧.

在WPF中,我希望mvvm和按钮应该绑定到某种iCommand.

In WPF terms I would expect mvvm and the button should be bound to an iCommand of some sort.

我将使用实体框架连接到数据库.

I would use entity framework to connect to the database.

由于要更改的行可能不在内存中,因此我将直接考虑对拥有已注册员工的表进行查询.可能是注册状态和某种必要的位置,或者可能是所有员工都已注册"了.在 在这种情况下,所有员工都需要更换.

Since the rows to be changed may not be in memory I would consider a query directly against whatever table holds registered employees. Maybe registered is a status and some sort of where is necessary, or maybe all employees are "registered" in which case it's all employees need changing.

您可以执行以下操作:

context.Database.ExecuteSqlCommand( 
        "UPDATE dbo.Employees SET Status= 'Absent' WHERE Registered = 1"); 

上下文是您的dbcontext的实例.

我会从命令中调用它.大多数开发人员使用框架来简化icommand的实现,Prism或MVVMLight很受欢迎.

Where context is an instance of your dbcontext.

And I'd call that from a command. Most devs use a framework to make implementing icommand easier and Prism or MVVMLight is popular.

我喜欢MVVMLight,您可以在此处看到一个简单的中继命令示例:

I like MVVMLight and you can see a simple example of a relaycommand here:

https://social.technet.microsoft.com/wiki/contents/articles/32164.wpf-mvvm-step-by-step-2.aspx

https://social.technet.microsoft.com/wiki/contents/articles/32164.wpf-mvvm-step-by-step-2.aspx

我倾向于使用更复杂的模式,例如:

I tend to use a rather more sophisticated pattern like:

        private RelayCommand addCommmand;
        public RelayCommand AddCommmand
        {
            get
            {
                return addCommmand
                ?? (addCommmand = new RelayCommand(
                 () =>
                 {
                     // Code goes here
                 }));
            }
        }


这篇关于只需单击一下,如何保存所有注册员工的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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