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();
            }
        }
示例#2
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();
            }
        }
示例#3
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 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();
            }
        }
示例#5
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();
            }
        }