private void GetFields(DataEntryController dec) { IDesignerHost idh = null; idh = (IDesignerHost)dec.Page.Site.GetService(typeof(IDesignerHost)); if (idh != null) { DataFieldControl dfc = null; foreach (Object c in idh.Container.Components) { dfc = c as DataFieldControl; if (dfc != null) { _fields.Add(new DataFieldColumn(dfc)); } } } }
public override string GetDesignTimeHtml() { /* // Retrieve the controls to ensure they are created. * ControlCollection controls = ((Control)Component).Controls; * return base.GetDesignTimeHtml(); */ // Retrieve the controls to ensure they are created. ControlCollection controls = ((Control)Component).Controls; DataFieldControl dfc = (DataFieldControl)Component; string designTimeHtml = null; string originalText = string.Empty; string originalFormatString = string.Empty; try { //Make a string to indicate the current settings // for field and set it as the field text string settings = string.Empty; if (dfc.IsInsertField == true) { if (dfc.IsInsertValueRequired == true) { settings += "Ir"; } else { settings += "I"; } } if (dfc.IsEntryField == true) { if (dfc.IsEntryValueRequired) { settings += (settings == string.Empty)? "Er" : ",Er"; } else { settings += (settings == string.Empty)? "E" : ",E"; } } if (dfc.IsDoubleEntryField == true) { settings += (settings == string.Empty)? "D" : ",D"; } if (dfc.IsReadOnly == true) { settings += (settings == string.Empty)? "R" : ",R"; } string ftype = string.Empty; switch (dfc.FieldDataType) { case FieldDataType.INT: ftype = "[INT]"; break; case FieldDataType.FLOAT: ftype = "[FLOAT]"; break; case FieldDataType.DATE: ftype = "[DATE]"; break; case FieldDataType.TEXT: ftype = "[TEXT]"; break; } // save any existing text and format string originalText = dfc.FieldTextBoxText; originalFormatString = dfc.FormatString; //Clear the format. This is needed to allow setting //of fieldtextboxtext without causing an attempt to format //an invalid value dfc.FormatString = string.Empty; dfc.FieldTextBoxText = ((settings != string.Empty)? "[" + settings + "] " : "") + ftype + originalText; if (dfc.ShowAllForLayout) { //set some fake errors dfc.AddError("Sample Error 1"); dfc.AddError("Sample Error 2"); dfc.AddError("Sample Error 3"); //show override check box dfc.VerifyError = true; } // return the html designTimeHtml = base.GetDesignTimeHtml(); } catch (Exception ex) { designTimeHtml = GetErrorDesignTimeHtml(ex); } finally { // restore original control settings dfc.FormatString = originalFormatString; dfc.FieldTextBoxText = originalText; //clear errors dfc.ClearErrors(); //turn off override check box dfc.VerifyError = false; } if ((designTimeHtml == null) || (designTimeHtml.Length == 0)) { designTimeHtml = GetEmptyDesignTimeHtml(); } //return return(designTimeHtml); }
public TableCell BuildCell(DataView dv, string mode, string display_the) { TableCell cell = new TableCell(); DataTable dt = dv.ToTable(); foreach (DataRow row in dt.Rows) { int width_label = (row["width_label"].ToString() == "") ? 300 : Convert.ToInt16(row["width_label"].ToString()); int width_box = (row["width_box"].ToString() == "") ? 120 : Convert.ToInt16(row["width_box"].ToString()); //HERE!!!! check to see if mode is necessary anymore if (mode == "DE Form") { if (display_the == "Layout") { DataFieldControl dfc = new DataFieldControl(); dfc.DatabaseField = row["databasefield"].ToString(); dfc.FieldLabelText = row["aspxfieldlabeltext"].ToString(); dfc.FieldLabelWidth = Unit.Pixel(width_label); width_box = (width_box < 120) ? 120 : width_box; dfc.FieldTextBoxWidth = Unit.Pixel(width_box); dfc.FieldTextBoxText = row["databasefield"].ToString(); dfc.ToolTip = row["databasefield"].ToString(); cell.Controls.Add(dfc); if (row["showValueLabels"].ToString() == "1") { ValueSetLabel vs = new ValueSetLabel(); vs.DatabaseField = row["databasefield"].ToString(); vs.DatabaseTable = row["databasetable"].ToString(); cell.Controls.Add(vs); } } else if (display_the == "Code") { string isReadonly = (row["isReadOnly"].ToString() == "0" | string.IsNullOrEmpty(row["isReadOnly"].ToString())) ? " IsEntryField=\"True\"" : " IsReadOnly=\"True\""; string isDoubleEntry = (row["DoubleEntryRequired"].ToString() == "0" | string.IsNullOrEmpty(row["isReadOnly"].ToString())) ? " IsDoubleEntryField=\"False\"" : " IsDoubleEntryField=\"True\""; cell.Text += "<def:datafieldcontrol runat=\"server\" ID=\"" + row["databasefield"].ToString() + "\" DatabaseField=\"" + row["databasefield"].ToString() + "\"" + isReadonly + isDoubleEntry + " />"; } } else if (mode == "Text") { if (row["aspxfieldlabeltext"].ToString() != "" & row["aspxfieldlabeltext"].ToString() != " ") { Label l = new Label(); l.Text = row["aspxfieldlabeltext"].ToString(); l.Width = width_label; cell.Controls.Add(l); } TextBox t = new TextBox(); t.Text = row["databasefield"].ToString(); t.Font.Size = 8; t.Width = (width_box < 120) ? 120 : width_box; t.ToolTip = row["databasefield"].ToString(); if (row["isReadOnly"].ToString() == "1") { t.BackColor = Color.SkyBlue; } else { t.BackColor = Color.LightYellow; } if (row["DoubleEntryRequired"].ToString() == "1" | row["DoubleEntryRequired"].ToString() == "") { t.ForeColor = Color.Black; } else { t.ForeColor = Color.Red; } Literal lit = new Literal(); lit.Text += "<br/>"; cell.Controls.Add(t); cell.Controls.Add(lit); if (row["showValueLabels"].ToString() == "1") { ValueSetLabel vs = new ValueSetLabel(); vs.DatabaseField = row["databasefield"].ToString(); vs.DatabaseTable = row["databasetable"].ToString(); cell.Controls.Add(vs); } //string lbl = row["aspxfieldlabeltext"].ToString(); string var //= row["databasefield"].ToString(); cell.Text += lbl.ToString() //+ "....<i><b>" + var + "</b></i><br/>"; } } cell.VerticalAlign = VerticalAlign.Top; cell.BorderColor = Color.Silver; cell.BorderWidth = 1; return(cell); }