init
This commit is contained in:
		@@ -0,0 +1,32 @@
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using Aspose.Words.Replacing;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public static class ApaczaiMentoriTamogatoNyilatkozatReplacers
 | 
			
		||||
    {
 | 
			
		||||
        public static Regex IntezmenyNeveRegex = new Regex("{intezmenyNeve}");
 | 
			
		||||
        public static Regex IntezmenyCimeRegex = new Regex("{intezmenyCime}");
 | 
			
		||||
        public static Regex IntezmenyOMAzonositoRegex = new Regex("{intezmenyOMAzonosito}");
 | 
			
		||||
        public static Regex IntezmenyVezetoNeveRegex = new Regex("{intezmenyVezetoNeve}");
 | 
			
		||||
 | 
			
		||||
        public static Regex TanuloNeveRegex = new Regex("{tanuloNeve}");
 | 
			
		||||
        public static Regex TanuloOMAzonositoRegex = new Regex("{tanuloOMAzonosito}");
 | 
			
		||||
        public static Regex TanuloOsztalyRegex = new Regex("{tanuloOsztaly}");
 | 
			
		||||
 | 
			
		||||
        public static Regex MentorNeveRegex = new Regex("{mentorNeve}");
 | 
			
		||||
        public static Regex MentorOMAzonositoRegex = new Regex("{mentorOMAzonosito}");
 | 
			
		||||
        public static Regex MentorEmailcimRegex = new Regex("{mentorEmail}");
 | 
			
		||||
        public static Regex MentorTelefonRegex = new Regex("{mentorTelefon}");
 | 
			
		||||
 | 
			
		||||
        public static Regex KeltezesVarosRegex = new Regex("{keltezesVaros}");
 | 
			
		||||
        public static Regex KeltezesDatumRegex = new Regex("{keltezesDatum}");
 | 
			
		||||
        public static Regex AlairoSzemelyRegex = new Regex("{alairoszemely}");
 | 
			
		||||
        public static FindReplaceOptions FindReplaceoptions = new FindReplaceOptions
 | 
			
		||||
        {
 | 
			
		||||
            MatchCase = true,
 | 
			
		||||
            FindWholeWordsOnly = false,
 | 
			
		||||
            ReplacingCallback = new WordTextReplacer(),
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										74
									
								
								Kreta.BusinessLogic/Utils/ComboboxHelperExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								Kreta.BusinessLogic/Utils/ComboboxHelperExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Web.Mvc;
 | 
			
		||||
using Kreta.BusinessLogic.Classes.ComboBox;
 | 
			
		||||
using Kreta.Framework.Caching;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public static class ComboBoxHelperExtensions
 | 
			
		||||
    {
 | 
			
		||||
        public static List<ComboBoxListItem> ToComboBoxItemList(this IDictionary<string, string> dictionary, List<string> removeValueList = null, List<string> onlyValueList = null)
 | 
			
		||||
        {
 | 
			
		||||
            var itemList = removeValueList != null
 | 
			
		||||
                ? dictionary.Where(x => !removeValueList.Contains(x.Key))
 | 
			
		||||
                : dictionary;
 | 
			
		||||
            var itemList2 = onlyValueList != null
 | 
			
		||||
                ? itemList.Where(x => onlyValueList.Contains(x.Key))
 | 
			
		||||
                : itemList;
 | 
			
		||||
            var result = itemList2.Select(x => new ComboBoxListItem
 | 
			
		||||
            {
 | 
			
		||||
                Value = x.Key,
 | 
			
		||||
                Text = x.Value
 | 
			
		||||
            }).ToList();
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static List<SelectListItem> ToSelectItemList(this IDictionary<string, string> dictionary, List<string> removeValueList = null, string selectedValuePart = null)
 | 
			
		||||
        {
 | 
			
		||||
            var itemList = removeValueList != null
 | 
			
		||||
                ? dictionary.Where(x => !removeValueList.Contains(x.Key))
 | 
			
		||||
                : dictionary;
 | 
			
		||||
 | 
			
		||||
            var result = itemList.Select(x => new SelectListItem
 | 
			
		||||
            {
 | 
			
		||||
                Value = x.Key,
 | 
			
		||||
                Text = x.Value,
 | 
			
		||||
                Selected = !string.IsNullOrWhiteSpace(selectedValuePart) && x.Value.ToLower().IndexOf("- " + selectedValuePart.ToLower()) > -1
 | 
			
		||||
            }).ToList();
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static List<ComboBoxListItem> ToComboBoxItemList(this List<DictionaryItem> dictionaryList, List<int> removeValueList = null, List<int> onlyValueList = null)
 | 
			
		||||
        {
 | 
			
		||||
            var itemList = removeValueList != null ? dictionaryList.Where(x => !removeValueList.Contains(x.Id)) : dictionaryList;
 | 
			
		||||
            var itemList2 = onlyValueList != null ? itemList.Where(x => onlyValueList.Contains(x.Id)) : itemList;
 | 
			
		||||
 | 
			
		||||
            var result = itemList2.Select(x => new ComboBoxListItem
 | 
			
		||||
            {
 | 
			
		||||
                Value = x.Id.ToString(),
 | 
			
		||||
                Text = x.Name
 | 
			
		||||
            }).ToList();
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static List<SelectListItem> ToSelectItemList(this List<DictionaryItem> dictionaryList, List<int> removeValueList = null, string selectedValuePart = null)
 | 
			
		||||
        {
 | 
			
		||||
            var itemList = removeValueList != null
 | 
			
		||||
                ? dictionaryList.Where(x => !removeValueList.Contains(x.Id))
 | 
			
		||||
                : dictionaryList;
 | 
			
		||||
 | 
			
		||||
            var result = itemList.Select(x => new SelectListItem
 | 
			
		||||
            {
 | 
			
		||||
                Value = x.Id.ToString(),
 | 
			
		||||
                Text = x.Name,
 | 
			
		||||
                Selected = !string.IsNullOrWhiteSpace(selectedValuePart) && x.Name.ToLower().IndexOf("- " + selectedValuePart.ToLower()) > -1
 | 
			
		||||
            }).ToList();
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										448
									
								
								Kreta.BusinessLogic/Utils/CommonUtils.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										448
									
								
								Kreta.BusinessLogic/Utils/CommonUtils.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,448 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using System.Xml;
 | 
			
		||||
using System.Xml.Linq;
 | 
			
		||||
using System.Xml.Serialization;
 | 
			
		||||
using HtmlAgilityPack;
 | 
			
		||||
using Kreta.BusinessLogic.Classes;
 | 
			
		||||
using Kreta.BusinessLogic.HelperClasses;
 | 
			
		||||
using Kreta.BusinessLogic.Helpers;
 | 
			
		||||
using Kreta.Core;
 | 
			
		||||
using Kreta.Core.ConnectionType;
 | 
			
		||||
using Kreta.DataAccess.Interfaces;
 | 
			
		||||
using Kreta.DataAccessManual;
 | 
			
		||||
using Kreta.DataAccessManual.Interfaces;
 | 
			
		||||
using Kreta.Enums;
 | 
			
		||||
using Kreta.Enums.ManualEnums;
 | 
			
		||||
using Kreta.Resources;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public static class CommonUtils
 | 
			
		||||
    {
 | 
			
		||||
        public static string GetIntezmenyUrl(string intezmenyAzonosito)
 | 
			
		||||
            => string.Format(CommonResource.IntezmenyUrl, intezmenyAzonosito);
 | 
			
		||||
 | 
			
		||||
        public static string GetIntezmenyLinkWithNevEsUrl(int felhasznaloId, string intezmenyAzonosito, int intezmenyId, int tanevId)
 | 
			
		||||
            => string.Format(CommonResource.IntezmenyNevEsUrlLink, GetIntezmenyNev(felhasznaloId, intezmenyAzonosito, intezmenyId, tanevId), intezmenyAzonosito);
 | 
			
		||||
 | 
			
		||||
        private static string GetIntezmenyNev(int felhasznaloId, string intezmenyAzonosito, int intezmenyId, int tanevId)
 | 
			
		||||
            => new IntezmenyHelper(new OrganizationConnectionType(felhasznaloId, intezmenyId, intezmenyAzonosito, tanevId)).GetAktivIntezmenyNevCim().Nev;
 | 
			
		||||
 | 
			
		||||
        public static string GetIntezmenyFenntartoEmail(int felhasznaloId, string intezmenyAzonosito, int intezmenyId, int tanevId)
 | 
			
		||||
            => new IntezmenyHelper(new OrganizationConnectionType(felhasznaloId, intezmenyId, intezmenyAzonosito, tanevId)).GetAktivIntezmenyNevCim().Email;
 | 
			
		||||
 | 
			
		||||
        public static bool TernaryXor(bool a, bool b, bool c)
 | 
			
		||||
        {
 | 
			
		||||
            return !a && b ^ c || a && !(b || c);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region Gondviselő bejelentkezési név generálás
 | 
			
		||||
 | 
			
		||||
        public static string GenerateGondviseloBejelentkezesiNev(IFelhasznaloBelepesDal felhasznaloBelepesDal, string oktatasiAzonosito, ref int gondviseloIndex, int tanevId)
 | 
			
		||||
        {
 | 
			
		||||
            string bejelentkezesiNev;
 | 
			
		||||
            var letezoBelepesek = new List<IFelhasznaloBelepes>();
 | 
			
		||||
            do
 | 
			
		||||
            {
 | 
			
		||||
                bejelentkezesiNev = $"{oktatasiAzonosito}G{gondviseloIndex:00}";
 | 
			
		||||
                letezoBelepesek = felhasznaloBelepesDal.GetFelhasznaloBelepesei(bejelentkezesiNev, tanevId);
 | 
			
		||||
 | 
			
		||||
                ++gondviseloIndex;
 | 
			
		||||
            } while (letezoBelepesek.Any());
 | 
			
		||||
 | 
			
		||||
            return bejelentkezesiNev;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Felhasználó jelszó generálás
 | 
			
		||||
 | 
			
		||||
        public static string GenerateJelszo()
 | 
			
		||||
        {
 | 
			
		||||
            return Guid.NewGuid().ToString().Substring(0, Constants.General.JelszoMinimumKarakterekSzama);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        public static bool HasDirtyWordsContains(string str)
 | 
			
		||||
        {
 | 
			
		||||
            var dirtyWordsFiles = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "DirtyWords.xml", SearchOption.AllDirectories);
 | 
			
		||||
            if (dirtyWordsFiles.Length == 0)
 | 
			
		||||
            {
 | 
			
		||||
                throw new Exception("Not found DirtyWords.xml file!");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var xml = XElement.Load(dirtyWordsFiles[0]);
 | 
			
		||||
            var lst = xml.Elements("Word").ToList().Select(x => x.Value);
 | 
			
		||||
            HashSet<string> dirtyWords = new HashSet<string>(lst, StringComparer.OrdinalIgnoreCase);
 | 
			
		||||
 | 
			
		||||
            string[] result = Regex.Split(str, @"\W");
 | 
			
		||||
            return result.Any(szo => dirtyWords.Contains(szo));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string SerializeXmlFromClass<T>(T classForXml) where T : new()
 | 
			
		||||
        {
 | 
			
		||||
            var xmlSerializer = new XmlSerializer(classForXml.GetType());
 | 
			
		||||
            string xml;
 | 
			
		||||
 | 
			
		||||
            using (var stringWriter = new StringWriter())
 | 
			
		||||
            {
 | 
			
		||||
                using (var xmlWriter = XmlWriter.Create(stringWriter))
 | 
			
		||||
                {
 | 
			
		||||
                    xmlSerializer.Serialize(xmlWriter, classForXml);
 | 
			
		||||
                    xml = stringWriter.ToString();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return xml;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string RemoveHtmlTags(string input)
 | 
			
		||||
            => input == null ? null : Regex.Replace(input, "<[^>]*?[^<br />|p]>", string.Empty);
 | 
			
		||||
 | 
			
		||||
        public static string RemoveAllHtmlTags(string input)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(input))
 | 
			
		||||
            {
 | 
			
		||||
                return string.Empty;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var htmlDocument = new HtmlDocument();
 | 
			
		||||
            htmlDocument.LoadHtml(input);
 | 
			
		||||
            return htmlDocument.DocumentNode.InnerText;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string RemoveNotAllowedHtmlTags(string html, List<string> allowedTags)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(html))
 | 
			
		||||
            {
 | 
			
		||||
                return html;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var document = new HtmlDocument();
 | 
			
		||||
            document.LoadHtml(html);
 | 
			
		||||
 | 
			
		||||
            HtmlNodeCollection tryGetNodes = document.DocumentNode.SelectNodes("./*|./text()");
 | 
			
		||||
 | 
			
		||||
            if (tryGetNodes == null || !tryGetNodes.Any())
 | 
			
		||||
            {
 | 
			
		||||
                return html;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var nodes = new Queue<HtmlNode>(tryGetNodes);
 | 
			
		||||
 | 
			
		||||
            while (nodes.Count > 0)
 | 
			
		||||
            {
 | 
			
		||||
                var node = nodes.Dequeue();
 | 
			
		||||
                var parentNode = node.ParentNode;
 | 
			
		||||
 | 
			
		||||
                var childNodes = node.SelectNodes("./*|./text()");
 | 
			
		||||
 | 
			
		||||
                if (childNodes != null)
 | 
			
		||||
                {
 | 
			
		||||
                    foreach (var child in childNodes)
 | 
			
		||||
                    {
 | 
			
		||||
                        nodes.Enqueue(child);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (!allowedTags.Any(tag => tag == node.Name))
 | 
			
		||||
                {
 | 
			
		||||
                    if (childNodes != null)
 | 
			
		||||
                    {
 | 
			
		||||
                        foreach (var child in childNodes)
 | 
			
		||||
                        {
 | 
			
		||||
                            parentNode.InsertBefore(child, node);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    parentNode.RemoveChild(node);
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return document.DocumentNode.InnerHtml;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string ReplaceNewLineToHtmlTag(string input)
 | 
			
		||||
        {
 | 
			
		||||
            if (input == null)
 | 
			
		||||
                return null;
 | 
			
		||||
            return Regex.Replace(input, Constants.RegularExpressions.OneOfLineBreak, "<br />");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string CreateLinksInText(string text)
 | 
			
		||||
        {
 | 
			
		||||
            var result = new StringBuilder(text);
 | 
			
		||||
            var regx = new Regex(Constants.RegularExpressions.URLPattern, RegexOptions.IgnoreCase);
 | 
			
		||||
 | 
			
		||||
            var darabokMatches = Regex.Matches(text, Constants.RegularExpressions.RemoveLinkFromText).OfType<Match>();
 | 
			
		||||
            if (darabokMatches.Any())
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var darab in darabokMatches.OrderByDescending(x => x.Index))
 | 
			
		||||
                {
 | 
			
		||||
                    result.Replace(darab.Groups["vege"].Value, "").Replace(darab.Groups["eleje"].Value, "");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            var urlList = regx.Matches(result.ToString()).OfType<Match>().Select(m => m.Groups[0].Value).Distinct();
 | 
			
		||||
            if (urlList.Any())
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var url in urlList)
 | 
			
		||||
                {
 | 
			
		||||
                    result = result.Replace(url, string.Format("<a href=\"{0}\" target=\"_blank\">{0}</a>", url));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return result.ToString();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string GetOrganizationIdentifier()
 | 
			
		||||
        {
 | 
			
		||||
            return KretaServer.KretaServer.Instance.GetOrganizationIdentifier();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static int GetIntezmenyId(int felhasznaloId, string intezmenyAzonosito = null)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                var intezmenyAzonositoValue = intezmenyAzonosito ?? GetOrganizationIdentifier();
 | 
			
		||||
 | 
			
		||||
                IntezmenyHelper intezmenyHelper = new IntezmenyHelper(new OrganizationConnectionType(felhasznaloId, 0, intezmenyAzonositoValue, 0));
 | 
			
		||||
 | 
			
		||||
                return intezmenyHelper.GetIntezmenyId();
 | 
			
		||||
            }
 | 
			
		||||
            catch
 | 
			
		||||
            {
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static int GetAktualisTanevId(int felhasznaloId, string intezmenyAzonosito = null)
 | 
			
		||||
        {
 | 
			
		||||
            var intezmenyAzonositoValue = intezmenyAzonosito ?? GetOrganizationIdentifier();
 | 
			
		||||
 | 
			
		||||
            TanevHelper tanevHelper = new TanevHelper(new OrganizationConnectionType(felhasznaloId, GetIntezmenyId(felhasznaloId, intezmenyAzonositoValue), intezmenyAzonositoValue, 0));
 | 
			
		||||
            var aktivTanev = tanevHelper.GetTanevInfo();
 | 
			
		||||
            return aktivTanev.Id;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static DataSet GetLoginDashboardUzenet(IConnectionType connectionType)
 | 
			
		||||
        {
 | 
			
		||||
            return Dal.CustomConnection.Run(connectionType, h =>
 | 
			
		||||
            {
 | 
			
		||||
                IDashboardUzenetDal dal = h.DashboardUzenet();
 | 
			
		||||
                return dal.GetLoginDashboardUzenet();
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static readonly List<HetNapjaTipusEnum> OrderedHetNapjaTipusEnumList = new List<HetNapjaTipusEnum>
 | 
			
		||||
        {
 | 
			
		||||
            HetNapjaTipusEnum.Hetfo,
 | 
			
		||||
            HetNapjaTipusEnum.Kedd,
 | 
			
		||||
            HetNapjaTipusEnum.Szerda,
 | 
			
		||||
            HetNapjaTipusEnum.Csutortok,
 | 
			
		||||
            HetNapjaTipusEnum.Pentek,
 | 
			
		||||
            HetNapjaTipusEnum.Szombat,
 | 
			
		||||
            HetNapjaTipusEnum.Vasarnap
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 2020/21-es tanévtől kezdődően (40, vagy annál nagyobb sorszám) új SZT van.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static bool IsSelectedTanev20_21OrLater(TanevCO selectedTanev)
 | 
			
		||||
        {
 | 
			
		||||
            var isSelectedTanev20_21OrLater = selectedTanev.Sorszam >= 40;
 | 
			
		||||
            return isSelectedTanev20_21OrLater;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static bool IsSelectedTanev21_22OrLater(TanevCO selectedTanev)
 | 
			
		||||
        {
 | 
			
		||||
            return selectedTanev.Sorszam >= 42;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Az igen/nem lista megjelenítését adja vissza a booleanDisplayFormatEnum alapján.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="booleanDisplayFormatEnum">Az igen/nem lista megjelenítését eldöntő enum: Igen/Nem, T/F, I/N</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public static List<string> GetIgenNemList(BooleanDisplayFormatEnum booleanDisplayFormatEnum)
 | 
			
		||||
        {
 | 
			
		||||
            var result = new List<string> { true.GetDisplayName(booleanDisplayFormatEnum), false.GetDisplayName(booleanDisplayFormatEnum) };
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// A value megjelenítéshez tartozó formázás.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <typeparam name="T">A value típusa.</typeparam>
 | 
			
		||||
        /// <param name="value">A formázni kívánt érték</param>
 | 
			
		||||
        /// <param name="dateTimeToStringPattern">Ha a T az DateTime, akkor annak a formázáshoz használható paraméter. Ha null, akkor Kreta.Core.Constants.ToStringPattern.HungarianDate.</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public static string GetDisplayableString<T>(T value, int tanevId, string dateTimeToStringPattern = null)
 | 
			
		||||
        {
 | 
			
		||||
            string result;
 | 
			
		||||
            switch (value)
 | 
			
		||||
            {
 | 
			
		||||
                case string stringValue:
 | 
			
		||||
                    result = !string.IsNullOrWhiteSpace(stringValue) ? stringValue : string.Empty;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DateTime dateValue:
 | 
			
		||||
                    string toStringPattern = string.IsNullOrWhiteSpace(dateTimeToStringPattern) ? Constants.ToStringPattern.HungarianDate : dateTimeToStringPattern;
 | 
			
		||||
                    result = dateValue.ToString(toStringPattern);
 | 
			
		||||
                    break;
 | 
			
		||||
                case bool boolvalue:
 | 
			
		||||
                    result = boolvalue.GetDisplayName();
 | 
			
		||||
                    break;
 | 
			
		||||
                case Enum enumValue:
 | 
			
		||||
                    result = enumValue.GetDisplayName(tanevId);
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    result = value != null ? value.ToString() : string.Empty;
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region NevElvalaszto
 | 
			
		||||
 | 
			
		||||
        public static int GetNevElvalasztoIndex(string nev)
 | 
			
		||||
        {
 | 
			
		||||
            var textInfo = new CultureInfo(Constants.General.HungarianCulture, false).TextInfo;
 | 
			
		||||
            var titleCaseName = textInfo.ToTitleCase(nev);
 | 
			
		||||
            var nevElotag = GetNevElotag(titleCaseName);
 | 
			
		||||
 | 
			
		||||
            var nevElotagNelkul = titleCaseName.Remove(0, nevElotag.Length);
 | 
			
		||||
 | 
			
		||||
            var nevElvalasztoIndex = nevElotag.Length + nevElotagNelkul.IndexOf(" ");
 | 
			
		||||
            return nevElvalasztoIndex;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string GetNevElotag(string nev)
 | 
			
		||||
        {
 | 
			
		||||
            var textInfo = new CultureInfo(Constants.General.HungarianCulture, false).TextInfo;
 | 
			
		||||
            var titleCaseName = textInfo.ToTitleCase(nev);
 | 
			
		||||
 | 
			
		||||
            var elotagMatch = Regex.Match(titleCaseName, Constants.RegularExpressions.NevElotagEllenorzes);
 | 
			
		||||
            var elotag = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
            while (elotagMatch.Success)
 | 
			
		||||
            {
 | 
			
		||||
                elotag.Append(elotagMatch.Value);
 | 
			
		||||
                titleCaseName = titleCaseName.Remove(0, elotagMatch.Value.Length).Trim();
 | 
			
		||||
                elotagMatch = Regex.Match(titleCaseName, Constants.RegularExpressions.NevElotagEllenorzes);
 | 
			
		||||
            }
 | 
			
		||||
            return elotag.ToString();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion NevElvalaszto
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// 2019/20-es tanév előtti összes-re vonatkkozik
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static bool IsSelectedTanevIsElozo(TanevCO selectedTanev)
 | 
			
		||||
        {
 | 
			
		||||
            var isSelectedTanevIsElozo = !selectedTanev.IsAktiv && !selectedTanev.IsKovetkezo;
 | 
			
		||||
            return isSelectedTanevIsElozo;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static bool IsSzcIntezmenyFenntartoAzonosito(IConnectionType connectionType)
 | 
			
		||||
        {
 | 
			
		||||
            var intezmenyAdatok = new IntezmenyHelper(connectionType).GetIntezmenyiAdatok();
 | 
			
		||||
            if (int.TryParse(intezmenyAdatok.FenntartoAzonosito, out int fenntartoAzonosito))
 | 
			
		||||
            {
 | 
			
		||||
                var isSzcFenntartoAzonosito = (601 <= fenntartoAzonosito && fenntartoAzonosito <= 644) || fenntartoAzonosito == 998;
 | 
			
		||||
                return isSzcFenntartoAzonosito;
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static double ConvertByteToMByte(double value)
 | 
			
		||||
        {
 | 
			
		||||
            return value / 1024 / 1024;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static double ConvertKByteToMByte(int value)
 | 
			
		||||
        {
 | 
			
		||||
            return value / 1024;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static double ConvertKByteToGByte(int value)
 | 
			
		||||
        {
 | 
			
		||||
            return value / 1024 / 1024;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static int GetHetNapja(DateTime date)
 | 
			
		||||
        {
 | 
			
		||||
            HetNapjaTipusEnum hetNapja = HetNapjaTipusEnum.na;
 | 
			
		||||
            switch (date.DayOfWeek)
 | 
			
		||||
            {
 | 
			
		||||
                case DayOfWeek.Monday:
 | 
			
		||||
                    hetNapja = HetNapjaTipusEnum.Hetfo;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DayOfWeek.Tuesday:
 | 
			
		||||
                    hetNapja = HetNapjaTipusEnum.Kedd;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DayOfWeek.Wednesday:
 | 
			
		||||
                    hetNapja = HetNapjaTipusEnum.Szerda;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DayOfWeek.Thursday:
 | 
			
		||||
                    hetNapja = HetNapjaTipusEnum.Csutortok;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DayOfWeek.Friday:
 | 
			
		||||
                    hetNapja = HetNapjaTipusEnum.Pentek;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DayOfWeek.Saturday:
 | 
			
		||||
                    hetNapja = HetNapjaTipusEnum.Szombat;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DayOfWeek.Sunday:
 | 
			
		||||
                    hetNapja = HetNapjaTipusEnum.Vasarnap;
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
            return (int)hetNapja;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static string GetEntitasIdJson(IEnumerable<int> ids)
 | 
			
		||||
        {
 | 
			
		||||
            return JsonConvert.SerializeObject(ids.Select(i => new { Id = i }).ToArray());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static IEnumerable<string> TajSzamValidation(string tajSzam)
 | 
			
		||||
        {
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(tajSzam))
 | 
			
		||||
            {
 | 
			
		||||
                tajSzam = tajSzam.Replace("_", "");
 | 
			
		||||
 | 
			
		||||
                if (tajSzam.Length > 0 && tajSzam.Length != 9)
 | 
			
		||||
                {
 | 
			
		||||
                    yield return ErrorResource.TAJszamHosszaNemMegfelelo;
 | 
			
		||||
                }
 | 
			
		||||
                else if (string.Equals(tajSzam, "000000000", StringComparison.OrdinalIgnoreCase))
 | 
			
		||||
                {
 | 
			
		||||
                    yield return ErrorResource.TAJszamCsupaNulla;
 | 
			
		||||
                }
 | 
			
		||||
                else if (tajSzam.Length == 9)
 | 
			
		||||
                {
 | 
			
		||||
                    var tajszam = new int[9];
 | 
			
		||||
                    for (var x = 0; x < tajszam.Length; x++)
 | 
			
		||||
                    {
 | 
			
		||||
                        tajszam[x] = Convert.ToInt32(tajSzam.Substring(x, 1));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if ((((tajszam[1] + tajszam[3] + tajszam[5] + tajszam[7]) * 7) + ((tajszam[0] + tajszam[2] + tajszam[4] + tajszam[6]) * 3)) % 10 != tajszam[8])
 | 
			
		||||
                    {
 | 
			
		||||
                        yield return ErrorResource.TAJszamNemErvenyes;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										71
									
								
								Kreta.BusinessLogic/Utils/DataTableExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Kreta.BusinessLogic/Utils/DataTableExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using DataTable = System.Data.DataTable;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Extensions for manipulating DataTables
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public static class DataTableExtensions
 | 
			
		||||
    {
 | 
			
		||||
        private static string suffixPattern = @"(_DNAME)|(_BNAME)|(_BOOL)";
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Replaces id columns with added _DNAME and _BNAME colums.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="table">DataTable returned by DataAccessBase.GetData.</param>
 | 
			
		||||
        public static DataTable ConsolidateColumns(this DataTable table)
 | 
			
		||||
        {
 | 
			
		||||
            //Reading all column names
 | 
			
		||||
            var columnNames = (table.Columns.Cast<DataColumn>().Select(column => column.ColumnName)).ToList();
 | 
			
		||||
 | 
			
		||||
            //Selecting the columns we need in the right order
 | 
			
		||||
            var orderedColumnNames = new List<string>();
 | 
			
		||||
            foreach (var name in columnNames)
 | 
			
		||||
            {
 | 
			
		||||
                if (Regex.IsMatch(name, suffixPattern))
 | 
			
		||||
                {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                if (columnNames.Contains($"{name}_DNAME"))
 | 
			
		||||
                {
 | 
			
		||||
                    orderedColumnNames.Add($"{name}_DNAME");
 | 
			
		||||
                }
 | 
			
		||||
                else if (columnNames.Contains($"{name}_BNAME"))
 | 
			
		||||
                {
 | 
			
		||||
                    orderedColumnNames.Add($"{name}_BNAME");
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    orderedColumnNames.Add(name);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //Removing everything else
 | 
			
		||||
            var redundantColumnNames = columnNames.Except(orderedColumnNames);
 | 
			
		||||
            foreach (var name in redundantColumnNames)
 | 
			
		||||
            {
 | 
			
		||||
                table.Columns.Remove(name);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //Ordering columns
 | 
			
		||||
            var i = 0;
 | 
			
		||||
            foreach (var name in orderedColumnNames)
 | 
			
		||||
            {
 | 
			
		||||
                table.Columns[name].SetOrdinal(i++);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //Renaming columns
 | 
			
		||||
            var suffixedColumnNames = orderedColumnNames.Where(n => Regex.IsMatch(n, suffixPattern));
 | 
			
		||||
            foreach (var name in suffixedColumnNames)
 | 
			
		||||
            {
 | 
			
		||||
                table.Columns[name].ColumnName = Regex.Replace(name, suffixPattern, string.Empty);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return table;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										45
									
								
								Kreta.BusinessLogic/Utils/JObjectExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								Kreta.BusinessLogic/Utils/JObjectExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using Newtonsoft.Json.Linq;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public static class JObjectExtensions
 | 
			
		||||
    {
 | 
			
		||||
        public static DataTable ToDataTable(this JObject jObject)
 | 
			
		||||
        {
 | 
			
		||||
            var props = jObject.Properties();
 | 
			
		||||
            DataTable table = new DataTable();
 | 
			
		||||
            var count = props.Count();
 | 
			
		||||
            for (int i = 0; i < count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                JProperty prop = props.ElementAt(i);
 | 
			
		||||
                switch (prop.Value.Type)
 | 
			
		||||
                {
 | 
			
		||||
                    case JTokenType.Integer:
 | 
			
		||||
                        table.Columns.Add(prop.Name, typeof(int));
 | 
			
		||||
                        break;
 | 
			
		||||
                    default:
 | 
			
		||||
                        table.Columns.Add(prop.Name, typeof(string));
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            object[] values = new object[props.Count()];
 | 
			
		||||
            for (int i = 0; i < values.Length; i++)
 | 
			
		||||
            {
 | 
			
		||||
                var prop = props.ElementAt(i);
 | 
			
		||||
                switch (prop.Value.Type)
 | 
			
		||||
                {
 | 
			
		||||
                    case JTokenType.Integer:
 | 
			
		||||
                        values[i] = prop.Value.Value<int>();
 | 
			
		||||
                        break;
 | 
			
		||||
                    default:
 | 
			
		||||
                        values[i] = prop.Value.Value<string>();
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            table.Rows.Add(values);
 | 
			
		||||
            return table;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										203
									
								
								Kreta.BusinessLogic/Utils/LogicUtil.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								Kreta.BusinessLogic/Utils/LogicUtil.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,203 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using Kreta.BusinessLogic.Classes.ComboBox;
 | 
			
		||||
using Kreta.Core;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    internal class LogicUtil
 | 
			
		||||
    {
 | 
			
		||||
        internal static IDictionary<string, string> CreateDropdownContent(DataSet ds, string key, string value, string baseItem = null, bool sort = true)
 | 
			
		||||
        {
 | 
			
		||||
            //Alapból mindenhol kell hogy legyen benne érték
 | 
			
		||||
            //
 | 
			
		||||
            IDictionary<string, string> result = new Dictionary<string, string>();
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(baseItem))
 | 
			
		||||
                result.Add("", baseItem);
 | 
			
		||||
            //else
 | 
			
		||||
            //    result.Add("", StringResourcesUtil.GetString(364));//Kérem válasszon...
 | 
			
		||||
 | 
			
		||||
            if (ds.Tables.Count < 1)
 | 
			
		||||
                return result;
 | 
			
		||||
            var dt = ds.Tables[0];
 | 
			
		||||
            var items = dt.AsEnumerable().ToDictionary(row => row.Field<int>(key).ToString(), row => row.Field<string>(value));
 | 
			
		||||
            if (sort)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var item in items.OrderBy(a => a.Value))
 | 
			
		||||
                {
 | 
			
		||||
                    result.Add(item);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var item in items)
 | 
			
		||||
                {
 | 
			
		||||
                    result.Add(item);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static IDictionary<string, string> CreateGroupedDropdownContent(DataSet ds, string key, string value,
 | 
			
		||||
            string group, IList<string> groupIds, string baseItem = null, bool groupIsEnum = false, bool noorder = false)
 | 
			
		||||
        {
 | 
			
		||||
            IDictionary<string, string> result = new Dictionary<string, string>();
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(baseItem))
 | 
			
		||||
            { result.Add("", baseItem); }
 | 
			
		||||
            //else { result.Add("", StringResourcesUtil.GetString(364)); } /*Kérem válasszon...*/
 | 
			
		||||
            if (ds.Tables.Count < 1)
 | 
			
		||||
            { return result; }
 | 
			
		||||
            var dt = ds.Tables[0];
 | 
			
		||||
 | 
			
		||||
            if (groupIsEnum)
 | 
			
		||||
            {
 | 
			
		||||
                if (noorder == false)
 | 
			
		||||
                {
 | 
			
		||||
                    foreach (var item in dt.AsEnumerable().OrderBy(a => a.Field<int>(group)))
 | 
			
		||||
                    {
 | 
			
		||||
                        var groupId = "SDAGID" + item.Field<int>(group);
 | 
			
		||||
                        if (groupIds.All(a => a != groupId))
 | 
			
		||||
                        {
 | 
			
		||||
                            groupIds.Add(groupId);
 | 
			
		||||
                            result.Add(groupId, item.Field<string>(group + "_DNAME"));
 | 
			
		||||
                        }
 | 
			
		||||
                        result.Add(item.Field<int>(key).ToString(), item.Field<string>(value));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    foreach (var item in dt.AsEnumerable())
 | 
			
		||||
                    {
 | 
			
		||||
                        var groupId = "SDAGID" + item.Field<int>(group);
 | 
			
		||||
                        if (groupIds.All(a => a != groupId))
 | 
			
		||||
                        {
 | 
			
		||||
                            groupIds.Add(groupId);
 | 
			
		||||
                            result.Add(groupId, item.Field<string>(group + "_DNAME"));
 | 
			
		||||
                        }
 | 
			
		||||
                        result.Add(item.Field<int>(key).ToString(), item.Field<string>(value));
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                if (noorder == false)
 | 
			
		||||
                {
 | 
			
		||||
                    foreach (var item in dt.AsEnumerable().OrderBy(a => a.Field<string>(group)))
 | 
			
		||||
                    {
 | 
			
		||||
                        var groupId = "SDAGID" + item.Field<string>(group);
 | 
			
		||||
                        if (groupIds.All(a => a != groupId))
 | 
			
		||||
                        {
 | 
			
		||||
                            groupIds.Add(groupId);
 | 
			
		||||
                            result.Add(groupId, item.Field<string>(group));
 | 
			
		||||
                        }
 | 
			
		||||
                        result.Add(item.Field<int>(key).ToString(), item.Field<string>(value));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    foreach (var item in dt.AsEnumerable())
 | 
			
		||||
                    {
 | 
			
		||||
                        var groupId = "SDAGID" + item.Field<string>(group);
 | 
			
		||||
                        if (groupIds.All(a => a != groupId))
 | 
			
		||||
                        {
 | 
			
		||||
                            groupIds.Add(groupId);
 | 
			
		||||
                            result.Add(groupId, item.Field<string>(group));
 | 
			
		||||
                        }
 | 
			
		||||
                        result.Add(item.Field<int>(key).ToString(), item.Field<string>(value));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// MVC-s csoportosítható select listát állít elő
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ds"></param>
 | 
			
		||||
        /// <param name="keyColumn"></param>
 | 
			
		||||
        /// <param name="valueColumn">ha null, akkor a <paramref name="valueFormat"/> paraméterből veszi a value formátumát</param>
 | 
			
		||||
        /// <param name="groupNamesColumn"></param>
 | 
			
		||||
        /// <param name="groupOrderColumn"></param>
 | 
			
		||||
        /// <param name="valueFormat">az item-ek megjelnési formátumát definiálja:
 | 
			
		||||
        ///     pl.: "{Nev} ({OktatasiAzonosito})" ahol a Nev és OktatasiAzonosito a <paramref name="ds"/>-ben az oszlop neve</param>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        internal static List<ComboBoxListItem> CreateMvcGroupedSelectListItem(DataSet ds, string keyColumn, string valueColumn, string groupNamesColumn, string groupOrderColumn = null, string valueFormat = null)
 | 
			
		||||
        {
 | 
			
		||||
            MatchCollection matchesInFormat = null;
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(valueFormat))
 | 
			
		||||
            {
 | 
			
		||||
                matchesInFormat = Regex.Matches(valueFormat, Constants.RegularExpressions.OszlopNevHelyettesito);
 | 
			
		||||
            }
 | 
			
		||||
            DataTable dt = ds.Tables.Count > 0 ? ds.Tables[0] : null;
 | 
			
		||||
            if (dt == null)
 | 
			
		||||
            {
 | 
			
		||||
                return new List<ComboBoxListItem>();
 | 
			
		||||
            }
 | 
			
		||||
            EnumerableRowCollection<DataRow> dataRowList = dt.AsEnumerable();
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(groupOrderColumn))
 | 
			
		||||
            {
 | 
			
		||||
                dataRowList = dataRowList.OrderBy(x => x.Field<int>(groupOrderColumn));
 | 
			
		||||
            }
 | 
			
		||||
            var groups = dataRowList
 | 
			
		||||
                .GroupBy(x => x.Field<string>(groupNamesColumn))
 | 
			
		||||
                .Select(group => new KeyValuePair<string, ComboListGroup>(group.Key, new ComboListGroup { Name = group.Key }))
 | 
			
		||||
                .ToDictionary(item => item.Key, item => item.Value);
 | 
			
		||||
 | 
			
		||||
            var result = dt.Rows
 | 
			
		||||
                .Cast<DataRow>()
 | 
			
		||||
                .Select(item => new ComboBoxListItem
 | 
			
		||||
                {
 | 
			
		||||
                    GroupName = groups[item.Field<string>(groupNamesColumn)].Name,
 | 
			
		||||
                    Text = valueColumn != null ? item.Field<string>(valueColumn) : GetFilledValueFormat(item, valueFormat, matchesInFormat),
 | 
			
		||||
                    Value = item.Field<int>(keyColumn).ToString()
 | 
			
		||||
                })
 | 
			
		||||
                .ToList();
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static string GetFilledValueFormat(DataRow item, string valueFormat, MatchCollection matches)
 | 
			
		||||
        {
 | 
			
		||||
            var sb = new StringBuilder(valueFormat);
 | 
			
		||||
            for (int i = 0; i < matches.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                sb = sb.Replace(matches[i].Value, item[matches[i].Value.Trim("{}".ToCharArray())].ToString());
 | 
			
		||||
            }
 | 
			
		||||
            return sb.ToString();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static List<ExtraDataComboBoxListItem> CreateMvcGroupedExtendedComboBoxListItem(DataSet ds, string keyColumn, string valueColumn, string groupNamesColumn, string groupOrderColumn = null, IEnumerable<string> extraDataParameters = null)
 | 
			
		||||
        {
 | 
			
		||||
            DataTable dt = ds.Tables.Count > 0 ? ds.Tables[0] : null;
 | 
			
		||||
            if (dt == null)
 | 
			
		||||
            {
 | 
			
		||||
                return new List<ExtraDataComboBoxListItem>();
 | 
			
		||||
            }
 | 
			
		||||
            EnumerableRowCollection<DataRow> dataRowList = dt.AsEnumerable();
 | 
			
		||||
            if (!string.IsNullOrWhiteSpace(groupOrderColumn))
 | 
			
		||||
            {
 | 
			
		||||
                dataRowList = dataRowList.OrderBy(x => x.Field<int>(groupOrderColumn));
 | 
			
		||||
            }
 | 
			
		||||
            var groups = dataRowList
 | 
			
		||||
                .GroupBy(x => x.Field<string>(groupNamesColumn))
 | 
			
		||||
                .Select(group => new KeyValuePair<string, ComboListGroup>(group.Key, new ComboListGroup { Name = group.Key }))
 | 
			
		||||
                .ToDictionary(item => item.Key, item => item.Value);
 | 
			
		||||
 | 
			
		||||
            var result = dt.Rows
 | 
			
		||||
                .Cast<DataRow>()
 | 
			
		||||
                .Select(item => new ExtraDataComboBoxListItem
 | 
			
		||||
                {
 | 
			
		||||
                    GroupName = groups[item.Field<string>(groupNamesColumn)].Name,
 | 
			
		||||
                    Text = item.Field<string>(valueColumn),
 | 
			
		||||
                    Value = item.Field<int>(keyColumn).ToString(),
 | 
			
		||||
                    Data = extraDataParameters.ToDictionary(extraParameterName => extraParameterName, extraParameterName => item[extraParameterName].ToString())
 | 
			
		||||
                })
 | 
			
		||||
                .ToList();
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										40
									
								
								Kreta.BusinessLogic/Utils/MulasztasiErtesitokReplacers.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Kreta.BusinessLogic/Utils/MulasztasiErtesitokReplacers.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using Aspose.Words.Replacing;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public static class MulasztasiErtesitokReplacers
 | 
			
		||||
    {
 | 
			
		||||
        public static Regex TanuloNeveRegex = new Regex("{tanuloNeve}");
 | 
			
		||||
        public static Regex IntezmenyNeveRegex = new Regex("{intezmenyNeve}");
 | 
			
		||||
        public static Regex IntezmenyCimeRegex = new Regex("{intezmenyCime}");
 | 
			
		||||
        public static Regex TagintezmenyNeveRegex = new Regex("{tagintezmenyNeve}");
 | 
			
		||||
        public static Regex TagintezmenyCimeRegex = new Regex("{tagintezmenyCime}");
 | 
			
		||||
        public static Regex OsztalyNeveRegex = new Regex("{osztalyNeve}");
 | 
			
		||||
        public static Regex AnyjaNeveRegex = new Regex("{anyjaNeve}");
 | 
			
		||||
        public static Regex SzuletesiHelyRegex = new Regex("{szuletesiHely}");
 | 
			
		||||
        public static Regex SzuletesiIdoRegex = new Regex("{szuletesiIdo}");
 | 
			
		||||
        public static Regex LakohelyCimeRegex = new Regex("{lakohelyCime}");
 | 
			
		||||
        public static Regex TartozkodasiCimeRegex = new Regex("{tartozkodasiCime}");
 | 
			
		||||
        public static Regex OsztalyfonokNeveRegex = new Regex("{osztalyfonokNeve}");
 | 
			
		||||
        public static Regex OsszesMulasztasSzamaRegex = new Regex("{osszesMulasztasSzama}");
 | 
			
		||||
        public static Regex IgazoltMulasztasokSzamaRegex = new Regex("{igazoltMulasztasokSzama}");
 | 
			
		||||
        public static Regex IgazolatlanMulasztasokSzamaRegex = new Regex("{igazolatlanMulasztasokSzama}");
 | 
			
		||||
        public static Regex IgazoltHozottMulasztasokSzamaRegex = new Regex("{igazoltHozottMulasztasokSzama}");
 | 
			
		||||
        public static Regex IgazolatlanHozottMulasztasokSzamaRegex = new Regex("{igazolatlanHozottMulasztasokSzama}");
 | 
			
		||||
        public static Regex KeltezesVarosRegex = new Regex("{keltezesVaros}");
 | 
			
		||||
        public static Regex KeltezesDatumRegex = new Regex("{keltezesDatum}");
 | 
			
		||||
        public static Regex IntezmenyVezetoNeveRegex = new Regex("{intezmenyVezetoNeve}");
 | 
			
		||||
        public static Regex IntezmenyVezetoRegex = new Regex("{intezmenyVezeto}");
 | 
			
		||||
        public static Regex GondviseloNeveRegex = new Regex("{gondviseloNeve}");
 | 
			
		||||
        public static Regex GondviseloTelefonszamaRegex = new Regex("{gondviseloTelefonszama}");
 | 
			
		||||
        public static Regex GondviseloLakohelyeRegex = new Regex("{gondviseloLakohelye}");
 | 
			
		||||
        public static Regex TanevNeveRegex = new Regex("{tanevNeve}");
 | 
			
		||||
        public static FindReplaceOptions FindReplaceoptions = new FindReplaceOptions
 | 
			
		||||
        {
 | 
			
		||||
            MatchCase = true,
 | 
			
		||||
            FindWholeWordsOnly = false,
 | 
			
		||||
            ReplacingCallback = new WordTextReplacer(),
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										50
									
								
								Kreta.BusinessLogic/Utils/NevUtils.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								Kreta.BusinessLogic/Utils/NevUtils.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using Kreta.BusinessLogic.Classes;
 | 
			
		||||
using Kreta.BusinessLogic.HelperClasses;
 | 
			
		||||
using Kreta.Core;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public static class NevUtils
 | 
			
		||||
    {
 | 
			
		||||
        public static NevCo GetNevCo(string nev)
 | 
			
		||||
        {
 | 
			
		||||
            if (nev.IndexOf(' ') < 0)
 | 
			
		||||
            {
 | 
			
		||||
                nev += ' ';
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            NevCo result;
 | 
			
		||||
 | 
			
		||||
            string nevElsoReszCompare = nev?.Split(' ')[0].ToComparableString();
 | 
			
		||||
            if (Constants.ElotagList.Any(x => x.ToComparableString() == nevElsoReszCompare))
 | 
			
		||||
            {
 | 
			
		||||
                result = new NevCo
 | 
			
		||||
                {
 | 
			
		||||
                    Elotag = nev?.Split(' ')[0],
 | 
			
		||||
                    Vezeteknev = nev?.Split(' ')[1]
 | 
			
		||||
                };
 | 
			
		||||
                //NOTE: A keresztneveket úgy kapjuk vissza, hogy levágjuk a teljes névből az elejét(Előtag + Vezetéknév + a 2 szóköz, ami ezeket követi)!
 | 
			
		||||
                if ((result.Elotag.Length + result.Vezeteknev.Length + 2) <= (nev?.Length ?? 0))
 | 
			
		||||
                {
 | 
			
		||||
                    result.Keresztnev = nev?.Substring(result.Elotag.Length + result.Vezeteknev.Length + 2);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                result = new NevCo
 | 
			
		||||
                {
 | 
			
		||||
                    Elotag = null,
 | 
			
		||||
                    Vezeteknev = nev?.Split(' ')[0]
 | 
			
		||||
                };
 | 
			
		||||
                //NOTE: A keresztneveket úgy kapjuk vissza, hogy levágjuk a teljes névből az elejét(Vezetéknév + a szóköz, ami ezt követi)!
 | 
			
		||||
                if ((result.Vezeteknev.Length + 1) <= (nev?.Length ?? 0))
 | 
			
		||||
                {
 | 
			
		||||
                    result.Keresztnev = nev?.Substring(result.Vezeteknev.Length + 1);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								Kreta.BusinessLogic/Utils/StringResourcesUtils.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Kreta.BusinessLogic/Utils/StringResourcesUtils.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
using Kreta.Framework;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public static class StringResourcesUtils
 | 
			
		||||
    {
 | 
			
		||||
        public static string GetString(int id)
 | 
			
		||||
        {
 | 
			
		||||
            return StringResourcesUtil.GetString(id, 0);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										83
									
								
								Kreta.BusinessLogic/Utils/WordTextReplacer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								Kreta.BusinessLogic/Utils/WordTextReplacer.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,83 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using Aspose.Words;
 | 
			
		||||
using Aspose.Words.Replacing;
 | 
			
		||||
 | 
			
		||||
namespace Kreta.BusinessLogic.Utils
 | 
			
		||||
{
 | 
			
		||||
    public class WordTextReplacer : IReplacingCallback
 | 
			
		||||
    {
 | 
			
		||||
        public List<Run> _nodes = new List<Run>();
 | 
			
		||||
 | 
			
		||||
        ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            // This is a Run node that contains either the beginning or the complete match.
 | 
			
		||||
            var currentNode = e.MatchNode;
 | 
			
		||||
 | 
			
		||||
            // The first (and may be the only) run can contain text before the match, 
 | 
			
		||||
            // in this case it is necessary to split the run.
 | 
			
		||||
            if (e.MatchOffset > 0)
 | 
			
		||||
            {
 | 
			
		||||
                currentNode = SplitRun((Run)currentNode, e.MatchOffset);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var runs = new System.Collections.ArrayList();
 | 
			
		||||
 | 
			
		||||
            // Find all runs that contain parts of the match string.
 | 
			
		||||
            var remainingLength = e.Match.Value.Length;
 | 
			
		||||
            while (
 | 
			
		||||
 | 
			
		||||
            (remainingLength > 0) &&
 | 
			
		||||
 | 
			
		||||
            (currentNode != null) &&
 | 
			
		||||
 | 
			
		||||
            (currentNode.GetText().Length <= remainingLength))
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                runs.Add(currentNode);
 | 
			
		||||
 | 
			
		||||
                remainingLength -= currentNode.GetText().Length;
 | 
			
		||||
 | 
			
		||||
                // Select the next Run node. 
 | 
			
		||||
                // Have to loop because there could be other nodes such as BookmarkStart etc.
 | 
			
		||||
                do
 | 
			
		||||
                {
 | 
			
		||||
                    currentNode = currentNode.NextSibling;
 | 
			
		||||
                }
 | 
			
		||||
                while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Split the last run that contains the match if there is any text left.
 | 
			
		||||
            if ((currentNode != null) && (remainingLength > 0))
 | 
			
		||||
            {
 | 
			
		||||
                SplitRun((Run)currentNode, remainingLength);
 | 
			
		||||
                runs.Add(currentNode);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var runText = "";
 | 
			
		||||
            foreach (Run run in runs)
 | 
			
		||||
            {
 | 
			
		||||
                runText += run.Text;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ((Run)runs[0]).Text = runText;
 | 
			
		||||
 | 
			
		||||
            for (var i = 1; i < runs.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                ((Run)runs[i]).Remove();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            _nodes.Add((Run)runs[0]);
 | 
			
		||||
 | 
			
		||||
            return ReplaceAction.Replace;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static Run SplitRun(Run run, int position)
 | 
			
		||||
        {
 | 
			
		||||
            var afterRun = (Run)run.Clone(true);
 | 
			
		||||
            afterRun.Text = run.Text.Substring(position);
 | 
			
		||||
            run.Text = run.Text.Substring(0, position);
 | 
			
		||||
            run.ParentNode.InsertAfter(afterRun, run);
 | 
			
		||||
            return afterRun;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user