Exemplo n.º 1
0
        private void EditMissingPeopleButtonClick(object sender, EventArgs e)
        {
            if (ListInfo.Items.Count == 0)
            {
                MessageBox.Show("Список пропавших людей пуст!");
                return;
            }

            if (ListInfo.SelectedItems.Count == 0)
            {
                MessageBox.Show("Не выбрано ни одного элемента! Пожалуйста, выберите пропавшего человека");
                return;
            }

            if (ListInfo.SelectedItems.Count > 1)
            {
                MessageBox.Show("Выбрано более 1 элемента, пожалуйста, оставьте только 1 элемент!");
                return;
            }

            var context  = new PSOConnect();
            var idPeople = int.Parse(ListInfo.SelectedItems[0].ToString().Split('-')[0].Split('{')[1]);
            var people   = context.people.FirstOrDefault(peoples => peoples.idPeople == idPeople);

            Hide();
            new People(this, null, () => ListInfo.Items.Remove(ListInfo.SelectedItems[0]), EditListInfo, people);
        }
Exemplo n.º 2
0
        private void AddMissingPeople()
        {
            var context       = new PSOConnect();
            var people        = context.people.FirstOrDefault(peoples => peoples.family.Equals(FamilyField.Text) && peoples.name.Equals(NameField.Text) && peoples.middleName.Equals(MiddleNameField.Text) && EntityFunctions.TruncateTime(peoples.dateOfBirth.Value) == EntityFunctions.TruncateTime(DateOfBirthField.Value));
            var missingPeople = context.missingPeople.FirstOrDefault(missingPeoples => missingPeoples.specialSign.Equals(SpecialSignField.Text) && missingPeoples.lastLocation.Equals(LastLocationField.Text) && EntityFunctions.TruncateTime(missingPeoples.dateOfLoss.Value) == EntityFunctions.TruncateTime(DateOfLossField.Value));

            if (people == null || missingPeople == null)
            {
                var newPeople = new people
                {
                    idPeople    = context.people.Count() > 0 ? context.people.Max(idPeople => idPeople.idPeople) + 1 : 1,
                    family      = FamilyField.Text,
                    name        = NameField.Text,
                    middleName  = MiddleNameField.Text,
                    dateOfBirth = DateOfBirthField.Value
                };

                var newMissingPeople = new missingPeople
                {
                    idPeople     = context.missingPeople.Count() > 0 ? context.missingPeople.Max(idPeople => idPeople.idPeople) + 1 : 1,
                    specialSign  = SpecialSignField.Text,
                    lastLocation = LastLocationField.Text,
                    dateOfLoss   = DateOfLossField.Value
                };

                context.people.Add(newPeople);
                context.missingPeople.Add(newMissingPeople);
                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        private void EditEquipmentButtonClick(object sender, EventArgs e)
        {
            if (ListInfo.Items.Count == 0)
            {
                MessageBox.Show("Список оборудования пуст!");
                return;
            }

            if (ListInfo.SelectedItems.Count > 1)
            {
                MessageBox.Show("Выбрано более 1 оборудование, пожалуйста, оставьте только 1 оборудование");
                return;
            }

            if (ListInfo.SelectedItems.Count == 0)
            {
                MessageBox.Show("Не выбрано ни одного элемента! Пожалуйста, выберите оборудование");
                return;
            }

            var context     = new PSOConnect();
            var idEquipment = int.Parse(ListInfo.SelectedItems[0].ToString().Split('-')[0].Split('{')[1]);
            var equpment    = context.equipment.FirstOrDefault(equpments => equpments.idEquipment == idEquipment);

            Hide();
            new EditProfession(this, EditListInfo, () => ListInfo.Items.Remove(ListInfo.SelectedItems[0]), equpment);
        }
Exemplo n.º 4
0
        private void EditDepartmentButtonClick(object sender, EventArgs e)
        {
            if (ListInfo.Items.Count == 0)
            {
                MessageBox.Show("Список департаментов пуст!");
                return;
            }

            if (ListInfo.SelectedItems.Count == 0)
            {
                MessageBox.Show("Не выбрано ни одного элемента! Пожалуйста, выберите департамент");
                return;
            }

            if (ListInfo.SelectedItems.Count > 1)
            {
                MessageBox.Show("Выбрано более 1 элемента, пожалуйста, оставьте только 1 элемент!");
                return;
            }

            var context  = new PSOConnect();
            var idRegion = int.Parse(ListInfo.SelectedItems[0].ToString().Split('-')[0].Split('{')[1]);
            var region   = context.region.FirstOrDefault(regions => regions.idRegion == idRegion);

            Hide();
            new Department(this, null, () => ListInfo.Items.Remove(ListInfo.SelectedItems[0]), EditListInfo, region);
        }
Exemplo n.º 5
0
        private void InitFields(people people)
        {
            if (people == null)
            {
                EditMissingPeopleButton.Hide();
                AddMissingPeopleButton.Show();
                DateOfBirthField.Value = DateTime.Now.AddSeconds(-1);
                DateOfLossField.Value  = DateTime.Now.AddSeconds(-1);
            }
            else
            {
                EditMissingPeopleButton.Show();
                AddMissingPeopleButton.Hide();

                FamilyField.Text       = people.family;
                NameField.Text         = people.name;
                MiddleNameField.Text   = people.middleName;
                DateOfBirthField.Value = people.dateOfBirth.Value;

                var context       = new PSOConnect();
                var missingPeople = context.missingPeople.FirstOrDefault(missingPeoples => missingPeoples.idPeople == people.idPeople);

                SpecialSignField.Text  = missingPeople.specialSign;
                LastLocationField.Text = missingPeople.lastLocation;
                DateOfLossField.Value  = missingPeople.dateOfLoss.Value;
            }
        }
Exemplo n.º 6
0
        private void EditMissingPeople()
        {
            var context = new PSOConnect();

            var checkExistPeople        = context.people.FirstOrDefault(peoples => peoples.family.Equals(FamilyField.Text) && peoples.name.Equals(NameField.Text) && peoples.middleName.Equals(MiddleNameField.Text) && EntityFunctions.TruncateTime(peoples.dateOfBirth.Value) == EntityFunctions.TruncateTime(DateOfBirthField.Value));
            var checkExistMissingPeople = context.missingPeople.FirstOrDefault(missingPeoples => missingPeoples.specialSign.Equals(SpecialSignField.Text) && missingPeoples.lastLocation.Equals(LastLocationField.Text) && EntityFunctions.TruncateTime(missingPeoples.dateOfLoss.Value) == EntityFunctions.TruncateTime(DateOfLossField.Value));

            var people        = context.people.FirstOrDefault(peoples => peoples.idPeople == _idPeople);
            var missingPeople = context.missingPeople.FirstOrDefault(missingPeoples => missingPeoples.idPeople == _idPeople);

            if (checkExistMissingPeople != null && checkExistPeople != null && checkExistMissingPeople.idPeople != _idPeople && checkExistPeople.idPeople != _idPeople)
            {
                _deletedElementInListInfo?.Invoke();
                context.people.Remove(people);
                context.missingPeople.Remove(missingPeople);
                context.SaveChanges();
                return;
            }

            people.family      = FamilyField.Text;
            people.name        = NameField.Text;
            people.middleName  = MiddleNameField.Text;
            people.dateOfBirth = DateOfBirthField.Value;

            missingPeople.specialSign  = SpecialSignField.Text;
            missingPeople.lastLocation = LastLocationField.Text;
            missingPeople.dateOfLoss   = DateOfLossField.Value;

            _updatedListInfo?.Invoke($"{people.idPeople}-ФАМИЛИЯ: {FamilyField.Text} ИМЯ: {NameField.Text} ОТЧЕСТВО: {MiddleNameField.Text} ДАТА РОЖДЕНИЯ: {DateOfBirthField.Value.ToLongDateString()}\n ДАТА ПРОПАЖИ: {DateOfLossField.Value.ToLongDateString()} ПОСЛЕДНЕЕ МЕСТО: {LastLocationField.Text} ОПИСАНИЕ: {SpecialSignField.Text}");

            context.SaveChanges();
        }
Exemplo n.º 7
0
        private void InitListInfo()
        {
            var context = new PSOConnect();

            var disasters = context.GetDisasterData();

            foreach (var disaster in disasters)
            {
                ListInfo.Items.Add($"{disaster.idReason}-ТИП: {disaster.typeReason} ПРИЧИНА: {disaster.reason} СТРАНА: {disaster.country} ГОРОД: {disaster.city} ДАТА: {disaster.date.Value.ToLongDateString()}");
            }
        }
Exemplo n.º 8
0
        private void InitListInfo()
        {
            var context = new PSOConnect();

            var missingPeople = context.GetPeopleData();

            foreach (var people in missingPeople)
            {
                ListInfo.Items.Add($"{people.idPeople}-ФАМИЛИЯ: {people.family} ИМЯ: {people.name} ОТЧЕСТВО: {people.middleName} ДАТА РОЖДЕНИЯ: {people.dateOfBirth.Value.ToLongDateString()}\n ДАТА ПРОПАЖИ: {people.dateOfLoss.Value.ToLongDateString()} ПОСЛЕДНЕЕ МЕСТО: {people.lastLocation} ОПИСАНИЕ: {people.specialSign}");
            }
        }
Exemplo n.º 9
0
        private void InitListInfo()
        {
            var context = new PSOConnect();

            var equipments = context.GetEquipmentData();

            foreach (var equipment in equipments)
            {
                ListInfo.Items.Add($"{equipment.idEquipment}-ТИП: {equipment.type} НАЗВАНИЕ: {equipment.equipmentName} ОПИСАНИЕ: {equipment.description} ПРОФЕССИИ: {equipment.position}");
            }
        }
Exemplo n.º 10
0
        private void AddDepartment()
        {
            var            context               = new PSOConnect();
            var            mainDepartment        = context.mainDepartment.FirstOrDefault(mainDepartments => mainDepartments.address.Equals(MainDepartmentField.Text));
            mainDepartment currentMainDepartment = null;

            if (mainDepartment == null)
            {
                currentMainDepartment = new mainDepartment
                {
                    idMainDepartment = context.mainDepartment.Count() > 0 ? context.mainDepartment.Max(mainDepartments => mainDepartments.idMainDepartment) + 1 : 1,
                    address          = MainDepartmentField.Text
                };

                context.mainDepartment.Add(currentMainDepartment);
            }

            var        idMainDepartment  = mainDepartment == null ? currentMainDepartment.idMainDepartment : mainDepartment.idMainDepartment;
            var        department        = context.department.FirstOrDefault(departments => departments.address.Equals(DepartmentField.Text) && departments.idMainDepartment == idMainDepartment);
            department currentDepartment = null;

            if (department == null)
            {
                currentDepartment = new department
                {
                    idDepartment = context.department.Count() > 0 ? context.department.Max(departments => departments.idDepartment) + 1 : 1,
                    address      = DepartmentField.Text,
                };

                context.department.Add(currentDepartment);
                var mainDep = mainDepartment == null ? currentMainDepartment : mainDepartment;
                mainDep.department.Add(currentDepartment);
            }

            var    idDepartment  = department == null ? currentDepartment.idDepartment : department.idDepartment;
            var    region        = context.region.FirstOrDefault(regions => regions.address.Equals(RegionField.Text) && regions.idDepartment == idDepartment);
            region currentRegion = null;

            if (region == null)
            {
                currentRegion = new region
                {
                    idRegion = context.region.Count() > 0 ? context.region.Max(regions => regions.idRegion) + 1 : 1,
                    address  = RegionField.Text
                };

                context.region.Add(currentRegion);
                var depart = department == null ? currentDepartment : department;
                depart.region.Add(currentRegion);
            }

            context.SaveChanges();
        }
Exemplo n.º 11
0
        private void DeleteDepartmentButtonClick(object sender, EventArgs e)
        {
            if (ListInfo.Items.Count == 0)
            {
                MessageBox.Show("Список пропавших людей пуст!");
                return;
            }

            if (ListInfo.SelectedItems.Count == 0)
            {
                MessageBox.Show("Не выбрано ни одного элемента! Пожалуйста, выберите пропавшего человека");
                return;
            }

            var context = new PSOConnect();
            var count   = ListInfo.SelectedItems.Count;

            for (var i = 0; i < count; i++)
            {
                var idRegion       = int.Parse(ListInfo.SelectedItems[i].ToString().Split('-')[0].Split('{')[1]);
                var region         = context.region.FirstOrDefault(regions => regions.idRegion == idRegion);
                var department     = context.department.FirstOrDefault(departmanets => departmanets.idDepartment == region.idDepartment);
                var mainDepartment = context.mainDepartment.FirstOrDefault(mainDepartments => mainDepartments.idMainDepartment == department.idMainDepartment);

                foreach (var coordinator in context.coordinator)
                {
                    if (coordinator.idRegion == idRegion)
                    {
                        coordinator.idRegion = null;
                    }
                }

                ListInfo.Items.Remove(ListInfo.SelectedItems[i]);
                context.region.Remove(region);

                if (department.region.Count < 1)
                {
                    context.department.Remove(department);
                }

                if (mainDepartment.department.Count < 1)
                {
                    context.mainDepartment.Remove(mainDepartment);
                }
            }

            context.SaveChanges();

            var message = count > 1 ? "Департамены успешно удалены" : "Департамент успешно удалён";

            MessageBox.Show(message);
        }
Exemplo n.º 12
0
        private void DisasterButtonClick(object sender, EventArgs e)
        {
            var context    = new PSOConnect();
            var idDisaster = context.team.FirstOrDefault(team => team.idTeam == Login.CurrentUser.idTeam).idDisaster;

            if (idDisaster == null)
            {
                MessageBox.Show("В данный момент нет актуального задания связанным с катастрофой");
                return;
            }

            Hide();
            new Disaster(this);
        }
Exemplo n.º 13
0
        private void InitProfession()
        {
            var context = new PSOConnect();

            foreach (var profession in context.profession)
            {
                ProfessionField.Items.Add(profession.position);
            }

            if (ProfessionField.Items.Count > 0)
            {
                ProfessionField.SelectedIndex = 0;
            }
        }
Exemplo n.º 14
0
        private void MissingPeopleButtonClick(object sender, EventArgs e)
        {
            var context         = new PSOConnect();
            var idMissingPeople = context.team.FirstOrDefault(team => team.idTeam == Login.CurrentUser.idTeam).idPeople;

            if (idMissingPeople == null)
            {
                MessageBox.Show("В данный момент нет актуального задания связанным с поиском человека");
                return;
            }

            Hide();
            new MissingPeople(this);
        }
Exemplo n.º 15
0
        private void MyUniformButtonClick(object sender, EventArgs e)
        {
            var context = new PSOConnect();

            var equpment = context.equipment.FirstOrDefault(equipments => equipments.idProfession == Login.CurrentUser.idProfession);

            if (equpment == null)
            {
                MessageBox.Show("У вас нету оборудования, обратитесь к администратору, для заполнения");
                return;
            }

            Hide();
            new Equipment(this);
        }
Exemplo n.º 16
0
        private void RegistrationUser()
        {
            var context = new PSOConnect();
            var user    = context.user.FirstOrDefault(findUser => findUser.login.Equals(LoginField.Text));

            if (user != null)
            {
                MessageBox.Show("Пользователь с таким логином уже существует, измените логин!");
                return;
            }


            var lastIdUser   = context.user.Count() > 0 ? context.user.Max(users => users.idUser) : 0;
            var idProfession = context.profession.FirstOrDefault(profession => profession.position.Equals(ProfessionField.SelectedItem.ToString())).idProfession;
            var currentUser  = new user
            {
                idUser       = lastIdUser + 1,
                login        = LoginField.Text,
                password     = PasswordField.Text,
                family       = FamilyField.Text,
                name         = NameField.Text,
                middleName   = MiddleNameField.Text,
                idProfession = idProfession
            };

            Login.CurrentUser = currentUser;
            context.user.Add(currentUser);
            context.SaveChanges();

            MessageBox.Show("Пользователь успешно добавлен!");

            if (ProfessionField.SelectedItem.Equals(Admin))
            {
                new AdminMenu(_loginForm);
            }
            else if (ProfessionField.SelectedItem.Equals(Coordinator))
            {
                new CoordinatorMenu(_loginForm);
            }
            else
            {
                new OtherUsersMenu(_loginForm);
            }

            ResetFields();
            Hide();
        }
Exemplo n.º 17
0
        private void AuthorizationButtonClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(LoginField.Text))
            {
                MessageBox.Show("Введите логин!");
                return;
            }

            if (string.IsNullOrEmpty(PasswordField.Text))
            {
                MessageBox.Show("Введите пароль!");
                return;
            }

            var context = new PSOConnect();
            var getUser = context.user.FirstOrDefault(user => user.login.Equals(LoginField.Text) && user.password.Equals(PasswordField.Text));

            if (getUser == null)
            {
                var getLogin = context.user.FirstOrDefault(user => user.login.Equals(LoginField.Text));
                var message  = getLogin != null ? "Неверный пароль" : "Такого логина не существует";
                MessageBox.Show(message);
            }
            else
            {
                var currentProfession = context.profession.FirstOrDefault(profession => profession.idProfession == getUser.idProfession).position;
                ResetFields();
                CurrentUser = getUser;

                MessageBox.Show($"Добро пожаловать, {CurrentUser.family} {CurrentUser.name} {CurrentUser.middleName}");

                if (currentProfession.Equals(Registration.Admin))
                {
                    new AdminMenu(this);
                }
                else if (currentProfession.Equals(Registration.Coordinator))
                {
                    new CoordinatorMenu(this);
                }
                else
                {
                    new OtherUsersMenu(this);
                }

                Hide();
            }
        }
