Пример #1
0
        /// <summary>
        /// 存储控件信息
        /// </summary>
        /// <param name="_ctrl"></param>
        public static bool Store(ControlClass _ctrl)
        {
            //是否对DataGridView具有列数据限制
            bool flag = false;

            if (_ctrl == null)
            {
                return false;
            }

            string _namespace = _ctrl._NameSpace;
            string _class = _ctrl._Class;
            string _control = _ctrl._Name;
            int _index = 0;
            string _type = string.Empty;

            switch (_ctrl._ControlType)
            {
                case "TextBox":
                    //当前不存储TextBox数据类型
                    //AttrTextBox attr = _ctrl._Attr as AttrTextBox;
                    //_index = attr.Attr.Index;
                    //_type = attr.Attr.DataType;
                    //Store(_namespace, _class, _control, _index, _type);
                    flag = false;
                    break;
                case "DataGridView":
                    AttrDataGridView attr = _ctrl._Attr as AttrDataGridView;

                    for (int i = 0; i < attr.Attr.Count; i++)
                    {
                        _index = attr.Attr[i].Index;
                        _type = attr.Attr[i].DataType;

                        //忽略一致性检测
                        if (_index == -1 || _type.Equals("CONSISTENCY"))
                            continue;

                        //具有列数据限制
                        flag = Store(_namespace, _class, _control, _index, _type);
                    }
                    break;
                default:
                    flag = false;
                    break;
            }

            return flag;
        }
