Exemplo n.º 1
0
        public static bool ModifyIndividual(IBaseWindow baseWin, ref GDMIndividualRecord indivRec,
                                            GDMIndividualRecord target, TargetMode targetMode, GDMSex needSex)
        {
            bool result;

            try {
                baseWin.Context.BeginUpdate();
                GDMTree tree = baseWin.Context.Tree;

                using (var dlg = AppHost.ResolveDialog <IPersonEditDlg>(baseWin)) {
                    bool exists = (indivRec != null);
                    if (!exists)
                    {
                        indivRec = new GDMIndividualRecord(tree);
                        indivRec.InitNew();

                        indivRec.AddPersonalName(new GDMPersonalName(indivRec));
                        baseWin.Context.CreateEventEx(indivRec, GEDCOMTagName.BIRT, "", "");
                    }

                    try {
                        baseWin.Context.LockRecord(indivRec);

                        dlg.Person = indivRec;

                        if (targetMode != TargetMode.tmNone)
                        {
                            if (needSex == GDMSex.svMale || needSex == GDMSex.svFemale)
                            {
                                dlg.SetNeedSex(needSex);
                            }
                            dlg.TargetMode = targetMode;
                            dlg.Target     = target;
                        }

                        result = (AppHost.Instance.ShowModalX(dlg, false));
                    } finally {
                        baseWin.Context.UnlockRecord(indivRec);
                    }

                    if (!exists)
                    {
                        if (result)
                        {
                            PostProcessPerson(baseWin, indivRec);

                            tree.AddRecord(indivRec);
                        }
                        else
                        {
                            indivRec.Clear();
                            indivRec.Dispose();
                            indivRec = null;
                        }
                    }
                }
            } finally {
                baseWin.Context.EndUpdate();
            }

            return(result);
        }