示例#1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            string sql;

            if (txtMaPhong.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã phòng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaPhong.Focus();
                return;
            }
            if (txtTenPhong.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên phòng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenPhong.Focus();
                return;
            }

            sql = "SELECT MaPhong FROM tblPhong WHERE MaPhong=N'" + txtMaPhong.Text.Trim() + "'";
            DataTable tblPhong = ThucThiSQL.Docbang(sql);

            if (tblPhong.Rows.Count > 0)
            {
                MessageBox.Show("Mã phòng này đã có, bạn phải nhập mã khác", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMaPhong.Focus();
                txtMaPhong.Text = "";
                return;
            }

            sql = "INSERT INTO tblPhong(MaPhong,TenPhong,Dongia) VALUES(N'" +
                  txtMaPhong.Text.Trim() + "',N'" + txtTenPhong.Text.Trim() + "'," +
                  txtDonGia.Text.Trim() + ")";
            ThucThiSQL.RunSQL(sql);
            this.Close();
        }
示例#2
0
        private void HienThi_Luoi()
        {
            string sql;

            sql      = "SELECT MaPhong,TenPhong, DonGia FROM tblPhong";
            tblPhong = ThucThiSQL.Docbang(sql);
            DataGridView.DataSource            = tblPhong;
            DataGridView.Columns[0].HeaderText = "Mã Phong";
            DataGridView.Columns[1].HeaderText = "Tên Phong";
            DataGridView.Columns[2].HeaderText = "Don Gia";
            DataGridView.Columns[0].Width      = 100;
            DataGridView.Columns[1].Width      = 300;
            DataGridView.Columns[2].Width      = 100;
            // Không cho phép thêm mới dữ liệu trực tiếp trên lưới
            DataGridView.AllowUserToAddRows = false;
            // Không cho phép sửa dữ liệu trực tiếp trên lưới
            DataGridView.EditMode = DataGridViewEditMode.EditProgrammatically;
            tblPhong.Dispose();
        }