-2

I'm working on a web application that is required to enable a multitude of users of various designations to log into a system. But unlike conventional method of generating user ids, I want to use certain parameters.

Eg: TECH12nameIND01

Here the example I've mentioned above contains

  • designation
  • year of join
  • name of the emp
  • location
  • auto increment number

The user id should appear in my registration page at the end of registering.

I seek the C# code for this particular issue.

4

2 回答 2

1

Actually building the string is super simple

string userId = string.Format("{0}{1}{2}{3}{4}", designation, year, name, location, autoIncrementNumber);

The autoincrement number is the tricky part. What is the infrastructure for this "registration page?" Are you generating webpages from a single server? a million servers? or is the software client-side?

If you have a common database, you can store the current autoincrement number in that database, and write a stored procedure to atomically increment the number and return the old number. Then, to get the autoincrement number, your code can call the database's stored procedure. If you don't have something that can act as a shared database and maintain ACID, you have to think much harder about concurrency control.

于 2012-02-08T06:10:55.187 回答
0

Have you tried string.format?

string pattern ="{0}{1}{2}{3}{4}";
string username = string.Format(pattern,"Tech",12,"name","IND","01");
于 2012-02-08T06:08:47.220 回答