Exemplo n.º 18
0
        private bool CheckExist()
        {
            var context    = new PSOConnect();
            var checkExist = false;
            var department = from region in context.region
                             join departments in context.department on region.idDepartment equals departments.idDepartment
                             join mainDepartment in context.mainDepartment on departments.idMainDepartment equals mainDepartment.idMainDepartment
                             select new
            {
                AddressRegion         = region.address,
                AddressDepartment     = departments.address,
                AddressMainDepartment = mainDepartment.address
            };

            foreach (var depart in department)
            {
                if (depart.AddressRegion.Equals(RegionField.Text) && depart.AddressDepartment.Equals(DepartmentField.Text) && depart.AddressMainDepartment.Equals(MainDepartmentField.Text))
                {
                    checkExist = true;
                    break;
                }
            }

            if (checkExist)
            {
                var region         = context.region.FirstOrDefault(regions => regions.idRegion == _idRegion);
                var dep            = context.department.FirstOrDefault(departments => departments.idDepartment == region.idDepartment);
                var mainDepartment = context.mainDepartment.FirstOrDefault(mainDepartments => mainDepartments.idMainDepartment == dep.idMainDepartment);
                context.region.Remove(region);

                if (dep.region.Count < 1)
                {
                    context.department.Remove(dep);
                }

                if (mainDepartment.department.Count < 1)
                {
                    context.mainDepartment.Remove(mainDepartment);
                }

                context.SaveChanges();
                _deletedElementInListInfo?.Invoke();
                return(true);
            }

            return(false);
        }
