コード例 #1
0
        /// <summary>
        /// 打开数据库框架
        /// </summary>
        internal void OpenDBFramework()
        {
            DBFramework dbf   = new DBFramework();
            var         child = new XtnChildWindow(this._IDesignFramework, dbf);

            child.Closed += child_Closed;
            child.Show();
        }
コード例 #2
0
        void child_Closed(object sender, EventArgs e)
        {
            var child = (sender as XtnChildWindow);

            if (true != child.DialogResult)
            {
                return;
            }
            DBFramework dbf = child.GetControl as DBFramework;
            var         mdi = dbf.GetMetaDataInfo;

            if (null == mdi || 0 == mdi.Item.Count)
            {
                return;
            }
            //-->判断tableName是否已经增加了
            MetaDataInfo old_mdi = GetMetaDataInfoByTableName(mdi.table_name);

            if (null == old_mdi)
            {
                _XmlTemplate.MetaDataItem.Add(mdi);
            }
            //-->增加控件
            _XmlTemplate.BaseInfo.SerialNum++;
            int                         SerialNum   = _XmlTemplate.BaseInfo.SerialNum;
            double                      top         = 0;
            double                      left        = 30;
            double                      maxWidth    = 0;
            List <String>               columns     = new List <string>();
            List <FrameworkElement>     feItem      = new List <FrameworkElement>();
            Dictionary <String, String> dictTopLeft = new Dictionary <string, string>();

            MetaDataInfo ctrlMetaData = new MetaDataInfo();

            ctrlMetaData.table_name    = mdi.table_name;
            ctrlMetaData.table_comment = mdi.table_comment;
            ctrlMetaData.table_type    = mdi.table_type;

            foreach (var ctrl in mdi.Item)
            {
                if (!ctrl.IsChoose)
                {
                    continue;
                }
                ctrlMetaData.Item = new List <MetaDataColumnInfo>();
                ctrlMetaData.Item.Add(ctrl);
                var    fe          = Wrapper.CreateCtrl <FrameworkElement>(ctrl.control_type);
                string controlName = string.Format("Form{0}_{1}", SerialNum, ctrl.column_name);
                fe.Name = controlName;
                this.DesignPage.AddChild(fe, false);
                feItem.Add(fe);
                UpdateXaml(fe);
                UpdateXml(fe, ctrl.column_name, ctrl.column_comment, mdi.table_name, string.Format("Form{0}", SerialNum), ctrlMetaData);
                double _maxWidth = GetCharWidth(ctrl.column_comment, this.FontSize, this.FontFamily, this.FontWeight);
                maxWidth = _maxWidth > maxWidth ? _maxWidth : maxWidth;
                columns.Add(ctrl.column_name);
                //-->修改期坐标位置
                if ((top + 30 + fe.Height + 30) < DesignPage.ActualHeight)
                {
                    top += 30;
                }
                else
                {
                    top = 30;
                    if ((left + 190) < DesignPage.ActualWidth)
                    {
                        left += 190;
                    }
                }
                dictTopLeft.Add(controlName, string.Format("{0};{1}", top, left));
                fe.SetValue(Canvas.LeftProperty, left);
                fe.SetValue(Canvas.TopProperty, top);
            }
            foreach (var v in feItem)
            {
                if (v is ICompositeCtrl)
                {
                    (v as ICompositeCtrl).TitleWidth = (int)maxWidth + 1;
                    v.Width = (int)maxWidth + 100 + 1;
                    //-->修改xaml的位置坐标
                    string t_l       = dictTopLeft[v.Name];
                    string new_value = Wrapper.ModifyAttribute(_XamlTemplate.CanvasTemplate.Children[v.Name],
                                                               new KeyValuePair <String, Object>[] {
                        new KeyValuePair <String, Object>("Canvas.Top", t_l.Split(';')[0]),
                        new KeyValuePair <String, Object>("Canvas.Left", t_l.Split(';')[1]),
                        new KeyValuePair <String, Object>("Width", v.Width),
                        new KeyValuePair <String, Object>("TitleWidth", (int)maxWidth + 1),
                    });
                    _XamlTemplate.CanvasTemplate.Children[v.Name] = new_value;
                }
            }
            feItem.Clear();
            dictTopLeft.Clear();
            //-->创建一个虚拟控件
            ControlInfo ci = new ControlInfo();

            ci.Name           = string.Format("Form{0}", SerialNum);
            ci.ColumnName     = string.Join("|", columns);
            ci.MetaData       = mdi.table_name;
            ci.Comment        = mdi.table_comment;
            ci.ControlType    = ConstantCollection.FORM_PREFIX;
            ci.ParentCtrlName = "LayoutRoot";
            ci.Type           = ConstantCollection.FORM_PREFIX;//
            //ci.ControlDataSourceTableName = mdi.table_name;
            _XmlTemplate.ControlItem.Add(ci);

            this.Xaml_Template = _XamlTemplate.ParseXml().ToString();
            this.Xml_Template  = _XmlTemplate.ParseXml().ToString();

            UpdateControlTree();

            //-->释放窗体里的资源
            child.Closed -= child_Closed;
            child.Dispose();
        }