Example #1
0
        public List <Stu> GetStusById(string id)
        {
            List <Stu> list = new List <Stu>();
            string     sql  = "SELECT * FROM  Stu where StuID=@id";
            // DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, sql);
            Stu stu = null;

            using (SqlDataReader row = SqlHelper.ExecuteReader(SqlHelper.ConnString, CommandType.Text, sql, new SqlParameter("@id", id)))
            {
                if (row.Read())
                {
                    stu          = new Stu();
                    stu.StuID    = (int)row["StuID"];
                    stu.StuPwd   = (string)row["StuPwd"];
                    stu.StuName  = (string)row["StuName"];
                    stu.StuClass = (int)row["StuClass"];
                    stu.StuGrade = (int)row["StuGrade"];
                    stu.StuTel   = (string)row["StuTel"];
                    list.Add(stu);
                }
            }


            return(list);
        }
        public List <Stu> GetStudentList()
        {
            List <Student> students = en.Students.ToList();

            List <Stu> slist = new List <Stu>();

            for (int i = 0; i < students.Count; i++)
            {
                Stu student = new Stu();
                student.ID          = students[i].ID;
                student.NRIC        = students[i].NRIC;
                student.StudentName = students[i].Name;
                student.Gender      = students[i].Gender == "Female" ? "F" : "M";
                student.Age         = DateTime.Now.Year - students[i].Birthday.Year;
                student.Number      = 0;
                if (Convert.ToBoolean(students[i].English) == true)
                {
                    student.Number += 1;
                }
                if (Convert.ToBoolean(students[i].Math) == true)
                {
                    student.Number += 1;
                }
                if (Convert.ToBoolean(students[i].Science == true))
                {
                    student.Number += 1;
                }
                slist.Add(student);
            }
            return(slist);
        }
        public int UpdateStudent(Stu s, int type)
        {
            int     result  = 0;
            Student student = new Student();

            if (type == 1)
            {
                student = en.Students.Where(x => x.ID == s.ID).FirstOrDefault();
            }
            student.NRIC          = s.NRIC;
            student.Name          = s.StudentName;
            student.Birthday      = s.Birthday;
            student.AvailableDate = s.AvailableDate;
            student.Gender        = s.Gender;
            student.English       = s.English;
            student.Math          = s.Math;
            student.Science       = s.Science;
            using (StudentEntities context = new StudentEntities())
            {
                if (type == 0)
                {
                    context.Students.Add(student);
                }
                else
                {
                    context.Entry(student).State = System.Data.Entity.EntityState.Modified;
                }
                context.SaveChanges();
            }
            return(result);
        }
Example #4
0
        static void Main()
        {
            Stu <string>    stu    = new Stu <string>();
            Action <string> action = new Action <string>(stu.Goodbye);

            action("\nIch liebe dich,Yuchen!");
        }
Example #5
0
        public static List <Stu> GetStus()
        {
            if (stuList.Count > 0)
            {
                return(stuList);
            }

            for (int i = 0; i < 100000; i++)
            {
                var stui = new Stu();
                stui.Id     = i;
                stui.Name   = "name1" + i;
                stui.Name2  = "name2" + i;
                stui.Name3  = "name3" + i;
                stui.Name4  = "name4" + i;
                stui.Name5  = "name5" + i;
                stui.Name6  = "name6" + i;
                stui.Name7  = "name7" + i;
                stui.Name8  = "name8" + i;
                stui.Name9  = "name9" + i;
                stui.Name10 = "name10" + i;
                stui.Name11 = "name11" + i;
                stui.Name12 = "name12" + i;
                stui.Name13 = "name13" + i;
                stui.Name14 = "name14" + i;
                stui.Name15 = "name15" + i;
                stui.Name16 = "name16" + i;
                stuList.Add(stui);
            }

            return(stuList);
        }
Example #6
0
        public List <Stu> GetStu(int PageNumber, int PageSize, string DataOrderBy, string safeSqlCondition)
        {
            StringBuilder commandText = new StringBuilder();

            commandText.Append("SELECT TOP " + PageSize + " * FROM (SELECT ROW_NUMBER() OVER (ORDER BY " + DataOrderBy + ") AS RowNumber,* FROM Stu ");
            commandText.Append(" WHERE " + safeSqlCondition + " ");//这里修改条件语句
            commandText.Append(" ) AS T  WHERE RowNumber > (" + PageSize + "*(" + PageNumber + "-1))");
            DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.StoredProcedure, commandText.ToString());

            List <Stu> list = new List <Stu>();

            if (ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                foreach (DataRow row in dt.Rows)
                {
                    Stu stu = new Stu();
                    stu.StuID    = (int)row["StuID"];
                    stu.StuName  = (string)row["StuName"];
                    stu.StuClass = (int)row["StuClass"];
                    stu.StuGrade = row["StuGrade"] != DBNull.Value ? (int)row["StuGrade"] : 0;
                    stu.StuTel   = (string)row["StuTel"];
                    list.Add(stu);
                }
            }
            return(list);
        }
