コード例 #1
0
ファイル: fmEEPWebWizard.cs プロジェクト: san90279/UK_OAS
        private void GenMainBlockControl(TBlockItem BlockItem)
        {
            #if VS90
            object oMaster = FDesignerDocument.webControls.item("Master", 0);

            WebDevPage.IHTMLElement eMaster = null;
            WebDevPage.IHTMLElement eWebGridView1 = null;

            if (oMaster == null || !(oMaster is WebDevPage.IHTMLElement))
                return;
            eMaster = (WebDevPage.IHTMLElement)oMaster;

            WebDefault Default = new WebDefault();
            Default.ID = "wd" + WzdUtils.RemoveSpecialCharacters(BlockItem.TableName);
            Default.DataSourceID = eMaster.getAttribute("ID", 0).ToString();
            Default.DataMember = FClientData.TableName;

            WebValidate Validate = new WebValidate();
            Validate.ID = "wv" + WzdUtils.RemoveSpecialCharacters(BlockItem.TableName);
            Validate.DataSourceID = eMaster.getAttribute("ID", 0).ToString();
            Validate.DataMember = FClientData.TableName;

            WebQueryFiledsCollection QueryFields = new WebQueryFiledsCollection(null, typeof(QueryField));
            WebQueryColumnsCollection QueryColumns = new WebQueryColumnsCollection(null, typeof(QueryColumns));
            foreach (TBlockFieldItem fielditem in BlockItem.BlockFieldItems)
            {
                GenDefault(fielditem, Default, Validate);
                GenQuery(fielditem, QueryFields, QueryColumns, BlockItem.TableName);
            }

            WebDevPage.IHTMLElement Page = FDesignerDocument.pageContentElement;
            InsertControl(Page, Default);
            InsertControl(Page, Validate);

            foreach (TBlockFieldItem fielditem in BlockItem.BlockFieldItems)
            {
                foreach (WebQueryColumns wqc in QueryColumns)
                {
                    if (wqc.ColumnType == "ClientQueryRefValColumn" && wqc.Column == fielditem.DataField && fielditem.RefValNo != String.Empty)
                    {
                        WebDataSource aWebDataSource = new WebDataSource();
                        InfoCommand aInfoCommand = new InfoCommand(FClientData.DatabaseType);
                        aInfoCommand.Connection = WzdUtils.AllocateConnection(FClientData.DatabaseName, FClientData.DatabaseType, true);
                        //aInfoCommand.Connection = FClientData.Owner.GlobalConnection;
                        IDbDataAdapter DA = DBUtils.CreateDbDataAdapter(aInfoCommand);
                        if (FSYS_REFVAL != null)
                            FSYS_REFVAL.Dispose();
                        FSYS_REFVAL = new DataSet();
                        aInfoCommand.CommandText = String.Format("Select * from SYS_REFVAL where REFVAL_NO = '{0}'", fielditem.RefValNo);
                        WzdUtils.FillDataAdapter(FClientData.DatabaseType, DA, FSYS_REFVAL, fielditem.RefValNo);

                        WebRefVal aWebRefVal = new WebRefVal();
                        aWebRefVal.ID = wqc.WebRefVal;
                        aWebRefVal.DataTextField = FSYS_REFVAL.Tables[0].Rows[0]["DISPLAY_MEMBER"].ToString();
                        aWebRefVal.DataValueField = FSYS_REFVAL.Tables[0].Rows[0]["VALUE_MEMBER"].ToString();
                        aWebRefVal.DataSourceID = String.Format("wds{0}{1}", WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), wqc.Column);
                        aWebRefVal.Visible = false;
                        InsertControl(Page, aWebRefVal);
                        break;
                    }
                    else if (wqc.ColumnType == "ClientQueryComboBoxColumn" && wqc.Column == fielditem.DataField
                        && !String.IsNullOrEmpty(fielditem.ComboTextField) && !String.IsNullOrEmpty(fielditem.ComboValueField))
                    {
                        WebRefVal aWebRefVal = new WebRefVal();
                        aWebRefVal.ID = wqc.WebRefVal;
                        aWebRefVal.DataTextField = fielditem.ComboTextField;
                        aWebRefVal.DataValueField = fielditem.ComboValueField;
                        aWebRefVal.DataSourceID = String.Format("wds{0}{1}", fielditem.ComboEntityName, wqc.Column);
                        aWebRefVal.Visible = false;
                        InsertControl(Page, aWebRefVal);
                        break;
                    }
                }
            }

            WebDevPage.IHTMLElement Navigator = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("WebNavigator1", 0);
            if (Navigator != null)
            {
                SetCollectionValue(Navigator, typeof(WebNavigator).GetProperty("QueryFields"), QueryFields);
            }
            WebDevPage.IHTMLElement ClientQuery = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("WebClientQuery1", 0);
            if (ClientQuery != null)
            {
                SetCollectionValue(ClientQuery, typeof(WebClientQuery).GetProperty("Columns"), QueryColumns);
            }

            object oWebGridView1 = FDesignerDocument.webControls.item("wgvMaster", 0);
            if (oWebGridView1 == null)
                oWebGridView1 = FDesignerDocument.webControls.item("WebGridView1", 0);
            eWebGridView1 = (WebDevPage.IHTMLElement)oWebGridView1;
            //eWebGridView1.setAttribute("DataMember", FClientData.TableName, 0);

            //这里本来想再往下找Columns节点的,可是找不到,只能先这样写了
            StringBuilder sb = new StringBuilder(eWebGridView1.innerHTML);
            int idx = eWebGridView1.innerHTML.IndexOf("</Columns>");
            if (idx == -1)
            {
                idx = sb.ToString().IndexOf("<SelectedRowStyle");
                sb.Insert(idx, "<Columns>\r\n            </Columns>");
            }
            List<string> KeyFields = new List<string>();
            foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
            {
                idx = sb.ToString().IndexOf("</Columns>");
                if (BFI.ControlType == "RefValBox" && String.IsNullOrEmpty(BFI.RefValNo))
                    BFI.ControlType = "TextBox";
                if (BFI.ControlType == "ComboBox" && (String.IsNullOrEmpty(BFI.ComboRemoteName)
                                                    || String.IsNullOrEmpty(BFI.ComboTextField)
                                                    || String.IsNullOrEmpty(BFI.ComboValueField)))
                    BFI.ControlType = "TextBox";
                if (!string.IsNullOrEmpty(BFI.RefValNo) || BFI.RefField != null)
                {
                    sb.Insert(idx, GenTemplateFieldHTML(BFI.ControlType, BlockItem, BFI));
                }
                else if (BFI.ControlType == "ComboBox" || BFI.ControlType == "ValidateBox" || BFI.ControlType == "CheckBox")
                {
                    sb.Insert(idx, GenTemplateFieldHTML(BFI.ControlType, BlockItem, BFI));
                }
                else
                {
                    if (BFI.DataType == typeof(DateTime) || (BFI.ControlType != null && BFI.ControlType == "DateTimeBox"))
                    {
                        sb.Insert(idx, GenTemplateFieldHTML("DateTimeBox", BlockItem, BFI));
                    }
                    else
                    {
                        sb.Insert(idx, "\r            <asp:BoundField DataField=\"" + BFI.DataField + "\" HeaderText=\"" + (string.IsNullOrEmpty(BFI.Description) ? BFI.DataField : BFI.Description) + "\" SortExpression=\"" + BFI.DataField + "\" />\r\n            ");
                    }
                }
            }
            eWebGridView1.innerHTML = sb.ToString();
            WebDevPage.IHTMLElement AjaxGridView1 = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("AjaxGridView1", 0);
            if (AjaxGridView1 != null)
            {
                AjaxTools.ExtGridColumnCollection aExtGridColumnCollection = new AjaxTools.ExtGridColumnCollection(new AjaxTools.AjaxGridView(), typeof(AjaxTools.ExtColumnMatch));
                DataTable srcTable = FWizardDataSet.RealDataSet.Tables[BlockItem.TableName];
                bool flag = true;
                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;
                    if ((BFI.RefValNo != null && BFI.RefValNo != "") || BFI.RefField != null)
                    {
                        String DataSourceID = GenWebDataSource(BFI, WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), "RefVal", "", true);
                        String extComboBox = GenExtComboBox(BFI, WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), "ExtRefVal", "", DataSourceID);
                        try
                        {
                            String str = AjaxGridView1.innerHTML;
                        }
                        catch
                        {
                            AjaxGridView1 = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("AjaxGridViewDetail", 0);
                        }
                        extCol.EditControlId = extComboBox;
                        extCol.Editor = AjaxTools.ExtGridEditor.ComboBox;
                    }
                    else if (BFI.ControlType == "ComboBox")
                    {
                        String DataSourceID = GenWebDataSource(BFI, BFI.ComboEntityName, "ComboBox", "", true);
                        String extComboBox = GenExtComboBox(BFI, WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), "ExtComboBox", "", DataSourceID);
                        try
                        {
                            String str = AjaxGridView1.innerHTML;
                        }
                        catch
                        {
                            AjaxGridView1 = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("AjaxGridViewDetail", 0);
                        }
                        extCol.EditControlId = extComboBox;
                        extCol.Editor = AjaxTools.ExtGridEditor.ComboBox;
                    }
                    this.FieldTypeSelector(BFI.DataType, extCol, BFI.ControlType);

                    aExtGridColumnCollection.Add(extCol);

                    flag = !flag;
                }

                SetCollectionValue(AjaxGridView1, typeof(AjaxTools.AjaxGridView).GetProperty("Columns"), aExtGridColumnCollection);
            }
            #else
            bool isAjaxPage = false;
            if (FPage.FindControl("AjaxScriptManager1") != null)
                isAjaxPage = true;

            WebDataSource Master = (WebDataSource)FPage.FindControl("Master");
            BlockItem.wDataSource = Master;
            WebGridView WebGridView1 = (WebGridView)FPage.FindControl("wgvMaster");
            if (WebGridView1 == null)
                WebGridView1 = (WebGridView)FPage.FindControl("WebGridView1");
            //Generate RESX
            //???GenResx(Master);

            //WebGridView1.DataMember = FClientData.TableName;
            //???WebGridView1.Columns.Clear();
            System.Web.UI.WebControls.BoundField aBoundField = null;
            System.Web.UI.WebControls.TemplateField aTemplateField = null;

            WebDefault aDefault = new WebDefault();
            aDefault.ID = "wd" + BlockItem.TableName;
            aDefault.DataSourceID = Master.ID;
            aDefault.DataMember = Master.DataMember;
            WebValidate aValidate = new WebValidate();
            aValidate.ID = "wv" + BlockItem.TableName;
            aValidate.DataSourceID = Master.ID;
            aValidate.DataMember = Master.DataMember;

            if (WebGridView1 != null)
            {
                List<string> KeyFields = new List<string>();
                foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
                {
                    if ((BFI.RefValNo != null && BFI.RefValNo != "") || BFI.RefField != null)
                    {
                        String DataSourceID = GenWebDataSource(BFI, BlockItem.TableName, "RefVal", "");
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;
                        if (isAjaxPage)
                        {
                            aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewAjaxRefValEditItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FAjaxRefValList, FClientData.DatabaseType, WebGridView1, FLabelList);
                            aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewAjaxRefValItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FAjaxRefValList, FClientData.DatabaseType, WebGridView1, FLabelList);
                            aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewAjaxRefValFooterItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FAjaxRefValList, FClientData.DatabaseType, WebGridView1, FLabelList);
                        }
                        else
                        {
                            aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewRefValEditItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FWebRefValList, FClientData.DatabaseType, WebGridView1);
                            aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewRefValItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FWebRefValList, FClientData.DatabaseType, WebGridView1);
                            aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewRefValFooterItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FWebRefValList, FClientData.DatabaseType, WebGridView1);
                        }
                        WebGridView1.Columns.Add(aTemplateField);
                    }
                    else if (BFI.ControlType == "ComboBox")
                    {
                        String DataSourceID = GenWebDataSource(BFI, BFI.ComboEntityName, "ComboBox", "");
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;
                        aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewComboBoxEditItemTemplate", BFI, BlockItem.TableName, DataSourceID, FMyWebDropDownList, FLabelList);
                        aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewComboBoxItemTemplate", BFI, BlockItem.TableName, DataSourceID, FMyWebDropDownList, FLabelList);
                        aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewComboBoxFooterItemTemplate", BFI, BlockItem.TableName, DataSourceID, FMyWebDropDownList, FLabelList);
                        WebGridView1.Columns.Add(aTemplateField);
                    }
                    else if (BFI.ControlType == "ValidateBox")
                    {
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;
                        aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewValidateBoxEditItemTemplate", BFI, BlockItem.TableName, aValidate, FWebValidateBoxList, FLabelList);
                        aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewValidateBoxItemTemplate", BFI, BlockItem.TableName, aValidate, FWebValidateBoxList, FLabelList);
                        aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewValidateBoxFooterItemTemplate", BFI, BlockItem.TableName, aValidate, FWebValidateBoxList, FLabelList);
                        WebGridView1.Columns.Add(aTemplateField);
                    }
                    else if (BFI.ControlType == "CheckBox")
                    {
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;
                        aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewCheckBoxEditItemTemplate", BFI, BlockItem.TableName, FWebCheckBoxList, FLabelList);
                        aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewCheckBoxItemTemplate", BFI, BlockItem.TableName, FWebCheckBoxList, FLabelList);
                        aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewCheckBoxFooterItemTemplate", BFI, BlockItem.TableName, FWebCheckBoxList, FLabelList);
                        WebGridView1.Columns.Add(aTemplateField);
                    }
                    else
                    {
                        if (BFI.DataType == typeof(DateTime) || (BFI.ControlType != null && BFI.ControlType.ToUpper() == "DATETIMEBOX"))
                        {
                            aTemplateField = new System.Web.UI.WebControls.TemplateField();
                            aTemplateField.HeaderText = BFI.Description;
                            aTemplateField.SortExpression = BFI.DataField;
                            if (aTemplateField.HeaderText == "")
                                aTemplateField.HeaderText = BFI.DataField;
                            if (isAjaxPage)
                            {
                                aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewAjaxDateTimeEditItemTemplate", BFI, BlockItem.TableName, FAjaxDateTimePickerList, FLabelList, WebGridView1);
                                aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewAjaxDateTimeItemTemplate", BFI, BlockItem.TableName, FAjaxDateTimePickerList, FLabelList, WebGridView1);
                                aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewAjaxDateTimeFooterItemTemplate", BFI, BlockItem.TableName, FAjaxDateTimePickerList, FLabelList, WebGridView1);
                            }
                            else
                            {
                                aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewDateTimeEditItemTemplate", BFI, BlockItem.TableName, FWebDateTimePickerList, FLabelList, WebGridView1);
                                aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewDateTimeItemTemplate", BFI, BlockItem.TableName, FWebDateTimePickerList, FLabelList, WebGridView1);
                                aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewDateTimeFooterItemTemplate", BFI, BlockItem.TableName, FWebDateTimePickerList, FLabelList, WebGridView1);
                            }
                            WebGridView1.Columns.Add(aTemplateField);
                        }
                        else
                        {
                            if (BFI.EditMask != null && BFI.EditMask != String.Empty)
                            {
                                aTemplateField = new System.Web.UI.WebControls.TemplateField();
                                aTemplateField.HeaderText = BFI.Description;
                                aTemplateField.SortExpression = BFI.DataField;
                                if (aTemplateField.HeaderText == "")
                                    aTemplateField.HeaderText = BFI.DataField;
                                aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewTextBoxEditItemTemplate", BFI, BlockItem.TableName, FWebTextBoxList, FLabelList, WebGridView1);
                                aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewTextBoxItemTemplate", BFI, BlockItem.TableName, FWebTextBoxList, FLabelList, WebGridView1);
                                aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewTextBoxFooterItemTemplate", BFI, BlockItem.TableName, FWebTextBoxList, FLabelList, WebGridView1);
                                WebGridView1.Columns.Add(aTemplateField);
                            }
                            else
                            {
                                aBoundField = new System.Web.UI.WebControls.BoundField();
                                aBoundField.DataField = BFI.DataField;
                                aBoundField.SortExpression = BFI.DataField;
                                aBoundField.HeaderText = BFI.Description;
                                //Field.HeaderStyle.Width = BFI.Length * ColumnWidthPixel;
                                if (aBoundField.HeaderText == "")
                                    aBoundField.HeaderText = BFI.DataField;
                                WebGridView1.Columns.Add(aBoundField);
                            }
                        }
                    }
                    if (BFI.IsKey)
                        KeyFields.Add(BFI.DataField);

                    CreateQueryField(BFI, "", null, BlockItem.TableName);

                    GenDefault(BFI, aDefault, aValidate);
                }

                DataTable DT = FWizardDataSet.RealDataSet.Tables[0];
                DataColumn[] PrimDc = DT.PrimaryKey;
                string[] AA = new string[PrimDc.Length];
                for (int J = 0; J < PrimDc.Length; J++)
                    AA[J] = PrimDc[J].ColumnName;

                /*
                WebGridView1.DataKeyNames = new string[AA.Length];
                for (int I = 0; I < AA.Length; I++)
                {
                    WebGridView1.DataKeyNames[I] = AA[I];
                }
                 */
                FWebDefaultList.Add(aDefault);
                FWebValidateList.Add(aValidate);
                IComponentChangeService FComponentChangeService = (IComponentChangeService)FDesignerHost.RootComponent.Site.GetService(typeof(IComponentChangeService));
                NotifyRefresh(200);
                FComponentChangeService.OnComponentChanged(WebGridView1, null, "", "M");
            }

            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);
                    this.FieldTypeSelector(BFI.DataType, extCol, BFI.ControlType);
                    iColumns.Add(extCol);
                    flag = !flag;
                }
                IComponentChangeService FComponentChangeService = (IComponentChangeService)FDesignerHost.RootComponent.Site.GetService(typeof(IComponentChangeService));
                NotifyRefresh(200);
                FComponentChangeService.OnComponentChanged(aAjaxGridView, null, "", "M");
            }
            #endif
        }
