Exemple #1
0
        public String GenerateTeacherId()
        {
            string        latestTeacherId = teacherDAO.GetLatestTeacherId();
            StringBuilder teacherId       = new StringBuilder();
            string        yearNow         = DateTime.Now.Year.ToString();
            int           con             = 1;
            string        c = String.Empty;

            if (!latestTeacherId.Equals("none"))
            {
                string latestYear = latestTeacherId.Substring(0, 4);

                string control = latestTeacherId.Substring(4, 3);
                con = Int32.Parse(control);

                teacherId.Append(yearNow);
                if (latestYear.Equals(yearNow))
                {
                    con++;
                    c = con.ToString();
                    if (c.Length == 1)
                    {
                        c = "00" + c;
                    }
                    else if (c.Length == 2)
                    {
                        c = "0" + c;
                    }
                }
                else
                {
                    c = "00" + con.ToString();
                }
                teacherId.Append(c);
            }
            else
            {
                teacherId.Append(yearNow);
                c = "00" + con.ToString();
                teacherId.Append(c);
            }
            return(teacherId.ToString());
        }