Exemple #1
0
        public bool DeleteCinema(string name, string addr)
        {
            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();

            //根据电影院名字遍历数据库表CINEMA
            var result = from cinema in entity.CINEMA
                         where cinema.name == name && cinema.address == addr
                         select cinema;

            //删除满足条件的电影院
            foreach (var deleteCinema in result)
            {
                entity.CINEMA.DeleteObject(deleteCinema);
            }
            try
            {
                int i = entity.SaveChanges();
            }
            catch (Exception exp)
            {
                // MessageBox.Show(exp.ToString());
                entity.Dispose();//销毁对象
                return(false);
            }
            entity.Dispose();//销毁对象
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 说明:<调用函数调用InsertCollection函数可以完成对收藏夹增加一条记录的功能>
        /// </summary>
        /// <param name="<newCollection>"><接受调用函数传入的一个COLLECTION对象></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库增加操作异常</exception>

        public bool InsertCollection(COLLECTION newCollection)
        {
            //创建数据库实体类对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //添加记录到内存
            _entity.AddToCOLLECTION(newCollection);

            //保存修改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //异常处理?
                return(false);
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }
Exemple #3
0
        /// 这个函数根据电影名,发表时间对电影院评论支持数增加1
        /// </summary>
        /// <param name="newMovieName"></param>
        /// <param name="newTime"></param>
        /// <returns></returns>
        //public bool IncreaseMovieCommentSupport(string newMovieName, DateTime newTime)
        //{
        //    bool isSucceed = false;
        //    _entity = new WATCHMOVIEEntities();
        //    int movieId = new Movie().GetMovieId(newMovieName);

        //    if (movieId != -1)//如果movie_id为-1则代表没有这个电影院,所以出错了
        //    {
        //        var result = from m in _entity.MOVIE_COMMENT
        //                     where m.movie_id == movieId && m.time.Equals(newTime)
        //                     select m;

        //        if (result.Count() == 1)
        //        {
        //            result.First().support += 1;
        //            try
        //            {
        //                int i = _entity.SaveChanges();
        //                isSucceed = true;
        //            }
        //            catch (Exception ex)
        //            {
        //                //异常处理
        //                Console.WriteLine(ex);
        //                return false;
        //            }
        //        }

        //        //撤销entity对象
        //        _entity.Dispose();
        //    }

        //    return isSucceed;
        //}


        // <summary>
        /// 这个函数根据电影名,发表时间对电影院评论支持数增加1
        /// </summary>
        /// <param name="newMovieName"></param>
        /// <param name="newTime"></param>
        /// <returns></returns>
        public bool IncreaseMovieCommentSupport(string newMovieName, DateTime newTime)
        {
            bool isSucceed = false;

            _entity = new WATCHMOVIEEntities();
            int movieId = new Movie().GetMovieId(newMovieName);

            if (movieId != -1)//如果movie_id为-1则代表没有这个电影院,所以出错了
            {
                var result = from m in _entity.MOVIE_COMMENT
                             where m.movie_id == movieId && m.time.Value.Equals(newTime)
                             select m;


                if (result.Count() == 1)
                {
                    result.First().support += 1;
                    try
                    {
                        int i = _entity.SaveChanges();
                        isSucceed = true;
                    }
                    catch (Exception ex)
                    {
                        //异常处理
                        Console.WriteLine(ex);
                        return(false);
                    }
                }
                //撤销entity对象
                _entity.Dispose();
            }

            return(isSucceed);
        }
Exemple #4
0
        /// <summary>
        /// 这个函数根据电影院名,电影院地址,发表时间对电影院评论支持数增加1
        /// </summary>
        /// <param name="newCinemaName"></param>
        /// <param name="newCinemaAddr"></param>
        /// <param name="newTime"></param>
        /// <returns></returns>
        //public bool IncreaseCinemaCommentSupport(string newCinemaName, string newCinemaAddr, DateTime newTime)
        //{
        //    bool isSucceed = false;
        //    _entity = new WATCHMOVIEEntities();
        //    int cinemaId = new Cinema().GetCinemaId(newCinemaName, newCinemaAddr);

        //    if (cinemaId != -1)//如果cinema_id为-1则代表没有这个电影院,所以出错了
        //    {
        //        var result = from c in _entity.CINAME_COMMENT
        //                     where c.cinema_id == cinemaId && c.time.Equals(newTime)
        //                     select c;

        //        if (result.Count() == 1)
        //        {
        //            result.First().support += 1;
        //            try
        //            {
        //                int i = _entity.SaveChanges();
        //                isSucceed = true;
        //            }
        //            catch (Exception ex)
        //            {
        //                //异常处理
        //                Console.WriteLine(ex);
        //                return false;
        //            }
        //        }

        //        //撤销entity对象
        //        _entity.Dispose();
        //    }

        //    return isSucceed;
        //}

        /// <summary>
        /// 这个函数根据电影院名,电影院地址,发表时间对电影院评论支持数增加1
        /// </summary>
        /// <param name="newCinemaName"></param>
        /// <param name="newCinemaAddr"></param>
        /// <param name="newTime"></param>
        /// <returns></returns>
        //public bool IncreaseCinemaCommentSupport(string newCinemaName, string newCinemaAddr, DateTime newTime)
        //{
        //    bool isSucceed = false;
        //    _entity = new WATCHMOVIEEntities();
        //    int cinemaId = new Cinema().GetCinemaId(newCinemaName, newCinemaAddr);

        //    if (cinemaId != -1)//如果cinema_id为-1则代表没有这个电影院,所以出错了
        //    {
        //        var result = from c in _entity.CINAME_COMMENT
        //                     where c.cinema_id == cinemaId && c.time.Value.Equals(newTime)
        //                     select c;

        //        if (result.Count() == 1)
        //        {
        //            result.First().support += 1;
        //            try
        //            {
        //                int i = _entity.SaveChanges();
        //                isSucceed = true;
        //            }
        //            catch (Exception ex)
        //            {
        //                //异常处理
        //                Console.WriteLine(ex);
        //                return false;
        //            }
        //        }

        //        //撤销entity对象
        //        _entity.Dispose();
        //    }

        //    return isSucceed;
        //}
        public bool IncreaseCinemaCommentSupport(string newCinemaName, DateTime newTime)
        {
            bool isSucceed = false;

            _entity = new WATCHMOVIEEntities();
            int cinemaId = new Cinema().GetCinemaId(newCinemaName);

            if (cinemaId != -1)//如果cinema_id为-1则代表没有这个电影院,所以出错了
            {
                var result = from c in _entity.CINAME_COMMENT
                             where c.cinema_id == cinemaId && c.time.Value.Equals(newTime)
                             select c;

                if (result.Count() == 1)
                {
                    result.First().support += 1;
                    try
                    {
                        int i = _entity.SaveChanges();
                        isSucceed = true;
                    }
                    catch (Exception ex)
                    {
                        //异常处理
                        Console.WriteLine(ex);
                        return(false);
                    }
                }

                //撤销entity对象
                _entity.Dispose();
            }

            return(isSucceed);
        }
Exemple #5
0
        /// <summary>
        /// 此函数用来根据id删除电影院评论
        /// </summary>
        /// <param name="<newId>"></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库删除操作异常</exception>
        public bool DeleteCinemaCommentById(int newId)
        {
            //创建数据库实体对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //查找到需要删除的数据——(根据收藏id查找 结果只可能是一个)
            var result = from c in _entity.CINAME_COMMENT
                         where c.id == newId
                         select c;

            //从数据库中删除查找到的记录 并保存
            if (result.Count() >= 1)
            {
                _entity.CINAME_COMMENT.DeleteObject(result.First());
                try
                {
                    int i = _entity.SaveChanges();
                    isSucceed = true;
                }
                catch (Exception ex)
                {
                    //异常处理
                    Console.WriteLine(ex);
                    return(false);
                }
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }
Exemple #6
0
        /// <summary>
        /// 此函数用来增加一条电影院评论
        /// </summary>
        /// <param name="newComment"></param>
        /// <returns></returns>
        /// <exception>数据库插入异常</exception>
        public bool InsertCinemaComment(CINAME_COMMENT newComment)
        {
            //创建数据库实体类对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //添加记录到内存
            _entity.AddToCINAME_COMMENT(newComment);

            //保存修改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                //异常处理?
                Console.WriteLine(ex);
                return(false);
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }
Exemple #7
0
        /// <summary>
        /// 说明:<调用函数调用InsertMovieSchedules函数可以完成对电影时刻表增加多条记录的功能>
        /// </summary>
        /// <param name="<newMovieSchedules>"><接受调用函数传入的一个COLLECTION对象集合></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库增加操作异常</exception>

        public bool InsertMovieSchedules(List <MOVIE_SCHEDULE> newMovieSchedules)
        {
            //创建数据库实体类对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //添加新记录到内存
            foreach (MOVIE_SCHEDULE newMovieSchedule in newMovieSchedules)
            {
                _entity.AddToMOVIE_SCHEDULE(newMovieSchedule);
            }

            //保存修改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                //异常处理?
                Console.WriteLine(ex);
                return(false);
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }
Exemple #8
0
        public bool AddCinemaComment(string newCinemaName, int newCinemaId, CINAME_COMMENT newComment)
        {
            //添加用户对电影院的评论
            //修改 增加一个电影院的ID 唯一定位电影院
            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
            var result = from cinema in entity.CINEMA
                         where cinema.name == newCinemaName && cinema.id == newCinemaId
                         select cinema;//检索出对应的电影院

            if (result.Count() == 1)
            {
                entity.CINAME_COMMENT.AddObject(newComment);//向电影评论列表中添加一条新评论
                try
                {
                    int i = entity.SaveChanges();
                    entity.Dispose();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #9
0
        public bool DeleteUser() //删除用户
        {
            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
            var result = from user in entity.RUSER
                         where user.id == _id
                         select user;

            if (result.Count() == 1)
            {
                entity.RUSER.DeleteObject(result.First());
                try
                {
                    int i = entity.SaveChanges();
                    entity.Dispose();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #10
0
        public bool PreferenceSave(string newEmail, string newType)
        {
            //保存用户偏好
            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
            var result = from user in entity.RUSER
                         where user.email == newEmail
                         select user;//找到用户

            if (result.Count() == 1)
            {
                result.First().like_kind = newType;//保存用户偏好
                //result.First().address = newAddr;
                try
                {
                    int i = entity.SaveChanges();//同步到数据库
                    entity.Dispose();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #11
0
        /// <summary>
        /// 说明:<调用函数调用DeleteMovieScheduleById函数可以完成对电影时刻表删除一条记录的功能>
        /// </summary>
        /// <param name="<newId>"><接受调用函数传入的一个MOVIE_SCHEDULE对象的Id></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库删除操作异常</exception>
        public bool DeleteMovieScheduleById(int newId)
        {
            //创建数据库实体对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //查找到需要删除的数据——(根据电影时刻表id查找 结果只可能是一个)
            var result = from c in _entity.MOVIE_SCHEDULE
                         where c.id == newId
                         select c;

            //从数据库中删除查找到的记录 并保存
            if (result.Count() >= 1)
            {
                _entity.MOVIE_SCHEDULE.DeleteObject(result.First());

                try
                {
                    int i = _entity.SaveChanges();
                    isSucceed = true;
                }
                catch (Exception ex)
                {
                    //异常处理?
                    Console.WriteLine(ex);
                    return(false);
                }
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }
Exemple #12
0
        public bool UpdatePassword(string newEmail, string newPassword)
        {
            //更新密码
            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
            var result = from user in entity.RUSER
                         where user.email == newEmail
                         select user;

            if (result.Count() == 1)
            {
                //修改密码
                result.First().password = newPassword;
                try
                {
                    int i = entity.SaveChanges();//保存修改
                    entity.Dispose();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #13
0
        public bool AddMovieComment(string newMovieName, MOVIE_COMMENT newComment)
        {
            //添加用户对电影的评论
            //??????????????????????????

            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
            var result = from movie in entity.MOVIE
                         where movie.name == newMovieName
                         select movie;//定位到对应的电影

            if (result.Count() == 1)
            {
                entity.MOVIE_COMMENT.AddObject(newComment);
                try
                {
                    int i = entity.SaveChanges();
                    entity.Dispose();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #14
0
        /* public bool AddMovie(string name,string director,string actor,string kind,string region
         *   ,int lastingTime,DateTime firstShowTime,string introduction,Byte  rank,int rankNum,
         *   int clickNum,bool onShow)
         * {//向数据库电影表MOVIEs中插入一个电影记录
         *
         *   WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
         *   MOVIE newMovie = new MOVIE();
         *   newMovie.name = name;
         *   newMovie.director = director;
         *   newMovie.actor = actor;
         *   newMovie.kind = kind;
         *   newMovie.region = region;
         *   newMovie.last_time = lastingTime;
         *   newMovie.first_showtime = firstShowTime;
         *   newMovie.introduction = introduction;
         *   newMovie.rank = rank;
         *   newMovie.rank_number = rankNum;
         *   newMovie.click_number = clickNum;
         *   newMovie.is_on_show = onShow;//给新对象添加属性;
         *
         *   entity.MOVIE.AddObject(newMovie);
         *   int i=0;
         *   try
         *   {
         *       i = entity.SaveChanges();
         *   }
         *   catch (Exception exp)
         *   {
         *       MessageBox.Show (exp.ToString());
         *       entity.Dispose();//销毁对象
         *       return false;
         *   }
         *   entity.Dispose();//销毁对象
         *   return true;
         *
         * }
         */
        public bool AddMovie(string name, string director, string actor, string kind, string region
                             , int lastingTime, DateTime firstShowTime, string introduction, Byte rank, int rankNum,
                             int clickNum)
        {//向数据库电影表MOVIEs中插入一个电影记录
            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
            MOVIE newMovie            = new MOVIE();

            //给新对象添加属性;
            newMovie.name     = name;
            newMovie.director = director;
            newMovie.actor    = actor;
            newMovie.kind     = kind;
            newMovie.region   = region;
            //newMovie.last_time = lastingTime;  //7.22 cm
            newMovie.last_time      = (short)lastingTime;
            newMovie.first_showtime = firstShowTime;
            newMovie.introduction   = introduction;
            newMovie.rank           = rank;
            //newMovie.rank_number = rankNum;   //7.22 cm
            newMovie.rank_number = (short)rankNum;
            //newMovie.click_number = clickNum;  //7.22 cm
            newMovie.click_number = (short)clickNum;


            entity.MOVIE.AddObject(newMovie);
            int i = 0;

            try
            {
                i = entity.SaveChanges();
            }
            catch (Exception exp)
            {
                //MessageBox.Show(exp.ToString());
                entity.Dispose();//销毁对象
                return(false);
            }
            entity.Dispose();//销毁对象
            return(true);
        }
Exemple #15
0
        public bool AddUser(string newName, string newEmail, string newePassword)
        {
            Search searchEmail = new Search();//用来检查newEmai是不是已经注册过

            if (!(searchEmail.SearchEmail(newEmail)))
            {
                //创建新用户

                WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
                RUSER newUser             = new RUSER();

                //为新用户添加基本信息
                newUser.name     = newName;
                newUser.password = newePassword;
                newUser.email    = newEmail;

                entity.RUSER.AddObject(newUser);
                try
                {
                    int i = entity.SaveChanges();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                    entity.Dispose();
                    return(false);
                }
                entity.Dispose();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #16
0
        public bool DeleteMovie(string movieName, DateTime movieShowTime)
        {
            WATCHMOVIEEntities entity = new WATCHMOVIEEntities();
            var result = from movie in entity.MOVIE
                         where movie.name == movieName && movie.first_showtime == movieShowTime
                         select movie;//现在数据库根据影片名字 和首次放映时间 选择相关的影片记录

            foreach (var oldMovie in result)
            {
                entity.MOVIE.DeleteObject(oldMovie);//是不是全部删除啊  根据什么删除?
            }
            try
            {
                int i = entity.SaveChanges();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
                entity.Dispose();//销毁对象
                return(false);
            }
            entity.Dispose();//销毁对象
            return(true);
        }
Exemple #17
0
        /// <summary>
        /// 说明:<重载InsertCollection >
        /// </summary>
        /// <param name="<newUserId>" name="<newMovieId>">
        /// <接受调用函数传入COLLECTION的三个字段作为参数></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库增加操作异常</exception>

        //public bool InsertCollection(int newUserId, int newMovieId)
        //{
        //    //创建数据库实体类对象
        //    _entity = new WATCHMOVIEEntities();

        //    bool isSucceed = false;

        //    //创建一个临时COLLECTION对象
        //    COLLECTION collection = new COLLECTION();


        //    //collection.id = newId;
        //    collection.user_id = newUserId;
        //    collection.movie_id = newMovieId;

        //    //添加记录到内存
        //    _entity.AddToCOLLECTION(collection);

        //    //保存修改到数据库
        //    try
        //    {
        //        int i = _entity.SaveChanges();
        //        isSucceed = true;
        //    }
        //    catch (Exception ex)
        //    {
        //        //异常处理?
        //        return false;
        //    }

        //    //撤销数据库实体
        //    _entity.Dispose();

        //    return isSucceed;
        //}
        public bool InsertCollection(int newUserId, int newMovieId)
        {
            //创建数据库实体类对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            var result = from c in _entity.COLLECTION
                         where c.user_id == newUserId && c.movie_id == newMovieId
                         select c;

            if (result.Count() > 0)
            {
                return(isSucceed);
            }
            //创建一个临时COLLECTION对象
            COLLECTION collection = new COLLECTION();


            //collection.id = newId;
            collection.user_id  = newUserId;
            collection.movie_id = newMovieId;


            //添加记录到内存
            _entity.AddToCOLLECTION(collection);

            //保存修改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                //异常处理?
                Console.WriteLine(ex);
                return(false);
            }

            //撤销数据库实体
            _entity.Dispose();

            return(isSucceed);
        }
Exemple #18
0
        public List <MOVIE_SCHEDULE> GetAllMovieSchedule(int newMovieId)
        {
            //根据电影名字选择对应的电影时刻表
            List <MOVIE_SCHEDULE> movieSchedule = new List <MOVIE_SCHEDULE>();
            WATCHMOVIEEntities    entity        = new WATCHMOVIEEntities();
            var result = from m in entity.MOVIE_SCHEDULE
                         where m.movie_id == newMovieId
                         select m;

            if (result.Count() > 0)
            {
                foreach (var m in result)
                {
                    movieSchedule.Add(m);
                }
            }
            entity.Dispose();
            return(movieSchedule);
        }
Exemple #19
0
        /// <summary>
        /// 说明:<调用函数调用DeleteCollectionsByUserId函数
        /// 可以完成对收藏夹删除于此用户相关的所以记录的功能>
        /// </summary>
        /// <param name="<newUserId>"><接受调用函数传入的一个用户对象的Id></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库删除操作异常</exception>
        public bool DeleteCollectionsByUserId(int newUserId)
        {
            //创建数据库实体对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //查找到需要删除的数据——(根据用户id查找 结果是该用户所有收藏记录)
            var result = from c in _entity.COLLECTION
                         where c.user_id == newUserId
                         select c;

            //从数据库中删除查找到的记录
            foreach (var a in result)
            {
                _entity.COLLECTION.DeleteObject(a);
            }

            //保存更改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                //异常处理?
                Console.WriteLine(ex);
                return(false);
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }
Exemple #20
0
        /// <summary>
        /// 说明:<调用函数调用DeleteMovieSchedulesByMovieId函数
        /// 可以完成对收藏夹删除于此电影相关的所以记录的功能>
        /// </summary>
        /// <param name="<newMovieId>"><接受调用函数传入的一个电影对象的Id></param>
        /// <returns><操作成功返回True,否则返回False> </returns>
        ///<exception>数据库删除操作异常</exception>
        public bool DeleteMovieSchedulesByMovieId(int newMovieId)
        {
            //创建数据库实体对象
            _entity = new WATCHMOVIEEntities();

            bool isSucceed = false;

            //查找到需要删除的数据——(根据电影id查找 结果是有关该电影所有电影时刻表记录)
            var result = from c in _entity.MOVIE_SCHEDULE
                         where c.movie_id == newMovieId
                         select c;

            //从数据库中删除查找到的记录
            foreach (var a in result)
            {
                _entity.MOVIE_SCHEDULE.DeleteObject(a);
            }

            //保存更改到数据库
            try
            {
                int i = _entity.SaveChanges();
                isSucceed = true;
            }
            catch (Exception ex)
            {
                //异常处理?
                Console.WriteLine(ex);
                return(false);
            }

            //撤销entity对象
            _entity.Dispose();

            return(isSucceed);
        }