日期:2014-05-17 浏览次数:20578 次
public class SqlBuilder
{
private List<CheckBox> _ckbColumns;
private List<CheckBox> _ckbCondtions;
private List<string> _conditions;
private string _tablename;
public SqlBuilder()
{
_ckbColumns = new List<CheckBox>();
_ckbCondtions = new List<CheckBox>();
_conditions = new List<string>();
}
public void AddCheckBoxColumn(CheckBox item)
{
_ckbColumns.Add(item);
}
public void AddCheckBoxCondition(CheckBox item,string condition)
{
_ckbCondtions.Add(item);
_conditions.Add(condition);
}
public string SQL
{
get
{
StringBuilder sbCondition = new StringBuilder();
StringBuilder sbColumns = new StringBuilder();
string sql;
int i = 0;
foreach (CheckBox ckbColumn in _ckbColumns)
{
if (ckbColumn.Checked)
sbColumns.Append("," + ckbColumn.Text);
}
sbCondition.Append(" where 1 = 1 ");
foreach (CheckBox ckbCondition in _ckbCondtions)
{
if (ckbCondition.Checked)
{ sbCondition.Append(" and " + ckbCondition.Text + " = N'" + _conditions[i].Trim() + "'");
i++;
}