Exemplo n.º 19
0
        private void DeleteDisasterButtonClick(object sender, EventArgs e)
        {
            if (ListInfo.Items.Count == 0)
            {
                MessageBox.Show("Список катастроф пуст!");
                return;
            }

            if (ListInfo.SelectedItems.Count == 0)
            {
                MessageBox.Show("Не выбрано ни одного элемента! Пожалуйста, выберите катастрофу");
                return;
            }

            var context = new PSOConnect();
            var count   = ListInfo.SelectedItems.Count;

            for (var i = 0; i < count; i++)
            {
                var idReason = int.Parse(ListInfo.SelectedItems[0].ToString().Split('-')[0].Split('{')[1]);
                var reason   = context.reason.FirstOrDefault(reasons => reasons.idReason == idReason);
                var disaster = context.disaster.FirstOrDefault(disasters => disasters.idDisaster == reason.idDisaster);

                foreach (var team in context.team)
                {
                    if (team.idDisaster == disaster.idDisaster && disaster.reason.Count < 1)
                    {
                        team.idDisaster = null;
                    }
                }

                context.reason.Remove(reason);

                if (disaster.reason.Count < 1)
                {
                    context.disaster.Remove(disaster);
                }

                ListInfo.Items.Remove(ListInfo.SelectedItems[0]);

                context.SaveChanges();
            }

            var message = count > 1 ? "Катастрофы успешно удалены" : "Катастрофа успешно удалёна";

            MessageBox.Show(message);
        }
