public GridField Clone() { GridField clone = (GridField)this.MemberwiseClone(); base.AssignMembers(clone); return(clone); }
/// <summary> /// Constructor for Grid Columns Dialog /// </summary> /// <param name="frm">The main form</param> /// <param name="fieldPage">The page containing the field</param> /// <param name="gridField">The grid's field</param> /// <param name="patternsDataView">The data view</param> /// <param name="formMode">The form mode</param> /// <param name="tempColumns">Temporary Columns</param> public GridColumnsDialog(MainForm frm, Page fieldPage, Epi.Fields.GridField gridField, DataView patternsDataView, FormMode formMode, List<GridColumnBase> tempColumns) : base(frm) { InitializeComponent(); page = fieldPage; grid = gridField; patterns = patternsDataView; mode = formMode; form = frm; gridColumns = tempColumns; }
/// <summary> /// Constructor of the Grid Field Definition /// </summary> /// <param name="frm">The main form</param> /// <param name="field">A grid field</param> public GridFieldDefinition(MainForm frm, GridField field) : base(frm) { InitializeComponent(); this.mode = FormMode.Edit; this.field = field; this.page = field.Page; Configuration config = Configuration.GetNewInstance(); FontStyle style = FontStyle.Regular; if (config.Settings.EditorFontBold) { style |= FontStyle.Bold; } if (config.Settings.EditorFontItalics) { style |= FontStyle.Italic; } if ((field.PromptFont == null) || ((field.PromptFont.Name == "Microsoft Sans Serif") && (field.PromptFont.Size == 8.5))) { field.PromptFont = new Font(config.Settings.EditorFontName, (float)config.Settings.EditorFontSize, style); } style = FontStyle.Regular; if (config.Settings.ControlFontBold) { style |= FontStyle.Bold; } if (config.Settings.ControlFontItalics) { style |= FontStyle.Italic; } field.ControlFont = new Font(config.Settings.ControlFontName, (float)config.Settings.ControlFontSize, style); txtPrompt.Font = field.PromptFont; promptFont = field.PromptFont; controlFont = field.PromptFont; field.ControlFont = field.PromptFont; dgColumns.Font = field.PromptFont; dgColumns.HeaderFont = field.PromptFont; if (Util.IsEmpty(gridColumns)) { if (field.Columns != null) { gridColumns = new List<GridColumnBase>(field.Columns); } } if (!this.field.Id.Equals(0)) { LoadFormData(); } }
private void UnMarkRelatedRecoredsAsDeleted(Epi.Data.Services.CollectedDataProvider OutputDriver, View pView, List <int> pIDList) { if (pIDList.Count < 1) { return; } Dictionary <string, bool> VisitedViews = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase); string SQL = null; StringBuilder InSQL = new StringBuilder(); InSQL.Append(" Where FKey In ("); foreach (int ID in pIDList) { pView.LoadRecord(ID); pView.RecStatusField.CurrentRecordValue = 1; pView.SaveRecord(ID); InSQL.Append("'"); InSQL.Append(pView.CurrentGlobalRecordId); InSQL.Append("',"); } InSQL.Length = InSQL.Length - 1; InSQL.Append(")"); foreach (Field field in pView.Fields) { if (field is RelatedViewField) { RelatedViewField rvf = field as RelatedViewField; if (!VisitedViews.ContainsKey(rvf.ChildView.Name)) { SQL = "Select UniqueKey From [" + rvf.ChildView.TableName + "] " + InSQL.ToString(); IDataReader reader = OutputDriver.ExecuteReader(OutputDriver.CreateQuery(SQL)); List <int> NewIdList = new List <int>(); while (reader.Read()) { if (reader["UniqueKey"] != DBNull.Value) { NewIdList.Add((int)reader["UniqueKey"]); } } VisitedViews.Add(rvf.ChildView.Name, true); UnMarkRelatedRecoredsAsDeleted(OutputDriver, rvf.ChildView, NewIdList); } else if (field is Epi.Fields.GridField) { Epi.Fields.GridField gf = field as Epi.Fields.GridField; SQL = "Update [" + gf.TableName + "] Set RecStatus = 1 Where FKey In " + InSQL.ToString(); OutputDriver.ExecuteNonQuery(OutputDriver.CreateQuery(SQL)); } } } }
/// <summary> /// Constructor /// </summary> /// <param name="gridRow">DataRow of column attributes</param> /// <param name="grid">Grid Field that contains Dropdown column.</param> public TableBasedDropDownColumn(DataRow gridDataRow, GridField gridField) : base(gridDataRow, gridField) { tableName = gridDataRow[ColumnNames.DATA_TABLE_NAME].ToString(); if (gridDataRow[ColumnNames.IS_EXCLUSIVE_TABLE] != null && gridDataRow[ColumnNames.IS_EXCLUSIVE_TABLE] != DBNull.Value) { isExclusiveTable = (bool)gridDataRow[ColumnNames.IS_EXCLUSIVE_TABLE]; } sourceTableName = gridDataRow[ColumnNames.SOURCE_TABLE_NAME].ToString(); textColumnName = gridDataRow[ColumnNames.TEXT_COLUMN_NAME].ToString(); if (gridDataRow[ColumnNames.CODE_COLUMN_NAME] != null) { codeColumnName = gridDataRow[ColumnNames.CODE_COLUMN_NAME].ToString(); } if (gridDataRow[ColumnNames.SORT] != null && gridDataRow[ColumnNames.SORT] != DBNull.Value) { shouldSort = (bool)gridDataRow[ColumnNames.SORT]; } }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField that the row belongs to</param> public GridColumnBase(DataRow gridRow, GridField grid) { this.id = (int)gridRow[ColumnNames.GRID_COLUMN_ID]; this.name = gridRow[ColumnNames.NAME].ToString(); this.text = gridRow[ColumnNames.TEXT].ToString(); this.shouldRepeatLast = (bool)gridRow[ColumnNames.SHOULD_REPEAT_LAST]; this.isRequired = (bool)gridRow[ColumnNames.IS_REQUIRED]; this.isReadOnly = (bool)gridRow[ColumnNames.IS_READ_ONLY]; if (gridRow.Table.Columns.Contains(ColumnNames.IS_UNIQUE_FIELD) && gridRow[ColumnNames.IS_UNIQUE_FIELD] is bool) { this.isUniqueField = (bool)gridRow[ColumnNames.IS_UNIQUE_FIELD]; } else { this.isUniqueField = false; } this.position = (short)gridRow[ColumnNames.POSITION]; this.width = int.Parse(gridRow["Width"].ToString()); this.grid = grid; }
/// <summary> /// /// </summary> /// <param name="field"></param> /// <returns></returns> public List<GridColumnBase> GetGridColumnCollection(GridField field) { List<GridColumnBase> columns = new List<GridColumnBase>(); DataTable table = GetGridColumns(field.Id); foreach (DataRow row in table.Rows) { switch ((MetaFieldType)row["FieldTypeId"]) { case MetaFieldType.GlobalRecordId: columns.Add(new GlobalRecordIdColumn(row, field)); break; case MetaFieldType.UniqueKey: columns.Add(new UniqueKeyColumn(row, field)); break; case MetaFieldType.UniqueRowId: columns.Add(new UniqueRowIdColumn(row, field)); break; case MetaFieldType.RecStatus: columns.Add(new RecStatusColumn(row, field)); break; case MetaFieldType.ForeignKey: columns.Add(new ForeignKeyColumn(row, field)); break; case MetaFieldType.Text: columns.Add(new TextColumn(row, field)); break; case MetaFieldType.Number: columns.Add(new NumberColumn(row, field)); break; case MetaFieldType.PhoneNumber: columns.Add(new PhoneNumberColumn(row, field)); break; case MetaFieldType.Date: columns.Add(new DateColumn(row, field)); break; case MetaFieldType.CommentLegal: columns.Add(new DDLColumnOfCommentLegal(row, field)); break; case MetaFieldType.LegalValues: columns.Add(new DDLColumnOfLegalValues(row, field)); break; default: break; } } return columns; }
/// <summary> /// Retrieves data for grid field from xml metadata. /// </summary> /// <param name="field">A grid field.</param> /// <param name="fieldNode">XML node for grid field.</param> public void GetFieldData(GridField field, XmlNode fieldNode) { }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public DDLColumnOfLegalValues(DataRow gridRow, GridField grid) : base(gridRow, grid) { construct(); }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public TextColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { construct(); this.size = (short)gridRow["Size"]; }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public UniqueRowIdColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { Construct(); }
/// <summary> /// Constructor for the class. Instantiates a grid field. /// </summary> /// <param name="grid">Grid field object.</param> public ForeignKeyColumn(GridField grid) : base(grid) { Construct(); }
/// <summary> /// Constructor for the class /// </summary> public PredefinedColumn(GridField grid) : base(grid) { }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The grid that contains the gridrow</param> public PatternableColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { this.pattern = gridRow[ColumnNames.PATTERN].ToString(); }
/// <summary> /// Constructor for the class /// </summary> public PatternableColumn(GridField grid) : base(grid) { }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public DDLColumnOfCommentLegal(DataRow gridRow, GridField grid) : base(gridRow, grid) { this.GridColumnType = MetaFieldType.CommentLegal; }
/// <summary> /// Constructor for the class. Instantiates a grid field. /// </summary> /// <param name="grid">Grid field object.</param> public GlobalRecordIdColumn(GridField grid) : base(grid) { Construct(); }
/// <summary> /// Constructor for the class. /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public ForeignKeyColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { Construct(); }
/// <summary> /// Constructor for the class /// </summary> public TextColumn(GridField grid) : base(grid) { construct(); }
/// <summary> /// Constructor /// </summary> /// <param name="grid">Grid Field that contains Dropdown column.</param> public TableBasedDropDownColumn(GridField gridField) : base(gridField) { }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The grid that contains the gridrow</param> public PredefinedColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { }
/// <summary> /// Constructor for the class /// </summary> public ContiguousColumn(GridField grid) : base(grid) { }
/// <summary> /// Constructor for the class /// </summary> public DateColumn(GridField grid) : base(grid) { Construct(); }
/// <summary> /// Constructor for the Phone Number Column class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The grid that contains the gridrow</param> public PhoneNumberColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { construct(); }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The grid that contains the DataRow</param> public DateColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { Construct(); }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The grid that contains the gridrow</param> public ContiguousColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { this.lower = gridRow[ColumnNames.LOWER].ToString(); this.upper = gridRow[ColumnNames.UPPER].ToString(); }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public RecStatusColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { construct(); }
/// <summary> /// Constructor for the class /// </summary> public YesNoColumn(GridField grid) : base(grid) { construct(); }
/// <summary> /// Insert a GridField record into the metaFields table. /// </summary> /// <param name="field">Grid field.</param> /// <returns>Returns the Id of the last GridField added.</returns> public int CreateField(GridField field) { try { #region InputValidation if (field == null) { throw new ArgumentNullException("GridField"); } #endregion Query insertQuery = db.CreateQuery("insert into metaFields([ViewId], [UniqueId], [ControlFontFamily], [ControlFontStyle], [ControlFontSize], [ControlHeightPercentage], [ControlLeftPositionPercentage], [ControlTopPositionPercentage], [ControlWidthPercentage], [FieldTypeId], [HasTabStop], [Name], [PageId], [PromptFontFamily], [PromptFontStyle], [PromptFontSize], [PromptText], [PromptLeftPositionPercentage], [PromptTopPositionPercentage], [TabIndex]) " + "values (@ViewId, @UniqueId, @ControlFontFamily, @ControlFontStyle, @ControlFontSize, @ControlHeightPercentage, @ControlLeftPositionPercentage, @ControlTopPositionPercentage, @ControlWidthPercentage, @FieldTypeId, @HasTabStop, @Name, @PageId, @PromptFontFamily, @PromptFontStyle, @PromptFontSize, @PromptText,@PromptLeftPositionPercentage, @PromptTopPositionPercentage, @TabIndex)"); insertQuery.Parameters.Add(new QueryParameter("@ViewId", DbType.Int32, field.GetView().Id)); insertQuery.Parameters.Add(new QueryParameter("@UniqueId", DbType.Guid, field.UniqueId)); insertQuery.Parameters.Add(new QueryParameter("@ControlFontFamily", DbType.String, field.ControlFont.Name)); insertQuery.Parameters.Add(new QueryParameter("@ControlFontStyle", DbType.String, field.ControlFont.Style.ToString())); insertQuery.Parameters.Add(new QueryParameter("@ControlFontSize", DbType.Double, field.ControlFont.Size)); insertQuery.Parameters.Add(new QueryParameter("@ControlHeightPercentage", DbType.Double, field.ControlHeightPercentage)); insertQuery.Parameters.Add(new QueryParameter("@ControlLeftPositionPercentage", DbType.Double, field.ControlLeftPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@ControlTopPositionPercentage", DbType.Double, field.ControlTopPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@ControlWidthPercentage", DbType.Double, field.ControlWidthPercentage)); insertQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)field.FieldType)); insertQuery.Parameters.Add(new QueryParameter("@HasTabStop", DbType.Boolean, field.HasTabStop)); insertQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, field.Name)); insertQuery.Parameters.Add(new QueryParameter("@PageId", DbType.Int32, field.Page.Id)); insertQuery.Parameters.Add(new QueryParameter("@PromptFontFamily", DbType.String, field.PromptFont.Name)); insertQuery.Parameters.Add(new QueryParameter("@PromptFontStyle", DbType.String, field.PromptFont.Style.ToString())); insertQuery.Parameters.Add(new QueryParameter("@PromptFontSize", DbType.Double, field.PromptFont.Size)); insertQuery.Parameters.Add(new QueryParameter("@PromptText", DbType.String, field.PromptText)); insertQuery.Parameters.Add(new QueryParameter("@PromptLeftPositionPercentage", DbType.Double, field.PromptLeftPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@PromptTopPositionPercentage", DbType.Double, field.PromptTopPositionPercentage)); insertQuery.Parameters.Add(new QueryParameter("@TabIndex", DbType.Int32, field.TabIndex)); db.ExecuteNonQuery(insertQuery); return GetMaxFieldId(field.GetView().Id); } catch (Exception ex) { throw new GeneralException("Could not create field in the database", ex); } finally { } }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public YesNoColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { construct(); }
/// <summary> /// Gets all the fields in a view /// </summary> /// <param name="view">A view object</param> /// <returns>A collection of fields</returns> public virtual FieldCollectionMaster GetFields(View view) { FieldCollectionMaster fields = new FieldCollectionMaster(); try { DataTable table = GetFieldsAsDataTable(view); foreach (DataRow row in table.Rows) { MetaFieldType fieldTypeId = (MetaFieldType)row[ColumnNames.FIELD_TYPE_ID]; Field field = null; switch (fieldTypeId) { case MetaFieldType.Text: field = new SingleLineTextField(view); field.LoadFromRow(row); break; case MetaFieldType.LabelTitle: field = new LabelField(view); field.LoadFromRow(row); break; case MetaFieldType.TextUppercase: field = new UpperCaseTextField(view); field.LoadFromRow(row); break; case MetaFieldType.Multiline: field = new MultilineTextField(view); field.LoadFromRow(row); break; case MetaFieldType.Number: field = new NumberField(view); field.LoadFromRow(row); break; case MetaFieldType.PhoneNumber: field = new PhoneNumberField(view); field.LoadFromRow(row); break; case MetaFieldType.Date: field = new DateField(view); field.LoadFromRow(row); break; case MetaFieldType.Time: field = new TimeField(view); field.LoadFromRow(row); break; case MetaFieldType.DateTime: field = new DateTimeField(view); field.LoadFromRow(row); break; case MetaFieldType.Checkbox: field = new CheckBoxField(view); field.LoadFromRow(row); break; case MetaFieldType.YesNo: field = new YesNoField(view); field.LoadFromRow(row); break; case MetaFieldType.Option: field = new OptionField(view); field.LoadFromRow(row); break; case MetaFieldType.CommandButton: field = new CommandButtonField(view); field.LoadFromRow(row); break; case MetaFieldType.Image: field = new ImageField(view); field.LoadFromRow(row); break; case MetaFieldType.Mirror: field = new MirrorField(view); field.LoadFromRow(row); break; case MetaFieldType.Grid: field = new GridField(view); field.LoadFromRow(row); break; case MetaFieldType.Group: field = new GroupField(view); field.LoadFromRow(row); break; case MetaFieldType.GUID: field = new GUIDField(view); field.LoadFromRow(row); break; case MetaFieldType.LegalValues: field = new DDLFieldOfLegalValues(view); field.LoadFromRow(row); break; case MetaFieldType.Codes: field = new DDLFieldOfCodes(view); ((DDLFieldOfCodes)field).LoadFromRow(row); //zack break; case MetaFieldType.List: field = new DDListField(view); ((DDListField)field).LoadFromRow(row); break; case MetaFieldType.CommentLegal: field = new DDLFieldOfCommentLegal(view); field.LoadFromRow(row); break; case MetaFieldType.Relate: field = new RelatedViewField(view); field.LoadFromRow(row); break; case MetaFieldType.RecStatus: field = new RecStatusField(view); field.LoadFromRow(row); break; case MetaFieldType.UniqueKey: field = new UniqueKeyField(view); field.LoadFromRow(row); break; case MetaFieldType.ForeignKey: field = new ForeignKeyField(view); field.LoadFromRow(row); break; case MetaFieldType.GlobalRecordId: field = new GlobalRecordIdField(view); field.LoadFromRow(row); break; default: throw new ApplicationException("Invalid Field Type"); } // Note: This check ideally shouldn't be necessary, but Epi 3.5.1 and previous versions actually do allow duplicate field names for group fields. if (fields.Contains(field)) { Logger.Log(DateTime.Now + ": " + string.Format("The {0} field with name \"{1}\" already exists in {2}. This field has not been imported.", field.GetType().ToString(), field.Name, view.Name)); } else { fields.Add(field); } } } catch (Exception ex) { } return (fields); }
/// <summary> /// Update Grid field. /// </summary> /// <param name="field">Grid field to update.</param> public void UpdateField(GridField field) { try { #region InputValidation if (field == null) { throw new ArgumentNullException("GridField"); } #endregion Query updateQuery = db.CreateQuery("update metaFields set [ControlFontFamily] = @ControlFontFamily, " + "[ControlFontStyle] = @ControlFontStyle, [ControlFontSize] = @ControlFontSize, [ControlHeightPercentage] = @ControlHeightPercentage, " + "[ControlLeftPositionPercentage] = @ControlLeftPositionPercentage, [ControlTopPositionPercentage] = @ControlTopPositionPercentage, " + "[ControlWidthPercentage] = @ControlWidthPercentage, [FieldTypeId] = @FieldTypeId, [HasTabStop] = @HasTabStop, [Name] = @Name, " + "[PageId] = @PageId, [PromptFontFamily] = @PromptFontFamily, [PromptFontStyle] = @PromptFontStyle, [PromptFontSize] = @PromptFontSize, " + "[PromptLeftPositionPercentage] = @PromptLeftPositionPercentage, " + "[PromptTopPositionPercentage] = @PromptTopPositionPercentage, " + "[PromptText] = @PromptText, " + "[TabIndex] = @TabIndex where [UniqueId] = @UniqueId"); updateQuery.Parameters.Add(new QueryParameter("@ControlFontFamily", DbType.String, field.ControlFont.Name)); updateQuery.Parameters.Add(new QueryParameter("@ControlFontStyle", DbType.String, field.ControlFont.Style.ToString())); updateQuery.Parameters.Add(new QueryParameter("@ControlFontSize", DbType.Double, field.ControlFont.Size)); updateQuery.Parameters.Add(new QueryParameter("@ControlHeightPercentage", DbType.Double, field.ControlHeightPercentage)); updateQuery.Parameters.Add(new QueryParameter("@ControlLeftPositionPercentage", DbType.Double, field.ControlLeftPositionPercentage)); updateQuery.Parameters.Add(new QueryParameter("@ControlTopPositionPercentage", DbType.Double, field.ControlTopPositionPercentage)); updateQuery.Parameters.Add(new QueryParameter("@ControlWidthPercentage", DbType.Double, field.ControlWidthPercentage)); updateQuery.Parameters.Add(new QueryParameter("@FieldTypeId", DbType.Int32, (int)field.FieldType)); updateQuery.Parameters.Add(new QueryParameter("@HasTabStop", DbType.Boolean, field.HasTabStop)); updateQuery.Parameters.Add(new QueryParameter("@Name", DbType.String, field.Name)); updateQuery.Parameters.Add(new QueryParameter("@PageId", DbType.Int32, field.Page.Id)); updateQuery.Parameters.Add(new QueryParameter("@PromptFontFamily", DbType.String, field.PromptFont.Name)); updateQuery.Parameters.Add(new QueryParameter("@PromptFontStyle", DbType.String, field.PromptFont.Style.ToString())); updateQuery.Parameters.Add(new QueryParameter("@PromptFontSize", DbType.Double, field.PromptFont.Size)); updateQuery.Parameters.Add(new QueryParameter("@PromptLeftPositionPercentage", DbType.Double, field.PromptLeftPositionPercentage)); updateQuery.Parameters.Add(new QueryParameter("@PromptTopPositionPercentage", DbType.Double, field.PromptTopPositionPercentage)); updateQuery.Parameters.Add(new QueryParameter("@PromptText", DbType.String, field.PromptText)); updateQuery.Parameters.Add(new QueryParameter("@TabIndex", DbType.Int32, field.TabIndex)); updateQuery.Parameters.Add(new QueryParameter("@UniqueId", DbType.Guid, field.UniqueId)); db.ExecuteNonQuery(updateQuery); } catch (Exception ex) { throw new GeneralException("Could not update GridField in the database", ex); } finally { } }
private List<Control> GetControls(GridField gridField, Size canvasSize) { DataGridView gridView = new DataGridView(); gridView.AutoGenerateColumns = false; gridView.Width = 160; gridView.Height = 150; SetControlProperties(gridView, gridField, canvasSize); gridView.TabStop = false; gridView.BorderStyle = borderStyle; gridView.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; gridView.EnableHeadersVisualStyles = true; gridView.ColumnHeadersDefaultCellStyle.Font = gridField.PromptFont; RectangleF rectF = new RectangleF(gridView.Left, gridView.Top, gridView.Width, ((float)1.75 * (int)gridField.PromptFont.Size)); gridView.Top = WinUtil.GetControlTop(gridField, canvasSize.Height); List<GridColumnBase> columns = new List<GridColumnBase>(gridField.Columns); columns.Sort(Util.SortByPosition); foreach (GridColumnBase gridCol in columns) { if (gridCol is TableBasedDropDownColumn) { DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn(); try { comboBoxColumn.MinimumWidth = 25; comboBoxColumn.Name = gridCol.Name; comboBoxColumn.DataPropertyName = gridCol.Name; comboBoxColumn.HeaderText = gridCol.Text; comboBoxColumn.ReadOnly = gridCol.IsReadOnly; comboBoxColumn.Width = gridCol.Width; comboBoxColumn.FlatStyle = FlatStyle.Flat; comboBoxColumn.Tag = gridCol; string displayMember = ((TableBasedDropDownColumn)gridCol).TextColumnName.Trim(); if (gridCol is YesNoColumn) { DataTable dataTable = new DataTable(); dataTable.Columns.Add("name", typeof(string)); dataTable.Columns.Add("value", typeof(byte)); DataRow dataRow; dataRow = dataTable.NewRow(); dataRow["name"] = config.Settings.RepresentationOfYes; dataRow["value"] = Constants.YES; dataTable.Rows.Add(dataRow); dataRow = dataTable.NewRow(); dataRow["name"] = config.Settings.RepresentationOfNo; dataRow["value"] = Constants.NO; dataTable.Rows.Add(dataRow); dataRow = dataTable.NewRow(); dataRow["name"] = config.Settings.RepresentationOfMissing; dataRow["value"] = DBNull.Value; dataTable.Rows.Add(dataRow); comboBoxColumn.ValueMember = "value"; comboBoxColumn.DisplayMember = "name"; comboBoxColumn.DataSource = dataTable; } else { if (!displayMember.Equals(string.Empty)) { comboBoxColumn.DisplayMember = displayMember; comboBoxColumn.ValueMember = displayMember; if (((TableBasedDropDownColumn)gridCol).ShouldSort) { DataTable dataTable = ((TableBasedDropDownColumn)gridCol).GetSourceData(); dataTable.Select(null, dataTable.Columns[0].ColumnName); comboBoxColumn.DataSource = dataTable; } else { comboBoxColumn.DataSource = ((TableBasedDropDownColumn)gridCol).GetSourceData(); } } } } catch (InvalidOperationException ioEx) { MsgBox.ShowException(ioEx); } gridView.Columns.Add(comboBoxColumn); } else if (gridCol is PatternableColumn) { bool isTimeBasedColumn = false; if (gridCol is DateColumn || gridCol is DateTimeColumn || gridCol is TimeColumn) { isTimeBasedColumn = true; } MaskedTextBoxColumn maskedTextBoxColumn = new MaskedTextBoxColumn(); maskedTextBoxColumn.MinimumWidth = 25; if (isTimeBasedColumn == false) { maskedTextBoxColumn.Mask = AppData.Instance.DataPatternsDataTable.GetMaskByPattern(((PatternableColumn)gridCol).Pattern); } maskedTextBoxColumn.HidePromptOnLeave = DataGridViewTriState.True; maskedTextBoxColumn.Name = gridCol.Name; maskedTextBoxColumn.HeaderText = gridCol.Text; maskedTextBoxColumn.ReadOnly = gridCol.IsReadOnly; maskedTextBoxColumn.Width = gridCol.Width; maskedTextBoxColumn.GridColumn = ((PatternableColumn)gridCol); maskedTextBoxColumn.DataPropertyName = gridCol.Name; if (isTimeBasedColumn == false) { maskedTextBoxColumn.DefaultCellStyle.Format = AppData.Instance.DataPatternsDataTable.GetExpressionByMask(maskedTextBoxColumn.Mask, ((PatternableColumn)gridCol).Pattern); } System.Globalization.DateTimeFormatInfo formatInfo = System.Globalization.DateTimeFormatInfo.CurrentInfo; if (gridCol is DateColumn) { ((System.Windows.Forms.DataGridViewColumn)(maskedTextBoxColumn)).DefaultCellStyle.Format = formatInfo.ShortDatePattern; } else if (gridCol is TimeColumn) { ((System.Windows.Forms.DataGridViewColumn)(maskedTextBoxColumn)).DefaultCellStyle.Format = formatInfo.ShortTimePattern; } gridView.Columns.Add(maskedTextBoxColumn); } else if (gridCol is CheckboxColumn) { DataGridViewColumn column = new DataGridViewCheckBoxColumn(); try { column.MinimumWidth = 25; column.Name = gridCol.Name; column.HeaderText = gridCol.Text; column.ReadOnly = gridCol.IsReadOnly; column.DataPropertyName = gridCol.Name; column.Width = gridCol.Width; } catch (InvalidOperationException ioEx) { MsgBox.ShowException(ioEx); } gridView.Columns.Add(column); } else { DataGridViewTextBoxColumn textBoxColumn = new DataGridViewTextBoxColumn(); try { textBoxColumn.MinimumWidth = 25; textBoxColumn.Name = gridCol.Name; textBoxColumn.HeaderText = gridCol.Text; textBoxColumn.ReadOnly = gridCol.IsReadOnly; textBoxColumn.DataPropertyName = gridCol.Name; if (gridCol is PredefinedColumn) { textBoxColumn.ReadOnly = true; } textBoxColumn.Width = gridCol.Width; if (gridCol is TextColumn) { textBoxColumn.MaxInputLength = ((TextColumn)gridCol).Size; } } catch (InvalidOperationException ioEx) { MsgBox.ShowException(ioEx); } gridView.Columns.Add(textBoxColumn); } } try { gridView.Columns[ColumnNames.REC_STATUS].ReadOnly = true; gridView.Columns[ColumnNames.REC_STATUS].Visible = false; gridView.Columns[ColumnNames.UNIQUE_ROW_ID].ReadOnly = true; gridView.Columns[ColumnNames.UNIQUE_ROW_ID].Visible = false; gridView.Columns[ColumnNames.FOREIGN_KEY].ReadOnly = true; gridView.Columns[ColumnNames.FOREIGN_KEY].Visible = false; if (gridView.Columns.Contains(ColumnNames.GLOBAL_RECORD_ID)) { gridView.Columns[ColumnNames.GLOBAL_RECORD_ID].ReadOnly = true; gridView.Columns[ColumnNames.GLOBAL_RECORD_ID].Visible = false; } gridView.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect; gridView.Tag = gridField; gridView.BackgroundColor = Color.White; gridView.RowHeadersVisible = false; gridView.MultiSelect = true; ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); ToolStripMenuItem deleteRowStripMenuItem = new ToolStripMenuItem(); contextMenuStrip.SuspendLayout(); deleteRowStripMenuItem.Name = "deleteRow"; deleteRowStripMenuItem.Text = "Delete Row"; deleteRowStripMenuItem.Image = global::Epi.Enter.Properties.Resources.delete_icon; deleteRowStripMenuItem.ImageTransparentColor = Color.White; deleteRowStripMenuItem.Tag = gridView; deleteRowStripMenuItem.Click += new EventHandler(deleteRowStripMenuItem_Click); contextMenuStrip.Items.Add(deleteRowStripMenuItem); contextMenuStrip.ResumeLayout(); gridView.ContextMenuStrip = contextMenuStrip; gridView.Refresh(); } catch (InvalidOperationException ioEx) { MsgBox.ShowException(ioEx); } catch (Exception ex) { MsgBox.ShowException(ex); } TransparentLabel prompt = GetPrompt(gridView, gridField, canvasSize); List<Control> controls = new List<Control>(); controls.Add(prompt); controls.Add(gridView); if (!fieldControls.ContainsKey(gridField)) { fieldControls.Add(gridField, controls); } return controls; }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The GridField the row belongs to</param> public GlobalRecordIdColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { Construct(); }
/// <summary> /// Constructor for the Phone Number Column class /// </summary> public PhoneNumberColumn(GridField grid) : base(grid) { construct(); }
/// <summary> /// Instantiates a grid field /// </summary> /// <param name="grid">Grid field object.</param> public RecStatusColumn(GridField grid) : base(grid) { construct(); }
/// <summary> /// Shows the GridColumnsDialog /// </summary> /// <param name="sender">Object that fired the event</param> /// <param name="e">.NET supplied event parameters</param> private void btnAdd_Click(object sender, EventArgs e) { if (!txtFieldName.TextLength.Equals(0)) { SetFieldProperties(); List<GridColumnBase> tempColumns; if (Util.IsEmpty(gridColumns)) { tempColumns = new List<GridColumnBase>(field.Columns); } else { tempColumns = new List<GridColumnBase>(gridColumns); } DataView patternsDataView = field.GetMetadata().GetPatterns().DefaultView; GridColumnsDialog gridColumnsDialog = new GridColumnsDialog ( this.mainForm, page, field, patternsDataView, mode, tempColumns ); gridColumnsDialog.ShowDialog(); if (gridColumnsDialog.DialogResult == DialogResult.OK) { tableStyle = new DataGridTableStyle(); tableStyle.MappingName = "GridColumns"; tableStyle.RowHeadersVisible = false; tableStyle.ReadOnly = true; field = gridColumnsDialog.Grid; DataTable columnTable = new DataTable("GridColumns"); tempColumns.Sort(Util.SortByPosition); foreach (GridColumnBase gridColumn in tempColumns) { if (!(gridColumn is PredefinedColumn)) { DataColumn dc = new DataColumn(gridColumn.Name); columnTable.Columns.Add(dc); DataGridTextBoxColumn textBoxColumn = new DataGridTextBoxColumn(); textBoxColumn.MappingName = gridColumn.Name; textBoxColumn.HeaderText = gridColumn.Text; textBoxColumn.Width = gridColumn.Width; textBoxColumn.WidthChanged += new EventHandler(textColumn_WidthChanged); tableStyle.GridColumnStyles.Add(textBoxColumn); } } dgColumns.DataSource = columnTable; dgColumns.TableStyles.Clear(); dgColumns.TableStyles.Add(tableStyle); gridColumns = tempColumns; btnOk.Enabled = true; } else { if (Util.IsEmpty(gridColumns)) { tempColumns = null; btnOk.Enabled = false; } } } }
/// <summary> /// Constructor for the class. Instantiates a grid field. /// </summary> /// <param name="grid">Grid field object.</param> public UniqueRowIdColumn(GridField grid) : base(grid) { Construct(); }
/// <summary> /// Creates an XmlElement representing an Epi Info 7 grid's data. /// </summary> /// <param name="xmlDataPackage">The data package xml document that the XmlElement should be added to</param> /// <param name="form">The form that contains the grid field</param> /// <param name="gridField">The grid field whose data will be serialized</param> /// <returns>XmlElement; represents the grid's data in Xml format, suitable for use in data packaging</returns> protected virtual XmlElement CreateXmlGridDataElement(XmlDocument xmlDataPackage, View form, GridField gridField) { #region Input Validation if (xmlDataPackage == null) { throw new ArgumentNullException("xmlDataPackage"); } if (form == null) { throw new ArgumentNullException("form"); } if (gridField == null) { throw new ArgumentNullException("gridField"); } #endregion // Input Validation XmlElement data = xmlDataPackage.CreateElement("GridData"); OnStatusChanged(String.Format(PackagerStrings.ADDING_GRID_DATA, gridField.Name, form.Name)); using (IDataReader reader = SourceProject.CollectedData.GetDatabase().GetTableDataReader(gridField.TableName)) { while (reader.Read()) { string guid = reader["GlobalRecordId"].ToString(); string fkey = reader["FKEY"].ToString(); string urid = reader["UniqueRowId"].ToString(); string recstatus = reader["RECSTATUS"].ToString(); if (recstatus.Equals("1")) { XmlElement element = xmlDataPackage.CreateElement("Record"); XmlAttribute id = xmlDataPackage.CreateAttribute("Id"); XmlAttribute foreignKey = xmlDataPackage.CreateAttribute("FKEY"); XmlAttribute uniqueRowId = xmlDataPackage.CreateAttribute("UniqueRowId"); id.Value = guid; foreignKey.Value = fkey; uniqueRowId.Value = urid; element.Attributes.Append(id); element.Attributes.Append(foreignKey); element.Attributes.Append(uniqueRowId); foreach (GridColumnBase column in gridField.Columns) { if (GridColumnsToNull == null || !(GridColumnsToNull.ContainsKey(gridField.Name) && GridColumnsToNull[gridField.Name].Contains(column.Name))) { if (!(column.Name.Equals("UniqueRowId") || column.Name.Equals("GlobalRecordId") || column.Name.Equals("FKEY") || column.Name.Equals("RECSTATUS"))) { XmlElement gridFieldData = xmlDataPackage.CreateElement("GridColumn"); XmlAttribute name = xmlDataPackage.CreateAttribute("Name"); name.Value = column.Name; gridFieldData.Attributes.Append(name); string value = reader[column.Name].ToString(); // To save space, don't include missing values in the Xml. Note that the requirement is for // missing data in the package to be ignored during an import, so this isn't harmful - missing // data, if it were included, wouldn't overwrite anything in the destination database anyway. if (!string.IsNullOrEmpty(value)) { if (column is DateTimeColumn || column is DateColumn || column is TimeColumn) { DateTime dt = Convert.ToDateTime(value); gridFieldData.InnerText = dt.Ticks.ToString(); } else { gridFieldData.InnerText = value; } } element.AppendChild(gridFieldData); data.AppendChild(element); } } } } } } return data; }
/// <summary> /// Creates an XmlElement representing an Epi Info 7 grid field. /// </summary> /// <param name="xmlDataPackage">The data package xml document that the XmlElement should be added to</param> /// <param name="form">The form that contains the grid field</param> /// <param name="gridField">The grid field to be serialized</param> /// <returns>XmlElement; represents the Grid field in Xml format, suitable for use in data packaging</returns> protected XmlElement CreateXmlGridElement(XmlDocument xmlDataPackage, View form, GridField gridField) { #region Input Validation if (xmlDataPackage == null) { throw new ArgumentNullException("xmlDataPackage"); } if (form == null) { throw new ArgumentNullException("form"); } if (gridField == null) { throw new ArgumentNullException("gridField"); } #endregion // Input Validation XmlElement gridElement = xmlDataPackage.CreateElement("Grid"); XmlAttribute name = xmlDataPackage.CreateAttribute("Name"); XmlAttribute columns = xmlDataPackage.CreateAttribute("Columns"); // The column count is here so we can check to see if the # of columns match between the Xml document and the destination project during import XmlAttribute parent = xmlDataPackage.CreateAttribute("ParentForm"); name.Value = gridField.Name; columns.Value = gridField.Columns.Count.ToString(); parent.Value = form.Name; gridElement.Attributes.Append(name); gridElement.Attributes.Append(columns); gridElement.Attributes.Append(parent); gridElement.AppendChild(CreateXmlGridMetadataElement(xmlDataPackage, form, gridField)); gridElement.AppendChild(CreateXmlGridDataElement(xmlDataPackage, form, gridField)); return gridElement; }
/// <summary> /// Constructor for the class /// </summary> public GridColumnBase(GridField grid) { this.grid = grid; }
/// <summary> /// Creates an XmlElement representing an Epi Info 7 grid field's metadata. /// </summary> /// <param name="xmlDataPackage">The data package xml document that the XmlElement should be added to</param> /// <param name="form">The form that contains the grid field</param> /// <param name="gridField">The grid field whose metadata will be serialized</param> /// <returns>XmlElement; represents the grid's metadata in Xml format, suitable for use in data packaging</returns> protected XmlElement CreateXmlGridMetadataElement(XmlDocument xmlDataPackage, View form, GridField gridField) { #region Input Validation if (xmlDataPackage == null) { throw new ArgumentNullException("xmlDataPackage"); } if (form == null) { throw new ArgumentNullException("form"); } if (gridField == null) { throw new ArgumentNullException("gridField"); } #endregion // Input Validation OnStatusChanged(String.Format(PackagerStrings.ADDING_GRID_METADATA, gridField.Name, form.Name)); XmlElement gridFields = xmlDataPackage.CreateElement("GridMetadata"); foreach (GridColumnBase column in gridField.Columns) { if (!(column.Name.Equals("UniqueRowId") || column.Name.Equals("GlobalRecordId") || column.Name.Equals("FKEY") || column.Name.Equals("RECSTATUS"))) { XmlElement gridFieldInfo = xmlDataPackage.CreateElement("GridFieldInfo"); XmlAttribute name = xmlDataPackage.CreateAttribute("Name"); XmlAttribute type = xmlDataPackage.CreateAttribute("FieldType"); name.Value = column.Name; type.Value = column.GridColumnType.ToString(); gridFieldInfo.Attributes.Append(name); gridFieldInfo.Attributes.Append(type); gridFields.AppendChild(gridFieldInfo); } } return gridFields; }
/// <summary> /// Constructor for the class /// </summary> public DateTimeColumn(GridField grid) : base(grid) { Construct(); }
private void UpdateRecStatus(GridField gridField, bool isDelete, string globalRecordId) { Epi.Data.Services.CollectedDataProvider collectedData = this.EnterCheckCodeEngine.Project.CollectedData; Epi.Data.Query updateQuery = collectedData.CreateQuery("update " + gridField.TableName + " set [RecStatus] = @RecStatus where [FKEY] = @FKEY"); updateQuery.Parameters.Add(new Epi.Data.QueryParameter("@RecStatus", DbType.Int32, isDelete ? 0 : 1)); updateQuery.Parameters.Add(new Epi.Data.QueryParameter("@FKEY", DbType.String, globalRecordId)); collectedData.ExecuteNonQuery(updateQuery); }
/// <summary> /// Constructor for the class /// </summary> /// <param name="gridRow">A DataRow containing the grid row's data</param> /// <param name="grid">The grid that contains the DataRow</param> public DateTimeColumn(DataRow gridRow, GridField grid) : base(gridRow, grid) { Construct(); }