Пример #1
0
        /// <summary>
        /// Отвечает за выселения жителя из комнаты
        /// </summary>
        /// <param name="roomId">Идентификатор комнаты</param>
        /// <param name="residentId">Идентификатор жителя</param>
        private void EvictResident(int roomId, int residentId)
        {
            DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите выселить данного жителя?\n",
                                                        "Предупреждение", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    Resident      resident      = db.GetTable <Resident>().FirstOrDefault(r => r.ResidentId == residentId);
                    RoomResidents roomResidents = db.GetTable <RoomResidents>().FirstOrDefault(r => (r.ResidentId == residentId && r.RoomId == roomId));
                    db.GetTable <RoomResidents>().DeleteOnSubmit(roomResidents);
                    ResidentRooms residentRooms = db.GetTable <ResidentRooms>()
                                                  .FirstOrDefault(r => (r.ResidentId == residentId && r.RoomId == roomId && r.DateOfEviction == null));
                    residentRooms.DateOfEviction = DateTime.Now;
                    db.SubmitChanges();
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Житель успешно выселен!");

                    HistoryRecordsController.WriteAboutSettlement(residentRooms, false);
                }
                catch (Exception ex)
                {
                    SystemSounds.Exclamation.Play();
                    HistoryRecordsController.WriteExceptionToLogFile(ex, "Ошибка при выселении жителя.");
                    MessageBox.Show("Ошибка выселения жителя. \nВызвано исключение: " + ex.Message);
                }
            }
        }
Пример #2
0
        // Заселяет жителя
        private void settleButton_Click(object sender, EventArgs e)
        {
            if (startRentDateTimePicker.Value.Date > endRentDateTimePicker.Value.Date)
            {
                SystemSounds.Exclamation.Play();
                MessageBox.Show("Нельзя добавить данный прокат. Дата начала проката должна быть раньше даты окончания.");
                return;
            }
            DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите заселить данного жителя?\n",
                                                        "Предупреждение", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    Int32.TryParse(residentIdLabel.Text, out int residentId);
                    Resident resident = db.GetTable <Resident>().SingleOrDefault(r => r.ResidentId == residentId);

                    var exist = db.GetTable <RoomResidents>().Any(r => r.ResidentId == resident.ResidentId);
                    if (exist)
                    {
                        SystemSounds.Exclamation.Play();
                        MessageBox.Show("Данный житель уже живет в другой комнате");
                    }
                    else
                    {
                        RoomResidents roomResidents = new RoomResidents
                        {
                            RoomId     = roomId,
                            ResidentId = resident.ResidentId
                        };
                        db.GetTable <RoomResidents>().InsertOnSubmit(roomResidents);

                        bool          isCash        = cashRadioButton.Checked ? true : false;
                        ResidentRooms residentRooms = new ResidentRooms
                        {
                            ResidentId     = resident.ResidentId,
                            RoomId         = roomId,
                            CashPayment    = isCash,
                            BedClothes     = bedClothesCheckBox.Checked,
                            SettlementDate = settlementDateTimePicker.Value
                        };
                        db.GetTable <ResidentRooms>().InsertOnSubmit(residentRooms);
                        db.SubmitChanges();

                        if (isRentCheckBox.Checked)
                        {
                            RentThing rentThing = db.GetTable <RentThing>().SingleOrDefault(r => r.Name == "Телевизор");
                            ResidentRoomsRentThing residentRoomsRentThing = new ResidentRoomsRentThing
                            {
                                ResidentRoomsId = residentRooms.ResidentRoomsId,
                                RentThingId     = rentThing.RentThingId,
                                StartRentDate   = startRentDateTimePicker.Value.Date,
                                EndRentDate     = endRentDateTimePicker.Value.Date
                            };
                            db.GetTable <ResidentRoomsRentThing>().InsertOnSubmit(residentRoomsRentThing);
                        }
                        db.SubmitChanges();

                        HistoryRecordsController.WriteAboutSettlement(residentRooms, true);
                        DialogResult = DialogResult.OK;
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    SystemSounds.Exclamation.Play();
                    HistoryRecordsController.WriteExceptionToLogFile(ex, "Ошибка при заселении жителя в settleButton_Click.");
                    MessageBox.Show("Ошибка при заселении жителя.\nВызвано исключение: " + ex.Message);
                }
            }
        }