Ejemplo n.º 1
0
        /// <summary>
        /// 修改学生邮箱
        /// </summary>
        /// <param name="username"></param>
        /// <param name="newemail"></param>
        /// <returns></returns>
        public bool ChangeEmail(string username, string newemail)
        {
            Help h     = new Help();
            bool flags = false;
            //正则表达匹配用户名,学号true
            bool    flag = h.IsStudentId(username);
            Student s    = new Student();

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (!flag)
                        {
                            s = context.Student.FirstOrDefault(x => x.Sid == username);
                            if (s != null)
                            {
                                s.Semail = newemail;
                                context.Student.Update(s);
                                context.SaveChanges();
                                transaction.Commit();
                                flags = true;
                            }
                            //修改对应邮箱,返回true
                        }
                        else
                        {
                            s = context.Student.FirstOrDefault(x => x.Semail == username);
                            if (s != null)
                            {
                                s.Semail = newemail;
                                context.Student.Update(s);
                                context.SaveChanges();
                                transaction.Commit();
                                flags = true;
                            }
                            //修改邮箱,返回false
                        }
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    return(flags);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 修改学生的积分
        /// </summary>
        /// <param name="a">目标值</param>
        public bool ResetGlory(int a)
        {
            //将所有学生的积分值都修改为a
            List <Student> student = new List <Student>();

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        student = (from s in context.Student
                                   select s
                                   ).ToList();
                        for (int i = 0; i < student.LongCount(); i++)
                        {
                            student[i].Svalue = a;
                            context.Student.Update(student[i]);
                        }
                        context.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 向管理员表中写入该管理员的新密码
        /// </summary>
        /// <param name="username">管理员名</param>
        /// <param name="newpassword">新密码</param>
        public bool ChangePassword(string userId, string newpassword)
        {
            //直接写密码(管理员表)
            bool flag = false;

            using (var dbContext = new LSSDataContext())
            {
                Administor adminstor = new Administor();
                //修改数据库信息最好有一些事务操作
                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        adminstor = dbContext.Administor.Where(x => x.Aid == userId).FirstOrDefault();
                        if (adminstor != null)
                        {
                            adminstor.Apassword = newpassword;
                            dbContext.Administor.Update(adminstor);
                            dbContext.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                }
                return(flag);
            }
        }
Ejemplo n.º 4
0
        public bool deleteSb(string sid)
        {
            bool flag = false;

            using (var dbContext = new LSSDataContext())
            {
                //修改数据库信息最好有一些事务操作
                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        var student = dbContext.Student.Where(x => x.Sid == sid).ToList().First();
                        dbContext.Student.Remove(student);
                        dbContext.SaveChanges();
                        transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        transaction.Rollback();
                    }
                    return(flag);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加图书馆
        /// </summary>
        /// <param name="library">图书馆对象</param>
        public bool AddLibrary(Library library)
        {
            bool flag = false;

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.Add(library);
                        context.SaveChanges();
                        transaction.Commit();
                        flag = true;
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    return(false);
                }
            }


            //将除id之外的字段添加进图书馆表中
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 修改该图书馆的起始楼层和结束楼层
        /// </summary>
        /// <param name="libraryname">图书馆名称</param>
        /// <param name="startfloor">起始楼层</param>
        /// <param name="endfloor">结束楼层</param>
        public bool AddFloor(string libraryname, int startfloor, int endfloor)
        {
            //修改该图书馆的起始楼层和结束楼层
            Library library = new Library();
            bool    flag    = false;

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        library = context.Library.FirstOrDefault(x => x.Lname == libraryname);
                        if (library != null)
                        {
                            library.Lsfloor = startfloor;
                            library.Lefloor = endfloor;
                            context.Library.Update(library);
                            context.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    return(flag);
                }
            }
        }
Ejemplo n.º 7
0
 public bool UpdataStudentFen(string sid)
 {
     using (var dbContext = new LSSDataContext())
     {
         bool flag = false;
         //修改数据库信息最好有一些事务操作
         using (var transaction = dbContext.Database.BeginTransaction())
         {
             try
             {
                 var sql = @"Update Student SET Svalue =  {0} WHERE Sid =  {1}";
                 dbContext.Database.ExecuteSqlCommand(sql, 2, sid);
                 dbContext.SaveChanges();
                 transaction.Commit();
                 flag = true;
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.Message);
                 transaction.Rollback();
             }
             return(flag);
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 修改该学生的积分
        /// </summary>
        /// <param name="studentid">学生id</param>
        public bool AddGlory(string studentid)
        {
            //给该学生的信誉积分加1
            Student student = new Student();
            bool    flag    = false;

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        student = context.Student.FirstOrDefault(x => x.Sid == studentid);
                        if (student != null)
                        {
                            student.Svalue += student.Svalue;
                            context.Student.Update(student);
                            context.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    return(flag);
                }
            }
        }
Ejemplo n.º 9
0
        public bool SetSeatState(string id, string operation)
        {
            bool flag = false;

            using (var dbContext = new LSSDataContext())
            {
                Seat seat = new Seat();
                //修改数据库信息最好有一些事务操作
                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        seat = dbContext.Seat.Where(x => x.Tid == id).FirstOrDefault();
                        if (seat != null)
                        {
                            seat.Tstate = operation;
                            dbContext.Seat.Update(seat);
                            dbContext.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                }
                return(flag);
            }
        }
Ejemplo n.º 10
0
        public bool updateLibrary(int lid, string name)
        {
            bool flag = false;

            using (var dbContext = new LSSDataContext())
            {
                //修改数据库信息最好有一些事务操作
                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        var library = dbContext.Library.Where(x => x.Lid == lid).ToList().First();
                        library.Lname = name;
                        dbContext.Library.Update(library);
                        dbContext.SaveChanges();
                        transaction.Commit();
                        flag = true;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        transaction.Rollback();
                    }
                    return(flag);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 根据ID直接改变订单状态
        /// </summary>
        /// <param name="oid">订单ID</param>
        public bool ChangeOrderState(string oid, string operation)
        {
            //根据ID直接改变订单状态
            bool flag = false;

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var order = context.Order.Where(x => x.Oid == oid).FirstOrDefault();
                        if (order != null)
                        {
                            order.Ostate = operation;
                            context.Order.Update(order);
                            context.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                }
            }
            return(flag);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 在订单表中插入一条记录
        /// </summary>
        /// <param name="order"></param>
        public bool SetOrder(Order order)
        {
            //插入一条订单记录到订单表(id,学号,座位号,订单开始时间,结束时间,打卡时间,订单状态)
            //订单id(图书馆号+层号+座位号+系统时间)
            bool flag = false;

            using (var context = new LSSDataContext())
            {
                context.Order.Add(order);
                context.SaveChanges();
                flag = true;
            }
            return(flag);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 修改个人的lock锁
        /// </summary>
        /// <param name="operation">状态修改的目标值这里为char类型,只传一个字符就可以例如‘1’</param>
        /// <param name="date">日期</param>
        /// <param name="username">个人id</param>
        public bool ModifyInfor(char operation, int date, string username)
        {
            Student student = new Student();
            bool    flag    = false;
            Help    h       = new Help();

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        if (h.IsStudentId(username))
                        {
                            student = context.Student.FirstOrDefault(x => x.Sid == username);
                        }
                        else
                        {
                            student = context.Student.FirstOrDefault(x => x.Semail == username);
                        }
                        if (student != null)
                        {
                            char[] old = { student.Slock.ElementAt(0), student.Slock.ElementAt(1) };
                            if (date == 0)
                            {
                                old[0] = operation;           //修改第一天的状态
                            }
                            else
                            {
                                old[1] = operation; //修改第二天的状态
                            }
                            string str = new string(old);
                            student.Slock = str;
                            context.Update(student);
                            context.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    return(flag);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 修改学生得信誉积分,每次修改减1
        /// </summary>
        /// <param name="sid">学生学号</param>
        /// <returns></returns>
        public bool DuctGlory(string sid)
        {
            bool flag = false;

            using (var dbContext = new LSSDataContext())
            {
                Student student = new Student();
                student = dbContext.Student.FirstOrDefault(x => x.Sid == sid);
                if (student != null)
                {
                    student.Svalue = student.Svalue + 1;
                    dbContext.Update(student);
                    dbContext.SaveChanges();
                    flag = true;
                }
            }
            return(flag);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 修改数据库中的对应密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        public bool ChangePassword(string user, string password)
        {
            //使用工具方法判断学号/邮箱IsStudentId()
            //修改对应密码
            Student student = null;
            bool    flag    = false;
            Help    h       = new Help();

            using (var dbContext = new LSSDataContext())
            {
                //修改数据库信息最好有一些事务操作
                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {//学号
                        if (h.IsStudentId(user))
                        {
                            student = dbContext.Student.Where(x => x.Sid == user).ToList().First();
                        }
                        else
                        {
                            student = dbContext.Student.Where(x => x.Semail == user).ToList().First();
                        }
                        if (student != null)
                        {
                            student.Spassword = password;
                            dbContext.Student.Update(student);
                            dbContext.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    return(flag);
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 修改座位状态 【operation 类型应该为string】
        /// </summary>
        /// <param name="seatid">座位id</param>
        /// <param name="operation">目标值</param>
        public bool SeatInfor(string seatid, int operation)
        {
            //将座位所有时间的状态修改为operation
            Seat seat = new Seat();
            bool flag = false;

            using (var context = new LSSDataContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        seat = context.Seat.FirstOrDefault(x => x.Tid == seatid);
                        if (seat != null)
                        {
                            char[] a = new char[48];
                            for (int i = 0; i < 48; i++)
                            {
                                a[i] = char.Parse(operation.ToString());
                            }
                            string str = new string(a);
                            seat.Tstate = str;
                            context.Seat.Update(seat);
                            context.SaveChanges();
                            transaction.Commit();
                            flag = true;
                        }
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    return(flag);
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 修改座位状态
        /// </summary>
        /// <param name="date">第几天</param>
        /// <param name="str">座位状态信息</param>
        /// <param name="seatid">座位id</param>
        /// <param name="num">处理后需要修改的状态的开始坐标</param>
        /// <param name="duration">时长</param>
        /// <param name="operation">目标值</param>
        public bool SeatInfor(int date, string seatid, int num, int duration, char operation)
        {
            Seat seat = new Seat();
            bool flag = false;

            using (var context = new LSSDataContext())
            {
                seat = context.Seat.FirstOrDefault(x => x.Tid == seatid);
                if (seat != null)
                {
                    char[] c = new char[48];
                    c = seat.Tstate.ToCharArray();
                    if (date == 1)
                    {
                        for (int i = 23 + num; i < 23 + num + duration; i++)
                        {
                            c[i] = operation;
                        }
                    }
                    else
                    {
                        for (int i = num; i < num + duration; i++)
                        {
                            c[i] = operation;
                        }
                    }
                    string s = new string(c);
                    seat.Tstate = s;
                    context.Seat.Update(seat);
                    context.SaveChanges();
                    flag = true;
                }
            }
            return(flag);
            //将字符串修改之后直接插入座位表
        }