private void ResetParents() { ParentsEntry.Items.Clear(); ParentsEntry.Items.Add("-Parents not listed"); ParentsEntry.SelectedIndex = 0; for (int i = 1; i < MainW.GetNumParents(); i++) { Couples Current = MainW.GetParentsFromParentList(i); string Entry = ""; if (LastNameEntry.Text != "") { if ((MainW.GetLastName(Current.GetFatherNumber()) == LastNameEntry.Text) || (MainW.GetMaidenName(Current.GetMotherNumber()) == LastNameEntry.Text) || (MainW.GetLastName(Current.GetMotherNumber()) == LastNameEntry.Text)) { if (Current.GetFatherNumber() == 0) { Entry += "[" + Current.GetMotherNumber().ToString("00000") + "] - " + MainW.GetLastName(Current.GetMotherNumber()) + ", " + MainW.GetFirstName(Current.GetMotherNumber()); } else if (Current.GetMotherNumber() == 0) { Entry += "[" + Current.GetFatherNumber().ToString("00000") + "] - " + MainW.GetLastName(Current.GetFatherNumber()) + ", " + MainW.GetFirstName(Current.GetFatherNumber()); } else { Entry += "[" + Current.GetFatherNumber().ToString("00000") + ", " + Current.GetMotherNumber().ToString("00000") + "] - " + MainW.GetLastName(Current.GetFatherNumber()) + ", " + MainW.GetFirstName(Current.GetFatherNumber()) + " and " + MainW.GetFirstName(Current.GetMotherNumber()); } ParentsEntry.Items.Add(Entry); } } } }
/// <summary> /// Initialize the main form. /// Also creates new instances for all of the declared objects of the form. /// </summary> public MainWindow() { InitializeComponent(); FamTree = new List <TreeNode>(); CurrentFamNode = new TreeNode(); FamTree.Add(CurrentFamNode); Couples PlaceHolder = new Couples(0, true); ParentsList.Add(PlaceHolder); }
public TreeNode(int R, string Fn, string Mn, string Ln, string Mdn, List <string> Prev, DateTime Bir, DateTime Dea, bool Mal, int Sp, Couples C) { Record = R; SetName(Fn, Mn, Ln, Mdn); PreviousNames = Prev; Birth = Bir; Death = Dea; IsMale = Mal; Spouse = Sp; Parents = C; }
/// <summary> /// Resets all objects in the main form. /// </summary> /// <remarks> /// Used when the New or Open options of the menu strip are selected. /// </remarks> public void Reset() { RecNum = 1; FamTree.Clear(); CurrentFamNode = new TreeNode(); FamTree.Add(CurrentFamNode); ParentsList.Clear(); Couples PlaceHolder = new Couples(0, true); ParentsList.Add(PlaceHolder); CurrentFile = ""; }
private void AddSubmit_Click(object sender, EventArgs e) { //Variable declarations string FN = "", MN = "", LN = "", MdN = ""; bool IsMale = true, flag = false; List <int> FlagList = new List <int>(); List <int> Kid = new List <int>(); List <string> PrevNames = new List <string>(); int SpouseNum = 0, TempKid = 0; Couples C = new Couples(); FN = FirstNameEntry.Text; MN = MiddleNameEntry.Text; LN = LastNameEntry.Text; MdN = MaidenNameEntry.Text; DateTime BDay = DoBEntry.Value; DateTime DDay = DateTime.MinValue; // Validity checking on name fields if (FN == "") { flag = true; FlagList.Add(1); FNLabel.ForeColor = System.Drawing.Color.Red; } else if (!(FN.All(Char.IsLetter))) { flag = true; FNLabel.ForeColor = System.Drawing.Color.Red; FlagList.Add(2); } else { FNLabel.ForeColor = System.Drawing.Color.Black; } if (LN == "") { flag = true; FlagList.Add(3); LNLabel.ForeColor = System.Drawing.Color.Red; } else if (!(LN.All(Char.IsLetter))) { flag = true; LNLabel.ForeColor = System.Drawing.Color.Red; bool exists = false; for (int i = 0; i < FlagList.Count(); i++) { if (FlagList[i] == 2) { exists = true; } } if (!exists) { FlagList.Add(2); } } else { LNLabel.ForeColor = System.Drawing.Color.Black; } if (!(MN.All(c => Char.IsLetter(c) || c == ' '))) { MNLabel.ForeColor = System.Drawing.Color.Red; flag = true; bool exists = false; for (int i = 0; i < FlagList.Count(); i++) { if (FlagList[i] == 2) { exists = true; } } if (!exists) { FlagList.Add(2); } } else { MNLabel.ForeColor = System.Drawing.Color.Black; } if (!(MdN.All(Char.IsLetter))) { MdNLabel.ForeColor = System.Drawing.Color.Red; flag = true; bool exists = false; for (int i = 0; i < FlagList.Count(); i++) { if (FlagList[i] == 2) { exists = true; } } if (!exists) { FlagList.Add(2); } } else { MNLabel.ForeColor = System.Drawing.Color.Black; } // Gender validity checking if (MaleButton.Checked) { IsMale = true; GenderLabel.ForeColor = System.Drawing.Color.Black; } else if (FemaleButton.Checked) { IsMale = false; GenderLabel.ForeColor = System.Drawing.Color.Black; } else { flag = true; FlagList.Add(4); GenderLabel.ForeColor = System.Drawing.Color.Red; } if (IsDeceased.Checked == true) { if (DoBEntry.Value.Date > DoDEntry.Value.Date) { flag = true; FlagList.Add(5); DoDLabel.ForeColor = System.Drawing.Color.Red; } else { DoDLabel.ForeColor = System.Drawing.Color.Black; DDay = DoDEntry.Value; } } // Store selected kids in temp list. foreach (int pers in KidsEntry.CheckedIndices) { TempKid = int.Parse(KidsEntry.Items[pers].ToString().Substring(1, 5)); Kid.Add(TempKid); } for (int i = 0; i < SpouseKidsDisplay.Items.Count; i++) { TempKid = int.Parse(SpouseKidsDisplay.Items[i].ToString().Substring(1, 5)); Kid.Add(TempKid); } if ((SpouseEntry.SelectedIndex == 0) && (ParentsEntry.SelectedIndex == 0) && (KidsEntry.CheckedIndices.Count == 0) && (MainW.GetRecordNum() != 1)) { flag = true; FlagList.Add(6); } // If no error thrown, commmit changes. if (!flag) { for (int i = 0; i < PreviousNamesList.Items.Count; i++) { PrevNames.Add(PreviousNamesList.Items[i].ToString()); } if (ParentsEntry.SelectedIndex > 0) { for (int i = 1; i < MainW.GetNumParents(); i++) { if (int.Parse(ParentsEntry.Text.Substring(1, 5)) == MainW.GetParentsFromParentList(i).GetFatherNumber() || (int.Parse(ParentsEntry.Text.Substring(1, 5)) == MainW.GetParentsFromParentList(i).GetMotherNumber())) { C = MainW.GetParentsFromParentList(i); break; } } } if (SpouseEntry.SelectedIndex > 0) { SpouseNum = int.Parse(SpouseEntry.Text.Substring(1, 5)); if (MainW.GetLastName(SpouseNum) != LN) { if (IsMale) { MainW.SetMaidenName(SpouseNum, MainW.GetLastName(SpouseNum)); MainW.SetLastName(SpouseNum, LN); } else { MdN = LN; LN = MainW.GetLastName(SpouseNum); } } } MainW.AddNewRecord(MainW.GetRecordNum(), FN, MN, LN, MdN, PrevNames, BDay, DDay, IsMale, SpouseNum, C, Kid); Success Succ = new Success(); Succ.ShowDialog(); MainW.Enable_Menu(); MainW.NextRec(); this.Close(); } // If any errors were thrown display them and ignore the submit request. else { ShowErrors(FlagList); } }
public void SetParents(Couples Par) { Parents = Par; }
private void OpenToolStripMenuItem_Click(object sender, EventArgs e) { bool Accept = true; if (RecNum > 1) { if (MessageBox.Show("Doing this will erase all current data", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { Accept = false; } } if (Accept) { if (Application.OpenForms.Count > 1) { Application.OpenForms[1].Close(); Enable_Menu(); } Reset(); string FamData; byte[] ToDecrypt; OpenFileDialog Opened = new OpenFileDialog { AddExtension = true, DefaultExt = "gen", Filter = "Genealogy Document (*.gen)|*.gen" }; if (Opened.ShowDialog() == DialogResult.OK) { CurrentFile = Opened.FileName; ToDecrypt = System.IO.File.ReadAllBytes(Opened.FileName); AesCryptoServiceProvider Crypto = new AesCryptoServiceProvider { BlockSize = 128, KeySize = 256, Key = System.Text.Encoding.ASCII.GetBytes("abcdefghijklmnop"), IV = System.Text.Encoding.ASCII.GetBytes("zyxwvutsrqponmlk"), Padding = PaddingMode.PKCS7, Mode = CipherMode.CBC }; ICryptoTransform CryptoTrans = Crypto.CreateDecryptor(Crypto.Key, Crypto.IV); byte[] DeCrypted = CryptoTrans.TransformFinalBlock(ToDecrypt, 0, ToDecrypt.Length); FamData = System.Text.Encoding.ASCII.GetString(DeCrypted); int i = 0, NextStop = 0, Count = 0; string FirstN, MiddleN, LastN, MaidenN, ParentsParse; DateTime TempBDay = DateTime.MinValue, TempDDay = DateTime.MinValue; CultureInfo ThisCulture = CultureInfo.InvariantCulture; Couples TempParents; List <int> TempKids, TempSibs; do { TempParents = new Couples(); FirstN = MiddleN = LastN = MaidenN = ""; TreeNode LoadNode = new TreeNode(); TempKids = new List <int>(); TempSibs = new List <int>(); LoadNode.SetRecord(int.Parse(FamData.Substring(i, 5))); i += 5; NextStop = FamData.IndexOf('|', NextStop + 1); FirstN = FamData.Substring(i, NextStop - i); i = NextStop + 1; NextStop = FamData.IndexOf('|', NextStop + 1); if (i != NextStop) { MiddleN = FamData.Substring(i, NextStop - i); } i = NextStop + 1; NextStop = FamData.IndexOf('|', NextStop + 1); if (i != NextStop) { MaidenN = FamData.Substring(i, NextStop - i); } i = NextStop + 1; NextStop = FamData.IndexOf('|', NextStop + 1); LastN = FamData.Substring(i, NextStop - i); i = NextStop + 1; LoadNode.SetName(FirstN, MiddleN, LastN, MaidenN); if (FamData[i] == 'F') { LoadNode.SetGender(false); } else { LoadNode.SetGender(true); } i++; LoadNode.SetDoB(DateTime.ParseExact(FamData.Substring(i, 8), "MMddyyyy", ThisCulture)); i += 8; LoadNode.SetDoD(DateTime.ParseExact(FamData.Substring(i, 8), "MMddyyyy", ThisCulture)); i += 8; LoadNode.SetSpouse(int.Parse(FamData.Substring(i, 5))); i += 5; ParentsParse = FamData.Substring(i, 10); i += 10; if (ParentsParse == "0000000000") { LoadNode.SetParents(TempParents); } else { TempParents.SetFatherNumber(int.Parse(ParentsParse.Substring(0, 5))); TempParents.SetMotherNumber(int.Parse(ParentsParse.Substring(5, 5))); LoadNode.SetParents(TempParents); } if (FamData[i] == 'N') { i++; } else { i++; NextStop = FamData.IndexOf('|', NextStop + 1); Count = int.Parse(FamData.Substring(i, NextStop - i)); i = NextStop + 1; for (int j = 1; j <= Count; j++) { TempKids.Add(int.Parse(FamData.Substring(i, 5))); i += 5; } } if (FamData[i] == 'N') { i++; } else { i++; NextStop = FamData.IndexOf('|', NextStop + 1); Count = int.Parse(FamData.Substring(i, NextStop - i)); for (int j = 1; j <= Count; j++) { TempSibs.Add(int.Parse(FamData.Substring(i, 5))); i += 5; } } LoadNode.SetChildren(TempKids); LoadNode.SetSiblings(TempSibs); FamTree.Add(LoadNode); RecNum++; }while (FamData.Length != i); Couples TempCoup; foreach (TreeNode j in FamTree) { if (j.GetGend()) { TempCoup = new Couples(); TempCoup.SetFatherNumber(j.GetRecord()); TempCoup.SetMotherNumber(j.GetSpouse()); ParentsList.Add(TempCoup); } else if (j.GetSpouse() == 0) { TempCoup = new Couples(); TempCoup.SetMotherNumber(j.GetRecord()); TempCoup.SetFatherNumber(0); ParentsList.Add(TempCoup); } } MessageBox.Show("Successfully loaded!", "Loaded", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } this.Refresh(); }
/// <summary> /// Adds a new record to the record list. /// </summary> /// <remarks> /// Called upon successful completion of a <c>NewRecord</c> form. /// </remarks> /// <param name="R">The current record number.</param> /// <param name="Fn">String containing first name.</param> /// <param name="Mn">String containing middle name.</param> /// <param name="Ln">String containing last name.</param> /// <param name="Mdn">String containing maiden name.</param> /// <param name="Prev">List of strings containing any previous last names used.</param> /// <param name="Bir">Datetimne containing the date of birth.</param> /// <param name="Dea">Datetime containing the date of death.</param> /// <param name="Mal">Bool representing gender (true for male).</param> /// <param name="Sp">The listed spouse's record number.</param> /// <param name="C">A <c>Couples</c> containing the listed parents.</param> /// <param name="K">A list of the record numbers of the listed children.</param> public void AddNewRecord(int R, string Fn, string Mn, string Ln, string Mdn, List <string> Prev, DateTime Bir, DateTime Dea, bool Mal, int Sp, Couples C, List <int> K) { // Add the results from the NewRecord form to the list of records. CurrentFamNode = new TreeNode(R, Fn, Mn, Ln, Mdn, Prev, Bir, Dea, Mal, Sp, C); FamTree.Add(CurrentFamNode); // Add this record to the list of couples. LogParent(R, Sp, Mal); // Add this record as a kid to the parent's kid list if parents are listed. if ((C.GetFatherNumber() != 0) || (C.GetMotherNumber() != 0)) { // Add to father. if (C.GetFatherNumber() != 0) { List <int> TempChildren = FamTree[C.GetFatherNumber()].GetChildren(); bool found = false; for (int i = 0; i < TempChildren.Count; i++) { if (TempChildren[i] == R) { found = true; } } if (!found) { TempChildren.Add(R); } } // Add to mother. if (C.GetMotherNumber() != 0) { List <int> TempChildren = FamTree[C.GetMotherNumber()].GetChildren(); bool found = false; for (int i = 0; i < TempChildren.Count; i++) { if (TempChildren[i] == R) { found = true; } } if (!found) { TempChildren.Add(R); } } } // If kids were listed add them to this record then set this record as a parent for each kid. if (K.Count != 0) { SetChildren(K, R); Couples TempPar = new Couples(); for (int j = 1; j < ParentsList.Count; j++) { if (Mal) { if (ParentsList[j].GetFatherNumber() == R) { TempPar = ParentsList[j]; } } else { if (ParentsList[j].GetMotherNumber() == R) { TempPar = ParentsList[j]; } } } for (int i = 0; i < K.Count; i++) { FamTree[K[i]].SetParents(TempPar); } } // If spouse was listed set this record as the spouse's spouse then share both spouse's listed kids. // (May need to verify that both spouses end up with the same kids list). if (Sp != 0) { FamTree[Sp].SetSpouse(R); if (K.Count != 0) { List <int> TempChildren = FamTree[Sp].GetChildren(); foreach (int i in K) { bool found = false; foreach (int j in FamTree[Sp].GetChildren()) { if (j == i) { found = true; } } if (found == false) { TempChildren.Add(i); } } FamTree[Sp].SetChildren(TempChildren); } } }