Beispiel #1
0
        /// <summary>
        /// Internal helper method for parser
        /// </summary>
        internal void SetRawData(GDMApproximated approximated, GDMCalendar calendar,
                                 short year, bool yearBC, string yearModifier, byte month, byte day)
        {
            fApproximated = approximated;
            fCalendar     = calendar;
            fYear         = year;
            fYearBC       = yearBC;
            fYearModifier = yearModifier;
            fMonth        = month;
            fDay          = day;

            DateChanged();
        }
Beispiel #2
0
        public override void Clear()
        {
            base.Clear();

            fApproximated = GDMApproximated.daExact;
            fCalendar     = GDMCalendar.dcGregorian;
            fYear         = UNKNOWN_YEAR;
            fYearBC       = false;
            fYearModifier = string.Empty;
            fMonth        = 0;
            fDay          = 0;

            DateChanged();
        }
        public override void Assign(GDMCustomDate source)
        {
            GDMDate srcDate = source as GDMDate;

            if (srcDate == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            fApproximated = srcDate.fApproximated;
            fYear         = srcDate.fYear;
            fYearBC       = srcDate.fYearBC;
            fYearModifier = srcDate.fYearModifier;
            fMonth        = srcDate.fMonth;
            fDay          = srcDate.fDay;

            DateChanged();
        }
Beispiel #4
0
        private void SetDate(GDMCustomDate date)
        {
            if (date is GDMDateRange)
            {
                GDMDateRange dtRange = date as GDMDateRange;

                if (dtRange.After.StringValue == "" && dtRange.Before.StringValue != "")
                {
                    cmbDateType.SelectedIndex = 1;
                }
                else if (dtRange.After.StringValue != "" && dtRange.Before.StringValue == "")
                {
                    cmbDateType.SelectedIndex = 2;
                }
                else if (dtRange.After.StringValue != "" && dtRange.Before.StringValue != "")
                {
                    cmbDateType.SelectedIndex = 3;
                }

                txtDate1.NormalizeDate = dtRange.After.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                txtDate2.NormalizeDate = dtRange.Before.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                cmbDate1Calendar.SetSelectedTag <GDMCalendar>(dtRange.After.DateCalendar);
                cmbDate2Calendar.SetSelectedTag <GDMCalendar>(dtRange.Before.DateCalendar);
                chkBC1.Checked = dtRange.After.YearBC;
                chkBC2.Checked = dtRange.Before.YearBC;
            }
            else if (date is GDMDatePeriod)
            {
                GDMDatePeriod dtPeriod = date as GDMDatePeriod;

                if (dtPeriod.DateFrom.StringValue != "" && dtPeriod.DateTo.StringValue == "")
                {
                    cmbDateType.SelectedIndex = 4;
                }
                else if (dtPeriod.DateFrom.StringValue == "" && dtPeriod.DateTo.StringValue != "")
                {
                    cmbDateType.SelectedIndex = 5;
                }
                else if (dtPeriod.DateFrom.StringValue != "" && dtPeriod.DateTo.StringValue != "")
                {
                    cmbDateType.SelectedIndex = 6;
                }

                txtDate1.NormalizeDate = dtPeriod.DateFrom.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                txtDate2.NormalizeDate = dtPeriod.DateTo.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                cmbDate1Calendar.SetSelectedTag <GDMCalendar>(dtPeriod.DateFrom.DateCalendar);
                cmbDate2Calendar.SetSelectedTag <GDMCalendar>(dtPeriod.DateTo.DateCalendar);
                chkBC1.Checked = dtPeriod.DateFrom.YearBC;
                chkBC2.Checked = dtPeriod.DateTo.YearBC;
            }
            else if (date is GDMDate)
            {
                GDMApproximated approximated = (date as GDMDate).Approximated;

                switch (approximated)
                {
                case GDMApproximated.daExact:
                    cmbDateType.SelectedIndex = 0;
                    break;

                case GDMApproximated.daAbout:
                    cmbDateType.SelectedIndex = 7;
                    break;

                case GDMApproximated.daCalculated:
                    cmbDateType.SelectedIndex = 8;
                    break;

                case GDMApproximated.daEstimated:
                    cmbDateType.SelectedIndex = 9;
                    break;
                }

                txtDate1.NormalizeDate = (date as GDMDate).GetDisplayString(DateFormat.dfDD_MM_YYYY);
                cmbDate1Calendar.SetSelectedTag <GDMCalendar>((date as GDMDate).DateCalendar);
                chkBC1.Checked = (date as GDMDate).YearBC;
            }
            else
            {
                cmbDateType.SelectedIndex = 0;
                txtDate1.NormalizeDate    = "";
                cmbDate1Calendar.SetSelectedTag <GDMCalendar>(GDMCalendar.dcGregorian);
                chkBC1.Checked = false;
            }
        }
        public override void UpdateView()
        {
            fView.NotesList.ListModel.DataOwner   = fEvent;
            fView.MediaList.ListModel.DataOwner   = fEvent;
            fView.SourcesList.ListModel.DataOwner = fEvent;

            var evtName = fEvent.GetTagName();

            if (fEvent is GDMFamilyEvent)
            {
                SetEventTypes(GKData.FamilyEvents);
                int idx = GKUtils.GetFamilyEventIndex(evtName);
                if (idx < 0)
                {
                    idx = 0;
                }
                fView.EventType.SelectedIndex = idx;
            }
            else
            {
                SetEventTypes(GKData.PersonEvents);
                int idx = GKUtils.GetPersonEventIndex(evtName);
                if (idx < 0)
                {
                    idx = 0;
                }
                fView.EventType.SelectedIndex = idx;

                if (idx >= 0 && GKData.PersonEvents[idx].Kind == PersonEventKind.ekFact)
                {
                    fView.Attribute.Text = fEvent.StringValue;
                }
            }

            ChangeEventType();

            GDMCustomDate date = fEvent.Date.Value;

            if (date is GDMDateRange)
            {
                GDMDateRange dtRange = date as GDMDateRange;

                if (dtRange.After.StringValue == "" && dtRange.Before.StringValue != "")
                {
                    fView.EventDateType.SelectedIndex = 1;
                }
                else if (dtRange.After.StringValue != "" && dtRange.Before.StringValue == "")
                {
                    fView.EventDateType.SelectedIndex = 2;
                }
                else if (dtRange.After.StringValue != "" && dtRange.Before.StringValue != "")
                {
                    fView.EventDateType.SelectedIndex = 3;
                }

                fView.Date1.NormalizeDate = dtRange.After.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                fView.Date2.NormalizeDate = dtRange.Before.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                fView.Date1Calendar.SetSelectedTag <GDMCalendar>(dtRange.After.DateCalendar);
                fView.Date2Calendar.SetSelectedTag <GDMCalendar>(dtRange.Before.DateCalendar);
                fView.Date1BC.Checked = dtRange.After.YearBC;
                fView.Date2BC.Checked = dtRange.Before.YearBC;
            }
            else if (date is GDMDatePeriod)
            {
                GDMDatePeriod dtPeriod = date as GDMDatePeriod;

                if (dtPeriod.DateFrom.StringValue != "" && dtPeriod.DateTo.StringValue == "")
                {
                    fView.EventDateType.SelectedIndex = 4;
                }
                else if (dtPeriod.DateFrom.StringValue == "" && dtPeriod.DateTo.StringValue != "")
                {
                    fView.EventDateType.SelectedIndex = 5;
                }
                else if (dtPeriod.DateFrom.StringValue != "" && dtPeriod.DateTo.StringValue != "")
                {
                    fView.EventDateType.SelectedIndex = 6;
                }

                fView.Date1.NormalizeDate = dtPeriod.DateFrom.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                fView.Date2.NormalizeDate = dtPeriod.DateTo.GetDisplayString(DateFormat.dfDD_MM_YYYY);
                fView.Date1Calendar.SetSelectedTag <GDMCalendar>(dtPeriod.DateFrom.DateCalendar);
                fView.Date2Calendar.SetSelectedTag <GDMCalendar>(dtPeriod.DateTo.DateCalendar);
                fView.Date1BC.Checked = dtPeriod.DateFrom.YearBC;
                fView.Date2BC.Checked = dtPeriod.DateTo.YearBC;
            }
            else if (date is GDMDate)
            {
                GDMApproximated approximated = (date as GDMDate).Approximated;

                switch (approximated)
                {
                case GDMApproximated.daExact:
                    fView.EventDateType.SelectedIndex = 0;
                    break;

                case GDMApproximated.daAbout:
                    fView.EventDateType.SelectedIndex = 7;
                    break;

                case GDMApproximated.daCalculated:
                    fView.EventDateType.SelectedIndex = 8;
                    break;

                case GDMApproximated.daEstimated:
                    fView.EventDateType.SelectedIndex = 9;
                    break;
                }

                fView.Date1.NormalizeDate = (date as GDMDate).GetDisplayString(DateFormat.dfDD_MM_YYYY);
                fView.Date1Calendar.SetSelectedTag <GDMCalendar>((date as GDMDate).DateCalendar);
                fView.Date1BC.Checked = (date as GDMDate).YearBC;
            }
            else
            {
                fView.EventDateType.SelectedIndex = 0;
                fView.Date1.NormalizeDate         = "";
                fView.Date1Calendar.SetSelectedTag <GDMCalendar>(GDMCalendar.dcGregorian);
                fView.Date1BC.Checked = false;
            }

            ChangeDateType();
            fView.EventName.Text = fEvent.Classification;
            fView.Cause.Text     = fEvent.Cause;
            fView.Agency.Text    = fEvent.Agency;

            fTempLocation = (fEvent.Place.Location.Value as GDMLocationRecord);
            UpdatePlace();

            fView.NotesList.UpdateSheet();
            fView.MediaList.UpdateSheet();
            fView.SourcesList.UpdateSheet();
        }
Beispiel #6
0
        // Format: [ <YEAR>[B.C.] | <MONTH> <YEAR> | <DAY> <MONTH> <YEAR> ] (see p.45-46)
        protected static string ParseDate(GEDCOMParser strTok, out GDMApproximated approximated,
                                          out short year, out bool yearBC,
                                          out string yearModifier, out byte month, out byte day)
        {
            approximated = GDMApproximated.daExact;
            year         = GDMDate.UNKNOWN_YEAR;
            yearBC       = false;
            yearModifier = string.Empty;
            month        = 0;
            day          = 0;

            strTok.SkipWhitespaces();

            var token = strTok.CurrentToken;

            // extract approximated
            token = strTok.CurrentToken;
            if (token == GEDCOMToken.Word)
            {
                string su  = InvariantTextInfo.ToUpper(strTok.GetWord());
                int    idx = Algorithms.BinarySearch(GDMCustomDate.GEDCOMDateApproximatedArray, su, string.CompareOrdinal);
                if (idx >= 0)
                {
                    approximated = (GDMApproximated)idx;
                    strTok.Next();
                    strTok.SkipWhitespaces();
                }
            }

            // extract day
            token = strTok.CurrentToken;
            int dNum;

            if (token == GEDCOMToken.Number && strTok.TokenLength() <= 2 && ((dNum = strTok.GetNumber()) <= 31))
            {
                day   = (byte)dNum;
                token = strTok.Next();
            }

            // extract delimiter
            if (token == GEDCOMToken.Whitespace && strTok.GetSymbol() == ' ')
            {
                token = strTok.Next();
            }

            // extract month
            if (token == GEDCOMToken.Word)
            {
                // in this case, according to performance test results, BinarySearch is more efficient
                // than a simple search or even a dictionary search (why?!)
                string su  = InvariantTextInfo.ToUpper(strTok.GetWord());
                int    idx = BinarySearch(GDMCustomDate.GEDCOMMonthValues, su, string.CompareOrdinal);
                month = (byte)((idx < 0) ? 0 : idx);

                token = strTok.Next();
            }

            // extract delimiter
            if (token == GEDCOMToken.Whitespace && strTok.GetSymbol() == ' ')
            {
                token = strTok.Next();
            }

            // extract negative years
            if (token == GEDCOMToken.Symbol && strTok.GetSymbol() == '-')
            {
                yearBC = true;
                token  = strTok.Next();
            }

            // extract year
            if (token == GEDCOMToken.Number)
            {
                year  = (short)strTok.GetNumber();
                token = strTok.Next();

                // extract year modifier
                if (token == GEDCOMToken.Symbol && strTok.GetSymbol() == GDMCustomDate.YearModifierSeparator)
                {
                    token = strTok.Next();
                    if (token != GEDCOMToken.Number)
                    {
                        // error
                    }
                    else
                    {
                        yearModifier = strTok.GetWord();
                    }
                    token = strTok.Next();
                }

                // extract bc/ad
                if (token == GEDCOMToken.Word && strTok.GetWord() == "B")
                {
                    token = strTok.Next();
                    if (token != GEDCOMToken.Symbol || strTok.GetSymbol() != '.')
                    {
                        // error
                    }
                    token = strTok.Next();
                    if (token != GEDCOMToken.Word || strTok.GetWord() != "C")
                    {
                        // error
                    }
                    token = strTok.Next();
                    if (token != GEDCOMToken.Symbol || strTok.GetSymbol() != '.')
                    {
                        // error
                    }
                    strTok.Next();
                    yearBC = true;
                }
            }

            token = strTok.CurrentToken;

            if (day > 0 && month == 0 && year == GDMDate.UNKNOWN_YEAR)
            {
                year = day;
                day  = 0;
            }

            //date.SetRawData(approximated, calendar, year, yearBC, yearModifier, month, day, dateFormat);
            string result = strTok.GetRest();

            return(result);
        }