示例#1
0
        // добавление
        private void button2_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                SozyvForm addForm = new SozyvForm();

                List <Deputaty> deps = db.Deputaties.ToList();
                addForm.listBox1.DataSource    = deps;
                addForm.listBox1.ValueMember   = "Partiyniy_bilet";
                addForm.listBox1.DisplayMember = "Familiya";

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                Sozyvy sozyv = new Sozyvy();
                sozyv.Nomer        = 0;
                sozyv.Data_nachala = DateTime.Parse(addForm.maskedTextBox1.Text);
                sozyv.Data_konca   = DateTime.Parse(addForm.maskedTextBox2.Text);
                deps.Clear(); // очищаем список и заново заполняем его выделенными элементами
                foreach (var dep in addForm.listBox1.SelectedItems)
                {
                    deps.Add((Deputaty)dep);
                }
                sozyv.Deputaties = deps;

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Sozyvies.Add(sozyv);

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateException ex)
                        {
                            MessageBox.Show("Ошибка добавления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка добавления : " + ex.ToString());

                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
        public ProcedureForm3()
        {
            InitializeComponent();
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                try
                {
                    var proc = db.GetSozyvyStatus();
                    dataGridView1.DataSource = proc;

                    int     best_soz     = -1;
                    decimal best_results = 0;

                    for (int i = 0; i < dataGridView1.RowCount; i++)
                    {
                        if ((decimal)dataGridView1[4, i].Value > best_results)
                        {
                            best_results = (decimal)dataGridView1[4, i].Value;
                            best_soz     = (int)dataGridView1[0, i].Value;
                        }
                    }
                    label1.Text = "Самый результативный созыв : " + best_soz;
                }
                catch
                {
                    MessageBox.Show("У вас нет прав для использования процедуры");
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                FrakciyaForm addForm = new FrakciyaForm();

                List <Deputaty> deps = db.Deputaties.ToList();
                for (int i = deps.Count - 1; i >= 0; i--)
                {
                    var dep = deps[i];

                    if (dep.Frakciya != null)
                    {
                        deps.RemoveAt(i);
                    }
                }

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                Frakciya frak = new Frakciya();

                frak.Naimenovanie = addForm.textBox1.Text;

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Frakciyas.Add(frak);

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateException ex)
                        {
                            MessageBox.Show("Ошибка добавления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка добавления : " + ex.ToString());

                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
示例#4
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                ZakonoproektForm addForm = new ZakonoproektForm();

                List <Deputaty> deps = db.Deputaties.ToList();
                addForm.comboBox1.DataSource    = deps;
                addForm.comboBox1.ValueMember   = "Partiyniy_bilet";
                addForm.comboBox1.DisplayMember = "Familiya";

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                Zakonoproekt zak = new Zakonoproekt();

                zak.Naimenovanie = addForm.textBox1.Text;
                zak.Opisanie     = addForm.richTextBox1.Text;
                zak.Deputaty     = (Deputaty)addForm.comboBox1.SelectedItem;
                zak.Vnesen       = (int)addForm.comboBox1.SelectedValue;

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Zakonoproekts.Add(zak);

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateException ex)
                        {
                            MessageBox.Show("Ошибка добавления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка добавления : " + ex.ToString());

                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
 public ProcedureForm2()
 {
     InitializeComponent();
     using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
     {
         List <Sozyvy> sozes = db.Sozyvies.ToList();
         comboBox1.DataSource    = sozes;
         comboBox1.ValueMember   = "Nomer";
         comboBox1.DisplayMember = "Nomer";
     }
 }
        private void button4_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                var confirmResult = MessageBox.Show("Вы уверены, что хотите удалить запись?",
                                                    "Подтвердить удаление",
                                                    MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
                    {
                        int  index     = dataGridView1.SelectedRows[0].Index;
                        int  id        = 0;
                        bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                        if (converted == false)
                        {
                            return;
                        }

                        using (var transaction = db.Database.BeginTransaction())
                        {
                            try
                            {
                                var frak = db.Frakciyas
                                           .FirstOrDefault(b => b.ID == id);

                                db.Frakciyas.Remove(frak);

                                try
                                {
                                    db.SaveChanges();
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("Ошибка удаления : " + ex.ToString());
                                }

                                transaction.Commit();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Ошибка удаления : " + ex.ToString());
                                try { transaction.Rollback(); }
                                catch (Exception ex2)
                                {
                                    MessageBox.Show("Ошибка отката : " + ex2.ToString());
                                }
                            }
                        }
                    }
                    RefreshData();
                }
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
     {
         try
         {
             dataGridView1.DataSource = db.FactionsPercentage((int)comboBox1.SelectedValue);
         }
         catch
         {
             MessageBox.Show("У вас нет прав для использования процедуры");
         }
     }
 }
 public void RefreshData()
 {
     using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
     {
         try
         {
             menu.frakciyaData = db.Frakciyas.Select(p => new { p.ID, p.Naimenovanie, p.Kolichestvo_deputatov, p.Deputaty }).ToList();
         }
         catch
         {
             MessageBox.Show("У вас нет прав для просмотра таблицы");
         }
     }
     dataGridView1.DataSource = menu.frakciyaData;
 }
示例#9
0
 public void RefreshData()
 {
     using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
     {
         try
         {
             menu.deputatyData = db.Deputaties.Select(p => new { p.Partiyniy_bilet, p.Familiya, p.Imya, p.Otchestovo, p.Region_vyborov, p.Data_rozhdeniya, p.Frakciya, p.Komitet }).ToList();
         }
         catch
         {
             MessageBox.Show("У вас нет прав для просмотра таблицы");
         }
     }
     dataGridView1.DataSource = menu.deputatyData;
 }
示例#10
0
        public void RefreshData()
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                try
                {
                    menu.sozyvData = db.Sozyvies.Select(p => new { p.Nomer, p.Frakciya, p.Data_nachala, p.Data_konca }).ToList();
                }
                catch
                {
                    MessageBox.Show("У вас нет прав для просмотра таблицы");
                }
            }

            dataGridView1.DataSource = menu.sozyvData;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                if (dataGridView1.SelectedRows.Count > 0)
                {
                    int  index     = dataGridView1.SelectedRows[0].Index;
                    int  id        = 0;
                    bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                    if (converted == false)
                    {
                        return;
                    }

                    Frakciya frak = db.Frakciyas.Find(id);
                    listBox1.DataSource    = frak.Deputaties.ToList();
                    listBox1.DisplayMember = "Familiya";
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            DBUtils.setLoginPassword(textBox1.Text, textBox2.Text); //
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                DbConnection conn = db.Database.Connection;
                try
                {
                    conn.Open(); // проверка соединения
                    Console.WriteLine("Connection success");

                    this.Hide();
                    var form1 = new MenuForm();
                    form1.Closed += (s, args) => this.Close();
                    form1.Show();
                }
                catch // ошибка соединения
                {
                    Console.WriteLine("Сonnection failed");
                    MessageBox.Show("Неправильная пара логин-пароль");
                    textBox2.Text = "";
                }
            }
        }
        public void RefreshData()
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                try
                {
                    db.UpdateSessionStatus();
                }
                catch
                {
                    MessageBox.Show("У вас нет прав для обновления статуса заседаний");
                }

                try
                {
                    menu.zasedaniyaData = db.Zasedanies.Select(p => new { p.Nomer, p.Naimenovanie, p.Tip, p.Nomer_sozyva, p.Data_provedeniya, p.Vremya_nachala, p.Vremya_konca, p.Status_zasedaniya, p.Mesto_provedeniya1 }).ToList();
                }
                catch
                {
                    MessageBox.Show("У вас нет прав для просмотра таблицы");
                }
            }
            dataGridView1.DataSource = menu.zasedaniyaData;
        }
