private static void InitializeLibrary() { SetBooks(); if (Directory.Exists(_LibraryPath)) { string[] arrBook = Directory.GetDirectories(_LibraryPath); foreach (string sBook in arrBook) { var objvar = _objLibrary.LstBooks.Where(x => x.Abbrev == (new DirectoryInfo(sBook).Name)); MTBookModel objBook = objvar.First() as MTBookModel; string[] arrChap = Directory.GetFiles(sBook); foreach (string sChap in arrChap) { MTChapterModel objChapter = new MTChapterModel(Convert.ToInt32(System.IO.Path.GetFileNameWithoutExtension(sChap))); objBook.LstChapter.Add(objChapter); objChapter.Parent = objBook; TextReader tReader = new StreamReader(sChap); using (tReader) { string sText = tReader.ReadToEnd(); int i = 1; while (true) { string[] arrSplit = new string[1] { "$" + i.ToString() + "$" }; string[] arrVerses = sText.Split(arrSplit, StringSplitOptions.None); string sVers = ""; if (arrVerses.Count() == 1) { break; } if (arrVerses.Count() == 2) { sVers = arrVerses[0]; } else if (arrVerses.Count() == 3) { sVers = arrVerses[1]; } MTVerseModel objVerse = new MTVerseModel(i); objVerse.Text = sVers; objChapter.LstVerses.Add(objVerse); objVerse.Parent = objChapter; i++; } } //add back in chapters objChapter.LstVerses.Add(new MTBackModel(objChapter)); } //add back in chapters objBook.LstChapter.Add(new MTBackModel(objBook)); } } }
public static int GetPositionAdrees(List <MTMapModel> lstMap) { if (lstMap.Count == 0) { return(0); } if (lstMap[0] as MTVerseModel == null) { return(0); } int iResult = lstMap.Count; MTVerseModel objFirstVerse = lstMap[0] as MTVerseModel; iResult += objFirstVerse.Verse * 10; MTChapterModel objChapter = objFirstVerse.Parent as MTChapterModel; iResult += objChapter.Chapter * 10000; MTBookModel objBook = objChapter.Parent as MTBookModel; iResult += (_objLibrary.LstBooks.IndexOf(objBook) + 1) * 10000000; return(iResult); }
public string GetAdrees() { string sText = ""; if (lvMap.SelectedItems.Count > 0) { if ((lvMap.SelectedItems[0] as MTBookModel) != null) { MTBookModel objBook = lvMap.SelectedItem as MTBookModel; sText = MTControler.GetAdrees(objBook, false); } else if ((lvMap.SelectedItems[0] as MTChapterModel) != null) { MTChapterModel objChapter = lvMap.SelectedItem as MTChapterModel; sText = MTControler.GetAdrees(objChapter, false); } else if ((lvMap.SelectedItems[0] as MTVerseModel) != null) { sText = MTControler.GetAdrees(SelectedPatch, false); } } return(sText); }
public static string GetAdrees(List <MTMapModel> lstMap, bool IsAbrevied) { if (lstMap == null || lstMap.Count == 0) { return(""); } if (lstMap.First() as MTBookModel != null) { MTBookModel objBook = lstMap.First() as MTBookModel; string sBookName = IsAbrevied ? objBook.Abbrev : objBook.Name; return(sBookName); } else if (lstMap.First() as MTChapterModel != null) { MTChapterModel objChapter = lstMap.First() as MTChapterModel; MTBookModel objBook = objChapter.Parent as MTBookModel; string sBookName = IsAbrevied ? objBook.Abbrev : objBook.Name; return(sBookName + " " + objChapter.Label); } else if (lstMap.First() as MTVerseModel != null) { MTVerseModel objVerse = lstMap.First() as MTVerseModel; MTChapterModel objChapter = objVerse.Parent as MTChapterModel; MTBookModel objBook = objChapter.Parent as MTBookModel; string sBookName = IsAbrevied ? objBook.Abbrev : objBook.Name; string sReturn = sBookName + " " + objChapter.Label + ":"; List <MTVerseModel> lstMTVers = new List <MTVerseModel>(); foreach (MTMapModel objMap in lstMap) { lstMTVers.Add(objMap as MTVerseModel); } sReturn += GetAdreesVerses(lstMTVers); return(sReturn); } return(null); }
public static List <MTMapModel> GetListMap(String sAdress) { try { List <MTMapModel> lstMap = new List <MTMapModel>(); //Book string[] s1Split = sAdress.Split(' '); if (s1Split.Count() == 0) { return(null); } string sBook = s1Split[0]; var varBook = _objLibrary.LstBooks.Where(x => x.Abbrev == sBook); if (varBook.Count() == 0) { return(null); } MTBookModel objBook = varBook.First() as MTBookModel; if (s1Split.Count() <= 1) { lstMap.Add(objBook as MTMapModel); return(lstMap); } //Chapter string[] s2Split = s1Split[1].Split(':'); string sChapter = s2Split[0]; var varChapter = objBook.LstChapter.Where(x => x.Label == sChapter); if (varChapter.First() == null) { return(null); } MTChapterModel objChapter = varChapter.First() as MTChapterModel; if (s2Split.Count() <= 1) { lstMap.Add(objChapter as MTMapModel); return(lstMap); } //Verses string[] s3Split = s2Split[1].Split(','); List <MTMapModel> lstVerses = new List <MTMapModel>();//MTVerseModel foreach (string sVers in s3Split) { // "-" string[] s4Split = sVers.Split('-'); if (s4Split.Count() > 1) { string sVer = s4Split[0]; while (Convert.ToInt32(sVer) <= Convert.ToInt32(s4Split[1])) { var varVer = objChapter.LstVerses.Where(x => x.Label == sVer); if (varVer.First() == null) { return(null); } lstVerses.Add(varVer.First() as MTMapModel); sVer = (Convert.ToInt32(sVer) + 1).ToString(); } } // "," else { var varVer = objChapter.LstVerses.Where(x => x.Label == s4Split[0]); lstVerses.Add(varVer.First() as MTMapModel); } } return(lstVerses); } catch (Exception ex) { string e = ex.Message; return(null); } }
//################# Ask Adrees by Text ##################### private void tbTextAdres_TextChanged(object sender, TextChangedEventArgs e) { string sText = tbTextAdres.Text.ToLower(); sText = sText.Trim(); if (sText == "") { tblockTextAdres.Text = ""; SelectedPatch.Clear(); return; } string sFirstchar = sText.Substring(0, 1); sText = sText.Substring(1); char[] arr = sText.ToCharArray(); arr = Array.FindAll <char>(arr, (c => (char.IsLetter(c) || char.IsWhiteSpace(c)))); sText = new string(arr); sText = sFirstchar + sText; sText = sText.Trim(); if (sText == "") { tblockTextAdres.Text = ""; Action(this); return; } MTBookModel objSelBook = null; foreach (MTBookModel objBook in MTControler.Library.LstBooks) { string sBookAbrev = objBook.Abbrev.ToLower(); if (sText.Length <= sBookAbrev.Length) { if (sText.StartsWith(sBookAbrev.Substring(0, sText.Length))) { objSelBook = objBook; } } string sBookFull = objBook.Name.ToLower(); if (sText.Length <= sBookFull.Length) { if (sText.StartsWith(sBookFull.Substring(0, sText.Length))) { objSelBook = objBook; } } } if (objSelBook == null) { tblockTextAdres.Text = "Texto Inválido!"; SelectedPatch.Clear(); Action(this); return; } string sChapterVerses = tbTextAdres.Text.ToLower().Replace(sText, ""); sChapterVerses = sChapterVerses.Replace(" ", ""); tblockTextAdres.Text = objSelBook.Name + " " + sChapterVerses; List <MTMapModel> lstMap = MTControler.GetListMap(objSelBook.Abbrev + " " + sChapterVerses); if (lstMap != null) { SelectedPatch = lstMap; } else { SelectedPatch.Clear(); } Action(this); }