Example #1
0
 /// <summary>
 /// Hides the person page.
 /// </summary>
 private void HidePersonPage()
 {
     this.panelPerson.Visible = false;
     this.lbAdd.ForeColor = SystemColors.ControlText;
     this.lbEdit.ForeColor = SystemColors.ControlText;
     this.lbRemove.ForeColor = SystemColors.ControlText;
     this.lbSpouseAdd.ForeColor = SystemColors.ControlText;
     this.mCurrentPerson = null;
     this.mPageMode = PersonPageMode.None;
 }
Example #2
0
        /// <summary>
        /// Prints a person
        /// </summary>
        /// <param name="p">Instance of person</param>
        /// <param name="p">Database instance</param>
        public void PrintPerson(Person p, TorpgenDB db)
        {
            mPerson = p;
            mDatabase = db;

            var ppd = new PrintPreviewDialog();
            var doc = new PrintDocument();

            var printSettings = new PrinterSettings();
            var pageSettings = new PageSettings();

            pageSettings.Margins.Left = 50;
            pageSettings.Margins.Right = 100;
            pageSettings.Margins.Top = 50;
            pageSettings.Margins.Bottom = 100;
            pageSettings.PaperSize = new PaperSize("A4", 850, 1100);

            //printSettings.PaperSizes = ;

            doc.PrintPage += new PrintPageEventHandler(HandlePrintPage);
            doc.DocumentName = p.listBoxString;
            doc.DefaultPageSettings = pageSettings;
            doc.PrinterSettings = printSettings;
            ppd.Document = doc;
            ((Form)ppd).WindowState = FormWindowState.Maximized;
            ppd.ShowDialog();
        }
Example #3
0
        /// <summary>
        /// Handles editing of a person
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="menuUsed">Flag if context menu is used to get to this function</param>
        private void HandleEditPerson(bool menuUsed)
        {
            if (this.lbEdit.ForeColor == SystemColors.InactiveCaption ||
                this.lbPersons.SelectedItem == null)
            {
                return;
            }

            lbPersons.Enabled = false;

            lbAdd.ForeColor = SystemColors.InactiveCaption;
            lbRemove.ForeColor = SystemColors.InactiveCaption;

            if (menuUsed)
            {
                // Get person under the mouse
                mCurrentPerson = (Person)mTree.GetSelectedNode().GetUserData();
            }
            else
            {
                // Get selected person from the listbox
                mCurrentPerson = (Person)lbPersons.SelectedItem;
            }

            ShowPersonPage(PersonPageMode.Edit, this.mCurrentPerson);
        }
