Пример #1
0
        /// <summary>
        /// Загружает информацию о жителе в поля ввода окна
        /// </summary>
        public void LoadData()
        {
            Resident resident = db.GetTable <Resident>().SingleOrDefault(r => r.ResidentId == residentId);

            residentIdLabel.Text    = resident.ResidentId.ToString();
            surnameTextBox.Text     = resident.Surname;
            nameTextBox.Text        = resident.Name;
            patronymicTextBox.Text  = resident.Patronymic;
            phoneNumberTextBox.Text = resident.PhoneNumber;
            birthdayDateTimePicker.NullableValue(resident.Birthday);
            noteTextBox.Text         = resident.Note;
            passportIdLabel.Text     = resident.PassportId.ToString();
            organizationIdLabel.Text = resident.OrganizationId.ToString();

            Int32.TryParse(organizationIdLabel.Text, out int organizationId);
            Organization organization = db.GetTable <Organization>().SingleOrDefault(o => o.OrganizationId == organizationId);

            organizationTextBox.Text = organization.Name;

            Int32.TryParse(passportIdLabel.Text, out int passportId);
            Passport passport = db.GetTable <Passport>().SingleOrDefault(p => p.PassportId == passportId);

            passportNumberTextBox.Text              = passport.Number;
            passportSeriesTextBox.Text              = passport.Series;
            passportRegistrationTextBox.Text        = passport.Registration;
            passportDateOfIssueDateTimePicker.Value = passport.DateOfIssue.Value;
            passportAuthorityTextBox.Text           = passport.Authority;
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        // Открывает окно жителей общежития для выбора и загружает информацию о выбранном жителе
        private void residentButton_Click(object sender, EventArgs e)
        {
            string value = ResidentsForm.ShowDialogForNewResident(sqlConnectionString);

            if (value != null)
            {
                Int32.TryParse(value, out int residentId);
                Resident resident = db.GetTable <Resident>().SingleOrDefault(r => r.ResidentId == residentId);
                residentIdLabel.Text   = resident.ResidentId.ToString();
                surnameTextBox.Text    = resident.Surname;
                nameTextBox.Text       = resident.Name;
                patronymicTextBox.Text = resident.Patronymic;
                Organization organization = db.GetTable <Organization>().SingleOrDefault(o => o.OrganizationId == resident.OrganizationId);
                organizationTextBox.Text = organization.Name;
            }
        }
Пример #4
0
        /// <summary>
        /// Запись о изменении жителя
        /// </summary>
        /// <param name="oldResident">Старая запись жителя</param>
        /// <param name="newResident">Новая запись жителя</param>
        public static void WriteAboutEditResident(Resident oldResident, Resident newResident)
        {
            try
            {
                string action = "Изменил жителя. ";
                string oldResidentFullName = oldResident.Surname + " " +
                                             oldResident.Name + " " + oldResident.Patronymic;
                string newResidentFullName = newResident.Surname + " " +
                                             newResident.Name + " " + newResident.Patronymic;
                if (oldResidentFullName != newResidentFullName)
                {
                    action += oldResidentFullName + "->" + newResidentFullName + ". ";
                }
                else
                {
                    action += oldResidentFullName + ". ";
                }

                if (oldResident.Organization.Name != newResident.Organization.Name)
                {
                    action += "Организация: " + oldResident.Organization.Name + "->" + newResident.Organization.Name + ". ";
                }
                //else
                //{
                //	action += "Организация: " + oldResident.Organization.Name + ". ";
                //}

                if (oldResident.PhoneNumber != newResident.PhoneNumber)
                {
                    action += "Телефонный номер: " + (string.IsNullOrEmpty(oldResident.PhoneNumber) ? "Нет" : oldResident.PhoneNumber) + "->" +
                              (string.IsNullOrEmpty(newResident.PhoneNumber) ? "Нет" : newResident.PhoneNumber) + ". ";
                }
                //else
                //{
                //	action += "Телефонный номер: " + oldResident.PhoneNumber + ". ";
                //}

                if (oldResident.Birthday != newResident.Birthday)
                {
                    string oldDate = "Нет", newDate = "Нет";

                    if (oldResident.Birthday.HasValue)
                    {
                        oldDate = oldResident.Birthday.Value.Day.ToString() + "." +
                                  oldResident.Birthday.Value.Month.ToString() + "." +
                                  oldResident.Birthday.Value.Year.ToString();
                    }
                    if (newResident.Birthday.HasValue)
                    {
                        newDate = newResident.Birthday.Value.Day.ToString() + "." +
                                  newResident.Birthday.Value.Month.ToString() + "." +
                                  newResident.Birthday.Value.Year.ToString();
                    }
                    action += "День рождения: " + oldDate + "->" + newDate + ". ";
                }
                //else
                //{
                //	action += "День рождения: " + oldResident.Birthday.Value.Day.ToString() + "." +
                //		oldResident.Birthday.Value.Month.ToString() + "." + oldResident.Birthday.Value.Year.ToString() + ". ";
                //}

                if (oldResident.Note != newResident.Note)
                {
                    action += "Пометка: " + (string.IsNullOrEmpty(oldResident.Note) ? "Нет" : oldResident.Note) + "->" +
                              (string.IsNullOrEmpty(newResident.Note) ? "Нет" : newResident.Note) + ". ";
                }
                //else
                //{
                //	action += "Пометка: " + oldResident.Note + ". ";
                //}

                Passport oldPassport = oldResident.Passport;
                Passport newPassport = newResident.Passport;

                string oldPassportName = oldPassport.Series + oldPassport.Number;
                string newPassportName = newPassport.Series + newPassport.Number;

                if (oldPassportName != newPassportName)
                {
                    action += "Паспортные данные: " + oldPassportName + "->" + newPassportName + ". ";
                }
                //else
                //{
                //	action += "Паспортные данные: " + oldPassportName + ". ";
                //}

                if (oldPassport.Registration != newPassport.Registration)
                {
                    action += "Прописка: " + oldPassport.Registration + "->" + newPassport.Registration + ". ";
                }
                //else
                //{
                //	action += "Прописка: " + oldPassport.Registration + ". ";
                //}

                if (oldPassport.DateOfIssue != newPassport.DateOfIssue)
                {
                    action += "Дата выдачи: " + oldPassport.DateOfIssue.Value.Day.ToString() + "." +
                              oldPassport.DateOfIssue.Value.Month.ToString() + "." + oldPassport.DateOfIssue.Value.Year.ToString() + "->" +
                              newPassport.DateOfIssue.Value.Day.ToString() + "." + newPassport.DateOfIssue.Value.Month.ToString() + "." +
                              newPassport.DateOfIssue.Value.Year.ToString() + ". ";
                }
                //else
                //{
                //	action += "Дата выдачи: " + oldPassport.DateOfIssue.Value.Day.ToString() + "." +
                //		oldPassport.DateOfIssue.Value.Month.ToString() + "." + oldPassport.DateOfIssue.Value.Year.ToString() + ". ";
                //}

                if (oldPassport.Authority != newPassport.Authority)
                {
                    action += "Орган выдачи: " + oldPassport.Authority + "->" + newPassport.Authority + ". ";
                }
                //else
                //{
                //	action += "Орган выдачи: " + oldPassport.Authority + ". ";
                //}

                HistoryRecord historyRecord = new HistoryRecord
                {
                    UserName     = HistoryRecordsController.UserName,
                    Action       = action,
                    DateOfAction = DateTime.Now
                };
                db.GetTable <HistoryRecord>().InsertOnSubmit(historyRecord);
                db.SubmitChanges();

                ClearHistory(92);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка ведения истории!\n" + ex.Message);
            }
        }
Пример #5
0
        // Удаляет выбранного жителя
        private void deleteButton_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите удалить выбранного жителя?\n",
                                                        "Предупреждение", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                    Int32.TryParse(residentIdLabel.Text, out int residentId);
                    if (residentId == 0)
                    {
                        MessageBox.Show("Выберите жителя");
                    }
                    else
                    {
                        SqlConnectionStringBuilder sConnBForOtherServer = new SqlConnectionStringBuilder()
                        {
                            DataSource     = Properties.Settings.Default.userServer2Name,
                            InitialCatalog = Properties.Settings.Default.userServer2Database,
                            UserID         = sqlConnectionString.UserID,
                            Password       = sqlConnectionString.Password,
                        };
                        DataContext dbFromOtherServer = new DataContext(sConnBForOtherServer.ConnectionString);
                        Resident    resident2         = dbFromOtherServer.GetTable <Resident>().FirstOrDefault(r => r.ResidentId == residentId);
                        if (resident2 != null)
                        {
                            dbFromOtherServer.GetTable <Resident>().DeleteOnSubmit(resident2);
                        }

                        Passport passport2 = dbFromOtherServer.GetTable <Passport>().FirstOrDefault(r => (r.PassportId == resident2.PassportId));
                        if (passport2 != null)
                        {
                            resident2.Passport = passport2;
                            dbFromOtherServer.GetTable <Passport>().DeleteOnSubmit(passport2);
                        }

                        RoomResidents roomResidents2 = dbFromOtherServer.GetTable <RoomResidents>().FirstOrDefault(r => (r.ResidentId == residentId));
                        if (roomResidents2 != null)
                        {
                            dbFromOtherServer.GetTable <RoomResidents>().DeleteOnSubmit(roomResidents2);
                        }

                        ResidentRooms residentRooms2 = dbFromOtherServer.GetTable <ResidentRooms>()
                                                       .FirstOrDefault(r => (r.ResidentId == residentId && r.DateOfEviction == null));
                        if (residentRooms2 != null)
                        {
                            residentRooms2.DateOfEviction = DateTime.Now;
                        }



                        db = new DataContext(sqlConnectionString.ConnectionString);
                        Resident resident = db.GetTable <Resident>().FirstOrDefault(r => r.ResidentId == residentId);
                        if (resident != null)
                        {
                            db.GetTable <Resident>().DeleteOnSubmit(resident);
                        }

                        Passport passport = db.GetTable <Passport>().FirstOrDefault(r => (r.PassportId == resident.PassportId));
                        if (passport != null)
                        {
                            resident.Passport = passport;
                            db.GetTable <Passport>().DeleteOnSubmit(passport);
                        }

                        RoomResidents roomResidents = db.GetTable <RoomResidents>().FirstOrDefault(r => (r.ResidentId == residentId));
                        if (roomResidents != null)
                        {
                            db.GetTable <RoomResidents>().DeleteOnSubmit(roomResidents);
                        }

                        ResidentRooms residentRooms = db.GetTable <ResidentRooms>()
                                                      .FirstOrDefault(r => (r.ResidentId == residentId && r.DateOfEviction == null));
                        if (residentRooms != null)
                        {
                            residentRooms.DateOfEviction = DateTime.Now;
                        }

                        dbFromOtherServer.SubmitChanges();
                        db.SubmitChanges();
                        LoadDataGrid();

                        HistoryRecordsController.WriteAboutAddDeleteResident(resident, false);
                    }
                }
                catch (Exception ex)
                {
                    HistoryRecordsController.WriteExceptionToLogFile(ex, "Ошибка при удалении жителя в deleteButton_Click.");
                    MessageBox.Show("Ошибка при удалении жителя.\nВызвано исключение: " + ex.Message);
                }
                finally
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
            }
        }
