在实际创建id之前显示数据库列中的id

时间:2015-12-21 12:04:29

标签: c# asp.net visual-studio-2010 exception frontend

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRMSController;
using HRMSBusinessEntities;
using System.Data;


namespace HumanResourceManagementSystems
{
    public partial class HRMSEmployee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = (string)(Session["LoginUser"]);
            if (Session["LoginUser"] != null)
            {
                lblDisplay.Text = "Welcome..." + username;
            }
            Calendar1.Visible = false;
            Label1.Visible = false;
            txtcurrdate.Text = System.DateTime.Now.ToLongDateString();
        }

        protected void Btnmodified_Click(object sender, EventArgs e)
        {
            Calendar1.Visible = true;

        }
        protected void Add_Click(object sender, EventArgs e)
        {
            EmployeeEntity record = new EmployeeEntity
            {
                name = txtname.Text,
                currentdate = Convert.ToDateTime(txtcurrdate.Text),
                modifieddate = Convert.ToDateTime(txtmodifieddate.Text)
            };
            EmployeeController add = new EmployeeController();
            add.Add(record);
            Label1.Visible = true;
            Label1.Text = "Added" ;
            Clear();


        }
        public void Clear()
        {
            txtname.Text = "";
            txtcurrdate.Text = "";
            txtmodifieddate.Text = "";
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            txtmodifieddate.Text = Calendar1.SelectedDate.ToString();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Clear();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Calendar1.Visible = true;
        }
    }


}

我创建了一个用于在Visual Studio 2010中插入员工详细信息的页面。当我点击添加时,它会显示为已添加,并且ID会自动在后端获得增量。但是如果我必须显示为(而不是添加) “你的EMP ID在执行时是前端的一些数字(例如10)),我该怎么办?

1 个答案:

答案 0 :(得分:1)

我不认为在用户仍在创建员工时显示员工ID是个好主意。

假设user1在页面中徘徊,花时间创建新员工,可能还有其他用户(user2)也在尝试同时创建员工.User2创建了员工,而user1仍然没有吨。因此,在创建过程中显示员工会产生歧义,因为当前用户创建员工时可能会创建许多其他员工。

因此,在完成创建员工后,最好在标签中向用户显示员工ID。

label1.text="Employee succesfully added"+getemployeeid();

public string getemployeeid(){return yourobject.hitTheDataBaseMethod().tostring();};