public EventEditDlg() { InitializeComponent(); int num = GKData.DateKinds.Length; for (int i = 0; i < num; i++) { cmbEventDateType.Items.Add(LangMan.LS(GKData.DateKinds[i].Name)); } for (GEDCOMCalendar gc = GEDCOMCalendar.dcGregorian; gc <= GEDCOMCalendar.dcLast; gc++) { GKData.CalendarStruct cdr = GKData.DateCalendars[(int)gc]; if (!cdr.HasSupport) { continue; } cmbDate1Calendar.Items.Add(new GKComboItem(LangMan.LS(cdr.Name), gc)); cmbDate2Calendar.Items.Add(new GKComboItem(LangMan.LS(cdr.Name), gc)); } cmbDate1Calendar.SelectedIndex = 0; cmbDate2Calendar.SelectedIndex = 0; fLocation = null; fNotesList = new GKSheetList(pageNotes); fMediaList = new GKSheetList(pageMultimedia); fSourcesList = new GKSheetList(pageSources); // SetLang() Title = LangMan.LS(LSID.LSID_Event); btnAccept.Text = LangMan.LS(LSID.LSID_DlgAccept); btnCancel.Text = LangMan.LS(LSID.LSID_DlgCancel); btnAddress.Text = LangMan.LS(LSID.LSID_Address) + @"..."; pageCommon.Text = LangMan.LS(LSID.LSID_Common); pageNotes.Text = LangMan.LS(LSID.LSID_RPNotes); pageMultimedia.Text = LangMan.LS(LSID.LSID_RPMultimedia); pageSources.Text = LangMan.LS(LSID.LSID_RPSources); lblEvent.Text = LangMan.LS(LSID.LSID_Event); lblAttrValue.Text = LangMan.LS(LSID.LSID_Value); lblPlace.Text = LangMan.LS(LSID.LSID_Place); lblDate.Text = LangMan.LS(LSID.LSID_Date); lblCause.Text = LangMan.LS(LSID.LSID_Cause); lblOrg.Text = LangMan.LS(LSID.LSID_Agency); btnPlaceAdd.ToolTip = LangMan.LS(LSID.LSID_PlaceAddTip); btnPlaceDelete.ToolTip = LangMan.LS(LSID.LSID_PlaceDeleteTip); }
protected override void CreateObj(GEDCOMTree owner, GEDCOMObject parent) { base.CreateObj(owner, parent); SetName("DATE"); fApproximated = GEDCOMApproximated.daExact; fCalendar = GEDCOMCalendar.dcGregorian; fYear = UNKNOWN_YEAR; fYearBC = false; fYearModifier = ""; fMonth = ""; fDay = 0; fDateFormat = GEDCOMDateFormat.dfGEDCOMStd; }
public void testSetDateHebrew() { GEDCOMCalendar calendar = GEDCOMCalendar.dcHebrew; int day = 20; int month = 12; int year = 1980; GEDCOMDate instance = new GEDCOMDate(null, null, "", ""); instance.SetDate(calendar, day, month, year); string result = instance.GetDisplayString(DateFormat.dfYYYY_MM_DD, false, false); Assert.AreEqual("1980.12.20", result); Assert.AreEqual("@#DHEBREW@ 20 AAV 1980", instance.StringValue); }
private static void SetComboCalendar(ComboBox comboBox, GEDCOMCalendar calendar) { foreach (object item in comboBox.Items) { GKComboItem comboItem = (GKComboItem)item; if ((GEDCOMCalendar)comboItem.Tag == calendar) { comboBox.SelectedItem = item; return; } } comboBox.SelectedIndex = 0; }
/// <summary> /// This function transforms the string into a date. All components of /// the date's string must be given by numbers in order of day / month / year. /// </summary> /// <param name="strDate"></param> /// <param name="calendar"></param> /// <param name="aException"></param> /// <returns></returns> public static GEDCOMDate CreateByFormattedStr(string dateStr, GEDCOMCalendar calendar, bool aException) { if (string.IsNullOrEmpty(dateStr)) { return(null); } if (dateStr.IndexOf("-") >= 0) { dateStr = dateStr.Replace("-", "."); } if (dateStr.IndexOf("/") >= 0) { dateStr = dateStr.Replace("/", "."); } if (dateStr.IndexOf("_") >= 0) { dateStr = dateStr.Replace("_", " "); } string[] dtParts = dateStr.Split('.'); if (dtParts.Length < 3) { if (aException) { throw new GEDCOMDateException(string.Format("GEDCOMDate.CreateByFormattedStr(): date format is invalid {0}", dateStr)); } return(null); } string pd = dtParts[0].Trim(); string pm = dtParts[1].Trim(); string py = dtParts[2].Trim(); int day = (pd == "") ? 0 : SysUtils.ParseInt(pd, 0); int month = (pm == "") ? 0 : SysUtils.ParseInt(pm, 0); int year = (py == "") ? UNKNOWN_YEAR : SysUtils.ParseInt(py, UNKNOWN_YEAR); var date = new GEDCOMDate(null, null, "", ""); date.SetDate(calendar, day, month, year); return(date); }
public override void Assign(GEDCOMTag source) { GEDCOMDate srcDate = source as GEDCOMDate; if (srcDate != null) { fCalendar = srcDate.fCalendar; fYear = srcDate.fYear; fYearBC = srcDate.fYearBC; fYearModifier = srcDate.fYearModifier; fMonth = srcDate.fMonth; fDay = srcDate.fDay; DateChanged(); } else { base.Assign(source); } }
private GEDCOMCustomDate AssembleDate() { GEDCOMCustomDate result = null; GEDCOMCalendar cal1 = GetComboCalendar(cmbDate1Calendar); GEDCOMCalendar cal2 = GetComboCalendar(cmbDate2Calendar); GEDCOMDate gcd1 = GEDCOMDate.CreateByFormattedStr(txtEventDate1.Text, cal1, true); if (gcd1 == null) { throw new ArgumentNullException("gcd1"); } GEDCOMDate gcd2 = GEDCOMDate.CreateByFormattedStr(txtEventDate2.Text, cal2, true); if (gcd2 == null) { throw new ArgumentNullException("gcd2"); } gcd1.YearBC = btnBC1.Checked; gcd2.YearBC = btnBC2.Checked; switch (cmbEventDateType.SelectedIndex) { case 0: result = gcd1; break; case 1: // BEF gcd2 result = GEDCOMCustomDate.CreateRange(null, null, null, gcd2); break; case 2: // AFT gcd1 result = GEDCOMCustomDate.CreateRange(null, null, gcd1, null); break; case 3: // "BET " + gcd1 + " AND " + gcd2 result = GEDCOMCustomDate.CreateRange(null, null, gcd1, gcd2); break; case 4: // FROM gcd1 result = GEDCOMCustomDate.CreatePeriod(null, null, gcd1, null); break; case 5: // TO gcd2 result = GEDCOMCustomDate.CreatePeriod(null, null, null, gcd2); break; case 6: // FROM gcd1 TO gcd2 result = GEDCOMCustomDate.CreatePeriod(null, null, gcd1, gcd2); break; case 7: // ABT gcd1 result = GEDCOMCustomDate.CreateApproximated(null, null, gcd1, GEDCOMApproximated.daAbout); break; case 8: // CAL gcd1 result = GEDCOMCustomDate.CreateApproximated(null, null, gcd1, GEDCOMApproximated.daCalculated); break; case 9: // EST gcd1 result = GEDCOMCustomDate.CreateApproximated(null, null, gcd1, GEDCOMApproximated.daEstimated); break; } return(result); }
private static GEDCOMCalendar GetComboCalendar(ComboBox comboBox) { GEDCOMCalendar result = (GEDCOMCalendar)(((GKComboItem)comboBox.SelectedItem).Tag); return(result); }
public static UDN GetUDNByFormattedStr(string dateStr, GEDCOMCalendar calendar, bool aException = false) { GEDCOMDate dtx = GEDCOMDate.CreateByFormattedStr(dateStr, calendar, aException); return((dtx != null) ? dtx.GetUDN() : UDN.CreateEmpty()); }
public override string ParseString(string strValue) { GEDCOMFormat format = GEDCOMProvider.GetGEDCOMFormat(Owner); fApproximated = GEDCOMApproximated.daExact; fCalendar = GEDCOMCalendar.dcGregorian; fYear = UNKNOWN_YEAR; fYearBC = false; fYearModifier = ""; fMonth = ""; fDay = 0; if (!string.IsNullOrEmpty(strValue)) { if (format == GEDCOMFormat.gf_Ahnenblatt) { strValue = PrepareAhnenblattDate(strValue); } var strTok = new StringTokenizer(strValue); strTok.IgnoreWhiteSpace = false; strTok.Next(); strTok.SkipWhiteSpaces(); // extract approximated var token = strTok.CurrentToken; if (token.Kind == TokenKind.Word) { string su = token.Value.ToUpperInvariant(); int idx = SysUtils.IndexOf(GEDCOMDateApproximatedArray, su); if (idx >= 0) { fApproximated = (GEDCOMApproximated)idx; strTok.Next(); strTok.SkipWhiteSpaces(); } } // extract escape token = strTok.CurrentToken; if (token.Kind == TokenKind.Symbol && token.Value[0] == '@') { var escapeStr = token.Value; do { token = strTok.Next(); escapeStr += token.Value; } while (token.Kind != TokenKind.Symbol || token.Value[0] != '@'); // FIXME: check for errors int idx = SysUtils.IndexOf(GEDCOMDateEscapeArray, escapeStr); if (idx >= 0) { fCalendar = (GEDCOMCalendar)idx; } strTok.Next(); strTok.SkipWhiteSpaces(); } // extract day token = strTok.CurrentToken; if (token.Kind == TokenKind.Number && token.Value.Length <= 2) { fDay = (byte)(int)token.ValObj; token = strTok.Next(); } // extract delimiter if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ') { fDateFormat = GEDCOMDateFormat.dfGEDCOMStd; token = strTok.Next(); } else if (token.Kind == TokenKind.Symbol && token.Value[0] == '.') { fDateFormat = GEDCOMDateFormat.dfSystem; token = strTok.Next(); } // extract month string[] monthes = GetMonthNames(fCalendar); if (token.Kind == TokenKind.Word) { string mth = token.Value; int idx = SysUtils.IndexOf(monthes, mth); if (idx >= 0) { fMonth = mth; } token = strTok.Next(); } else if (fDateFormat == GEDCOMDateFormat.dfSystem && token.Kind == TokenKind.Number) { int idx = (int)token.ValObj; fMonth = monthes[idx - 1]; token = strTok.Next(); } // extract delimiter if (fDateFormat == GEDCOMDateFormat.dfSystem) { if (token.Kind == TokenKind.Symbol && token.Value[0] == '.') { token = strTok.Next(); } } else { if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ') { token = strTok.Next(); } } // extract year if (token.Kind == TokenKind.Number) { fYear = (short)(int)token.ValObj; token = strTok.Next(); // extract year modifier if (token.Kind == TokenKind.Symbol && token.Value[0] == '/') { token = strTok.Next(); if (token.Kind != TokenKind.Number) { // error } fYearModifier = token.Value; token = strTok.Next(); } // extract bc/ad if (token.Kind == TokenKind.Word && token.Value[0] == 'B') { token = strTok.Next(); if (token.Kind != TokenKind.Symbol || token.Value[0] != '.') { // error } token = strTok.Next(); if (token.Kind != TokenKind.Word || token.Value[0] != 'C') { // error } token = strTok.Next(); if (token.Kind != TokenKind.Symbol || token.Value[0] != '.') { // error } strTok.Next(); fYearBC = true; } } strValue = strTok.GetRest(); } DateChanged(); return(strValue); }