⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datatypefieldbuilder.cs~

📁 一种.net实现ajax方法的类库
💻 CS~
字号:
/**
 * Project: emergetk: stateful web framework for the masses
 * File name: DataTypeFieldBuilder.cs
 * Description: WidgetFactory that generates widgets based on incoming data type and output medium.
 *   
 * @author Ben Joldersma, All-In-One Creations, Ltd. http://all-in-one-creations.net, Copyright (C) 2006.
 *   
 * @see The GNU Public License (GPL)
 */
/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
using System;
using EmergeTk.Model;
using System.Collections.Generic;
using System.Reflection;
using EmergeTk.Widgets.Html;

namespace EmergeTk
{
    public enum FieldLayout
    {
        Terse,
        Spacious
    }
	/// <summary>
	/// Summary description for DataTypeFieldBuilder.
	/// </summary>
	public class DataTypeFieldBuilder
	{
		private DataTypeFieldBuilder()
		{
		}

        public static Widget GetViewWidget(ColumnInfo fi)
        {
            Widget l = Context.Current.CreateWidget<Label>();
            l.id = fi.Name;
            return l;
        }

        public static Widget GetEditWidget<T>(ColumnInfo fi, FieldLayout layout) where T : AbstractRecord, new()
		{
			if( fi.Type.Name.Contains("RecordList") )
				return null;
            
            Widget propWidget = null;
			switch( fi.DataType )
			{
                case DataType.SmallText:
                    TextBox smallTexBox = Context.Current.CreateWidget<TextBox>();
                    smallTexBox.Columns = 20;
                    propWidget = smallTexBox;
                    break;
                case DataType.Xml:
                    TextBox xmlTextBox = Context.Current.CreateWidget<TextBox>();
                    xmlTextBox.Rows = 10;
                    xmlTextBox.Columns = 40;
                    xmlTextBox.ClassName = "xmlTextBox";
                    propWidget = xmlTextBox;
                    break;
                case DataType.LargeText:
                    TextBox largeTextBox = Context.Current.CreateWidget<TextBox>();
                    largeTextBox.Rows = 10;
                    largeTextBox.Columns = 40;
                    largeTextBox.IsRich = true;
                    if( layout == FieldLayout.Terse )
                        largeTextBox.ClassName = "largeGridEditTextBox";
                    propWidget = largeTextBox;
                    break;
                case DataType.RecordSelect:
                    MethodInfo mi = typeof(DataTypeFieldBuilder).GetMethod("GetRecordSelect");
                    mi = mi.MakeGenericMethod(fi.Type);
                    propWidget = mi.Invoke(null, new object[] { fi }) as Widget;
                    break;
			}
				
			if( propWidget == null )
			{
				if( fi.Type == typeof(DateTime) )
				{
					propWidget = Context.Current.CreateWidget<DateField>();
				}
                else if (fi.Type.IsEnum)
                {
                    DropDown dd = Context.Current.CreateWidget<DropDown>();
                    dd.Options = new List<string>(Enum.GetNames(fi.Type));
                    dd.DefaultProperty = "SelectedIndex";
                    propWidget = dd;
                }
                else
                {
                    TextBox tb = Context.Current.CreateWidget<TextBox>();
                    if (layout == FieldLayout.Spacious) tb.Columns = 50;
                    propWidget = tb;
                }
			}
			propWidget.Id = fi.Name;
            if (layout == FieldLayout.Spacious)
            {
                LabeledWidget<Widget> lc = Context.Current.CreateWidget<LabeledWidget<Widget>>();
                lc.Label.Text = fi.Name;
                lc.Widget = propWidget;
                propWidget = lc;
            }
			return propWidget;
		}

        public static Widget GetRecordSelect<T>(Model.ColumnInfo fi) where T : AbstractRecord, new()
        {
            RecordSelect<T> dd = Context.Current.CreateWidget<RecordSelect<T>>();
            IRecordList<T> records = DataProvider.RequestProvider<T>().Load<T>();
            dd.DataSource = records;
            dd.DataBind();
            return dd;
        }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -