init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
24
Kreta.DataAccessManual/Util/CommandParameter.cs
Normal file
24
Kreta.DataAccessManual/Util/CommandParameter.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using SDA.DataProvider;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
public class CommandParameter
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public object Value { get; set; }
|
||||
public SDADBType Type { get; set; }
|
||||
|
||||
public CommandParameter(string name, object value)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public CommandParameter(string name, object value, SDADBType type)
|
||||
{
|
||||
Name = name;
|
||||
Value = value;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
}
|
318
Kreta.DataAccessManual/Util/CommonUtilsDal.cs
Normal file
318
Kreta.DataAccessManual/Util/CommonUtilsDal.cs
Normal file
|
@ -0,0 +1,318 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
public static class CommonUtilsDal
|
||||
{
|
||||
#region LookupTable
|
||||
static uint[] CRCTbl = {
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
|
||||
0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
|
||||
0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
|
||||
|
||||
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
|
||||
0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
|
||||
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
|
||||
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
|
||||
|
||||
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
|
||||
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
|
||||
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
|
||||
0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
|
||||
|
||||
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
|
||||
0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
|
||||
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
|
||||
0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
|
||||
|
||||
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
|
||||
0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
|
||||
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
|
||||
0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
|
||||
|
||||
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
|
||||
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
|
||||
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
|
||||
0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
|
||||
|
||||
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
|
||||
0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
|
||||
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
|
||||
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
||||
|
||||
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
|
||||
0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
|
||||
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
|
||||
0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
|
||||
|
||||
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
|
||||
0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
|
||||
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
|
||||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
|
||||
|
||||
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
|
||||
0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
|
||||
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
|
||||
0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
|
||||
|
||||
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
|
||||
0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
||||
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
|
||||
0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
|
||||
|
||||
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
|
||||
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
|
||||
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
|
||||
0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
|
||||
|
||||
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
|
||||
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
|
||||
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
|
||||
0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
|
||||
|
||||
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
|
||||
0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
|
||||
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
|
||||
0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
||||
|
||||
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
|
||||
0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
|
||||
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
|
||||
0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
|
||||
|
||||
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
|
||||
0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
|
||||
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
||||
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};
|
||||
#endregion
|
||||
|
||||
#region CRC
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="Str">Str</param>
|
||||
/// <returns>Str-bol generált CRC, ami 6 karakter hosszú, számok/betűk</returns>
|
||||
static string CRC(string Str)
|
||||
{
|
||||
string RetValue = "";
|
||||
int CRCVal = -1; // Kréta specifikus init érték
|
||||
int Count, L;
|
||||
string C;
|
||||
|
||||
int tmp;
|
||||
uint tmp2, tmp3;
|
||||
for (Count = 0; Count < Str.Length; Count++)
|
||||
{
|
||||
tmp = Convert.ToInt32(Str[Count]);
|
||||
tmp2 = (uint)((CRCVal >> 8) & 0x00FFFFFF);
|
||||
tmp3 = CRCTbl[(byte)(CRCVal ^ tmp)];
|
||||
CRCVal = (int)(tmp3 ^ tmp2);
|
||||
}
|
||||
|
||||
CRCVal -= 552776587; // Kréta specifikus eltolás
|
||||
CRCVal = Math.Abs(CRCVal);
|
||||
CRCVal %= 0x5DB4A800; // ennyi kód lehet 26*36*36*36*36*36
|
||||
|
||||
for (Count = 6; Count > 0; Count--)
|
||||
{
|
||||
CRCVal = (int)Math.DivRem(CRCVal, 36, out L);
|
||||
if (L < 26)
|
||||
C = Convert.ToChar(Convert.ToInt32('a') + L).ToString();
|
||||
else
|
||||
C = Convert.ToChar(Convert.ToInt32('0') + L - 26).ToString();
|
||||
|
||||
RetValue = C + RetValue;
|
||||
}
|
||||
return RetValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region KopaszNev
|
||||
/// <summary>
|
||||
/// Mikre figyel?
|
||||
/// elejen a dr.,Dr.,DR. elhagyasa
|
||||
/// sch->s
|
||||
/// ts->cs
|
||||
/// ch->cs
|
||||
/// y->i
|
||||
/// msh+h->msh
|
||||
/// cz->c
|
||||
/// ly->j
|
||||
/// ekezetekre nem figyel
|
||||
/// csupa kISbetu a nev,space-ek nelkul
|
||||
/// _-t kiveszi
|
||||
/// </summary>
|
||||
/// <param name="nev">Kap egy sztringet</param>
|
||||
/// <returns>Visszaadja a sztring "kopasz" verzióját</returns>
|
||||
public static string KopaszNev(string nev)
|
||||
{
|
||||
System.Text.StringBuilder RetValue = new System.Text.StringBuilder();
|
||||
System.Text.StringBuilder KopaszNev = new System.Text.StringBuilder();
|
||||
|
||||
nev = nev.ToLower();
|
||||
|
||||
#region Ékezetes karaktereket ékezet nélküliekre cseréli.
|
||||
for (int i = 0; i < nev.Length; i++)
|
||||
{
|
||||
switch (Convert.ToInt16(nev[i]))
|
||||
{
|
||||
case 246: //ö
|
||||
case 243: //ó
|
||||
case 337: //o - hosszu o
|
||||
case 244: //ô - kalapos
|
||||
case 245: //ő - hullámos o
|
||||
case 242: //ò
|
||||
KopaszNev.Append(Convert.ToChar(111).ToString());// o
|
||||
break;
|
||||
case 252: //ü
|
||||
case 369: //u
|
||||
case 250: //ú
|
||||
case 249: //ù
|
||||
case 251: //ű
|
||||
KopaszNev.Append(Convert.ToChar(117).ToString());// u
|
||||
break;
|
||||
case 232: //è
|
||||
case 234: //ê
|
||||
case 233: //é
|
||||
case 235: //ë
|
||||
KopaszNev.Append(Convert.ToChar(101).ToString());// e
|
||||
break;
|
||||
case 225: //á
|
||||
case 228: //ä
|
||||
case 229: //â
|
||||
case 224: //à
|
||||
case 226: //â
|
||||
case 227: //ã
|
||||
KopaszNev.Append(Convert.ToChar(97).ToString());// a
|
||||
break;
|
||||
case 236: //ì
|
||||
case 237: //í
|
||||
case 238: //î
|
||||
case 239: //î
|
||||
KopaszNev.Append(Convert.ToChar(105).ToString());// i
|
||||
break;
|
||||
default:
|
||||
KopaszNev.Append(nev[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
nev = KopaszNev.ToString();
|
||||
// ascii karakterekké és kisbetukké konvertáljuk.
|
||||
nev = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(nev)).ToLower();
|
||||
bool b = true;
|
||||
// az elejérol levágjuk a space-eket
|
||||
nev = nev.TrimStart(' ');
|
||||
for (int szlo = 0; szlo < nev.Length; szlo++)
|
||||
{
|
||||
// ha nem space, és nem is "dr." vagy "dr " karakterekkel kezdodik...
|
||||
if (b && (nev.StartsWith("dr.", StringComparison.CurrentCulture) || nev.StartsWith("dr ", StringComparison.CurrentCulture)))
|
||||
{
|
||||
b = false;
|
||||
szlo += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
// a space-eket kihagyjuk
|
||||
if (nev[szlo] == ' ')
|
||||
continue;
|
||||
|
||||
// ha belefér a hátralévo sztringbe, és egyezik a következo karakterekkel, csere...
|
||||
#region "sch" -> "s"
|
||||
if ((string.Compare(nev, szlo, "sch", 0, 3, StringComparison.CurrentCulture) == 0))//( nev.Length-1-szlo ) >= 3 ) &&
|
||||
{
|
||||
RetValue.Append("s");
|
||||
szlo += 2;
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
#region "ts" -> "cs" vagy "ch" -> "cs"
|
||||
if ((string.Compare(nev, szlo, "ts", 0, 2, StringComparison.CurrentCulture) == 0 || string.Compare(nev, szlo, "ch", 0, 2, StringComparison.CurrentCulture) == 0))
|
||||
{
|
||||
RetValue.Append("cs");
|
||||
szlo++;
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
#region "cz" -> "c"
|
||||
if (string.Compare(nev, szlo, "cz", 0, 2, StringComparison.CurrentCulture) == 0)
|
||||
{
|
||||
RetValue.Append("c");
|
||||
szlo++;
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
#region "ly" -> "j"
|
||||
if (string.Compare(nev, szlo, "ly", 0, 2, StringComparison.CurrentCulture) == 0)
|
||||
{
|
||||
RetValue.Append("j");
|
||||
szlo++;
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
#region "y" -> "i"
|
||||
// csak akkor, ha nem gy, ty vagy ny beturol van szo
|
||||
bool m_IsGYTYNYBetu = false;
|
||||
if (szlo > 0
|
||||
&& (string.Compare(nev, szlo - 1, "g", 0, 1, StringComparison.CurrentCulture) == 0
|
||||
|| string.Compare(nev, szlo - 1, "n", 0, 1, StringComparison.CurrentCulture) == 0
|
||||
|| string.Compare(nev, szlo - 1, "t", 0, 1, StringComparison.CurrentCulture) == 0
|
||||
)
|
||||
&& string.Compare(nev, szlo, "y", 0, 1, StringComparison.CurrentCulture) == 0)
|
||||
{
|
||||
m_IsGYTYNYBetu = true;
|
||||
}
|
||||
|
||||
if (!m_IsGYTYNYBetu && string.Compare(nev, szlo, "y", 0, 1, StringComparison.CurrentCulture) == 0)
|
||||
{
|
||||
RetValue.Append("i");
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
#region Csak akkor kell a 'h', ha elotte a,e,i,o,u karakterek vannak. (ha a fir parameter = true, akkor ezt nem hasznaljuk)
|
||||
if (string.Compare(nev, szlo, "h", 0, 1, StringComparison.CurrentCulture) == 0 &&
|
||||
(szlo > 0 &&
|
||||
nev[szlo - 1] != 'a' &&
|
||||
nev[szlo - 1] != 'e' &&
|
||||
nev[szlo - 1] != 'i' &&
|
||||
nev[szlo - 1] != 'o' &&
|
||||
nev[szlo - 1] != 'u' &&
|
||||
nev[szlo - 1] != ' '))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
#region Ha ponthoz érve az elotte lévo karakterek sorrendben: d és r
|
||||
if ( //( ( nev.Length-1-szlo ) >= 1 ) &&
|
||||
szlo > 1 &&// hogy vissza tudjunk lépni ketto char-t
|
||||
string.Compare(nev, szlo, ".", 0, 1, StringComparison.CurrentCulture) == 0 &&
|
||||
string.Compare(nev, szlo - 1, "r", 0, 1, StringComparison.CurrentCulture) == 0 &&
|
||||
string.Compare(nev, szlo - 2, "d", 0, 1, StringComparison.CurrentCulture) == 0)
|
||||
{
|
||||
// visszalépünk a d-re, és mintha az elején lenne, az az eset következik.
|
||||
//b = true;
|
||||
//szlo -= 3;
|
||||
RetValue.Remove(RetValue.Length - 2, 2);
|
||||
continue;
|
||||
}
|
||||
#endregion
|
||||
#region Az egyforma egymás melletti karakterekbol csak az elso számít (ha a fir parameter = true, akkor ezt nem hasznaljuk)
|
||||
if (szlo > 0 && string.Compare(nev, szlo, nev[szlo - 1].ToString(), 0, 1, StringComparison.CurrentCulture) == 0)
|
||||
continue;
|
||||
#endregion
|
||||
#region Ha az aktuális karakter speciális, akkor nem számít
|
||||
if ("abcdefghijklmnopqrstuvwxyz".IndexOf(nev[szlo].ToString(), StringComparison.CurrentCulture) == -1)
|
||||
continue;
|
||||
#endregion
|
||||
|
||||
// Ha minden stimmel, akkor kell a karakter
|
||||
RetValue.Append(nev[szlo].ToString());
|
||||
}
|
||||
return RetValue.ToString();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
149
Kreta.DataAccessManual/Util/ConnectionBase.cs
Normal file
149
Kreta.DataAccessManual/Util/ConnectionBase.cs
Normal file
|
@ -0,0 +1,149 @@
|
|||
using System;
|
||||
using Kreta.Core;
|
||||
using Kreta.Framework;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
internal class Connection : ConnectionBase
|
||||
{
|
||||
public Connection(string sessionId) : base(sessionId)
|
||||
{
|
||||
activatedByMe = ActivateSession();
|
||||
}
|
||||
|
||||
protected override bool ActivateSession()
|
||||
{
|
||||
return DataUtil.ActivateSession(this.SessionId);
|
||||
}
|
||||
|
||||
protected override void DeactivateSession()
|
||||
{
|
||||
DataUtil.DeactivateSession(SessionId);
|
||||
}
|
||||
}
|
||||
|
||||
internal class OrganizationConnection : ConnectionBase
|
||||
{
|
||||
private readonly string intezmenyAzonosito;
|
||||
|
||||
public OrganizationConnection(string intezmenyAzonosito) : base(string.Empty)
|
||||
{
|
||||
this.intezmenyAzonosito = intezmenyAzonosito;
|
||||
activatedByMe = ActivateSession();
|
||||
}
|
||||
|
||||
protected override bool ActivateSession()
|
||||
{
|
||||
return DataUtil.ActivateOrganizationSystemSession(intezmenyAzonosito);
|
||||
}
|
||||
|
||||
protected override void DeactivateSession()
|
||||
{
|
||||
DataUtil.DeactivateOrganizationSystemSession();
|
||||
}
|
||||
}
|
||||
|
||||
internal class MobileConnection : ConnectionBase
|
||||
{
|
||||
private readonly string intezmenyAzonosito;
|
||||
|
||||
public MobileConnection(string intezmenyAzonosito, int? tanevId, int? felhasznaloId) : base(string.Empty)
|
||||
{
|
||||
this.intezmenyAzonosito = intezmenyAzonosito;
|
||||
activatedByMe = ActivateSession();
|
||||
|
||||
if (tanevId.IsEntityId())
|
||||
{
|
||||
UserContext.Instance.SetTanev(tanevId.Value, tanevId.Value);
|
||||
}
|
||||
if (felhasznaloId.IsEntityId())
|
||||
{
|
||||
UserContext.Instance.SetFelhasznaloId(felhasznaloId.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ActivateSession()
|
||||
{
|
||||
return DataUtil.ActivateMobileSession(intezmenyAzonosito);
|
||||
}
|
||||
|
||||
protected override void DeactivateSession()
|
||||
{
|
||||
DataUtil.DeactivateMobileSession();
|
||||
}
|
||||
}
|
||||
|
||||
internal class SystemConnection : ConnectionBase
|
||||
{
|
||||
public SystemConnection() : base(string.Empty)
|
||||
{
|
||||
activatedByMe = ActivateSession();
|
||||
}
|
||||
|
||||
protected override bool ActivateSession()
|
||||
{
|
||||
return DataUtil.ActivateSystemSession();
|
||||
}
|
||||
|
||||
protected override void DeactivateSession()
|
||||
{
|
||||
DataUtil.DeactivateSystemSession();
|
||||
}
|
||||
}
|
||||
|
||||
internal class ServiceSystemConnection : ConnectionBase
|
||||
{
|
||||
private readonly string connectionString;
|
||||
|
||||
public ServiceSystemConnection(string connectionString) : base(string.Empty)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
activatedByMe = ActivateSession();
|
||||
}
|
||||
|
||||
protected override bool ActivateSession()
|
||||
{
|
||||
return DataUtil.ActivateServiceSystemSession(connectionString);
|
||||
}
|
||||
|
||||
protected override void DeactivateSession()
|
||||
{
|
||||
DataUtil.DeactivateServiceSystemSession();
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract class ConnectionBase : IDisposable
|
||||
{
|
||||
/*TODO: ezek törölhetőek lesznek ha majd kikopik a helperes Session aktiváció*/
|
||||
protected bool activatedByMe = false;
|
||||
|
||||
protected readonly string SessionId;
|
||||
|
||||
internal ConnectionBase(string sessionId)
|
||||
{
|
||||
this.SessionId = sessionId;
|
||||
}
|
||||
|
||||
protected virtual bool ActivateSession()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual void DeactivateSession()
|
||||
{
|
||||
}
|
||||
|
||||
~ConnectionBase()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (activatedByMe)
|
||||
{
|
||||
DeactivateSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
190
Kreta.DataAccessManual/Util/ConnectionHandler.cs
Normal file
190
Kreta.DataAccessManual/Util/ConnectionHandler.cs
Normal file
|
@ -0,0 +1,190 @@
|
|||
using System;
|
||||
using Kreta.Core.ConnectionType;
|
||||
using Kreta.DataAccessManual.Interfaces;
|
||||
using Kreta.Framework;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
internal abstract class ConnectionHandlerBase
|
||||
{
|
||||
internal void ActionWithHandler(Action<IDalHandler> actions, IDalHandler handler = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var isNotNestedConnection = handler == null;
|
||||
handler = handler ?? new DalHandler();
|
||||
actions(handler);
|
||||
if (isNotNestedConnection && handler.CommitOnEnd)
|
||||
{
|
||||
UserContext.Instance.CommitTransaction();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
UserContext.Instance.RollbackTransaction();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
internal T FunctionWithHandler<T>(Func<IDalHandler, T> actions, IDalHandler handler = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var isNotNestedConnection = handler == null;
|
||||
handler = handler ?? new DalHandler();
|
||||
var result = actions(handler);
|
||||
if (isNotNestedConnection && handler.CommitOnEnd)
|
||||
{
|
||||
UserContext.Instance.CommitTransaction();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
UserContext.Instance.RollbackTransaction();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class ConnectionHandler : ConnectionHandlerBase, IConnectionHandler
|
||||
{
|
||||
public void Run(string sessionId, Action<IDalHandler> actions)
|
||||
{
|
||||
using (new Connection(sessionId))
|
||||
{
|
||||
ActionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
|
||||
public T Run<T>(string sessionId, Func<IDalHandler, T> actions)
|
||||
{
|
||||
using (new Connection(sessionId))
|
||||
{
|
||||
return FunctionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class OrganizationConnectionHandler : ConnectionHandlerBase, IOrganizationConnectionHandler
|
||||
{
|
||||
public void Run(string intezmenyAzonosito, Action<IDalHandler> actions)
|
||||
{
|
||||
using (new OrganizationConnection(intezmenyAzonosito))
|
||||
{
|
||||
ActionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
|
||||
public T Run<T>(string intezmenyAzonosito, Func<IDalHandler, T> actions)
|
||||
{
|
||||
using (new OrganizationConnection(intezmenyAzonosito))
|
||||
{
|
||||
return FunctionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class MobileConnectionHandler : ConnectionHandlerBase, IMobileConnectionHandler
|
||||
{
|
||||
public void Run(string intezmenyAzonosito, int? tanevId, Action<IDalHandler> actions, int? felhasznaloId = null)
|
||||
{
|
||||
using (new MobileConnection(intezmenyAzonosito, tanevId, felhasznaloId))
|
||||
{
|
||||
ActionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
|
||||
public T Run<T>(string intezmenyAzonosito, int? tanevId, Func<IDalHandler, T> actions, int? felhasznaloId = null)
|
||||
{
|
||||
using (new MobileConnection(intezmenyAzonosito, tanevId, felhasznaloId))
|
||||
{
|
||||
return FunctionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class SystemConnectionHandler : ConnectionHandlerBase, ISystemConnectionHandler
|
||||
{
|
||||
public void Run(Action<IDalHandler> actions)
|
||||
{
|
||||
using (new SystemConnection())
|
||||
{
|
||||
ActionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
|
||||
public T Run<T>(Func<IDalHandler, T> actions)
|
||||
{
|
||||
using (new SystemConnection())
|
||||
{
|
||||
return FunctionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class ServiceSystemConnectionHandler : ConnectionHandlerBase, IServiceSystemConnectionHandler
|
||||
{
|
||||
public void Run(string connectionString, Action<IDalHandler> actions)
|
||||
{
|
||||
using (new ServiceSystemConnection(connectionString))
|
||||
{
|
||||
ActionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
|
||||
public T Run<T>(string connectionString, Func<IDalHandler, T> actions)
|
||||
{
|
||||
using (new ServiceSystemConnection(connectionString))
|
||||
{
|
||||
return FunctionWithHandler(actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class CustomConnectionHandler : ConnectionHandlerBase, ICustomConnectionHandler
|
||||
{
|
||||
public void Run(IConnectionType connectionType, Action<IDalHandler> actions)
|
||||
{
|
||||
switch (connectionType)
|
||||
{
|
||||
case DalHandlerConnectionType dalHandlerConnectionType:
|
||||
ActionWithHandler(actions, dalHandlerConnectionType.DalHandler);
|
||||
break;
|
||||
case MobileConnectionType mobileConnectionType:
|
||||
new MobileConnectionHandler().Run(mobileConnectionType.IntezmenyAzonosito, mobileConnectionType.TanevId, actions, mobileConnectionType.FelhasznaloId);
|
||||
break;
|
||||
case OrganizationConnectionType organizationConnectionType:
|
||||
new OrganizationConnectionHandler().Run(organizationConnectionType.IntezmenyAzonosito, actions);
|
||||
break;
|
||||
case SessionConnectionType sessionConnectionType:
|
||||
new ConnectionHandler().Run(sessionConnectionType.SessionId, actions);
|
||||
break;
|
||||
case SystemConnectionType systemConnectionType:
|
||||
new SystemConnectionHandler().Run(actions);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Ismeretlen ConnectionTpye", nameof(connectionType));
|
||||
}
|
||||
}
|
||||
|
||||
public T Run<T>(IConnectionType connectionType, Func<IDalHandler, T> actions)
|
||||
{
|
||||
switch (connectionType)
|
||||
{
|
||||
case DalHandlerConnectionType dalHandlerConnectionType:
|
||||
return FunctionWithHandler(actions, dalHandlerConnectionType.DalHandler);
|
||||
case MobileConnectionType mobileConnectionType:
|
||||
return new MobileConnectionHandler().Run(mobileConnectionType.IntezmenyAzonosito, mobileConnectionType.TanevId, actions, mobileConnectionType.FelhasznaloId);
|
||||
case OrganizationConnectionType organizationConnectionType:
|
||||
return new OrganizationConnectionHandler().Run(organizationConnectionType.IntezmenyAzonosito, actions);
|
||||
case SessionConnectionType sessionConnectionType:
|
||||
return new ConnectionHandler().Run(sessionConnectionType.SessionId, actions);
|
||||
case SystemConnectionType systemConnectionType:
|
||||
return new SystemConnectionHandler().Run(actions);
|
||||
default:
|
||||
throw new ArgumentException("Ismeretlen ConnectionTpye", nameof(connectionType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1008
Kreta.DataAccessManual/Util/DalHandler.cs
Normal file
1008
Kreta.DataAccessManual/Util/DalHandler.cs
Normal file
File diff suppressed because it is too large
Load diff
16
Kreta.DataAccessManual/Util/DalHandlerConnectionType.cs
Normal file
16
Kreta.DataAccessManual/Util/DalHandlerConnectionType.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using Kreta.Core.ConnectionType;
|
||||
using Kreta.DataAccessManual.Interfaces;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
public sealed class DalHandlerConnectionType : ConnectionTypeBase
|
||||
{
|
||||
public DalHandlerConnectionType(IConnectionType connectionType, IDalHandler dalHandler) : base(connectionType.FelhasznaloId, connectionType.IntezmenyId, connectionType.IntezmenyAzonosito, connectionType.TanevId)
|
||||
{
|
||||
DalHandler = dalHandler ?? throw new ArgumentNullException(nameof(dalHandler));
|
||||
}
|
||||
|
||||
internal IDalHandler DalHandler { get; }
|
||||
}
|
||||
}
|
429
Kreta.DataAccessManual/Util/DataAccessBase.cs
Normal file
429
Kreta.DataAccessManual/Util/DataAccessBase.cs
Normal file
|
@ -0,0 +1,429 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Resources;
|
||||
using Kreta.Core;
|
||||
using Kreta.DataAccess.Interfaces;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Util;
|
||||
using Kreta.Resources;
|
||||
using SDA.DataProvider;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
public abstract class DataAccessBase
|
||||
{
|
||||
protected GridParameters GridParameters;
|
||||
|
||||
protected DalHandler DalHelper { get; private set; }
|
||||
|
||||
protected DataAccessBase(DalHandler handler) : this(handler, null)
|
||||
{
|
||||
}
|
||||
|
||||
protected DataAccessBase(DalHandler handler, GridParameters gridParameters)
|
||||
{
|
||||
DalHelper = handler;
|
||||
GridParameters = gridParameters;
|
||||
}
|
||||
|
||||
protected DataSet GetData(string commandText, List<CommandParameter> parameters = null, string dictionaryItemColumns = null, string booleanColumns = null)
|
||||
{
|
||||
DataTable table;
|
||||
|
||||
using (SDACommand command = UserContext.Instance.SDAConnection.CreateCommand())
|
||||
{
|
||||
command.Transaction = UserContext.Instance.SDATransaction;
|
||||
command.CommandType = CommandType.Text;
|
||||
command.CommandText = commandText;
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
if (param.Type != SDADBType.Binary)
|
||||
{
|
||||
command.Parameters.Add(param.Name, param.Type);
|
||||
command.Parameters[param.Name].Value = param.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
command.Parameters.Add(param.Name, param.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GridParameters == null)
|
||||
{
|
||||
GridParameters = new GridParameters();
|
||||
}
|
||||
|
||||
table = DataUtil.GetData(command, GridParameters);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dictionaryItemColumns))
|
||||
{
|
||||
SetDNAME(table, dictionaryItemColumns);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(booleanColumns))
|
||||
{
|
||||
SetBoolFields(table, booleanColumns);
|
||||
}
|
||||
|
||||
return table.AsDataSet();
|
||||
}
|
||||
|
||||
protected DataSet GetReadOnlyData(string commandText, List<CommandParameter> parameters = null, string dictionaryItemColumns = null, string booleanColumns = null)
|
||||
{
|
||||
DataTable table;
|
||||
|
||||
using (SDAConnection connection = DataUtil.GetReadOnlyConnection(UserContext.Instance.IntezmenyAzonosito))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
using (SDACommand command = connection.CreateCommand())
|
||||
{
|
||||
command.CommandType = CommandType.Text;
|
||||
command.CommandText = commandText;
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
if (param.Type != SDADBType.Binary)
|
||||
{
|
||||
command.Parameters.Add(param.Name, param.Type);
|
||||
command.Parameters[param.Name].Value = param.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
command.Parameters.Add(param.Name, param.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GridParameters == null)
|
||||
{
|
||||
GridParameters = new GridParameters();
|
||||
}
|
||||
|
||||
table = DataUtil.GetData(command, GridParameters);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dictionaryItemColumns))
|
||||
{
|
||||
SetDNAME(table, dictionaryItemColumns);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(booleanColumns))
|
||||
{
|
||||
SetBoolFields(table, booleanColumns);
|
||||
}
|
||||
|
||||
return table.AsDataSet();
|
||||
}
|
||||
|
||||
protected int CheckRowCount(string commandText, List<CommandParameter> parameters = null)
|
||||
{
|
||||
using (SDACommand command = UserContext.Instance.SDAConnection.CreateCommand())
|
||||
{
|
||||
command.CommandType = CommandType.Text;
|
||||
command.CommandText = commandText;
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
if (param.Type != SDADBType.Binary)
|
||||
{
|
||||
command.Parameters.Add(param.Name, param.Type);
|
||||
command.Parameters[param.Name].Value = param.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
command.Parameters.Add(param.Name, param.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DataUtil.CheckRowCount(command);
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete(@"A Kreta.Core.Extensions.SortingAndPaging<T>-t kell használni model listákkal, mivel ezeket mostmár tudjuk sorbarendezni a GridParameters-el,
|
||||
így nincs szükség rá, hogy elmenjen a DataSet a Web-re ezért nincs is szükség itt sorrenezni őket!")]
|
||||
protected DataTable SortingAndPaging(DataTable dataTable, GridParameters gridParameteres)
|
||||
{
|
||||
return DataUtil.SortingAndPaging(dataTable, gridParameteres);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A vesszővel átadott oszlopokból csinál egy egy új oszlopot oszlopnév+'_DNAME' névvel amelybe betölti a kódtétel nevét
|
||||
/// </summary>
|
||||
/// <param name="table">Adatforrás amibe bele kell rakni a kódtételeket</param>
|
||||
/// <param name="columns">Oszlopok amelyeknél az ID helyett kódtétel neveket kell nyelvhelyesen betenni</param>
|
||||
public static void SetDNAME(DataTable table, string columns)
|
||||
{
|
||||
DictionaryItemCacheUtil.TableColumnFromDictionaryCache(table, columns);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Az átadott adatforráson a _DNAME-hez hasonlóan egy _BOOL mezőt hoz létre és az átadott oszlopok
|
||||
/// T vagy F értékei alapján beállítja a true-t vagy false-ot
|
||||
/// </summary>
|
||||
/// <param name="srcTable"></param>
|
||||
/// <param name="fields">Oszlopnevek vesszővel elválasztva "mezo1,mezo2,mezo3..."</param>
|
||||
public static void SetBoolFields(DataTable srcTable, string fields)
|
||||
{
|
||||
var list = new ArrayList(fields.Split(','));
|
||||
foreach (string column in list)
|
||||
{
|
||||
string boolColumnName = column + "_BOOL";
|
||||
srcTable.Columns.Add(boolColumnName, typeof(bool));
|
||||
|
||||
string boolTextColumnName = column + "_BNAME";
|
||||
srcTable.Columns.Add(boolTextColumnName, typeof(string));
|
||||
foreach (DataRow myRow in srcTable.Rows)
|
||||
{
|
||||
//ha dbnull akkor nem allitunk be semmit, hagyjuk dbnull-on
|
||||
if (myRow[column] != DBNull.Value)
|
||||
{
|
||||
bool value = Convert.ToBoolean(myRow[column].ToString() == "T");
|
||||
myRow[boolColumnName] = value;
|
||||
myRow[boolTextColumnName] = value ? CommonResource.Igen : CommonResource.Nem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Oszlopnevek lecserélése 'map' alapján a paraméterben kapott 'dataTable'-ben.
|
||||
/// </summary>
|
||||
/// <param name="dataTable">Az átnevezendő oszlopokat tartalmazó DataTable.</param>
|
||||
/// <param name="map">Az átnevezendő oszlopnév párok.</param>
|
||||
public static void RenameDataTableColumns(DataTable dataTable, (string fromColumn, string toColumn)[] map)
|
||||
{
|
||||
foreach (var (fromColumn, toColumn) in map)
|
||||
{
|
||||
dataTable.Columns[fromColumn].ColumnName = toColumn;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTableRowsFromResourceFile(Type resourceFileType, DataTable processedTable, string columnNames)
|
||||
{
|
||||
var resourceManager = new ResourceManager(resourceFileType);
|
||||
var newColumnNamesList = new List<string>();
|
||||
var oldColumnNamesList = new List<string>();
|
||||
|
||||
oldColumnNamesList.AddRange(columnNames.Split(",;".ToCharArray()));
|
||||
|
||||
oldColumnNamesList.ForEach(name =>
|
||||
{
|
||||
if (!processedTable.Columns.Contains(name))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(name, ErrorResource.ColumnNamesParameterContainsColumnnameThatNotExistsInTheSpecifiedTable);
|
||||
}
|
||||
|
||||
string newColumnName = name + "Value";
|
||||
|
||||
if (processedTable.Columns[newColumnName] == null)
|
||||
{
|
||||
newColumnNamesList.Add(newColumnName);
|
||||
processedTable.Columns.Add(newColumnName);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(ErrorResource.TheNewColumnNameExistsInDatatable);
|
||||
}
|
||||
});
|
||||
|
||||
foreach (DataRow dataRow in processedTable.Rows)
|
||||
{
|
||||
newColumnNamesList.ForEach(newColumnName =>
|
||||
oldColumnNamesList.ForEach(oldColumnName =>
|
||||
dataRow[newColumnName] = resourceManager.GetString(dataRow[oldColumnName].ToString())));
|
||||
}
|
||||
|
||||
oldColumnNamesList.ForEach(oldColumnName => processedTable.Columns.Remove(oldColumnName));
|
||||
}
|
||||
|
||||
public void FollowUp<T>(T entity) where T : IEntity
|
||||
{
|
||||
var kovTanevId = GetKovetkezoTanevId();
|
||||
var aktualisTanevId = GetAktivTanevId();
|
||||
|
||||
if (kovTanevId.IsEntityId())
|
||||
{
|
||||
switch (entity)
|
||||
{
|
||||
case IDictionaryItemBase dictionaryItemBaseEntity:
|
||||
if (aktualisTanevId == dictionaryItemBaseEntity.TanevId)
|
||||
{
|
||||
DalHelper.AdatszotarDAL().FollowUpDictionaryItemBase(dictionaryItemBaseEntity.IntezmenyId, dictionaryItemBaseEntity.TanevId, kovTanevId.Value, dictionaryItemBaseEntity.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IDictionaryItemBaseNyelv dictionaryItemBaseNyelv:
|
||||
if (aktualisTanevId == dictionaryItemBaseNyelv.TanevId)
|
||||
{
|
||||
DalHelper.DictionaryItemBaseNyelvDal().FollowUpDictionaryItemBaseNyelv(dictionaryItemBaseNyelv.IntezmenyId, dictionaryItemBaseNyelv.TanevId, kovTanevId.Value, dictionaryItemBaseNyelv.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IOraTerv oraTervEntity:
|
||||
if (aktualisTanevId == oraTervEntity.TanevId)
|
||||
{
|
||||
DalHelper.OratervDal().FollowUpOraterv(oraTervEntity.IntezmenyId, oraTervEntity.TanevId, kovTanevId.Value, entity.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case ITerem teremEntity:
|
||||
if (aktualisTanevId == teremEntity.TanevId)
|
||||
{
|
||||
DalHelper.Terem().FollowUpTerem(teremEntity.IntezmenyId, teremEntity.TanevId, kovTanevId.Value, entity.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IFeladatEllatasiHely feladatEllatasiHelyEntity:
|
||||
if (aktualisTanevId == feladatEllatasiHelyEntity.TanevId)
|
||||
{
|
||||
DalHelper.FeladatEllatasiHelyDal().FollowUpFeladatellatasiHely(feladatEllatasiHelyEntity.IntezmenyId, feladatEllatasiHelyEntity.TanevId, kovTanevId.Value, entity.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IIntezmenyAdatok intezmenyAdatokEntity:
|
||||
if (aktualisTanevId == intezmenyAdatokEntity.TanevId)
|
||||
{
|
||||
DalHelper.IntezmenyDal().FollowUpIntezmenyAdatok(intezmenyAdatokEntity.IntezmenyId, intezmenyAdatokEntity.TanevId, kovTanevId.Value);
|
||||
}
|
||||
|
||||
break;
|
||||
case ITanterv tantervEntity:
|
||||
if (aktualisTanevId == tantervEntity.TanevId)
|
||||
{
|
||||
DalHelper.TantervDAL().FollowUpTanterv(tantervEntity.IntezmenyId, tantervEntity.TanevId, kovTanevId.Value, entity.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IMukodesiHely mukodesiHelyEntity:
|
||||
if (aktualisTanevId == mukodesiHelyEntity.TanevId)
|
||||
{
|
||||
DalHelper.MukodesiHelyDAL().FollowUpMukodesiHely(mukodesiHelyEntity.IntezmenyId, mukodesiHelyEntity.TanevId, kovTanevId.Value, entity.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IEszkoz eszkozEntity:
|
||||
if (aktualisTanevId == eszkozEntity.TanevId)
|
||||
{
|
||||
DalHelper.EszkozDal().FollowUpEszkoz(eszkozEntity.IntezmenyId, eszkozEntity.TanevId, kovTanevId.Value, eszkozEntity.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IOraTervTargy oraTervTargy:
|
||||
if (aktualisTanevId == oraTervTargy.TanevId)
|
||||
{
|
||||
DalHelper.OratervDal().FollowUpOratervTargy(oraTervTargy.IntezmenyId, oraTervTargy.TanevId, kovTanevId.Value, oraTervTargy.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IAlkalmazott alkalmazott:
|
||||
if (aktualisTanevId == alkalmazott.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazott(alkalmazott.IntezmenyId, alkalmazott.TanevId, kovTanevId.Value, alkalmazott.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case ITantargy tantargy:
|
||||
if (aktualisTanevId == tantargy.TanevId)
|
||||
{
|
||||
DalHelper.Tantargy().FollowUpTantargy(tantargy.IntezmenyId, tantargy.TanevId, kovTanevId.Value, tantargy.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IKKAMIVegzettseg kkAmiVegzettseg:
|
||||
if (aktualisTanevId == kkAmiVegzettseg.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazottVegzettsegKK(kkAmiVegzettseg.IntezmenyId, kkAmiVegzettseg.TanevId, kovTanevId.Value, kkAmiVegzettseg.AlkalmazottId);
|
||||
}
|
||||
|
||||
break;
|
||||
case IKKTanitoVezgettseg kkTanitoVezgettseg:
|
||||
if (aktualisTanevId == kkTanitoVezgettseg.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazottVegzettsegKK(kkTanitoVezgettseg.IntezmenyId, kkTanitoVezgettseg.TanevId, kovTanevId.Value, kkTanitoVezgettseg.AlkalmazottId);
|
||||
}
|
||||
|
||||
break;
|
||||
case ICsengetesiRend csengetesiRend:
|
||||
if (aktualisTanevId == csengetesiRend.TanevId)
|
||||
{
|
||||
DalHelper.CsengetesiRend().FollowUpCsengetesiRend(csengetesiRend.IntezmenyId, csengetesiRend.TanevId, kovTanevId.Value, csengetesiRend.ID);
|
||||
}
|
||||
break;
|
||||
case IVegzettseg vegzettseg:
|
||||
if (aktualisTanevId == vegzettseg.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazottVegzettseg(vegzettseg.IntezmenyId, vegzettseg.TanevId, kovTanevId.Value, vegzettseg.ID);
|
||||
}
|
||||
break;
|
||||
case IKKGyogypedVegzettseg kkGyogypedVegzettseg:
|
||||
if (aktualisTanevId == kkGyogypedVegzettseg.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazottVegzettsegKK(kkGyogypedVegzettseg.IntezmenyId, kkGyogypedVegzettseg.TanevId, kovTanevId.Value, kkGyogypedVegzettseg.AlkalmazottId);
|
||||
}
|
||||
|
||||
break;
|
||||
case IKKTanarVegzettseg kkTanarVegzettseg:
|
||||
if (aktualisTanevId == kkTanarVegzettseg.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazottVegzettsegKK(kkTanarVegzettseg.IntezmenyId, kkTanarVegzettseg.TanevId, kovTanevId.Value, kkTanarVegzettseg.AlkalmazottId);
|
||||
}
|
||||
|
||||
break;
|
||||
case IPedagogusEletpalyamodell pedagogusEletpalyamodell:
|
||||
if (aktualisTanevId == pedagogusEletpalyamodell.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazottPEP(pedagogusEletpalyamodell.IntezmenyId, pedagogusEletpalyamodell.TanevId, kovTanevId.Value, pedagogusEletpalyamodell.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case ITovabbiMunkaugyiAdatok tovabbiMunkaugyiAdatok:
|
||||
if (aktualisTanevId == tovabbiMunkaugyiAdatok.TanevId)
|
||||
{
|
||||
DalHelper.Alkalmazott().FollowUpAlkalmazottTovabbiMunkaugyiAdatok(tovabbiMunkaugyiAdatok.IntezmenyId, tovabbiMunkaugyiAdatok.TanevId, kovTanevId.Value, tovabbiMunkaugyiAdatok.ID);
|
||||
}
|
||||
|
||||
break;
|
||||
case IRendszerBeallitas rendszerBeallitas:
|
||||
if (aktualisTanevId == rendszerBeallitas.TanevId)
|
||||
{
|
||||
DalHelper.RendszerBeallitas().FollowupRendszerBeallitas(rendszerBeallitas.IntezmenyId, rendszerBeallitas.TanevId, kovTanevId.Value, rendszerBeallitas.ID);
|
||||
}
|
||||
break;
|
||||
|
||||
case ITantargyNyelv tantargyNyelv:
|
||||
if (aktualisTanevId == tantargyNyelv.TanevId)
|
||||
{
|
||||
DalHelper.Tantargy().FollowUpTantargyNyelv(tantargyNyelv.IntezmenyId, tantargyNyelv.TanevId, kovTanevId.Value, tantargyNyelv.ID);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Ismeretlen típus!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int? GetKovetkezoTanevId()
|
||||
{
|
||||
var dal = DalHelper.TanevDal(GridParameters);
|
||||
var ds = dal.GetKovetkezoTanev();
|
||||
|
||||
return ds != null && ds.Tables[0].Rows.Count > 0 ? Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]) : default;
|
||||
}
|
||||
|
||||
private int GetAktivTanevId() => DalHelper.TanevDal().GetAktivTanevId();
|
||||
}
|
||||
}
|
593
Kreta.DataAccessManual/Util/DataUtil.cs
Normal file
593
Kreta.DataAccessManual/Util/DataUtil.cs
Normal file
|
@ -0,0 +1,593 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Util;
|
||||
using SDA.DataProvider;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
internal static class DataUtil
|
||||
{
|
||||
#region Session
|
||||
|
||||
public static bool ActivateSession(string sessionId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sessionId))
|
||||
return false;
|
||||
|
||||
if (UserContext.Instance == null || !UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.ActivateSession(sessionId);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void DeactivateSession(string sessionId)
|
||||
{
|
||||
if (UserContext.Instance != null && UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.DeActivateSession(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ActivateOrganizationSystemSession(string intezmenyAzonosito)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(intezmenyAzonosito))
|
||||
return false;
|
||||
|
||||
if (UserContext.Instance == null || !UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.ActivateOrganizationSystemSession(intezmenyAzonosito);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void DeactivateOrganizationSystemSession()
|
||||
{
|
||||
if (UserContext.Instance != null && UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.DeactivateOrganizationSystemSession();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ActivateMobileSession(string intezmenyAzonosito)
|
||||
{
|
||||
return ActivateOrganizationSystemSession(intezmenyAzonosito);
|
||||
}
|
||||
|
||||
public static void DeactivateMobileSession()
|
||||
{
|
||||
DeactivateOrganizationSystemSession();
|
||||
}
|
||||
|
||||
public static bool ActivateSystemSession()
|
||||
{
|
||||
if (UserContext.Instance == null || !UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.ActivateSystemSession();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void DeactivateSystemSession()
|
||||
{
|
||||
if (UserContext.Instance != null && UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.DeactivateSystemSession();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ActivateServiceSystemSession(string connectionString)
|
||||
{
|
||||
if (UserContext.Instance == null || !UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.ActivateServiceSystemSession(connectionString);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void DeactivateServiceSystemSession()
|
||||
{
|
||||
if (UserContext.Instance != null && UserContext.Instance.Activated)
|
||||
{
|
||||
SDAServer.Instance.SessionManager.DeactivateServiceSystemSession();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static SDAConnection GetReadOnlyConnection(string intezmenyAzonosito)
|
||||
{
|
||||
var sqlConnectionStringBuilder = new SqlConnectionStringBuilder(SDAServer.Instance.ConnectionManager.GetIntezmenyConnectionString(intezmenyAzonosito))
|
||||
{
|
||||
ApplicationIntent = ApplicationIntent.ReadOnly
|
||||
};
|
||||
|
||||
return new SDAConnection(sqlConnectionStringBuilder.ToString());
|
||||
}
|
||||
|
||||
[Obsolete(@"A Kreta.Core.Extensions.SortingAndPaging<T>-t kell használni model listákkal, mivel ezeket mostmár tudjuk sorbarendezni a GridParameters-el,
|
||||
így nincs szükség rá, hogy elmenjen a DataSet a Web-re ezért nincs is szükség itt sorrenezni őket!")]
|
||||
public static DataTable SortingAndPaging(DataTable dataTable, GridParameters gridParameters)
|
||||
{
|
||||
if (gridParameters == null)
|
||||
{
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
int rowCount = dataTable.Rows.Count;
|
||||
if (rowCount > 0)
|
||||
{
|
||||
string orderBy = gridParameters.OrderBy ?? "";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(orderBy.Trim()))
|
||||
{
|
||||
var comparer = new AlphanumComparator<string>();
|
||||
|
||||
string[] orderByList = orderBy.Split(',');
|
||||
|
||||
foreach (string strOrderBy in orderByList)
|
||||
{
|
||||
string[] strOrderByColType = strOrderBy.Trim().Split(' ');
|
||||
|
||||
//A rendezés oszlopa
|
||||
string strOrderByCol = strOrderByColType[0];
|
||||
|
||||
//A rendezés típusa
|
||||
string strOrderByType;
|
||||
|
||||
//A rendezés típusának beállítása. ASC, vagy DESC a tartalma
|
||||
if (strOrderByColType.Length > 1)
|
||||
{
|
||||
strOrderByType = strOrderByColType[1].IndexOf("ASC", StringComparison.OrdinalIgnoreCase) >= 0 ? "ASC" : "DESC";
|
||||
}
|
||||
else
|
||||
{
|
||||
strOrderByType = "ASC";
|
||||
}
|
||||
|
||||
var tableName = dataTable.TableName;
|
||||
|
||||
if (strOrderByType == "ASC")
|
||||
{
|
||||
dataTable = dataTable.AsEnumerable().OrderBy(x => ToString(x[strOrderByCol]), comparer).CopyToDataTable();
|
||||
}
|
||||
else
|
||||
{
|
||||
dataTable = dataTable.AsEnumerable().OrderByDescending(x => ToString(x[strOrderByCol]), comparer).CopyToDataTable();
|
||||
}
|
||||
|
||||
dataTable.TableName = tableName;
|
||||
}
|
||||
}
|
||||
|
||||
if (gridParameters.FirstRow <= gridParameters.LastRow)
|
||||
{
|
||||
int pageSize = gridParameters.LastRow - gridParameters.FirstRow + 1;
|
||||
if (pageSize < rowCount)
|
||||
{
|
||||
dataTable = dataTable.AsEnumerable().Skip(gridParameters.FirstRow).Take(pageSize).CopyToDataTable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gridParameters.LoadResultSetInfo && !dataTable.ExtendedProperties.ContainsKey("RowCount"))
|
||||
{
|
||||
dataTable.ExtendedProperties.Add("RowCount", rowCount);
|
||||
}
|
||||
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
public static DataSet AsDataSet(this DataTable dataTable)
|
||||
{
|
||||
if (dataTable.DataSet == null)
|
||||
{
|
||||
var dataSet = new DataSet();
|
||||
dataSet.Tables.Add(dataTable);
|
||||
}
|
||||
|
||||
return dataTable.DataSet;
|
||||
}
|
||||
|
||||
public static DataTable GetData(SDACommand command, GridParameters gridParameters)
|
||||
{
|
||||
using (var adapter = new SDADataAdapter())
|
||||
{
|
||||
adapter.SelectCommand = command;
|
||||
string mOriginalcommandtext = command.CommandText;
|
||||
|
||||
string orderBy = gridParameters.OrderBy ?? "";
|
||||
GenerateOrderString(command, ref orderBy, out string fullinnerfilter);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(fullinnerfilter) || !string.IsNullOrWhiteSpace(orderBy))
|
||||
{
|
||||
command.CommandText = string.Format(@"
|
||||
SELECT szurttabla.*
|
||||
FROM
|
||||
( {0} ) szurttabla {1}", mOriginalcommandtext, fullinnerfilter ?? "");
|
||||
}
|
||||
|
||||
//Ha van rendezési feltétel
|
||||
if (!string.IsNullOrWhiteSpace(orderBy))
|
||||
{
|
||||
command.CommandText += string.Format(" order by {0}", orderBy);
|
||||
}
|
||||
|
||||
//Feltoltes a sorok szamanak lekerdezesevel egyutt
|
||||
var table = new DataTable();
|
||||
if (gridParameters.LoadResultSetInfo && !table.ExtendedProperties.ContainsKey("RowCount"))
|
||||
{
|
||||
table.ExtendedProperties.Add("RowCount", GetRowCount(command));
|
||||
}
|
||||
|
||||
int firstRow = gridParameters.FirstRow;
|
||||
int lastRow = gridParameters.LastRow == -1 ? SDAServer.Instance.Configuration.MaximalRecordCountPerRequest - 1 : gridParameters.LastRow;
|
||||
|
||||
bool reduceDbLoadEnabled = false;
|
||||
// optimalizált lekérdezés template - csak a szükséges sorokat kéri majd le az adapter
|
||||
// ha engedélyezve van és ha van értelme (azaz a kért utolsó sor különbözik a max. sortól)
|
||||
if (lastRow < SDAServer.Instance.Configuration.MaximalRecordCountPerRequest - 1)
|
||||
{
|
||||
reduceDbLoadEnabled = true;
|
||||
// ORACLE
|
||||
|
||||
// subquery-ben nem lehet order by
|
||||
|
||||
bool canWrap = !(mOriginalcommandtext.Contains("order by") || mOriginalcommandtext.Contains("ORDER BY"));
|
||||
if (canWrap)
|
||||
{
|
||||
command.CommandText = string.Format(@"
|
||||
select * from
|
||||
(
|
||||
select row_number() over(order by {0}) as rnum_, szurttabla.*
|
||||
from
|
||||
( {1} ) szurttabla
|
||||
{2}
|
||||
) qqq
|
||||
where qqq.rnum_ between {3} and {4}",
|
||||
!string.IsNullOrWhiteSpace(orderBy.Trim()) ? orderBy : "(select 0)",
|
||||
mOriginalcommandtext,
|
||||
fullinnerfilter,
|
||||
firstRow + 1,
|
||||
lastRow + 1);
|
||||
}
|
||||
// nem tudunk optimalizálni
|
||||
else
|
||||
{
|
||||
reduceDbLoadEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region Language
|
||||
|
||||
//nyelvesites (c_name,c_name_1........)
|
||||
//SetMultilanguage(command);
|
||||
|
||||
#endregion Language
|
||||
|
||||
//Lekerdezes lefuttatasa
|
||||
if (reduceDbLoadEnabled)
|
||||
adapter.Fill(table);
|
||||
else
|
||||
adapter.Fill(table, (int)firstRow, (int)lastRow);
|
||||
|
||||
//ne legyen benne datasetben
|
||||
if (table.DataSet != null)
|
||||
{
|
||||
table.DataSet.Tables.Remove(table);
|
||||
}
|
||||
|
||||
// osszes mezore beallitom, hogy adatbazisbol jott
|
||||
var cols = new List<string>();
|
||||
foreach (DataColumn col in table.Columns)
|
||||
{
|
||||
cols.Add(col.ColumnName.ToUpper());
|
||||
}
|
||||
table.ExtendedProperties["DatabaseColumns"] = cols;
|
||||
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
public static int CheckRowCount(SDACommand command)
|
||||
{
|
||||
command.CommandType = CommandType.Text;
|
||||
command.Connection = UserContext.Instance.SDAConnection;
|
||||
command.Transaction = UserContext.Instance.SDATransaction;
|
||||
|
||||
using (var adapter = new SDADataAdapter())
|
||||
{
|
||||
adapter.SelectCommand = command;
|
||||
return GetRowCount(command);
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateOrderString(SDACommand command, ref string orderBy, out string fullinnerfilter)
|
||||
{
|
||||
const string orderFormatString = @"
|
||||
CASE WHEN (LEN({0}) < 10 AND {0} NOT LIKE '%[^0-9]%') OR (LEN({0}) = 10 AND ISDATE({0}) = 1)
|
||||
THEN CAST({0} AS INT)
|
||||
ELSE CASE WHEN LEFT({0}, 1) BETWEEN '0' AND '9' AND {0} LIKE '%[^0-9]%'
|
||||
THEN CAST(LEFT(SUBSTRING(CONVERT(VARCHAR, {0}), 1, ISNULL(PATINDEX('%[^0-9]%', CONVERT(VARCHAR, {0})), 0) - 1),9) AS INT)
|
||||
ELSE 2147483647
|
||||
END
|
||||
END {1}, {0} {1}";
|
||||
|
||||
//Ha van rendezési feltétel
|
||||
fullinnerfilter = "";
|
||||
if (!string.IsNullOrWhiteSpace(orderBy.Trim()))
|
||||
{
|
||||
//Több rendezési szempont esetén felbontjuk az egyes oszlopokra
|
||||
string[] orderByList = orderBy.Split(',');
|
||||
|
||||
//OrderBy-t ürítjük, majd újra összerakjuk a DNAME oszlopok miatt
|
||||
orderBy = "";
|
||||
|
||||
//Számoljuk a DNAME-es rendezési szempontok számát
|
||||
int dnameNo = 0;
|
||||
|
||||
//Végigmegyünk a rendezési szempontokon
|
||||
foreach (string strOrderBy in orderByList)
|
||||
{
|
||||
//A végső order by kifejezés tárolásához szükséges változó
|
||||
string strTempOrderBy = "";
|
||||
|
||||
string[] strOrderByColType = strOrderBy.Trim().Split(' ');
|
||||
|
||||
//A rendezés oszlopa
|
||||
string strOrderByCol = strOrderByColType[0];
|
||||
|
||||
//A rendezés típusa
|
||||
string strOrderByType;
|
||||
|
||||
//A rendezés típusának beállítása. ASC, vagy DESC a tartalma
|
||||
if (strOrderByColType.Length > 1)
|
||||
{ strOrderByType = strOrderByColType[1].IndexOf("ASC", StringComparison.OrdinalIgnoreCase) >= 0 ? " ASC" : " DESC"; }
|
||||
else
|
||||
{
|
||||
strOrderByType = " ASC";
|
||||
}
|
||||
|
||||
//Ha az aktuális rendezési szempont DNAME-es oszlop, akkor nyelvesítjük
|
||||
//és hozzákapcsolunk egy DictionaryItemBase táblát
|
||||
if (!string.IsNullOrWhiteSpace(strOrderByCol) && strOrderByCol.IndexOf("_DNAME", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
//leszedem a DNAME-et mert igy kapom meg az oszlopnevet amivel joinolok
|
||||
string DNAME = Regex.Replace(strOrderByCol, "_DNAME", "", RegexOptions.IgnoreCase);
|
||||
|
||||
//A tábla neve
|
||||
string strTableName = "t_dictionaryitembase";
|
||||
//A tábla alias-a, hogy több DNAME-es oszloppal is működjön
|
||||
string strTableAlias = "dict" + dnameNo.ToString();
|
||||
|
||||
strTempOrderBy = string.Format(orderFormatString, $"{strTableAlias}.c_name", strOrderByType);
|
||||
|
||||
fullinnerfilter += string.Format(" left join {0} {1} on {1}.id = szurttabla.{2}", strTableName, strTableAlias, DNAME);
|
||||
|
||||
//Megöveljük a DNAME-es rendezési szempontok számlálóját
|
||||
dnameNo++;
|
||||
}
|
||||
// Ha az aktuális rendezési szempont BNAME-es oszlop
|
||||
else if (!string.IsNullOrWhiteSpace(strOrderByCol) && strOrderByCol.IndexOf("_BNAME", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
{
|
||||
//leszedem a BNAME-et mert igy kapom meg az oszlopnevet amivel joinolok
|
||||
string BNAME = Regex.Replace(strOrderByCol, "_BNAME", "", RegexOptions.IgnoreCase);
|
||||
|
||||
if (strOrderByType.Equals(" ASC", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
strTempOrderBy = BNAME + " asc";
|
||||
}
|
||||
else
|
||||
{
|
||||
strTempOrderBy = BNAME + " desc";
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(strOrderByCol))
|
||||
{
|
||||
if (command.CommandText.Contains($"[\"]{strOrderByCol}[\"]"))
|
||||
{
|
||||
strTempOrderBy = string.Format(orderFormatString, $"\"{strOrderByCol}\"", strOrderByType);
|
||||
}
|
||||
else
|
||||
{
|
||||
strTempOrderBy = string.Format(orderFormatString, strOrderByCol, strOrderByType);
|
||||
}
|
||||
}
|
||||
//Ha nincs benne a lekérdezésben az az oszlop, amire rendezünk, akkor nem lehet
|
||||
//ez alapján rendezni, nem adjuk hozzá
|
||||
else
|
||||
{
|
||||
strTempOrderBy = "";
|
||||
}
|
||||
|
||||
//Végső, teljes OrderBy rész összerakása
|
||||
if (!string.IsNullOrWhiteSpace(strTempOrderBy))
|
||||
orderBy += strTempOrderBy + ",";
|
||||
}
|
||||
|
||||
orderBy = orderBy.TrimEnd(',');
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetRowCount(SDACommand command)
|
||||
{
|
||||
string oldCommandText = command.CommandText;
|
||||
|
||||
//utolso where helye
|
||||
int lastIndexOfWhere = command.CommandText.LastIndexOf("where", StringComparison.OrdinalIgnoreCase) == -1 ? 0 : command.CommandText.LastIndexOf("where", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
//utolso orderby helye
|
||||
int lastIndexOfOrderBy = command.CommandText.LastIndexOf("order by", StringComparison.OrdinalIgnoreCase) == -1 ? command.CommandText.Length : command.CommandText.LastIndexOf("order by", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
//levagom az order by-os végét, ha az a legutolsó
|
||||
if (lastIndexOfOrderBy > lastIndexOfWhere)
|
||||
{
|
||||
command.CommandText = command.CommandText.Substring(0, lastIndexOfOrderBy);
|
||||
}
|
||||
|
||||
command.CommandText = "SELECT COUNT(1) FROM ( " + command.CommandText + " ) ttt";
|
||||
|
||||
int rowsCount = Convert.ToInt32(command.ExecuteScalar());
|
||||
|
||||
command.CommandText = oldCommandText;
|
||||
|
||||
return rowsCount;
|
||||
}
|
||||
|
||||
public static string ToString(object data)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((data == null) || (data == DBNull.Value))
|
||||
? string.Empty
|
||||
: data.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ToInt32(object data)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((data == null) || (data == DBNull.Value) || string.IsNullOrWhiteSpace(data.ToString()))
|
||||
? 0
|
||||
: Convert.ToInt32(data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class AlphanumComparator<T> : IComparer<T>
|
||||
{
|
||||
private enum ChunkType { Alphanumeric, Numeric };
|
||||
private bool InChunk(char ch, char otherCh)
|
||||
{
|
||||
ChunkType type = ChunkType.Alphanumeric;
|
||||
|
||||
if (char.IsDigit(otherCh))
|
||||
{
|
||||
type = ChunkType.Numeric;
|
||||
}
|
||||
|
||||
if ((type == ChunkType.Alphanumeric && char.IsDigit(ch))
|
||||
|| (type == ChunkType.Numeric && !char.IsDigit(ch)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int Compare(T x, T y)
|
||||
{
|
||||
if (!(x is string s1) || !(y is string s2) || (s1 == null) || (s2 == null))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int thisMarker = 0;
|
||||
int thatMarker = 0;
|
||||
|
||||
while ((thisMarker < s1.Length) || (thatMarker < s2.Length))
|
||||
{
|
||||
if (thisMarker >= s1.Length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (thatMarker >= s2.Length)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
char thisCh = s1[thisMarker];
|
||||
char thatCh = s2[thatMarker];
|
||||
|
||||
var thisChunk = new StringBuilder();
|
||||
var thatChunk = new StringBuilder();
|
||||
|
||||
while ((thisMarker < s1.Length) && (thisChunk.Length == 0 || InChunk(thisCh, thisChunk[0])))
|
||||
{
|
||||
thisChunk.Append(thisCh);
|
||||
thisMarker++;
|
||||
|
||||
if (thisMarker < s1.Length)
|
||||
{
|
||||
thisCh = s1[thisMarker];
|
||||
}
|
||||
}
|
||||
|
||||
while ((thatMarker < s2.Length) && (thatChunk.Length == 0 || InChunk(thatCh, thatChunk[0])))
|
||||
{
|
||||
thatChunk.Append(thatCh);
|
||||
thatMarker++;
|
||||
|
||||
if (thatMarker < s2.Length)
|
||||
{
|
||||
thatCh = s2[thatMarker];
|
||||
}
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
// If both chunks contain numeric characters, sort them numerically
|
||||
if (char.IsDigit(thisChunk[0]) && char.IsDigit(thatChunk[0]))
|
||||
{
|
||||
if (int.TryParse(thisChunk.ToString(), out int thisIntNumericChunk) && int.TryParse(thatChunk.ToString(), out int thatIntNumericChunk))
|
||||
{
|
||||
if (thisIntNumericChunk < thatIntNumericChunk)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if (thisIntNumericChunk > thatIntNumericChunk)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
else if (long.TryParse(thisChunk.ToString(), out long thisLongNumericChunk) && long.TryParse(thatChunk.ToString(), out long thatLongNumericChunk))
|
||||
{
|
||||
if (thisLongNumericChunk < thatLongNumericChunk)
|
||||
{
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if (thisLongNumericChunk > thatLongNumericChunk)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = thisChunk.ToString().CompareTo(thatChunk.ToString());
|
||||
}
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
101
Kreta.DataAccessManual/Util/DictionaryItemCacheUtil.cs
Normal file
101
Kreta.DataAccessManual/Util/DictionaryItemCacheUtil.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Util;
|
||||
|
||||
namespace Kreta.DataAccessManual.Util
|
||||
{
|
||||
public sealed class DictionaryItemCacheUtil
|
||||
{
|
||||
private const string DictionaryNamePostfix = "_DNAME";
|
||||
private const string SeparatorString = ",;";
|
||||
|
||||
/// <summary>
|
||||
/// Létrehoz új oszlopokat processedTable-ben {ColumnName}_DNAME névvel(ha még ilyen nevű oszlopok nem léteznek).
|
||||
/// Kitölti a DictionaryCache-ből a columnNamesString értéke alapján {ColumnName}_DNAME értékét.
|
||||
/// Ha már létezik a {ColumnName}_DNAME oszlop, akkor felülírja az oszlop tartalmát.
|
||||
/// </summary>
|
||||
/// <param name="processedTable"></param>
|
||||
/// <param name="columnNamesString"></param>
|
||||
public static void TableColumnFromDictionaryCache(DataTable processedTable, string columnNamesString)
|
||||
{
|
||||
#region Argumentnull-ellenőrzés
|
||||
|
||||
if (processedTable == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(processedTable));
|
||||
}
|
||||
|
||||
if (columnNamesString == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(columnNamesString));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Oszlopnevek kinyerése columnNamesString argumentumból
|
||||
|
||||
// oszlopnevek szeparálása
|
||||
var separator = SeparatorString.ToCharArray();
|
||||
var columnNames = columnNamesString.Split(separator);
|
||||
var columnCount = columnNames.Length;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Egzisztencia-ellenőrzés
|
||||
|
||||
for (var i = 0; i < columnCount; i++)
|
||||
{
|
||||
var columnName = columnNames[i];
|
||||
if (processedTable.Columns.Contains(columnName) == false)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(columnNamesString), columnNamesString, @"The columnNamesString parameter contains columnName that not exists in the specified table!");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Oszlopok hozzáadása
|
||||
|
||||
for (var i = 0; i < columnCount; i++)
|
||||
{
|
||||
var newColumnName = columnNames[i] + DictionaryNamePostfix;
|
||||
if (processedTable.Columns[newColumnName] == null)
|
||||
{
|
||||
processedTable.Columns.Add(newColumnName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Szövegek beállítása a cache-selt szótárból (nyelvesen)
|
||||
|
||||
// DNAME beállítás a cache-ből
|
||||
foreach (DataRow dataRow in processedTable.Rows)
|
||||
{
|
||||
for (var i = 0; i < columnCount; i++)
|
||||
{
|
||||
var rowHasValue = true;
|
||||
|
||||
var newColumnName = columnNames[i] + DictionaryNamePostfix;
|
||||
if (dataRow[columnNames[i]] == DBNull.Value || string.IsNullOrWhiteSpace(dataRow[columnNames[i]].ToString()))
|
||||
{
|
||||
rowHasValue = false;
|
||||
}
|
||||
|
||||
if (rowHasValue)
|
||||
{
|
||||
var strActCache = Convert.ToInt32(dataRow[columnNames[i]]).GetItemNameFromCache(UserContext.Instance.SelectedTanevId);
|
||||
dataRow[newColumnName] = strActCache;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataRow[newColumnName] = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue