Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 工资单系统-';打卡退出';功能_C#_Asp.net_Database_Ms Access_Oledb - Fatal编程技术网

C# 工资单系统-';打卡退出';功能

C# 工资单系统-';打卡退出';功能,c#,asp.net,database,ms-access,oledb,C#,Asp.net,Database,Ms Access,Oledb,我正在设计一个使用access数据库作为后端的工资系统 目前,我在实现“时钟退出”功能时遇到问题 “时钟输入”按钮在数据库中插入时间。但是,当单击“退出时钟”按钮时,它会将数据插入新行。是否有任何方法可以避免这种情况,并根据员工姓名更新现有的最后一行。我试图用不同的方法来解决这个问题,但到目前为止我还没有解决它 有没有办法纠正这个问题 我想我必须在某处实现一个循环来检查emp名称、时钟输入并在时钟输出字段中定位空值。不过我不确定 请告知 我的代码如下 using System; using Sy

我正在设计一个使用access数据库作为后端的工资系统

目前,我在实现“时钟退出”功能时遇到问题

“时钟输入”按钮在数据库中插入时间。但是,当单击“退出时钟”按钮时,它会将数据插入新行。是否有任何方法可以避免这种情况,并根据员工姓名更新现有的最后一行。我试图用不同的方法来解决这个问题,但到目前为止我还没有解决它

有没有办法纠正这个问题

我想我必须在某处实现一个循环来检查emp名称、时钟输入并在时钟输出字段中定位空值。不过我不确定

请告知

我的代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class timecards : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        {
            if (Session["ID"] != null && Session["ID"].ToString() != "")
            {
                PanelUsersInfo.Visible = true;

            }
            else
            {
                PanelUsersInfo.Visible = false;
            }
            empLabel.Visible = false;
            mainPagebutton.Visible = false;
            logoutButton.Visible = false;
            if (Session["Title"] == null || Session["Names"] == null)
            {
                clockPanel.Visible = false;
                return;
            }
            else
            {
                mainPagebutton.Visible = true;
                logoutButton.Visible = true;
                empLabel.Visible = true;
                empLabel.Text = "<b>Hi, " + Session["Names"].ToString() + "</b>";
                nameLabel.Text = Session["Names"].ToString();
                clockinLabel.Text = DateTime.Now.ToString("HH:mm");
                Label1.Text = clockinLabel.Text;

            }
        }
    }




    protected void mainPage_Click(object sender, EventArgs e)
    {
        Response.Redirect("employeeLoggedin.aspx");
    }
    protected void logout_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("default.aspx");
    }
    protected void clockinButton_Click(object sender, EventArgs e)
    {
        informLabel.Text = "Clocked in at " + Label1.Text + "";
        Label1.Visible = false;
        Label2.Visible = false;
        clockinButton.Enabled = false;
        clockoutButton.Enabled = true;

        string connectionString = "provider=Microsoft.Jet.OLEDB.4.0;" + "data source=" + Page.Server.MapPath("App_Data\\database.mdb");
        System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connectionString);
        System.Data.OleDb.OleDbCommand cmd = conn.CreateCommand();


        cmd.Parameters.Add("Employee", System.Data.OleDb.OleDbType.VarChar);
        cmd.Parameters["Employee"].Value = nameLabel.Text;

        cmd.Parameters.Add("Clockin", System.Data.OleDb.OleDbType.VarChar);
        cmd.Parameters["Clockin"].Value = clockinLabel.Text;

        cmd.CommandText = "INSERT INTO [timecard] ([Employee], [Clockin]) VALUES (@Employee, @Clockin)";

        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();




    }
    protected void clockoutButton_Click(object sender, EventArgs e)
    {
        clockoutLabel.Visible = true;
        clockoutLabel.Text = "You have now been clocked out.";
        informLabel.Visible = false;
        Label1.Visible = false;
        clockoutButton.Enabled = false;

        infoLabel.Visible = true;
        infoLabel.Text = "If you want to clock in again, please select timecard option from the main employee page.";


        string connectionString = "provider=Microsoft.Jet.OLEDB.4.0;" + "data source=" + Page.Server.MapPath("App_Data\\database.mdb");
        System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connectionString);
        System.Data.OleDb.OleDbCommand cmd = conn.CreateCommand();

        cmd.Parameters.Add("Employee", System.Data.OleDb.OleDbType.VarChar);
        cmd.Parameters["Employee"].Value = this.nameLabel.Text;
        //String x = DateTime.Now.ToString("HH:mm");
        cmd.Parameters.Add("Clockout", System.Data.OleDb.OleDbType.VarChar);
        cmd.Parameters["Clockout"].Value = this.clockinLabel.Text;


        cmd.CommandText = "UPDATE [timecard] SET [Employee]=@Employee, [Clockout]=@Clockout";




            conn.Open();
            int numberOfRows = cmd.ExecuteNonQuery();
            conn.Close();



    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
