123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bowin.Web.Controls.Mvc
- {
- public abstract class TextBoxValueResolver
- {
- public abstract string Execute(TextBox txtBox);
- public static TextBoxValueResolver CreateValueResolver(TextBoxType type)
- {
- TextBoxValueResolver resolver = new DefaultTextBoxValueResolver();
- switch (type)
- {
- case TextBoxType.DateTime:
- resolver = new DateTimeTextBoxValueResolver();
- break;
- case TextBoxType.Date:
- resolver = new DateTextBoxValueResolver();
- break;
- case TextBoxType.Time:
- resolver = new TimeTextBoxValueResolver();
- break;
- default:
- break;
- }
- return resolver;
- }
- }
- public class DefaultTextBoxValueResolver:TextBoxValueResolver
- {
- public override string Execute(TextBox txtBox)
- {
- return txtBox.Value == null ? "" : txtBox.Value.ToString();
- }
- }
- internal class DateTextBoxValueResolver : TextBoxValueResolver
- {
- public override string Execute(TextBox txtBox)
- {
- return txtBox.Value == null ? "" : (Convert.ToDateTime(txtBox.Value)).ToString("yyyy-MM-dd");
- }
- }
- internal class DateTimeTextBoxValueResolver : TextBoxValueResolver
- {
- public override string Execute(TextBox txtBox)
- {
- return txtBox.Value == null ? "" : (Convert.ToDateTime(txtBox.Value)).ToString("yyyy-MM-dd HH:mm:ss");
- }
- }
- internal class TimeTextBoxValueResolver : TextBoxValueResolver
- {
- public override string Execute(TextBox txtBox)
- {
- if (txtBox.Value is TimeSpan)
- {
- return txtBox.Value == null ? "" : ((TimeSpan)txtBox.Value).ToString("hh\\:mm\\:ss");
- }
- else
- {
- return txtBox.Value == null ? "" : (Convert.ToDateTime(txtBox.Value)).ToString("HH:mm:ss");
- }
- }
- }
- }
|