예제 #1
0
        private int AddNewRowToTable(string name)
        {
            int id = -1;

            switch ((Types)tabControl1.SelectedIndex)
            {
            case Types.Family:
                family obj = new family {
                    name = name, majorid = Selections[Types.Major].Id
                };
                entities.family.Add(obj);
                id = obj.id;
                break;

            case Types.Genus:
                genus obj2 = new genus {
                    name = name, familyid = Selections[Types.Family].Id
                };
                entities.genus.Add(obj2);
                id = obj2.id;
                break;

            case Types.Species:
                species obj3 = new species {
                    name = name, genusid = Selections[Types.Genus].Id
                };
                entities.species.Add(obj3);
                id = obj3.id;
                break;

            case Types.Synonym:
                synonym obj4 = new synonym {
                    name = name, speciesid = Selections[Types.Species].Id
                };
                entities.synonym.Add(obj4);
                id = obj4.id;
                break;

            default:
                major obj5 = new major {
                    name = name
                };
                entities.major.Add(obj5);
                id = obj5.id;
                break;
            }

            entities.SaveChanges();
            GridView.CurrentRow.Cells[0].Value = id;
            Selections[(Types)tabControl1.SelectedIndex].Id = id;
            return(id);
        }
예제 #2
0
        private void cmbSpecies_Leave(object sender, EventArgs e)
        {
            string text = cmbSpecies.Text.Trim().Replace(" (sinonim)", "");

            if (text == string.Empty || text.Contains("DynamicProxies"))
            {
                _plant.speciesid = null;
                return;
            }
            int   id = -1;
            genus g  = entities.genus.Where(x => x.name == cmbGenus.Text).FirstOrDefault();

            species s  = entities.species.Where(x => x.name == text).FirstOrDefault();
            synonym sy = entities.synonym.Where(x => x.name == text).FirstOrDefault();

            _plant.issynonym = false;

            if (s != null)
            {
                id = s.id;
            }
            else if (sy != null)
            {
                id = sy.id;
                _plant.issynonym = true;
            }
            else
            {
                DialogResult dr = MessageBox.Show(cmbSpecies.Text + " isminde bir tür bulunamadı yanlış yazdıysanız hayıra basın ve düzeltin. Yanlışlık yoksa kayıt oluşturulsun mu?", "Tür Bulunamadı", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dr == DialogResult.No)
                {
                    return;
                }

                species newSpecies = new species();
                newSpecies.genus = g;
                newSpecies.name  = text;
                entities.species.Add(newSpecies);
                entities.SaveChanges();
                id = newSpecies.id;
                Log.Debug("[Yeni Tür]: " + text, "ID:" + id + "\nMajor:" + newSpecies.genus.family.major.name + "\nFamilya:" + newSpecies.genus.family.name + "\nCins:" + newSpecies.genus.name + "\n->Cins:" + text);
            }

            _plant.speciesid = id;

            plantName = cmbSpecies.Text;
            generateSpeciesLabel();
        }