Пример #6
0
        public void LoadTabs()
        {
            //dataAdapter = new SqlDataAdapter("SELECT * FROM ORGANIZATIONS", sqlConnection);
            //dataTable = new DataTable();
            //dataAdapter.Fill(dataTable);
            //organizationsDataGridView.DataSource = dataTable;
            try
            {
                Table <Section> sections = db.GetTable <Section>();

                foreach (var section in sections)
                {
                    TabPage myTabPage = new TabPage(section.Number.ToString());

                    TableLayoutPanel sectionPanel = new TableLayoutPanel();
                    //sectionPanel.Anchor = System.Windows.Forms.AnchorStyles.None;
                    sectionPanel.ColumnCount = 3;
                    sectionPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
                    sectionPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 75F));
                    sectionPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F));
                    sectionPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
                    sectionPanel.Controls.Add(new Label()
                    {
                        Text = "Комната"
                    }, 0, 0);
                    sectionPanel.Controls.Add(new Label()
                    {
                        Text = "Житель"
                    }, 1, 0);
                    sectionPanel.Controls.Add(new Label()
                    {
                        Text = "Организация"
                    }, 2, 0);
                    int row = 1;
                    foreach (var room in section.Rooms)
                    {
                        Label label = new Label()
                        {
                            Text = room.Number.ToString()
                        };

                        for (int i = 0; i < room.Seats; i++)
                        {
                            sectionPanel.Controls.Add(label, 0, row + i);
                            Resident resident = room.Residents.ElementAtOrDefault(i);

                            LinkLabelModified linkLabel = new LinkLabelModified();
                            linkLabel.AutoSize     = true;
                            linkLabel.Name         = "linkLabel";
                            linkLabel.Size         = new System.Drawing.Size(55, 13);
                            linkLabel.TabIndex     = 3;
                            linkLabel.TabStop      = true;
                            linkLabel.Text         = "Пусто";
                            linkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel_LinkClicked);
                            if (resident != null)
                            {
                                string fullName = resident.Surname.ToString() + " " + resident.Name.ToString() + " " + resident.Patronymic.ToString();
                                linkLabel.Text       = fullName;
                                linkLabel.residentId = resident.ResidentId;
                                string organizationName = resident.Organization.Name.ToString();
                                sectionPanel.Controls.Add(linkLabel, 1, row + i);
                                sectionPanel.Controls.Add(new Label()
                                {
                                    Text = organizationName + (i + 1).ToString()
                                }, 2, row + i);
                            }
                            else
                            {
                                linkLabel.roomId = room.RoomId;
                                sectionPanel.Controls.Add(linkLabel, 1, row + i);
                                sectionPanel.Controls.Add(new Label()
                                {
                                    Text = "Пусто" + (i + 1).ToString()
                                }, 2, row + i);
                            }
                        }
                        //sectionPanel.SetRowSpan(label, room.Seats);
                        row += room.Seats;
                    }

                    sectionPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;

                    sectionPanel.Name = "sectionPanel" + section.Number.ToString();
                    //sectionPanel.RowCount = section.NumberOfRooms;
                    sectionPanel.Size = new System.Drawing.Size(600, 400);
                    myTabPage.Controls.Add(sectionPanel);
                    sectionsTabControl.TabPages.Add(myTabPage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                sqlConnection.Close();
            }
        }
