Beispiel #1
0
        private void GenViewBlockControl(TBlockItem BlockItem)
        {
            #if VS90
            object oView = FDesignerDocument.webControls.item("View", 0);
            if (oView == null)
                oView = FDesignerDocument.webControls.item("Master", 0);

            WebDevPage.IHTMLElement eView = null;
            WebDevPage.IHTMLElement eWebView1 = null;

            if (oView == null || !(oView is WebDevPage.IHTMLElement))
                return;
            eView = (WebDevPage.IHTMLElement)oView;
            BlockItem.wDataSource = new WebDataSource();
            String viewDataMember = FClientData.ViewProviderName.Substring(FClientData.ViewProviderName.IndexOf('.') + 1, FClientData.ViewProviderName.Length -
                                                    FClientData.ViewProviderName.IndexOf('.') - 1);
            if (eView != null)
            {
                eView.setAttribute("DataMember", viewDataMember, 0);
            }

            object oWebView1 = FDesignerDocument.webControls.item("WgView", 0);
            if (oWebView1 != null)
            {
                eWebView1 = (WebDevPage.IHTMLElement)oWebView1;
                //eWebView1.setAttribute("DataMember", viewDataMember, 0);
            }

            if (oWebView1 == null)
                oWebView1 = FDesignerDocument.webControls.item("WebGridView1", 0);

            if (oWebView1 != null)
            {
                eWebView1 = (WebDevPage.IHTMLElement)oWebView1;

                //这里本来想再往下找Columns节点的,可是找不到,只能先这样写了
                StringBuilder sb = new StringBuilder(eWebView1.innerHTML);
                int idx = eWebView1.innerHTML.IndexOf("</Columns>");
                List<string> KeyFields = new List<string>();
                foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
                {
                    idx = sb.ToString().IndexOf("</Columns>");
                    sb.Insert(idx, "\r            <asp:BoundField DataField=\"" + BFI.DataField + "\" HeaderText=\"" + (string.IsNullOrEmpty(BFI.Description) ? BFI.DataField : BFI.Description) + "\" SortExpression=\"" + BFI.DataField + "\" />\r\n            ");
                }
                eWebView1.innerHTML = sb.ToString();
            }

            AjaxTools.ExtGridColumnCollection aExtGridColumnCollection = new AjaxTools.ExtGridColumnCollection(new AjaxTools.AjaxGridView(), typeof(AjaxTools.ExtColumnMatch));
            AjaxTools.ExtQueryFieldCollection aExtQueryFieldCollection = new ExtQueryFieldCollection(new AjaxTools.AjaxGridView(), typeof(AjaxTools.ExtQueryField));
            bool flag = true;
            DataTable srcTable = FWizardDataSet.RealDataSet.Tables[BlockItem.TableName];
            foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
            {
                AjaxTools.ExtGridColumn extCol = new AjaxTools.ExtGridColumn();
                if (BFI.CheckNull == "Y")
                    extCol.AllowNull = false;
                else
                    extCol.AllowNull = true;
                extCol.AllowSort = false;
                extCol.ColumnName = string.Format("col{0}", BFI.DataField);
                extCol.DataField = BFI.DataField;
                extCol.ExpandColumn = true;
                if (BFI.Description != null && BFI.Description != String.Empty)
                    extCol.HeaderText = BFI.Description;
                else
                    extCol.HeaderText = BFI.DataField;
                extCol.IsKeyField = BFI.IsKey;
                extCol.IsKeyField = IsKeyField(BFI.DataField, srcTable.PrimaryKey);
                extCol.NewLine = flag;
                extCol.Resizable = true;
                extCol.TextAlign = "left";
                extCol.Visible = true;
                extCol.Width = 75;
                extCol.ReadOnly = true;
                if (BFI.QueryMode == "Normal")
                {
                    AjaxTools.ExtQueryField aExtQueryField = new AjaxTools.ExtQueryField();
                    aExtQueryField.Condition = "And";
                    aExtQueryField.Id = BFI.DataField;
                    aExtQueryField.DataField = BFI.DataField;
                    aExtQueryField.Caption = BFI.Description;
                    if (BFI.DataType == typeof(int) || BFI.DataType == typeof(float) || BFI.DataType == typeof(double))
                    {
                        aExtQueryField.Operator = "=";
                    }
                    else
                    {
                        aExtQueryField.Operator = "%";
                    }
                    aExtQueryFieldCollection.Add(aExtQueryField);
                }
                else if (BFI.QueryMode == "Range")
                {
                    AjaxTools.ExtQueryField aExtQueryField = new AjaxTools.ExtQueryField();
                    aExtQueryField.Id = BFI.DataField;
                    aExtQueryField.DataField = BFI.DataField;
                    aExtQueryField.Caption = BFI.Description;
                    aExtQueryField.Condition = "And";
                    aExtQueryField.Operator = ">=";
                    aExtQueryFieldCollection.Add(aExtQueryField);

                    AjaxTools.ExtQueryField aExtQueryField2 = new AjaxTools.ExtQueryField();
                    aExtQueryField2.Id = BFI.DataField + "2";
                    aExtQueryField2.DataField = BFI.DataField;
                    aExtQueryField2.Caption = BFI.Description;
                    aExtQueryField2.Condition = "And";
                    aExtQueryField2.Operator = "<=";
                    aExtQueryFieldCollection.Add(aExtQueryField2);
                }
                this.FieldTypeSelector(BFI.DataType, extCol, BFI.ControlType);

                aExtGridColumnCollection.Add(extCol);
                flag = !flag;
            }

            WebDevPage.IHTMLElement AjaxGridView1 = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("AjaxGridView1", 0);
            if (AjaxGridView1 != null)
            {
                SetCollectionValue(AjaxGridView1, typeof(AjaxTools.AjaxGridView).GetProperty("Columns"), aExtGridColumnCollection);
            }
            if (AjaxGridView1 != null && aExtQueryFieldCollection.Count > 0)
            {
                SetCollectionValue(AjaxGridView1, typeof(AjaxTools.AjaxGridView).GetProperty("QueryFields"), aExtQueryFieldCollection);
            }
            #else

            WebDataSource View = (WebDataSource)FPage.FindControl("View");
            if (View == null)
                View = (WebDataSource)FPage.FindControl("Master");
            BlockItem.wDataSource = View;
            View.DataMember = FClientData.ViewProviderName;
            if (View.DataMember == null || View.DataMember == "")
                View.DataMember = FClientData.ProviderName;
            View.DataMember = View.DataMember.Substring(View.DataMember.IndexOf('.') + 1, View.DataMember.Length -
                View.DataMember.IndexOf('.') - 1);
            IComponentChangeService FComponentChangeService = (IComponentChangeService)FDesignerHost.RootComponent.Site.GetService(typeof(IComponentChangeService));
            FComponentChangeService.OnComponentChanged(View, null, "", "M");
            WebGridView WgView = (WebGridView)FPage.FindControl("WgView");
            if (WgView == null)
                WgView = (WebGridView)FPage.FindControl("WebGridView1");
            //???WebGridView2.Columns.Clear();
            if (WgView != null)
            {
                System.Web.UI.WebControls.BoundField Field = null;
                List<string> KeyFields = new List<string>();
                foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
                {
                    Field = new System.Web.UI.WebControls.BoundField();
                    Field.DataField = BFI.DataField;
                    Field.SortExpression = BFI.DataField;
                    Field.HeaderText = BFI.Description;
                    //Field.HeaderStyle.Width = BFI.Length * ColumnWidthPixel;
                    if (Field.HeaderText == "")
                        Field.HeaderText = BFI.DataField;
                    if (BFI.IsKey)
                        KeyFields.Add(Field.DataField);
                    WgView.Columns.Add(Field);
                }
                FComponentChangeService = (IComponentChangeService)FDesignerHost.RootComponent.Site.GetService(typeof(IComponentChangeService));
                FComponentChangeService.OnComponentChanged(WgView, null, "", "M");
            }

            //AjaxTools.AjaxGridView aAjaxGridView = FPage.FindControl("AjaxGridView1") as AjaxTools.AjaxGridView;
            Object aAjaxGridView = FPage.FindControl("AjaxGridView1");
            if (aAjaxGridView != null)
            {
                bool flag = true;
                DataTable srcTable = FWizardDataSet.RealDataSet.Tables[BlockItem.TableName];
                IList iColumns = aAjaxGridView.GetType().GetProperty("Columns").GetValue(aAjaxGridView, null) as IList;
                foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
                {
                    Type columnsType = aAjaxGridView.GetType().GetProperty("Columns").PropertyType.GetProperties()[0].PropertyType;
                    object extCol = Activator.CreateInstance(columnsType);
                    if (BFI.CheckNull == "Y")
                        extCol.GetType().GetProperty("AllowNull").SetValue(extCol, false, null);
                    else
                        extCol.GetType().GetProperty("AllowNull").SetValue(extCol, true, null);
                    extCol.GetType().GetProperty("AllowSort").SetValue(extCol, false, null);
                    extCol.GetType().GetProperty("ColumnName").SetValue(extCol, string.Format("col{0}", BFI.DataField), null);
                    extCol.GetType().GetProperty("DataField").SetValue(extCol, BFI.DataField, null);
                    extCol.GetType().GetProperty("DefaultValue").SetValue(extCol, BFI.DefaultValue, null);
                    extCol.GetType().GetProperty("ExpandColumn").SetValue(extCol, true, null);
                    if (BFI.Description != null && BFI.Description != String.Empty)
                        extCol.GetType().GetProperty("HeaderText").SetValue(extCol, BFI.Description, null);
                    else
                        extCol.GetType().GetProperty("HeaderText").SetValue(extCol, BFI.DataField, null);
                    //extCol.GetType().GetProperty("IsKeyField").SetValue(extCol, BFI.IsKey, null);
                    extCol.GetType().GetProperty("IsKeyField").SetValue(extCol, IsKeyField(BFI.DataField, srcTable.PrimaryKey), null);
                    extCol.GetType().GetProperty("NewLine").SetValue(extCol, flag, null);
                    extCol.GetType().GetProperty("Resizable").SetValue(extCol, true, null);
                    extCol.GetType().GetProperty("TextAlign").SetValue(extCol, "left", null);
                    extCol.GetType().GetProperty("Visible").SetValue(extCol, true, null);
                    extCol.GetType().GetProperty("Width").SetValue(extCol, 75, null);
                    if (BFI.QueryMode == "Normal")
                    {
                        IList iQueryFields = aAjaxGridView.GetType().GetProperty("QueryFields").GetValue(aAjaxGridView, null) as IList;
                        Type queryFieldsType = aAjaxGridView.GetType().GetProperty("QueryFields").PropertyType.GetProperties()[0].PropertyType;
                        object aQueryField = Activator.CreateInstance(queryFieldsType);
                        aQueryField.GetType().GetProperty("Condition").SetValue(aQueryField, "And", null);
                        aQueryField.GetType().GetProperty("DataField").SetValue(aQueryField, BFI.DataField, null);
                        aQueryField.GetType().GetProperty("Caption").SetValue(aQueryField, BFI.Description, null);
                        if (BFI.DataType == typeof(int) || BFI.DataType == typeof(float) || BFI.DataType == typeof(double))
                        {
                            aQueryField.GetType().GetProperty("Operator").SetValue(aQueryField, "=", null);
                        }
                        else
                        {
                            aQueryField.GetType().GetProperty("Operator").SetValue(aQueryField, "%", null);
                        }
                        iQueryFields.Add(aQueryField);
                    }
                    else if (BFI.QueryMode == "Range")
                    {
                        IList iQueryFields = aAjaxGridView.GetType().GetProperty("QueryFields").GetValue(aAjaxGridView, null) as IList;
                        Type queryFieldsType = aAjaxGridView.GetType().GetProperty("QueryFields").PropertyType.GetProperties()[0].PropertyType;
                        object aQueryField = Activator.CreateInstance(queryFieldsType);
                        aQueryField.GetType().GetProperty("Condition").SetValue(aQueryField, "And", null);
                        aQueryField.GetType().GetProperty("DataField").SetValue(aQueryField, BFI.DataField, null);
                        aQueryField.GetType().GetProperty("Caption").SetValue(aQueryField, BFI.Description, null);
                        aQueryField.GetType().GetProperty("Condition").SetValue(aQueryField, "And", null);
                        aQueryField.GetType().GetProperty("Operator").SetValue(aQueryField, ">=", null);
                        iQueryFields.Add(aQueryField);

                        object aQueryField2 = Activator.CreateInstance(queryFieldsType);
                        aQueryField2.GetType().GetProperty("Condition").SetValue(aQueryField2, "And", null);
                        aQueryField2.GetType().GetProperty("DataField").SetValue(aQueryField2, BFI.DataField, null);
                        aQueryField2.GetType().GetProperty("Caption").SetValue(aQueryField2, BFI.Description, null);
                        aQueryField2.GetType().GetProperty("Condition").SetValue(aQueryField2, "And", null);
                        aQueryField2.GetType().GetProperty("Operator").SetValue(aQueryField2, "<=", null);
                        iQueryFields.Add(aQueryField2);

                    }
                    this.FieldTypeSelector(BFI.DataType, extCol, BFI.ControlType);
                    iColumns.Add(extCol);
                    //AjaxTools.ExtGridColumn extCol = new AjaxTools.ExtGridColumn();
                    //extCol.AllowSort = false;
                    //extCol.ColumnName = string.Format("col{0}", BFI.DataField);
                    //extCol.DataField = BFI.DataField;
                    //extCol.ExpandColumn = true;
                    //extCol.HeaderText = BFI.Description;
                    //extCol.IsKeyField = BFI.IsKey;
                    //extCol.IsKeyField = IsKeyField(BFI.DataField, srcTable.PrimaryKey);
                    //extCol.NewLine = flag;
                    //extCol.Resizable = true;
                    //extCol.TextAlign = "left";
                    //extCol.Visible = true;
                    //extCol.Width = 75;
                    //this.FieldTypeSelector(BFI.DataType, extCol);

                    //aAjaxGridView.Columns.Add(extCol);
                    flag = !flag;
                }
                NotifyRefresh(200);
                FComponentChangeService.OnComponentChanged(aAjaxGridView, null, "", "M");
            }

            /*
            WebGridView2.DataKeyNames = new string[KeyFields.Count];
            for (int I = 0; I < KeyFields.Count; I++)
                WebGridView2.DataKeyNames[I] = KeyFields[I];
             *
             */

            /*
            if (FClientData.IsMasterDetailBaseForm())
            {
                InfoDataSet ViewDataSet = FDesignerHost.CreateComponent(typeof(InfoDataSet), "idView") as InfoDataSet;
                ViewDataSet.RemoteName = FClientData.ViewProviderName;
                if (ViewDataSet.RemoteName.Trim() == "")
                {
                    ViewDataSet.RemoteName = FClientData.ProviderName;
                }
                ViewDataSet.Active = true;
                InfoBindingSource ViewBindingSource = FDesignerHost.CreateComponent(typeof(InfoBindingSource),
                    "ibsView") as InfoBindingSource;
                ViewBindingSource.DataSource = ViewDataSet;
                ViewBindingSource.DataMember = ViewDataSet.RealDataSet.Tables[0].TableName;
                BlockItem.BindingSource = ViewBindingSource;
                InfoNavigator navigator1 = FRootForm.Controls["infoNavigator1"] as InfoNavigator;
                if (navigator1 != null)
                    navigator1.ViewBindingSource = ViewBindingSource;
                InfoRelation Relation = new InfoRelation();
                Relation.RelationDataSet = FDataSet;
                InfoKeyField KeyField;
                KeyField = new InfoKeyField();
                KeyField.FieldName = ViewDataSet.RealDataSet.Tables[0].Columns[0].ColumnName;
                Relation.SourceKeyFields.Add(KeyField);
                KeyField = new InfoKeyField();
                KeyField.FieldName = ViewDataSet.RealDataSet.Tables[0].Columns[0].ColumnName;
                Relation.TargetKeyFields.Add(KeyField);
                Relation.Active = true;
                ViewBindingSource.Relations.Add(Relation);
            }

            TBlockFieldItem FieldItem;
            System.Windows.Forms.SplitContainer scMaster = FRootForm.Controls["scMaster"] as System.Windows.Forms.SplitContainer;
            FViewGrid = FDesignerHost.CreateComponent(typeof(InfoDataGridView), "grdView") as InfoDataGridView;
            FViewGrid.Parent = scMaster.Panel1;
            FViewGrid.Dock = DockStyle.Fill;
            FViewGrid.TabIndex = 0;
            FViewGrid.DataSource = BlockItem.BindingSource;

            if (FClientData.IsMasterDetailBaseForm())
            {
                //???FViewGrid.Columns.Clear();
                DataGridViewColumn Column;
                int I, Index;
                for (I = 0; I < BlockItem.BlockFieldItems.Count; I++)
                {
                    FieldItem = BlockItem.BlockFieldItems[I] as TBlockFieldItem;
                    if (FieldItem.Description == "")
                        Index = FViewGrid.Columns.Add(FieldItem.DataField, FieldItem.DataField);
                    else
                        Index = FViewGrid.Columns.Add(FieldItem.DataField, FieldItem.Description);
                    Column = FViewGrid.Columns[Index];
                    Column.DataPropertyName = FieldItem.DataField;
                    if (Column.HeaderText.Trim() == "")
                        Column.HeaderText = FieldItem.DataField;
                }
            }
             */
            #endif
        }
