private void btnBanVe_Click(object sender, EventArgs e)
        {
            int i = 0;
            string dayghe = "";
            //chinh sua lai VePhim theo SuatChieu va SoGhe
            DataGridViewSelectedRowCollection rows = grvVePhim.SelectedRows;
            foreach (DataGridViewRow row in rows)
            {
                DataRow myRow = (row.DataBoundItem as DataRowView).Row;
                int pMaVe = Convert.ToInt32(myRow.Field<string>("MaVe"));
                int pMaSuatChieu = Convert.ToInt32(myRow.Field<string>("MaSuatChieu"));
                string pSoGhe = myRow.Field<string>("SoGhe");
                vephim = vephimDB.TimVePhim(pMaVe);
                VePhim newVephim = new VePhim();
                newVephim.MaVe = vephim.MaVe;
                newVephim.MaSuatChieu = vephim.MaSuatChieu;
                newVephim.SoGhe = vephim.SoGhe;
                PutVePhimData(newVephim);
                vephimDB.CapNhatVePhim(vephim, newVephim);

                i++;
                dayghe += pSoGhe + " ";
            }
            MessageBox.Show("Da ban " + i + " ve phim!");
            //hien thi Danh sach VePhim cua DatCho
            DanhSachVePhim(dayghe);
            //cap nhat trang thai Dat Cho
            cboTrangThaiDatCho.SelectedIndex = 2;
            //hien thi button Luu Dat cho
            btnLuu.Enabled = true;
            //btnKhong.Visible = false;
        }
 //dem tong so VePhim theo SuatChieu
 public int SoVePhim(int maSuatChieu)
 {
     VePhim vephim = new VePhim();
     DataTable data = new DataTable();
     int soLuongVe = 0;
     string query = "";
     if (maSuatChieu > 0 )
     {
         query = "select count([VePhim].MaVe) " +
                 "from [VePhim] " +
                 " where [VePhim].MaSuatChieu = " + maSuatChieu;
         try
         {
             if (getValue(query)!=null)
             {
                 soLuongVe = (int)this.getValue(query);
             }
             else
             {
                 soLuongVe = 0;
             }
         }
         catch (OracleException ex)
         {
             throw ex;
         }
     }
     else
     {
         soLuongVe = 0;
     }
     return soLuongVe;
 }
        public void CapNhatVePhim(VePhim oldVephim, VePhim newVephim)
        {
            int oldtrangthaimua;
            int newtrangthaimua;
            if (oldVephim.TrangThaiMua == true)
            {
                oldtrangthaimua = 1;
            }
            else
            {
                oldtrangthaimua = 0;
            }

            if (newVephim.TrangThaiMua == true)
            {
                newtrangthaimua = 1;
            }
            else
            {
                newtrangthaimua = 0;
            }
            string query = "";
            query = "Update [VePhim] " +
                     "Set [VePhim].NgayInVe = '" + newVephim.NgayInVe.ToShortDateString() + "', " +
                         "[VePhim].MaSuatChieu = " + newVephim.MaSuatChieu + ", " +
                         "[VePhim].SoGhe = '" + newVephim.SoGhe + "', " +
                         "[VePhim].GiaVe = " + newVephim.GiaVe + ", " +
                         "[VePhim].MaKhuyenMai = " + newVephim.MaKhuyenMai + ", " +
                         "[VePhim].GiaVeUuDai = " + newVephim.GiaVeUuDai + ", " +
                         "[VePhim].TrangThaiMua = " + newtrangthaimua +
                     " where [VePhim].MaVe = " + oldVephim.MaVe +
                     " and [VePhim].NgayInVe = '" + oldVephim.NgayInVe.ToShortDateString() + "'" +
                     " and [VePhim].MaSuatChieu = " + oldVephim.MaSuatChieu +
                     " and [VePhim].SoGhe = '" + oldVephim.SoGhe + "'" +
                     " and [VePhim].GiaVe = " + oldVephim.GiaVe +
                     " and [VePhim].MaKhuyenMai = " + oldVephim.MaKhuyenMai +
                     " and [VePhim].GiaVeUuDai = " + oldVephim.GiaVeUuDai +
                     " and [VePhim].TrangThaiMua = " + oldtrangthaimua;

            try
            {
                this.editRow(query);
            }
            catch (         OracleException  ex)
            {
                throw ex;
            }
        }
        //tim VePhim theo SuatChieu va SoGhe
        public VePhim TimVePhim(int maSuatChieu, string soGhe)
        {
            VePhim vephim = new VePhim();
            DataTable data = new DataTable();
            string query = "";
            if (maSuatChieu > 0 && soGhe!="")
            {
                query = "select [VePhim].* " +
                        "from [VePhim] " +
                        " where [VePhim].MaSuatChieu = " + maSuatChieu +
                        " and [VePhim].SoGhe = '" + soGhe + "'";
                try
                {
                    data = this.getRows(query);
                    if (data.Rows.Count > 0)
                    {
                        DataRow row = data.Rows[0];
                        vephim.MaVe = (int)row[0];
                        vephim.NgayInVe = (DateTime)row[1];
                        vephim.MaSuatChieu = (int)row[2];
                        vephim.SoGhe = row[3].ToString();
                        vephim.GiaVe = (decimal)row[4];
                        vephim.GiaVeUuDai = (decimal)row[5];
                        vephim.MaKhuyenMai = (int)row[6];
                        vephim.TrangThaiMua = (bool)row[7];

                        return vephim;
                    }
                    else
                    {
                        vephim=null;
                    }
                }
                catch (OracleException ex)
                {
                    throw ex;
                }
            }
            else
            {
                vephim=null;
            }
            return vephim;
        }
        //tim VePhim theo MaVe
        public VePhim TimVePhim(int maVe)
        {
            VePhim vephim = new VePhim();
            DataTable data = new DataTable();
            string query = "";
            if (maVe > 0)
            {
                query = @"select [VePhim].*
                          from [VePhim]
                          where [VePhim].MaVe = " + maVe;
                try
                {
                    data = this.getRows(query);
                    if (data.Rows.Count > 0)
                    {
                        DataRow row = data.Rows[0];
                        vephim.MaVe = (int)row[0];
                        if (row[1] != null)
                        {
                            vephim.NgayInVe = (DateTime)row[1];
                        }
                        else
                        {
                            vephim.NgayInVe = DateTime.MinValue;
                        }
                        vephim.MaSuatChieu = (int)row[2];
                        vephim.SoGhe = row[3].ToString();
                        if (row[4]!=null)
                        {
                            vephim.GiaVe = (decimal)row[4];
                        }
                        else
                        {
                            vephim.GiaVe = 0;
                        }
                        if (row[5]!=null)
                        {
                            vephim.GiaVeUuDai = (decimal)row[5];
                        }
                        else
                        {
                            vephim.GiaVeUuDai = 0;
                        }
                        if (row[6]!=null)
                        {
                            vephim.MaKhuyenMai = (int)row[6];
                        }
                        else
                        {
                            vephim.MaKhuyenMai = 0;
                        }
                        vephim.TrangThaiMua = (bool)row[7];

                        return vephim;
                    }
                    else
                    {
                        return vephim;
                    }
                }
                catch (OracleException  ex)
                {
                    throw ex;
                }
            }
            else
            {
                return vephim;
            }
        }
        public void ThemVePhim(VePhim vephim)
        {
            int trangthaimua;
            if (vephim.TrangThaiMua == true)
            {
                trangthaimua = 1;
            }
            else
            {
                trangthaimua = 0;
            }
            string query = "";
            query = "Insert into [VePhim] (NgayInVe, MaSuatChieu, SoGhe, GiaVe, GiaVeUuDai, MaKhuyenMai, TrangThaiMua) " +
                     "values ('" + vephim.NgayInVe.ToShortDateString() + "'," + vephim.MaSuatChieu + ",'" + vephim.SoGhe + "',"  +
                                   vephim.GiaVe + "," + vephim.GiaVeUuDai + "," + vephim.MaKhuyenMai + "," + trangthaimua + ")";

            //query = "Insert into [VePhim] (MaSuatChieu, SoGhe) " +
            //         "values (" + vephim.MaSuatChieu + ",'" + vephim.SoGhe + "')";
            try
            {
                this.addRow(query);
            }
            catch (         OracleException  ex)
            {
                throw ex;
            }
        }
 private void TaoVePhimTuDong(int pmaSuatChieu)
 {
     //tao Ve Phim theo SuatChieu
     //tao danh sach ten ghe voi 10 hang, 11 cot
     bool trangthaimua = false;
     vephim = new VePhim();
     List<string> listGhe = new List<string>();
     listGhe = DanhSachTenGhe(10, 11);
     try
     {
         int j = 0;
         for (int i = 0; i < listGhe.Count; i++)
         {
             vephim.NgayInVe = DateTime.Today;
             vephim.MaSuatChieu = pmaSuatChieu;
             vephim.SoGhe = listGhe[i];
             vephim.GiaVe = giaVe;
             vephim.GiaVeUuDai = 0;
             vephim.MaKhuyenMai = 1;
             vephim.TrangThaiMua = trangthaimua;
             vephimDB.ThemVePhim(vephim);
             j++;
         }
         MessageBox.Show("Da tao " + j + " ve phim cua suat chieu " + pmaSuatChieu);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void PutVePhimData(VePhim newVephim)
 {
     newVephim.NgayInVe = dtpNgayInVe.Value;
     newVephim.GiaVe = Convert.ToDecimal(txtGiaVe.Text);
     KhuyenMai khuyenmai = new KhuyenMai();
     khuyenmai = khuyenmaiDB.ThongTinKhuyenMai(dtpNgayInVe.Value);
     newVephim.MaKhuyenMai = khuyenmai.MaKhuyenMai;
     newVephim.GiaVeUuDai = Convert.ToDecimal(txtGiaVeUuDai.Text);
     newVephim.TrangThaiMua = true;
 }
        private void DanhSachVePhim(string cacsoghe)
        {
            DataTable dtVePhim = new DataTable();
            dtVePhim.Columns.Add("MaVe");
            dtVePhim.Columns.Add("MaSuatChieu");
            dtVePhim.Columns.Add("SoGhe");
            dtVePhim.Columns.Add("TrangThaiMua");

            //tim VePhim theo SuatChieu va SoGhe
            vephim = new VePhim();
            string[] dayGhe = Chuyen(cacsoghe);
            if (maSuatChieu > 0)
            {
                if (dayGhe != null)
                {
                    for (int i = 0; i < dayGhe.Length; i++)
                    {
                        string ghe = dayGhe[i];
                        vephim = vephimDB.TimVePhim(maSuatChieu, ghe);
                        if (vephim != null)
                        {
                            dtVePhim.Rows.Add(vephim.MaVe, vephim.MaSuatChieu, vephim.SoGhe, vephim.TrangThaiMua);
                            grvVePhim.DataSource = dtVePhim;
                        }
                        else
                        {
                            MessageBox.Show("SuatChieu chua tao VePhim tu dong!");
                        }

                    }
                }
                else
                {
                    MessageBox.Show("Chua nhap so ghe");
                }
            }
            else
            {
                MessageBox.Show("Chua chon SuatChieu!");
            }
        }