wicket中日历控件的用法
来源:互联网 发布:淘宝网店怎么开 编辑:程序博客网 时间:2024/06/06 02:25
本文的解决方案,通过自动生成SQL语句,在一定程度上降低出错的概率,从而提高编程效率。
public interface IClause
{
void Add(string name, object val);
void AddWhere(string name, object val);
void Clear();
string TableName { set;}
}
首先抽象出生成器的标准接口,Add及Addwhere,分别用增加字段及WHERE条件的,
比如说,在Insert状态下,Add("name","gates")相当于字段name的值为gates
在select状态下,Add("name","gates")相当于字段name的别名为gates即select name as gates
在update状态下,Add("name","gates")相当于字段name的值为gates即update name = "gates"
TableName属性即操作的表名
Clear()是为了一个实例多次应用,清空当前的字段及WHERE条件,表名的设置都通过TABLENAME属性设置
基类实现接口,通过基类的实现,从而有效的实现的代码屏蔽。...{
private string m_strTable = string.Empty;
private Where m_oWhere = new Where();
protected BaseClause()
...{
this.m_strTable = string.Empty;
this.Clear();
}
public virtual void Add(string name, object val)
...{
}
public void AddWhere(string name, object val)
...{
this.m_oWhere.Add(name, val);
}
public void Clear()
...{
this.m_oWhere.Clear();
this.auxClear();
}
public string TableName
...{
set ...{ this.m_strTable = value; }
protected get ...{ return this.m_strTable; }
}
public sealed override string ToString()
...{
return this.ToStr + this.m_oWhere.ToString();
}
protected abstract string ToStr ...{ get;}
protected virtual void auxClear() ...{ }
}
...{
public enum Flag
...{
Insert,
Update,
Select,
Delete,
}
public static IClause Create(string table, Flag category)
...{
BaseClause ret = null;
switch (category)
...{
case Flag.Insert:
ret = new Insert();
break;
case Flag.Update:
ret = new Update();
break;
case Flag.Select:
ret = new Select();
break;
case Flag.Delete:
ret = new Delete();
break;
default:
break;
}
if (ret != null)
...{
ret.TableName = table;
}
return ret;
}
}
各派生类的具体实现
...{
private string m_strName;
private string m_strValue;
public override void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strName == string.Empty)
...{
this.m_strName = "[" + name + "]";
this.m_strValue = val;
}
else
...{
this.m_strName += ",[" + name + "]";
this.m_strValue += "," + val;
}
}
protected override string ToStr
...{
get ...{ return "INSERT INTO [" + base.TableName + "] ( " + this.m_strName + " ) values ( " + this.m_strValue + " )"; }
}
protected override void auxClear()
...{
this.m_strValue = string.Empty;
this.m_strName = string.Empty;
}
}
private class Delete : BaseClause
...{
public Delete()
...{
}
protected override string ToStr
...{
get ...{ return "DELETE FROM [" + base.TableName + "]"; }
}
}
private class Update : BaseClause
...{
private string m_strUpdate;
public override void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strUpdate == string.Empty)
...{
this.m_strUpdate = "[" + name + "]=" + val;
}
else
...{
this.m_strUpdate += ",[" + name + "]=" + val;
}
}
protected override string ToStr
...{
get ...{ return "UPDATE [" + base.TableName + "] SET " + this.m_strUpdate; }
}
protected override void auxClear()
...{
this.m_strUpdate = string.Empty;
}
}
private class Select : BaseClause
...{
private string m_strSelect;
public override void Add(string name, object alis)
...{
if (alis == null)
...{
this.Add(name, name, false);
}
else
...{
this.Add(name, alis.ToString(), false);
}
}
private void Add(string name, string alis, bool isref)
...{
if (this.m_strSelect == string.Empty)
...{
this.m_strSelect = "[" + name + "] as [" + alis + "]";
}
else
...{
this.m_strSelect += ",[" + name + "] as [" + alis + "]";
}
}
protected override string ToStr
...{
get
...{
if (this.m_strSelect == string.Empty)
...{
this.m_strSelect = "*";
}
return "SELECT " + this.m_strSelect + " FROM [" + base.TableName + "]";
}
}
protected override void auxClear()
...{
this.m_strSelect = string.Empty;
}
}
private class Where
...{
private string m_strWhere;
public Where()
...{
this.Clear();
}
public void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strWhere == string.Empty)
...{
this.m_strWhere = "[" + name + "]=" + val;
}
else
...{
this.m_strWhere += " and [" + name + "]=" + val;
}
}
public override string ToString()
...{
string strRet = string.Empty;
if (this.m_strWhere != string.Empty)
...{
strRet = " Where " + this.m_strWhere;
}
return strRet;
}
public void Clear()
...{
this.m_strWhere = string.Empty;
}
}
虽然在DotNet Framework3.5 面世以后,可通过LINQ支持SQL的直接查询,但LINQ只支持SQL系列的,SQL2K,SQL2K5,对于ACCESS,ORACLE,MYSQL等不支持。同时平常的一些工具的创作,对于我们的软件水平也大有好处
下面附上DBACCESS的整套代码,供大家分享
下面附上DBACCESS的整套代码,供大家分享
...{
void Add(string name, object val);
void AddWhere(string name, object val);
void Clear();
string TableName ...{ set;}
}
public abstract class ClauseFactory
...{
public enum Flag
...{
Insert,
Update,
Select,
Delete,
}
Create#region Create
public static IClause Create(string table, Flag category)
...{
BaseClause ret = null;
switch (category)
...{
case Flag.Insert:
ret = new Insert();
break;
case Flag.Update:
ret = new Update();
break;
case Flag.Select:
ret = new Select();
break;
case Flag.Delete:
ret = new Delete();
break;
default:
break;
}
if (ret != null)
...{
ret.TableName = table;
}
return ret;
}
#endregion
BaseClause#region BaseClause
private abstract class BaseClause : IClause
...{
private string m_strTable = string.Empty;
private Where m_oWhere = new Where();
protected BaseClause()
...{
this.m_strTable = string.Empty;
this.Clear();
}
public virtual void Add(string name, object val)
...{
}
public void AddWhere(string name, object val)
...{
this.m_oWhere.Add(name, val);
}
public void Clear()
...{
this.m_oWhere.Clear();
this.auxClear();
}
public string TableName
...{
set ...{ this.m_strTable = value; }
protected get ...{ return this.m_strTable; }
}
public sealed override string ToString()
...{
return this.ToStr + this.m_oWhere.ToString();
}
protected abstract string ToStr ...{ get;}
protected virtual void auxClear() ...{ }
}
#endregion
Insert, Update..Join#region Insert, Update..Join
private class Insert : BaseClause
...{
private string m_strName;
private string m_strValue;
public override void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strName == string.Empty)
...{
this.m_strName = "[" + name + "]";
this.m_strValue = val;
}
else
...{
this.m_strName += ",[" + name + "]";
this.m_strValue += "," + val;
}
}
protected override string ToStr
...{
get ...{ return "INSERT INTO [" + base.TableName + "] ( " + this.m_strName + " ) values ( " + this.m_strValue + " )"; }
}
protected override void auxClear()
...{
this.m_strValue = string.Empty;
this.m_strName = string.Empty;
}
}
private class Delete : BaseClause
...{
public Delete()
...{
}
protected override string ToStr
...{
get ...{ return "DELETE FROM [" + base.TableName + "]"; }
}
}
private class Update : BaseClause
...{
private string m_strUpdate;
public override void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strUpdate == string.Empty)
...{
this.m_strUpdate = "[" + name + "]=" + val;
}
else
...{
this.m_strUpdate += ",[" + name + "]=" + val;
}
}
protected override string ToStr
...{
get ...{ return "UPDATE [" + base.TableName + "] SET " + this.m_strUpdate; }
}
protected override void auxClear()
...{
this.m_strUpdate = string.Empty;
}
}
private class Select : BaseClause
...{
private string m_strSelect;
public override void Add(string name, object alis)
...{
if (alis == null)
...{
this.Add(name, name, false);
}
else
...{
this.Add(name, alis.ToString(), false);
}
}
private void Add(string name, string alis, bool isref)
...{
if (this.m_strSelect == string.Empty)
...{
this.m_strSelect = "[" + name + "] as [" + alis + "]";
}
else
...{
this.m_strSelect += ",[" + name + "] as [" + alis + "]";
}
}
protected override string ToStr
...{
get
...{
if (this.m_strSelect == string.Empty)
...{
this.m_strSelect = "*";
}
return "SELECT " + this.m_strSelect + " FROM [" + base.TableName + "]";
}
}
protected override void auxClear()
...{
this.m_strSelect = string.Empty;
}
}
private class Where
...{
private string m_strWhere;
public Where()
...{
this.Clear();
}
public void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strWhere == string.Empty)
...{
this.m_strWhere = "[" + name + "]=" + val;
}
else
...{
this.m_strWhere += " and [" + name + "]=" + val;
}
}
public override string ToString()
...{
string strRet = string.Empty;
if (this.m_strWhere != string.Empty)
...{
strRet = " Where " + this.m_strWhere;
}
return strRet;
}
public void Clear()
...{
this.m_strWhere = string.Empty;
}
}
#endregion
}
...{
void Add(string name, object val);
void AddWhere(string name, object val);
void Clear();
string TableName ...{ set;}
}
public abstract class ClauseFactory
...{
public enum Flag
...{
Insert,
Update,
Select,
Delete,
}
Create#region Create
public static IClause Create(string table, Flag category)
...{
BaseClause ret = null;
switch (category)
...{
case Flag.Insert:
ret = new Insert();
break;
case Flag.Update:
ret = new Update();
break;
case Flag.Select:
ret = new Select();
break;
case Flag.Delete:
ret = new Delete();
break;
default:
break;
}
if (ret != null)
...{
ret.TableName = table;
}
return ret;
}
#endregion
BaseClause#region BaseClause
private abstract class BaseClause : IClause
...{
private string m_strTable = string.Empty;
private Where m_oWhere = new Where();
protected BaseClause()
...{
this.m_strTable = string.Empty;
this.Clear();
}
public virtual void Add(string name, object val)
...{
}
public void AddWhere(string name, object val)
...{
this.m_oWhere.Add(name, val);
}
public void Clear()
...{
this.m_oWhere.Clear();
this.auxClear();
}
public string TableName
...{
set ...{ this.m_strTable = value; }
protected get ...{ return this.m_strTable; }
}
public sealed override string ToString()
...{
return this.ToStr + this.m_oWhere.ToString();
}
protected abstract string ToStr ...{ get;}
protected virtual void auxClear() ...{ }
}
#endregion
Insert, Update..Join#region Insert, Update..Join
private class Insert : BaseClause
...{
private string m_strName;
private string m_strValue;
public override void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strName == string.Empty)
...{
this.m_strName = "[" + name + "]";
this.m_strValue = val;
}
else
...{
this.m_strName += ",[" + name + "]";
this.m_strValue += "," + val;
}
}
protected override string ToStr
...{
get ...{ return "INSERT INTO [" + base.TableName + "] ( " + this.m_strName + " ) values ( " + this.m_strValue + " )"; }
}
protected override void auxClear()
...{
this.m_strValue = string.Empty;
this.m_strName = string.Empty;
}
}
private class Delete : BaseClause
...{
public Delete()
...{
}
protected override string ToStr
...{
get ...{ return "DELETE FROM [" + base.TableName + "]"; }
}
}
private class Update : BaseClause
...{
private string m_strUpdate;
public override void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strUpdate == string.Empty)
...{
this.m_strUpdate = "[" + name + "]=" + val;
}
else
...{
this.m_strUpdate += ",[" + name + "]=" + val;
}
}
protected override string ToStr
...{
get ...{ return "UPDATE [" + base.TableName + "] SET " + this.m_strUpdate; }
}
protected override void auxClear()
...{
this.m_strUpdate = string.Empty;
}
}
private class Select : BaseClause
...{
private string m_strSelect;
public override void Add(string name, object alis)
...{
if (alis == null)
...{
this.Add(name, name, false);
}
else
...{
this.Add(name, alis.ToString(), false);
}
}
private void Add(string name, string alis, bool isref)
...{
if (this.m_strSelect == string.Empty)
...{
this.m_strSelect = "[" + name + "] as [" + alis + "]";
}
else
...{
this.m_strSelect += ",[" + name + "] as [" + alis + "]";
}
}
protected override string ToStr
...{
get
...{
if (this.m_strSelect == string.Empty)
...{
this.m_strSelect = "*";
}
return "SELECT " + this.m_strSelect + " FROM [" + base.TableName + "]";
}
}
protected override void auxClear()
...{
this.m_strSelect = string.Empty;
}
}
private class Where
...{
private string m_strWhere;
public Where()
...{
this.Clear();
}
public void Add(string name, object val)
...{
if (val == null)
...{
this.Add(name, "null", false);
}
else
...{
this.Add(name, val.ToString(), val is string || val is DateTime);
}
}
private void Add(string name, string val, bool isref)
...{
if (isref)
...{
val = "'" + val + "'";
}
if (this.m_strWhere == string.Empty)
...{
this.m_strWhere = "[" + name + "]=" + val;
}
else
...{
this.m_strWhere += " and [" + name + "]=" + val;
}
}
public override string ToString()
...{
string strRet = string.Empty;
if (this.m_strWhere != string.Empty)
...{
strRet = " Where " + this.m_strWhere;
}
return strRet;
}
public void Clear()
...{
this.m_strWhere = string.Empty;
}
}
#endregion
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=2243132
- wicket中日历控件的用法
- AjaxControlToolkit中CalendarExtender日历控件的用法
- wicket控件RadioChoice,ropDownChoice用法
- my97datepicker日历控件的用法
- WdatePicker日历控件的用法
- Wicket中动态添加控件
- 关于wicket的checkgroup控件
- wicket基础应用(2)--wicket表单控件的使用
- My97DatePicker 日历控件的简单用法
- My97DatePicker日历控件的简单用法
- jQuery easyui 日历控件的用法:
- My97日历控件用法
- wicket控件的隐藏和显示
- Android中日历控件的使用
- 2009-03-29技术学习:wicket控件RadioChoice,ropDownChoice用法
- my97日历控件用法大全
- wicket基础应用(3)——wicket控件的隐藏和显示
- <wicket:link> <wicket:child> <wicket:extend> <wicket:remove>的使用
- svn使用和配置方法
- 使用P/Invoke、C#与Windows Media Player互操作(一)
- 谷歌的愚人节玩笑开大了
- Quest3D簡介
- 利用using和try-finally来释放资源
- wicket中日历控件的用法
- 网络安全工具开发函数库介绍之二——libpcap
- [原创]PHP could not find driver 解决方法
- 有多少xxx-Oriented Architecture可以“乱来”?--XOA大全
- 登录证书验证
- Start CSDNing
- EON Studio软件详细介绍
- WPF之Brush浅见
- 换工作了!