Example #7
0
 public ActionResult Create(Stu stu)
 {
     if (ModelState.IsValid)
     {
         db.Stus.Add(stu);
         db.SaveChanges();
         return(RedirectToAction("reg"));
     }
     return(View(stu));
 }
Example #8
0
        public ActionResult Edit(string id)
        {
            Stu s = db.Stus.Find(id);

            if (s == null)
            {
                return(HttpNotFound());
            }
            return(View(s));
        }
Example #9
0
 public ActionResult Edit(Stu s)
 {
     if (ModelState.IsValid)
     {
         db.Entry(s).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("reg"));
     }
     return(View(s));
 }
 public ActionResult Edit(Stu s)
 {
     try
     {
         UpdateStudent(s, 1);
         return(View("Index", GetStudentList()));
     }
     catch (Exception)
     {
         return(View("Index", new List <Stu>()));
     }
 }
 public ActionResult Create(Stu s)
 {
     try
     {
         UpdateStudent(s, 0);
         return(View("Index", GetStudentList()));
     }
     catch (Exception)
     {
         return(View("Create"));
     }
 }
Example #12
0
 public ActionResult EditStu(Stu stu)
 {
     try
     {
         new StuManager().ModifyStu(stu);//调用修改学生信息方法
         return(Content("<script type='text/javascript'>alert('修改成功!');location.href='" + Url.Action("StuList", "Admin") + "' </script>"));
     }
     catch (Exception)
     {
         return(Content("<script type='text/javascript'>alert('信息不合法!');location.href='" + Url.Action("EditStu", "Admin") + "' </script>"));
     }
 }
Example #13
0
        public ActionResult AddStu()
        {
            Stu stu = new Stu();//定义一个Stu类

            //stu.StuID = Convert.ToInt32(Request.QueryString["stu.StuID"]);
            //定义stu的默认值
            stu.StuID    = 20130000;
            stu.StuPwd   = "1111";
            stu.StuClass = 1;
            stu.StuGrade = 1;
            stu.StuTel   = "0000000";
            return(View(stu));
        }
Example #14
0
    private void Awake()
    {
        Singleton = this;

        var t = Camera.main.transform;

        t.SetParent(cameraAnchor, false);
        t.localPosition = Vector3.zero;

        launcherAnchor.SetParent(t, false);

        LookTarget = t;
    }
Example #15
0
        public ActionResult AddStu(Stu stu)
        {
            try
            {
                new StuManager().AddStu(stu);//调用添加学生信息方法

                return(Content("<script type='text/javascript'>alert('添加成功!');location.href='" + Url.Action("AddStu", "Admin") + "' </script>"));
            }
            catch (Exception)
            {
                return(Content("<script type='text/javascript'>alert('学生编号重复!');location.href='" + Url.Action("AddStu", "Admin") + "' </script>"));
            }
        }
Example #16
0
        public ActionResult ModifyStuPaw(Stu stu)
        {
            try
            {
                //调用修改学生信息方法
                new StuManager().ModifyStu(stu);

                return(Content("<script type='text/javascript'>alert('修改成功!');location.href='" + Url.Action("ModifyStuPaw", "Stu") + "' </script>"));
            }
            catch (Exception)
            {
                return(Content("<script type='text/javascript'>alert('信息不合法!');location.href='" + Url.Action("ModifyStuPaw", "Stu") + "' </script>"));
            }
        }
Example #17
0
        static void Main(string[] args)
        {
            Stu    s1   = new Stu("Mr. MeeSeeks");
            Course c1   = new Course("C#", 9990);
            Course c2   = new Course("Java", 12800);
            Course c3   = new Course("Java II", 12300);
            Cart   cart = new Cart(s1);

            s1.BuyCourse(c1);
            s1.BuyCourse(c2);
            s1.BuyCourse(c3);
            Console.WriteLine(
                $" Total is ${cart.GetPrice()}"
                );
            Console.ReadLine();
        }
