Esempio n. 1
0
        protected void AddMockTeacher(int num)
        {
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            db.Connect();

            Random rand = new Random((int)DateTime.Now.Ticks);

            for (int i = 0; i < num; i++)
            {
                Teacher t = new Teacher();

                t._firstname = StringUtil.RandomString(11, true);
                t._surname = StringUtil.RandomString(16, true);
                t._img = "teacher" + rand.Next(1, 6) + ".jpg";
                t._birthday = new DateTime(rand.Next(1900, 2005), rand.Next(1, 13), rand.Next(1, 29));
                t._subject = StringUtil.RandomString(30, true);
                t._tel = "08" + rand.Next(10000000, 99999999);
                t._sex = (rand.Next(0, 2) > 0 ? "Male" : "Female");
                t._addr = StringUtil.RandomString(50, true);

                t.AddToDB(db);
            }
        }
Esempio n. 2
0
        protected void DoAddSubmitTeacher()
        {
            Teacher t = new Teacher();

            // validate data
            t._firstname = Request["firstname"];
            t._surname = Request["surname"];
            t._citizenID = Request["citizen_id"];
            t._sex = Request["sex"];
            t._tel = Request["tel"];
            t._email = Request["email"];
            t._addr = Request["addr"];
            //t._subject = Request["subject"];

            if (Request["birthday"] != null)
            {
                string[] s = Request["birthday"].Split('/');

                t._birthday = new DateTime(Int32.Parse(s[2]) - 543, Int32.Parse(s[1]), Int32.Parse(s[0]));
            }
            else
            {
                t._birthday = new DateTime();
            }

            t._img = "noimg.jpg";
            if (portrait.PostedFile.FileName != "")
            {
                try
                {
                    string serverFileExt = Path.GetExtension(portrait.PostedFile.FileName);
                    Random rand = new Random((int)DateTime.Now.Ticks);
                    string fullpath = "";
                    string imgname = "";
                    do
                    {
                        string randomFName = rand.Next(Int32.MaxValue).ToString();
                        imgname = randomFName + serverFileExt;
                        fullpath = Config.PATH_APP_ROOT + "\\" + Config.URL_PIC_TEACHER + "\\" + imgname;
                    } while (File.Exists(fullpath));

                    portrait.PostedFile.SaveAs(fullpath);
                    t._img = imgname;
                }
                catch (Exception err)
                {
                    errorText = err.Message + err.StackTrace;
                }
            }

            // Save to DB
            DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
            db.Connect();
            t.AddToDB(db);
            db.Close();
        }