当前位置: 首页>>代码示例>>C#>>正文


C# Student.AddToDB方法代码示例

本文整理汇总了C#中Student.AddToDB方法的典型用法代码示例。如果您正苦于以下问题:C# Student.AddToDB方法的具体用法?C# Student.AddToDB怎么用?C# Student.AddToDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Student的用法示例。


在下文中一共展示了Student.AddToDB方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddMockStudent

        protected void AddMockStudent(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++)
            {
                Student t = new Student();

                t._firstname = StringUtil.RandomString(8, true);
                t._surname = StringUtil.RandomString(12, true);
                t._nickname = StringUtil.RandomString(7, true);
                t._img = "student"+rand.Next(1,6)+".jpg";
                t._birthday = new DateTime(rand.Next(1980, 2005), rand.Next(1, 13), rand.Next(1, 29));
                t._school = StringUtil.RandomString(20, true);
                t._tel = "08" + rand.Next(10000000, 99999999);
                t._tel2 = "08" + rand.Next(10000000, 99999999);
                t._sex = (rand.Next(0,2)>0?"Male":"Female");
                t._addr = StringUtil.RandomString(50, true);

                t.AddToDB(db);
            }
        }
开发者ID:nettatata,项目名称:btsman,代码行数:25,代码来源:DevTool.aspx.cs

示例2: ProcessWizAddNewStudent

        protected Student ProcessWizAddNewStudent()
        {
            Student t = new Student();

            // validate data
            t._firstname = Request["firstname"];
            t._surname = Request["surname"];
            t._nickname = Request["nickname"];
            t._citizenID = Request["citizen_id"];
            t._sex = Request["sex"];
            t._tel = Request["tel1"] + Request["tel2"] + Request["tel3"];
            t._tel2 = Request["tel21"] + Request["tel22"] + Request["tel23"];
            t._email = Request["email"];
            t._addr = Request["addr"];
            t._school = Request["school"];
            t._level = Int32.Parse(Request["level"]);
            t._quiz = Student.EncodeQuizText(Page.Request);

            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._create_date = DateTime.Today;

            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_STUDENT + "\\" + imgname;
                    } while (File.Exists(fullpath));

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

            // Do validation
            // Save to DB and read to get student id
            // Need to use transaction
            DBManager db = null;
            try
            {
                db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);
                db.Connect();
                db.BeginTransaction(IsolationLevel.ReadCommitted);

                // validate
                // duplicate citizen id
                if (t._citizenID.Length > 0)
                {
                    int count = db.QueryCount("SELECT COUNT(*) FROM student WHERE citizen_id='" + t._citizenID + "'");
                    if (count > 0)
                    {
                        errorText = "รหัสบัตรประชาชน " + t._citizenID + " มีอยู่ในระบบแล้ว";
                        return null;
                    }
                }
                // Save to DB
                t.AddToDB(db);

                // Get just saved student
                Student savedStudent = new Student();
                savedStudent.LoadFromDBCustom(db, "SELECT * FROM student ORDER BY student_id DESC LIMIT 1");
                db.Commit();
                return savedStudent;
            }
            catch (Exception e)
            {
                errorText = "พบปัญหาบางประการ ข้อมูลไม่ถูกบันทึก";
                return null;
            }
            finally
            {
                db.Close();
            }
        }
开发者ID:nettatata,项目名称:btsman,代码行数:97,代码来源:RegisterCourse.aspx.cs


注:本文中的Student.AddToDB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。