Exemplo n.º 20
0
        private void EditDisaster()
        {
            if (CheckExist())
            {
                return;
            }

            var      context            = new PSOConnect();
            var      reason             = context.reason.FirstOrDefault(reasons => reasons.idReason == _idReason);
            var      disaster           = context.disaster.FirstOrDefault(disasters => disasters.idDisaster == reason.idDisaster);
            var      checkExistDisaster = context.disaster.FirstOrDefault(disasters => disasters.country.Equals(CountryField.Text) && disasters.city.Equals(CityField.Text) && EntityFunctions.TruncateTime(disasters.date.Value) == EntityFunctions.TruncateTime(DateField.Value));
            disaster currentDisaster;

            reason.reason1    = ReasonField.Text;
            reason.typeReason = TypeField.SelectedItem.ToString();

            if (disaster.reason.Count == 1)
            {
                currentDisaster         = disaster;
                currentDisaster.country = CountryField.Text;
                currentDisaster.city    = CityField.Text;
                currentDisaster.date    = DateField.Value;
            }
            else if (checkExistDisaster != null)
            {
                currentDisaster = checkExistDisaster;
                checkExistDisaster.reason.Add(reason);
            }
            else
            {
                currentDisaster = new disaster
                {
                    idDisaster = context.disaster.Count() > 0 ? context.disaster.Max(idDisaster => idDisaster.idDisaster) + 1 : 1,
                    country    = CountryField.Text,
                    city       = CityField.Text,
                    date       = DateField.Value
                };

                currentDisaster.reason.Add(reason);
                context.disaster.Add(currentDisaster);
            }

            _updatedListInfo?.Invoke($"{reason.idReason}-ТИП: {TypeField.SelectedItem} ПРИЧИНА: {ReasonField.Text} СТРАНА: {CountryField.Text} ГОРОД: {CityField.Text} ДАТА: {DateField.Value.ToLongDateString()}");
            context.SaveChanges();
        }