示例#14
0
        private void button3_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                if (dataGridView1.SelectedRows.Count < 1)
                {
                    return;
                }

                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Deputaty dep = db.Deputaties.Find(id);

                DeputatyForm addForm = new DeputatyForm();

                addForm.numericUpDown1.Value = dep.Partiyniy_bilet;
                addForm.textBox2.Text        = dep.Familiya;
                addForm.textBox1.Text        = dep.Imya;
                addForm.textBox3.Text        = dep.Otchestovo;
                addForm.textBox4.Text        = dep.Region_vyborov;
                addForm.maskedTextBox1.Text  = dep.Data_rozhdeniya.ToString();

                // получаем список команд
                List <Sozyvy> sozes = db.Sozyvies.ToList();
                addForm.listBox1.DataSource    = sozes;
                addForm.listBox1.ValueMember   = "Nomer";
                addForm.listBox1.DisplayMember = "Nomer";

                List <Frakciya> frakces = db.Frakciyas.ToList();
                addForm.comboBox1.DataSource    = frakces;
                addForm.comboBox1.ValueMember   = "ID";
                addForm.comboBox1.DisplayMember = "Naimenovanie";

                List <Komitet> kometes = db.Komitets.ToList();
                addForm.comboBox2.DataSource    = kometes;
                addForm.comboBox2.ValueMember   = "ID";
                addForm.comboBox2.DisplayMember = "Naimenovanie";

                foreach (Sozyvy s in dep.Sozyvies)
                {
                    addForm.listBox1.SelectedItem = s;
                }

                addForm.comboBox1.SelectedItem = dep.Frakciya;
                addForm.comboBox2.SelectedItem = dep.Komitet;

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                dep.Partiyniy_bilet = (int)addForm.numericUpDown1.Value;
                dep.Familiya        = addForm.textBox2.Text;
                dep.Imya            = addForm.textBox1.Text;
                dep.Otchestovo      = addForm.textBox3.Text;
                dep.Region_vyborov  = addForm.textBox4.Text;

                dep.Data_rozhdeniya = DateTime.Parse(addForm.maskedTextBox1.Text);

                sozes.Clear(); // очищаем список и заново заполняем его выделенными элементами
                foreach (var soz in addForm.listBox1.SelectedItems)
                {
                    sozes.Add((Sozyvy)soz);
                }
                dep.Sozyvies = sozes;

                foreach (var s in sozes)
                {
                    if (addForm.listBox1.SelectedItems.Contains(s))
                    {
                        if (!dep.Sozyvies.Contains(s))
                        {
                            dep.Sozyvies.Add(s);
                        }
                    }
                    else
                    {
                        if (dep.Sozyvies.Contains(s))
                        {
                            dep.Sozyvies.Remove(s);
                        }
                    }
                }

                dep.Frakciya   = (Frakciya)addForm.comboBox1.SelectedItem;
                dep.ID_frakcii = (int)addForm.comboBox1.SelectedValue;

                dep.Komitet     = (Komitet)addForm.comboBox2.SelectedItem;
                dep.ID_komiteta = (int)addForm.comboBox2.SelectedValue;

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Entry(dep).State = EntityState.Modified;

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                if (dataGridView1.SelectedRows.Count < 1)
                {
                    return;
                }

                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Frakciya frak = db.Frakciyas.Find(id);

                FrakciyaForm addForm = new FrakciyaForm();

                addForm.textBox1.Text = frak.Naimenovanie;

                List <Deputaty> deps = db.Deputaties.ToList();
                for (int i = deps.Count - 1; i >= 0; i--)
                {
                    if (deps[i].ID_frakcii != id)
                    {
                        deps.RemoveAt(i);
                    }
                }

                addForm.comboBox1.DataSource    = deps;
                addForm.comboBox1.ValueMember   = "Partiyniy_bilet";
                addForm.comboBox1.DisplayMember = "Familiya";

                addForm.comboBox1.SelectedItem = frak.Lider_frakcii;

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                frak.Naimenovanie = addForm.textBox1.Text;
                if (addForm.comboBox1.SelectedItem != null)
                {
                    frak.Deputaty = (Deputaty)addForm.comboBox1.SelectedItem;
                }
                else
                {
                    frak.Deputaty = null;
                }
                if (addForm.comboBox1.SelectedValue != null)
                {
                    frak.Lider_frakcii = (int)addForm.comboBox1.SelectedValue;
                }
                else
                {
                    frak.Lider_frakcii = null;
                }

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Entry(frak).State = EntityState.Modified;

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
示例#16
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                DeputatyForm addForm = new DeputatyForm();

                List <Sozyvy> sozes = db.Sozyvies.ToList();
                addForm.listBox1.DataSource    = sozes;
                addForm.listBox1.ValueMember   = "Nomer";
                addForm.listBox1.DisplayMember = "Nomer";

                List <Frakciya> frakces = db.Frakciyas.ToList();
                addForm.comboBox1.DataSource    = frakces;
                addForm.comboBox1.ValueMember   = "ID";
                addForm.comboBox1.DisplayMember = "Naimenovanie";

                List <Komitet> kometes = db.Komitets.ToList();
                addForm.comboBox2.DataSource    = kometes;
                addForm.comboBox2.ValueMember   = "ID";
                addForm.comboBox2.DisplayMember = "Naimenovanie";

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                Deputaty dep = new Deputaty();
                dep.Partiyniy_bilet = (int)addForm.numericUpDown1.Value;
                dep.Familiya        = addForm.textBox2.Text;
                dep.Imya            = addForm.textBox1.Text;
                dep.Otchestovo      = addForm.textBox3.Text;
                dep.Region_vyborov  = addForm.textBox4.Text;

                dep.Data_rozhdeniya = DateTime.Parse(addForm.maskedTextBox1.Text);

                sozes.Clear(); // очищаем список и заново заполняем его выделенными элементами
                foreach (var soz in addForm.listBox1.SelectedItems)
                {
                    sozes.Add((Sozyvy)soz);
                }
                dep.Sozyvies = sozes;

                dep.Frakciya   = (Frakciya)addForm.comboBox1.SelectedItem;
                dep.ID_frakcii = (int)addForm.comboBox1.SelectedValue;

                dep.Komitet     = (Komitet)addForm.comboBox2.SelectedItem;
                dep.ID_komiteta = (int)addForm.comboBox2.SelectedValue;

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Deputaties.Add(dep);

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateException ex)
                        {
                            MessageBox.Show("Ошибка добавления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка добавления : " + ex.ToString());

                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
示例#17
0
        private void button3_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                if (dataGridView1.SelectedRows.Count < 1)
                {
                    return;
                }

                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Zakonoproekt     zak     = db.Zakonoproekts.Find(id);
                ZakonoproektForm addForm = new ZakonoproektForm();

                addForm.textBox1.Text     = zak.Naimenovanie;
                addForm.richTextBox1.Text = zak.Opisanie;

                List <Deputaty> deps = db.Deputaties.ToList();

                addForm.comboBox1.DataSource    = deps;
                addForm.comboBox1.ValueMember   = "Partiyniy_bilet";
                addForm.comboBox1.DisplayMember = "Familiya";

                addForm.comboBox1.SelectedItem = zak.Deputaty;

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                zak.Naimenovanie = addForm.textBox1.Text;
                zak.Opisanie     = addForm.richTextBox1.Text;
                zak.Deputaty     = (Deputaty)addForm.comboBox1.SelectedItem;
                zak.Vnesen       = (int)addForm.comboBox1.SelectedValue;

                using (var transaction = db.Database.BeginTransaction()) {
                    try {
                        db.Entry(zak).State = EntityState.Modified;
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex) {
                        MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
示例#18
0
        private void button3_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                if (dataGridView1.SelectedRows.Count < 1)
                {
                    return;
                }

                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Sozyvy sozyv = db.Sozyvies.Find(id);

                SozyvForm addForm = new SozyvForm();

                addForm.maskedTextBox1.Text = sozyv.Data_nachala.ToString();
                addForm.maskedTextBox2.Text = sozyv.Data_konca.ToString();

                // получаем список команд
                List <Deputaty> deps = db.Deputaties.ToList();
                addForm.listBox1.DataSource    = deps;
                addForm.listBox1.ValueMember   = "Partiyniy_bilet";
                addForm.listBox1.DisplayMember = "Familiya";

                foreach (Deputaty d in sozyv.Deputaties)
                {
                    addForm.listBox1.SelectedItem = d;
                }

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                sozyv.Data_nachala = DateTime.Parse(addForm.maskedTextBox1.Text);
                sozyv.Data_konca   = DateTime.Parse(addForm.maskedTextBox2.Text);
                deps.Clear(); // очищаем список и заново заполняем его выделенными элементами
                foreach (var dep in addForm.listBox1.SelectedItems)
                {
                    deps.Add((Deputaty)dep);
                }
                sozyv.Deputaties = deps;

                foreach (var d in deps)
                {
                    if (addForm.listBox1.SelectedItems.Contains(d))
                    {
                        if (!sozyv.Deputaties.Contains(d))
                        {
                            sozyv.Deputaties.Add(d);
                        }
                    }
                    else
                    {
                        if (sozyv.Deputaties.Contains(d))
                        {
                            sozyv.Deputaties.Remove(d);
                        }
                    }
                }

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Entry(sozyv).State = EntityState.Modified;

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }

                RefreshData();
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                ZasedaniyaForm addForm = new ZasedaniyaForm();

                List <Sozyvy> sozes = db.Sozyvies.ToList();
                addForm.comboBox1.DataSource    = sozes;
                addForm.comboBox1.ValueMember   = "Nomer";
                addForm.comboBox1.DisplayMember = "Nomer";

                List <Mesto_provedeniya> mesta = db.Mesto_provedeniya.ToList();
                addForm.comboBox2.DataSource    = mesta;
                addForm.comboBox2.ValueMember   = "ID";
                addForm.comboBox2.DisplayMember = "Ulica";

                addForm.radioButton1.Checked = true;
                addForm.radioButton2.Checked = false;

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                Zasedanie zased = new Zasedanie();
                zased.Nomer        = 0;
                zased.Naimenovanie = addForm.textBox1.Text;

                zased.Data_provedeniya = DateTime.Parse(addForm.maskedTextBox1.Text);
                zased.Vremya_nachala   = TimeSpan.Parse(addForm.maskedTextBox2.Text);
                zased.Vremya_konca     = TimeSpan.Parse(addForm.maskedTextBox3.Text);

                if (addForm.radioButton1.Checked)
                {
                    zased.Tip = addForm.radioButton1.Text;
                }
                else
                {
                    zased.Tip = addForm.radioButton2.Text;
                }

                zased.Nomer_sozyva = (int)addForm.comboBox1.SelectedValue;
                zased.Sozyvy       = (Sozyvy)addForm.comboBox1.SelectedItem;

                zased.Mesto_provedeniya  = (int)addForm.comboBox2.SelectedValue;
                zased.Mesto_provedeniya1 = (Mesto_provedeniya)addForm.comboBox2.SelectedItem;

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Zasedanies.Add(zased);

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (DbUpdateException ex)
                        {
                            MessageBox.Show("Ошибка добавления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка добавления : " + ex.ToString());

                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            using (The_State_Duma_Entities db = new The_State_Duma_Entities(DBUtils.getConnString()))
            {
                if (dataGridView1.SelectedRows.Count < 1)
                {
                    return;
                }

                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Zasedanie zased = db.Zasedanies.Find(id);

                ZasedaniyaForm addForm = new ZasedaniyaForm();

                addForm.textBox1.Text       = zased.Naimenovanie;
                addForm.maskedTextBox1.Text = zased.Data_provedeniya.ToString();
                addForm.maskedTextBox2.Text = zased.Vremya_nachala.ToString();
                addForm.maskedTextBox3.Text = zased.Vremya_konca.ToString();

                List <Sozyvy> sozes = db.Sozyvies.ToList();
                addForm.comboBox1.DataSource    = sozes;
                addForm.comboBox1.ValueMember   = "Nomer";
                addForm.comboBox1.DisplayMember = "Nomer";

                List <Mesto_provedeniya> mesta = db.Mesto_provedeniya.ToList();
                addForm.comboBox2.DataSource    = mesta;
                addForm.comboBox2.ValueMember   = "ID";
                addForm.comboBox2.DisplayMember = "Ulica";

                addForm.comboBox1.SelectedItem = zased.Sozyvy;
                addForm.comboBox2.SelectedItem = zased.Mesto_provedeniya1;

                if (zased.Tip == "Plenarnoe Zasedanie" || zased.Tip == "Пленарное заседание")
                {
                    addForm.radioButton1.Checked = true;
                }
                else if (zased.Tip == "Заседание совета ГД")
                {
                    addForm.radioButton2.Checked = true;
                }

                DialogResult result = addForm.ShowDialog(this);

                if (result == DialogResult.Cancel)
                {
                    return;
                }

                zased.Naimenovanie     = addForm.textBox1.Text;
                zased.Data_provedeniya = DateTime.Parse(addForm.maskedTextBox1.Text);
                zased.Vremya_nachala   = TimeSpan.Parse(addForm.maskedTextBox2.Text);
                zased.Vremya_konca     = TimeSpan.Parse(addForm.maskedTextBox3.Text);
                if (addForm.radioButton1.Checked)
                {
                    zased.Tip = addForm.radioButton1.Text;
                }
                else
                {
                    zased.Tip = addForm.radioButton2.Text;
                }

                zased.Nomer_sozyva = (int)addForm.comboBox1.SelectedValue;
                zased.Sozyvy       = (Sozyvy)addForm.comboBox1.SelectedItem;

                zased.Mesto_provedeniya  = (int)addForm.comboBox2.SelectedValue;
                zased.Mesto_provedeniya1 = (Mesto_provedeniya)addForm.comboBox2.SelectedItem;

                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Entry(zased).State = EntityState.Modified;

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибка обновления : " + ex.ToString());
                        try { transaction.Rollback(); }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Ошибка отката : " + ex2.ToString());
                        }
                    }
                }
                RefreshData();
            }
        }