Beispiel #2
0
 public string GenQueryPart(ExtQueryField field, Type dataType)
 {
     StringBuilder builder = new StringBuilder();
     if (field.Condition != "None")
     {
         ExtGridColumn editorColumn = this.GetExtGridColumnByDataField(field.DataField);
         if (editorColumn != null)
         {
             builder.Append("{");
             builder.AppendFormat("condition:'{0}',operator:'{1}',caption:'{2}',editor:'{3}'",
                 field.Condition,
                 field.Operator,
                 field.Caption,
                 editorColumn.Editor.ToString());
             if (editorColumn.Editor == ExtGridEditor.ComboBox)
             {
                 ExtComboBox cmb = this.GetObjByID(editorColumn.EditControlId) as ExtComboBox;
                 if (cmb != null)
                 {
                     builder.AppendFormat(",editorConfig:{0}", cmb.GenComboBoxConfig(field.DataField));
                 }
             }
             if (!string.IsNullOrEmpty(field.DefaultValue))
             {
                 if (GloFix.IsNumeric(dataType))
                 {
                     builder.AppendFormat(",defVal:{0}", field.DefaultValue);
                 }
                 else if (dataType == typeof(Boolean))
                 {
                     builder.AppendFormat(",defVal:{0}", field.DefaultValue.ToLower());
                 }
                 else
                 {
                     builder.AppendFormat(",defVal:'{0}'", field.DefaultValue);
                 }
             }
             builder.Append("}");
         }
     }
     return builder.ToString();
 }