Example #18
0
        public async Task DbContextExtension_TestAsync()
        {
            var context = GetDbContext();

            var id = Guid.Parse("f0158dca-e568-47ec-9980-07503ab389ef");

            //await context.Stus.AddAsync(new Stu
            //{
            //    Id = id,
            //    Name = "121",
            //});
            //await context.SaveChangesAsync();

            //var stu = new Stu
            //{
            //    Id = id,
            //    Name = "312312331235435",
            //    Score = 20
            //};
            //context.Stus.Update(stu, true, b => b.Name);
            //await context.SaveChangesAsync();

            //context.Stus.SoftDelete(new Stu { Id = id });
            //context.Stus.Delete(id);
            //await context.SaveChangesAsync();

            var stu1 = new Stu
            {
                Id    = id,
                Name  = "31231233123543531231",
                Score = 20
            };

            //context.Add(stu1);
            //await context.SaveChangesAsync();

            //context.Update(stu1, true, b => b.Name);
            //await context.SaveChangesAsync();

            //context.SoftDelete<Stu, Guid>(id);
            //await context.SaveChangesAsync();

            context.Delete(stu1);
            await context.SaveChangesAsync();
        }
Example #19
0
        static void Main(string[] args)
        {
            Car      car      = new Car(4, 20);
            SmallCar smallCar = new SmallCar(4, 20, 20);
            BigCar   bigCar   = new BigCar(8, 40, 3, 500);

            Console.WriteLine(bigCar.Print());
            Shape shape = new Circle(1, 2);

            Console.WriteLine(shape.GetArea());
            BaseClass    baseClass    = new BaseClass();
            BaseClass    ba           = new DerivedClass();
            DerivedClass derivedClass = new DerivedClass();

            baseClass.fn1();
            baseClass.fn2();
            ba.fn1();
            ba.fn2();
            derivedClass.fn1();
            derivedClass.fn2();
            Cat     cat     = new Cat();
            Dog     dog     = new Dog();
            Student student = new Student();

            for (int i = 0; i < 10; i++)
            {
                Stu stu = new Stu();
                stu.stuName   = stu.stunNum = Convert.ToString(i);
                stu.score.cs  = stu.score.eng = stu.score.math = i;
                stu.score.avg = (stu.score.cs + stu.score.eng + stu.score.math) / 3;
                student.enqueue(stu);
            }
            student.Print();
            Stacks stacks = new Stacks();

            for (int i = 0; i < 10; i++)
            {
                Book book = new Book();
                book.author = book.bookName = book.publish = Convert.ToString(i);
                book.price  = i;
                stacks.Push(book);
            }
            stacks.Print();
        }
Example #20
0
        public List <Stu> GetStu(StuQuery category, string keyWord)
        {
            List <Stu> list = new List <Stu>();
            //category.CompareTo(StuQueryCategories.书名)
            string sql = "SELECT * FROM Stu where  ";

            if (String.Compare(category.ToString(), "学号", true) == 0)
            {
                sql = sql + " StuID LIKE '%" + keyWord + "%'";
            }
            else if (String.Compare(category.ToString(), "姓名", true) == 0)
            {
                sql = sql + " StuName LIKE '%" + keyWord + "%'";
            }
            else if (String.Compare(category.ToString(), "年级", true) == 0)
            {
                sql = sql + " StuGrade LIKE '%" + keyWord + "%'";
            }
            else if (String.Compare(category.ToString(), "班级", true) == 0)
            {
                sql = sql + " StuClass LIKE '%" + keyWord + "%'";
            }
            //DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, "sp_QueryStus", category, keyWord);
            DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, sql);

            if (ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                foreach (DataRow row in dt.Rows)
                {
                    Stu stu = new Stu();
                    stu.StuID    = (int)row["StuID"];
                    stu.StuName  = (string)row["StuName"];
                    stu.StuClass = (int)row["StuClass"];
                    stu.StuGrade = row["StuGrade"] != DBNull.Value ? (int)row["StuGrade"] : 0;
                    stu.StuTel   = (string)row["StuTel"];
                    list.Add(stu);
                }
            }
            return(list);
        }