Exemplo n.º 21
0
        private void EditProfesson()
        {
            if (CheckExist())
            {
                return;
            }

            var context   = new PSOConnect();
            var equipment = context.equipment.FirstOrDefault(equipments => equipments.idEquipment == _idEquipment);

            equipment.equipmentName = NameEquipmentField.Text;
            equipment.type          = TypeEqupmentField.SelectedItem.ToString();
            equipment.description   = DescriptionEqupmentField.Text;

            var profession = context.profession.FirstOrDefault(professions => professions.idProfession == equipment.idProfession);

            var        checkExistProfession = context.profession.FirstOrDefault(professions => professions.position.Equals(ProfessionField.Text));
            profession currentProfession    = null;

            if (profession.equipment.Count == 1)
            {
                currentProfession   = profession;
                profession.position = ProfessionField.Text;
            }
            else if (checkExistProfession != null)
            {
                currentProfession = checkExistProfession;
                checkExistProfession.equipment.Add(equipment);
            }
            else
            {
                currentProfession = new profession
                {
                    idProfession = context.profession.Count() > 0 ? context.profession.Max(idProfession => idProfession.idProfession) + 1 : 1,
                    position     = ProfessionField.Text
                };

                currentProfession.equipment.Add(equipment);
                context.profession.Add(currentProfession);
            }

            _updatedListInfo?.Invoke($"{equipment.idEquipment}-ТИП: {TypeEqupmentField.SelectedItem} НАЗВАНИЕ: {NameEquipmentField.Text} ОПИСАНИЕ: {DescriptionEqupmentField.Text} ПРОФЕССИИ: {ProfessionField.Text}");

            context.SaveChanges();
        }
