コード例 #1
0
        /// <summary>
        /// (递归)序列化单个控件
        /// </summary>
        /// <param name="nametable"></param>
        /// <param name="parentSiteName"></param>
        /// <param name="level"></param>
        /// <param name="value"></param>
        /// <param name="serializedData"></param>
        private void SerializeControl(Hashtable nametable, string parentSiteName, object value, List <EntityFormCtrl> serializedData, bool recursive)
        {
            try
            {
                IComponent     component = value as IComponent;
                EntityFormCtrl entity    = new EntityFormCtrl();

                entity.ControlType = value.GetType().AssemblyQualifiedName;

                if (component != null && component.Site != null && component.Site.Name != null)
                {
                    entity.ControlName = component.Site.Name;
                    entity.Parent      = parentSiteName;
                    nametable[value]   = component.Site.Name;
                }

                bool    isControl = (value is Control);
                Control ctrl      = value as Control;

                if (isControl)
                {
                    if (ctrl is IRuntimeDesignControl)
                    {
                        IRuntimeDesignControl ictrl = ctrl as IRuntimeDesignControl;
                        entity.Height           = (int)ictrl.Height;
                        entity.Width            = (int)ictrl.Width;
                        entity.Top              = (int)ictrl.Location.Y;
                        entity.Left             = (int)ictrl.Location.X;
                        entity.Text             = ictrl.Text;
                        entity.ForeColor        = ictrl.ForeColor;
                        entity.BackColor        = ictrl.BackColor;
                        entity.TabIndex         = ictrl.TabIndex;
                        entity.PresentationMode = ictrl.PresentationMode;
                        entity.ReferenceType    = ictrl.Referencetype ? 1 : 0;
                        entity.Essential        = ictrl.Essential ? 1 : 0;

                        //序列化字体
                        if (ictrl.TextFont != null)
                        {
                            entity.TextFont = FontSerializationService.Serialize(ictrl.TextFont);
                        }
                    }
                    else
                    {
                        entity.Height    = (int)ctrl.Height;
                        entity.Width     = (int)ctrl.Width;
                        entity.Top       = (int)ctrl.Top;
                        entity.Left      = (int)ctrl.Left;
                        entity.ForeColor = ctrl.ForeColor;
                        entity.BackColor = ctrl.BackColor;
                    }

                    if (value is IFormCtrl)
                    {
                        IFormCtrl iForm = value as IFormCtrl;
                        entity.ItemName       = iForm.ItemName;
                        entity.ItemCaption    = iForm.ItemCaption;
                        entity.ItemType       = iForm.ItemType;
                        entity.ParentNode     = iForm.ParentNode;
                        entity.CalProperty    = iForm.CalProperty;
                        entity.RowShrinkDigit = iForm.RowShrinkDigit;
                    }

                    if (string.IsNullOrEmpty(parentSiteName) && ctrl.Parent != null && ctrl.Parent != designerHost.RootComponent)
                    {
                        if (ctrl != designerHost.RootComponent)
                        {
                            entity.Parent = ctrl.Parent.Site.Name;
                        }
                    }

                    if (value is ICheckBox)
                    {
                        ICheckBox iChk = value as ICheckBox;
                        entity.GroupName          = iChk.GroupName;
                        entity.SumName            = iChk.SumName;
                        entity.CheckedWeightValue = iChk.CheckedWeightValue;
                        entity.Checked            = (iChk.Checked ? "1" : "0");
                    }
                    else if (value is ICombox)
                    {
                        ICombox iCbx = value as ICombox;
                        if (iCbx.Items.Count > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            foreach (string item in iCbx.Items)
                            {
                                sb.Append(string.Format(ConstValue.CONTROL_ITEMS_SPLITER + "{0}", item));
                            }
                            sb.Remove(0, 1);
                            entity.Items = sb.ToString();
                        }
                    }
                    else if (value is ICtlLine)
                    {
                        ICtlLine iLine = value as ICtlLine;
                        entity.LineStyle = iLine.LineStyle.ToString();
                        entity.LineWidth = iLine.LineWidth;
                    }
                    else if (value is IPictureBox)
                    {
                        IPictureBox iPic = value as IPictureBox;
                        entity.PicFileName = iPic.FileName;
                    }
                    else if (value is IPanel)
                    {
                        IPanel ipnl = ctrl as IPanel;
                        entity.ReserveField = string.Format("{0}{1}{2}", ipnl.Columns, ConstValue.CONTROL_ITEMS_SPLITER, ipnl.Rows);
                        entity.Items        = ipnl.BorderStyle.ToString();
                    }
                    else if (ctrl is ITabControl)
                    {
                        ITabControl iTab = ctrl as ITabControl;
                        entity.Items = iTab.HeaderLocation.ToString().ToLower();
                    }
                    else if (ctrl is DevExpress.XtraTab.XtraTabPage)
                    {
                        entity.Text = ((DevExpress.XtraTab.XtraTabPage)ctrl).Text;
                    }
                    else if (ctrl is IXtraDateTime)
                    {
                        IXtraDateTime ictrl = ctrl as IXtraDateTime;
                        entity.Items = string.Format("{0}{1}{2}{3}{4}"
                                                     , ictrl.DateTimeValue
                                                     , ConstValue.CONTROL_ITEMS_SPLITER
                                                     , ictrl.EditMask
                                                     , ConstValue.CONTROL_ITEMS_SPLITER
                                                     , ictrl.SPDefaultValue
                                                     );
                    }
                    else if (ctrl is ISignatureControl)
                    {
                        ISignatureControl iSign = ctrl as ISignatureControl;
                        entity.Items = string.Format("{0}{1}{2}{3}{4}"
                                                     , iSign.Caption
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iSign.IsAllowSignNull.ToString()
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iSign.IsAutoSignature.ToString());
                        entity.Text = string.Empty;
                    }
                    else if (ctrl is IRtfEditor)
                    {
                        IRtfEditor iRtx = ctrl as IRtfEditor;
                        entity.Items = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}"
                                                     , (iRtx.Multiline ? "1" : "0")
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , (iRtx.FixedHeight ? "1" : "0")
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iRtx.RowShrinkdigit.ToString()
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iRtx.DefaultRows.ToString()
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iRtx.FirstlineCaption);
                    }
                    else if (value is IPatientControl)
                    {
                        IPatientControl iPatctrl = ctrl as IPatientControl;
                        entity.Items = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}"
                                                     , iPatctrl.CaptionText
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iPatctrl.InfoType.ToString()
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iPatctrl.ShowCaption.ToString()
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iPatctrl.CalcAgeType.ToString()
                                                     , ConstValue.EVENT_STRING_SPLITER
                                                     , iPatctrl.BandingPage.ToString());
                    }
                }

                if (component != null && isControl)
                {
                    if (recursive)
                    {
                        foreach (Control child in ((Control)value).Controls)
                        {
                            if (child.Site != null && child.Site.Container == designerHost.Container)
                            {
                                if (!nametable.ContainsKey(child))
                                {
                                    SerializeControl(nametable, component.Site.Name, child, serializedData, recursive);
                                }
                            }
                        }
                    }
                }
                serializedData.Add(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        /// <summary>
        /// (递归)序列化单个控件
        /// </summary>
        /// <param name="nametable"></param>
        /// <param name="parentSiteName"></param>
        /// <param name="level"></param>
        /// <param name="value"></param>
        /// <param name="serializedData"></param>
        private void SerializeControl(Hashtable nametable, string parentSiteName, object value, List <EntityCPNode> serializedData, bool recursive)
        {
            try
            {
                IComponent   component = value as IComponent;
                EntityCPNode entity    = new EntityCPNode();

                entity.ControlType = value.GetType().AssemblyQualifiedName;

                if (component != null && component.Site != null && component.Site.Name != null)
                {
                    entity.ControlName = component.Site.Name;
                    //entity.Parent = parentSiteName;
                    nametable[value] = component.Site.Name;
                }

                bool    isControl = (value is Control);
                Control ctrl      = value as Control;

                if (isControl)
                {
                    if (ctrl is IRuntimeDesignControl)
                    {
                        IRuntimeDesignControl ictrl = ctrl as IRuntimeDesignControl;

                        entity.Height    = (int)ictrl.Height;
                        entity.Width     = (int)ictrl.Width;
                        entity.Top       = (int)ictrl.Location.Y;
                        entity.Left      = (int)ictrl.Location.X;
                        entity.NodeDesc  = ictrl.Text;
                        entity.ForeColor = ictrl.ForeColor;
                        //序列化字体
                        if (ictrl.TextFont != null)
                        {
                            entity.TextFont = FontSerializationService.Serialize(ictrl.TextFont);
                        }
                    }
                    else
                    {
                        entity.Height = (int)ctrl.Height;
                        entity.Width  = (int)ctrl.Width;
                        entity.Top    = (int)ctrl.Top;
                        entity.Left   = (int)ctrl.Left;
                    }

                    if (value is ICpNode)
                    {
                        ICpNode iNode = value as ICpNode;

                        entity.NodeName       = iNode.NodeName;
                        entity.NodeType       = iNode.NodeType;
                        entity.NodeDays       = iNode.NodeDays;
                        entity.ParentNodeName = iNode.ParentNodeName;
                    }
                }

                if (component != null && isControl)
                {
                    if (recursive)
                    {
                        foreach (Control child in ((Control)value).Controls)
                        {
                            if (child.Site != null && child.Site.Container == designerHost.Container)
                            {
                                if (!nametable.ContainsKey(child))
                                {
                                    SerializeControl(nametable, component.Site.Name, child, serializedData, recursive);
                                }
                            }
                        }
                    }
                }

                serializedData.Add(entity);
            }
            catch (Exception ex)
            {
                throw;
            }
        }