如何在Windows窗体应用程序中使用会话 [英] How to use sessions in windows form application

查看:93
本文介绍了如何在Windows窗体应用程序中使用会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在开发一个时间跟踪系统,我有一个时钟输入和时钟输出按钮,一个人进入并退出应用程序,当他们再次打开应用程序,必须禁用按钮中的时钟并启用时钟输出按钮。



提前谢谢。

Hi Everyone

I am developing a Time Tracking system where i have a clock in and clock out buttons, a person clocks in and exit the application, when they come back to open the application again, the clock in button must be disabled and the clock out button enabled.

Thank you in advance.

推荐答案

您必须在应用程序关闭时保存应用程序的最后状态

并在启动时读取它。



本文介绍如何保留用户设置:

C#中的Windows窗体用户设置 [ ^ ]
You must save the last state of your application when it is about to shut down
and read it on startup.

This article explains how to persist user settings:
Windows Forms User Settings in C#[^]


非常感谢您的回复...



但我不在我的应用程序上使用登录。在页面加载我有一个列表框,有名称和两个(Clockin和Clockout)禁用按钮,如果一个人选择他们的名称,这是按钮启用时。



从列表框中选择名称时,按钮中的时钟将启用;当一个人点击该按钮时,他们能够在系统上输入并且按钮时钟输出被启用,那么他们也可以退出系统。



唯一的问题是当一个人登录系统然后决定关闭应用程序时,下次他们打开应用程序时,从列表框中选择他们的名字必须启用时钟输出按钮才能使其超时。系统不允许它们进行两次计时。
Thank you so much for your responses...

But i do not use login on my application. on page load I have a list box that has names and two (Clockin and Clockout) disabled buttons, if a person select their name that is when the buttons get enabled.

When the name is selected from the list box, the clock in button gets enabled; when a person clicks on that button they are able to clock in on the system and the button clock out gets enabled, then they are able to clock out of the system as well.

The only problem is when a person clocks in on the system and then decide to close the application, next time they open the application, select their name from the list box the clock out button must be enabled for them to clock out. The system must not allow them to clock in two times.


Windows窗体中没有Session变量的概念。



创建一个静态类,其中包含用户名和密码以及整个应用程序所需的任何其他变量。



在您的情况下,它将类似于:



There is no concept of Session variables in windows forms.

Create a Static class that holds the User name and password and any other variables needed across the application .

In your case it would be something like:

public static class LoginInfo
{
    public static string UserID;
}
Now you can access the UserID simply from anywhere in your code:

MessageBox.Show(LogInfo.UserID);
Or set the values after login like

LogInfo.UserID=TextBox1.Text;















只使用这种类型的概念。








use just this type of concept.


这篇关于如何在Windows窗体应用程序中使用会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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