Exemplo n.º 1
0
        private void InitializeLayout(List <Sys_Layout> sys_Layouts, Control parentControl)
        {
            try
            {
                DataTable dt = (DataTable)gdb.DataSource;
                parentControl.Visible = false;
                parentControl.Controls.Clear();
                foreach (Sys_Layout sys_Layout in sys_Layouts.OrderBy(s => s.Layout_Sort))
                {
                    Control contain = parentControl;
                    if (!string.IsNullOrEmpty(sys_Layout.Layout_Parent))
                    {
                        Control[] cks = parentControl.Controls.Find(sys_Layout.Layout_Parent, true);
                        if (cks.Length > 0)
                        {
                            contain = cks[0];
                        }
                    }
                    contain.ControlAdded += delegate(object sender, ControlEventArgs e)
                    {
                        e.Control.Paint += Layout_SizeChanged;
                        e.Control.Click += Layout_Select;
                    };
                    switch (sys_Layout.Layout_Type)
                    {
                    case 0:     //Query
                        GroupControl qry = new GroupControl();
                        InitializeControl(qry, sys_Layout);
                        contain.Controls.Add(qry);
                        qry.BringToFront();
                        //this.QueryControl = qry;
                        break;

                    case 12:     //GroupControl
                        GroupControl grp = new GroupControl();
                        InitializeControl(grp, sys_Layout);
                        contain.Controls.Add(grp);
                        grp.BringToFront();
                        break;

                    case 14:     //PanelControl
                        PanelControl panel = new PanelControl();
                        InitializeControl(panel, sys_Layout);
                        contain.Controls.Add(panel);
                        panel.BorderStyle = BorderStyles.NoBorder;
                        panel.BringToFront();
                        break;

                    case 13:
                        SplitterControl OneSpli = new SplitterControl();
                        OneSpli.Dock = (DockStyle)sys_Layout.Layout_Dock;
                        OneSpli.Name = sys_Layout.Layout_Name;
                        contain.Controls.Add(OneSpli);
                        OneSpli.BringToFront();
                        break;

                    case 1:     //Grid
                    case 6:     //Submit
                    case 7:     //Tree    这三个都只有Grid 是在Grid上覆盖控件实现 Submit  和  Tree 效果
                        GridControl gd = new GridControl();
                        InitializeControl(gd, sys_Layout);
                        GridView gv = (GridView)gd.CreateView("GridView");
                        gv.Name = gd.Name.Replace("d", "v");
                        gv.OptionsView.ShowGroupPanel   = false;
                        gv.OptionsView.ShowFooter       = true;
                        gv.OptionsSelection.MultiSelect = true;
                        gd.MainView = gv;
                        contain.Controls.Add(gd);
                        gd.BringToFront();
                        break;

                    case 9:     //TabPage
                        TabEx ntabs = new TabEx();
                        InitializeControl(ntabs, sys_Layout);
                        ntabs.BorderStyle     = BorderStyles.NoBorder;
                        ntabs.BorderStylePage = BorderStyles.NoBorder;
                        contain.Controls.Add(ntabs);
                        ntabs.BringToFront();
                        break;

                    case 10:
                        DevExpress.XtraTab.XtraTabPage tab = new DevExpress.XtraTab.XtraTabPage();
                        tab.Name = sys_Layout.Layout_Name;
                        tab.Text = sys_Layout.Layout_Nick;
                        if (contain.GetType() == typeof(TabEx))
                        {
                            TabEx tabs = (TabEx)contain;
                            tabs.TabPages.Add(tab);
                        }
                        break;

                    case 11:
                        Pagination pagination = new Pagination();
                        pagination.Name = sys_Layout.Layout_Name;
                        pagination.Dock = (DockStyle)sys_Layout.Layout_Dock;
                        contain.Controls.Add(pagination);
                        pagination.BringToFront();
                        break;

                    case 2:     //Chart
                        ChartControl chart = new ChartControl();
                        InitializeControl(chart, sys_Layout);
                        chart.BorderOptions.Visibility = DevExpress.Utils.DefaultBoolean.False;
                        contain.Controls.Add(chart);
                        chart.BringToFront();
                        break;

                    case 3:    //text
                        MemoEdit memoEdit = new MemoEdit();
                        InitializeControl(memoEdit, sys_Layout);
                        memoEdit.BorderStyle = BorderStyles.NoBorder;
                        contain.Controls.Add(memoEdit);
                        memoEdit.BringToFront();
                        break;

                    case 4:    //RichText
                        RichEditControl rtf = new RichEditControl();
                        InitializeControl(rtf, sys_Layout);
                        rtf.BorderStyle    = BorderStyles.NoBorder;
                        rtf.ActiveViewType = RichEditViewType.Simple;
                        contain.Controls.Add(rtf);
                        rtf.BringToFront();
                        break;

                    case 5:     //image
                        PictureEdit pictureEdit = new PictureEdit();
                        InitializeControl(pictureEdit, sys_Layout);
                        pictureEdit.BorderStyle = BorderStyles.NoBorder;
                        pictureEdit.Properties.PictureStoreMode = PictureStoreMode.ByteArray;
                        pictureEdit.Properties.SizeMode         = PictureSizeMode.Squeeze;
                        contain.Controls.Add(pictureEdit);
                        pictureEdit.BringToFront();
                        break;

                    case 8:     //BarCode
                        BarCodeControl barCodeControl = new BarCodeControl();
                        InitializeControl(barCodeControl, sys_Layout);
                        barCodeControl.BorderStyle = BorderStyles.NoBorder;
                        barCodeControl.BackColor   = Color.White;
                        barCodeControl.AutoModule  = true;
                        barCodeControl.ShowText    = false;
                        //QRCodeGenerator
                        DevExpress.XtraPrinting.BarCode.QRCodeGenerator qrCodeGenerator1 = new DevExpress.XtraPrinting.BarCode.QRCodeGenerator();
                        qrCodeGenerator1.CompactionMode       = DevExpress.XtraPrinting.BarCode.QRCodeCompactionMode.Byte;
                        qrCodeGenerator1.ErrorCorrectionLevel = DevExpress.XtraPrinting.BarCode.QRCodeErrorCorrectionLevel.H;
                        qrCodeGenerator1.Version = DevExpress.XtraPrinting.BarCode.QRCodeVersion.Version1;
                        //Code128Generator
                        DevExpress.XtraPrinting.BarCode.Code128Generator code128Generator1 = new DevExpress.XtraPrinting.BarCode.Code128Generator();
                        //根据长宽比切换二维码 条码显示
                        if (barCodeControl.Width > barCodeControl.Height * 2)
                        {
                            barCodeControl.Symbology = code128Generator1;
                        }
                        else
                        {
                            barCodeControl.Symbology = qrCodeGenerator1;
                        }
                        contain.Controls.Add(barCodeControl);
                        barCodeControl.BringToFront();
                        break;

                    default:
                        break;
                    }
                }
                parentControl.Visible = true;
            }
            catch (Exception ex)
            {
                SharedFunc.RaiseError(ex);
            }
        }