/// <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.UniqueRowIdColumn"/> in <see cref="Epi.Fields.GridField"/>.
        /// </summary>
        /// <param name="column"><see cref="Epi.Fields.UniqueRowIdColumn"/> to create.</param>
        /// <returns>Id of the newly created column.</returns>
        public int CreateGridColumn(UniqueRowIdColumn column)
        {
            try
            {
                #region InputValidation
                if (column == null)
                {
                    throw new ArgumentNullException("UniqueRowIdColumn");
                }
                #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 UniqueRowIdColumn grid column in the database.", ex);
            }
            finally
            {
            }
        }
Example #3
0
        /// <summary>
        /// Creates a new <see cref="Epi.Fields.GlobalRecordIdColumn"/> in <see cref="Epi.Fields.GridField"/>.
        /// </summary>
        /// <param name="column"><see cref="Epi.Fields.GlobalRecordId"/></param>
        /// <returns>Id of the newly created column.</returns>
        public int CreateGridColumn(UniqueRowIdColumn column)
        {
            try
            {
                #region InputValidation
                if (column == null)
                {
                    throw new ArgumentNullException("UniqueRowIdColumn");
                }
                #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 column in the database", ex);
            }
            finally
            {
            }
        }
        /// <summary>
        /// Creates a new <see cref="Epi.Fields.GlobalRecordIdColumn"/> in <see cref="Epi.Fields.GridField"/>.
        /// </summary>
        /// <param name="column"><see cref="Epi.Fields.GlobalRecordId"/></param>
        /// <returns>Id of the newly created column.</returns>
        public int CreateGridColumn(UniqueRowIdColumn column)
        {
            try
            {
                #region InputValidation
                if (column == null)
                {
                    throw new ArgumentNullException("UniqueRowIdColumn");
                }
                #endregion

                Query query = db.CreateQuery("select F.[FieldTypeId],  F.[Name],  F.[HasRepeatLast], F.[HasRequired], F.[HasReadOnly], F.[HasRetainImageSize],  F.[HasFont], F.[IsGridColumn], F.[IsDropDown] " +
                "from metaFieldTypes F " +
                "where [F.FieldTypeId]=@FieldTypeId");
                query.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)column.GridColumnType));
                DataTable dt = db.Select(query);
                if (dt.Rows.Count == 0)
                {
                    query = null;
                    query = db.CreateQuery("insert into metaFieldTypes ([FieldTypeId], [Name], [HasRepeatLast], [HasRequired], [HasReadOnly], [HasRetainImageSize], [HasFont], [IsDropDown], [IsGridColumn], [DataTypeId], [IsSystem],DefaultPatternId) values (@FieldTypeId, @Name, @HasRepeatLast, @HasRequired, @HasReadOnly, @HasRetainImageSize, @HasFont, @IsDropDown, @IsGridColumn, @DataTypeId, @IsSystem,@DefaultPatternId)");
                    query.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)column.GridColumnType));
                    query.Parameters.Add(new QueryParameter("@Name", DbType.String, column.Name));
                    query.Parameters.Add(new QueryParameter("@HasRepeatLast", DbType.Boolean, false));
                    query.Parameters.Add(new QueryParameter("@HasRequired", DbType.Boolean, false));
                    query.Parameters.Add(new QueryParameter("@HasReadOnly", DbType.Boolean, false));
                    query.Parameters.Add(new QueryParameter("@HasRetainImageSize", DbType.Boolean, false));
                    query.Parameters.Add(new QueryParameter("@HasFont", DbType.Boolean, false));
                    query.Parameters.Add(new QueryParameter("@IsDropDown", DbType.Boolean, false));
                    query.Parameters.Add(new QueryParameter("@IsGridColumn", DbType.Boolean, false));
                    query.Parameters.Add(new QueryParameter("@DataTypeId", DbType.Int32, 1));
                    query.Parameters.Add(new QueryParameter("@IsSystem", DbType.Boolean, true));
                    query.Parameters.Add(new QueryParameter("@DefaultPatternId", DbType.Int32, 0));
                    db.ExecuteNonQuery(query);
                }
                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 column in the database", ex);
            }
            finally
            {
            }
        }