Exemple #1
0
        public void DoDuLieuVaoCacTruong(Phong ph)
        {
            txtMaPhong.Text = ph.MaPhong;
            int soLuongSV = int.Parse(txtSoLuongSV.Text);

            ph.SoLuongSV           = int.Parse(txtSoLuongSV.Text);
            txtTinhTrangPhong.Text = ph.TinhTrangPhong;
        }
 protected void gvPhong_SelectedIndexChanged(object sender, EventArgs e)
 {
     string mp = gvPhong.SelectedRow.Cells[0].Text;
     PhongDAO phDAO = new PhongDAO();
     Phong ph = phDAO.LayPhongTheoMa(mp);
     if (ph != null)
     {
         DoDuLieuVaoCacTruong(ph);
     }
 }
        private Phong LayDuLieuTuForm()
        {
            string maPhong = txtMaPhong.Text;
            string tinhTrangPhong = txtTinhTrangPhong.Text;
            int soLuongSV = int.Parse(txtSoLuongSV.Text);

            Phong ph = new Phong
            {
                MaPhong = maPhong,
                TinhTrangPhong = tinhTrangPhong,
                SoLuongSV = soLuongSV,
            };
            return ph;
        }
Exemple #4
0
 public bool Them(Phong ph)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         string sql = @"INSERT INTO PHONG(maPhong, soLuongSV,tinhTrangPhong) VALUES(@maphong, @soluong, @tinhtrangphong)";
         {
             SqlCommand command = new SqlCommand(sql, connection);
             command.Parameters.AddWithValue("@maphong", ph.MaPhong);
             command.Parameters.AddWithValue("@soluong", ph.SoLuongSV);
             command.Parameters.AddWithValue("@tinhtrangphong", ph.TinhTrangPhong);
             connection.Open();
             int result = command.ExecuteNonQuery();
             return(result >= 1);
         }
     }
 }
        protected void btnSua_Click(object sender, EventArgs e)
        {
            string maphong = txtMaPhong.Text;
            Phong ph = LayDuLieuTuForm();
            PhongDAO phDAO = new PhongDAO();
            bool result = phDAO.ChinhSua(ph);
            if (result)
            {

                lblThongBao.Text = "Cập nhật thành công cho Mã Phòng: " + maphong;
                LayPhongVaoGV();
            }
            else
            {
                lblThongBao.Text = "Cập nhật không thành công, vui lòng kiểm tra lại";
            }
        }
Exemple #6
0
 public bool ChinhSua(Phong ph)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         string     sql     = @"UPDATE PHONG SET soLuongSV= @soluong, tinhTrangPhong =@tinhtrangphong WHERE maPhong = @maphong";
         SqlCommand command = new SqlCommand(sql, connection);
         command.Parameters.AddWithValue("@maphong", ph.MaPhong);
         command.Parameters.AddWithValue("@soluong", ph.SoLuongSV);
         command.Parameters.AddWithValue("@tinhtrangphong", ph.TinhTrangPhong);
         connection.Open();
         int result = command.ExecuteNonQuery();
         if (result >= 1)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #7
0
 public Phong LayPhongTheoMa(string mp)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         string     sql = @"SELECT * FROM PHONG WHERE MaPhong = @maphong";
         SqlCommand cmd = new SqlCommand(sql, connection);
         cmd.Parameters.AddWithValue("@maphong", mp);
         connection.Open();
         SqlDataReader reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             Phong ph = new Phong
             {
                 MaPhong = reader["MaPhong"].ToString(),
             };
             return(ph);
         }
     }
     return(null);
 }