public void HienThi(ListView list, ComboBox day, ComboBox trangthai)
        {
            PhongData phong = new PhongData();

            list.Items.Clear();
            DataTable table = phong.LayDSPhong();

            foreach (DataRow row in table.Rows)
            {
                PhongInfo    info = RowToInfo(row);
                ListViewItem item = new ListViewItem();
                item.Text = info.MaPhong;
                item.SubItems.Add(info.TenPhong);
                item.SubItems.Add(info.Day.TenDay);
                item.SubItems.Add(info.SoLuongToiDa.ToString());
                item.SubItems.Add(info.TrangThai.TenTrangThai);
                item.SubItems.Add((info.PhongNam == true?"Nam":"Nữ"));
                item.Tag = info;
                list.Items.Add(item);
            }

            //----------------
            DayCtrl dayctrl = new DayCtrl();

            dayctrl.LayDuLieuLenComboBox(day);
            TrangThaiPhongCtrl dayctrl1 = new TrangThaiPhongCtrl();

            dayctrl1.LayDuLieuLenComboBox(trangthai);
        }
        public PhongInfo RowToInfo(DataRow row)
        {
            PhongInfo phong = new PhongInfo();

            phong.MaPhong = row["MAPHG"].ToString();

            phong.TenPhong = row["TENPHG"].ToString();

            phong.SoLuongToiDa = Convert.ToInt32(row["SOLUONGTOIDA"].ToString());

            phong.PhongNam = Convert.ToBoolean(row["PhongNam"].ToString());

            DayInfo day = new DayInfo();

            day.MaDay  = row["MADAY"].ToString();
            day.TenDay = row["TENDAY"].ToString();

            phong.Day = day;
            TrangThaiPhongInfo trangthai = new TrangThaiPhongInfo();

            trangthai.MaTrangThai  = Convert.ToInt32(row["MATRANGTHAI"].ToString());
            trangthai.TenTrangThai = row["TENTRANGTHAI"].ToString();

            phong.TrangThai = trangthai;

            return(phong);
        }
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (ctrl.KiemTra(txtMa, txtTen, txtSoLuong, chkPhongNam, cmbDay, cmbTrangThai))
            {
                group.Enabled = false;

                listDSPhong.Enabled = true;

                btnThem.Enabled    = true;
                btnXoa.Enabled     = true;
                btnSua.Enabled     = true;
                btnCapNhat.Enabled = false;
                btnBoQua.Visible   = false;
                if (adding == true)
                {
                    PhongInfo phong = ctrl.ControlToInfo(txtMa, txtTen, txtSoLuong, chkPhongNam, cmbDay, cmbTrangThai);
                    if (ctrl.Them(phong))//Thêm thành công thì thêm một dòng trên LISTVIEW
                    {
                        listDSPhong.Items.Add(ctrl.InfoToItem(phong));
                    }
                }
                else if (updating == true)
                {
                    PhongInfo phong = ctrl.ControlToInfo(txtMa, txtTen, txtSoLuong, chkPhongNam, cmbDay, cmbTrangThai);
                    if (ctrl.Sua(phong))//Sửa thành công thì sửa một dòng trên LISTVIEW
                    {
                        ctrl.SuaListView(listDSPhong, phong);
                    }
                }
                // ctrl.HienThi(listDSPhong, cmbDay, cmbTrangThai);
            }
        }
 public void RowToControl(ListView list, TextBox ma, TextBox ten, TextBox Sl, CheckBoxX phgNam, ComboBox day, ComboBox trangthai)
 {
     if (list.SelectedItems.Count > 0)
     {
         PhongInfo phong = (PhongInfo)list.SelectedItems[0].Tag;
         ma.Text        = phong.MaPhong;
         ten.Text       = phong.TenPhong;
         Sl.Text        = phong.SoLuongToiDa.ToString();
         phgNam.Checked = phong.PhongNam;
         day.Text       = phong.Day.TenDay;
         trangthai.Text = phong.TrangThai.TenTrangThai;
     }
 }
        public ListViewItem InfoToItem(PhongInfo phong)
        {
            ListViewItem item = new ListViewItem();

            item.Text = phong.MaPhong;
            item.SubItems.Add(phong.TenPhong);
            item.SubItems.Add(phong.Day.TenDay);
            item.SubItems.Add(phong.SoLuongToiDa.ToString());
            item.SubItems.Add(phong.TrangThai.TenTrangThai);
            item.SubItems.Add((phong.PhongNam == true ? "Nam" : "Nữ"));
            item.Tag = phong;
            return(item);
        }
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có muốn xóa " + (listDSPhong.SelectedItems.Count > 1 ? listDSPhong.SelectedItems.Count.ToString() + " " : "") + "dòng này không?", "Phòng", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         IEnumerator list = listDSPhong.SelectedItems.GetEnumerator();
         while (list.MoveNext())
         {
             ListViewItem item  = (ListViewItem)list.Current;
             PhongInfo    phong = (PhongInfo)item.Tag;
             ctrl.Xoa(phong);
         }
     }
     ctrl.HienThi(listDSPhong, cmbDay, cmbTrangThai);
 }
        /// <summary>
        /// Sửa một dòng trên LISTVIEW có cùng Mã với phòng vừa sửa
        /// </summary>
        /// <param name="list">Listview cần sửa</param>
        /// <param name="phong">Phòng có khóa cần sửa</param>
        public void SuaListView(ListView list, PhongInfo phong)
        {
            ListViewItem itemPhong = InfoToItem(phong);

            for (int i = 0; i < list.Items.Count; i++)
            {
                if (list.Items[i].Text == itemPhong.Text)
                {
                    //Thay đổi nội dung từng ô một trên dòng cần sửa
                    for (int j = 1; j < list.Items[i].SubItems.Count; j++)
                    {
                        list.Items[i].SubItems[j] = itemPhong.SubItems[j];
                    }
                }
            }
        }
        public bool Xoa(PhongInfo phong)
        {
            SqlCommand command = new SqlCommand("Delete Phong where MAPHG = @maphg");

            command.Parameters.Add("@maphg", SqlDbType.VarChar, 4).Value = phong.MaPhong;

            try
            {
                ser.Load(command);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
Пример #9
0
        public DiemDanhInfo DataToInfo(DataGridViewRow r, DateTime ngay, bool cophep)
        {
            DiemDanhInfo dd = new DiemDanhInfo();

            dd.CoPhep   = cophep;
            dd.NgayVang = ngay;
            PhongInfo p = new PhongInfo();

            p.MaPhong = r.Cells["MAPHG"].Value.ToString();
            dd.Phong  = p;
            SinhVienInfo sv = new SinhVienInfo();

            sv.MaKTX    = r.Cells["MAKTX"].Value.ToString();
            sv.HoTen    = r.Cells["HOTEN"].Value.ToString();
            dd.SinhVien = sv;
            return(dd);
        }
        public bool Them(PhongInfo phong)
        {
            SqlCommand command = new SqlCommand("insert into Phong(MAPHG,TENPHG,MADAY,SOLUONGTOIDA,TRANGTHAI,PHONGNAM)"
                                                + "values(@maphg,@tenphg,@maday,@soluong,@trangthai,@phongnam)");

            command.Parameters.Add("@maphg", SqlDbType.VarChar, 4).Value    = phong.MaPhong;
            command.Parameters.Add("@tenphg", SqlDbType.NVarChar, 30).Value = phong.TenPhong;
            command.Parameters.Add("@maday", SqlDbType.VarChar, 4).Value    = phong.Day.MaDay;
            command.Parameters.Add("@soluong", SqlDbType.Int).Value         = phong.SoLuongToiDa;
            command.Parameters.Add("@trangthai", SqlDbType.Int).Value       = phong.TrangThai.MaTrangThai;
            command.Parameters.Add("@phongnam", SqlDbType.Bit).Value        = phong.PhongNam;
            try
            {
                ser.Load(command);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
        public bool Sua(PhongInfo phong)
        {
            SqlCommand command = new SqlCommand("Update Phong set TENPHG=@tenphg,"
                                                + "MADAY=@maday,SOLUONGTOIDA=@soluong,TRANGTHAI=@trangthai" +
                                                ",PHONGNAM=@phongnam where MAPHG=@maphg");

            command.Parameters.Add("@maphg", SqlDbType.VarChar, 4).Value    = phong.MaPhong;
            command.Parameters.Add("@tenphg", SqlDbType.NVarChar, 30).Value = phong.TenPhong;
            command.Parameters.Add("@maday", SqlDbType.VarChar, 4).Value    = phong.Day.MaDay;
            command.Parameters.Add("@soluong", SqlDbType.Int).Value         = phong.SoLuongToiDa;
            command.Parameters.Add("@trangthai", SqlDbType.Int).Value       = phong.TrangThai.MaTrangThai;
            command.Parameters.Add("@phongnam", SqlDbType.Bit).Value        = phong.PhongNam;
            try
            {
                ser.Load(command);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
        public PhongInfo ControlToInfo(TextBox ma, TextBox ten, TextBox Sl, CheckBoxX phgNam, ComboBox day, ComboBox trangthai)
        {
            PhongInfo phong = new PhongInfo();

            phong.MaPhong      = ma.Text;
            phong.TenPhong     = ten.Text;
            phong.SoLuongToiDa = Convert.ToInt32(Sl.Text);
            phong.PhongNam     = phgNam.Checked;

            DayInfo d = new DayInfo();

            d.MaDay   = day.SelectedValue.ToString();
            d.TenDay  = day.Text;
            phong.Day = d;

            TrangThaiPhongInfo th = new TrangThaiPhongInfo();

            th.MaTrangThai  = Convert.ToInt32(trangthai.SelectedValue.ToString());
            th.TenTrangThai = trangthai.Text;

            phong.TrangThai = th;

            return(phong);
        }
 private StackPanel Column(PhongInfo item)
 {
     StackPanel retBorder = new StackPanel();
     retBorder.Orientation = Orientation.Vertical;
     retBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
     retBorder.Cursor = Cursors.Hand;
     retBorder.Margin = new Thickness(20,10,0,15);
     retBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
     retBorder.VerticalAlignment = System.Windows.VerticalAlignment.Center;
     CheckBox cbx = new CheckBox();
     cbx.Name = item.PhongID.ToString();
     cbx.CommandParameter = item;
     TextBlock txtContent = new TextBlock();
     txtContent.FontSize = 14;
     txtContent.Text = item.PhongName;
     txtContent.VerticalAlignment = System.Windows.VerticalAlignment.Center;
     txtContent.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
     txtContent.FontWeight = FontWeights.Bold;
     StackPanel Row0 = new StackPanel();
     Row0.Orientation = Orientation.Horizontal;
     Row0.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
     Row0.Children.Add(cbx);
     Row0.Children.Add(txtContent);
     StackPanel Row1 = new StackPanel();
     Row1.Orientation = Orientation.Horizontal;
     Row1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
     HyperlinkButton cmdXem = new HyperlinkButton();
     cmdXem.Content = "[xem]";
     cmdXem.CommandParameter = item;
     cmdXem.Click += new RoutedEventHandler(cmdXem_Click);
     HyperlinkButton cmdSua = new HyperlinkButton();
     cmdSua.Content = "[sửa]";
     cmdSua.CommandParameter = item;
     cmdSua.Click += new RoutedEventHandler(cmdSua_Click);
     Row1.Children.Add(cmdXem);
     Row1.Children.Add(cmdSua);
     retBorder.Children.Add(Row0);
     retBorder.Children.Add(Row1);
     return retBorder;
 }
        public bool Sua(PhongInfo phong)
        {
            PhongData data = new PhongData();

            return(data.Sua(phong));
        }
        public bool Them(PhongInfo phong)
        {
            PhongData data = new PhongData();

            return(data.Them(phong));
        }