Example #4
0
        /// <summary>
        /// Handles removal of a person
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="menuUsed">Flag if context menu is used to get to this function</param>
        private void HandleRemovePerson(bool menuUsed)
        {
            if (this.lbRemove.ForeColor == SystemColors.InactiveCaption)
            {
                return;
            }

            if (menuUsed)
            {
                // Get person under the mouse
                mCurrentPerson = (Person)mTree.GetSelectedNode().GetUserData();
            }
            else
            {
                // Get selected person from the listbox
                mCurrentPerson = (Person)lbPersons.SelectedItem;
            }

            if (mCurrentPerson == null)
            {
                return;
            }

            String str = "Do you want to remove \"" + mCurrentPerson.listBoxString + "\"?";

            if (MessageBox.Show(str, "Remove person?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                // Remove person.
            }
        }
Example #5
0
        /// <summary>
        /// Draws the person's tree
        /// </summary>
        /// <param name="person"></param>
        private void DrawTree(Person person)
        {
            if (mGraphics != null)
            {
                mGraphics.Clear(System.Drawing.Color.White);
            }
            else
            {
                mGraphics = this.CreateGraphics();
                mGraphics.SmoothingMode = SmoothingMode.AntiAlias;
                mGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            }

            int xmin; int ymin;

            xmin = lbPersons.Location.X + (this.Width - lbPersons.Location.X) / 2;
            ymin = lbPersons.Location.Y;

            // Create a new tree (the panel containing person information for, and align to to listbox containing persons.
            mTree = new GenericTree.GenericTree(mGraphics, panelPerson.Location.X, lbPersons.Location.Y, panelPerson.Width, panelPerson.Height, this.BackColor);

            mTree.SetFont(new FontFamily("Segoe UI"), FontStyle.Regular, 13, 11);

            bool hasParents = false;
            bool hasChildren = false;

            //
            // Add person's parents
            //
            if (person.father != Guid.Empty)
            {
                // Got either mother or father or both.
                hasParents = true;

                Person p = mDB.GetPerson(person.father);

                if (p != null)
                {
                    mTree.AddNode(0, AssembleNodeString(p), p, false, true);
                }
            }

            if (person.mother != Guid.Empty)
            {
                hasParents = true;

                Person p = mDB.GetPerson(person.mother);

                if (p != null)
                {
                    mTree.AddNode(0, AssembleNodeString(p), p, false, true);
                }
            }

            //// Add main person
            hasChildren = true;

            if (person.children == null || person.children.Count == 0)
            {
                hasChildren = false;
            }

            mTree.AddNode(1, AssembleNodeString(person), person, hasParents, hasChildren);

            // Add spouse
            if (person.marriages != null && person.marriages.Count > 0)
            {
                Person spouse = null;

                Marriage m = mDB.GetMarriage(person.marriages[0]);

                if (person.gender == Gender.Male)
                {
                    spouse = mDB.GetPerson(m.wife);
                }
                else
                {
                    spouse = mDB.GetPerson(m.husband);
                }

                hasChildren = true;
                if (spouse.children == null || spouse.children.Count == 0)
                {
                    hasChildren = false;
                }

                mTree.AddNode(1, AssembleNodeString(spouse), spouse, false, hasChildren);
            }

            // Add  person's children
            if (person.children != null)
            {
                var sorted = mDB.GetPersonListSortedByBirth(person.children);

                foreach (var c in sorted)
                {
                    mTree.AddNode(2, AssembleNodeString(c), c, true, false);
                }
            }

            mTree.Draw();
        }
Example #6
0
        private void HandleAddPerson()
        {
            this.lbPanelTopLabel.Text = "Add Person";
            this.lbEdit.ForeColor = SystemColors.InactiveCaption;
            this.lbRemove.ForeColor = SystemColors.InactiveCaption;

            this.mCurrentPerson = new Person(mDB);
            this.mCurrentPerson.id = System.Guid.NewGuid();

            lbPersons.Enabled = false;

            ShowPersonPage(PersonPageMode.Add, mCurrentPerson);
        }
Example #7
0
        private String[] AssembleNodeString(Person p)
        {
            String[] txt = new String[3] { "", "", "" };

            if (p.firstName != "")
            {
                txt[0] += p.firstName;
            }
            if (p.lastName != "")
            {
                txt[0] += " " + p.lastName;
            }

            txt[1] += "b. ";
            if (p.birth.date != "")
            {
                txt[1] += p.birth.date;
            }
            if (p.birth.place != "")
            {
                txt[1] += " " + p.birth.place;
            }

            txt[2] += "d. ";
            if (p.death.date != "")
            {
                txt[2] += p.death.date;
            }
            if (p.death.place != "")
            {
                txt[2] += " " + p.death.place;
            }

            return txt;
        }
Example #8
0
 private void ctxMenuPrint_Click(object sender, EventArgs e)
 {
     // Get person under the mouse
     mCurrentPerson = (Person)mTree.GetSelectedNode().GetUserData();
     mPrint.PrintPerson(mCurrentPerson, mDB);
 }
Example #9
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Form1()
        {
            InitializeComponent();

            mCurrentPerson = null;
            mPageMode = PersonPageMode.None;
            mFileName = "";

            LoadPersonsFromFile();
            toolStripStatusLabel1.Text = "";
        }
Example #10
0
        /// <summary>
        /// Shows the person page
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="person"></param>
        private void ShowPersonPage(PersonPageMode mode, Person person)
        {
            mPageMode = mode;

            if (mMen != null)
            {
                mMen.Clear();
            }

            if (mWomen != null)
            {
                mWomen.Clear();
            }

            mMen = mDB.GetPersonsWithGender(Gender.Male);
            mWomen = mDB.GetPersonsWithGender(Gender.Female);

            // Make sure all fields are empty.
            tbFirstName.Text = "";
            tbLastName.Text = "";
            rbMale.Checked = true;
            rbFemale.Checked = false;
            tbBirthDate.Text = "";
            tbBirthLocation.Text = "";
            tbBirthNote.Text = "";
            tbDeathDate.Text = "";
            tbDeathLocation.Text = "";
            tbDeathNotes.Text = "";

            tbMarriageDate.Text = "";
            tbMarriageLocation.Text = "";
            tbMarriageNotes.Text = "";

            tbNotes.Text = "";
            lbSpouses.Items.Clear();

            if (mMen != null)
            {
                cmbFather.Items.Clear();
                cmbFather.Items.Add(String.Empty);
                cmbFather.Items.AddRange(mMen.ToArray());
            }

            if (mWomen != null)
            {
                cmbMother.Items.Clear();
                cmbMother.Items.Add(String.Empty);
                cmbMother.Items.AddRange(mWomen.ToArray());
            }

            cmbFather.DisplayMember = "listBoxString";
            cmbFather.ValueMember = "id";
            cmbMother.DisplayMember = "listBoxString";
            cmbMother.ValueMember = "id";

            if (mode == PersonPageMode.Add)
            {
                lbPanelTopLabel.Text = "Add Person";
                mTempFather = Guid.Empty;
                mTempFather = Guid.Empty;
                mTempMarriages = new List<Marriage>();

                person = mCurrentPerson;
            }
            else if (mode == PersonPageMode.Edit)
            {
                lbPanelTopLabel.Text = "Edit Person";

                tbFirstName.Text = person.firstName;
                tbLastName.Text = person.lastName;

                if (person.birth != null)
                {
                    tbBirthDate.Text = person.birth.date;
                    tbBirthLocation.Text = person.birth.place;
                    tbBirthNote.Text = person.birth.note;
                }

                if (person.death != null)
                {
                    tbDeathDate.Text = person.death.date;
                    tbDeathLocation.Text = person.death.place;
                    tbDeathNotes.Text = person.death.note;
                }

                mTempFather = person.father;
                mTempFather = person.mother;

                if (person.father != Guid.Empty)
                {
                    cmbFather.SelectedItem = mDB.GetPerson(person.father);
                }

                if (person.mother != Guid.Empty)
                {
                    cmbMother.SelectedItem = mDB.GetPerson(person.mother);
                }

                // Create a temporary list of marriages to be able to handle changes upon saving the person
                mTempMarriages = new List<Marriage>();

                if (person.marriages.Count > 0)
                {
                    for (int i = 0; i < person.marriages.Count; i++)
                    {
                        mTempMarriages.Add(mDB.GetMarriage(person.marriages[i]));
                    }
                }
            }

            if (person.gender == Gender.Male)
            {
                rbMale.Checked = true;
            }
            else
            {
                rbFemale.Checked = true;
            }

            UpdateMarriageSpouseCombo();
            UpdateMarriageControls();

            // Make sure the first tag is open
            tabPerson.SelectedIndex = 0;

            panelPerson.Visible = true;
        }
Example #11
0
        /// <summary>
        /// Saves a person after adding/editing
        /// </summary>
        private void SavePerson()
        {
            mCurrentPerson.firstName = tbFirstName.Text.Trim();
            mCurrentPerson.lastName = tbLastName.Text.Trim();
            mCurrentPerson.notes = tbNotes.Text.Trim();

            if (rbMale.Checked)
            {
                mCurrentPerson.gender = Gender.Male;
            }
            else
            {
                mCurrentPerson.gender = Gender.Female;
            }

            mCurrentPerson.birth = new LifeEvent(LifeEventTypes.Birth, tbBirthDate.Text.Trim(), tbBirthLocation.Text.Trim(), tbBirthNote.Text.Trim());
            mCurrentPerson.death = new LifeEvent(LifeEventTypes.Death, tbDeathDate.Text.Trim(), tbDeathLocation.Text.Trim(), tbDeathNotes.Text.Trim());

            mTempFather = (cmbFather.SelectedItem != null && cmbFather.Text != "") ? ((Person)cmbFather.SelectedItem).id : Guid.Empty;
            mTempMother = (cmbMother.SelectedItem != null && cmbMother.Text != "") ? ((Person)cmbMother.SelectedItem).id : Guid.Empty;

            // If adding, just add to database
            if (mPageMode == PersonPageMode.Add)
            {
                this.mDB.AddPerson(mCurrentPerson);
            }

            // Check if parents have changed
            if (mTempFather != mCurrentPerson.father)
            {
                mCurrentPerson.father = HandleParentChanges(mCurrentPerson.father, mTempFather, mCurrentPerson.id);
            }

            if (mTempMother != mCurrentPerson.mother)
            {
                mCurrentPerson.mother = HandleParentChanges(mCurrentPerson.mother, mTempMother, mCurrentPerson.id);
            }

            // Handle changes in spouses
            HandleSpouseChanges();

            mCurrentPerson = null;
        }
Example #12
0
 /// <summary>
 /// Adds a child to a person
 /// </summary>
 /// <param name="id">Parent's ID</param>
 /// <param name="child">Childs person data</param>
 public void AddChildToPerson(Guid id, Person child)
 {
     if (mDictPersons.ContainsKey(id))
     {
         mDictPersons[id].AddChild(child.id);
     }
 }
Example #13
0
 /// <summary>
 /// Returns if a person has children
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public bool PersonHasChildren(Person p)
 {
     return (p.children.Count > 0);
 }
Example #14
0
        /// <summary>
        /// Adds a person
        /// </summary>
        /// <param name="p">Instance of person.</param>
        public void AddPerson(Person p)
        {
            mPersons.Add(p);

            mDictPersons.Add(p.id, p);

            // If person's parents have been specified, make sure that there their marriage contains the current person as a child
            AddChildToPerson(p.father, p);
            AddChildToPerson(p.mother, p);
        }
Example #15
0
        /// <summary>
        /// Add a marriage
        /// </summary>
        /// <param name="man"></param>
        /// <param name="woman"></param>
        /// <param name="text"></param>
        /// <param name="place"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public Marriage AddMarriage(Person man, Person woman, String text, String place, String notes)
        {
            // See if there already is a marriage containing these twe people

            for (int i = 0; i < mMarriages.Count; i++)
            {
                if (mMarriages[i].husband == man.id && mMarriages[i].wife == woman.id)
                {
                    // Already there...
                    return mMarriages[i];
                }
            }

            // Not there ...add a new one
            Marriage m = new Marriage(man.id, woman.id, text, place, notes);

            man.AddMarriage(m.id);
            woman.AddMarriage(m.id);

            mMarriages.Add(m);
            return m;
        }