private void AddForm_Load(object sender, EventArgs e) { nameBox.Text = Generic_Form.chosenhuman.Name; SnameBox.Text = Generic_Form.chosenhuman.SName; FnameBox.Text = Generic_Form.chosenhuman.FName; BornDateBox.Value = Generic_Form.chosenhuman.BornDate; DeathDateBox.Value = Generic_Form.chosenhuman.DeathDate; if (Generic_Form.chosenhuman.Life == false) { LifeBox.Checked = false; } else { LifeBox.Checked = true; } parents = Generic_Form.SearchAllByID(Generic_Form.chosenhuman.Parents, Generic_Form.humanlist); children = Generic_Form.SearchAllByID(Generic_Form.chosenhuman.Children, Generic_Form.humanlist); FolksUpd(); ParentBoxUpdate(); ChildrenBoxUpdate(); }
private void HumanAddButton_Click(object sender, EventArgs e) { string name = nameBox.Text, sname = SnameBox.Text, fname = FnameBox.Text, id = Generic_Form.chosenhuman.ID; DateTime brn = BornDateBox.Value.Date; bool life = LifeBox.Checked; DateTime dth = DeathDateBox.Value.Date; string[] par = new string[2]; if (parents.Count < 3) { for (int i = 0; i < parents.Count; i++) { par[i] = parents[i].ID; } } else { throw new FormatException(Properties.Resources.Error_ParentsQ); } string[] chil = new string[children.Count]; for (int i = 0; i < children.Count; i++) { chil[i] = children[i].ID; } int chq = chil.Length; Human newhuman = null; try { newhuman = new Human(name, sname, fname, brn, life, dth, par, chq, chil, id); } catch (FormatException ex) { MessageBox.Show(ex.Message, "Ошибка"); } if (newhuman != null) { foreach (string s in newhuman.Parents) { if (s != "" && s != null) { if (IdCheck( Generic_Form.humanlist[IndexByID(s, Generic_Form.humanlist)].Children, newhuman.ID)) { string[] temp = Generic_Form.SearchByID(s, Generic_Form.humanlist).Children; Array.Resize(ref temp, temp.Length + 1); temp[temp.Length - 1] = newhuman.ID; Generic_Form.SearchByID(s, Generic_Form.humanlist).Children = temp; } } } foreach (string s in newhuman.Children) { if (s != "" && s != null) { { if (IdCheck(Generic_Form.SearchByID(s, Generic_Form.humanlist).Parents, newhuman.ID) && Generic_Form.SearchByID(s, Generic_Form.humanlist).Parents[0] == null) { Generic_Form.SearchByID(s, Generic_Form.humanlist).Parents[0] = newhuman.ID; } if (IdCheck(Generic_Form.SearchByID(s, Generic_Form.humanlist).Parents, newhuman.ID) && Generic_Form.SearchByID(s, Generic_Form.humanlist).Parents[0] != null && Generic_Form.SearchByID(s, Generic_Form.humanlist).Parents[1] == null) { Generic_Form.SearchByID(s, Generic_Form.humanlist).Parents[1] = newhuman.ID; } } } } Generic_Form.humandb.dblist[IndexByID(newhuman.ID, Generic_Form.humandb.dblist)] = newhuman; Generic_Form.chosenhuman = newhuman; Generic_Form.humandb.Date_Last_Edit = DateTime.Now.Date; Close(); } }