我正在設計一個使用訪問數據庫作爲後端的工資系統。工資系統 - '時鐘輸出'功能
目前,我正面臨實施「計時」功能的問題。
「時鐘進入」按鈕在數據庫中插入時間。但是,當單擊「時鐘輸出」按鈕時,它會將數據插入到新行中。是否有任何方法可以避免這種情況,並考慮員工姓名更新現有的最後一行。我試圖用不同的方法來處理這個問題,到目前爲止我還沒有能夠解決這個問題。
有什麼辦法可以糾正這個問題嗎?
我想我將不得不實施一個循環某處檢查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][email protected], [Clockout][email protected]";
conn.Open();
int numberOfRows = cmd.ExecuteNonQuery();
conn.Close();
}
}
你能提供用戶界面的截圖嗎? – 2013-05-03 13:28:47
你的意思是數據庫或只是這個代碼的用戶界面? – jamesbond 2013-05-03 14:15:29
用戶界面。我對可能的答案有一定的認識,但我想確保我在你的情況下解釋。您可能需要改變用戶與時間表交互的方式,以使其可靠和正確地工作。 – 2013-05-03 15:25:17