Exemplo n.º 1
0
        //////////ДОБАВЛЕНИЕ В БАЗУ ДАННЫХ\\\\\\\\\\\\\\\\

        // ДОБАВИТЬ БРИГАДУ
        private void addBrigabe_Click(object sender, EventArgs e)
        {
            using (MillitaryDbContext context = new MillitaryDbContext())
            {
                foreach (Brigade br in context.Brigades)
                {
                    if (br.Name == newNameBrigabe.Text)
                    {
                        MessageBox.Show("Бригада с такми названием уже существует!\nИзмените название и попробуйте еще раз!");
                        return;
                    }
                }
                Brigade brigade = new Brigade()
                {
                    Name = newNameBrigabe.Text
                };
                context.Brigades.Add(brigade);
                context.SaveChanges();
            }
            // Обновление источника данных
            newNameBrigabe.Clear();
            UpdateDb update = new UpdateDb();

            chooseBrig1.DataSource      = update.UpdateBrigade();
            changeBrig4Batt.DataSource  = update.UpdateBrigade();
            changeBrig4Equip.DataSource = update.UpdateBrigade();
            MessageBox.Show("Бригада успешно добавлена");
        }
Exemplo n.º 2
0
        //Связываем технику и батальон
        private void updateBatt_Click(object sender, EventArgs e)
        {
            MillitaryDbContext context = new MillitaryDbContext();
            var foundBat = from bat in context.Battalions
                           where bat.Name == chooseBat4Equip.Text
                           select bat;
            //Создаем и заполняем список ВВТ для батальона
            List <EquipmentBattalion> listEquip = new List <EquipmentBattalion>();

            while (dataGridViewAddEquip.RowCount != 1)
            {
                string newName = dataGridViewAddEquip[0, 0].Value.ToString();
                foreach (Equipment eq in context.Equipments)
                {
                    if (eq.Name == newName)
                    {
                        EquipmentBattalion eq2bat = new EquipmentBattalion()
                        {
                            Battalions = foundBat.First(),
                            Equipments = eq,
                            Count      = Convert.ToInt32(dataGridViewAddEquip[1, 0].Value)
                        };
                        listEquip.Add(eq2bat);
                        break;
                    }
                }
                dataGridViewAddEquip.Rows.RemoveAt(0);
            }
            context.EquipmentBattalions.AddRange(listEquip);
            context.SaveChanges();
            MessageBox.Show("Техника успешно добавлена в батальон");
        }
Exemplo n.º 3
0
        //ДОБАВИТЬ ТЕХНИКУ
        private void addEquip_Click(object sender, EventArgs e)
        {
            using (MillitaryDbContext context = new MillitaryDbContext())
            {
                Equipment equipment = new Equipment();
                equipment.Name      = newNameEquip.Text;
                equipment.FullName  = newFullNameEquip.Text;
                equipment.Lenght    = Convert.ToInt32(newLenghtEquip.Text);
                equipment.Mass      = Convert.ToInt32(newMassEquip.Text);
                equipment.TypeEquip = typeEquip.Checked;
                context.Equipments.Add(equipment);
                context.SaveChanges();
            }
            // Обновление источника данных
            UpdateDb up = new UpdateDb();

            lookAllEquip.DataSource = up.UpdateListEquipment();
            newNameEquip.Text       = ""; newFullNameEquip.Text = ""; newLenghtEquip.Text = "0";
            newMassEquip.Text       = "0";
            MessageBox.Show("Техника успешно добавлена");
        }
Exemplo n.º 4
0
        //ДОБАВИТЬ БАТАЛЬОН
        private void addBattalion_Click(object sender, EventArgs e)
        {
            using (MillitaryDbContext context = new MillitaryDbContext())
            {
                foreach (Battalion bat in context.Battalions)
                {
                    if (bat.Name == newNameBattalion.Text)
                    {
                        MessageBox.Show("Батальон с такми названием уже существует!\nИзмените название и попробуйте еще раз!");
                        return;
                    }
                }
                Battalion battalion = new Battalion();
                battalion.Name     = newNameBattalion.Text;
                battalion.Load     = false;
                battalion.Officer  = Convert.ToInt32(newOfficer.Text.ToString());
                battalion.Serjant  = Convert.ToInt32(newSerjant.Text);
                battalion.Soldat   = Convert.ToInt32(newSoldat.Text);
                battalion.Civilian = Convert.ToInt32(newCivilan.Text);
                // Определяем ID выбранной бригады
                foreach (Brigade br in context.Brigades)
                {
                    if (br.Name == changeBrig4Batt.Text)
                    {
                        battalion.BrigadeId = br.BrigadeId;
                        break;
                    }
                }
                context.Battalions.Add(battalion);
                context.SaveChanges();
            }
            //// Обновление источника данных
            UpdateDataGridViewBattalions(chooseBrig1.Text);
            UpdatechangeBrig4Equip(changeBrig4Equip.Text);
            newNameBattalion.Text = ""; newOfficer.Text = "0"; newSerjant.Text = "0";
            newSoldat.Text        = "0"; newCivilan.Text = "0";
            UpdateDb update = new UpdateDb();

            MessageBox.Show("Батальон успешно добавлен");
        }
