示例#1
0
        private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var currentRow = dataGridView.CurrentRow;

            if (currentRow != null)
            {
                FormElementEmployees formElementEmployees = new FormElementEmployees();
                int       idEmployees = Int32.Parse(currentRow.Cells["id"].Value.ToString());
                Employees Employees   = db.Employees.Find(idEmployees);


                formElementEmployees.textBoxId.Text       = currentRow.Cells["id"].Value.ToString();
                formElementEmployees.textBoxEmail.Text    = currentRow.Cells["email"].Value.ToString();
                formElementEmployees.textBoxFIO.Text      = currentRow.Cells["fio"].Value.ToString();
                formElementEmployees.textBoxPosition.Text = currentRow.Cells["position"].Value.ToString();
                formElementEmployees.textBoxPhone.Text    = currentRow.Cells["phone"].Value.ToString();


                DialogResult result = formElementEmployees.ShowDialog(this);
                if (result == DialogResult.OK && Employees != null)
                {
                    Employees.email    = formElementEmployees.textBoxEmail.Text.ToString();
                    Employees.fio      = formElementEmployees.textBoxFIO.Text.ToString();
                    Employees.position = formElementEmployees.textBoxPosition.Text.ToString();
                    Employees.phone    = formElementEmployees.textBoxPhone.Text.ToString();

                    db.SaveChanges();
                    checkFilter();
                    dataGridView.Refresh();
                }
            }
        }
示例#2
0
        private void buttonCreate_Click(object sender, EventArgs e)
        {
            FormElementEmployees formElementEmployees = new FormElementEmployees();
            DialogResult         result = formElementEmployees.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                Employees Employees = new Employees();
                Employees.email    = formElementEmployees.textBoxEmail.Text.ToString();
                Employees.fio      = formElementEmployees.textBoxFIO.Text.ToString();
                Employees.position = formElementEmployees.textBoxPosition.Text.ToString();
                Employees.phone    = formElementEmployees.textBoxPhone.Text.ToString();

                db.Employees.Add(Employees);
                db.SaveChanges();
                checkFilter();
                dataGridView.Refresh();
            }
        }