Exemplo n.º 22
0
        private void CompletedButtonClick(object sender, EventArgs e)
        {
            var context       = new PSOConnect();
            var idPeople      = int.Parse(IdPeopleText.Text);
            var missingPeople = context.missingPeople.FirstOrDefault(missinpPeoples => missinpPeoples.idPeople == idPeople);
            var people        = context.people.FirstOrDefault(peoples => peoples.idPeople == idPeople);

            missingPeople.team.Clear();

            context.missingPeople.Remove(missingPeople);
            context.people.Remove(people);
            context.SaveChanges();

            MessageBox.Show("Поздравляем с выполненым заданием!");

            ResetField();
            InitFields();
        }
Exemplo n.º 23
0
        private bool CheckExist()
        {
            var context    = new PSOConnect();
            var checkExist = false;
            var disasters  = from reason in context.reason
                             join disaster in context.disaster on reason.idDisaster equals disaster.idDisaster
                             select new
            {
                Id     = reason.idReason,
                Type   = reason.typeReason,
                Reason = reason.reason1,
                County = disaster.country,
                City   = disaster.city,
                Date   = disaster.date,
            };

            foreach (var disaster in disasters)
            {
                if (disaster.Type.Equals(TypeField.SelectedItem.ToString()) && disaster.Reason.Equals(ReasonField.Text) && disaster.County.Equals(CountryField.Text) && disaster.City.Equals(CityField.Text) && EntityFunctions.TruncateTime(disaster.Date.Value) == EntityFunctions.TruncateTime(DateField.Value))
                {
                    checkExist = true;
                    break;
                }
            }

            if (checkExist)
            {
                var reason   = context.reason.FirstOrDefault(reasons => reasons.idReason == _idReason);
                var disaster = context.disaster.FirstOrDefault(dis => dis.idDisaster == reason.idDisaster);

                context.reason.Remove(reason);

                if (disaster.reason.Count < 1)
                {
                    context.disaster.Remove(disaster);
                }

                context.SaveChanges();
                _deletedListInfo?.Invoke();
                return(true);
            }

            return(false);
        }
