示例#1
0
        public void GenFields(object sender, EventArgs e)
        {
            if (formView == null)
            {
                formView = this.Component as AjaxFormView;
            }
            if (formView != null && !string.IsNullOrEmpty(formView.DataSourceID))
            {
                if (formView.Fields.Count == 0)
                {
                    WebDataSource wds = formView.GetObjByID(formView.DataSourceID) as WebDataSource;
                    DataTable srcTable = GetDesignTable(wds);
                    if (srcTable != null)
                    {
                        DataTable ddTable = DBUtils.GetDataDictionary(wds, true).Tables[0];

                        bool genAlternateColumns = (MessageBox.Show("generate alternate columns", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
                        if (host == null)
                        {
                            host = (IDesignerHost)GetService(typeof(IDesignerHost));
                        }
                        if (svcCompChange == null)
                        {
                            svcCompChange = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
                        }
                        DesignerTransaction trans = host.CreateTransaction("Generate Fields");

                        for (int i = 0; i < srcTable.Columns.Count; i++)
                        {
                            AjaxFormField field = new AjaxFormField();
                            field.FieldControlId = string.Format("ctrl{0}", srcTable.Columns[i].ColumnName);
                            field.Caption = Caption(srcTable.Columns[i].ColumnName, ddTable);
                            field.IsKeyField = IsKeyField(srcTable.Columns[i].ColumnName, srcTable.PrimaryKey);
                            field.DataField = srcTable.Columns[i].ColumnName;
                            if (genAlternateColumns && i % 2 == 1)
                            {
                                field.NewLine = false;
                            }
                            this.FieldTypeSelector(srcTable.Columns[i].DataType, field);

                            svcCompChange.OnComponentChanging(formView, null);
                            formView.Fields.Add(field);
                            svcCompChange.OnComponentChanged(formView, null, null, null);
                        }
                        trans.Commit();
                        MessageBox.Show("generate fields successful!");
                    }
                }
            }
        }
示例#2
0
        public void Preview(object sender, EventArgs e)
        {
            if (formView == null)
            {
                formView = this.Component as AjaxFormView;
            }
            if (formView.Fields.Count > 0)
            {
                List<AjaxViewFieldLayout> fieldLayouts = new List<AjaxViewFieldLayout>();
                foreach (AjaxFormField field in formView.Fields)
                {
                    AjaxViewFieldLayout fieldLayout = new AjaxViewFieldLayout();
                    fieldLayout.FieldName = field.DataField;
                    fieldLayout.Header = string.IsNullOrEmpty(field.Caption) ? field.DataField : field.Caption;
                    fieldLayout.NewLine = field.NewLine;
                    fieldLayout.FieldEditor = field.Editor;
                    fieldLayout.FieldWidth = formView.FieldWidth;
                    fieldLayout.LabelWidth = formView.LabelWidth;
                    fieldLayout.EditorWidth = field.Width;

                    fieldLayouts.Add(fieldLayout);
                }
                using (AjaxViewPreviewEditor editor = new AjaxViewPreviewEditor(fieldLayouts, "form"))
                {
                    editor.ShowDialog();
                }
            }
        }