Example #21
0
        //增加
        public void AddStu(Stu stu)
        {
            //1、sql语句

            string sql = "insert into Stu(StuID,StuPwd,StuName,StuClass,StuGrade,StuTel) values(@StuID,@StuPwd,@StuName,@StuClass,@StuGrade,@StuTel)";

            //sql += " select @@IDENTITY";
            //2、参数赋值
            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@StuID", stu.StuID),
                new SqlParameter("@StuPwd", stu.StuPwd),
                new SqlParameter("@StuName", stu.StuName),
                new SqlParameter("@StuClass", stu.StuClass),
                new SqlParameter("@StuGrade", stu.StuGrade),
                new SqlParameter("@StuTel", stu.StuTel)
            };
            //3、执行sql

            stu.StuID = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, sql, para));
        }
Example #22
0
        //修改
        public bool ModifyStu(Stu stu)
        {
            string sql = "UPDATE Stu " +
                         " SET StuPwd = @StuPwd," +
                         " StuName = @StuName," +
                         " StuClass = @StuClass," +
                         " StuGrade = @StuGrade," +
                         " StuTel = @StuTel WHERE " +
                         "StuID = @StuID";

            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@StuID", stu.StuID),
                new SqlParameter("@StuPwd", stu.StuPwd),
                new SqlParameter("@StuName", stu.StuName),
                new SqlParameter("@StuClass", stu.StuClass),
                new SqlParameter("@StuGrade", stu.StuGrade),
                new SqlParameter("@StuTel", stu.StuTel)
            };
            return(SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, sql, para) > 0);
        }
 public ActionResult Edit(int id)
 {
     try
     {
         Student s   = GetStudent(id);
         Stu     stu = new Stu();
         stu.NRIC          = s.NRIC;
         stu.StudentName   = s.Name;
         stu.Birthday      = s.Birthday;
         stu.AvailableDate = s.AvailableDate;
         stu.Gender        = s.Gender;
         stu.English       = s.English;
         stu.Math          = s.Math;
         stu.Science       = s.Science;
         return(View(stu));
     }
     catch (Exception)
     {
         return(View("Index", new List <Stu>()));
     }
 }
Example #24
0
        public List <Stu> GetStu()
        {
            List <Stu> list = new List <Stu>();
            string     sql  = "SELECT * FROM  Stu ORDER BY StuID";
            DataSet    ds   = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, sql);

            if (ds.Tables.Count > 0)
            {
                DataTable dt = ds.Tables[0];
                foreach (DataRow row in dt.Rows)
                {
                    Stu stu = new Stu();
                    stu.StuID    = (int)row["StuID"];
                    stu.StuName  = (string)row["StuName"];
                    stu.StuClass = (int)row["StuClass"];
                    stu.StuGrade = row["StuGrade"] != DBNull.Value ? (int)row["StuGrade"] : 0;
                    stu.StuTel   = (string)row["StuTel"];
                    list.Add(stu);
                }
            }
            return(list);
        }
