Пример #1
0
        public static bool ModifyFamily(IBaseWindow baseWin, ref GEDCOMFamilyRecord familyRec, TargetMode targetType, GEDCOMIndividualRecord target)
        {
            bool result;

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

                if (targetType == TargetMode.tmFamilySpouse && target != null)
                {
                    GEDCOMSex sex = target.Sex;
                    if (sex < GEDCOMSex.svMale || sex >= GEDCOMSex.svUndetermined)
                    {
                        AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_IsNotDefinedSex));
                        return(false);
                    }
                }

                using (var dlg = AppHost.Container.Resolve <IFamilyEditDlg>(baseWin)) {
                    bool exists = (familyRec != null);
                    if (!exists)
                    {
                        familyRec = new GEDCOMFamilyRecord(tree, tree, "", "");
                        familyRec.InitNew();
                    }

                    try {
                        baseWin.Context.LockRecord(familyRec);

                        dlg.Family = familyRec;

                        if (targetType != TargetMode.tmNone && target != null)
                        {
                            dlg.SetTarget(targetType, target);
                        }

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

                    if (!exists)
                    {
                        if (result)
                        {
                            tree.AddRecord(familyRec);
                        }
                        else
                        {
                            familyRec.Clear();
                            familyRec.Dispose();
                            familyRec = null;
                        }
                    }
                }
            } finally {
                baseWin.Context.EndUpdate();
            }

            return(result);
        }