codesmith mysql 模板_分享一套简单的CodeSmith三层模板

Author: maomao

Created:Description:--%>

usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespace {public static partial class DAL

{public static List<> Search(string sqlStr,Listpms)

{

List<> list = new List<>();

DataTable table=SqlHelper.ExecuteDataTable(sqlStr,pms.ToArray());foreach (DataRow dr intable.Rows)

{ model = new (dr);

list.Add(model);

}returnlist;

}public static bool Insert(model)

{string sqlStr = "";

List fileds = new List();

List pFileds = new List();

List pms = new List();#region 添加参数

{%>

if(model.!=null&&model.!=newDateTime())

{

fileds.Add("[]");

pFileds.Add("@");

pms.Add(new SqlParameter("",SqlDbType.,){Value=model.});

}

if(model.!=null)

{

fileds.Add("[]");

pFileds.Add("@");

pms.Add(new SqlParameter("", SqlDbType.,){Value=model.});

}{

fileds.Add("[]");

pFileds.Add("@");

pms.Add(new SqlParameter("", SqlDbType.,){Value=model.});

}

#endregionStringBuilder sb= newStringBuilder();

sb.Append("INSERT INTO (");

sb.Append(string.Join(",", fileds));

sb.Append(") values (");

sb.Append(string.Join(",", pFileds));

sb.Append(")");

sqlStr=sb.ToString();int i=SqlHelper.ExecuteNonQuery(sqlStr, pms.ToArray());return i>0;

}public static bool Update(model)

{string sqlStr = "";

List fileds = new List();

List pFileds = new List();

List pms = new List();#region 添加参数

pFileds.Add("[]=@");

pms.Add(new SqlParameter("", SqlDbType.,){Value=model.});

if(model.!=null&&model.!=newDateTime())

{

fileds.Add("[]=@");

pms.Add(new SqlParameter("", SqlDbType.,){Value=model.});

}

if(model.!=null)

{

fileds.Add("[]=@");

pms.Add(new SqlParameter("", SqlDbType.,){Value=model.});

}fileds.Add("[]=@");

pms.Add(new SqlParameter("", SqlDbType.,){Value=model.});

#endregionStringBuilder sb= newStringBuilder();

sb.Append("update set");

sb.Append(string.Join(",", fileds));

sb.Append("where");

sb.Append(string.Join("and", pFileds));

sqlStr=sb.ToString();int i=SqlHelper.ExecuteNonQuery(sqlStr, pms.ToArray());return i>0;

}

}

}

public string Convert2Pascal(stringname)

{

StringBuilder sb= newStringBuilder();string[] strs = name.Split(new char[] { '_'});foreach (string str instrs)

{

sb.Append(str.Substring(0,1).ToUpper());

sb.Append(str.Substring(1));

}returnsb.ToString();

}public stringConvertTablename2Pascal(TableSchema table)

{

StringBuilder sb= newStringBuilder();string[] strs = table.Name.Split(new char[] { '_'});int index=0;foreach (string str instrs)

{if(index==0)

{

index++;continue;

}

sb.Append(str.Substring(0,1).ToUpper());

sb.Append(str.Substring(1));

}returnsb.ToString();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值