Esempio n. 1
0
        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
        }
Esempio n. 2
0
        private void GenTextBoxTemplate(String ExtraName)
        {
            if (ExtraName == "")
            {
                System.Web.UI.WebControls.Label aLabel = new System.Web.UI.WebControls.Label();
                aLabel.ID = "l" + FTableName + FFieldItem.DataField + ExtraName + "GridView";
                aLabel.ToolTip = FFieldItem.DataField;
                FContainer.Controls.Add(aLabel);

                Boolean Found = false;
                foreach (System.Web.UI.WebControls.Label bLabel in aLabelList)
                {
                    if (String.Compare(aLabel.ID, bLabel.ID) == 0)
                    {
                        Found = true;
                        break;
                    }
                }
                if (!Found)
                {
                    aLabelList.Add(aLabel);
                }
            }
            else
            {
                System.Web.UI.WebControls.TextBox aTextBox = new System.Web.UI.WebControls.TextBox();
                aTextBox.ID = "wdtp" + FTableName + FFieldItem.DataField + ExtraName + "GridView";
                aTextBox.ToolTip = FFieldItem.DataField;
                //aPicker.Text = String.Format("'<%# Bind(\"{0}\") %>'", FFieldItem.DataField);
                FContainer.Controls.Add(aTextBox);
                Boolean Found = false;
                foreach (System.Web.UI.WebControls.TextBox bWebPicker in aWebTextBoxList)
                {
                    if (String.Compare(aTextBox.ID, bWebPicker.ID) == 0)
                    {
                        Found = true;
                        break;
                    }
                }
                if (!Found)
                {
                    aWebTextBoxList.Add(aTextBox);

                    //Add AddNewRowControlItem to WebGridView
                    if (ExtraName == "F")
                    {
                        if (FWebGridView != null)
                        {
                            Found = false;
                            foreach (AddNewRowControlItem aControlItem in FWebGridView.AddNewRowControls)
                            {
                                if (aControlItem.FieldName.CompareTo(FFieldItem.DataField) == 0)
                                {
                                    Found = true;
                                    break;
                                }
                            }
                            if (!Found)
                            {
                                AddNewRowControlItem aItem = new AddNewRowControlItem();
                                aItem.ControlID = "wdtp" + FTableName + FFieldItem.DataField + ExtraName;
                                aItem.ControlType = WebGridView.AddNewRowControlType.TextBox;
                                aItem.FieldName = FFieldItem.DataField;
                                FWebGridView.AddNewRowControls.Add(aItem);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void GenRefValTemplate(String ExtraName)
        {
            //WebRefVal
            WebRefVal aWebRefVal = new WebRefVal();
            aWebRefVal.ID = "wrv" + FTableName + FFieldItem.DataField + ExtraName + "GridView";
            aWebRefVal.DataSourceID = FDataSourceID;
            //if (ExtraName != "F")
            aWebRefVal.DataBindingField = FFieldItem.DataField;
            if (ExtraName == "")
            {
                aWebRefVal.ReadOnly = true;
                aWebRefVal.BackColor = Color.Transparent;
                aWebRefVal.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
            }
            aWebRefVal.Width = 130;

            if (FFieldItem.RefField != null)
            {
                aWebRefVal.DataValueField = FFieldItem.RefField.ValueMember;
                aWebRefVal.DataTextField = FFieldItem.RefField.DisplayMember;
                foreach (RefColumns aColumn in FFieldItem.RefField.LookupColumns)
                {
                    WebRefColumn RC = new WebRefColumn();
                    RC.ColumnName = aColumn.Column;
                    RC.HeadText = aColumn.HeaderText;
                    aWebRefVal.Columns.Add(RC);
                }
            }
            else
            {
                InfoCommand aInfoCommand = new InfoCommand(DatabaseType);
                //aInfoCommand.Connection = WzdUtils.AllocateConnection(DatabaseName, DatabaseType, true);
                aInfoCommand.Connection = FConnection;
                IDbDataAdapter DA = DBUtils.CreateDbDataAdapter(aInfoCommand);
                DataSet aDataSet = new DataSet();
                //SYS_REFVAL
                aDataSet.Clear();
                aInfoCommand.CommandText = String.Format("Select * from SYS_REFVAL where REFVAL_NO = '{0}'", FFieldItem.RefValNo);
                WzdUtils.FillDataAdapter(FDatabaseType, DA, aDataSet, FFieldItem.RefValNo);
                aWebRefVal.DataValueField = aDataSet.Tables[0].Rows[0]["VALUE_MEMBER"].ToString();
                aWebRefVal.DataTextField = aDataSet.Tables[0].Rows[0]["DISPLAY_MEMBER"].ToString();
                //aWebRefVal.BindingValue = "'<%# + Bind(\"" + FFieldItem.DataField + "\") %>'";
                //SYS_REFVSL_D1 --> Columns
                aDataSet.Clear();
                aInfoCommand.CommandText = String.Format("Select * from SYS_REFVAL_D1 where REFVAL_NO = '{0}'", FFieldItem.RefValNo);
                WzdUtils.FillDataAdapter(FDatabaseType, DA, aDataSet, FFieldItem.RefValNo);
                foreach (DataRow DR in aDataSet.Tables[0].Rows)
                {
                    WebRefColumn RC = new WebRefColumn();
                    RC.ColumnName = DR["FIELD_NAME"].ToString();
                    RC.HeadText = DR["HEADER_TEXT"].ToString();
                    aWebRefVal.Columns.Add(RC);
                }
            }

            FContainer.Controls.Add(aWebRefVal);
            Boolean Found = false;
            foreach (WebRefVal bWebRefVal in aWebRefValList)
            {
                if (String.Compare(bWebRefVal.ID, aWebRefVal.ID) == 0)
                {
                    Found = true;
                    break;
                }
            }
            if (!Found)
                aWebRefValList.Add(aWebRefVal);

            //Add AddNewRowControlItem to WebGridView
            if (ExtraName == "F")
            {
                if (FWebGridView != null)
                {
                    Found = false;
                    foreach (AddNewRowControlItem aControlItem in FWebGridView.AddNewRowControls)
                    {
                        if (aControlItem.FieldName.CompareTo(FFieldItem.DataField) == 0)
                        {
                            Found = true;
                            break;
                        }
                    }
                    if (!Found)
                    {
                        AddNewRowControlItem aItem = new AddNewRowControlItem();
                        aItem.ControlID = "wrv" + FTableName + FFieldItem.DataField + ExtraName;
                        aItem.ControlType = WebGridView.AddNewRowControlType.RefVal;
                        aItem.FieldName = FFieldItem.DataField;
                        FWebGridView.AddNewRowControls.Add(aItem);
                    }
                }
            }
        }
Esempio n. 4
0
        private void GenDateTimeTemplate(String ExtraName)
        {
            if (ExtraName == "")
            {
                System.Web.UI.WebControls.Label aLabel = new System.Web.UI.WebControls.Label();
                aLabel.ID = "l" + FTableName + FFieldItem.DataField + ExtraName + "GridView";
                aLabel.ToolTip = FFieldItem.DataField;
                FContainer.Controls.Add(aLabel);

                Boolean Found = false;
                foreach (System.Web.UI.WebControls.Label bLabel in aLabelList)
                {
                    if (String.Compare(aLabel.ID, bLabel.ID) == 0)
                    {
                        Found = true;
                        break;
                    }
                }
                if (!Found)
                {
                    aLabelList.Add(aLabel);
                }
            }
            else
            {
                WebDateTimePicker aPicker = new WebDateTimePicker();
                aPicker.ID = "wdtp" + FTableName + FFieldItem.DataField + ExtraName + "GridView";
                if (FFieldItem.DataType == typeof(DateTime))
                    aPicker.DateTimeType = dateTimeType.DateTime;
                else if (FFieldItem.DataType == typeof(String))
                    aPicker.DateTimeType = dateTimeType.VarChar;
                aPicker.ToolTip = FFieldItem.DataField;
                //aPicker.Text = String.Format("'<%# Bind(\"{0}\") %>'", FFieldItem.DataField);
                FContainer.Controls.Add(aPicker);
                Boolean Found = false;
                foreach (WebDateTimePicker aWebPicker in aWebDateTimePickerList)
                {
                    if (String.Compare(aPicker.ID, aWebPicker.ID) == 0)
                    {
                        Found = true;
                        break;
                    }
                }
                if (!Found)
                {
                    aWebDateTimePickerList.Add(aPicker);

                    //Add AddNewRowControlItem to WebGridView
                    if (ExtraName == "F")
                    {
                        if (FWebGridView != null)
                        {
                            Found = false;
                            foreach (AddNewRowControlItem aControlItem in FWebGridView.AddNewRowControls)
                            {
                                if (aControlItem.FieldName.CompareTo(FFieldItem.DataField) == 0)
                                {
                                    Found = true;
                                    break;
                                }
                            }
                            if (!Found)
                            {
                                AddNewRowControlItem aItem = new AddNewRowControlItem();
                                aItem.ControlID = "wdtp" + FTableName + FFieldItem.DataField + ExtraName;
                                aItem.ControlType = WebGridView.AddNewRowControlType.DateTimePicker;
                                aItem.FieldName = FFieldItem.DataField;
                                FWebGridView.AddNewRowControls.Add(aItem);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private void GenComboBoxTemplate(String ExtraName)
        {
            if (ExtraName == "")
            {
                System.Web.UI.WebControls.Label aLabel = new System.Web.UI.WebControls.Label();
                aLabel.ID = "l" + FTableName + FFieldItem.DataField + ExtraName + "GridView";
                aLabel.ToolTip = FFieldItem.DataField;
                FContainer.Controls.Add(aLabel);

                Boolean Found = false;
                foreach (System.Web.UI.WebControls.Label bLabel in aLabelList)
                {
                    if (String.Compare(aLabel.ID, bLabel.ID) == 0)
                    {
                        Found = true;
                        break;
                    }
                }
                if (!Found)
                {
                    aLabelList.Add(aLabel);
                }
            }
            else
            {
                WebDropDownList aComboBox = new WebDropDownList();
                aComboBox.ID = "wdd" + FTableName + FFieldItem.DataField + ExtraName + "GridView";
                aComboBox.DataSourceID = FDataSourceID;
                aComboBox.DataMember = FFieldItem.ComboEntityName;
                aComboBox.DataTextField = FFieldItem.ComboTextField;
                aComboBox.DataValueField = FFieldItem.ComboValueField;
                aComboBox.Width = 130;
                FContainer.Controls.Add(aComboBox);

                Boolean Found = false;
                foreach (MyWebDropDownList aDropDownList in aWebDropDownList)
                {
                    if (String.Compare(aComboBox.ID, aDropDownList.WebDropDownList.ID) == 0)
                    {
                        Found = true;
                        break;
                    }
                }
                if (!Found)
                {
                    MyWebDropDownList aDropDown = new MyWebDropDownList(aComboBox, FFieldItem.DataField);
                    aWebDropDownList.Add(aDropDown);

                    //Add AddNewRowControlItem to WebGridView
                    if (ExtraName == "F")
                    {
                        if (FWebGridView != null)
                        {
                            Found = false;
                            foreach (AddNewRowControlItem aControlItem in FWebGridView.AddNewRowControls)
                            {
                                if (aControlItem.FieldName.CompareTo(FFieldItem.DataField) == 0)
                                {
                                    Found = true;
                                    break;
                                }
                            }
                            if (!Found)
                            {
                                AddNewRowControlItem aItem = new AddNewRowControlItem();
                                aItem.ControlID = "wdd" + FTableName + FFieldItem.DataField + ExtraName;
                                aItem.ControlType = WebGridView.AddNewRowControlType.DropDownList;
                                aItem.FieldName = FFieldItem.DataField;
                                FWebGridView.AddNewRowControls.Add(aItem);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
 public void OnCopyAddNewControls(object sender, EventArgs e)
 {
     WebGridView gridView = (WebGridView)this.Component;
     IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
     ControlDesigner designer = (ControlDesigner)host.GetDesigner(gridView);
     foreach (TemplateGroup group in designer.TemplateGroups)
     {
         if (group.GroupName != "EmptyDataTemplate" && group.GroupName != "PagerTemplate")
         {
             string fieldName = "";
             bool foundField = false;
             foreach (TemplateDefinition def in group.Templates)
             {
                 string content = def.Content;
                 if (content != "")
                 {
                     Control[] addCtrls = ControlParser.ParseControls(host, content);
                     if (def.Name == "ItemTemplate" || def.Name == "EditTemplate")
                     {
                         if (!foundField)
                         {
                             foreach (Control ctrl in addCtrls)
                             {
                                 IDataBindingsAccessor dbAccess = (IDataBindingsAccessor)ctrl;
                                 if (dbAccess.HasDataBindings)
                                 {
                                     foreach (DataBinding binding in dbAccess.DataBindings)
                                     {
                                         string[] ExpParts = binding.Expression.Split('"');
                                         if (ExpParts.Length >= 3)
                                         {
                                             fieldName = ExpParts[1];
                                             foundField = true;
                                             break;
                                         }
                                     }
                                     if (foundField)
                                         break;
                                 }
                             }
                         }
                     }
                     else if (def.Name == "FooterTemplate")
                     {
                         foreach (Control ctrl in addCtrls)
                         {
                             if (!(ctrl is LiteralControl))
                             {
                                 AddNewRowControlItem item = new AddNewRowControlItem();
                                 if (ctrl is CheckBox)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.CheckBox;
                                 }
                                 else if (ctrl is IDateTimePicker)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.DateTimePicker;
                                 }
                                 else if (ctrl is DropDownList)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.DropDownList;
                                 }
                                 else if (ctrl is Label)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.Label;
                                 }
                                 else if (ctrl is WebRefValBase)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.RefVal;
                                 }
                                 else if (ctrl is TextBox)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.TextBox;
                                 }
                                 else if (ctrl is HtmlInputText)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.HtmlInputText;
                                 }
                                 else if (ctrl is WebImage)
                                 {
                                     item.ControlType = WebGridView.AddNewRowControlType.WebImage;
                                 }
                                 else
                                 {
                                     continue;
                                 }
                                 item.ControlID = ctrl.ID;
                                 if (foundField)
                                 {
                                     item.FieldName = fieldName;
                                 }
                                 gridView.AddNewRowControls.Add(item);
                                 break;
                             }
                         }
                     }
                 }
             }
             this.Tag.SetDirty(true);
         }
     }
 }