Question Code for automatic staff number

Dreal1

Member
Joined
Apr 27, 2017
Messages
10
Programming Experience
Beginner
I'M WRITING A CODE TO AUTOMATIC GENERATE STAFF NUMBER. AM STOCK PLEASE HELP ME OUT...

// FORMAT OF THE STAFF NUMBER (FMCEB/HR/1043) THAT IS THE LAST NUMBER IN MY DATABASE


// READING FROM DATABASE
            var a = (from m in db.Staffs orderby m.StaffId descending select m).Take(1).SingleOrDefault();
            if (a != null)
            {
                
                string stid = a.StaffNo.ToString();
                if (stid.Length == 9)
                {
                    string output = (stid.Substring(9, 3));
                    int num = Convert.ToInt32(output) + 1;
                    newstaffno = "FMCEB/HR/" + num.ToString();


                }
            }
            else
            {
                int id = 1;
                string year = DateTime.Now.Year.ToString();
                newstaffno = "FMCEB/HR/" + year + id.ToString();
            }

PLEASE HELP A BROTHER OUT!!!
 
Last edited by a moderator:
Firstly, please use appropriate formatting tags when posting code snippets. I have added them for you on this occasion.

Secondly, there's never a good reason to write in all caps on this forum. Please write normally. Even if it doesn't come across as shouting, all caps is not as easy to read as normally-cased type.

As for your issue, you haven't really explained where your code is deficient. What does it do that it shouldn't or not do that it should? ALWAYS provide a FULL and CLEAR explanation of the problem.
 
Re- reply

thanks boss.
i am write a code for an application that i am developing now , in d process of developing i notice the code is not working the way i want.
below highlighted code that i think is the issue:
****
// i'm stock here


int num = Convert.ToInt32(output) + 1;
newstaffno = "FMCEB/HR/" + num.ToString();
***
And, what i what the code to execute is pick from the last staff number from my database and automatic generate a new one an pass it to d designated textbox
below is the format of the code and how i want it to wrk.

example 1:
this is the last staff number in my FMCEB/HR/1234 in my database so i want it to automatic read d last staff number from the data n generate a new one like dis FMCEB/HR/1235
like dis FMCEB/HR/1235.


below is the sample of my code

// FORMAT OF THE STAFF NUMBER (FMCEB/HR/1043) THAT IS THE LAST NUMBER IN MY DATABASE


// READING FROM DATABASE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21​
var a = (from m in db.Staffs orderby m.StaffId descending select m).Take(1).SingleOrDefault();
if (a != null)
{

string stid = a.StaffNo.ToString();
if (stid.Length == 9)
{
string output = (stid.Substring(9, 3));
****
// i'm stock here and dont know hoe
int num = Convert.ToInt32(output) + 1;
newstaffno = "FMCEB/HR/" + num.ToString();
***

}
}
else
{
int id = 1;
string year = DateTime.Now.Year.ToString();
newstaffno = "FMCEB/HR/" + year + id.ToString();
}


 
Back
Top Bottom