private void roomDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            bool blank = false;

            if (roomDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString() == "")
            {
                blank = true;
            }
            if (roomDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString() == "")
            {
                blank = true;
            }
            if (roomDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString() == "")
            {
                blank = true;
            }
            if (roomDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString() == "")
            {
                blank = true;
            }

            if (blank)
            {
                loadRoomsInfo();
                return;
            }

            string roomNo   = roomDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString();
            int    price    = Convert.ToInt32(roomDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString());
            string roomType = roomDataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();
            int    staffId  = Convert.ToInt32(roomDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString());

            DataSet  ds = new DataSet();
            roomDAO  rD = new roomDAO();
            staffDAO sD = new staffDAO();

            ds = sD.getStaffs();
            bool flag = false;

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                int sI = Convert.ToInt32(row["staffId"].ToString());
                if (staffId == sI)
                {
                    flag = true;
                    break;
                }
            }

            if (flag == false)
            {
                loadRoomsInfo();
                return;
            }

            r = new roomDTO(roomNo, price, roomType, staffId);
            rD.updateRoom(r);
            loadRoomsInfo();
        }
        private void roomDataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            string roomNo   = roomDataGridView.Rows[e.Row.Index].Cells[0].Value.ToString();
            int    price    = Convert.ToInt32(roomDataGridView.Rows[e.Row.Index].Cells[1].Value.ToString());
            string roomType = roomDataGridView.Rows[e.Row.Index].Cells[2].Value.ToString();
            int    staffId  = Convert.ToInt32(roomDataGridView.Rows[e.Row.Index].Cells[3].Value.ToString());

            r = new roomDTO(roomNo, price, roomType, staffId);
        }
        public void deleteRoom(roomDTO r)
        {
            s.sqlConnection.Open();
            string query = "delete from rooms where roomNo = '" + r.RoomNo + "'";

            s.sqlCommand = new SqlCommand(query, s.sqlConnection);
            s.sqlCommand.ExecuteNonQuery();
            s.sqlConnection.Close();
        }
        public void createRoom(roomDTO r)
        {
            s.sqlConnection.Open();
            string query = "insert into rooms values('" + r.RoomNo + "','"
                           + r.Price + "','"
                           + r.RoomType + "','"
                           + r.StaffId + "')";

            s.sqlCommand = new SqlCommand(query, s.sqlConnection);
            s.sqlCommand.ExecuteNonQuery();
            s.sqlConnection.Close();
        }
        public void updateRoom(roomDTO r)
        {
            s.sqlConnection.Open();
            string query = "update rooms set price = '"
                           + r.Price + "', roomType = '"
                           + r.RoomType + "', staffId = '"
                           + r.StaffId + "' where roomNo = '"
                           + r.RoomNo + "' ";

            s.sqlCommand = new SqlCommand(query, s.sqlConnection);
            s.sqlCommand.ExecuteNonQuery();
            s.sqlConnection.Close();
        }
        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (roomDataGridView.SelectedRows.Count == 0)
            {
                MessageBox.Show("Select a row from table");
                return;
            }
            int    idx      = roomDataGridView.SelectedRows[0].Index;
            string roomNo   = roomDataGridView.Rows[idx].Cells[0].Value.ToString();
            int    price    = Convert.ToInt32(roomDataGridView.Rows[idx].Cells[1].Value.ToString());
            string roomType = roomDataGridView.Rows[idx].Cells[2].Value.ToString();
            int    staffId  = Convert.ToInt32(roomDataGridView.Rows[idx].Cells[3].Value.ToString());

            r = new roomDTO(roomNo, price, roomType, staffId);
            rD.deleteRoom(r);
            loadRoomsInfo();
        }
예제 #7
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (roomNoBox.Text == "" || priceBox.Text == "" || roomTypeBox.Text == "" || staffComboBox.Items.Count == 0)
            {
                MessageBox.Show("Please give all information");
                return;
            }


            string roomNo   = roomNoBox.Text;
            int    price    = Convert.ToInt32(priceBox.Text);
            string roomType = roomTypeBox.Text;
            string s        = staffComboBox.SelectedItem.ToString();

            string[] values  = s.Split(',');
            int      staffId = Convert.ToInt32(values[0]);
            roomDTO  r       = new roomDTO(roomNo, price, roomType, staffId);
            roomDAO  rD      = new roomDAO();

            rD.createRoom(r);
            clearFields();
        }