Exemplo n.º 5
0
        // Создание коллекции батальонов выбранных для погрузки
        public List <BuildnUnit> CreateCollectBatt()//List<string> nameOfBatt)
        {
            List <BuildnUnit>  collBatt4Load = new List <BuildnUnit>();
            MillitaryDbContext context       = new MillitaryDbContext();
            int ii = 0;

            foreach (string batt in nameOfBatt)
            {
                var foundBat = from dumb in context.Battalions
                               where dumb.Name == batt
                               select dumb;
                Battalion          battalion = foundBat.First();
                List <EquipInBatt> collEquip = new List <EquipInBatt>();
                //List<EquipInBatt> collEquipSpec = new List<EquipInBatt>();
                //List<EquipInBatt> collEquipUsual = new List<EquipInBatt>();
                int rgb = 1;
                foreach (EquipmentBattalion eq2bat in context.EquipmentBattalions)
                {
                    if (eq2bat.BattalionId == battalion.BattalionId)
                    {
                        //Задаем новый цвет
                        Color newColor = new Color();
                        newColor = DefineColor(rgb++);
                        EquipInBatt equip = new EquipInBatt(eq2bat.Equipments.Name, newColor, eq2bat.Equipments.Lenght,
                                                            eq2bat.Equipments.Mass, eq2bat.Count, eq2bat.Equipments.TypeEquip);
                        //Отделяем специальную технику от обычной
                        //if (eq2bat.Equipments.TypeEquip) collEquipUsual.Add(equip);
                        //else collEquipSpec.Add(equip);
                        collEquip.Add(equip);
                    }
                }
                BuildnUnit newUnit = new BuildnUnit(++ii, battalion.Name, battalion.Brigade.Name,
                                                    battalion.Officer, battalion.Serjant, battalion.Soldat, battalion.Civilian, collEquip); //collEquipSpec, collEquipUsual);
                collBatt4Load.Add(newUnit);
            }
            return(collBatt4Load);
        }
Exemplo n.º 6
0
        //Вывод информаии о батальоне
        private void battalionsDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int changeCell = battalionsDataGridView.CurrentCellAddress.X;

            if (changeCell == 0)
            {
                viewOficer.Text   = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[2].Value);
                viewSerjant.Text  = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[3].Value);
                viewSoldat.Text   = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[4].Value);
                viewCivilian.Text = Convert.ToString(this.battalionsDataGridView.CurrentRow.Cells[5].Value);
                dataGridViewEquip.Rows.Clear();
                MillitaryDbContext context = new MillitaryDbContext();
                string             qwest   = battalionsDataGridView.CurrentRow.Cells[0].Value.ToString();
                var foundBat = from bat in context.Battalions
                               where bat.Name == qwest
                               select bat;
                Battalion battalion = foundBat.First();
                int       ii        = 0;
                foreach (EquipmentBattalion eq2bat in context.EquipmentBattalions)
                {
                    if (eq2bat.BattalionId == battalion.BattalionId)
                    {
                        dataGridViewEquip.Rows.Add();
                        dataGridViewEquip[0, ii].Value = eq2bat.Equipments.Name;
                        dataGridViewEquip[1, ii].Value = eq2bat.Count;
                        ii++;
                    }
                }



                //List<EquipmentBattalion> eqList = new List<EquipmentBattalion>();
                //eqList = context.EquipmentBattalions.Where(x => x.BattalionId == battalion.BattalionId).ToList();
                //dataGridViewEquip.DataSource = eqList.;
            }
        }