public HoatDongInfo ListViewItemToInfo(ListViewItem item)
        {
            HoatDongInfo hd = new HoatDongInfo();

            hd.MaHoatDong  = Convert.ToInt32(item.Text);
            hd.TenHoatDong = item.SubItems[1].Text;
            return(hd);
        }
        public HoatDongInfo ControlToInfo(TextBox txtMa, TextBox txtTen)
        {
            HoatDongInfo hd = new HoatDongInfo();

            hd.MaHoatDong  = Convert.ToInt32(txtMa.Text);
            hd.TenHoatDong = txtTen.Text;
            return(hd);
        }
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có muốn xóa không?", "Hoạt Động", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         if (ctrl.KiemTra(txtMa, txtTen))
         {
             HoatDongInfo hoatdong = ctrl.ControlToInfo(txtMa, txtTen);
             ctrl.Xoa(hoatdong);
             ctrl.LayLenListView(listHoatDong);
         }
     }
 }
        public ListViewItem DataRowToListViewItem(DataRow row)
        {
            ListViewItem item = new ListViewItem();

            item.Text = row["MAHOATDONG"].ToString();
            item.SubItems.Add(row["TENHOATDONG"].ToString());

            HoatDongInfo info = ListViewItemToInfo(item);

            item.Tag = info;
            return(item);
        }
예제 #5
0
        public bool Xoa(HoatDongInfo hoatdong)
        {
            SqlCommand com = new SqlCommand("Delete HOATDONG where MAHOATDONG=@ma");

            com.Parameters.Add("@ma", SqlDbType.Int).Value = hoatdong.MaHoatDong;
            try
            {
                ser.Load(com);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
예제 #6
0
        public bool Sua(HoatDongInfo hoatdong)
        {
            SqlCommand com = new SqlCommand("Update HOATDONG set TENHOATDONG=@ten where MAHOATDONG=@ma");

            com.Parameters.Add("@ma", SqlDbType.Int).Value           = hoatdong.MaHoatDong;
            com.Parameters.Add("@ten", SqlDbType.NVarChar, 30).Value = hoatdong.TenHoatDong;
            try
            {
                ser.Load(com);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
예제 #7
0
        public bool Them(HoatDongInfo hoatdong)
        {
            SqlCommand com = new SqlCommand("Insert into HOATDONG(MAHOATDONG,TENHOATDONG) values(@ma,@ten)");

            com.Parameters.Add("@ma", SqlDbType.Int).Value           = hoatdong.MaHoatDong;
            com.Parameters.Add("@ten", SqlDbType.NVarChar, 30).Value = hoatdong.TenHoatDong;
            try
            {
                ser.Load(com);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
        private void btnKetThuc_Click(object sender, EventArgs e)
        {
            if (listHoatDong.Items.Count > 0)
            {
                txtMa.Text  = listHoatDong.Items[listHoatDong.Items.Count - 1].SubItems[0].Text;
                txtTen.Text = listHoatDong.Items[listHoatDong.Items.Count - 1].SubItems[1].Text;

                HoatDong          = ctrl.ControlToInfo(txtMa, txtTen);
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                txtMa.Text  = "";
                txtTen.Text = "";

                HoatDong          = ctrl.ControlToInfo(txtMa, txtTen);
                this.DialogResult = DialogResult.Cancel;
            }
        }
        private void btnLuu_Sua_Click(object sender, EventArgs e)
        {
            if (ctrl.KiemTra(txtMa, txtTen))
            {
                HoatDongInfo phong = ctrl.ControlToInfo(txtMa, txtTen);
                ctrl.Sua(phong);
                ctrl.LayLenListView(listHoatDong);

                Updating            = false;
                btnSua.Text         = "Sửa";
                btnXoa.Enabled      = true;
                btnThem.Enabled     = true;
                btnKetThuc.Visible  = true;
                btnLuu_Them.Visible = false;
                btnLuu_Sua.Visible  = false;

                listHoatDong.Enabled = true;

                txtMa.Enabled  = false;
                txtTen.Enabled = false;
            }
        }
 public bool Sua(HoatDongInfo phong)
 {
     return(data.Sua(phong));
 }
 public bool Xoa(HoatDongInfo phong)
 {
     return(data.Xoa(phong));
 }
 public bool Them(HoatDongInfo phong)
 {
     return(data.Them(phong));
 }