Пример #2
0
        /// <summary>
        /// 判断按钮对应的控件是否有空值
        /// </summary>
        /// <param name="btnClass">按钮控件实体类</param>
        /// <returns></returns>
        private static bool HasCtrlsNull(ButtonClass btnClass)
        {
            bool flag = false;

            if (btnClass._Controls == null || btnClass._Controls.Count < 0)
            {
                //窗体中所有控件
                Form FormOwner = UtilClass.SearchOwner(btnClass._FrmControl) as Form;
                List<Control> FormControls = UtilClass.InitControls(FormOwner);

                string[] ctrlTmps = btnClass._CtrlStr.Split(',');

                foreach (string item in ctrlTmps)
                {
                    Control FormControl = FormControls.Where(n => n.Name.Equals(item)).FirstOrDefault();

                    if (FormControl != null && FormControl.Name.Equals(item))
                    {
                        ControlClass SubCtrl = new ControlClass();
                        SubCtrl._NameSpace = btnClass._NameSpace;
                        SubCtrl._Class = btnClass._Class;
                        SubCtrl._Name = item;
                        SubCtrl._ControlType = FormControl.GetType().Name;
                        SubCtrl._FrmControl = FormControl;

                        btnClass._Controls.Add(SubCtrl);
                    }
                }
            }

            string tipFailureMsg = "请完整输入必填项信息!";
            string tipSuccessMsg = string.Empty;
            if (null != btnClass._Tips[1])
            {
                tipFailureMsg = btnClass._Tips[1].ToString();
            }
            if (null != btnClass._Tips[0])
            {
                tipSuccessMsg = btnClass._Tips[0].ToString();
            }

            foreach (ControlClass item in btnClass._Controls)
            {
                //Control ctrl = item._FrmControl;
                //获取窗体对应控件
                Control ctrl = item._FrmControl;
                if (ctrl != null)
                {
                    switch (item._ControlType.Trim().ToLower())
                    {
                        case "textbox":
                            TextBox textBox = ctrl as TextBox;
                            if (string.IsNullOrEmpty(textBox.Text))
                            {
                                if (IsCommentShow)
                                {
                                    TipForm tip = new TipForm(btnClass._FrmControl, tipFailureMsg);
                                    tip.Show();

                                    //设置焦点
                                    textBox.Focus();
                                }

                                flag = true;

                                //切换到指定TabPage
                                TabPage tabPage = UtilClass.SearchOwnerTabPage(ctrl) as TabPage;
                                TabControl tabControl = tabPage.Parent as TabControl;
                                if (tabControl.SelectedTab != tabPage)
                                {
                                    tabControl.SelectedTab = tabPage;
                                }
                                break;
                            }
                            break;
                        case "datagridview":
                            DataGridView grid = ctrl as DataGridView;
                            if (grid.Rows.Count <= 0 || grid.NewRowIndex == 0)
                            {
                                if (IsCommentShow)
                                {
                                    TipForm tip = new TipForm(btnClass._FrmControl, tipFailureMsg);
                                    tip.Show();

                                    grid.Focus();
                                }
                                flag = true;

                                //切换到指定TabPage
                                TabPage tabPage = UtilClass.SearchOwnerTabPage(ctrl) as TabPage;
                                TabControl tabControl = tabPage.Parent as TabControl;
                                if (tabControl.SelectedTab != tabPage)
                                {
                                    tabControl.SelectedTab = tabPage;
                                }
                            }

                            //判断必填数据列
                            if (grid.Rows.Count > 0)
                            {
                                int ColCount = grid.Columns.Count;

                                //获取DataGridView必填数据列索引
                                List<int> ColIndex = item._NotNullIndex;

                                foreach (DataGridViewRow row in grid.Rows)
                                {
                                    //忽略新行
                                    if (row.Index == grid.NewRowIndex)
                                        continue;

                                    for (int c = 0; c < ColIndex.Count; c++)
                                    {
                                        if (row.Cells[ColIndex[c]].Value == null || string.IsNullOrEmpty(row.Cells[ColIndex[c]].Value.ToString()))
                                        {
                                            flag = true;

                                            //切换到指定TabPage
                                            TabPage tabPage = UtilClass.SearchOwnerTabPage(ctrl) as TabPage;
                                            TabControl tabControl = tabPage.Parent as TabControl;
                                            if (tabControl.SelectedTab != tabPage)
                                            {
                                                tabControl.SelectedTab = tabPage;
                                            }

                                            TipForm tip = new TipForm(grid, string.Format("DataGridView的第{0}列不能为空!", ColIndex[c] + 1));
                                            tip.Show();

                                            grid.CurrentCell = row.Cells[ColIndex[c]];
                                            grid.BeginEdit(true);

                                            break;
                                        }
                                    }
                                    if (flag)
                                    {
                                        break;  //若一出现空数据,即刻跳出循环
                                    }
                                }
                            }
                            break;
                        default:

                            break;
                    }
                }

                if (flag)
                {
                    ////切换到指定TabPage
                    //TabPage tabPage = UtilClass.SearchOwnerTabPage(ctrl) as TabPage;

                    //TabControl tabControl = tabPage.Parent as TabControl;

                    //if (tabControl.SelectedTab != tabPage)
                    //{
                    //    tabControl.SelectedTab = tabPage;
                    //}

                    break;  //出现没有填内容的直接跳出循环
                }
            }

            if (!flag)
            {
                if (!string.IsNullOrEmpty(tipSuccessMsg))
                {
                    TipForm tip = new TipForm(btnClass._FrmControl, tipSuccessMsg);
                    tip.Show();
                }
            }

            return flag;
        }
Пример #3
0
        /// <summary>
        /// 查询数据类型
        /// </summary>
        /// <param name="_ctrl">指定控件实体类</param>
        /// <param name="_index">列索引</param>
        /// <returns></returns>
        public static string Query(ControlClass _ctrl, int _index)
        {
            string _namespace = _ctrl._NameSpace;
            string _class = _ctrl._Class;
            string _control = _ctrl._Name;

            return Query(_namespace, _class, _control, _index);
        }
