/// <summary>
 /// 添加电影
 /// </summary>
 /// <param name="fmc"></param>
 /// <returns></returns>
 public bool AddFilm(FilmMsgCommon fmc)
 {
     if (filmMsg.AddFilm(fmc) > 0)
     {
         return true;
     }
     return false;
 }
 /// <summary>
 /// 添加电影
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_Add_Click(object sender, EventArgs e)
 {
     if (btn_Add.Text.Contains("要"))
     {
         CleanTxtControl();
         btn_Cancel.Visible = true;
         btn_Modify.Enabled = false;
         btn_Del.Enabled = false;
         btn_DownLine.Enabled = false;
         lbl_ImportExport.Enabled = false;
         txt_Country.Enabled = true;
         txt_Director.Enabled = true;
         txt_FilmId.Enabled = true;
         txt_FilmName.Enabled = true;
         txt_FilmTimes.Enabled = true;
         txt_FilmType.Enabled = true;
         txt_Producers.Enabled = true;
         txt_Protagonists.Enabled = true;
         btn_Add.Text = "保存添加";
         return;
     }
     FilmMsgCommon fmc = new FilmMsgCommon();
     fmc.FilmId = 0;
     try
     {
         fmc.FilmId = Convert.ToInt32(txt_FilmId.Text);
     }
     catch
     {
         MessageBox.Show("请输入正确的电影ID");
         return;
     }
     //将控件的值赋给数据库模型
     ControlToModel(fmc);
     fmc.FilmState = 1;
     fmc.ScheduleTime = 0;
     if (filmMsg.AddFilm(fmc))
     {
         GetFilmsMsg();
         MessageBox.Show("添加成功");
     }
     else
     {
         MessageBox.Show("添加失败");
     }
     btn_Cancel.Visible = false;
     btn_Add.Text = "要添加";
     btn_Cancel_Click(sender, e);
 }
 /// <summary>
 /// 添加电影
 /// </summary>
 /// <param name="fmc"></param>
 /// <returns></returns>
 public int AddFilm(FilmMsgCommon fmc)
 {
     if (IsReapt(fmc.FilmId))
     {
         return 0;
     }
     string sql = " insert into FilmsMsg(FilmId,FilmName,FilmTimes,Director,Protagonists," +
         "FilmType,Producers,Country,FilmState,ScheduleTime,Deadline) " +
         " values(@FilmId,@FilmName,@FilmTimes,@Director,@Protagonists," +
         "@FilmType,@Producers,@Country,@FilmState,@ScheduleTime,@Deadline) ";
     SqlParameter[] paras ={
                              new SqlParameter("@FilmId",SqlDbType.Int,4),
                              new SqlParameter("@FilmName",SqlDbType.VarChar,50),
                              new SqlParameter("@FilmTimes",SqlDbType.VarChar,50),
                              new SqlParameter("@Director",SqlDbType.VarChar,50),
                              new SqlParameter("@Protagonists",SqlDbType.VarChar,50),
                              new SqlParameter("@FilmType",SqlDbType.VarChar,50),
                              new SqlParameter("@Producers",SqlDbType.VarChar,50),
                              new SqlParameter("@Country",SqlDbType.VarChar,50),
                              new SqlParameter("@FilmState",SqlDbType.Int,4),
                              new SqlParameter("@ScheduleTime",SqlDbType.Int,4),
                              new SqlParameter("@Deadline",SqlDbType.Date)
                          };
     paras[0].Value = fmc.FilmId;
     paras[1].Value = fmc.FilmName;
     paras[2].Value = fmc.FilmTimes;
     paras[3].Value = fmc.Director;
     paras[4].Value = fmc.Protagonists;
     paras[5].Value = fmc.FilmType;
     paras[6].Value = fmc.Producers;
     paras[7].Value = fmc.Country;
     paras[8].Value = fmc.FilmState;
     paras[9].Value = fmc.ScheduleTime;
     paras[10].Value = fmc.Deadline;
     return SQLHelper.ExecuteNonQuery(sql, paras);
 }
        /// <summary>
        /// 将控件的值赋给数据库模型
        /// </summary>
        /// <param name="fmc"></param>
        private void ControlToModel(FilmMsgCommon fmc)
        {
            fmc.FilmId = Convert.ToInt32(txt_FilmId.Text);
            fmc.FilmName = txt_FilmName.Text;
            fmc.FilmTimes = txt_FilmTimes.Text;
            fmc.Director = txt_Director.Text;
            fmc.Protagonists = txt_Protagonists.Text;
            fmc.FilmType = txt_FilmType.Text;
            fmc.Producers = txt_Producers.Text;
            fmc.Country = txt_Country.Text;

            //fmc.Deadline = dtp_Deadline.Value;
            string deadline = Convert.ToString(dtp_Deadline.Value);
            //-*-*--*--*-*-*-*-*-*-*-*--*-*-*-*-*-**
            //日期转换问题
            fmc.Deadline = DateFormat.GetRightDateFormat(deadline);
        }
 /// <summary>
 /// 修改电影
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_Modify_Click(object sender, EventArgs e)
 {
     if (btn_Modify.Text.Contains("要"))
     {
         btn_Cancel.Visible = true;
         btn_Add.Enabled = false;
         btn_Del.Enabled = false;
         btn_DownLine.Enabled = false;
         lbl_ImportExport.Enabled = false;
         txt_Country.Enabled = true;
         txt_Director.Enabled = true;
         txt_FilmId.Enabled = true;
         txt_FilmName.Enabled = true;
         txt_FilmTimes.Enabled = true;
         txt_FilmType.Enabled = true;
         txt_Producers.Enabled = true;
         txt_Protagonists.Enabled = true;
         btn_Modify.Text = "保存修改";
         return;
     }
     FilmMsgCommon fmc = new FilmMsgCommon();
     int oldFilmId = 0;
     try
     {
         oldFilmId = Convert.ToInt32(lbl_OldFilmId.Text);
     }
     catch
     {
         MessageBox.Show("请选择影片");
         return;
     }
     //将控件的值赋给数据库模型
     ControlToModel(fmc);
     fmc.FilmState = (int)dgv_FilmSourceM.SelectedRows[0].Cells["FilmState"].Value;
     fmc.ScheduleTime = (int)dgv_FilmSourceM.SelectedRows[0].Cells["ScheduleTime"].Value;
     if (filmMsg.ModifyFilm(oldFilmId, fmc))
     {
         GetFilmsMsg();
         MessageBox.Show("修改成功");
     }
     else
     {
         MessageBox.Show("修改失败");
     }
     btn_Modify.Text = "要修改";
     btn_Cancel.Visible = false;
     btn_Cancel_Click(sender, e);
 }
        /// <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>
 /// <param name="fmc"></param>
 /// <returns></returns>
 public bool ModifyFilm(int oldfilmId, FilmMsgCommon fmc)
 {
     fmc.Deadline = DateFormat.GetRightDateFormat(fmc.Deadline);
     if (filmMsg.ModifyFilm(oldfilmId, fmc) > 0)
     {
         return true;
     }
     return false;
 }
        /// <summary>
        ///获取影片信息
        /// </summary>
        /// <param name="fileName"></param>
        public FilmMsgCommon GetFilmMsg(string filmName)
        {
            SqlDataReader sdr = filmMsg.GetFilmMsg(filmName);
            FilmMsgCommon fmc = new FilmMsgCommon();
            if (sdr.HasRows)
            {
                while (sdr.Read())
                {
                    fmc.FilmId = Convert.ToInt32(sdr[0]);
                    fmc.FilmName = sdr.GetString(1);
                    fmc.Director = sdr.GetString(2);
                    fmc.FilmType = sdr.GetString(3);
                    fmc.Producers = sdr.GetString(4);
                    fmc.Country = sdr.GetString(5);
                    fmc.FilmTimes = sdr.GetString(6);
                    fmc.Protagonists = sdr.GetString(7);
                    fmc.FilmState = sdr.GetInt32(8);

                }
            }
            return fmc;
        }
 /// <summary>
 /// 修改电影信息
 /// </summary>
 /// <param name="fmc"></param>
 /// <returns></returns>
 public int ModifyFilm(int oldfilmId, FilmMsgCommon fmc)
 {
     if (oldfilmId != fmc.FilmId)
     {
         if (IsReapt(fmc.FilmId))
         {
             return 0;
         }
     }
     string sql = " update FilmsMsg " +
         " set FilmId=@FilmId,FilmName=@FilmName,FilmTimes=@FilmTimes," +
         " Director=@Director,Protagonists=@Protagonists," +
         " FilmType=@FilmType,Producers=@Producers," +
         " Country=@Country,Deadline=@Deadline " +
         " where FilmId=@oldfilmId ";
     SqlParameter[] paras ={
                              new SqlParameter("@FilmId",SqlDbType.Int,4),
                              new SqlParameter("@FilmName",SqlDbType.VarChar,50),
                              new SqlParameter("@FilmTimes",SqlDbType.VarChar,50),
                              new SqlParameter("@Director",SqlDbType.VarChar,50),
                              new SqlParameter("@Protagonists",SqlDbType.VarChar,50),
                              new SqlParameter("@FilmType",SqlDbType.VarChar,50),
                              new SqlParameter("@Producers",SqlDbType.VarChar,50),
                              new SqlParameter("@Country",SqlDbType.VarChar,50),
                              new SqlParameter("@Deadline",SqlDbType.Date),
                              new SqlParameter("@oldfilmId",SqlDbType.Int,4)
                          };
     paras[0].Value = fmc.FilmId;
     paras[1].Value = fmc.FilmName;
     paras[2].Value = fmc.FilmTimes;
     paras[3].Value = fmc.Director;
     paras[4].Value = fmc.Protagonists;
     paras[5].Value = fmc.FilmType;
     paras[6].Value = fmc.Producers;
     paras[7].Value = fmc.Country;
     paras[8].Value = fmc.Deadline;
     paras[9].Value = oldfilmId;
     return SQLHelper.ExecuteNonQuery(sql, paras);
 }