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);
        }
        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();
        }
        private void cmbGenus_Leave(object sender, EventArgs e)
        {
            string text = cmbGenus.Text.Trim();

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

            if (g == null)
            {
                DialogResult dr = MessageBox.Show(cmbGenus.Text + " isminde bir cins bulunamadı yanlış yazdıysanız hayıra basın ve düzeltin. Yanlışlık yoksa kayıt oluşturulsun mu?", "Cins Bulunamadı", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (dr == DialogResult.No)
                {
                    cmbSpecies.Enabled = false; return;
                }

                genus newGenus = new genus();
                newGenus.family = f;
                newGenus.name   = text;
                entities.genus.Add(newGenus);
                entities.SaveChanges();
                id = newGenus.id;
                Log.Debug("[Yeni Cins]: " + text, "ID:" + id + "\nMajor:" + f.major.name + "\nFamilya:" + f.name + "\n->Cins:" + text);
            }
            else
            {
                id = g.id;
            }

            var           list   = entities.synonym.Where(x => x.species.genusid == id).ToList();
            var           list2  = entities.species.Where(x => x.genusid == id).Select(x => x.name).ToList();
            List <string> turler = new List <string>();
            int           turId  = -1;

            foreach (synonym sinonim in list)
            {
                if (sinonim.speciesid != turId)
                {
                    turId = Convert.ToInt32(sinonim.speciesid);
                    turler.Add(sinonim.species.name);
                }
                turler.Add(sinonim.name + " (sinonim)");
            }
            foreach (string tur in list2)
            {
                if (turler.IndexOf(tur) == -1)
                {
                    turler.Add(tur);
                }
            }

            cmbSpecies.DataSource = turler;
            cmbSpecies.Invalidate();
            cmbSpecies.Enabled  = true;
            cmbSpecies.Text     = "";
            lblGenus.Visible    = true;
            lblGenus.Text       = "Cins: " + cmbGenus.Text;
            lblSpeciesName.Text = string.Empty;
        }