62,254
社区成员
发帖
与我相关
我的任务
分享
添加
public static bool AddZXNews(ZX_New zx_new)
{
string sql = string.Format("insert into zx_news values('{0}','{1}','{2}','{3}',null)",zx_new.Zx_Title,zx_new.Zx_Content,zx_new.Zx_Image,zx_new.Zx_Date);
int bb = DBHelper.ExecuteCommand(sql);
if (bb > 0)
return true;
return false;
}
删
public static void DeleteZX_NewByZx_ID(int zx_ID)
{
string sql = "DELETE ZX_News WHERE Zx_ID = @Zx_ID";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@Zx_ID", zx_ID)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
改
public static void ModifyZX_New(ZX_New zX_New)
{
string sql =
"UPDATE ZX_News " +
"SET " +
"Zx_Title = @Zx_Title, " +
"Zx_Content = @Zx_Content, " +
"Zx_Image = @Zx_Image, " +
"Zx_Date = @Zx_Date " +
"WHERE Zx_ID = @Zx_ID";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@Zx_ID", zX_New.Zx_ID),
new SqlParameter("@Zx_Title", zX_New.Zx_Title),
new SqlParameter("@Zx_Content", zX_New.Zx_Content),
new SqlParameter("@Zx_Image", zX_New.Zx_Image),
new SqlParameter("@Zx_Date", zX_New.Zx_Date)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
查
private static IList<ZX_New> GetZX_NewsBySql(string safeSql)
{
List<ZX_New> list = new List<ZX_New>();
try
{
DataTable table = DBHelper.GetDataSet(safeSql);
foreach (DataRow row in table.Rows)
{
ZX_New zX_New = new ZX_New();
zX_New.Zx_ID = (int)row["Zx_ID"];
zX_New.Zx_Title = (string)row["Zx_Title"];
zX_New.Zx_Content = (string)row["Zx_Content"];
zX_New.Zx_Image = (string)row["Zx_Image"];
zX_New.Zx_Date = (string)row["Zx_Date"];
list.Add(zX_New);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
public static IList<ZX_New> GetAllZX_News()
{
string sqlAll = "SELECT * FROM ZX_News";
return GetZX_NewsBySql(sqlAll);
}
public class userDAL : Iuser
{
public userDAL()
{ }
#region 成员方法
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(biai.Model.t_user model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into t_user(");
strSql.Append("uname,password,utime,uemail,uaddress,utelephone,umobile,ucompany,aid)");
strSql.Append(" values (");
strSql.Append("@uname,@password,@utime,@uemail,@uaddress,@utelephone,@umobile,@ucompany,@aid)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@uname", SqlDbType.VarChar,50),
new SqlParameter("@password", SqlDbType.VarChar,45),
new SqlParameter("@utime", SqlDbType.DateTime),
new SqlParameter("@uemail", SqlDbType.VarChar,50),
new SqlParameter("@uaddress", SqlDbType.VarChar,100),
new SqlParameter("@utelephone", SqlDbType.VarChar,20),
new SqlParameter("@umobile", SqlDbType.VarChar,20),
new SqlParameter("@ucompany", SqlDbType.VarChar,200),
new SqlParameter("@aid", SqlDbType.Int,4)};
parameters[0].Value = model.uname;
parameters[1].Value = model.password;
parameters[2].Value = model.utime;
parameters[3].Value = model.uemail;
parameters[4].Value = model.uaddress;
parameters[5].Value = model.utelephone;
parameters[6].Value = model.umobile;
parameters[7].Value = model.ucompany;
parameters[8].Value = model.aid;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 1;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(biai.Model.t_user model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update t_user set ");
strSql.Append("uname=@uname,");
strSql.Append("password=@password,");
strSql.Append("utime=@utime,");
strSql.Append("uemail=@uemail,");
strSql.Append("uaddress=@uaddress,");
strSql.Append("utelephone=@utelephone,");
strSql.Append("umobile=@umobile,");
strSql.Append("ucompany=@ucompany,");
strSql.Append("aid=@aid");
strSql.Append(" where uid=@uid ");
SqlParameter[] parameters = {
new SqlParameter("@uid", SqlDbType.Int,4),
new SqlParameter("@uname", SqlDbType.VarChar,50),
new SqlParameter("@password", SqlDbType.VarChar,45),
new SqlParameter("@utime", SqlDbType.DateTime),
new SqlParameter("@uemail", SqlDbType.VarChar,50),
new SqlParameter("@uaddress", SqlDbType.VarChar,100),
new SqlParameter("@utelephone", SqlDbType.VarChar,20),
new SqlParameter("@umobile", SqlDbType.VarChar,20),
new SqlParameter("@ucompany", SqlDbType.VarChar,200),
new SqlParameter("@aid", SqlDbType.Int,4)};
parameters[0].Value = model.uid;
parameters[1].Value = model.uname;
parameters[2].Value = model.password;
parameters[3].Value = model.utime;
parameters[4].Value = model.uemail;
parameters[5].Value = model.uaddress;
parameters[6].Value = model.utelephone;
parameters[7].Value = model.umobile;
parameters[8].Value = model.ucompany;
parameters[9].Value = model.aid;
return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
}
/// <summary>
/// 更新一个用户的密码
/// </summary>
/// <param name="id">用户编号uid</param>
/// <param name="pw">新密码</param>
/// <returns></returns>
public int UpdateUserPWbyUid(int id, string pw)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update t_user set ");
strSql.Append("password=@password ");
strSql.Append(" where uid = @uid ");
SqlParameter[] parameters = {
new SqlParameter("@uid", SqlDbType.Int,4),
new SqlParameter("@password", SqlDbType.VarChar,45)};
parameters[0].Value = id;
parameters[1].Value = pw.ToString();
return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(int uid)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from t_user ");
strSql.Append(" where uid=@uid ");
SqlParameter[] parameters = {
new SqlParameter("@uid", SqlDbType.Int,4)};
parameters[0].Value = uid;
return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
}
/// <summary>
/// 删除多条数据
/// </summary>
public int Delete(string ids)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from t_user ");
strSql.Append(" where uid in (");
strSql.Append(ids);
strSql.Append(") ");
return DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public biai.Model.t_user GetModel(int uid)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 uid,uname,password,utime,uemail,uaddress,utelephone,umobile,ucompany,aid from t_user ");
strSql.Append(" where uid=@uid ");
SqlParameter[] parameters = {
new SqlParameter("@uid", SqlDbType.Int,4)};
parameters[0].Value = uid;
biai.Model.t_user model = new biai.Model.t_user();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["uid"].ToString() != "")
{
model.uid = int.Parse(ds.Tables[0].Rows[0]["uid"].ToString());
}
model.uname = ds.Tables[0].Rows[0]["uname"].ToString();
model.password = ds.Tables[0].Rows[0]["password"].ToString();
if (ds.Tables[0].Rows[0]["utime"].ToString() != "")
{
model.utime = DateTime.Parse(ds.Tables[0].Rows[0]["utime"].ToString());
}
model.uemail = ds.Tables[0].Rows[0]["uemail"].ToString();
model.uaddress = ds.Tables[0].Rows[0]["uaddress"].ToString();
model.utelephone = ds.Tables[0].Rows[0]["utelephone"].ToString();
model.umobile = ds.Tables[0].Rows[0]["umobile"].ToString();
model.ucompany = ds.Tables[0].Rows[0]["ucompany"].ToString();
if (ds.Tables[0].Rows[0]["aid"].ToString() != "")
{
model.aid = int.Parse(ds.Tables[0].Rows[0]["aid"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select uid,uname,password,utime,uemail,uaddress,utelephone,umobile,ucompany,aid ");
strSql.Append(" FROM t_user ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
#endregion 成员方法
}