Ejemplo n.º 1
0
        public String GenerateStudentId()
        {
            string        latestStudentId = studentDAO.GetLatestStudentId();
            StringBuilder studentId       = new StringBuilder();
            string        yearNow         = DateTime.Now.Year.ToString();
            int           con             = 1;
            string        c = String.Empty;

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

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

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

                studentId.Append(c);
            }
            else
            {
                studentId.Append(yearNow);
                c = "000" + con.ToString();
                studentId.Append(c);
            }

            return(studentId.ToString());
        }