示例#1
0
文件: FormMain.cs 项目: han6man/EF6
        private void toolStripButtonMuacaEdit_Click(object sender, EventArgs e)
        {
            if (dataGridViewMuacot.SelectedRows.Count > 0)
            {
                int  index = dataGridViewMuacot.SelectedRows[0].Index;
                int  muaca_ezorit_code;
                bool converted = Int32.TryParse(dataGridViewMuacot[0, index].Value.ToString(), out muaca_ezorit_code);
                if (converted == false)
                {
                    return;
                }

                Regional_Council muaca = db.Regional_Councils.Find(muaca_ezorit_code);

                FormMuaca formMuaca = new FormMuaca();
                formMuaca.textBoxMuacaCode.Text    = muaca.Regional_Council_Code.ToString();
                formMuaca.textBoxMuacaName.Text    = muaca.Regional_Council_Name;
                formMuaca.textBoxMuacaCode.Enabled = false;

                DialogResult result = formMuaca.ShowDialog(this);

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

                muaca.Regional_Council_Name = formMuaca.textBoxMuacaName.Text;

                db.SaveChanges();

                dataGridViewMuacot.Refresh(); // обновляем грид

                MessageBox.Show("Object updated");
            }
        }
示例#2
0
文件: FormMain.cs 项目: han6man/EF6
        private void toolStripButtonMuacaAdd_Click(object sender, EventArgs e)
        {
            FormMuaca    formMuaca = new FormMuaca();
            DialogResult result    = formMuaca.ShowDialog(this);

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

            Regional_Council muaca = new Regional_Council();
            int  muaca_ezorit_code;
            bool converted = Int32.TryParse(formMuaca.textBoxMuacaCode.Text, out muaca_ezorit_code);

            if (converted == false)
            {
                return;
            }
            muaca.Regional_Council_Code = muaca_ezorit_code;
            muaca.Regional_Council_Name = formMuaca.textBoxMuacaName.Text;

            db.Regional_Councils.Add(muaca);
            db.SaveChanges();

            MessageBox.Show("New object added");
        }