Beispiel #1
0
        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;
        }
Beispiel #2
0
        public static DataGridViewColumn CreateDataGridViewColumn(RuleColumn rcolumn)
        {
            if (rcolumn == null)
            {
                return(null);
            }

            DataGridViewColumn gcolumn = null;

            switch (rcolumn.DataType)
            {
            case DataTypes.dtBoolean:
                gcolumn = new DataGridViewCheckBoxColumn();
                break;

            case DataTypes.dtDateTime:
                gcolumn = new CalendarColumn("yyyy-MM-dd HH:mm:ss");
                break;

            case DataTypes.dtDate:
                gcolumn = new CalendarColumn("yyyy-MM-dd");
                break;

            case DataTypes.dtTime:
                gcolumn = new CalendarColumn("HH:mm:ss");
                break;

            case DataTypes.dtBLOB:
                gcolumn = new DataGridViewImageColumn();
                break;

            default:
                if (rcolumn.HasMapInfo)
                {
                    DataMap dm = SystemContext.MapManager.FromMapInfo(rcolumn.MapInfo);
                    if (dm != null)
                    {
                        DataTable mtable = dm.GetMapTable(rcolumn.GetLocalType());
                        if (mtable != null && mtable.Rows.Count > 0)
                        {
                            gcolumn = new DataGridViewComboBoxColumn();
                            DataGridViewComboBoxCell combboxcell = gcolumn.CellTemplate as DataGridViewComboBoxCell;
                            if (combboxcell != null)
                            {
                                combboxcell.DataSource    = mtable;
                                combboxcell.ValueMember   = "Key";
                                combboxcell.DisplayMember = "Value";
                            }
                        }
                    }
                }
                else if (rcolumn.HasMask)
                {
                    gcolumn = new MaskedTextBoxColumn(rcolumn.Mask);
                }
                else
                {
                    switch (rcolumn.UiCtrOpt)
                    {
                    case UICtrOpt.TextButton:
                        gcolumn = new TextBoxButtonColumn();
                        break;

                    default:
                        gcolumn = new DataGridViewTextBoxColumn();
                        break;
                    }
                }
                break;
            }

            if (gcolumn == null)
            {
                gcolumn = new DataGridViewTextBoxColumn();
            }

            gcolumn.Name             = rcolumn.ColumnName;
            gcolumn.HeaderText       = rcolumn.Label;
            gcolumn.DataPropertyName = rcolumn.ColumnName;
            gcolumn.Width            = rcolumn.Width;
            gcolumn.Visible          = rcolumn.ListCtrlVision; //rcolumn.Visible;
            gcolumn.SortMode         = DataGridViewColumnSortMode.Automatic;

            if (rcolumn.HasDisplayFormat)
            {
                gcolumn.CellTemplate.Style.Format = rcolumn.DisplayFormat;
            }

            if (gcolumn.Visible && gcolumn.Width < 100)
            {
                if (gcolumn.Width == 0)
                {
                    gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
                }
                else
                {
                    gcolumn.Width = 100;
                }
            }

            return(gcolumn);
        }
Beispiel #3
0
        //  Creates and Initializes the columns for our DataGridView.
        private void InitializeDataGridViewColumns()
        {
            DataGridViewTextBoxColumn dgvtbc;
            MaskedTextBoxColumn       mtbc;

            //
            // employee name.
            //
            dgvtbc            = new DataGridViewTextBoxColumn();
            dgvtbc.HeaderText = "Name";
            dgvtbc.Width      = 120;
            this.employeesDataGridView.Columns.Add(dgvtbc);

            //
            // Employee ID -- this will be of the format:
            // [A-Z][0-9][0-9][0-9][0-9][0-9]
            //
            // this is well sutied to using a MaskedTextBox column.
            //
            mtbc            = new MaskedTextBoxColumn();
            mtbc.HeaderText = "Employee ID";
            mtbc.Mask       = "L00000";
            mtbc.Width      = 75;
            this.employeesDataGridView.Columns.Add(mtbc);

            //
            // [American] Social Security number, of the format:
            // ###-##-####
            //
            mtbc            = new MaskedTextBoxColumn();
            mtbc.HeaderText = "SSN";
            mtbc.Mask       = "000-00-0000";
            mtbc.Width      = 75;
            this.employeesDataGridView.Columns.Add(mtbc);

            //
            // Address
            //
            dgvtbc            = new DataGridViewTextBoxColumn();
            dgvtbc.HeaderText = "Address";
            dgvtbc.Width      = 150;
            this.employeesDataGridView.Columns.Add(dgvtbc);

            //
            // City
            //
            dgvtbc            = new DataGridViewTextBoxColumn();
            dgvtbc.HeaderText = "City";
            dgvtbc.Width      = 75;
            this.employeesDataGridView.Columns.Add(dgvtbc);

            //
            // State
            //
            mtbc            = new MaskedTextBoxColumn();
            mtbc.HeaderText = "State";
            mtbc.Mask       = "LL";
            mtbc.Width      = 40;
            this.employeesDataGridView.Columns.Add(mtbc);

            //
            // Zip Code #####-#### (+4 optional)
            //
            mtbc                = new MaskedTextBoxColumn();
            mtbc.HeaderText     = "Zip Code";
            mtbc.Mask           = "00000-0000";
            mtbc.Width          = 75;
            mtbc.ValidatingType = typeof(ZipCode);
            this.employeesDataGridView.Columns.Add(mtbc);


            //
            // Department Code
            //
            dgvtbc            = new DataGridViewTextBoxColumn();
            dgvtbc.HeaderText = "Department";
            dgvtbc.ValueType  = typeof(int);
            dgvtbc.Width      = 75;
            this.employeesDataGridView.Columns.Add(dgvtbc);
        }