Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var rows = dataGridView1.SelectedRows;

            if (rows.Count == 0)
            {
                MyMsgBox.showError("Ничего не выделено");
                return;
            }
            List <PERSONCARD> selected = new List <PERSONCARD>();

            foreach (DataGridViewRow row in rows)
            {
                selected.Add(result[row.Index]);
            }

            komandirovkaForm.SetWorkers(selected);
            MyMsgBox.showInfo("Добавлено!");
            this.Close();
            komandirovkaForm.Show();
        }
Ejemplo n.º 2
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            var country = CountryComboBox.SelectedValue;

            if (country == null)
            {
                MyMsgBox.showError("Страна не выбрана!");
                return;
            }

            var city = CityTextBox.Text;

            if (city == null)
            {
                MyMsgBox.showError("Введите город");
                return;
            }
            var org = OrganizationTextBox.Text;

            if (string.IsNullOrEmpty(org))
            {
                MyMsgBox.showError("Введите название организации");
                return;
            }
            var places = model.PLACE_TRIP;

            //Вдруг такое уже есть
            PLACE_TRIP neededPlace = null;

            foreach (PLACE_TRIP place in places)
            {
                if (String.Compare(place.City, city, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    neededPlace = place;
                    break;
                }
            }

            if (neededPlace == null)
            {
                PLACE_TRIP newPlace = new PLACE_TRIP();
                string     test     = country as string;
                newPlace.Country = test;
                newPlace.City    = city;
                newPlace.createName();
                model.PLACE_TRIP.Add(newPlace);
                model.SaveChanges();
                neededPlace = newPlace;
                Console.WriteLine($"id = {neededPlace.PK_PLACE_TRIP}");
                //neededPlace = model.PLACE_TRIP.FirstOrDefault(place => place.NAME == newPlace.NAME);
            }

            TRIP_ORG trip_org = model.TRIP_ORG.Create();

            trip_org.NAME       = org;
            trip_org.PLACE_TRIP = neededPlace;
            model.TRIP_ORG.Add(trip_org);
            model.SaveChanges();
            komandirovkaForm.UpdatePlaces();
            Console.WriteLine($"id org = {trip_org.PK_TRIP_ORG}");
            komandirovkaForm.AddOrgTrip(trip_org);
            MyMsgBox.showInfo("Добавлено!");
            this.Close();
            komandirovkaForm.Show();
        }