示例#1
0
        public int sureChip(string cinemaName, string officeName, string movieName, DateTime time)
        {
            string                selectMinutes = "select MovieDuration from MovieInfo where MovieName=@movieName";
            SqlDataReader         reader        = SqlHelper.GetSqlDataReader(selectMinutes, new SqlParameter("@movieName", movieName));
            List <MovieInfoModel> ls            = new List <MovieInfoModel>();

            while (reader.Read())
            {
                MovieInfoModel mov = new MovieInfoModel(reader);
                ls.Add(mov);
            }
            reader.Close();
            int minutes = ls[0].MovieDuration;
            //插入数据
            string sql = "insert into ChipInfo values((select CinemaID from CinemaInfo where CinemaName=@cinemaName),(select officeID from OfficeInfo where OfficeName=@officeName and CinemaID=(select CinemaID from CinemaInfo where CinemaName=@cinemaName)),@movieName,@time,@time2)";
            int    a   = SqlHelper.ExecuteNonQuery(sql, System.Data.CommandType.Text,
                                                   new SqlParameter("@cinemaName", cinemaName.ToString().Trim()),
                                                   new SqlParameter("@officeName", officeName.ToString().Trim()),
                                                   new SqlParameter("@movieName", movieName.ToString().Trim()),
                                                   new SqlParameter("@time", time),
                                                   new SqlParameter("@time2", time.AddMinutes(minutes))
                                                   );
            //调用存储过程生成座位
            ChipInfoModel chipInfoModel = new ChipInfoModel();

            sql = "select top 1 *from ChipInfo order by ChipInfoID desc";
            var read = SqlHelper.GetSqlDataReader(sql);

            while (read.Read())
            {
                chipInfoModel = new ChipInfoModel(read);
            }

            a += SqlHelper.ExecuteNonQuery("proc_CreateSeat", System.Data.CommandType.StoredProcedure, new SqlParameter("@OfficeID", chipInfoModel.OfficeID), new SqlParameter("@ChipID", chipInfoModel.ChipInfoID));
            return(a);
        }
示例#2
0
        /// <summary>
        /// 传入影院ID和电影ID时返回厅院上映信息
        /// </summary>
        /// <param name="mi"></param>
        /// <param name="om"></param>
        /// <returns></returns>
        public List <ShowDetails> FindShowDetails(MovieInfoModel mi, CinemaInfoModel om)
        {
            string str;

            SqlParameter[] sqlParameters = null;
            if (mi.MovieID != 0)
            {
                //通过电影ID查询到该电影信息
                str           = "select * from MovieInfo where MovieID =@MovieID";
                sqlParameters = new SqlParameter[] {
                    new SqlParameter("@MovieID", System.Data.SqlDbType.Int)
                    {
                        Value = mi.MovieID
                    }
                };
            }
            else
            {
                // 在没有电影ID的时候,查询该电影院的Top 1排片电影
                str = " Select Top 1* from MovieInfo where MovieName in " +
                      "(select MovieName from[dbo].[ChipInfo] where CinemaID = @CinemaID " +
                      " and datediff(MINUTE, getdate(),StartTime)>15)";

                sqlParameters = new SqlParameter[] {
                    new SqlParameter("@CinemaID", System.Data.SqlDbType.Int)
                    {
                        Value = om.CinemaID
                    }
                };
            }

            SqlDataReader reader = SqlHelper.ExecuteReader(str, System.Data.CommandType.Text, sqlParameters);

            MovieInfoModel mo = new MovieInfoModel();

            while (reader.Read())
            {
                mo = new MovieInfoModel(reader);
            }
            reader.Close();

            //上映详情集合
            List <ShowDetails> ls = new List <ShowDetails>();

            if (String.IsNullOrEmpty(mo.MovieName))
            {
                return(ls);
            }

            //通过传入的影院ID获取该排片的开始结束时间、且必须为今日排片、离上映时间大于15分钟
            str           = "select * from [dbo].[ChipInfo] where CinemaID=@CinemaID and datediff(MINUTE,getdate(),StartTime)>15 and Convert(nvarchar,StartTime,120) like @TimeNow+'%' and MovieName=@MovieName";
            sqlParameters = new SqlParameter[] {
                new SqlParameter("@CinemaID", System.Data.SqlDbType.Int)
                {
                    Value = om.CinemaID
                },
                new SqlParameter("@MovieName", System.Data.SqlDbType.NVarChar)
                {
                    Value = mo.MovieName
                },
                new SqlParameter("@TimeNow", System.Data.SqlDbType.NVarChar)
                {
                    Value = DateTime.Now.ToString().Substring(0, DateTime.Now.ToString().IndexOf(' ')).Replace('/', '-')
                }
            };

            reader = SqlHelper.ExecuteReader(str, System.Data.CommandType.Text, sqlParameters);

            //排片集合
            List <ChipInfoModel> os = new List <ChipInfoModel>();

            while (reader.Read())
            {
                ChipInfoModel oi = new ChipInfoModel(reader);
                os.Add(oi);
            }
            reader.Close();

            //将该影院所有关于该电影的排片信息(开始结束时间)放入ShowDetails集合
            for (int i = 0; i < os.Count; i++)
            {
                ls.Add(new ShowDetails()
                {
                    ChipInfoID = os[i].ChipInfoID, StartTime = os[i].StartTime, StopTime = os[i].StopTime, Money = mo.MovieMoney, Language = mo.MovieArea
                });
            }

            List <OfficeInfoModel> of = new List <OfficeInfoModel>();

            //通过传入的影院ID获取厅信息
            for (int i = 0; i < os.Count; i++)
            {
                str           = " select * from [dbo].[OfficeInfo] where [OfficeID] in  (@OfficeID)";
                sqlParameters = new SqlParameter[] {
                    new SqlParameter("@OfficeID", System.Data.SqlDbType.Int)
                    {
                        Value = os[i].OfficeID
                    }
                };

                reader = SqlHelper.ExecuteReader(str, System.Data.CommandType.Text, sqlParameters);

                //获取到了所有的厅位信息
                while (reader.Read())
                {
                    OfficeInfoModel ofs = new OfficeInfoModel(reader);
                    of.Add(ofs);
                }
                reader.Close();
            }

            for (int i = 0; i < of.Count; i++)
            {
                ls[i].OfficeID   = of[i].OfficeID;
                ls[i].OfficeName = of[i].OfficeName;
            }

            return(ls);
        }