Inheritance: ActiveRecordHooksBase
        public EditCatalogWindow (string model, object record,
            ActiveRecordModel mod, EventHandler OnSaveButtonClicked, Gtk.Window parent) :
                base(Gtk.WindowType.Toplevel)
        {
            this.Build ();
            this.TransientFor = parent;
            this.Modal = true;
            this.model = model;
            this.mod = mod;
            this.record = (ActiveRecordBase)record;
            this.OnRecordSaved = OnSaveButtonClicked;
            this.WindowPosition = Gtk.WindowPosition.CenterAlways;
            this.Title = model + " creation";

            modelLabel.Text = model;

            if (!mod.PropertyDictionary.Keys.Contains("Notes"))
            {
                editRecord.HideNotesEntry ();

            }

            PropertyInfo p = record.GetType().GetProperty("ParentId");
            if (p != null) {
               MethodInfo modelMethod = record.GetType().GetMethod("ParentModel");
               editRecord.ParentName = modelMethod.Invoke (record, null) as String;

               MethodInfo nameMethod = record.GetType().GetMethod("ParentName");
               editRecord.ParentValue = nameMethod.Invoke (record, null) as String;

           } else {
               editRecord.HideParentEntry ();
           }
        }
        protected ActiveRecordBase SetDetailsKeys(ActiveRecordBase entityMaster, ActiveRecordBase entityDetail, KPFormItemKeyFieldsCollection keyFieldsConfig)
        {
            if (keyFieldsConfig != null)
            {
                foreach (KPMappingKeyModel key in keyFieldsConfig)
                {
                    PropertyInfo propMaster = entityMaster.GetType().GetProperty(key.KeyMaster);
                    PropertyInfo propDetail = entityDetail.GetType().GetProperty(key.KeyDetail);
                    if (propMaster != null && propDetail != null)
                    {
                        object value = propMaster.GetValue(entityMaster, null);

                        if (value == null)
                            continue;

                        int idKey = 0;
                        if (Int32.TryParse(value.ToString(), out idKey))
                        {
                            // Proteção para não trazer nada quando novo
                            if (idKey == 0)
                                continue;
                        }

                        if (propMaster.PropertyType == propDetail.PropertyType)
                        {
                            propDetail.SetValue(entityDetail, value, null);
                        }
                        else
                        {
                            if (typeof(ActiveRecordBase).IsSubclassOfRawGeneric(propDetail.PropertyType))
                            {
                                MethodInfo methodFind = propDetail.PropertyType.GetMethodInheritance("Find", new Type[] { typeof(object) });
                                if (methodFind != null)
                                {
                                    object objValue = methodFind.Invoke(null, new object[] { value });
                                    if (objValue != null)
                                    {
                                        propDetail.SetValue(entityDetail, objValue, null);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return entityDetail;
        }
示例#3
0
 /// <summary>
 /// Creates (Saves) a new instance to the database.
 /// </summary>
 public virtual void Create()
 {
     ActiveRecordBase.Create(this);
 }
示例#4
0
 /// <summary>
 /// Deletes the instance from the database.
 /// </summary>
 public virtual void Delete()
 {
     ActiveRecordBase.Delete(this);
 }
示例#5
0
 /// <summary>
 /// Check if there is any records in the db for <typeparamref name="T"/>
 /// </summary>
 /// <returns><c>true</c> if there's at least one row</returns>
 public static bool Exists()
 {
     return(ActiveRecordBase.Exists(typeof(T)));
 }
示例#6
0
 /// <summary>
 /// Deletes the instance from the database.
 /// </summary>
 /// <param name="instance">The ActiveRecord instance to be deleted</param>
 protected internal static void Delete(T instance)
 {
     ActiveRecordBase.Delete(instance);
 }
 /// <summary>
 /// Check if any instance matching the criteria exists in the database.
 /// </summary>
 /// <param name="detachedCriteria">The criteria expression</param>
 /// <returns><c>true</c> if an instance is found; otherwise <c>false</c>.</returns>
 public static bool Exists(DetachedCriteria detachedCriteria)
 {
     return(ActiveRecordBase.Exists(typeof(T), detachedCriteria));
 }
示例#8
0
 /// <summary>
 /// Saves the instance to the database. If the primary key is unitialized
 /// it creates the instance on the database. Otherwise it updates it.
 /// <para>
 /// If the primary key is assigned, then you must invoke <see cref="Create"/>
 /// or <see cref="Update"/> instead.
 /// </para>
 /// </summary>
 /// <param name="instance">The ActiveRecord instance to be saved</param>
 protected internal static void Save(T instance)
 {
     ActiveRecordBase.Save(instance);
 }
示例#9
0
 public static void Delete(T instance)
 {
     ActiveRecordBase.Delete(instance);
 }
 /// <summary>
 /// Check if the <paramref name="id"/> exists in the database.
 /// </summary>
 /// <param name="id">The id to check on</param>
 /// <returns><c>true</c> if the ID exists; otherwise <c>false</c>.</returns>
 public static bool Exists(object id)
 {
     return(ActiveRecordBase.Exists(typeof(T), id));
 }
示例#11
0
 public static void Create(T instance)
 {
     ActiveRecordBase.Create(instance);
 }
示例#12
0
 public static void Update(T instance)
 {
     ActiveRecordBase.Update(instance);
 }
示例#13
0
 public static void Save(T instance)
 {
     ActiveRecordBase.Save(instance);
 }
示例#14
0
 public static T[] FindAll(ICriterion[] criterias, Order[] orders, int firstResult, int maxresults)
 {
     return((T[])ActiveRecordBase.SlicedFindAll(typeof(T), firstResult, maxresults, orders, criterias));
 }
示例#15
0
 public static T[] FindAll(ICriterion[] criterias, Order[] orders)
 {
     return((T[])ActiveRecordBase.FindAll(typeof(T), orders, criterias));
 }
        /// <summary>
        /// Responsável por setar a Company na entrada do formulário.
        /// Usar apenas quando é um novo cadastro.
        /// </summary>
        /// <param name="entityData"></param>
        private void SetCurrentCompany(ActiveRecordBase entityData)
        {
            #region Responsável por Setar Company
            if (entityData == null)
                return;

            KPSecuritySession session = KPFormsAuthentication.SecuritySession;

            if (!String.IsNullOrEmpty(this.PropertyCompanyEntity) && !PropertyCompanyEntity.Equals("!") && session != null)
            {
                PropertyInfo propCompany = entityData.GetType().GetProperty(this.PropertyCompanyEntity);
                if (propCompany != null && propCompany.PropertyType.Equals(typeof(FrwCompany)))
                {
                    FrwCompany companyInstance = FrwCompany.Find(session.FrwCompany);
                    propCompany.SetValue(entityData, companyInstance, null);
                }
            }
            #endregion
        }
示例#17
0
 public static void Execute(T instnace, NHibernateDelegate call)
 {
     ActiveRecordBase.Execute(typeof(T), call, instnace);
 }
示例#18
0
 public static T[] FindAll(params ICriterion[] criterias)
 {
     return((T[])ActiveRecordBase.FindAll(typeof(T), criterias));
 }
 /// <summary>
 /// Finds records based on a property value - automatically converts null values to IS NULL style queries.
 /// </summary>
 /// <param name="orderByColumn">The column name to be ordered ASC</param>
 /// <param name="property">A property name (not a column name)</param>
 /// <param name="value">The value to be equals to</param>
 /// <returns></returns>
 public static T[] FindAllByProperty(String orderByColumn, String property, object value)
 {
     return(ActiveRecordBase <T> .FindAllByProperty(orderByColumn, property, value));
 }
 /// <summary>
 /// Check if any instance matches the criteria.
 /// </summary>
 /// <returns><c>true</c> if an instance is found; otherwise <c>false</c>.</returns>
 public static bool Exists(params ICriterion[] criterias)
 {
     return(ActiveRecordBase.Exists(typeof(T), criterias));
 }
 /// <summary>
 /// Executes the query and return a strongly typed result
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public static R ExecuteQuery2 <R>(IActiveRecordQuery <R> query)
 {
     return(ActiveRecordBase <T> .ExecuteQuery2(query));
 }
示例#22
0
 /// <summary>
 /// Refresh the instance from the database.
 /// </summary>
 /// <param name="instance">The ActiveRecord instance to be reloaded</param>
 protected internal static void Refresh(T instance)
 {
     ActiveRecordBase.Refresh(instance);
 }
 /// <summary>
 /// Check if the <paramref name="id"/> exists in the database.
 /// </summary>
 /// <typeparam name="PkType">The <c>System.Type</c> of the PrimaryKey</typeparam>
 /// <param name="id">The id to check on</param>
 /// <returns><c>true</c> if the ID exists; otherwise <c>false</c>.</returns>
 public static bool Exists <PkType>(PkType id)
 {
     return(ActiveRecordBase <T> .Exists(id));
 }
示例#24
0
 /// <summary>
 /// Saves a copy of the instance to the database. If the primary key is unitialized
 /// it creates the instance on the database. Otherwise it updates it.
 /// <para>
 /// If the primary key is assigned, then you must invoke <see cref="Create"/>
 /// or <see cref="Update"/> instead.
 /// </para>
 /// </summary>
 /// <param name="instance">The transient instance to be saved</param>
 /// <returns>The saved ActiveRecord instance.</returns>
 protected internal static T SaveCopy(T instance)
 {
     return((T)ActiveRecordBase.SaveCopy(instance));
 }
 /// <summary>
 /// Returns the number of records of the specified
 /// type in the database
 /// </summary>
 /// <returns>The count result</returns>
 public static int Count()
 {
     return(ActiveRecordBase.Count(typeof(T)));
 }
示例#26
0
 /// <summary>
 /// Creates (Saves) a new instance to the database.
 /// </summary>
 /// <param name="instance">The ActiveRecord instance to be created on the database</param>
 protected internal static void Create(T instance)
 {
     ActiveRecordBase.Create(instance);
 }
 /// <summary>
 /// Returns the number of records of the specified
 /// type in the database that match the given critera
 /// </summary>
 /// <param name="criteria">The criteria expression</param>
 /// <returns>The count result</returns>
 public static int Count(params ICriterion[] criteria)
 {
     return(ActiveRecordBase.Count(typeof(T), criteria));
 }
示例#28
0
 /// <summary>
 /// Saves the instance information to the database.
 /// May Create or Update the instance depending
 /// on whether it has a valid ID.
 /// </summary>
 public virtual void Save()
 {
     ActiveRecordBase.Save(this);
 }
 /// <summary>
 /// Returns the number of records of the specified
 /// type in the database
 /// </summary>
 /// <param name="filter">A sql where string i.e. Person=? and DOB &gt; ?</param>
 /// <param name="args">Positional parameters for the filter string</param>
 /// <returns>The count result</returns>
 public static int Count(string filter, params object[] args)
 {
     return(ActiveRecordBase.Count(typeof(T), filter, args));
 }
示例#30
0
 /// <summary>
 /// Persists the modification on the instance
 /// state to the database.
 /// </summary>
 public virtual void Update()
 {
     ActiveRecordBase.Update(this);
 }
 public KPExceptionValidator(ActiveRecordBase entity, InvalidValue[] errors)
 {
     Entity = entity;
     Erros = errors;
 }
        protected virtual void AfterSaveEntity(ActiveRecordBase entity)
        {
            try
            {
                if (KPFormMasterDetailConfig != null && KPFormMasterDetailConfig.Count > 0)
                {
                    foreach (KPFormMasterDetailModel item in KPFormMasterDetailConfig)
                    {
                        string masterDetailID = item.MasterDetailID;
                        DetailSession detailSession = KPSessionHelper.GetSessionMasterDetailList(PageBase.SessionPageID, masterDetailID);
                        if (detailSession != null)
                        {
                            foreach (DetailEntity detailEntity in detailSession.DetailsEntity)
                            {
                                detailEntity.Entity.Delete();
                            }

                            foreach (var objEntity in detailSession.Entities)
                            {
                                var entityDetail = (objEntity as ActiveRecordBase);
                                if (entityDetail != null)
                                {
                                    var entitySaving = SetDetailsKeys(entity, entityDetail, item.KeyFieldsConfig);
                                    PropertyInfo propPK = entitySaving.GetType().GetEntityPrimaryKey();
                                    object valuePK = propPK.GetValue(entitySaving, null);
                                    int valuePKInt = 0;
                                    if (Int32.TryParse(valuePK.ToString(), out valuePKInt))
                                    {
                                        if (valuePKInt < 0)
                                            propPK.SetValue(entitySaving, 0, null);

                                        entitySaving.Save();
                                    }
                                }
                            }
                        }
                        KPSessionHelper.RemoveSessionMasterDetailList(PageBase.SessionPageID, masterDetailID);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private ICriterion GetFiltering(KPFormItemKeyFieldsCollection keys, ActiveRecordBase entity)
        {
            Conjunction conjuntion = new Conjunction();

            if (entity != null && MasterDetailConfig.TypeEntityDetail != null)
            {
                foreach (KPMappingKeyModel key in keys)
                {
                    PropertyInfo propMaster = entity.GetType().GetProperty(key.KeyMaster);
                    PropertyInfo propDetail = MasterDetailConfig.TypeEntityDetail.GetProperty(key.KeyDetail);
                    if (propMaster != null && propDetail != null)
                    {
                        object value = propMaster.GetValue(entity, null);

                        int idKey = 0;
                        if (Int32.TryParse(value.ToString(), out idKey))
                        {
                            // Proteção para não trazer nada quando novo
                            if (idKey == 0)
                            {
                                conjuntion.Add(Expression.Sql(" 1 = 2"));
                                return conjuntion;
                            }

                        }

                        if (propMaster.PropertyType == propDetail.PropertyType)
                        {
                            conjuntion.Add(Expression.Eq(key.KeyDetail, value));
                        }
                        else
                        {
                            if (typeof(ActiveRecordBase).IsSubclassOfRawGeneric(propDetail.PropertyType))
                            {
                                MethodInfo methodFind = propDetail.PropertyType.GetMethodInheritance("Find", new Type[] { typeof(object) });
                                if (methodFind != null)
                                {
                                    object objValue = methodFind.Invoke(null, new object[] { value });
                                    if (objValue != null)
                                    {
                                        conjuntion.Add(Expression.Eq(key.KeyDetail, objValue));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return conjuntion;
        }
 /// <summary>
 /// Returns the number of records of the specified
 /// type in the database
 /// </summary>
 /// <param name="detachedCriteria">The criteria expression</param>
 /// <returns>The count result</returns>
 public static int Count(DetachedCriteria detachedCriteria)
 {
     return(ActiveRecordBase.Count(typeof(T), detachedCriteria));
 }
示例#35
0
 public static T[] FindAll()
 {
     return((T[])ActiveRecordBase.FindAll(typeof(T)));
 }
 /// <summary>
 /// Check if there is any records in the db for the target type
 /// </summary>
 /// <param name="filter">A sql where string i.e. Person=? and DOB &gt; ?</param>
 /// <param name="args">Positional parameters for the filter string</param>
 /// <returns><c>true</c> if there's at least one row</returns>
 public static bool Exists(string filter, params object[] args)
 {
     return(ActiveRecordBase.Exists(typeof(T), filter, args));
 }
 public DetailEntity(ActiveRecordBase entity, StateDetailEntity stateEntity)
 {
     Entity = entity;
     StateEntity = stateEntity;
 }