Exemplo n.º 1
0
        /// <summary>
        /// Remove a object.
        /// </summary>
        /// <param name="object">The object to remove.</param>
        public void RemoveObject(object sender, EventArgs e)
        {
            HotelObject hotelObject = (HotelObject)sender;

            if (hotelObject is Person)
            {
                // Remove guest from the hotel.
                if (hotelObject is Guest)
                {
                    string item  = Guests.First(x => x.Value == hotelObject).Key;
                    Guest  guest = (Guest)hotelObject;

                    if (guest.Room != null)
                    {
                        if (guest.Room.State != RoomState.Emergency && guest.Room.State != RoomState.InCleaning)
                        {
                            guest.Room.State = RoomState.Dirty;
                        }
                        guest.Room = null;
                    }

                    //Remove the guest from a checkin/out queue where applicable.
                    if (guest.CurrentRoom is Lobby)
                    {
                        (guest.CurrentRoom as Lobby).RemoveFromQueues(guest);
                    }

                    Guests.Remove(item);
                }
                // Remove receptionist from hotel.
                else if (hotelObject is Receptionist)
                {
                    Lobby lobby = Rooms.Where(x => x is Lobby && (x as Lobby).Receptionist == hotelObject) as Lobby;
                    if (lobby != null)
                    {
                        lobby.Receptionist = null;
                    }
                    Staff.Remove(hotelObject as Person);
                }
                // Remove cleaner from the hotel.
                else if (hotelObject is Cleaner)
                {
                    Cleaner cleaner = (Cleaner)hotelObject;
                    Staff.Remove(cleaner);

                    // Spawn a ghost
                    CleanerGhost cGhost = new CleanerGhost(cleaner.CurrentRoom);
                    cGhost.RemoveObjectEvent += RemoveObject;
                    Staff.Add(cGhost);
                }
                else if (hotelObject is CleanerGhost)
                {
                    CleanerGhost cleanerGhost = (CleanerGhost)hotelObject;

                    // Spawn a new cleaner
                    Cleaner cleaner = new Cleaner(cleanerGhost.CurrentRoom);
                    cleaner.RemoveObjectEvent += RemoveObject;
                    Staff.Add(cleaner);
                    // Make it walk indoors
                    cleaner.FindAndTargetRoom(x => (x is Lobby && (x as Lobby).Receptionist != null));

                    Staff.Remove(cleanerGhost);
                }

                hotelObject.RemoveObjectEvent -= RemoveObject;
            }
        }
Exemplo n.º 2
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            string c = " ";

            sql.Open();
            string        sql_request = "SELECT Name FROM Room WHERE Name ='" + Nametb.Text + "' ";
            SQLiteCommand add         = new SQLiteCommand(sql_request, sql);

            add.ExecuteNonQuery();
            SQLiteDataReader reader = add.ExecuteReader();

            while (reader.Read())
            {
                c = reader[0] + "";
            }
            sql.Close();

            if (Nametb.Text.Trim() == c)
            {
                MessageBox.Show("Номер с таким именем уже существует!");
            }
            else
            {
                var stop_array = new[] { ".", ",", ";", ":", "?", "!", "<", ">", "-", "=" };
                if ((Nametb.Text.Equals("")) || (Descriptioncmb.Text.Equals("")) || (PricemaskedTextBox.Text.Equals("")) || (Typecmbb.Text.Equals("")))
                {
                    MessageBox.Show("Одно или несколько полей не заполнены");
                }
                else
                {
                    var flag = true;
                    if (Nametb.Text != "")
                    {
                        foreach (string t in stop_array)
                        {
                            if (Nametb.Text.Contains(t))
                            {
                                flag = false;
                                break;
                            }
                        }
                        if (flag == false)
                        {
                            MessageBox.Show("Название номера введено не верно!");
                        }
                        if (flag == true)
                        {
                            sql.Open();
                            string        check_name = @"UPDATE Room SET Name = '" + Convert.ToString(Nametb.Text) + "', Description = '" + Convert.ToString(Descriptioncmb.Text) + "', Price = '" + Convert.ToDouble(PricemaskedTextBox.Text) + "', TypeName = '" + Convert.ToString(Typecmbb.Text) + "' WHERE Name LIKE '" + Current_Name + "'";
                            SQLiteCommand check      = new SQLiteCommand(check_name, sql);
                            check.ExecuteNonQuery();
                            sql.Close();
                            if (MessageBox.Show("Изменения были успешно сохранены!") == DialogResult.OK)
                            {
                                this.Close();
                                Rooms room = new Rooms();
                                room.Show();
                            }
                            sql.Close();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            string c = " ";

            sql.Open();
            string        sql_request = "SELECT Name FROM Room WHERE Name ='" + NametextBox.Text + "' ";
            SQLiteCommand add         = new SQLiteCommand(sql_request, sql);

            add.ExecuteNonQuery();
            SQLiteDataReader reader = add.ExecuteReader();

            while (reader.Read())
            {
                c = reader[0] + "";
            }
            sql.Close();

            if (NametextBox.Text.Trim() == c)
            {
                MessageBox.Show("Номер с таким именем уже существует!");
            }
            else
            {
                var stop_array = new[] { ".", ",", ";", ":", "?", "!", "<", ">", "-", "=" };
                if ((NametextBox.Text.Equals("")) || (Descriptioncmb.Text.Equals("")) || (PricemaskedTextBox.Text.Equals("")) || (Typecmbb.Text.Equals("")))
                {
                    MessageBox.Show("Одно или несколько полей не заполнены");
                }
                else
                {
                    var flag = true;
                    if (NametextBox.Text != "")
                    {
                        foreach (string t in stop_array)
                        {
                            if (NametextBox.Text.Contains(t))
                            {
                                flag = false;
                                break;
                            }
                        }
                        if (flag == false)
                        {
                            MessageBox.Show("Название номера введено не верно!");
                        }
                        if (flag == true)
                        {
                            sql.Open();
                            SQLiteCommand sqlcon = new SQLiteCommand(sql);
                            sqlcon.CommandText = @"insert into room(roomID, Name, Description, Status, Price, TypeName) values(null, '" + Convert.ToString(NametextBox.Text) + "', '" + Convert.ToString(Descriptioncmb.Text) + "', 'свободен','" + Convert.ToDouble(PricemaskedTextBox.Text) + "', '" + Convert.ToString(Typecmbb.Text) + "');";
                            SQLiteDataReader srd = sqlcon.ExecuteReader();
                            MessageBox.Show("Номер добавлен");
                            sql.Close();
                            Close();
                            Rooms r = new Rooms();
                            r.Show();
                        }
                    }
                }
            }
        }