public DbEntryDesignerDataSourceView(DbEntryDataSourceDesigner owner) : base(owner, "MainView") { _dataSource = (DataSourceControl)owner.Component; _modelType = _dataSource.GetType().BaseType.GetGenericArguments()[0]; _info = ObjectInfoFactory.Instance.GetInstance(_modelType); }
/// <summary> /// Occurs when the server control is initialized. /// </summary> /// <param name="e"></param> protected override void OnInit(EventArgs e) { base.OnInit(e); if (!String.IsNullOrEmpty(this.DataSourceID)) { if (Page.IsPostBack == false && base.DesignMode == false) { this.Sort(DefaultSortColumnName, _defaultSortDirection); } DataSourceControl dsc = (DataSourceControl)this.NamingContainer.FindControl(this.DataSourceID); System.Reflection.EventInfo eventInfo = dsc.GetType().GetEvent("Selected"); Delegate d = Delegate.CreateDelegate(eventInfo.EventHandlerType, this, "dsc_Selected"); eventInfo.AddEventHandler(dsc, d); } }
/// <summary> /// Sets DataSourceObject Parameter's WhereClause property /// </summary> /// <param name="whereClause"></param> private void SetWhereClause(string whereClause) { Type t = TypedDataSource.GetType(); System.Reflection.PropertyInfo prop = t.GetProperty("Parameters"); ParameterCollection col = (ParameterCollection)prop.GetValue(TypedDataSource, null); CustomParameter p = col["WhereClause"] as CustomParameter; // -- check if WhereClause exists in parameter's collection if (p != null) { p.Value = GetWhereClauseStatement(whereClause); } else { p = new CustomParameter(); p.Name = "WhereClause"; p.ConvertEmptyStringToNull = false; p.Value = GetWhereClauseStatement(whereClause); col.Add(p); } }
/// <summary> /// Called by the ASP.NET page framework to notify server controls that /// use composition-based implementation to create any child controls they /// contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { // Start with a clean form base.Controls.Clear(); cboFieldName = new DropDownList(); cboFieldName.ID = "cboFieldName"; cboFieldName.SkinID = "cboFieldName"; if (!base.DesignMode) { GridView1 = (GridView)this.NamingContainer.FindControl(this.GridViewControlID); TypedDataSource = (DataSourceControl)this.NamingContainer.FindControl(GridView1.DataSourceID); Type[] typeArguments = TypedDataSource.GetType().BaseType.GetGenericArguments(); _businessEntityType = typeArguments[0].FullName; #region Set up the fields drop down list using the list of table columns Type enumType = EntityUtil.GetType(string.Format("{0}Column", _businessEntityType)); Array c = Enum.GetValues(enumType); for (int i = 0; i < c.Length; i++) { ColumnEnumAttribute cea = EntityHelper.GetAttribute <ColumnEnumAttribute>((Enum)c.GetValue(i)); EnumTextValueAttribute etv = EntityHelper.GetAttribute <EnumTextValueAttribute>((Enum)c.GetValue(i)); // only show fields that we can realistically search against switch (cea.DbType) { case System.Data.DbType.AnsiString: case System.Data.DbType.AnsiStringFixedLength: case System.Data.DbType.Boolean: case System.Data.DbType.Byte: case System.Data.DbType.Currency: case System.Data.DbType.Date: case System.Data.DbType.DateTime: case System.Data.DbType.Decimal: case System.Data.DbType.Double: case System.Data.DbType.Int16: case System.Data.DbType.Int32: case System.Data.DbType.Int64: case System.Data.DbType.SByte: case System.Data.DbType.Single: case System.Data.DbType.String: case System.Data.DbType.StringFixedLength: case System.Data.DbType.Time: case System.Data.DbType.UInt16: case System.Data.DbType.UInt32: case System.Data.DbType.UInt64: case System.Data.DbType.VarNumeric: case System.Data.DbType.Xml: #region Add fields to the dropdown collection ListItem li = new ListItem(); li.Text = etv != null && !string.IsNullOrEmpty(etv.Text) ? EntityHelper.GetPascalSpacedName(etv.Text) : EntityHelper.GetPascalSpacedName(cea.Name); li.Value = cea.Name; cboFieldName.Items.Add(li); #endregion break; default: break; } } #endregion } else { cboFieldName.Items.Add(new ListItem("FieldName", "FieldValue")); } #region UI implementation cboOperator = new DropDownList(); cboOperator.ID = "cboOperator"; cboOperator.SkinID = "cboOperator"; cboOperator.Items.Add(new ListItem("contains", "0")); cboOperator.Items.Add(new ListItem("starts with", "1")); cboOperator.Items.Add(new ListItem("equals", "2")); cboOperator.Items.Add(new ListItem("ends with", "3")); txtKeyword = new TextBox(); txtKeyword.ID = "txtKeyword"; txtKeyword.SkinID = "txtKeyword"; Label lblLookFor = new Label(); lblLookFor.ID = "lblLookFor"; lblLookFor.SkinID = "lblLookFor"; lblLookFor.Text = LookForText; Label lblWhich = new Label(); lblWhich.ID = "lblWhich"; lblWhich.SkinID = "lblWhich"; lblWhich.Text = WhichText; Button cmdSearch = new Button(); cmdSearch.ID = "cmdSearch"; cmdSearch.SkinID = "cmdSearch"; cmdSearch.Text = "Search"; cmdSearch.CausesValidation = CausesValidation; cmdSearch.Click += new EventHandler(cmdSearch_Click); Button cmdReset = new Button(); cmdReset.ID = "cmdReset"; cmdReset.SkinID = "cmdReset"; cmdReset.Text = "Reset"; cmdReset.CausesValidation = CausesValidation; cmdReset.Click += new EventHandler(cmdReset_Click); Table tbl = new Table(); tbl.SkinID = "tblSearchPanel"; TableRow tr = new TableRow(); TableCell td; td = new TableCell(); td.Controls.Add(lblLookFor); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cboFieldName); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(lblWhich); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cboOperator); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(txtKeyword); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cmdSearch); tr.Cells.Add(td); td = new TableCell(); td.Controls.Add(cmdReset); tr.Cells.Add(td); tbl.Rows.Add(tr); #endregion base.Controls.Add(tbl); base.ClearChildViewState(); }