/// <summary> /// Creates a new <see cref="Epi.Fields.ForeignKeyColumn"/> in <see cref="Epi.Fields.GridField"/>. /// </summary> /// <param name="column"><see cref="Epi.Fields.ForeignKeyColumn"/></param> /// <returns>Id of the newly created ForeignKey column.</returns> public int CreateGridColumn(ForeignKeyColumn column) { try { #region InputValidation if (column == null) { throw new ArgumentNullException("UniqueKeyColumn"); } #endregion Query insertQuery = db.CreateQuery("insert into metaGridColumns([Name], [FieldTypeId], [Width], [Size], [Position], [Text], [ShouldRepeatLast], [IsRequired], [IsReadOnly], [FieldId]) " + "values (@Name, @FieldTypeId, @Width, @Size, @Position, @Text, @ShouldRepeatLast, @IsRequired, @IsReadOnly, @FieldId)"); insertQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, column.Name)); insertQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)column.GridColumnType)); insertQuery.Parameters.Add(new QueryParameter("@Width", DbType.Int32, 0)); insertQuery.Parameters.Add(new QueryParameter("@Size", DbType.Int32, 0)); insertQuery.Parameters.Add(new QueryParameter("@Position", DbType.Int32, 0)); insertQuery.Parameters.Add(new QueryParameter("@Text", DbType.String, string.Empty)); insertQuery.Parameters.Add(new QueryParameter("@ShouldRepeatLast", DbType.Boolean, false)); insertQuery.Parameters.Add(new QueryParameter("@IsRequired", DbType.Boolean, false)); insertQuery.Parameters.Add(new QueryParameter("@IsReadOnly", DbType.Boolean, true)); insertQuery.Parameters.Add(new QueryParameter("@FieldId", DbType.Int32, column.Grid.Id)); db.ExecuteNonQuery(insertQuery); return GetMaxGridColumnId(column.Grid.Id); } catch (Exception ex) { throw new GeneralException("Could not create grid ForeignKey column in the database", ex); } finally { } }
/// <summary> /// Sets the field's properties based on GUI values /// </summary> protected override void SetFieldProperties() { field.PromptText = txtPrompt.Text; field.Name = txtFieldName.Text; if (field.Columns == null) { field.Columns = new List<GridColumnBase>(); //UniqueKeyColumn uniqueKeyColumn = new UniqueKeyColumn(field); UniqueRowIdColumn uniqueRowIdColumn = new UniqueRowIdColumn(field); RecStatusColumn recStatusColumn = new RecStatusColumn(field); ForeignKeyColumn foreignKeyColumn = new ForeignKeyColumn(field); GlobalRecordIdColumn globalRecordIdColumn = new GlobalRecordIdColumn(field); field.Columns.AddRange (new List<GridColumnBase> { //uniqueKeyColumn, uniqueRowIdColumn, recStatusColumn, foreignKeyColumn, globalRecordIdColumn }); } }
/// <summary> /// Creates a new <see cref="Epi.Fields.ForeignKeyColumn"/> in <see cref="Epi.Fields.GridField"/>. /// </summary> /// <param name="column"><see cref="Epi.Fields.ForeignKeyColumn"/> to create.</param> /// <returns>Id of the newly created column.</returns> public int CreateGridColumn(ForeignKeyColumn column) { try { #region InputValidation if (column == null) { throw new ArgumentNullException("ForeignKeyColumn"); } #endregion Query insertQuery = db.CreateQuery("insert into metaGridColumns([Name], [FieldTypeId]) " + "values (@Name, @FieldTypeId,)"); insertQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, column.Name)); insertQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)column.GridColumnType)); db.ExecuteNonQuery(insertQuery); return GetMaxGridColumnId(column.Grid.Id); } catch (Exception ex) { throw new GeneralException("Could not create ForeignKey grid column in the database.", ex); } finally { } }