Example #1
0
        public static GridControlModel GetGridControlModel(string type)
        {
            GridControlModel model = null;

            XMLDataManage.Manage().gridControlDict.TryGetValue(type, out model);
            return(model);
        }
Example #2
0
        public ActionResult Show()
        {
            var model = new GridControlModel("testGridView")
            {
                ViewModel = GetUtenti()
            };

            return(this.PartialView(model));
        }
Example #3
0
        /// <summary>
        /// 获取GridControl 的标题数据
        /// </summary>
        /// <returns></returns>
        private void ReadGridControlXML()
        {
            string      xmlFilePath = Application.StartupPath + "//GridControl.xml";
            XmlDocument xmlDoc      = new XmlDocument();

            xmlDoc.Load(xmlFilePath);

            XmlNodeList gridList = xmlDoc.SelectNodes("//gridcontrol//grid");

            foreach (XmlElement nodeEle in gridList)
            {
                string             key     = nodeEle.GetAttribute("type");
                GridControlModel   model   = new GridControlModel();
                List <ColumnModel> columns = new List <ColumnModel>();

                XmlNodeList columnList = nodeEle.SelectNodes("column");
                foreach (XmlElement columnEle in columnList)
                {
                    ColumnModel column = new ColumnModel();
                    column.name  = columnEle.GetAttribute("name");
                    column.field = columnEle.GetAttribute("field") == null || columnEle.GetAttribute("field") == ""? "None":columnEle.GetAttribute("field");
                    column.tag   = columnEle.GetAttribute("tag") == null || columnEle.GetAttribute("tag") == "" ? "-1" : columnEle.GetAttribute("tag");
                    column.type  = (ColumnType)Enum.Parse(typeof(ColumnType), columnEle.GetAttribute("type"));

                    switch (column.type)
                    {
                    case ColumnType.C_Button:
                        char[]   sp    = { '/' };
                        string[] names = columnEle.GetAttribute("bnames").Split(sp);
                        column.buttonNames = names.ToList <string>();
                        break;

                    default:
                        break;
                    }


                    columns.Add(column);
                }
                model.columns = columns;

                this.gridControlDict.Add(key, model);
            }
        }
