コード例 #1
0
        private void addResidentButton_Click(object sender, EventArgs e)
        {
            if (hotel.IsFull())
            {
                MessageBox.Show("В отеле нет свободных номеров.");
            }
            else
            {
                var rf = new RegRecForm(hotel);
                if (rf.ShowDialog() == DialogResult.OK)
                {
                    hotel.AddRegRec(rf.RegRecord);
                    roomBindingSource.ResetBindings(false);
                    residentBindingSource.ResetBindings(false);
                    regRecsGridView.Rows.Add($"{rf.RegRecord.Resident.Surname}",
                                             $"{rf.RegRecord.Resident.Name}",
                                             $"{rf.RegRecord.Resident.Gender}",
                                             $"{rf.RegRecord.Resident.BirthDate.ToShortDateString()}",
                                             $"{rf.RegRecord.Resident.Phone}",
                                             $"{rf.RegRecord.Resident.Email}",
                                             $"{rf.RegRecord.Room.Floor}",
                                             $"{rf.RegRecord.Room.Number}",
                                             $"{rf.RegRecord.ArrivalDate.ToShortDateString()}",
                                             $"{rf.RegRecord.DepartureDate.ToShortDateString()}",
                                             $"{rf.RegRecord.Total}");
                    hotel.IsDirty = true;

                    // Обрати та перейти до останнього рядка.
                    var lastIdx = regRecsGridView.Rows.Count - 1;
                    regRecsGridView.Rows[lastIdx].Selected          = true;
                    regRecsGridView.FirstDisplayedScrollingRowIndex = lastIdx;
                }
            }
        }
コード例 #2
0
        private void editResidentButton_Click(object sender, EventArgs e)
        {
            int    ind     = regRecsGridView.SelectedRows[0].Index;
            string surname = regRecsGridView.Rows[ind].Cells[0].Value.ToString();
            string phone   = regRecsGridView.Rows[ind].Cells[4].Value.ToString();
            var    toEdit  = hotel.FindRegRec(surname, phone);
            var    pf      = new RegRecForm(hotel, toEdit);

            if (pf.ShowDialog() == DialogResult.OK)
            {
                roomBindingSource.ResetBindings(false);
                regRecsGridView.Rows.Clear();
                FillRegRecs();
                hotel.IsDirty = true;

                regRecsGridView.Rows[ind].Selected = true;
                regRecsGridView.FirstDisplayedScrollingRowIndex = ind;
            }
        }