private void OnReferenceObjectSelected(object selectedReference) { ReferenceProxy proxy = selectedReference as ReferenceProxy; this.Value = proxy; this.SetupValueView(); }
private void OnReferenceObjectSelected(ChameleonBox target, ReferenceProxy entity) { target.ChameleonValue = entity; target.ChameleonType = entity.Type; UpdateSourceObjectValue(target); DataGridCell cell = target.GetParent<DataGridCell>(); if (cell == null) return; cell.IsEditing = false; }
public List <Dictionary <string, object> > ExecuteAsRowData() { string ConnectionString = MetadataPersistentContext.Current.ConnectionString; PropertyReferenceManager manager; List <Dictionary <string, object> > result = new List <Dictionary <string, object> >(); using (SqlConnection connection = new SqlConnection(ConnectionString)) using (SqlCommand command = new SqlCommand(sql.ToString(), connection)) { connection.Open(); if (query.Parameters != null) { foreach (ParameterExpression parameter in query.Parameters) { if (parameter.Value is ReferenceProxy) { ReferenceProxy parameterValue = (ReferenceProxy)parameter.Value; if (parameterValue.Type.Namespace.Name == "MetaModel") { command.Parameters.AddWithValue(parameter.Name, parameterValue.Identity); } else { command.Parameters.AddWithValue(parameter.Name, parameterValue.Identity.ToByteArray()); } } else { command.Parameters.AddWithValue(parameter.Name, parameter.Value); } } } using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Dictionary <string, object> item = new Dictionary <string, object>(); foreach (KeyValuePair <string, PropertyReferenceManager> pm in propertyManagers) { manager = pm.Value; string name = pm.Key; object value = manager.GetValue(reader); item.Add(pm.Key, value); } result.Add(item); } } } return(result); }
private void SetupValueView() { ParameterExpression model = this.Model as ParameterExpression; if (model == null) { this.ValueView = null; return; } if (this.Type == null) { this.ValueView = null; return; } if (this.Type == Entity.Int32 || this.Type == Entity.Decimal || this.Type == Entity.String) { SetupTextBoxView(); } else if (this.Type == Entity.Boolean) { SetupCheckBoxView(); } else if (this.Type == Entity.DateTime) { SetupDatePickerView(); } else if (this.Value == null) { TextBlock view = new TextBlock(); view.Text = this.Type.FullName; this.ValueView = view; } else { ReferenceProxy proxy = this.Value as ReferenceProxy; TextBlock view = new TextBlock(); view.Text = proxy.ToString(); view.ToolTip = proxy.Type.FullName; this.ValueView = view; } }
private object TranslateComplexType(IDataReader reader) { byte[] buffer; object value; int typeCode = -1; if (purposes.TryGetValue(FieldPurpose.TypeCode, out typeCode)) { value = reader[typeCode]; if (value is int) { typeCode = (int)value; } else { buffer = (byte[])value; typeCode = BitConverter.ToInt32(buffer, 0); } } if (typeCode > 0) // ReferenceObject { Relation relation = property.Property.Relations.Where(r => r.Entity.Code == typeCode).FirstOrDefault(); if (relation == null) { return(null); // unsupported value type for this property } int index = -1; if (!purposes.TryGetValue(FieldPurpose.Object, out index)) { index = purposes[FieldPurpose.Value]; } Guid identity = Guid.Empty; value = reader[index]; if (value is Guid) { identity = (Guid)value; } else { buffer = (byte[])reader[index]; identity = new Guid(buffer); } return(new ReferenceProxy(relation.Entity, identity)); } // primitive types int locator = purposes[FieldPurpose.Locator]; buffer = (byte[])reader[locator]; locator = buffer[0]; value = null; if (locator == 1) // Неопределено { return(null); } else if (locator == 2) // Булево { value = ((byte[])reader[purposes[FieldPurpose.Boolean]])[0] == 0 ? false : true; } else if (locator == 3) // Число { value = (decimal)reader[purposes[FieldPurpose.Number]]; } else if (locator == 4) // Дата { value = reader.GetDateTime(purposes[FieldPurpose.DateTime]); } else if (locator == 5) // Строка { value = (string)reader[purposes[FieldPurpose.String]]; } else if (locator == 8) // Ссылка { Relation relation = property.Property.Relations.Where(r => r.Entity.Code == typeCode).FirstOrDefault(); if (relation == null) { return(null); // unsupported value type for this property } buffer = (byte[])reader[purposes[FieldPurpose.Object]]; Guid identity = new Guid(buffer); value = new ReferenceProxy(relation.Entity, identity); } else { return(null); } return(value); }