Esempio n. 1
0
        private static void InitComboBox(ComboBox box, RuleColumn rcolumn)
        {
            if (box == null || rcolumn == null)
            {
                return;
            }

            if (rcolumn.HasMapInfo)
            {
                DataMap dm = SystemContext.MapManager.FromMapInfo(rcolumn.MapInfo);

                if (dm != null)
                {
                    box.DataSource    = dm.GetMapTable(rcolumn.GetLocalType());
                    box.ValueMember   = "Key";
                    box.DisplayMember = "Value";
                }
            }
            box.Text = "";
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public static void InitDataGridViewColumns(DataGridView grid, DataTable table)
        {
            if (grid == null || table == null)
            {
                return;
            }

            //if (grid.Columns.Count > 0)
            //    grid.Columns.Clear();

            if (grid.Columns.Count == 0)
            {
                grid.EditingControlShowing -= new DataGridViewEditingControlShowingEventHandler(DataGridViewEditingControlShowing);
                grid.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(DataGridViewEditingControlShowing);

                DataRule dr = TableUtil.GetDataRule(table);
                if (dr != null)
                {
                    DataColumnCollection columns = table.Columns;
                    if (columns.Count > 0)
                    {
                        DataGridViewColumn gcolumn;
                        RuleColumn         rcolumn;
                        foreach (DataColumn column in columns)
                        {
                            rcolumn = TableUtil.GetRuleColumn(column);
                            if (rcolumn != null)
                            {
                                gcolumn = CreateDataGridViewColumn(rcolumn);
                                grid.Columns.Add(gcolumn);
                            }
                            else
                            {
                                InitDataGridViewColumns(grid, dr);
                                break;
                            }
                        }
                    }
                    else
                    {
                        InitDataGridViewColumns(grid, dr);
                    }
                }
                else if (table.Columns.Count > 0)
                {
                    DataGridViewColumn gcolumn;

                    foreach (DataColumn column in table.Columns)
                    {
                        if (TableUtil.StrProperty(column, "Visible").Equals("0"))
                        {
                            continue;
                        }

                        gcolumn = null;

                        string datatype = column.DataType.ToString();

                        if (datatype.Equals("System.Boolean"))
                        {
                            gcolumn              = new DataGridViewCheckBoxColumn();
                            gcolumn.Width        = column.MaxLength > 50 ? column.MaxLength : 50;
                            gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                        }
                        else if (datatype.Equals("System.DateTime"))
                        {
                            gcolumn              = new CalendarColumn("yyyy-MM-dd HH:mm:ss");
                            gcolumn.Width        = 130;
                            gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                        }
                        else
                        {
                            string mapInfo = TableUtil.StrProperty(column, "MapInfo");
                            if (!mapInfo.Equals(""))
                            {
                                DataMap dm = SystemContext.MapManager.FromMapInfo(mapInfo);
                                if (dm != null)
                                {
                                    DataTable mtable = dm.GetMapTable(null);
                                    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";
                                        }
                                    }
                                }
                            }

                            if (gcolumn == null)
                            {
                                gcolumn              = new DataGridViewTextBoxColumn();
                                gcolumn.Width        = column.MaxLength > 100 ? column.MaxLength : 100;
                                gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                            }
                        }

                        gcolumn.Name             = column.ColumnName;
                        gcolumn.HeaderText       = column.Caption;
                        gcolumn.DataPropertyName = column.ColumnName;

                        //gcolumn.Width = column.MaxLength;
                        //gcolumn.Width = column.MaxLength > 100 ? column.MaxLength : 100;

                        //gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;

                        grid.Columns.Add(gcolumn);
                    }
                }

                grid.AutoGenerateColumns = false;
                grid.DataSource          = GetBindingSource(table);
            }
            else
            {
                DataColumn column;
                string     mapInfo;
                foreach (DataGridViewColumn gcolumn in grid.Columns)
                {
                    column = table.Columns[gcolumn.DataPropertyName];
                    if (column != null)
                    {
                        mapInfo = TableUtil.StrProperty(column, "MapInfo");
                        if (!mapInfo.Equals(""))
                        {
                            DataMap dm = SystemContext.MapManager.FromMapInfo(mapInfo);
                            if (dm != null)
                            {
                                DataTable mtable = dm.GetMapTable(null);
                                if (mtable != null && mtable.Rows.Count > 0)
                                {
                                    DataGridViewComboBoxCell combboxcell = gcolumn.CellTemplate as DataGridViewComboBoxCell;
                                    if (combboxcell != null)
                                    {
                                        combboxcell.DataSource    = mtable;
                                        combboxcell.ValueMember   = "Key";
                                        combboxcell.DisplayMember = "Value";
                                    }
                                }
                            }
                        }
                    }
                }

                grid.AutoGenerateColumns = false;
                grid.DataSource          = GetBindingSource(table);
            }

            grid.CellLeave -= new DataGridViewCellEventHandler(DataGridView_CellLeave);
            grid.CellLeave += new DataGridViewCellEventHandler(DataGridView_CellLeave);
        }