public override string Get() { if (string.IsNullOrWhiteSpace(this.FieldConfig.ColumnName)) { return(string.Empty); } StringBuilder textBox = new StringBuilder(); string type = "text"; bool isPasswordField = this.FieldConfig.ColumnName.ToUpperInvariant().Equals("PASSWORD"); TagBuilder.Begin(textBox, "input"); TagBuilder.AddId(textBox, this.FieldConfig.ColumnName); TagBuilder.AddAttribute(textBox, "data-scrud", "text"); if (isPasswordField && this.FieldConfig.IsDisabled) { type = "password"; this.FieldConfig.DefaultValue = "fake-password"; } if (this.FieldConfig.IsDisabled) { textBox.Append(" readonly='readonly'"); } if (!string.IsNullOrWhiteSpace(this.ValidationType)) { TagBuilder.AddAttribute(textBox, "data-vtype", this.ValidationType); } TagBuilder.AddType(textBox, type); if (this.FieldConfig.DataType.ToUpperInvariant().Equals("COLOR")) { TagBuilder.AddClass(textBox, "color"); } if (!this.FieldConfig.DefaultValue.StartsWith("nextVal", StringComparison.OrdinalIgnoreCase)) { if (this.ValidationType == "date") { DateTime date = Conversion.TryCastDate(this.FieldConfig.DefaultValue); if (date != DateTime.MinValue) { TagBuilder.AddValue(textBox, date.Date == date ? date.ToString("d") : date.ToString("f")); } TagBuilder.AddClass(textBox, "date"); } else { TagBuilder.AddValue(textBox, this.FieldConfig.DefaultValue); } } if (!this.FieldConfig.IsNullable) { TagBuilder.AddRequired(textBox); } if (this.FieldConfig.MaxLength > 0) { TagBuilder.AddAttribute(textBox, "maxlength", this.FieldConfig.MaxLength); } TagBuilder.Close(textBox, true); return(textBox.ToString()); }
private string GetSelect() { StringBuilder select = new StringBuilder(); TagBuilder.Begin(select, "select"); TagBuilder.AddId(select, this.FieldConfig.ColumnName); TagBuilder.AddAttribute(select, "data-scrud", "select"); if (!this.FieldConfig.IsNullable) { TagBuilder.AddRequired(select); } if (this.FieldConfig.IsDisabled) { TagBuilder.AddDisabled(select); } TagBuilder.Close(select); using ( DataTable table = GetTable(this.FieldConfig.ParentTableSchema, this.FieldConfig.ParentTable, this.FieldConfig.ParentTableColumn, this.Config.DisplayViews, this.Config.UseDisplayViewsAsParents)) { //Get the expression value of display field from comma separated list of expressions. //The expression can be either the column name or a column expression. string columnOrExpression = Helpers.Expression.GetExpressionValue(this.Config.DisplayFields, this.FieldConfig.ParentTableSchema, this.FieldConfig.ParentTable, this.FieldConfig.ParentTableColumn); //Let's check whether the display field expression really exists. //If it does not exist, it is probably an expression column. if (!table.Columns.Contains(columnOrExpression) && !string.IsNullOrWhiteSpace(columnOrExpression)) { //Add the expression as a new column in the datatable. table.Columns.Add("DataTextField", typeof(string), columnOrExpression); columnOrExpression = "DataTextField"; } if (table.Rows.Count > 0) { if (this.FieldConfig.IsNullable) { TagBuilder.Begin(select, "option"); TagBuilder.AddAttribute(select, "value", string.Empty); TagBuilder.Close(select); select.Append(string.Empty); TagBuilder.EndTag(select, "option"); } foreach (DataRow row in table.Rows) { string value = row[this.FieldConfig.ParentTableColumn].ToString(); TagBuilder.Begin(select, "option"); TagBuilder.AddAttribute(select, "value", value); if (value == this.FieldConfig.DefaultValue) { TagBuilder.AddSelected(select); } TagBuilder.Close(select); @select.Append(!string.IsNullOrWhiteSpace(columnOrExpression) ? row[columnOrExpression] : row[1]); TagBuilder.EndTag(select, "option"); } } } TagBuilder.EndTag(select, "select"); return(select.ToString()); }