/////////////////////////////////////////////////////////// // NLHotList.cs // Implementation of the Class NLHotList // Created on: 6.10.2011 // Original author: Miroslav Brousek // Description: Třída záznamu uživatelských nabídek pro nabídky typu Divoká karta /////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using NaCesty.IKSEngine; using NaCesty.IKSEngine.Resources; using NaCesty.IKSEngine.Data; using NaCesty.IKSEngine.Data.DataModel; using NaCesty.IKSEngine.Transactions; using NaCesty.Newsletters.Resources; namespace NaCesty.Newsletters.Data { /// /// Třída definující datový záznam hotlistu - seznamu uživatelských nabídek pro nabídky typu Divoká karta. /// [IKSDataClassAttr("NL_HotList", DBEntityKind.Table)] public class NLHotList : IKSPersistentClass { //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Public properties & methods //////////////////////////////////////////////////////////////////////////////////////////////////////////////// public NLHotList() {} public NLHotList(IIKSProcess aOwner) : base(aOwner) { } public NLHotList(IKSTransaction aTransaction) : base(aTransaction) { } // ---- Data column properties --------------------------------------------------------------------------------- [IKSDataPropertyAttr("UID_HotList", DBKeyKind.Primary, SqlDbType.VarChar, 10, true, null)] public object UID_HotList; [IKSDataPropertyAttr("UID_Transaction", DBKeyKind.None, SqlDbType.VarChar, 10, true, null)] public object UID_Transaction; [IKSDataPropertyAttr("NaCestyURL", SqlDbType.VarChar, 500)] public string NaCestyURL; [IKSDataPropertyAttr("ImageURL", SqlDbType.VarChar, 500)] public string ImageURL; [IKSDataPropertyAttr("Title", SqlDbType.NVarChar, 500)] public string Title; [IKSDataPropertyAttr("Description", SqlDbType.NVarChar, 1000)] public string Description; [IKSDataPropertyAttr("StateCode", SqlDbType.Int)] public int StateCode; // ---- Class properties --------------------------------------------------------------------------------------- public IKSTransaction Transaction { get { return this.getTransaction(); } set { this.setTransaction(value); }} public NLHotListState State { get { return this.getStateCode(); } set { this.setStateCode(value); }} // ---- Public methods ----------------------------------------------------------------------------------------- /// /// Vrátí hodnotu true, pokud se jedná o novou instanci nabídky hotlistu /// public bool IsNew() { return this.UID_HotList == null; } /// /// Nastaví a zapíše stav nabídky /// /// public void UpdateState(NLHotListState aState) { this.checkNewState(aState); this.State = aState; this.Write(); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Protected properties & methods //////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected override bool doValidate() { return //Musí být vyplněná transakce ((this.UID_Transaction != null) && !String.IsNullOrWhiteSpace(this.UID_Transaction.ToString())) && //Musí být definován platný druh záznamu Enum.IsDefined(typeof(NLHotListState), this.StateCode); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Private properties & methods implementation //////////////////////////////////////////////////////////////////////////////////////////////////////////////// // ---- Private attributes ------------------------------------------------------------------------------------- private IKSTransaction _Transaction; // ---- Properties Get.. & Set.. methods ----------------------------------------------------------------------- private NLHotListState getStateCode() { return (NLHotListState)Enum.Parse(typeof(NLHotListState), Enum.GetName(typeof(NLHotListState), this.StateCode)); } private void setStateCode(NLHotListState value) { this.StateCode = (int)value; } private IKSTransaction getTransaction() { if (this.UID_Transaction == null) this.clearTransaction(); else if ((_Transaction == null) || (!_Transaction.UID_Transaction.Equals(UID_Transaction))) { if (_Transaction != null) this.clearTransaction(); _Transaction = new IKSTransaction(UID_Transaction); } return _Transaction; } private void setTransaction(IKSTransaction value) { if (this.UID_HotList != null) IKSException.InternalError("NLHotList setTransaction error: Instanci transakce lze explicitně přiřadit pouze u nového záznamu nabídky hotlistu." ); this.clearTransaction(); _Transaction = value; this.UID_Transaction = _Transaction != null ? _Transaction.UID_Transaction : null; } // ---- Private methods implementation --------------------------------------------------------------------------------- private void clearTransaction() { if (_Transaction != null) { _Transaction.Dispose(); _Transaction = null; } } private void checkNewState(NLHotListState aState) { if (this.StateCode == (int)NLHotListState.Deleted) throw IKSException.Error("Nelze změnit stav smazaného záznamu"); } } }