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; }
/// <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 }
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; }