コード例 #1
0
        /// <summary>
        /// 把设置的选项存储到XML 文件中。
        /// </summary>
        /// <param name="info"></param>
        /// <param name="xmlFileName"></param>
        public void SaveOptionsInfoToXML(GridViewOptionsInfo info, string xmlFileName)
        {
            StringBuilder xmlSB = new StringBuilder();

            try{
                //描述
                xmlSB.Append("<?xml version='1.0' encoding='utf-8' ?>");
                xmlSB.Append("<!-- Copyright (C) 2009-2010 Chen.Dc Soft (www.mb.com)  -->");
                //xmlSB.Append("<XtraGrid>");
                writeFirstMarker(xmlSB, MAIN_NODE_NAME);

                string objXml = objectToXml(info);
                xmlSB.Append(objXml);

                writeLastMarker(xmlSB, MAIN_NODE_NAME);

                if (!System.IO.Directory.Exists(CFG_FILE_PATH))
                {
                    System.IO.Directory.CreateDirectory(CFG_FILE_PATH);
                }

                System.Xml.XmlDocument xDoc = new XmlDocument();

                xDoc.LoadXml(xmlSB.ToString());
                string fullFileName = CFG_FILE_PATH + xmlFileName;

                xDoc.Save(fullFileName);
            }
            catch (Exception e) {
                MB.Util.TraceEx.Write("把选项数据存储到XML 文件时出错。" + e.Message);
            }
        }
コード例 #2
0
        protected override void OnLoaded()
        {
            base.OnLoaded();
            if (_IsDesign)
            {
                return;
            }
            if (base.ContextMenu == null)
            {
                XtraContextMenu xMenu = new XtraContextMenu(this, XtraContextMenuType.Copy | XtraContextMenuType.Export | XtraContextMenuType.ExportAsTemplet |
                                                            XtraContextMenuType.DataImport | XtraContextMenuType.SaveGridState | XtraContextMenuType.ColumnsAllowSort |
                                                            XtraContextMenuType.Chart | XtraContextMenuType.ChartDesign);
                base.ContextMenu = xMenu.GridContextMenu;
            }

            if (_HasInitilizeGridLoad || !_ShowOptionMenu)
            {
                return;
            }

            _HasInitilizeGridLoad = true;
            _ParentFrm            = MB.WinBase.ShareLib.Instance.GetControlParentForm(this);
            if (_ParentFrm == null)
            {
                return;
            }

            MB.WinBase.IFace.IForm viewFrm = _ParentFrm as MB.WinBase.IFace.IForm;
            if (viewFrm != null && viewFrm.ClientRuleObject != null)
            {
                _XmlCfgFileName = viewFrm.ClientRuleObject.ClientLayoutAttribute.UIXmlConfigFile;
                _OptionsCFGName = viewFrm.GetType().FullName + "~" + viewFrm.ClientRuleObject.GetType().FullName + "~" + this.Name + ".xml";
                var layOutXmlHelper = LayoutXmlConfigHelper.Instance;
                var colPros         = layOutXmlHelper.GetColumnPropertys(_XmlCfgFileName);
                var colEditPros     = layOutXmlHelper.GetColumnEdits(colPros, _XmlCfgFileName);
            }
            else
            {
                _OptionsCFGName = _ParentFrm.GetType().FullName + "~" + this.Name + ".xml";
            }

            _CurrentInfo = GridViewOptionsHelper.Instance.CreateFromXMLToInfo(_OptionsCFGName);

            _GridView = this.DefaultView as DevExpress.XtraGrid.Views.Grid.GridView;

            if (_GridView != null)
            {
                _GridView.OptionsView.EnableAppearanceEvenRow = true;

                _GridView.Appearance.EvenRow.BackColor = ODD_ROW_BACK_COLOR;
                // _GridView.OptionsView.EnableAppearanceEvenRow = true;
                //  _GridView.OptionsView.EnableAppearanceOddRow = true;
                _GridView.RowCellStyle       += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(_GridView_RowCellStyle);
                _GridView.CustomFilterDialog += new DevExpress.XtraGrid.Views.Grid.CustomFilterDialogEventHandler(_GridView_CustomFilterDialog);
            }

            setGridViewByOptions();
            createOptionsMenu(ContextMenu);
            createCopyCellMenu(ContextMenu);
        }
コード例 #3
0
        /// <summary>
        /// 构造函数...
        /// </summary>
        /// <param name="optionsInfo"></param>
        public FrmXtraGridViewOptions(DevExpress.XtraGrid.Views.Grid.GridView gridView, GridViewOptionsInfo currentOptionsInfo, string optionsCfgFile)
        {
            InitializeComponent();

            _OptionsCfgFile     = optionsCfgFile;
            _CurrentOptionsInfo = currentOptionsInfo;

            _GridView = gridView;

            setByOptionsInfo();
        }
コード例 #4
0
        /// <summary>
        /// 从指定的XML 样式文件中创建ViewOptionsInfo.
        /// </summary>
        /// <param name="xmlFileName"></param>
        /// <returns></returns>
        public GridViewOptionsInfo CreateFromXMLToInfo(string xmlFileName)
        {
            string fullFileName      = CFG_FILE_PATH + xmlFileName;
            GridViewOptionsInfo info = new GridViewOptionsInfo();

            if (System.IO.File.Exists(fullFileName))
            {
                try{
                    System.Xml.XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(fullFileName);
                    XmlNode xNode = xDoc.SelectSingleNode("/" + MAIN_NODE_NAME);
                    setObjectProperty(xNode, info);
                }
                catch (Exception e) {
                    MB.Util.TraceEx.Write("把配置的XML 文件信息存储为描述的Info 对象时出错:" + e.Message);
                }
            }
            return(info);
        }
コード例 #5
0
        private void _OptionMenu_Click(object sender, EventArgs e)
        {
            if (_OptionsCFGName == null || _OptionsCFGName.Length == 0)
            {
                return;
            }

            FrmXtraGridViewOptions frm = new FrmXtraGridViewOptions(_GridView, _CurrentInfo, _OptionsCFGName);

            var result = frm.ShowDialog();

            // 确定,应用条件样式
            if (result == DialogResult.OK)
            {
                setGridViewByOptions();
            }

            // 取消,重新加载配置文件
            if (result == DialogResult.Cancel)
            {
                _CurrentInfo = GridViewOptionsHelper.Instance.CreateFromXMLToInfo(_OptionsCFGName);
            }
        }