Пример #4
0
        /// <summary>
        /// 从Node获取控件实体
        /// </summary>
        /// <param name="_xmlpath">Xml文件路径</param>
        /// <param name="node">节点信息</param>
        /// <param name="frmCtrl">对应窗体中的控件</param>
        /// <returns></returns>
        private static BaseCtrl GetControl(string _xmlpath, XmlNode node, Control frmCtrl = null)
        {
            BaseCtrl ctrl;

            //查找到节点
            if (node != null)
            {
                if (xmlHelper.IsAttrExist(node, "controltype"))
                {

                    #region 以前版本
                    string controlType = node.Attributes["controltype"].Value.Trim();
                    switch (controlType.ToLower())
                    {
                        case "textbox":
                            {
                                ControlClass c = new ControlClass();

                                //命名空间
                                if (xmlHelper.IsAttrExist(node, "namespace"))
                                {
                                    c._NameSpace = node.Attributes["namespace"].Value.Trim();
                                }
                                else if (node.ParentNode != null && node.ParentNode.ParentNode != null)
                                {
                                    XmlNode NameSpaceNode = node.ParentNode.ParentNode;
                                    c._NameSpace = NameSpaceNode.Name;
                                }
                                //类
                                if (xmlHelper.IsAttrExist(node, "class"))
                                {
                                    c._Class = node.Attributes["class"].Value.Trim();
                                }
                                else if (node.ParentNode != null)
                                {
                                    XmlNode ClassNode = node.ParentNode;
                                    c._Class = ClassNode.Name;
                                }
                                //控件
                                if (!string.IsNullOrEmpty(node.Name))
                                {
                                    c._Name = node.Name.Trim();
                                }
                                //控件类型
                                c._ControlType = controlType;
                                //数据类型
                                if (xmlHelper.IsAttrExist(node, "datatype"))
                                {
                                    string typename = node.Attributes["datatype"].Value.Trim();

                                    CtrlAttr attr = GetAttr(_xmlpath, c._ControlType, typename);

                                    if (attr != null)
                                    {
                                        c._TypeName = typename;
                                        c._Attr = attr;
                                    }
                                    else
                                    {
                                        MessageBox.Show("没有找到指定类型名的数据类型!");
                                    }
                                }
                                //事件类型
                                if (xmlHelper.IsAttrExist(node, "eventtype"))
                                {
                                    c._EventType = node.Attributes["eventtype"].Value.Trim().ToUpper();
                                }
                                //if (!string.IsNullOrEmpty(node.Attributes["requiretype"].Value))
                                //{
                                //    c._RequireType = node.Attributes["requiretype"].Value.Trim();
                                //}

                                if (frmCtrl != null && frmCtrl.Name.Equals(c._Name))
                                {
                                    c._FrmControl = frmCtrl;
                                }

                                ctrl = c;
                            }
                            break;
                        case "datagridview":
                            {
                                ControlClass c = new ControlClass();

                                //命名空间
                                if (xmlHelper.IsAttrExist(node, "namespace"))
                                {
                                    c._NameSpace = node.Attributes["namespace"].Value.Trim();
                                }
                                else if (node.ParentNode != null && node.ParentNode.ParentNode != null)
                                {
                                    XmlNode NameSpaceNode = node.ParentNode.ParentNode;
                                    c._NameSpace = NameSpaceNode.Name;
                                }
                                //类
                                if (xmlHelper.IsAttrExist(node, "class"))
                                {
                                    c._Class = node.Attributes["class"].Value.Trim();
                                }
                                else if (node.ParentNode != null)
                                {
                                    XmlNode ClassNode = node.ParentNode.ParentNode;
                                    c._Class = ClassNode.Name;
                                }
                                //控件
                                if (!string.IsNullOrEmpty(node.Name))
                                {
                                    c._Name = node.Name.Trim();
                                }
                                //控件类型
                                c._ControlType = controlType;
                                //数据类型
                                if (xmlHelper.IsAttrExist(node, "datatype"))
                                {
                                    string typename = node.Attributes["datatype"].Value.Trim();

                                    CtrlAttr attr = GetAttr(_xmlpath, c._ControlType, typename);

                                    if (attr != null)
                                    {
                                        c._TypeName = typename;
                                        c._Attr = attr;
                                    }
                                    else
                                    {
                                        MessageBox.Show("没有找到指定类型名的数据类型!");
                                    }
                                }
                                //获取DataGridView数据列可空限制
                                if (!string.IsNullOrEmpty(node.Attributes["notnullindex"].Value.Trim()))
                                {
                                    string tmp = node.Attributes["notnullindex"].Value.Trim();
                                    tmp.Replace(',', ',');

                                    string[] indexTemp = tmp.Split(',');

                                    foreach (string item in indexTemp)
                                    {
                                        int idx;
                                        if (Int32.TryParse(item.Trim(), out idx))
                                        {
                                            c._NotNullIndex.Add(idx);
                                        }
                                        else
                                        {
                                            MessageBox.Show("DataGridView:" + c._Name + "非空列索引有误!");
                                        }
                                    }

                                    //string typename = node.Attributes["nulltype"].Value.Trim();

                                    //CtrlAttr atemp = GetAttr(_xmlpath, c._ControlType, typename);

                                    //if (atemp != null && atemp is AttrDataGridView)
                                    //{
                                    //    AttrDataGridView gTemp = atemp as AttrDataGridView;

                                    //    foreach (AttrInfo item in gTemp.Attr)
                                    //    {
                                    //        c._NullType.Add(item);
                                    //    }
                                    //}

                                }

                                if (frmCtrl != null && frmCtrl.Name.Equals(c._Name))
                                {
                                    c._FrmControl = frmCtrl;
                                }

                                ctrl = c;
                            }
                            break;
                        case "button":
                            {
                                ButtonClass btn = new ButtonClass();

                                //命名空间
                                if (xmlHelper.IsAttrExist(node, "namespace"))
                                {
                                    btn._NameSpace = node.Attributes["namespace"].Value.Trim();
                                }
                                else if (node.ParentNode != null && node.ParentNode.ParentNode != null)
                                {
                                    XmlNode NameSpaceNode = node.ParentNode.ParentNode;
                                    btn._NameSpace = NameSpaceNode.Name;
                                }
                                //类
                                if (xmlHelper.IsAttrExist(node, "class"))
                                {
                                    btn._Class = node.Attributes["class"].Value.Trim();
                                }
                                else if (node.ParentNode != null)
                                {
                                    XmlNode ClassNode = node.ParentNode;
                                    btn._Class = ClassNode.Name;
                                }
                                //控件
                                if (!string.IsNullOrEmpty(node.Name))
                                {
                                    btn._Name = node.Name.Trim();
                                }
                                //控件类型
                                btn._ControlType = controlType;
                                //验证控件
                                if (xmlHelper.IsAttrExist(node, "controls"))
                                {
                                    //edit by dwq 2015-06-12 按钮数据实体需要关联当前窗体控件
                                    btn._CtrlStr = node.Attributes["controls"].Value.Trim();

                                    //窗体中所有控件
                                    Form FormOwner = UtilClass.SearchOwner(frmCtrl) as Form;
                                    List<Control> FormControls = UtilClass.InitControls(FormOwner);

                                    string[] ctrlTmps = node.Attributes["controls"].Value.Trim().Split(',');

                                    foreach (string item in ctrlTmps)
                                    {
                                        Control FormControl = FormControls.Where(n => n.Name.Equals(item)).FirstOrDefault();

                                        if (FormControl != null && FormControl.Name.Equals(item))
                                        {
                                            ControlClass SubCtrl = new ControlClass();
                                            SubCtrl._NameSpace = btn._NameSpace;
                                            SubCtrl._Class = btn._Class;
                                            SubCtrl._Name = item;
                                            SubCtrl._ControlType = FormControl.GetType().Name;
                                            SubCtrl._FrmControl = FormControl;

                                            btn._Controls.Add(SubCtrl);
                                        }
                                    }
                                }
                                //提示信息
                                if (xmlHelper.IsAttrExist(node, "tip"))
                                {
                                    string tipname = node.Attributes["tip"].Value.ToString().Trim();

                                    btn._TipName = tipname;
                                    btn._Tips = GetTip(_xmlpath, tipname);
                                }

                                if (frmCtrl != null && frmCtrl.Name.Equals(btn._Name))
                                {
                                    btn._FrmControl = frmCtrl;
                                }

                                ctrl = btn;
                            }
                            break;
                        default:
                            ctrl = null;
                            break;
                    }
                    #endregion
                }
                else
                {
                    #region Xml精简后
                    if (frmCtrl != null)
                    {
                        string ctrlType = frmCtrl.GetType().Name;
                        switch (ctrlType.ToLower())
                        {
                            case "textbox":
                                {
                                    ControlClass c = new ControlClass();

                                    //命名空间
                                    if (xmlHelper.IsAttrExist(node, "namespace"))
                                    {
                                        c._NameSpace = node.Attributes["namespace"].Value.Trim();
                                    }
                                    else if (node.ParentNode != null && node.ParentNode.ParentNode != null)
                                    {
                                        XmlNode NameSpaceNode = node.ParentNode.ParentNode;
                                        c._NameSpace = NameSpaceNode.Name;
                                    }
                                    //类
                                    if (xmlHelper.IsAttrExist(node, "class"))
                                    {
                                        c._Class = node.Attributes["class"].Value.Trim();
                                    }
                                    else if (node.ParentNode != null)
                                    {
                                        XmlNode ClassNode = node.ParentNode;
                                        c._Class = ClassNode.Name;
                                    }
                                    //控件
                                    if (!string.IsNullOrEmpty(node.Name))
                                    {
                                        c._Name = node.Name.Trim();
                                    }
                                    //控件类型
                                    c._ControlType = ctrlType;
                                    //数据类型
                                    if (xmlHelper.IsAttrExist(node, "datatype"))
                                    {
                                        string typename = node.Attributes["datatype"].Value.Trim();

                                        CtrlAttr attr = GetAttr(_xmlpath, c._ControlType, typename);

                                        if (attr != null)
                                        {
                                            c._TypeName = typename;
                                            c._Attr = attr;
                                        }
                                        else
                                        {
                                            MessageBox.Show("没有找到指定类型名的数据类型!");
                                        }
                                    }
                                    //事件类型
                                    if (xmlHelper.IsAttrExist(node, "eventtype"))
                                    {
                                        c._EventType = node.Attributes["eventtype"].Value.Trim().ToUpper();
                                    }
                                    //if (!string.IsNullOrEmpty(node.Attributes["requiretype"].Value))
                                    //{
                                    //    c._RequireType = node.Attributes["requiretype"].Value.Trim();
                                    //}
                                    if (frmCtrl != null && frmCtrl.Name.Equals(c._Name))
                                    {
                                        c._FrmControl = frmCtrl;
                                    }

                                    ctrl = c;
                                }
                                break;
                            case "datagridview":
                                {
                                    ControlClass c = new ControlClass();

                                    //命名空间
                                    if (xmlHelper.IsAttrExist(node, "namespace"))
                                    {
                                        c._NameSpace = node.Attributes["namespace"].Value.Trim();
                                    }
                                    else if (node.ParentNode != null && node.ParentNode.ParentNode != null)
                                    {
                                        XmlNode NameSpaceNode = node.ParentNode.ParentNode;
                                        c._NameSpace = NameSpaceNode.Name;
                                    }
                                    //类
                                    if (xmlHelper.IsAttrExist(node, "class"))
                                    {
                                        c._Class = node.Attributes["class"].Value.Trim();
                                    }
                                    else if (node.ParentNode != null)
                                    {
                                        XmlNode ClassNode = node.ParentNode.ParentNode;
                                        c._Class = ClassNode.Name;
                                    }
                                    //控件
                                    if (!string.IsNullOrEmpty(node.Name))
                                    {
                                        c._Name = node.Name.Trim();
                                    }
                                    //控件类型
                                    c._ControlType = ctrlType;
                                    //数据类型
                                    if (xmlHelper.IsAttrExist(node, "datatype"))
                                    {
                                        string typename = node.Attributes["datatype"].Value.Trim();

                                        CtrlAttr attr = GetAttr(_xmlpath, c._ControlType, typename);

                                        if (attr != null)
                                        {
                                            c._TypeName = typename;
                                            c._Attr = attr;
                                        }
                                        else
                                        {
                                            MessageBox.Show("没有找到指定类型名的数据类型!");
                                        }
                                    }
                                    //获取DataGridView数据列可空限制
                                    if (!string.IsNullOrEmpty(node.Attributes["notnullindex"].Value.Trim()))
                                    {
                                        string tmp = node.Attributes["notnullindex"].Value.Trim();
                                        tmp.Replace(',', ',');

                                        string[] indexTemp = tmp.Split(',');

                                        foreach (string item in indexTemp)
                                        {
                                            int idx;
                                            if (Int32.TryParse(item.Trim(), out idx))
                                            {
                                                c._NotNullIndex.Add(idx);
                                            }
                                            else
                                            {
                                                MessageBox.Show("DataGridView:" + c._Name + "非空列索引有误!");
                                            }
                                        }

                                        //string typename = node.Attributes["nulltype"].Value.Trim();

                                        //CtrlAttr atemp = GetAttr(_xmlpath, c._ControlType, typename);

                                        //if (atemp != null && atemp is AttrDataGridView)
                                        //{
                                        //    AttrDataGridView gTemp = atemp as AttrDataGridView;

                                        //    foreach (AttrInfo item in gTemp.Attr)
                                        //    {
                                        //        c._NullType.Add(item);
                                        //    }
                                        //}

                                    }

                                    if (frmCtrl != null && frmCtrl.Name.Equals(c._Name))
                                    {
                                        c._FrmControl = frmCtrl;
                                    }

                                    ctrl = c;
                                }
                                break;
                            case "button":
                                {
                                    ButtonClass btn = new ButtonClass();

                                    //命名空间
                                    if (xmlHelper.IsAttrExist(node, "namespace"))
                                    {
                                        btn._NameSpace = node.Attributes["namespace"].Value.Trim();
                                    }
                                    else if (node.ParentNode != null && node.ParentNode.ParentNode != null)
                                    {
                                        XmlNode NameSpaceNode = node.ParentNode.ParentNode;
                                        btn._NameSpace = NameSpaceNode.Name;
                                    }
                                    //类
                                    if (xmlHelper.IsAttrExist(node, "class"))
                                    {
                                        btn._Class = node.Attributes["class"].Value.Trim();
                                    }
                                    else if (node.ParentNode != null)
                                    {
                                        XmlNode ClassNode = node.ParentNode;
                                        btn._Class = ClassNode.Name;
                                    }
                                    //控件
                                    if (!string.IsNullOrEmpty(node.Name))
                                    {
                                        btn._Name = node.Name.Trim();
                                    }
                                    //控件类型
                                    btn._ControlType = ctrlType;
                                    //验证控件
                                    if (xmlHelper.IsAttrExist(node, "controls"))
                                    {
                                        //edit by dwq 2015-06-12 按钮数据实体需要关联当前窗体控件
                                        btn._CtrlStr = node.Attributes["controls"].Value.Trim();

                                        //窗体中所有控件
                                        Form FormOwner = UtilClass.SearchOwner(frmCtrl) as Form;
                                        List<Control> FormControls = UtilClass.InitControls(FormOwner);

                                        string[] ctrlTmps = node.Attributes["controls"].Value.Trim().Split(',');

                                        foreach (string item in ctrlTmps)
                                        {
                                            Control FormControl = FormControls.Where(n => n.Name.Equals(item)).FirstOrDefault();

                                            if (FormControl != null && FormControl.Name.Equals(item))
                                            {
                                                if (FormControl.GetType().Name.Equals("TextBox"))
                                                {
                                                    ControlClass SubCtrl = new ControlClass();
                                                    SubCtrl._NameSpace = btn._NameSpace;
                                                    SubCtrl._Class = btn._Class;
                                                    SubCtrl._Name = item;
                                                    SubCtrl._ControlType = FormControl.GetType().Name;
                                                    SubCtrl._FrmControl = FormControl;

                                                    btn._Controls.Add(SubCtrl);
                                                }
                                                else if (FormControl.GetType().Name.Equals("DataGridView"))
                                                {
                                                    ControlClass SubCtrl = GetControl(_xmlpath, btn._NameSpace, btn._Class, FormControl) as ControlClass;

                                                    btn._Controls.Add(SubCtrl);
                                                }
                                            }
                                        }
                                    }
                                    //提示信息
                                    if (xmlHelper.IsAttrExist(node, "tip"))
                                    {
                                        string tipname = node.Attributes["tip"].Value.ToString().Trim();

                                        btn._TipName = tipname;
                                        btn._Tips = GetTip(_xmlpath, tipname);
                                    }

                                    if (frmCtrl != null && frmCtrl.Name.Equals(btn._Name))
                                    {
                                        btn._FrmControl = frmCtrl;
                                    }

                                    ctrl = btn;
                                }
                                break;
                            default:
                                ctrl = null;
                                break;
                        }
                    }
                    else
                    {
                        ctrl = null;
                    }
                    #endregion
                }
            }
            else
            {
                //node==null

                ctrl = null;
            }

            return ctrl;
        }