Пример #7
0
        public void LoadTabs()
        {
            //dataGridView.Columns.Clear();
            //dataGridView.Rows.Clear();
            //dataAdapter = new SqlDataAdapter("SELECT * FROM ORGANIZATIONS", sqlConnection);
            //dataTable = new DataTable();
            //dataAdapter.Fill(dataTable);
            //organizationsDataGridView.DataSource = dataTable;
            try
            {
                Table <Section> sections = db.GetTable <Section>();

                foreach (var section in sections)
                {
                    TabPage      myTabPage    = new TabPage(section.Number.ToString());
                    DataGridView dataGridView = new DataGridView();
                    dataGridView.MultiSelect = false;
                    //dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                    dataGridView.AllowUserToAddRows          = false;
                    dataGridView.AllowUserToDeleteRows       = false;
                    dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                    //dataGridView.Location = new System.Drawing.Point(32, 285);
                    dataGridView.Name     = "dataGridView1";
                    dataGridView.ReadOnly = true;
                    dataGridView.Size     = new System.Drawing.Size(700, 400);
                    //dataGridView.TabIndex = 1;
                    dataGridView.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellContentClick);
                    DataGridViewColumn Column1 = new DataGridViewColumn
                    {
                        HeaderText   = "#",
                        Name         = "Column1",
                        ReadOnly     = true,
                        CellTemplate = new DataGridViewTextBoxCell()
                    };
                    DataGridViewLinkColumn Column2 = new DataGridViewLinkColumn
                    {
                        HeaderText = "FIO",
                        Name       = "Column1",
                        //	ReadOnly = true,
                        AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
                        UseColumnTextForLinkValue = true,
                        //	ActiveLinkColor = Color.White,
                        //	LinkBehavior = LinkBehavior.SystemDefault,
                        LinkColor = Color.Blue,
                        //	TrackVisitedState = true,
                        VisitedLinkColor = Color.Blue,
                        CellTemplate     = new DataGridViewLinkCell()
                    };
                    DataGridViewColumn Column3 = new DataGridViewColumn
                    {
                        HeaderText   = "Org",
                        Name         = "Column1",
                        ReadOnly     = true,
                        AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill,
                        CellTemplate = new DataGridViewTextBoxCell()
                    };
                    dataGridView.Columns.Add(Column1);
                    //	dataGridView1.Columns.Add("sa", "das");
                    dataGridView.Columns.Add(Column2);
                    dataGridView.Columns.Add(Column3);
                    int k = 0;
                    //foreach (var section in sections)
                    //{
                    int row = 0;
                    foreach (var room in section.Rooms)
                    {
                        dataGridView.Rows.Add(room.Seats);
                        for (int i = 0; i < room.Seats; i++)
                        {
                            Resident resident = room.Residents.ElementAtOrDefault(i);
                            dynamic  kek      = new System.Dynamic.ExpandoObject();
                            if (resident != null)
                            {
                                string fullName = resident.Surname.ToString() + " " + resident.Name.ToString() + " " + resident.Patronymic.ToString();
                                //linkLabel.Text = fullName;
                                //linkLabel.residentId = resident.ResidentId;
                                kek.residentId = resident.ResidentId;
                                kek.roomId     = 0;
                                string organizationName = resident.Organization.Name.ToString();
                                dataGridView.Rows[row + i].Cells[1].Value = fullName;
                                dataGridView.Rows[row + i].Cells[1].Tag   = kek;
                                dataGridView.Rows[row + i].Cells[2].Value = organizationName;
                                //sectionPanel.Controls.Add(linkLabel, 1, row + i);
                                //sectionPanel.Controls.Add(new Label() { Text = organizationName + (i + 1).ToString() }, 2, row + i);
                            }
                            else
                            {
                                kek.residentId = 0;
                                kek.roomId     = room.RoomId;
                                dataGridView.Rows[row + i].Cells[1].Value = "Добавить";
                                dataGridView.Rows[row + i].Cells[1].Tag   = kek;
                                dataGridView.Rows[row + i].Cells[2].Value = "Пусто";
                                //	linkLabel.roomId = room.RoomId;
                                //sectionPanel.Controls.Add(linkLabel, 1, row + i);
                                //sectionPanel.Controls.Add(new Label() { Text = "Пусто" + (i + 1).ToString() }, 2, row + i);
                            }
                            dataGridView.Rows[row].Cells[0].Value = room.Number;
                        }
                        k++;
                        row += room.Seats;
                    }
                    myTabPage.Controls.Add(dataGridView);
                    tabControl1.TabPages.Add(myTabPage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                sqlConnection.Close();
            }
        }
Пример #8
0
        // Сохранение информации о жителе
        private void saveButton_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите сохранить изменения?\n",
                                                        "Предупреждение", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (isAllFieldsValid() == false)
                {
                    return;
                }
                try
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                    db = new DataContext(sqlConnectionString.ConnectionString);
                    Resident resident       = db.GetTable <Resident>().SingleOrDefault(r => r.ResidentId == residentId);
                    Resident oldResident    = resident.ShallowCopy();
                    int      organizationId = Int32.Parse(organizationIdLabel.Text);
                    resident.Surname      = surnameTextBox.Text;
                    resident.Name         = nameTextBox.Text;
                    resident.Patronymic   = patronymicTextBox.Text;
                    resident.PhoneNumber  = phoneNumberTextBox.Text;
                    resident.Birthday     = birthdayDateTimePicker.NullableValue();
                    resident.Note         = noteTextBox.Text;
                    resident.Organization = db.GetTable <Organization>().SingleOrDefault(r => r.OrganizationId == organizationId);

                    Passport passport = db.GetTable <Passport>().SingleOrDefault(p => p.PassportId == resident.PassportId);
                    oldResident.Passport  = passport.ShallowCopy();
                    passport.Number       = passportNumberTextBox.Text;
                    passport.Series       = passportSeriesTextBox.Text;
                    passport.Registration = passportRegistrationTextBox.Text;
                    passport.DateOfIssue  = passportDateOfIssueDateTimePicker.Value.Date;
                    passport.Authority    = passportAuthorityTextBox.Text;


                    SqlConnectionStringBuilder sConnBForOtherServer = new SqlConnectionStringBuilder()
                    {
                        DataSource     = Properties.Settings.Default.userServer2Name,
                        InitialCatalog = Properties.Settings.Default.userServer2Database,
                        UserID         = sqlConnectionString.UserID,
                        Password       = sqlConnectionString.Password,
                    };
                    DataContext dbFromOtherServer = new DataContext(sConnBForOtherServer.ConnectionString);
                    Resident    resident2         = dbFromOtherServer.GetTable <Resident>().SingleOrDefault(r => r.ResidentId == residentId);
                    resident2.Surname      = surnameTextBox.Text;
                    resident2.Name         = nameTextBox.Text;
                    resident2.Patronymic   = patronymicTextBox.Text;
                    resident2.PhoneNumber  = phoneNumberTextBox.Text;
                    resident2.Birthday     = birthdayDateTimePicker.NullableValue();
                    resident2.Note         = noteTextBox.Text;
                    resident2.Organization = dbFromOtherServer.GetTable <Organization>().SingleOrDefault(r => r.OrganizationId == organizationId);

                    Passport passport2 = dbFromOtherServer.GetTable <Passport>().SingleOrDefault(p => p.PassportId == resident2.PassportId);
                    passport2.Number       = passportNumberTextBox.Text;
                    passport2.Series       = passportSeriesTextBox.Text;
                    passport2.Registration = passportRegistrationTextBox.Text;
                    passport2.DateOfIssue  = passportDateOfIssueDateTimePicker.Value.Date;
                    passport2.Authority    = passportAuthorityTextBox.Text;
                    dbFromOtherServer.SubmitChanges();

                    db.SubmitChanges();
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Успешно сохранено!");

                    HistoryRecordsController.WriteAboutEditResident(oldResident, resident);
                }
                catch (Exception ex)
                {
                    SystemSounds.Exclamation.Play();
                    HistoryRecordsController.WriteExceptionToLogFile(ex, "Ошибка при сохранении изменений жителя.");
                    MessageBox.Show("Ошибка при сохранении изменений. \nВызвано исключение: " + ex.Message);
                }
                finally
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
            }
        }