公共部分类时间卡:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
{
if(Session[“ID”!=null&&Session[“ID”].ToString()!=“”)
{
PanelUsersInfo.Visible=true;
}
其他的
{
PanelUsersInfo.Visible=false;
}
empLabel.Visible=false;
mainPagebutton.Visible=false;
logoutButton.Visible=false;
如果(会话[“标题”]==null | |会话[“名称”]==null)
{
clockPanel.Visible=假;
返回;
}
其他的
{
mainPagebutton.Visible=true;
logoutButton.Visible=true;
empLabel.Visible=true;
empLabel.Text=“Hi,”+会话[“名称”].ToString()+”;
namelab.Text=Session[“Names”].ToString();
clockinLabel.Text=DateTime.Now.ToString(“HH:mm”);
Label1.Text=clockinLabel.Text;
}
}
}
受保护的无效主页\u单击(对象发送方,事件参数e)
{
重定向(“employeeLoggedin.aspx”);
}
受保护的无效注销\u单击(对象发送者,事件参数e)
{
会话。放弃();
重定向(“default.aspx”);
}
受保护的无效时钟按钮单击(对象发送方,事件参数e)
{
informLabel.Text=“在“+Label1.Text+处打卡”;
标签1.可见=假;
标签2.可见=假;
clockinButton.Enabled=false;
ClockBurtton.Enabled=真;
string connectionString=“provider=Microsoft.Jet.OLEDB.4.0;”“+”数据源=“+Page.Server.MapPath”(“App_data\\database.mdb”);
System.Data.OleDb.OleDbConnection conn=新的System.Data.OleDb.OleDbConnection(connectionString);
System.Data.OleDb.OleDbCommand cmd=conn.CreateCommand();
cmd.Parameters.Add(“Employee”,System.Data.OleDb.OleDbType.VarChar);
cmd.Parameters[“Employee”].Value=namelab.Text;
cmd.Parameters.Add(“Clockin”,System.Data.OleDb.OleDbType.VarChar);
cmd.Parameters[“Clockin”].Value=clockinLabel.Text;
cmd.CommandText=“插入[timecard]([Employee],[Clockin])值(@Employee,@Clockin)”;
conn.Open();
cmd.ExecuteNonQuery();
康涅狄格州关闭();
}
受保护的无效时钟不点击(对象发送者,事件参数e)
{
clockoutLabel.Visible=true;
clockoutLabel.Text=“您现在已被打卡下班。”;
informLabel.Visible=false;
标签1.可见=假;
ClockBurtton.Enabled=假;
infoLabel.Visible=true;
infoLabel.Text=“如果您想再次打卡,请从员工主页选择时间卡选项。”;
string connectionString=“provider=Microsoft.Jet.OLEDB.4.0;”“+”数据源=“+Page.Server.MapPath”(“App_data\\database.mdb”);
System.Data.OleDb.OleDbConnection conn=新的System.Data.OleDb.OleDbConnection(connectionString);
System.Data.OleDb.OleDbCommand cmd=conn.CreateCommand();
cmd.Parameters.Add(“Employee”,System.Data.OleDb.OleDbType.VarChar);
cmd.Parameters[“Employee”].Value=this.namelab.Text;
//字符串x=DateTime.Now.ToString(“HH:mm”);
cmd.Parameters.Add(“Clockout”,System.Data.OleDb.OleDbType.VarChar);
cmd.Parameters[“Clockout”].Value=this.clockinLabel.Text;
cmd.CommandText=“更新[timecard]设置[Employee]=@Employee,[Clockout]=@Clockout”;
conn.Open();
int numberOfRows=cmd.ExecuteNonQuery();
康涅狄格州关闭();
}
}

如果两个按钮都在插入记录,则两个按钮运行的代码相同。检查
.aspx
页面,查看两个按钮是否恰好具有相同的
onClick=
属性。

感谢所有帮助我克服困难并提供建议的人


显然,我找到了解决办法。最好将这些值存储为字符串,然后使用WHERE子句对其进行更新。出于某种原因,它不会直接从文本字段中获取值

嗨,谢谢你的回复。这两个按钮都具有不同的onClick属性。onClick=“clockinButton\u Click”onClick=“clockburutton\u Click”您能提供用户界面的屏幕截图吗?您是指数据库还是仅此代码的UI?UI。我知道答案可能是什么,但我想确保我在你的情况下解释。您可能需要更改用户与他们的时间表交互的方式,以使其可靠、正确地工作。我不能不注意到时钟输出的UPDATE语句没有WHERE子句<代码>更新[timecard]设置[Employee]=@Employee,[Clockout]=@Clockout