private static List<SpecialOfferEntity> FillMissingOffers(SpecialOfferEntity[] collectionToFill)
        {
            if (collectionToFill.Length > short.MaxValue)
            {
                throw new ArgumentException("The length of the collection (amount of special offers) must not exceed a short data type.");
            }

            for (int i = 0; i < collectionToFill.Length; i++)
            {
                SpecialOfferEntity placeholderSof = new SpecialOfferEntity();
                placeholderSof.Number = (short) (i + 1);
                ProductEntity placeholderProduct = new ProductEntity();
                placeholderProduct.Name = "Please Choose Product";
                placeholderProduct.Id = -1;

                placeholderSof.Product = placeholderProduct;

                if (collectionToFill[i] == null)
                {
                    collectionToFill[i] = placeholderSof;
                }
            }

            return new List<SpecialOfferEntity>(collectionToFill);
        }
        public static ProductEntity LoadProductById(int productId)
        {
            var product = new ProductEntity(productId);

            using (var adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(product);
            }

            return product;
        }
 protected void btnUpdate_Click(object sender, EventArgs e)
 {
     Thread.Sleep(200);
     var toSave = new ProductEntity(int.Parse(txtProdId.Text));
     toSave.IsNew = false;
     toSave.Name = txtProdName.Text;
     toSave.Description = txtProdDescription.Text;
     toSave.ExtraInformation = txtExtraInformation.Text;
     toSave.Price = decimal.Parse(txtProdPrice.Text);
     toSave.PriceIncludesVat = chkIncludesVat.Checked;
     toSave.PriceIsFrom = chkPriceIsFrom.Checked;
     toSave.Enabled = chkVisible.Checked;
     toSave.DeliveryPrice = decimal.Parse(txtDeliveryPrice.Text);
     toSave.ImageName = txtImageFileName.Text;
     toSave.Save();
 }
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     Thread.Sleep(200);
     var toDelete = new ProductEntity(int.Parse(txtProdId.Text));
     toDelete.Delete();
 }
        /// <summary> setups the sync logic for member _product</summary>
        /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
        private void SetupSyncProduct(IEntity2 relatedEntity)
        {
            DesetupSyncProduct(true);
            if(relatedEntity!=null)
            {
                _product = (ProductEntity)relatedEntity;
                _product.ActiveContext = base.ActiveContext;
                _product.AfterSave+=new EventHandler(OnEntityAfterSave);
                base.SetEntitySyncInformation("Product", _product, SpecialOfferEntity.Relations.ProductEntityUsingProductId);

            }
        }
        /// <summary> Removes the sync logic for member _product</summary>
        /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
        private void DesetupSyncProduct(bool signalRelatedEntity)
        {
            if(_product != null)
            {

                _product.AfterSave-=new EventHandler(OnEntityAfterSave);
                base.UnsetEntitySyncInformation("Product", _product, SpecialOfferEntity.Relations.ProductEntityUsingProductId);
                if(signalRelatedEntity)
                {
                    _product.UnsetRelatedEntity(this, "SpecialOffer");
                }
                SetNewFieldValue((int)SpecialOfferFieldIndex.ProductId, null);
                _product = null;
            }
        }
        /// <summary> Initializes the class members</summary>
        protected virtual void InitClassMembers()
        {
            _product = null;

            // __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
 /// <summary>Sets the field on index fieldIndex to the new value value. Marks also the fields object as dirty.</summary>
 /// <param name="fieldIndex">Index of field to set the new value of</param>
 /// <param name="value">Value to set</param>
 /// <returns>true if the value is actually set, false otherwise.</returns>
 /// <remarks>Dereferences a related object in an 1:1/m:1 relation if the field is an FK field and responsible for the reference of that particular related object.</remarks>
 /// <exception cref="ArgumentOutOfRangeException">When fieldIndex is smaller than 0 or bigger than the number of fields in the fields collection.</exception>
 public override bool SetNewFieldValue(int fieldIndex, object value)
 {
     bool toReturn = base.SetNewFieldValue (fieldIndex, value, false);
     if(toReturn && Enum.IsDefined(typeof(SpecialOfferFieldIndex), fieldIndex))
     {
         switch((SpecialOfferFieldIndex)fieldIndex)
         {
             case SpecialOfferFieldIndex.ProductId:
                 DecoupleEventsProduct();
                 _product = null;
                 break;
             default:
                 break;
         }
         base.PostFieldValueSetAction(toReturn);
         switch((SpecialOfferFieldIndex)fieldIndex)
         {
             case SpecialOfferFieldIndex.Id:
                 OnIdChanged();
                 break;
             case SpecialOfferFieldIndex.ProductId:
                 OnProductIdChanged();
                 break;
             case SpecialOfferFieldIndex.Number:
                 OnNumberChanged();
                 break;
             default:
                 break;
         }
     }
     return toReturn;
 }
        protected SpecialOfferEntity(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _product = (ProductEntity)info.GetValue("_product", typeof(ProductEntity));
            if(_product!=null)
            {
                _product.AfterSave+=new EventHandler(OnEntityAfterSave);
            }

            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
        /// <summary>Creates a new ProductEntity instance but uses a special constructor which will set the Fields object of the new
        /// IEntity2 instance to the passed in fields object. Implement this method to support multi-type in single table inheritance.</summary>
        /// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
        /// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
        public virtual IEntity2 Create(IEntityFields2 fields)
        {
            IEntity2 toReturn = new ProductEntity(fields);

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewProductUsingFields
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
        /// <summary>Creates a new, empty ProductEntity object.</summary>
        /// <returns>A new, empty ProductEntity object.</returns>
        public virtual IEntity2 Create()
        {
            IEntity2 toReturn = new ProductEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewProduct
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
 /// <summary>Sets the field on index fieldIndex to the new value value. Marks also the fields object as dirty.</summary>
 /// <param name="fieldIndex">Index of field to set the new value of</param>
 /// <param name="value">Value to set</param>
 /// <returns>true if the value is actually set, false otherwise.</returns>
 /// <remarks>Dereferences a related object in an 1:1/m:1 relation if the field is an FK field and responsible for the reference of that particular related object.</remarks>
 /// <exception cref="ArgumentOutOfRangeException">When fieldIndex is smaller than 0 or bigger than the number of fields in the fields collection.</exception>
 public override bool SetNewFieldValue(int fieldIndex, object value)
 {
     bool toReturn = base.SetNewFieldValue (fieldIndex, value, false);
     if(toReturn && Enum.IsDefined(typeof(ProductVariationFieldIndex), fieldIndex))
     {
         switch((ProductVariationFieldIndex)fieldIndex)
         {
             case ProductVariationFieldIndex.ProductId:
                 DecoupleEventsProduct();
                 _product = null;
                 break;
             default:
                 break;
         }
         base.PostFieldValueSetAction(toReturn);
         switch((ProductVariationFieldIndex)fieldIndex)
         {
             case ProductVariationFieldIndex.Id:
                 OnIdChanged();
                 break;
             case ProductVariationFieldIndex.ProductId:
                 OnProductIdChanged();
                 break;
             case ProductVariationFieldIndex.Price:
                 OnPriceChanged();
                 break;
             case ProductVariationFieldIndex.PriceIncludesVat:
                 OnPriceIncludesVatChanged();
                 break;
             case ProductVariationFieldIndex.PriceIsFrom:
                 OnPriceIsFromChanged();
                 break;
             case ProductVariationFieldIndex.Text:
                 OnTextChanged();
                 break;
             default:
                 break;
         }
     }
     return toReturn;
 }