using MicroFour.StrataFrame.Business;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Serialization;
using System.Text;

namespace TestConcurr1
{
    [Serializable()]
    public partial class TesteBaseBO : MicroFour.StrataFrame.Business.BusinessLayer
    {

        private Boolean lbCollision = false;

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the BusinessObject1 class.
        /// </summary>
        public TesteBaseBO()
            : base()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Initializes a new instance of the BusinessObject1 class.
        /// </summary>
        /// <param name="container">The IContainer to which this business object will be added.</param>
        public TesteBaseBO(IContainer container)
            : base()
        {
            container.Add(this);

            InitializeComponent();
        }

        /// <summary>
        /// Initializes a new instance of the BusinessObject1 class.
        /// </summary>
        /// <param name="info">The SerializationInfo for the object to create.</param>
        /// <param name="context">The StreamingContext for the source stream.</param>
        protected TesteBaseBO(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            InitializeComponent();
        }

        #endregion

        #region Data Retrieval Methods



        #endregion

        #region Event Handlers

        /// <summary>
        /// Checks the business rules on the current row
        /// </summary>
        /// <param name="e"></param>
        /// <remarks></remarks>
        private void TesteBaseBO_CheckRulesOnCurrentRow(CheckRulesEventArgs e)
        {
            if ((lbCollision == true))
            {
                this.AddBrokenRule(this.PrimaryKeyField, "Another user has amended this item at the same time");
            }
        }

        /// <summary>
        /// Sets the default values for a new row
        /// </summary>
        /// <remarks></remarks>
        private void TesteBaseBO_SetDefaultValues()
        {

        }

        private void TesteBaseBO_ConcurrencyException(MicroFour.StrataFrame.Data.ConcurrencyExceptionEventArgs e)
        {
            //System.Windows.Forms.MessageBox.Show("teste");
            this.AddBrokenRule(this.PrimaryKeyField, "Another user has amended this item at the same time");
            //e.ResaveRecord = true;
            //this.Save();
            e.ResaveRecord = false;
            lbCollision = true;
            this.CheckRulesOnRow(true);
        }

        #endregion

    }
}
