示例#1
0
        public MainForm()
        {
            hotel  = new Hotel();
            guests = new Guests(hotel);
            InitializeComponent();
            hotelBindingSource.DataSource  = hotel;
            guestsBindingSource.DataSource = guests;
            InformChange += updateMainFormData;

            ////////
            hotel.AddFloor();
            hotel.AddFloor();
            hotel.AddRoomRange(1, 215, 220, "FIRSTЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕ", 3, 15);
            guests.SettleGuests(216, new DateTime(2016, 5, 14), new Guest("Ivan", "Petrov", "0502122222"));
            showHotelPanel();
        }
示例#2
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            //проверка номера комнаты
            string text = roomNumberTextBox.Text;
            int    number;
            string name, surname, phone;

            if (text == "")
            {
                errorProvider.SetError(roomNumberTextBox, "Заполните это поле.");
                return;
            }

            if (Int32.TryParse(text, out number) == false || number <= 0)
            {
                errorProvider.SetError(roomNumberTextBox, "Введите положительное число не больше миллиарда.");
                return;
            }

            //проверка присутствия хоть 1 гостя
            if (guestsToAdd.Rows.Count == 0)
            {
                MessageBox.Show("Добавьте как минимум одного гостя.",
                                "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <Guest> guestList = new List <Guest>();

            //проверка и парсинг списка гостей
            foreach (DataGridViewRow row in guestsToAdd.Rows)
            {
                name    = row.Cells[0].EditedFormattedValue.ToString();
                surname = row.Cells[1].EditedFormattedValue.ToString();
                phone   = row.Cells[2].EditedFormattedValue.ToString();
                if (name == "")
                {
                    row.Cells[0].ErrorText = "Заполните это поле.";
                    return;
                }
                if (surname == "")
                {
                    row.Cells[1].ErrorText = "Заполните это поле.";
                    return;
                }
                //в номере могут быть скобки, дефисы, плюс и т.д. поэтому проверить очень сложно
                if (phone == "")
                {
                    row.Cells[2].ErrorText = "Заполните это поле.";
                    return;
                }
                guestList.Add(new Guest(name, surname, phone));
            }

            try
            {
                DateTime date = new DateTime(datePicker.Value.Year, datePicker.Value.Month, datePicker.Value.Day);
                guests.SettleGuests(number, date, guestList);
                MessageBox.Show($"Гости успешно добавлены в комнату {number}.\nПодробная информация содержится в квитанции.",
                                "Заселение успешно",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception exc)
            {
                errorProvider.SetError(roomNumberTextBox, null);
                MessageBox.Show(exc.Message,
                                "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }