/// <summary>
 /// 获取数据库里中电影票出售情况,实现多机互联。
 /// </summary>
 /// <param name="ticketsMsg"></param>
 public void GetSellTicketSeatsMsg(SitulationOfTickets ticketsMsg)
 {
     //在每一次获取已售出票的信息时,重置控件状态
     ResetControls();
     List<string> seatsMsg = fmb.GetSitulationOfTickets(ticketsMsg);
     if (seatsMsg != null)
     {
         foreach (string seatMsg in seatsMsg)
         {
             foreach (LinkLabel item in (List<LinkLabel>)ht[ticketsMsg.videoHallId])
             {
                 if (item.Text.Trim() == seatMsg.Trim())//如果存在,则设其控件属性enable为false
                 {
                     item.Enabled = false;
                 }
             }
         }
     }
     else
     {
         //返回的数组为空,说明暂时还没有座位出售信息,不做操作
     }
 }
        /// <summary>
        /// 点击选中节点,获取影片信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void trv1_movieList_AfterSelect(object sender, TreeViewEventArgs e)
        {
            DeleteExtraTicketState();//在节点改变的情况下,自动删除多余的座位信息
            this.trv1_movieList.SelectedNode.BackColor = Color.DarkTurquoise;
            string nodeName = trv1_movieList.SelectedNode.Text.Trim();
            //判断是不是使用邀请码跳转的影片信息
            if (txt_giver.Enabled == true)
            {
                int id = Convert.ToInt32(trv1_movieList.SelectedNode.Tag);
                if (!imc.FilmId.ToString().Equals(this.trv1_movieList.SelectedNode.Tag.ToString()))
                {
                    MessageBox.Show("对不起,该邀请码只能用于观看指定的电影,请返回重新选择!", "错误的操作");
                    this.trv1_movieList.Nodes[id - 1].Checked = true;
                    return;
                }
            }
            if (e.Node.Parent == null)//父节点trv1_movieList.SelectedNode.Text.Trim()
            {
                fmc = fmb.GetFilmMsg(nodeName);
                lbl_filmName.Text = fmc.FilmName;
                lbl_director.Text = fmc.Director;
                lbl_protagonist.Text = fmc.Protagonists;
                lbl_filmType.Text = fmc.FilmType;
                lbl_filmTime.Text = fmc.FilmTimes;
                pic_filmImg.Image = imgLIst_FilmPic.Images[fmc.FilmId - 1];
                // ResetControls();
            }
            else//子节点
            {
                //点击字节点,获取,优惠价,票价,和放映厅号信息
                string filmName = this.trv1_movieList.SelectedNode.Parent.Text;
                fmc = fmb.GetFilmMsg(filmName);
                lbl_filmName.Text = fmc.FilmName;
                lbl_director.Text = fmc.Director;
                lbl_protagonist.Text = fmc.Protagonists;
                lbl_filmType.Text = fmc.FilmType;
                lbl_filmTime.Text = fmc.FilmTimes;
                pic_filmImg.Image = imgLIst_FilmPic.Images[fmc.FilmId - 1];
                DataTable dt = fmb.GetFilmReleaseDate(cboReleaseDate.Text);
                dv = new DataView(dt);
                foreach (DataRowView drv in dv)
                {
                    //if (Convert.ToString(drv["PlayTime"]) == e.Node.Text)
                    string playTime = Convert.ToString(drv["FilmBeginTime"]).Trim() + "-" + drv["FilmEndTime"].ToString().Trim();
                    if (playTime == e.Node.Text)
                    {
                        lbl_price.Text = drv["TicketPrice"].ToString();
                        lbl_bestPrice.Text = drv["PreferentialPrice"].ToString();
                        //得到当前电影id
                        filmid = Convert.ToInt32(drv["FilmId"]);
                        //得到放映厅号
                        videoHallid = Convert.ToInt32(drv["VideoHallId"]);
                        //切换放映厅
                        this.tabcon_videoHall.SelectedIndex = videoHallid - 1;//由于放映厅号id是从0开始,因此需要减1
                        break;

                    }
                }
                //从文本文件中获取此时段该影片的售票信息
                // GetSellTicketSeats(filmName);
                //从数据库中获取此时段该影片的售票信息并将获取结果显示在放映厅的座位状态上
                SitulationOfTickets tiketsMsg = new SitulationOfTickets();
                tiketsMsg.ReleaseDates = cboReleaseDate.Text;
                tiketsMsg.videoHallId = videoHallid;
                tiketsMsg.Playtime = this.trv1_movieList.SelectedNode.Text.Trim();
                tiketsMsg.FilmName = filmName;
                tiketsMsg.SeatsState = -1;//
                //获取已售出的座位信息
                GetSellTicketSeatsMsg(tiketsMsg);
            }
        }
 /// <summary>
 /// 向数据库中插入购买的票
 /// </summary>
 public int InsertTickets()
 {
     DialogResult ds2 = MessageBox.Show("确定选择选中的座位?", "确认界面", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     int ticketCounts = 0;
     if (ds2 == DialogResult.Yes)
     {
         //得到要添加信息的电影名称
         string filmName = this.trv1_movieList.SelectedNode.Parent.Text;
         string releaseDates = cboReleaseDate.Text;
         SitulationOfTickets insertTicketMsg = new SitulationOfTickets();
         //操作转换日期的形式
         insertTicketMsg.ReleaseDates = releaseDates;
         insertTicketMsg.videoHallId = videoHallid;
         insertTicketMsg.FilmName = filmName;
         insertTicketMsg.Playtime = this.trv1_movieList.SelectedNode.Text.Trim();
         insertTicketMsg.SeatsState = -1;//插入信息设置票的状态为已购买(-1)
         //插入票
         List<LinkLabel> seats = ht[videoHallid] as List<LinkLabel>;
         for (int i = 0; i < seats.Count; i++)
         {
             if (seats[i].LinkVisited == true && seats[i].Enabled == true)
             {
                 seats[i].Enabled = false;
                 insertTicketMsg.SeatsNumber = seats[i].Text;
                 fmb.InsertSellTicetsMsg(insertTicketMsg);
                 fmb.DeleteSeatMsg(insertTicketMsg);
                 ticketCounts++;
             }
         }
         //将卖出的电影票数量传回数据库,返回受影响的行数
         int isSelledTickets = fmb.GetTicketCounts(ticketCounts, this.trv1_movieList.SelectedNode.Text.Trim(), filmid);
         if (isSelledTickets > 0)//如果大于0,则操作成功
         {
             MessageBox.Show("操作成功,您已获得" + ticketCounts.ToString() + "张票", "购买成功");
         }
     }
     else
     {
         MessageBox.Show("您已取消操作,系统自动返回购票界面!!!");
     }
     return ticketCounts;
 }
 /// <summary>
 /// 座位点击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void linkLb5_8_Click(object sender, EventArgs e)
 {
     try
     {
         SitulationOfTickets tiketsMsg = new SitulationOfTickets();
         tiketsMsg.ReleaseDates = cboReleaseDate.Text;
         tiketsMsg.videoHallId = videoHallid;
         tiketsMsg.Playtime = this.trv1_movieList.SelectedNode.Text.Trim();
         tiketsMsg.FilmName = this.trv1_movieList.SelectedNode.Parent.Text.Trim();
         List<LinkLabel> llinkLables = ht[videoHallid] as List<LinkLabel>;
         LinkLabel l = sender as LinkLabel;
         tiketsMsg.SeatsNumber = l.Text;
         int i = fmb.GetTicketState(tiketsMsg);
         if (!l.LinkVisited && fmb.GetTicketState(tiketsMsg) > 0)
         {
             MessageBox.Show("对不起,该座位被锁定,请稍后子再试");
             return;
         }
         foreach (LinkLabel item in llinkLables)
         {
             if (l.Text == item.Text)
             {
                 //判断是否已经有人选择这个座位,防止重复购买的情况出现,待增。
                 //遍历数据库查询状态为0的座位信息
                 item.LinkVisited = !item.LinkVisited;
                 tiketsMsg.SeatsNumber = item.Text;
                 //选中,向数据库中插入此电影票的状态为0,既选定状态
                 if (item.LinkVisited)
                 {
                     tiketsMsg.SeatsState = 0;//该状态为锁定状态
                     fmb.InsertSellTicetsMsg(tiketsMsg);
                 }
                 else//取消选中,删除此电影票在数据库的信息
                 {
                     fmb.DeleteSeatMsg(tiketsMsg);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("请先选择影片和时段");
         return;
     }
 }
 /// <summary>
 /// 插入座位信息
 /// </summary>
 /// <param name="ticketMsgs"></param>
 public int InsertSellTicetsMsg(SitulationOfTickets ticketMsgs)
 {
     ticketMsgs.ReleaseDates = DateFormat.GetRightDateFormat(ticketMsgs.ReleaseDates);
     return filmMsg.InsertSellTicetsMsg(ticketMsgs);
 }
 /// <summary>
 ///   更新座位的状态
 /// </summary>
 /// <param name="situlationOfTickets"></param>
 /// <returns></returns>
 public int UpdateSeatsState(SitulationOfTickets ticketMsgs)
 {
     ticketMsgs.ReleaseDates = DateFormat.GetRightDateFormat(ticketMsgs.ReleaseDates);
     return filmMsg.UpdateSeatsState(ticketMsgs);
 }
 /// <summary>
 /// 获取数据库中已有的指定日期的电影,指定厅的已售出的座位信息
 /// </summary>
 /// <param name="situlationOfTickets"></param>
 public List<string> GetSitulationOfTickets(SitulationOfTickets ticketMsgs)
 {
     List<string> SeatsMsg = new List<string>();
     ticketMsgs.ReleaseDates = DateFormat.GetRightDateFormat(ticketMsgs.ReleaseDates);
     SqlDataReader sdr = filmMsg.GetSitulationOfTickets(ticketMsgs);
     if (sdr.HasRows)
     {
         while (sdr.Read())
         {
             SeatsMsg.Add(sdr[0].ToString());
         }
     }
     return SeatsMsg;
 }
 /// <summary>
 /// 获取当前电影票座位状态
 /// </summary>
 /// <param name="ticketMsg"></param>
 /// <returns></returns>
 public int GetTicketState(SitulationOfTickets ticketMsg)
 {
     ticketMsg.ReleaseDates = DateFormat.GetRightDateFormat(ticketMsg.ReleaseDates);
     return filmMsg.GetTicketState(ticketMsg);
 }
 /// <summary>
 /// 删除锁定状态的电影票座位信息
 /// </summary>
 public int DeleteSeatMsg(SitulationOfTickets ticketMsgs)
 {
     ticketMsgs.ReleaseDates = DateFormat.GetRightDateFormat(ticketMsgs.ReleaseDates);
     return filmMsg.DeleteSeatMsg(ticketMsgs);
 }
 /// <summary>
 /// 获取数据库中已有的指定日期的电影,指定厅的指定座位状态的信息
 /// </summary>
 /// <param name="situlationOfTickets"></param>
 public int GetSeatStates(SitulationOfTickets ticketMsgs)
 {
     ticketMsgs.ReleaseDates = DateFormat.GetRightDateFormat(ticketMsgs.ReleaseDates);
     SqlDataReader sdr = filmMsg.GetSeatStates(ticketMsgs);
     if (sdr.HasRows)
     {
         while (sdr.Read())
         {
             int seatsState = (int)sdr[0];
             return seatsState;
         }
     }
     return 0;//错误
 }
 /// <summary>
 ///  更新座位的状态
 /// </summary>
 /// <param name="situlationOfTickets"></param>
 /// <returns></returns>
 public int UpdateSeatsState(SitulationOfTickets situlationOfTickets)
 {
     string sql = "update [dbo].[SitulationOfTickets] "
     + " set SeatsState=@SeatsState "
     + " where  ReleaseDates=@releasedates and VideoHallId =@videoHallId "
     + " and FilmName=@filmName and Playtimes=@playtimes and SeatsNumber=@seatsNumber";
     SqlParameter[] paras ={
                              new SqlParameter("@SeatsState",SqlDbType.Int,4),
                              new SqlParameter ("@ReleaseDates",SqlDbType.VarChar,50),
                              new SqlParameter ("@VideoHallId",SqlDbType.Int,4),
                              new SqlParameter ("@FilmName",SqlDbType.VarChar,50),
                              new SqlParameter ("@Playtimes",SqlDbType.VarChar,50),
                              new SqlParameter ("@SeatsNumber",SqlDbType.VarChar,10)
                          };
     paras[0].Value = situlationOfTickets.SeatsState;
     paras[1].Value = situlationOfTickets.ReleaseDates;
     paras[2].Value = situlationOfTickets.videoHallId;
     paras[3].Value = situlationOfTickets.FilmName;
     paras[4].Value = situlationOfTickets.Playtime;
     paras[5].Value = situlationOfTickets.SeatsNumber;
     return SQLHelper.ExecuteNonQuery(sql, paras);
 }
 /// <summary>
 /// 插入座位信息
 /// </summary>
 /// <param name="ticketMsgs"></param>
 public int InsertSellTicetsMsg(SitulationOfTickets ticketMsgs)
 {
     string sql = "insert into [dbo].[SitulationOfTickets] "
     + " values(@ReleaseDates,@VideoHallId,@FilmName,@Playtimes,@SeatsNumber,@SeatsState) ";
     SqlParameter[] paras ={
                              new SqlParameter("@ReleaseDates",SqlDbType.VarChar,50),
                              new SqlParameter("@VideoHallId",SqlDbType.Int,4),
                              new SqlParameter("@FilmName",SqlDbType.VarChar,50),
                              new SqlParameter("@Playtimes",SqlDbType.VarChar,50),
                              new SqlParameter("@SeatsNumber",SqlDbType.VarChar,4),
                              new SqlParameter("@SeatsState",SqlDbType.Int,4)
                          };
     paras[0].Value = ticketMsgs.ReleaseDates;
     paras[1].Value = ticketMsgs.videoHallId;
     paras[2].Value = ticketMsgs.FilmName;
     paras[3].Value = ticketMsgs.Playtime;
     paras[4].Value = ticketMsgs.SeatsNumber;
     paras[5].Value = ticketMsgs.SeatsState;
     return SQLHelper.ExecuteNonQuery(sql, paras);
 }
 /// <summary>
 /// 判断座位的状态信息
 /// </summary>
 /// <param name="ticketMsg"></param>
 /// <returns></returns>
 public int GetTicketState(SitulationOfTickets ticketMsg)
 {
     string sql = "select COUNT(*) from [dbo].[SitulationOfTickets] ";
     sql += "where ReleaseDates=@ReleaseDates and VideoHallId=@VideoHallId and  ";
     sql += "Playtimes=@Playtimes and SeatsNumber=@SeatsNumber and SeatsState=0";
     SqlParameter[] paras ={
                              new SqlParameter("@ReleaseDates",SqlDbType.VarChar,50),
                              new SqlParameter("@VideoHallId",SqlDbType.Int,4),
                              new SqlParameter("@FilmName",SqlDbType.VarChar,50),
                              new SqlParameter("@Playtimes",SqlDbType.VarChar,50),
                              new SqlParameter("@SeatsNumber",SqlDbType.VarChar,4),
                              new SqlParameter("@SeatsState",SqlDbType.Int,4)
                          };
     paras[0].Value = ticketMsg.ReleaseDates;
     paras[1].Value = ticketMsg.videoHallId;
     paras[2].Value = ticketMsg.FilmName;
     paras[3].Value = ticketMsg.Playtime;
     paras[4].Value = ticketMsg.SeatsNumber;
     paras[5].Value = ticketMsg.SeatsState;
     return (int)SQLHelper.ExecuteScalar(sql, paras);
 }
        /// <summary>
        /// 获取数据库中已有的指定日期的电影,指定厅的已的各座位的信息(已售出,被锁定,可买)
        /// </summary>
        /// <param name="situlationOfTickets"></param>
        public SqlDataReader GetSitulationOfTickets(SitulationOfTickets ticketMsgs)
        {
            string sql = "select SeatsNumber from [dbo].[SitulationOfTickets]";

            sql += "where ReleaseDates=@ReleaseDates  and VideoHallId =@VideoHallId "
                    + "and Playtimes=@Playtimes and FilmName=@FilmName and SeatsState=@SeatsState";
            SqlParameter[] paras ={
                                   new SqlParameter("@ReleaseDates",SqlDbType.VarChar,50 ),
                                   new SqlParameter("@VideoHallId",SqlDbType.Int,4 ),
                                   new SqlParameter("@Playtimes",SqlDbType.VarChar,50 ),
                                   new SqlParameter("@FilmName",SqlDbType.VarChar,50 ),
                                   new SqlParameter("@SeatsState",SqlDbType.Int,4  )
                                  };
            paras[0].Value = ticketMsgs.ReleaseDates;
            paras[1].Value = ticketMsgs.videoHallId;
            paras[2].Value = ticketMsgs.Playtime;
            paras[3].Value = ticketMsgs.FilmName;
            paras[4].Value = ticketMsgs.SeatsState;
            return SQLHelper.ExecuteReader(sql, paras);
        }
 /// <summary>
 /// 删除锁定状态的电影票座位信息
 /// </summary>
 public int DeleteSeatMsg(SitulationOfTickets ticketMsgs)
 {
     string sql = "Delete [dbo].[SitulationOfTickets] "
     + " where ReleaseDates=@ReleaseDates and VideoHallId=@VideoHallId and FilmName=@FilmName "
     + " and Playtimes=@Playtimes and SeatsNumber=@SeatsNumber and SeatsState=@SeatsState";
     SqlParameter[] paras ={
                              new SqlParameter("@ReleaseDates",SqlDbType.VarChar,50),
                              new SqlParameter("@VideoHallId",SqlDbType.Int,4),
                              new SqlParameter("@FilmName",SqlDbType.VarChar,50),
                              new SqlParameter("@Playtimes",SqlDbType.VarChar,20),
                              new SqlParameter("@SeatsNumber",SqlDbType.VarChar,10),
                              new SqlParameter("@SeatsState",SqlDbType.Int,4)
                          };
     paras[0].Value = ticketMsgs.ReleaseDates;
     paras[1].Value = ticketMsgs.videoHallId;
     paras[2].Value = ticketMsgs.FilmName;
     paras[3].Value = ticketMsgs.Playtime;
     paras[4].Value = ticketMsgs.SeatsNumber;
     paras[5].Value = 0;
     return SQLHelper.ExecuteNonQuery(sql, paras);
 }