private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells["scientistIdDataGridViewTextBoxColumn"].Value);

            // updating
            if (e.ColumnIndex == 6)
            {
                formDTO.op = CrudOpr.Update;

                ViewScientist findScientist = dataFormDTO.db.ViewScientists.SingleOrDefault(o => o.scientistId == id);
                formDTO.obj = findScientist;

                CreateUpdateScientistForm form = new CreateUpdateScientistForm(this, formDTO);
                form.Show();

                dataGridView1.DataSource = dataFormDTO.db.ViewScientists.ToList();
            }

            // deleting
            if (e.ColumnIndex == 7)
            {
                // Запрашиваем подтверждение
                string message = "Do you want to delete?";
                string caption = "Y/n";
                var    result  = MessageBox.Show(message, caption,
                                                 MessageBoxButtons.YesNo,
                                                 MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    scientist s = new scientist();
                    s.scientistId = id;
                    // deleting
                    if (crud.delete(s))
                    {
                        MessageBox.Show("Scientist was deleted!");
                        resetData();
                    }
                    else
                    {
                        MessageBox.Show("Deleting was denied");
                    }
                }
            }
        }
        public override participant create(participant obj)
        {
            participant p =
                db.participants.Where(o => o.participantId == obj.participantId).FirstOrDefault();

            if (p != null)
            {
                // obj is alredy existed
                return(null);
            }
            else
            {
                scientist s = (scientist)db.scientists.Find(obj.scientist);

                obj.scientist1 = s;

                db.participants.Add(obj);
                db.SaveChanges();
                return(obj);
            }
        }
示例#3
0
        private void doCrud()
        {
            scientist s = new scientist();

            s.firstName      = dto.firstName;
            s.secondName     = dto.secondName;
            s.academicDegree = dto.degree;
            s.company        = dto.company;
            s.country        = dto.country;

            switch (crudOp)
            {
            // create
            case CrudOpr.Create:
                if (crud.create(s) != null)
                {
                    MessageBox.Show("Scientist was added!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Adding was denied");
                }
                break;

            case CrudOpr.Update:
                s.scientistId = formDTO.obj.scientistId;
                if (crud.update(s))
                {
                    MessageBox.Show("Scientist was updated!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Updating was denied");
                }
                break;
            }
        }