init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal interface IListControl {
|
||||
|
||||
String[] Options { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class IntDroplist : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (String str in this.Options) {
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "<option value=\"{0}\" selected=\"selected\">{0}</option>", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "<option value=\"{0}\">{0}</option>", str );
|
||||
}
|
||||
}
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><select name=\"{1}\" class=\"IntDroplist\">{2}</select></span>", base.Label, base.Name, builder.ToString() );
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override System.Type Type {
|
||||
get { return typeof( int ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class IntTextbox : ParamControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><input name=\"{1}\" type=\"text\" value=\"{2}\" class=\"IntTextbox\" /></span>", base.Label, base.Name, base.Value );
|
||||
}
|
||||
}
|
||||
|
||||
public override System.Type Type {
|
||||
get { return typeof( int ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class LongTextbox : ParamControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><textarea name=\"{1}\" class=\"LongTextbox\">{2}</textarea></span>", base.Label, base.Name, base.Value );
|
||||
}
|
||||
}
|
||||
|
||||
public override System.Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using Zhaizj.Framework;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
/// <summary>
|
||||
/// 参数在 html 表单中对应的控件
|
||||
/// </summary>
|
||||
public abstract class ParamControl {
|
||||
|
||||
/// <summary>
|
||||
/// web界面中显示用的字符
|
||||
/// </summary>
|
||||
public String Label { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数名称,从0开始:param0, param1, param2, .... paramN
|
||||
/// </summary>
|
||||
public String Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数的值,用于传递
|
||||
/// </summary>
|
||||
public String Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 控件的 Html
|
||||
/// </summary>
|
||||
public abstract String Html { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数的类型
|
||||
/// </summary>
|
||||
public abstract Type Type { get; }
|
||||
|
||||
protected ParamControl() { }
|
||||
|
||||
/// <summary>
|
||||
/// 将参数值转换为正确的参数类型
|
||||
/// </summary>
|
||||
/// <param name="val"></param>
|
||||
/// <returns></returns>
|
||||
public Object ChangeType( Object val ) {
|
||||
|
||||
if (val == null) return getNullValue( val );
|
||||
|
||||
try {
|
||||
return Convert.ChangeType( val, this.Type );
|
||||
}
|
||||
catch {
|
||||
return getNullValue( val );
|
||||
}
|
||||
}
|
||||
|
||||
private Object getNullValue( Object val ) {
|
||||
if (this.Type == typeof( int )) return 0;
|
||||
if (this.Type == typeof( DateTime )) return DateTime.Now;
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取参数对应的控件
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="paramIndex"></param>
|
||||
/// <returns></returns>
|
||||
public static ParamControl GetControl( String param, int paramIndex ) {
|
||||
return GetControl( param, paramIndex, "" );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取参数对应的控件
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <param name="paramIndex"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static ParamControl GetControl( String param, int paramIndex, String value ) {
|
||||
|
||||
if (strUtil.IsNullOrEmpty( param )) return null;
|
||||
|
||||
String[] strArray = param.Split( new char[] { '=' } );
|
||||
String itemName = strArray[0];
|
||||
String itemValue = strArray[1];
|
||||
|
||||
if (itemValue.StartsWith( "IntTextbox" )) {
|
||||
IntTextbox intBox = new IntTextbox();
|
||||
init( intBox, itemName, paramIndex, value );
|
||||
return intBox;
|
||||
}
|
||||
if (itemValue.StartsWith( "IntDroplist" )) {
|
||||
IntDroplist droplist = new IntDroplist();
|
||||
initList( droplist, itemName, paramIndex, value, itemValue );
|
||||
return droplist;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringTextbox" )) {
|
||||
StringTextbox strBox = new StringTextbox();
|
||||
init( strBox, itemName, paramIndex, value );
|
||||
return strBox;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringDroplist" )) {
|
||||
StringDroplist droplist = new StringDroplist();
|
||||
initList( droplist, itemName, paramIndex, value, itemValue );
|
||||
return droplist;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringRadio" )) {
|
||||
StringRadio radio = new StringRadio();
|
||||
initList( radio, itemName, paramIndex, value, itemValue );
|
||||
return radio;
|
||||
}
|
||||
if (itemValue.StartsWith( "StringCheckbox" )) {
|
||||
StringCheckbox checkbox = new StringCheckbox();
|
||||
initList( checkbox, itemName, paramIndex, value, itemValue );
|
||||
return checkbox;
|
||||
}
|
||||
if (itemValue.StartsWith( "LongTextbox" )) {
|
||||
LongTextbox longBox = new LongTextbox();
|
||||
init( longBox, itemName, paramIndex, value );
|
||||
return longBox;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void init( ParamControl ctl, String itemName, int paramIndex, String value ) {
|
||||
ctl.Label = itemName;
|
||||
|
||||
// 参数从0开始:param0, param1, param2, .... paramN
|
||||
ctl.Name = "param" + paramIndex;
|
||||
ctl.Value = value;
|
||||
}
|
||||
|
||||
private static void initList( ParamControl ctl, String itemName, int paramIndex, String value, String itemValue ) {
|
||||
ctl.Label = itemName;
|
||||
ctl.Name = "param" + paramIndex;
|
||||
ctl.Value = value;
|
||||
((IListControl)ctl).Options = getOptions( itemValue );
|
||||
}
|
||||
|
||||
private static String[] getOptions( String itemValue ) {
|
||||
String str = itemValue.TrimEnd( ')' ).Split( '(' )[1];
|
||||
return str.Split( '/' );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringCheckbox : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append( "<span class=\"paramLabel\">" );
|
||||
builder.Append( base.Label );
|
||||
builder.Append( "</span> <span class=\"paramControl\">" );
|
||||
foreach (String str in this.Options) {
|
||||
builder.AppendFormat( "<input name=\"{0}\" value=\"{1}\" type=\"checkbox\" class=\"StringCheckbox\"", base.Name, str );
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "checked=\"checked\" />{0} ", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "/>{0} ", str );
|
||||
}
|
||||
}
|
||||
builder.Append( "</span>" );
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringDroplist : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
foreach (String str in this.Options) {
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "<option value=\"{0}\" selected=\"selected\">{0}</option>", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "<option value=\"{0}\">{0}</option>", str );
|
||||
}
|
||||
}
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><select name=\"{1}\" class=\"StringDroplist\">{2}</select></span>", base.Label, base.Name, builder.ToString() );
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringRadio : ParamControl, IListControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append( "<span class=\"paramLabel\">" );
|
||||
builder.Append( base.Label );
|
||||
builder.Append( "</span> <span class=\"paramControl\">" );
|
||||
foreach (String str in this.Options) {
|
||||
builder.AppendFormat( "<input name=\"{0}\" value=\"{1}\" type=\"radio\" class=\"StringRadio\"", base.Name, str );
|
||||
if (str.Equals( base.Value )) {
|
||||
builder.AppendFormat( "checked=\"checked\" />{0} ", str );
|
||||
}
|
||||
else {
|
||||
builder.AppendFormat( "/>{0} ", str );
|
||||
}
|
||||
}
|
||||
builder.Append( "</span>" );
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public String[] Options { get; set; }
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.SOA.Controls {
|
||||
|
||||
|
||||
internal class StringTextbox : ParamControl {
|
||||
|
||||
public override String Html {
|
||||
get {
|
||||
return String.Format( "<span class=\"paramLabel\">{0}</span> <span class=\"paramControl\"><input name=\"{1}\" type=\"text\" value=\"{2}\" class=\"StringTextbox\"/></span>", base.Label, base.Name, base.Value );
|
||||
}
|
||||
}
|
||||
|
||||
public override Type Type {
|
||||
get { return typeof( String ); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user