Exemplo n.º 24
0
        private void InitFields(equipment equipment)
        {
            var context = new PSOConnect();

            DescriptionEqupmentField.Text = equipment.description;
            NameEquipmentField.Text       = equipment.equipmentName;

            foreach (var type in _typeEqipment)
            {
                TypeEqupmentField.Items.Add(type);

                if (type.Equals(equipment.type))
                {
                    TypeEqupmentField.SelectedItem = type;
                }
            }

            ProfessionField.Text = context.profession.FirstOrDefault(profession => profession.idProfession == equipment.idProfession).position;
        }
Exemplo n.º 25
0
        private bool CheckExist()
        {
            var context    = new PSOConnect();
            var checkExist = false;
            var equipments = from equipment in context.equipment
                             join profession in context.profession on equipment.idProfession equals profession.idProfession
                             select new
            {
                Id            = equipment.idEquipment,
                Type          = equipment.type,
                EquipmentName = equipment.equipmentName,
                Description   = equipment.description,
                Profession    = profession.position
            };

            foreach (var equipment in equipments)
            {
                if (equipment.Type.Equals(TypeEqupmentField.SelectedItem.ToString()) && equipment.EquipmentName.Equals(NameEquipmentField.Text) && equipment.Description.Equals(DescriptionEqupmentField.Text) && equipment.Profession.Equals(ProfessionField.Text))
                {
                    checkExist = true;
                    break;
                }
            }

            if (checkExist)
            {
                var equipment  = context.equipment.FirstOrDefault(equip => equip.idEquipment == _idEquipment);
                var profession = context.profession.FirstOrDefault(professions => professions.idProfession == equipment.idProfession);

                context.equipment.Remove(equipment);

                if (profession.equipment.Count < 1)
                {
                    context.profession.Remove(profession);
                }

                context.SaveChanges();
                _deletedListInfo?.Invoke();
                return(true);
            }

            return(false);
        }
Exemplo n.º 26
0
        private void AddDisaster()
        {
            var context = new PSOConnect();

            var      disaster        = context.disaster.FirstOrDefault(disasters => disasters.country.Equals(CountryField.Text) && disasters.city.Equals(CityField.Text) && EntityFunctions.TruncateTime(disasters.date.Value) == EntityFunctions.TruncateTime(DateField.Value));
            disaster currentDisaster = null;

            if (disaster == null)
            {
                currentDisaster = new disaster
                {
                    idDisaster = context.disaster.Count() > 0 ? context.disaster.Max(disasters => disasters.idDisaster) + 1 : 1,
                    country    = CountryField.Text,
                    city       = CityField.Text,
                    date       = DateField.Value
                };

                context.disaster.Add(currentDisaster);
            }
            else
            {
                currentDisaster = disaster;
            }

            var    reason        = context.reason.FirstOrDefault(reasons => reasons.typeReason.Equals(TypeField.SelectedItem.ToString()) && reasons.reason1.Equals(ReasonField.Text) && reasons.idDisaster == currentDisaster.idDisaster);
            reason currentReason = null;

            if (reason == null)
            {
                currentReason = new reason
                {
                    idReason   = context.reason.Count() > 0 ? context.reason.Max(reasons => reasons.idReason) + 1 : 1,
                    typeReason = TypeField.Text,
                    reason1    = ReasonField.Text,
                };

                currentDisaster.reason.Add(currentReason);
                context.reason.Add(currentReason);
            }

            context.SaveChanges();
        }
