Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="Epi.Fields.DateColumn"/> in <see cref="Epi.Fields.GridField"/>.
        /// </summary>
        /// <param name="column"><see cref="Epi.Fields.DateColumn"/></param>
        /// <returns>Id of the newly created column.</returns>
        public int CreateGridColumn(ContiguousColumn column)
        {
            try
            {
                Query insertQuery = db.CreateQuery("insert into metaGridColumns([Name], [Width], [Position], [FieldTypeId], [Text], [ShouldRepeatLast], [IsRequired], [IsReadOnly], [Pattern], [Upper], [Lower], [FieldId]) " +
                    "values (@Name, @Width, @Position, @FieldTypeId, @Text, @ShouldRepeatLast, @IsRequired, @IsReadOnly, @Pattern, @Upper, @Lower, @FieldId)");

                insertQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, column.Name));
                insertQuery.Parameters.Add(new QueryParameter("@Width", DbType.Int32, column.Width));
                insertQuery.Parameters.Add(new QueryParameter("@Position", DbType.Int32, column.Position));
                insertQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)column.GridColumnType));
                insertQuery.Parameters.Add(new QueryParameter("@Text", DbType.String, column.Text));
                insertQuery.Parameters.Add(new QueryParameter("@ShouldRepeatLast", DbType.Boolean, column.ShouldRepeatLast));
                insertQuery.Parameters.Add(new QueryParameter("@IsRequired", DbType.Boolean, column.IsRequired));
                insertQuery.Parameters.Add(new QueryParameter("@IsReadOnly", DbType.Boolean, column.IsReadOnly));
                if (column.Pattern == null)
                {
                    insertQuery.Parameters.Add(new QueryParameter("@Pattern", DbType.String, DBNull.Value));
                }
                else
                {
                    insertQuery.Parameters.Add(new QueryParameter("@Pattern", DbType.String, column.Pattern));
                }
                if (column.Upper == null)
                {
                    insertQuery.Parameters.Add(new QueryParameter("@Upper", DbType.String, DBNull.Value));
                }
                else
                {
                    insertQuery.Parameters.Add(new QueryParameter("@Upper", DbType.String, column.Upper));
                }
                if (column.Lower == null)
                {
                    insertQuery.Parameters.Add(new QueryParameter("@Lower", DbType.String, DBNull.Value));
                }
                else
                {
                    insertQuery.Parameters.Add(new QueryParameter("@Lower", DbType.String, column.Lower));
                }
                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
            {

            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates a date column saved in the database
        /// </summary>
        /// <param name="column">Column to be updated</param>
        public void UpdateGridColumn(ContiguousColumn column)
        {
            #region InputValidation
            if (column == null)
            {
                throw new ArgumentNullException("DateColumn");
            }
            #endregion
            try
            {
                Query updateQuery = db.CreateQuery("update [metaGridColumns] set [Name] = @Name, [Width] = @Width, [Position] = @Position, [FieldTypeId] = @FieldTypeId, [Text] = @Text, [ShouldRepeatLast] = @ShouldRepeatLast, [IsRequired] = @IsRequired, [IsReadOnly] = @IsReadOnly, [Pattern] = @Pattern, [Upper] = @Upper , [Lower] = @Lower " +
                    "where [GridColumnId] = @GridColumnId");

                updateQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, column.Name));
                updateQuery.Parameters.Add(new QueryParameter("@Width", DbType.Int32, column.Width));
                updateQuery.Parameters.Add(new QueryParameter("@Position", DbType.Int32, column.Position));
                updateQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)column.GridColumnType));
                updateQuery.Parameters.Add(new QueryParameter("@Text", DbType.String, column.Text));
                updateQuery.Parameters.Add(new QueryParameter("@ShouldRepeatLast", DbType.Boolean, column.ShouldRepeatLast));
                updateQuery.Parameters.Add(new QueryParameter("@IsRequired", DbType.Boolean, column.IsRequired));
                updateQuery.Parameters.Add(new QueryParameter("@IsReadOnly", DbType.Boolean, column.IsReadOnly));
                if (column.Pattern == null)
                {
                    updateQuery.Parameters.Add(new QueryParameter("@Pattern", DbType.String, DBNull.Value));
                }
                else
                {
                    updateQuery.Parameters.Add(new QueryParameter("@Pattern", DbType.String, column.Pattern));
                }
                if (column.Upper == null)
                {
                    updateQuery.Parameters.Add(new QueryParameter("@Upper", DbType.String, DBNull.Value));
                }
                else
                {
                    updateQuery.Parameters.Add(new QueryParameter("@Upper", DbType.String, column.Upper));
                }
                if (column.Lower == null)
                {
                    updateQuery.Parameters.Add(new QueryParameter("@Lower", DbType.String, DBNull.Value));
                }
                else
                {
                    updateQuery.Parameters.Add(new QueryParameter("@Lower", DbType.String, column.Lower));
                }
                updateQuery.Parameters.Add(new QueryParameter("@GridColumnId", DbType.Int32, column.Id));

                db.ExecuteNonQuery(updateQuery);

            }
            catch (Exception ex)
            {
                throw new GeneralException("Could not update grid column in the database", ex);
            }
            finally
            {

            }
        }
Exemplo n.º 3
0
        private void SetContiguousColumnProperties(ContiguousColumn contiguousColumn)
        {
            contiguousColumn.Name = txtFieldName.Text;
            contiguousColumn.Text = txtColumnName.Text;
            contiguousColumn.ShouldRepeatLast = cbxRepeatLast.Checked;
            contiguousColumn.IsRequired = cbxRequired.Checked;
            contiguousColumn.IsReadOnly = cbxReadOnly.Checked;
            contiguousColumn.Position = gridColumnsTable.Columns[txtFieldName.Text].Ordinal;
            contiguousColumn.Width = this.dgColumns.TableStyles["GridColumns"].PreferredColumnWidth;
            contiguousColumn.Pattern = cmbPattern.Text;

            if (cbxRange.Checked)
            {
                DateTime upper;
                DateTime lower;
                bool isValid = true;
                if (!DateTime.TryParse(txtLower.Text, out lower))
                {
                    isValid = false;
                    ErrorMessages.Add(SharedStrings.INVALID_LOWER_DATE_RANGE);
                }
                if (!DateTime.TryParse(txtUpper.Text, out upper))
                {
                    isValid = false;
                    ErrorMessages.Add(SharedStrings.INVALID_UPPER_DATE_RANGE);
                }
                if (isValid)
                {
                    if (lower.CompareTo(upper) > 0)
                    {
                        isValid = false;
                        ErrorMessages.Add(SharedStrings.UPPER_DATE_RANGE_IS_LOWER);
                    }
                }

                if (isValid)
                {
                    contiguousColumn.Lower = txtLower.Text;
                    contiguousColumn.Upper = txtUpper.Text;
                }
                else
                {
                    ShowErrorMessages();
                    //break;
                }
            }
            gridColumns.Add(contiguousColumn);
            SetColumnStyle(contiguousColumn);
        }