コード例 #2
0
ファイル: fmEEPWebWizard.cs プロジェクト: san90279/UK_OAS
        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
        }
コード例 #3
0
ファイル: fmEEPWebWizard.cs プロジェクト: san90279/UK_OAS
        private void GenDetailBlock(String TemplateName)
        {
            MWizard.TBlockItem BlockItem = null;
            foreach (TBlockItem B in FClientData.Blocks)
            {
                if (B.wDataSource == null)
                {
                    BlockItem = B;
                    break;
                }
            }

            #if VS90
            object oDetail = FDesignerDocument.webControls.item("Detail", 0);

            WebDevPage.IHTMLElement eDetail = null;
            WebDevPage.IHTMLElement eWebGridView1 = null;

            if (oDetail == null || !(oDetail is WebDevPage.IHTMLElement))
                return;
            eDetail = (WebDevPage.IHTMLElement)oDetail;
            eDetail.setAttribute("DataMember", BlockItem.TableName, 0);

            WebQueryFiledsCollection QueryFields = new WebQueryFiledsCollection(null, typeof(QueryField));
            WebQueryColumnsCollection QueryColumns = new WebQueryColumnsCollection(null, typeof(QueryColumns));
            if (FDesignerDocument.webControls.item("wd" + WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), 0) == null && FDesignerDocument.webControls.item("wv" + WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), 0) == null)
            {
                WebDefault Default = new WebDefault();
                Default.ID = "wd" + WzdUtils.RemoveSpecialCharacters(BlockItem.TableName);
                Default.DataSourceID = eDetail.getAttribute("ID", 0).ToString();
                Default.DataMember = BlockItem.TableName;

                WebValidate Validate = new WebValidate();
                Validate.ID = "wv" + WzdUtils.RemoveSpecialCharacters(BlockItem.TableName);
                Validate.DataSourceID = eDetail.getAttribute("ID", 0).ToString();
                Validate.DataMember = BlockItem.TableName;

                foreach (TBlockFieldItem fielditem in BlockItem.BlockFieldItems)
                {
                    GenDefault(fielditem, Default, Validate);
                    GenQuery(fielditem, QueryFields, QueryColumns, BlockItem.TableName);
                }

                WebDevPage.IHTMLElement Page = FDesignerDocument.pageContentElement;
                InsertControl(Page, Default);
                InsertControl(Page, Validate);
            }

            WebDevPage.IHTMLElement Navigator = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("WebNavigator1", 0);
            if (Navigator != null)
            {
                SetCollectionValue(Navigator, typeof(WebNavigator).GetProperty("QueryFields"), QueryFields);
            }
            WebDevPage.IHTMLElement ClientQuery = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("WebClientQuery1", 0);
            if (ClientQuery != null)
            {
                SetCollectionValue(ClientQuery, typeof(WebClientQuery).GetProperty("Columns"), QueryColumns);
            }

            object oWebGridView1 = FDesignerDocument.webControls.item("wgvDetail", 0);
            eWebGridView1 = (WebDevPage.IHTMLElement)oWebGridView1;
            if (eWebGridView1 != null)
            {
                //eWebGridView1.setAttribute("DataSourceID", "Detail", 0);
                //eWebGridView1.setAttribute("DataMember", BlockItem.TableName, 0);

                //这里本来想再往下找Columns节点的,可是找不到,只能先这样写了
                StringBuilder sb = new StringBuilder(eWebGridView1.innerHTML);
                int idx = eWebGridView1.innerHTML.IndexOf("</Columns>");
                List<string> KeyFields = new List<string>();
                AddNewRowControlCollection controls = new AddNewRowControlCollection(null, typeof(AddNewRowControlItem));
                foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
                {
                    //if (TemplateName == "WMasterDetail4" || TemplateName == "VBWebCMasterDetail4")
                    //{
                    //    BFI.RefField = null;
                    //    BFI.ControlType = "TextBox";
                    //}
                    string controlid = string.Empty;
                    WebGridView.AddNewRowControlType type = WebGridView.AddNewRowControlType.TextBox;
                    idx = sb.ToString().IndexOf("</Columns>");
                    if (!string.IsNullOrEmpty(BFI.RefValNo) || BFI.RefField != null)
                    {
                        sb.Insert(idx, GenTemplateFieldHTML(BFI.ControlType, BlockItem, BFI));
                        controlid = WzdUtils.RemoveSpecialCharacters("wrv" + BlockItem.TableName + BFI.DataField + "F");
                        type = WebGridView.AddNewRowControlType.RefVal;
                    }
                    else if (BFI.ControlType == "ComboBox")
                    {
                        sb.Insert(idx, GenTemplateFieldHTML(BFI.ControlType, BlockItem, BFI));
                        controlid = WzdUtils.RemoveSpecialCharacters("wdd" + BlockItem.TableName + BFI.DataField + "F");
                        type = WebGridView.AddNewRowControlType.DropDownList;
                    }
                    else if (BFI.ControlType == "ValidateBox")
                    {
                        sb.Insert(idx, GenTemplateFieldHTML(BFI.ControlType, BlockItem, BFI));
                        controlid = WzdUtils.RemoveSpecialCharacters("wvb" + BlockItem.TableName + BFI.DataField + "F");
                        type = WebGridView.AddNewRowControlType.TextBox;
                    }
                    else if (BFI.ControlType == "CheckBox")
                    {
                        sb.Insert(idx, GenTemplateFieldHTML(BFI.ControlType, BlockItem, BFI));
                        controlid = WzdUtils.RemoveSpecialCharacters("cb" + BlockItem.TableName + BFI.DataField + "F");
                        type = WebGridView.AddNewRowControlType.CheckBox;
                    }
                    else
                    {
                        if (BFI.DataType == typeof(DateTime) || (BFI.ControlType != null && BFI.ControlType == "DateTimeBox"))
                        {
                            sb.Insert(idx, GenTemplateFieldHTML("DateTimeBox", BlockItem, BFI));
                            controlid = WzdUtils.RemoveSpecialCharacters("wdt" + BlockItem.TableName + BFI.DataField + "F");
                            type = WebGridView.AddNewRowControlType.DateTimePicker;
                        }
                        else
                        {
                            sb.Insert(idx, "\r            <asp:BoundField DataField=\"" + BFI.DataField + "\" HeaderText=\"" + (string.IsNullOrEmpty(BFI.Description) ? BFI.DataField : BFI.Description) + "\" SortExpression=\"" + BFI.DataField + "\" />\r\n            ");
                        }
                    }
                    if (controlid.Length > 0)
                    {
                        AddNewRowControlItem item = new AddNewRowControlItem();
                        item.FieldName = BFI.DataField;
                        item.ControlID = controlid;
                        item.ControlType = type;
                        controls.Add(item);
                    }
                }
                eWebGridView1.innerHTML = sb.ToString();
                SetCollectionValue(eWebGridView1, typeof(WebGridView).GetProperty("AddNewRowControls"), controls);
            }

            WebDevPage.IHTMLElement AjaxGridView1 = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("AjaxGridViewDetail", 0);
            if (AjaxGridView1 != null)
            {
                AjaxTools.ExtGridColumnCollection aExtGridColumnCollection = new AjaxTools.ExtGridColumnCollection(new AjaxTools.AjaxGridView(), typeof(AjaxTools.ExtColumnMatch));
                DataTable srcTable = FWizardDataSet.RealDataSet.Tables[BlockItem.TableName];
                bool flag = true;
                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.DefaultValue = BFI.DefaultValue;
                    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;
                    if ((BFI.RefValNo != null && BFI.RefValNo != "") || BFI.RefField != null)
                    {
                        String DataSourceID = GenWebDataSource(BFI, WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), "RefVal", "", true);
                        String extComboBox = GenExtComboBox(BFI, WzdUtils.RemoveSpecialCharacters(BlockItem.TableName), "ExtRefVal", "", DataSourceID);
                        try
                        {
                            String str = AjaxGridView1.innerHTML;
                        }
                        catch
                        {
                            AjaxGridView1 = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("AjaxGridViewDetail", 0);
                        }
                        extCol.EditControlId = extComboBox;
                        extCol.Editor = AjaxTools.ExtGridEditor.ComboBox;
                    }
                    else if (BFI.ControlType == "ComboBox")
                    {
                        String DataSourceID = GenWebDataSource(BFI, BFI.ComboEntityName, "ComboBox", "", true);
                        String extComboBox = GenExtComboBox(BFI, BlockItem.TableName, "ExtComboBox", "", DataSourceID);
                        try
                        {
                            String str = AjaxGridView1.innerHTML;
                        }
                        catch
                        {
                            AjaxGridView1 = (WebDevPage.IHTMLElement)FDesignerDocument.webControls.item("AjaxGridViewDetail", 0);
                        }
                        extCol.EditControlId = extComboBox;
                        extCol.Editor = AjaxTools.ExtGridEditor.ComboBox;
                    }
                    this.FieldTypeSelector(BFI.DataType, extCol, BFI.ControlType);

                    aExtGridColumnCollection.Add(extCol);

                    flag = !flag;

                }
                SetCollectionValue(AjaxGridView1, typeof(AjaxTools.AjaxGridView).GetProperty("Columns"), aExtGridColumnCollection);
            }

            #else
            bool isAjaxPage = false;
            if (FPage.FindControl("AjaxScriptManager1") != null)
                isAjaxPage = true;

            WebDataSource Detail = (WebDataSource)FPage.FindControl("Detail");
            Detail.DataMember = BlockItem.TableName;
            IComponentChangeService FComponentChangeService = (IComponentChangeService)FDesignerHost.RootComponent.Site.GetService(typeof(IComponentChangeService));
            FComponentChangeService.OnComponentChanged(Detail, null, "", "M");
            WebGridView WebGridView2 = (WebGridView)FPage.FindControl("WebGridView2");
            if (WebGridView2 == null)
            {
                WebGridView2 = (WebGridView)FPage.FindControl("wgvDetail");
            }
            if (WebGridView2 != null)
            {
                int length = WebGridView2.Columns.Count;
                for (int i = 1; i < length; i++)
                {
                    WebGridView2.Columns.RemoveAt(1);
                }
                WebGridView2.DataSourceID = "Detail";
                //WebGridView2.DataMember = BlockItem.TableName;
                //???WebGridView2.Columns.Clear();
                System.Web.UI.WebControls.BoundField aBoundField = null;
                System.Web.UI.WebControls.TemplateField aTemplateField = null;
                WebDefault aDefault = new WebDefault();
                aDefault.ID = "wd" + BlockItem.TableName;
                aDefault.DataSourceID = Detail.ID;
                aDefault.DataMember = Detail.DataMember;
                WebValidate aValidate = new WebValidate();
                aValidate.ID = "wv" + BlockItem.TableName;
                aValidate.DataSourceID = Detail.ID;
                aValidate.DataMember = Detail.DataMember;
                List<string> KeyFields = new List<string>();
                foreach (TBlockFieldItem BFI in BlockItem.BlockFieldItems)
                {
                    //if (TemplateName == "WMasterDetail4")
                    //{
                    //    BFI.RefValNo = null;
                    //    BFI.ControlType = "TextBox";
                    //    BFI.DataType = null;
                    //}
                    if ((BFI.RefValNo != null && BFI.RefValNo != "") || BFI.RefField != null)
                    {
                        String DataSourceID = GenWebDataSource(BFI, BlockItem.TableName, "RefVal", "");
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;

                        if (isAjaxPage)
                        {
                            if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                            {
                                aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewAjaxRefValEditItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FAjaxRefValList, FClientData.DatabaseType, WebGridView2, FLabelList);
                                aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewAjaxRefValFooterItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FAjaxRefValList, FClientData.DatabaseType, WebGridView2, FLabelList);
                            }
                            aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewAjaxRefValItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FAjaxRefValList, FClientData.DatabaseType, WebGridView2, FLabelList);
                        }
                        else
                        {
                            if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                            {
                                aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewRefValEditItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FWebRefValList, FClientData.DatabaseType, WebGridView2);
                                aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewRefValFooterItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FWebRefValList, FClientData.DatabaseType, WebGridView2);
                            }
                            aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewRefValItemTemplate", BFI, BlockItem.TableName, DataSourceID, FClientData.Owner.GlobalConnection, FWebRefValList, FClientData.DatabaseType, WebGridView2);
                        }

                        WebGridView2.Columns.Add(aTemplateField);
                    }
                    else if (BFI.ControlType == "ComboBox")
                    {
                        String DataSourceID = GenWebDataSource(BFI, BFI.ComboEntityName, "ComboBox", "");
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;
                        if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                        {
                            aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewComboBoxEditItemTemplate", BFI, BlockItem.TableName, DataSourceID, FMyWebDropDownList, FLabelList);
                            aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewComboBoxFooterItemTemplate", BFI, BlockItem.TableName, DataSourceID, FMyWebDropDownList, FLabelList);
                        }
                        aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewComboBoxItemTemplate", BFI, BlockItem.TableName, DataSourceID, FMyWebDropDownList, FLabelList);
                        WebGridView2.Columns.Add(aTemplateField);
                    }
                    else if (BFI.ControlType == "ValidateBox")
                    {
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;
                        if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                        {
                            aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewValidateBoxEditItemTemplate", BFI, BlockItem.TableName, aValidate, FWebValidateBoxList, FLabelList);
                            aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewValidateBoxFooterItemTemplate", BFI, BlockItem.TableName, aValidate, FWebValidateBoxList, FLabelList);
                        }
                        aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewValidateBoxItemTemplate", BFI, BlockItem.TableName, aValidate, FWebValidateBoxList, FLabelList);
                        WebGridView2.Columns.Add(aTemplateField);
                    }
                    else if (BFI.ControlType == "CheckBox")
                    {
                        aTemplateField = new System.Web.UI.WebControls.TemplateField();
                        aTemplateField.HeaderText = BFI.Description;
                        aTemplateField.SortExpression = BFI.DataField;
                        if (aTemplateField.HeaderText == "")
                            aTemplateField.HeaderText = BFI.DataField;
                        if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                        {
                            aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewCheckBoxEditItemTemplate", BFI, BlockItem.TableName, FWebCheckBoxList, FLabelList);
                            aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewCheckBoxFooterItemTemplate", BFI, BlockItem.TableName, FWebCheckBoxList, FLabelList);
                        }
                        aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewCheckBoxItemTemplate", BFI, BlockItem.TableName, FWebCheckBoxList, FLabelList);
                        WebGridView2.Columns.Add(aTemplateField);
                    }
                    else
                    {
                        if (BFI.DataType == typeof(DateTime) || (BFI.ControlType != null && BFI.ControlType.ToUpper() == "DATETIMEBOX"))
                        {
                            aTemplateField = new System.Web.UI.WebControls.TemplateField();
                            aTemplateField.HeaderText = BFI.Description;
                            aTemplateField.SortExpression = BFI.DataField;
                            if (aTemplateField.HeaderText == "")
                                aTemplateField.HeaderText = BFI.DataField;

                            if (isAjaxPage)
                            {
                                if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                                {
                                    aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewAjaxDateTimeEditItemTemplate", BFI, BlockItem.TableName, FAjaxDateTimePickerList, FLabelList, WebGridView2);
                                    aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewAjaxDateTimeFooterItemTemplate", BFI, BlockItem.TableName, FAjaxDateTimePickerList, FLabelList, WebGridView2);
                                }
                                aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewAjaxDateTimeItemTemplate", BFI, BlockItem.TableName, FAjaxDateTimePickerList, FLabelList, WebGridView2);
                            }
                            else
                            {
                                if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                                {
                                    aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewDateTimeEditItemTemplate", BFI, BlockItem.TableName, FWebDateTimePickerList, FLabelList, WebGridView2);
                                    aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewDateTimeFooterItemTemplate", BFI, BlockItem.TableName, FWebDateTimePickerList, FLabelList, WebGridView2);
                                }
                                aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewDateTimeItemTemplate", BFI, BlockItem.TableName, FWebDateTimePickerList, FLabelList, WebGridView2);
                            }
                            WebGridView2.Columns.Add(aTemplateField);
                        }
                        else
                        {
                            if (BFI.EditMask != null && BFI.EditMask != String.Empty)
                            {
                                aTemplateField = new System.Web.UI.WebControls.TemplateField();
                                aTemplateField.HeaderText = BFI.Description;
                                aTemplateField.SortExpression = BFI.DataField;
                                if (aTemplateField.HeaderText == "")
                                    aTemplateField.HeaderText = BFI.DataField;
                                if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4")
                                {
                                    aTemplateField.EditItemTemplate = new WebControlTemplate("WebGridViewTextBoxEditItemTemplate", BFI, BlockItem.TableName, FWebTextBoxList, FLabelList, WebGridView2);
                                    aTemplateField.FooterTemplate = new WebControlTemplate("WebGridViewTextBoxFooterItemTemplate", BFI, BlockItem.TableName, FWebTextBoxList, FLabelList, WebGridView2);
                                }
                                aTemplateField.ItemTemplate = new WebControlTemplate("WebGridViewTextBoxItemTemplate", BFI, BlockItem.TableName, FWebTextBoxList, FLabelList, WebGridView2);
                                WebGridView2.Columns.Add(aTemplateField);
                            }
                            else
                            {
                                aBoundField = new System.Web.UI.WebControls.BoundField();
                                aBoundField.DataField = BFI.DataField;
                                aBoundField.SortExpression = BFI.DataField;
                                aBoundField.HeaderText = BFI.Description;
                                //Field.HeaderStyle.Width = BFI.Length * ColumnWidthPixel;
                                if (aBoundField.HeaderText == "")
                                    aBoundField.HeaderText = BFI.DataField;
                                WebGridView2.Columns.Add(aBoundField);
                            }
                        }
                    }
                    if (BFI.IsKey)
                        KeyFields.Add(BFI.DataField);

                    GenDefault(BFI, aDefault, aValidate);
                }
                /*
                WebGridView2.DataKeyNames = new string[KeyFields.Count];
                for (int I = 0; I < KeyFields.Count; I++)
                    WebGridView2.DataKeyNames[I] = KeyFields[I];
                 */
                if (TemplateName != "WMasterDetail4" && TemplateName != "VBWebCMasterDetail4" && TemplateName != "WMasterDetail6")
                {
                    FWebDefaultList.Add(aDefault);
                    FWebValidateList.Add(aValidate);
                }
                FComponentChangeService = (IComponentChangeService)FDesignerHost.RootComponent.Site.GetService(typeof(IComponentChangeService));
                FComponentChangeService.OnComponentChanged(WebGridView2, null, "", "M");
            }

            Object aAjaxGridView = FPage.FindControl("AjaxGridViewDetail");
            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, 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.RefValNo != null && BFI.RefValNo != "") || BFI.RefField != null)
                    {
                        String DataSourceID = GenWebDataSource(BFI, BlockItem.TableName, "RefVal", "", true);
                        String extComboBox = GenExtComboBox(BFI, BlockItem.TableName, "ExtRefVal", "", DataSourceID);
                        extCol.GetType().GetProperty("EditControlId").SetValue(extCol, extComboBox, null);
                        extCol.GetType().GetProperty("Editor").SetValue(extCol, extCol.GetType().GetProperty("Editor").PropertyType.GetField("ComboBox").GetValue(extCol), null);
                    }
                    else if (BFI.ControlType == "ComboBox")
                    {
                        String DataSourceID = GenWebDataSource(BFI, BlockItem.TableName, "ComboBox", "", true);
                        String extComboBox = GenExtComboBox(BFI, BlockItem.TableName, "ExtComboBox", "", DataSourceID);
                        extCol.GetType().GetProperty("EditControlId").SetValue(extCol, extComboBox, null);
                        extCol.GetType().GetProperty("Editor").SetValue(extCol, extCol.GetType().GetProperty("Editor").PropertyType.GetField("ComboBox").GetValue(extCol), null);
                    }
                    this.FieldTypeSelector(BFI.DataType, extCol, BFI.ControlType);
                    iColumns.Add(extCol);
                    flag = !flag;
                }
                NotifyRefresh(200);
                FComponentChangeService.OnComponentChanged(aAjaxGridView, null, "", "M");
            }
            #endif
        }