private void btn_Save_Room_Click(object sender, EventArgs e) { int status = 0; BLRoom blR = new BLRoom(); if (rbtn_Empty.Checked == true) { status = 0; } if (rbtn_Hired.Checked == true) { status = 1; } if (rbtn_Reserved.Checked == true) { status = 2; } if (SaveStatus == 1) { blR.CreateRoom(txt_Room_RoomTypeID.Text, txt_Room_OnFloor.Text, status); } else if (SaveStatus == 2) { blR.UpdateRoom(Convert.ToInt32(txt_Room_RoomID.Text), txt_Room_RoomTypeID.Text, txt_Room_OnFloor.Text, status); } SaveStatus = 0; dgv_Room.DataSource = blR.LoadRoom(); dgv_Room_CellClick(null, null); btn_Update_Room.Enabled = true; btn_Create_Room.Enabled = true; btn_Save_Room.Enabled = false; }
private void pbSave_Click(object sender, EventArgs e) { // Mở kết nối // Thêm dữ liệu if (Them) { if (this.txtRoomID.Text == "" || this.cmbRoomType.Text == "") { if (this.txtRoomID.Text == "") { MessageBox.Show("Please fill in Room ID !"); pbCancel_Click(sender, e); return; } else { MessageBox.Show("Please fill in RoomType !"); pbCancel_Click(sender, e); return; } } for (int i = 0; i < dgvRoom.Rows.Count; i++) { if (txtRoomID.Text == dgvRoom.Rows[i].Cells["RoomID"].Value.ToString().Trim()) { MessageBox.Show("Existed '" + txtRoomID.Text + "', please type another one !"); txtRoomID.ResetText(); txtArea.ResetText(); txtNote.ResetText(); txtPrice.ResetText(); txtRoomID.Focus(); pbCancel_Click(sender, e); return; } } try { // Thực hiện lệnh BLRoom blRoom = new BLRoom(); if (this.txtRoomID.Text != "" && this.cmbRoomType.Text != "") { float Price = 0; if (this.txtPrice.Text != "") { Price = float.Parse(this.txtPrice.Text); } blRoom.AddRoom(this.txtRoomID.Text, this.cmbRoomType.SelectedValue.ToString(), this.cbStatus.Checked.ToString(), this.txtNote.Text, this.txtArea.Text, Price, ref err); // Load lại dữ liệu trên DataGridView LoadData(); // Thông báo MessageBox.Show("Added successfully!"); } } catch (SqlException) { this.gbInfor.Text = "Information"; MessageBox.Show("Cannot add data !"); } } else { if (this.txtRoomID.Text == "" || this.cmbRoomType.Text == "") { if (this.txtRoomID.Text == "") { MessageBox.Show("Please fill in Room ID !"); pbCancel_Click(sender, e); return; } else { MessageBox.Show("Please fill in RoomType !"); pbCancel_Click(sender, e); return; } } // Thực hiện lệnh BLRoom blRoom = new BLRoom(); blRoom.UpdateRoom(this.txtRoomID.Text, this.cmbRoomType.SelectedValue.ToString(), this.cbStatus.Checked.ToString(), this.txtNote.Text, this.txtArea.Text, float.Parse(this.txtPrice.Text), ref err); // Thông báo MessageBox.Show("Edited successfully!"); // Load lại dữ liệu trên DataGridView LoadData(); } // Đóng kết nối }