Example #25
0
        static void Main()
        {
            try
            {
                Stu stu1 = new Stu();
                stu1.SetAge(20);

                Stu stu2 = new Stu();
                stu2.SetAge(20);

                Stu stu3 = new Stu();
                // 赋予字段非法值 导致字段被污染 可以在类中定义get和set字段的方法来保护字段
                stu3.SetAge(200);

                var avgAge = (stu1.GetAge() + stu2.GetAge() + stu3.GetAge()) / 3;
                Console.WriteLine(avgAge);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #26
0
        //查询
        public Stu GetStuById(string id)
        {
            //sql语句

            string sql = "SELECT *  FROM  Stu where StuID=@id";
            Stu    stu = null;

            using (SqlDataReader row = SqlHelper.ExecuteReader(SqlHelper.ConnString, CommandType.Text, sql, new SqlParameter("@id", id)))
            {
                if (row.Read())
                {
                    stu          = new Stu();
                    stu.StuID    = (int)row["StuID"];
                    stu.StuPwd   = (string)row["StuPwd"];
                    stu.StuName  = (string)row["StuName"];
                    stu.StuClass = (int)row["StuClass"];
                    stu.StuGrade = (int)row["StuGrade"];
                    stu.StuTel   = (string)row["StuTel"];
                }
            }

            return(stu);
        }
Example #27
0
        /// <summary>
        /// 登陆处理
        /// </summary>
        /// <param name="loginId">登陆账号</param>
        /// <param name="password">登录密码</param>
        /// <returns></returns>

        public ActionResult Login(string loginId, string password)
        {
            //1、获取数据

            string charge = Request.Form["identity"];

            //2、非空验证

            if (string.IsNullOrEmpty(loginId))
            {
                return(View("Login"));//返回login视图
            }
            if (string.IsNullOrEmpty("password"))
            {
                return(View("Login"));//返回login视图
            }
            //3、数据库验证,判定登陆是否成功
            if (charge == "教师")
            {
                TeacherManager tm      = new TeacherManager();
                Teacher        teacher = new Teacher();
                if (tm.TeacherLogIn(loginId, password, out teacher))
                {
                    //4、记住用户名和密码 cookie
                    string recordMe = Request.Form["RecordMe"];
                    if (!string.IsNullOrEmpty(recordMe))//记录用户名和密码
                    {
                        HttpCookie nameCookie = new HttpCookie("loginId", loginId);
                        nameCookie.Expires = DateTime.MaxValue;
                        Response.Cookies.Add(nameCookie);
                        HttpCookie passwordCookie = new HttpCookie("password", password);
                        nameCookie.Expires = DateTime.MaxValue;
                        Response.Cookies.Add(passwordCookie);
                    }
                    else
                    {
                        //让Cookie失效
                        Response.Cookies["loginId"].Expires  = DateTime.Now.AddDays(-1);
                        Response.Cookies["password"].Expires = DateTime.Now.AddDays(-1);
                    }
                    //5、保存用户的状态 sesion
                    teacher = new TeacherManager().GetTeacherById(loginId);
                    Session["CurrentUser"] = loginId;
                    Session["UserName"]    = teacher.TeacherName;
                    //登陆成功页面
                    return(Redirect("~/Teacher/Index"));
                }
                else
                {
                    //返回登陆页面

                    return(View("Login"));
                }
            }
            if (charge == "学生")
            {
                StuManager tm  = new StuManager();
                Stu        stu = new Stu();
                if (tm.StuLogIn(loginId, password, out stu))
                {
                    //4、记住用户名和密码 cookie
                    string recordMe = Request.Form["RecordMe"];
                    if (!string.IsNullOrEmpty(recordMe))//记录用户名和密码
                    {
                        HttpCookie nameCookie = new HttpCookie("loginId", loginId);
                        nameCookie.Expires = DateTime.MaxValue;
                        Response.Cookies.Add(nameCookie);
                        HttpCookie passwordCookie = new HttpCookie("password", password);
                        nameCookie.Expires = DateTime.MaxValue;
                        Response.Cookies.Add(passwordCookie);
                    }
                    else
                    {
                        //让Cookie失效
                        Response.Cookies["loginId"].Expires  = DateTime.Now.AddDays(-1);
                        Response.Cookies["password"].Expires = DateTime.Now.AddDays(-1);
                    }
                    //5、保存用户的状态 sesion

                    stu = new StuManager().GetStuById(loginId);
                    Session["CurrentUser"] = loginId;
                    Session["UserName"]    = stu.StuName;

                    //登陆成功页面
                    return(Redirect("~/Stu/Index"));
                }
                else
                {
                    //返回登陆页面
                    return(View("Login"));
                }
            }
            if (charge == "管理员")
            {
                AdminManager tm    = new AdminManager();
                Admin        admin = new Admin();
                if (tm.AdminLogIn(loginId, password, out admin))
                {
                    //4、记住用户名和密码 cookie
                    string recordMe = Request.Form["RecordMe"];
                    if (!string.IsNullOrEmpty(recordMe))//记录用户名和密码
                    {
                        HttpCookie nameCookie = new HttpCookie("loginId", loginId);
                        nameCookie.Expires = DateTime.MaxValue;
                        Response.Cookies.Add(nameCookie);
                        HttpCookie passwordCookie = new HttpCookie("password", password);
                        nameCookie.Expires = DateTime.MaxValue;
                        Response.Cookies.Add(passwordCookie);
                    }
                    else
                    {
                        //让Cookie失效
                        Response.Cookies["loginId"].Expires  = DateTime.Now.AddDays(-1);
                        Response.Cookies["password"].Expires = DateTime.Now.AddDays(-1);
                    }
                    //5、保存用户的状态 sesion


                    Session["CurrentUser"] = loginId;
                    Session["UserName"]    = loginId;

                    //登陆成功页面
                    return(Redirect("~/Admin/Index"));
                }
                else
                {
                    //返回登陆页面
                    return(View("Login"));
                }
            }
            else
            {
                //返回登陆页面
                return(View("Login"));
            }
        }
Example #28
0
 void OnDestroy()
 {
     Singleton = null;
 }
Example #29
0
 public void LookAt(Stu stu)
 {
     LookAt(stu.LookTarget);
 }