Exemplo n.º 27
0
        private void InitListInfo()
        {
            var context = new PSOConnect();

            var department = from region in context.region
                             join departments in context.department on region.idDepartment equals departments.idDepartment
                             join mainDepartment in context.mainDepartment on departments.idMainDepartment equals mainDepartment.idMainDepartment
                             select new
            {
                Id                    = region.idRegion,
                AddressRegion         = region.address,
                AddressDepartment     = departments.address,
                AddressMainDepartment = mainDepartment.address
            };

            foreach (var dep in department)
            {
                ListInfo.Items.Add($"{dep.Id}-АДРЕС РЕГИОНА: {dep.AddressRegion} АДРЕС ДЕПАРТАМЕНТА: {dep.AddressDepartment} АДРЕС ГЛАВНОГО ДЕПАРТАМЕНТА: {dep.AddressMainDepartment}");
            }
        }
Exemplo n.º 28
0
        private void InitFields(region region)
        {
            if (region == null)
            {
                AddDepartmentButton.Show();
                EditButton.Hide();
                return;
            }

            AddDepartmentButton.Hide();
            EditButton.Show();

            var context        = new PSOConnect();
            var department     = context.department.FirstOrDefault(departments => departments.idDepartment == region.idDepartment);
            var mainDepartment = context.mainDepartment.FirstOrDefault(mainDepartments => mainDepartments.idMainDepartment == department.idMainDepartment);

            RegionField.Text         = region.address;
            DepartmentField.Text     = department.address;
            MainDepartmentField.Text = mainDepartment.address;
        }
Exemplo n.º 29
0
        private void DeleteMissingPeopleButtonClick(object sender, EventArgs e)
        {
            if (ListInfo.Items.Count == 0)
            {
                MessageBox.Show("Список пропавших людей пуст!");
                return;
            }

            if (ListInfo.SelectedItems.Count == 0)
            {
                MessageBox.Show("Не выбрано ни одного элемента! Пожалуйста, выберите пропавшего человека");
                return;
            }

            var context = new PSOConnect();
            var count   = ListInfo.SelectedItems.Count;

            for (var i = 0; i < count; i++)
            {
                var idPeople      = int.Parse(ListInfo.SelectedItems[i].ToString().Split('-')[0].Split('{')[1]);
                var people        = context.people.FirstOrDefault(peoples => peoples.idPeople == idPeople);
                var missingPeople = context.missingPeople.FirstOrDefault(missingPeoples => missingPeoples.idPeople == idPeople);

                foreach (var team in context.team)
                {
                    if (team.idPeople == missingPeople.idPeople)
                    {
                        team.idPeople = null;
                    }
                }

                ListInfo.Items.Remove(ListInfo.SelectedItems[i]);
                context.people.Remove(people);
                context.missingPeople.Remove(missingPeople);
                context.SaveChanges();
            }

            var message = count > 1 ? "Пропавшие люди успешно удалены" : "Пропавший человек успешно удалён";

            MessageBox.Show(message);
        }
Exemplo n.º 30
0
        private void SelectButtonClick(object sender, EventArgs e)
        {
            if (NoFoundMissingPeopleText.Visible)
            {
                MessageBox.Show("Выбор невозможен, нет пропавших людей, с чем вас и поздравляем :)");
                return;
            }

            var context  = new PSOConnect();
            var team     = context.team.FirstOrDefault(teams => teams.idTeam == Login.CurrentUser.idTeam);
            var idPeople = int.Parse(SelectMissingPeopleField.SelectedItem.ToString().Split('-')[0]);

            team.idPeople = idPeople;

            context.SaveChanges();

            MessageBox.Show("Не подведите, родственники хотят, чтобы вы его нашли!");

            ResetField();
            InitFields();
        }