private void btnLuu_Click(object sender, EventArgs e)
        {
            if (themmoi)
            {
                km = new KhuyenMai();
                try
                {
                    PutKhuyenMaiData(km);
                    kmDB.ThemKhuyenMai(km);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                KhuyenMai newKM = new KhuyenMai();
                newKM.MaKhuyenMai = km.MaKhuyenMai;
                try
                {
                    this.PutKhuyenMaiData(newKM);
                    kmDB.CapNhatKhuyenMai(newKM);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                }
            }
            DanhSachKhuyenMai();
            EmptyControl();
            this.EnabledControlNhap(false);
            this.EnabledControl(true);
        }
 public void ThemKhuyenMai(KhuyenMai khuyenmai)
 {
     string query = "";
     query = "Insert into KhuyenMai (ThongTinGiam, ThoiGianBatDau, ThoiGianKetThuc) " +
              "values ("+  khuyenmai.ThongTinGiam + ",'" + khuyenmai.ThoiGianBatDau + "','" + khuyenmai.ThoiGianKetThuc + "')" ;
     try
     {
         this.addRow(query);
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
 public void CapNhatKhuyenMai(KhuyenMai khuyenmai)
 {
     string query = "";
     query = "Update [KhuyenMai] " +
             "Set [KhuyenMai].ThongTinGiam = " + khuyenmai.ThongTinGiam + "," +
                 "[KhuyenMai].ThoiGianBatDau = '" + khuyenmai.ThoiGianBatDau + "'," +
                 "[KhuyenMai].ThoiGianKetThuc = '" + khuyenmai.ThoiGianKetThuc + "'" +
            " Where [KhuyenMai].MaKhuyenMai = " + khuyenmai.MaKhuyenMai ;
     try
     {
         this.editRow(query);
     }
     catch (SqlException ex)
     {
         throw ex;
     }
 }
        //thong tin
        public KhuyenMai ThongTinKhuyenMai(int maKhuyenMai)
        {
            KhuyenMai khuyenmai = new KhuyenMai();
            DataTable data = new DataTable();
            string query = "";
            if (maKhuyenMai >= 0)
            {
                query = @"select [KhuyenMai].*
                          from [KhuyenMai]
                          where [KhuyenMai].MaKhuyenMai = " + maKhuyenMai;
                try
                {
                    data = this.getRows(query);
                    if (data.Rows.Count>0)
                    {
                        DataRow row = data.Rows[0];
                        khuyenmai.MaKhuyenMai = (int)row[0];
                        khuyenmai.ThongTinGiam = (int)row[1];
                        khuyenmai.ThoiGianBatDau = (DateTime)row[2];
                        khuyenmai.ThoiGianKetThuc = (DateTime)row[3];

                        return khuyenmai;
                    }
                    else
                    {
                        return khuyenmai;
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
            }
            else
            {
                return khuyenmai;
            }
        }
 ///xoa 
 public void XoaKhuyenMai(KhuyenMai khuyenmai)
 {
     string query = "";
     if (khuyenmai.MaKhuyenMai > 0)
     {
         query = "Delete [KhuyenMai] "+
                 " where [KhuyenMai].MaKhuyenMai = " + khuyenmai.MaKhuyenMai;
         try
         {
             this.deleteRow(query);
         }
         catch (SqlException ex)
         {
             throw ex;
         }
     }
 }
        public KhuyenMai ThongTinKhuyenMai(DateTime ngay)
        {
            KhuyenMai khuyenmai = new KhuyenMai();
            DataTable data = new DataTable();
            string query = "";
            if (ngay != null)
            {
                query = "select [KhuyenMai].* " +
                        " from [KhuyenMai] " +
                        " where ([KhuyenMai].ThoiGianBatDau ='" + ngay.ToShortDateString() + "') " +
                        "or ([KhuyenMai].ThoiGianKetThuc ='" + ngay.ToShortDateString() + "') " +
                        "or ([KhuyenMai].ThoiGianBatDau <'" + ngay.ToShortDateString() + "'" +
                        " and [KhuyenMai].ThoiGianKetThuc >'" + ngay.ToShortDateString() + "')";
                try
                {
                    data = this.getRows(query);
                    if (data.Rows.Count > 0)
                    {
                        DataRow row = data.Rows[0];
                        khuyenmai.MaKhuyenMai = (int)row[0];
                        khuyenmai.ThongTinGiam = (int)row[1];
                        khuyenmai.ThoiGianBatDau = (DateTime)row[2];
                        khuyenmai.ThoiGianKetThuc = (DateTime)row[3];

                        return khuyenmai;
                    }
                    else
                    {
                        return khuyenmai;
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
            }
            else
            {
                return khuyenmai;
            }
        }
 private void PutKhuyenMaiData(KhuyenMai km)
 {
     km.ThongTinGiam = Convert.ToInt16(txtThongTinGiam.Text);
     km.ThoiGianBatDau = dtpNgayBatDau.Value;
     km.ThoiGianKetThuc = dtpNgayKetThuc.Value;
 }
 private void HienThiKhuyenMai(KhuyenMai km)
 {
     if (km!=null)
     {
         txtThongTinGiam.Text = km.ThongTinGiam.ToString();
         dtpNgayBatDau.Text = km.ThoiGianBatDau.ToString();
         dtpNgayKetThuc.Text = km.ThoiGianKetThuc.ToString();
     }
     else
     {
         MessageBox.Show("Ko co KhuyenMai");
     }
 }
 private void grvKhuyenMai_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     int i = e.RowIndex;
     DataGridViewSelectedRowCollection rows = grvKhuyenMai.SelectedRows;
     foreach (DataGridViewRow row in rows)
     {
         DataRow myRow = (row.DataBoundItem as DataRowView).Row;
         int maKhuyenMai = myRow.Field<int>("MaKhuyenMai");
         km = kmDB.ThongTinKhuyenMai(maKhuyenMai);
         HienThiKhuyenMai(km);
     }
 }
 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;
 }