Beispiel #1
0
        /// <summary>
        /// 在树中显示当前页面的子控件信息
        /// </summary>
        /// <param Name="pageWidget">页面控件窗口对象</param>
        public void setPageWidget(SVPageWidget pageWidget)
        {
            //如果没有发生变化,就直接返回
            //if (getCurrentNode() == pageWidget)
            //    return;

            clearAllNodes();
            String      text     = String.Format("页面名称:{0}, (ID:{1})", pageWidget.PageName, pageWidget.Attrib.id);
            ObjTreeNode rootNode = new ObjTreeNode();

            rootNode.Text       = text;
            rootNode.objControl = pageWidget;
            this.Nodes.Add(rootNode);

            //根据ID进行排序
            var sortList = from SVPanel item in pageWidget.Controls
                           orderby item.Id ascending //或descending 和ascending
                           select item;

            foreach (Control item in sortList)
            {
                String name = item.GetType().Name;
                if (_nameDict.ContainsKey(name))
                {
                    _nameDict[name](rootNode, item);
                }
            }

            rootNode.ExpandAll();
        }
Beispiel #2
0
        /// <summary>
        /// 通过控件ID号来查找对应的页面,并记录相关跳转信息
        /// </summary>
        /// <param oldName="id">控件ID</param>
        private void findID(int id)
        {
            _findView.Clear();
            _findView.AppendText("---------------查找结果如下:-----------------\n");
            _findView.AppendText("\n");

            foreach (SVPageNode pageNode in _treeView.Nodes)
            {
                foreach (TreeNode classItem in pageNode.Nodes)
                {
                    foreach (SVPageNode item in classItem.Nodes)
                    {
                        SVPageWidget widget = item.Addtionobj as SVPageWidget;
                        if (widget == null)
                        {
                            continue;
                        }

                        if (widget.Attrib.id == id)
                        {
                            String text = String.Format("找到名为【{0}】的页面, id:{1}", widget.PageName, id);
                            _findView.AppendText(text);
                            _findView.setMark(widget);
                            _findView.AppendText("\n");
                        }

                        foreach (var panel in widget.Controls)
                        {
                            SVPanel p = panel as SVPanel;
                            if (p == null)
                            {
                                continue;
                            }

                            if (p.Id == id)
                            {
                                String text = String.Format("名为【{0}】的页面中, 找到控件====>类型【{1}】.", widget.PageName, p.GetType().Name);
                                _findView.AppendText(text);
                                _findView.setMark(p);
                                _findView.AppendText("\n");
                            }
                        }
                    }
                }
            }

            if (!_findView.isMatches())
            {
                _findView.AppendText("没有查找到相关内容!");
            }
        }