Example #4
0
        /// <summary>
        ///  设置GridControl下的GridView
        /// </summary>
        /// <param name="gridView">被设置的GridView</param>
        /// <param name="type">GridControl 的类型</param>
        /// <param name="table">数据源DataTable</param>
        /// <param name="buttonclik">按钮列按钮点击事件</param>
        /// <param name="titleHandler">点击标题列点击事件</param>
        public static void SetGridView(GridView gridView,
                                       GridControlType type,
                                       out DataTable table
                                       , ButtonPressedEventHandler buttonclik,
                                       DevExpress.XtraGrid.Views.Base.CustomColumnSortEventHandler titleHandler)
        {
            GridControlModel model = XMLDataManage.GetGridControlModel(type.ToString());

            table = new DataTable();

            int i = 0;

            foreach (ColumnModel columnModel in model.columns)
            {
                string fieldname = "column_" + i;
                if (columnModel.field != "None")
                {
                    fieldname = columnModel.field;
                }

                GridColumn column = gridView.Columns.AddVisible(fieldname, columnModel.name);
                //表头文本水平位置
                column.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                //表头文本自动换行
                column.AppearanceHeader.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                column.AppearanceHeader.Font = new Font("宋体", 12, GraphicsUnit.Pixel);


                column.OptionsColumn.AllowEdit = false;

                switch (columnModel.type)
                {
                    #region 添加链接
                case ColumnType.C_LineLink:
                {
                    RepositoryItemHyperLinkEdit link = new RepositoryItemHyperLinkEdit();
                    link.LinkColor = Color.Blue;

                    column.ColumnEdit = link;
                    column.OptionsColumn.AllowEdit = true;

                    DataColumn dataColumn = new DataColumn(fieldname);
                    table.Columns.Add(dataColumn);
                    // dataColumn.DataType = typeof(string);
                }


                break;

                    #endregion

                    #region 添加复选框
                case ColumnType.C_Check:            //添加复选框
                {
                    RepositoryItemCheckEdit check = new RepositoryItemCheckEdit();
                    check.NullStyle   = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
                    column.ColumnEdit = check;
                    column.OptionsColumn.AllowEdit = true;
                    column.Width = 40;

                    DataColumn dataColumn = new DataColumn(fieldname);
                    table.Columns.Add(dataColumn);
                    dataColumn.DataType = typeof(bool);
                }


                break;
                    #endregion

                    #region 添加按钮
                case ColumnType.C_Button:            //添加按钮
                {
                    //color = "131,157,199"
                    RepositoryItemButtonEdit buttonEdit = new RepositoryItemButtonEdit();
                    buttonEdit.Buttons.Clear();
                    buttonEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
                    //buttonEdit.ButtonsStyle = BorderStyles.NoBorder;
                    //buttonEdit.BorderStyle = BorderStyles.NoBorder;
                    //buttonEdit.AutoHeight = false;
                    if (buttonclik != null)
                    {
                        buttonEdit.ButtonClick += buttonclik;
                    }

                    #region 添加按钮
                    int num   = 0;
                    int width = 8;
                    foreach (string name in columnModel.buttonNames)
                    {
                        char[]   splits = { '(', ')' };
                        string[] names  = name.Split(splits);

                        EditorButton button = new EditorButton();
                        button.Kind = ButtonPredefines.Glyph;

                        //按钮显示
                        button.Visible = true;
                        button.Tag     = fieldname + "_" + num;
                        //62,141,232
                        //if (names.Count() > 1)
                        //{
                        //    char[] color_sp = { ','};
                        //    string[] colors = names[1].Split(color_sp);
                        //    button.Appearance.ForeColor = Color.FromArgb(int.Parse(colors[0]), int.Parse(colors[1]), int.Parse(colors[2]));
                        //}
                        //else
                        //{
                        //    button.Appearance.ForeColor = Color.Blue;

                        //}

                        button.Appearance.ForeColor = Color.FromArgb(62, 141, 232);
                        button.Caption = names[0];
                        width         += 50;

                        //button.ImageLocation = DevExpress.XtraEditors.ImageLocation.MiddleCenter;
                        button.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                        buttonEdit.Buttons.Add(button);
                        num++;
                    }
                    #endregion
                    column.ColumnEdit = buttonEdit;
                    column.Width      = width;
                    //column.MinWidth = width;
                    column.OptionsColumn.AllowEdit = true;
                    column.UnboundType             = DevExpress.Data.UnboundColumnType.String;


                    DataColumn dataColumn = new DataColumn(fieldname);
                    table.Columns.Add(dataColumn);
                    //dataColumn.DataType = typeof(RepositoryItemButtonEdit);
                }
                break;

                    #endregion
                default:
                {
                    RepositoryItemMemoEdit edit = new RepositoryItemMemoEdit();
                    column.SortMode   = ColumnSortMode.Custom;
                    column.Width      = 100;   //columnModel.width;
                    column.ColumnEdit = edit;
                    //表头下文本自动换行
                    column.AppearanceCell.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
                    //表头下文本书平内容
                    column.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    column.AppearanceCell.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;

                    DataColumn dataColumn = new DataColumn(fieldname);
                    table.Columns.Add(dataColumn);
                }

                break;
                }
                i++;
            }

            gridView.OptionsSelection.MultiSelect     = true;
            gridView.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect;
            gridView.RowHeight = 25;

            //表头高度
            gridView.ColumnPanelRowHeight = 30;

            //关闭最左侧
            gridView.OptionsView.ShowIndicator = false;
            //关闭表头右键快捷键
            gridView.OptionsMenu.EnableColumnMenu = false;
            if (titleHandler != null)
            {
                gridView.CustomColumnSort += titleHandler;
            }
        }