Пример #9
0
        // Добавление нового жителя
        private void addButton_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите добавить данного жителя?\n",
                                                        "Предупреждение", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                if (isAllFieldsValid() == false)
                {
                    return;
                }
                try
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
                    // Для сброса контекста, если была попытка ввода нового значения
                    db = new DataContext(sqlConnectionString.ConnectionString);

                    string   surname              = surnameTextBox.Text;
                    string   name                 = nameTextBox.Text;
                    string   patronymic           = patronymicTextBox.Text;
                    string   phoneNumber          = phoneNumberTextBox.Text;
                    DateTime?birthday             = birthdayDateTimePicker.NullableValue();
                    string   passportSeries       = passportSeriesTextBox.Text;
                    string   passportNumber       = passportNumberTextBox.Text;
                    string   passportRegistration = passportRegistrationTextBox.Text;
                    string   note                 = noteTextBox.Text;
                    DateTime passportDateOfIssue  = passportDateOfIssueDateTimePicker.Value.Date;
                    string   passportAuthority    = passportAuthorityTextBox.Text;

                    int          organizationId = Int32.Parse(organizationIdLabel.Text);
                    Organization organization   = db.GetTable <Organization>().SingleOrDefault(r => r.OrganizationId == organizationId);

                    Passport passport = new Passport
                    {
                        Series       = passportSeries,
                        Number       = passportNumber,
                        Registration = passportRegistration,
                        DateOfIssue  = passportDateOfIssue,
                        Authority    = passportAuthority
                    };
                    db.GetTable <Passport>().InsertOnSubmit(passport);

                    Resident resident = new Resident
                    {
                        Surname      = surname,
                        Name         = name,
                        Patronymic   = patronymic,
                        PhoneNumber  = phoneNumber,
                        Birthday     = birthday,
                        Note         = note,
                        Passport     = passport,
                        Organization = organization,
                    };
                    db.GetTable <Resident>().InsertOnSubmit(resident);


                    SqlConnectionStringBuilder sConnBForOtherServer = new SqlConnectionStringBuilder()
                    {
                        DataSource     = Properties.Settings.Default.userServer2Name,
                        InitialCatalog = Properties.Settings.Default.userServer2Database,
                        UserID         = sqlConnectionString.UserID,
                        Password       = sqlConnectionString.Password,
                    };
                    DataContext  dbFromOtherServer = new DataContext(sConnBForOtherServer.ConnectionString);
                    Organization organization2     = dbFromOtherServer.GetTable <Organization>().SingleOrDefault(r => r.OrganizationId == organizationId);

                    Passport passport2 = new Passport
                    {
                        Series       = passportSeries,
                        Number       = passportNumber,
                        Registration = passportRegistration,
                        DateOfIssue  = passportDateOfIssue,
                        Authority    = passportAuthority
                    };
                    dbFromOtherServer.GetTable <Passport>().InsertOnSubmit(passport2);

                    Resident resident2 = new Resident
                    {
                        Surname      = surname,
                        Name         = name,
                        Patronymic   = patronymic,
                        PhoneNumber  = phoneNumber,
                        Birthday     = birthday,
                        Note         = note,
                        Passport     = passport2,
                        Organization = organization2,
                    };
                    dbFromOtherServer.GetTable <Resident>().InsertOnSubmit(resident2);
                    dbFromOtherServer.SubmitChanges();

                    db.SubmitChanges();
                    SystemSounds.Beep.Play();
                    MessageBox.Show("Успешно добавлен!");
                    HistoryRecordsController.WriteAboutAddDeleteResident(resident, true);
                    Close();
                }
                catch (Exception ex)
                {
                    SystemSounds.Exclamation.Play();
                    HistoryRecordsController.WriteExceptionToLogFile(ex, "Ошибка при добавлении жителя.");
                    MessageBox.Show("Ошибка при добавлении жителя.\nВызвано исключение: " + ex.Message);
                }
                finally
                {
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
                }
            }
        }
Пример #10
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);
                }
            }
        }