Beispiel #3
0
        /// <summary>
        /// 输出查找结果
        /// </summary>
        /// <param oldName="panel">当前控件</param>
        /// <param oldName="vStr">当前判断的字符串</param>
        void outputFindResult(SVPanel panel, String vStr)
        {
            SVPageWidget widget = panel.Parent as SVPageWidget;

            if (widget == null)
            {
                return;
            }

            ///查找的字符串是否为空
            String findString = textBox.Text;

            if (String.IsNullOrWhiteSpace(findString))
            {
                return;
            }

            ///字符串
            String findStr = findString;
            String oldStr  = vStr;

            ///是否大小写匹配
            if (caseCheckBox.Checked)
            {
                findStr = findStr.ToLower();
                oldStr  = oldStr.ToLower();
            }

            ///全字匹配
            if (wholeCheckBox.Checked)
            {
                if (findStr == oldStr)
                {
                    String text = String.Format("页面【{0}】中, 找到控件====>类型【{1}】.", widget.PageName, panel.GetType().Name);
                    _findView.AppendText(text);
                    _findView.setMark(panel);
                    _findView.AppendText("\n");
                }
            }
            else
            {
                if (oldStr.Contains(findStr))
                {
                    String text = String.Format("页面【{0}】中, 找到控件====>类型【{1}】.", widget.PageName, panel.GetType().Name);
                    _findView.AppendText(text);
                    _findView.setMark(panel);
                    _findView.AppendText("\n");
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 检查当前页面中的元素超出了页面的显示范围
        /// </summary>
        /// <param Name="panel">页面对象</param>
        void checkOutOfRange(SVPageWidget widget)
        {
            foreach (Control ctrl in widget.Controls)
            {
                SVPanel svCtrl = ctrl as SVPanel;
                if (svCtrl == null)
                {
                    continue;
                }

                if (!widget.ClientRectangle.Contains(svCtrl.Bounds))
                {
                    String msg = String.Format("ID为{0}的控件超出当前页面{1}的显示范围", svCtrl.Id, widget.PageName);
                    throw new SVCheckValidException(msg);
                }
            }
        }
Beispiel #5
0
        /*
         * 检查当前页面中,多个控件之间是否有重叠的情况
         * 如果控件之间有重叠,将抛出异常 SVCheckValidException
         **/
        void checkOverlapping(SVPageWidget widget)
        {
            foreach (Control ctrl in widget.Controls)
            {
                foreach (Control child in widget.Controls)
                {
                    ///如果是同一个控件,就排除
                    if (ctrl == child)
                    {
                        continue;
                    }

                    //排除直线控件的相交情况
                    if (ctrl is SVLine || child is SVLine)
                    {
                        continue;
                    }

                    SVPanel svCtrl  = ctrl as SVPanel;
                    SVPanel svChild = child as SVPanel;

                    ///过滤控件类型
                    if (svCtrl == null || svChild == null)
                    {
                        continue;
                    }

                    int left1   = ctrl.Location.X;
                    int right1  = ctrl.Location.X + ctrl.Width;
                    int top1    = ctrl.Location.Y;
                    int bottom1 = ctrl.Location.Y + ctrl.Height;

                    int left2   = child.Location.X;
                    int right2  = child.Location.X + child.Width;
                    int top2    = child.Location.Y;
                    int bottom2 = child.Location.Y + child.Height;

                    if (!(right1 < left2 || left1 > right2 || bottom1 < top2 || top1 > bottom2))
                    {
                        String msg = String.Format("{0}页面中的,控件{1} 和 控件{2} 产生重叠", widget.PageName, svCtrl.Id, svChild.Id);
                        throw new SVCheckValidException(msg);
                    }
                }
            }
        }
Beispiel #6
0
        //检查ID是否重复
        void checkIDRepeat()
        {
            ///用来保存当前工程中已经遍历的页面和控件的ID及名称
            Dictionary <Int32, String> dict    = new Dictionary <Int32, String>();
            HashSet <UInt16>           hashSet = new HashSet <UInt16>();

            foreach (var item in SVGlobalData.PageContainer)
            {
                SVPageWidget widget   = item.Value;
                String       pageText = widget.PageName;

                ///检查页面ID是否发生重复
                if (dict.ContainsKey(widget.Attrib.id))
                {
                    String msg = String.Format(dict[widget.Attrib.id] + "和页面{0}的ID重复", pageText);
                    throw new SVCheckValidException(msg);
                }

                ///保存页面ID
                dict.Add(widget.Attrib.id, String.Format("页面{0}", pageText));

                hashSet.Clear();
                ///遍历页面中的所有子控件
                foreach (var contrl in widget.Controls)
                {
                    ///过滤不是定义的控件
                    SVPanel panel = contrl as SVPanel;
                    if (panel == null)
                    {
                        continue;
                    }

                    ///当前控件ID是否存在
                    if (hashSet.Contains(panel.Id))
                    {
                        String msg = String.Format("页面[{0}]存在重复的ID号, 值为:{1}", pageText, panel.Id);
                        throw new SVCheckValidException(msg);
                    }

                    hashSet.Add(panel.Id);
                }
            }
        }
        /// <summary>
        /// 确定
        /// </summary>
        /// <param Name="sender"></param>
        /// <param Name="e"></param>
        private void okBtn_Click(object sender, EventArgs e)
        {
            SVPageNode node = _svTreeView.SelectedNode as SVPageNode;

            if (node == null || node.Level != 2)
            {
                SVMessageBox msgBox = new SVMessageBox();
                msgBox.content(Resource.提示, Resource.请选择页面);
                msgBox.ShowDialog();
                return;
            }

            SVPageWidget widget = node.Addtionobj as SVPageWidget;
            ///模板文件
            String file = Path.Combine(SVProData.TemplatePath, node.Text);

            if (File.Exists(file))
            {
                SVMessageBox msgBox = new SVMessageBox();
                msgBox.content(Resource.提示, node.Text + " " + Resource.模板已经存在);
                msgBox.ShowDialog();
                return;
            }

            //保存文件
            SVXml pageXML = new SVXml();

            pageXML.createRootEle("Page");
            widget.saveXML(pageXML);
            pageXML.writeXml(file);

            //保存缩略图
            Bitmap ctlbitmap = new Bitmap(widget.Width, widget.Height);

            widget.DrawToBitmap(ctlbitmap, widget.ClientRectangle);
            ctlbitmap.Save(file + ".jpg");

            //记录日志
            SVLog.WinLog.Info(String.Format("模板{0}保存成功", node.Text));

            this.DialogResult = System.Windows.Forms.DialogResult.Yes;
        }
Beispiel #8
0
        //检查控件数量是否正确,并且包含检查每个控件本身
        void checkControlCount()
        {
            ///判断当前页面数是否超出最大范围
            if (SVGlobalData.PageContainer.Count > SVLimit.MAX_PAGE_NUMBER)
            {
                String msg = String.Format("最大页面数为{0},当前总页面数为{1}", SVLimit.MAX_PAGE_NUMBER, SVGlobalData.PageContainer.Count);
                throw new SVCheckValidException(msg);
            }

            ///循环判断每一页面
            foreach (var item in SVGlobalData.PageContainer)
            {
                SVPageWidget widget = item.Value;
                checkOverlapping(widget);
                checkOutOfRange(widget);

                ///所有计数都为0
                Int32 btnCount    = 0;
                Int32 labelCount  = 0;
                Int32 iconCount   = 0;
                Int32 gifCount    = 0;
                Int32 lineCount   = 0;
                Int32 analogCount = 0;
                Int32 binaryCount = 0;
                Int32 trendCount  = 0;
                Int32 heartCount  = 0;

                //检查每个控件本身属性
                foreach (var contrl in widget.Controls)
                {
                    SVPanel panel = contrl as SVPanel;
                    if (panel == null)
                    {
                        continue;
                    }

                    ///对每一种控件进行计数
                    if (panel is SVButton)
                    {
                        btnCount++;
                    }
                    else if (panel is SVLabel)
                    {
                        labelCount++;
                    }
                    else if (panel is SVLine)
                    {
                        lineCount++;
                    }
                    else if (panel is SVIcon)
                    {
                        iconCount++;
                    }
                    else if (panel is SVGif)
                    {
                        gifCount++;
                    }
                    else if (panel is SVAnalog)
                    {
                        analogCount++;
                    }
                    else if (panel is SVBinary)
                    {
                        binaryCount++;
                    }
                    else if (panel is SVHeartbeat)
                    {
                        heartCount++;
                    }
                    else if (panel is SVCurve)
                    {
                        trendCount++;
                    }

                    ///判断当前控件个数是否合法
                    if (btnCount > SVLimit.PAGE_BTN_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的按钮个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (labelCount > SVLimit.PAGE_AREA_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的文本个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (lineCount > SVLimit.PAGE_LINE_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的线条个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (iconCount > SVLimit.PAGE_ICON_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的静态图个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (gifCount > SVLimit.PAGE_GIF_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的静态图个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (analogCount > SVLimit.PAGE_ANA_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的模拟量个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (binaryCount > SVLimit.PAGE_BOOL_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的开关量个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (trendCount > SVLimit.PAGE_TCHART_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的趋势图个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    if (heartCount > SVLimit.PAGE_TICKGIF_MAXNUM)
                    {
                        String msg = String.Format("页面{0}中的心跳控件个数超出最大值!", widget.PageName);
                        throw new SVCheckValidException(msg);
                    }

                    ///单个控件判断
                    panel.checkValid();
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 通过变量名称来查找对应控件
        /// </summary>
        /// <param oldName="findString">变量名称</param>
        private void findStr(string findString)
        {
            if (String.IsNullOrWhiteSpace(findString))
            {
                return;
            }

            _findView.Clear();
            _findView.AppendText("---------------查找结果如下:-----------------\n");
            _findView.AppendText("\n");

            foreach (SVPageNode pageNode in _treeView.Nodes)
            {
                foreach (TreeNode classItem in pageNode.Nodes)
                {
                    foreach (SVPageNode item in classItem.Nodes)
                    {
                        SVPageWidget widget = item.Addtionobj as SVPageWidget;
                        if (widget == null)
                        {
                            continue;
                        }

                        foreach (var panel in widget.Controls)
                        {
                            //如果为按钮
                            if (panel is SVButton)
                            {
                                SVButton button = (SVButton)panel;
                                String   str    = button.Attrib.BtnVarText.VarName;
                                outputFindResult(button, str);

                                str = button.Attrib.EnVarText.VarName;
                                outputFindResult(button, str);
                            }

                            //如果为模拟量
                            if (panel is SVAnalog)
                            {
                                SVAnalog analog = (SVAnalog)panel;
                                String   str    = analog.Attrib.Variable.VarName;
                                outputFindResult(analog, str);
                            }

                            //如果为开关量
                            if (panel is SVBinary)
                            {
                                SVBinary binary = (SVBinary)panel;
                                String   str    = binary.Attrib.Variable.VarName;
                                outputFindResult(binary, str);
                            }

                            //动态图
                            if (panel is SVGif)
                            {
                                SVGif gif = (SVGif)panel;
                                foreach (var str in gif.Attrib.VarName)
                                {
                                    outputFindResult(gif, str);
                                }
                            }

                            //趋势图
                            if (panel is SVCurve)
                            {
                                SVCurve curve = (SVCurve)panel;
                                foreach (var str in curve.Attrib.Variable)
                                {
                                    outputFindResult(curve, str.Var.VarName);
                                }
                            }
                        }
                    }
                }
            }

            if (!_findView.isMatches())
            {
                _findView.AppendText("没有找到符合条件的相关内容!");
            }
        }